[FFmpeg-devel] Add waveformat extensible support in wav muxer (SoC qualification task)

Michael Niedermayer michaelni
Sun Apr 5 23:04:38 CEST 2009


On Mon, Apr 06, 2009 at 12:04:58AM +0800, zhentan feng wrote:
> Hi
> 
> 2009/4/4 Michael Niedermayer <michaelni at gmx.at>
> 
> > On Sat, Apr 04, 2009 at 05:14:06PM +0800, zhentan feng wrote:
> > > 2009/4/4 Michael Niedermayer <michaelni at gmx.at>
> > >
> > > > [...]
> > > >
> > > > > Index: libavformat/riff.c
> > > > > ===================================================================
> > > > > --- libavformat/riff.c        (revision 18184)
> > > > > +++ libavformat/riff.c        (working copy)
> > > > > @@ -283,6 +283,7 @@
> > > > >  {
> > > > >      int bps, blkalign, bytespersec;
> > > > >      int hdrsize = 18;
> > > > > +    int pre_size = 0;
> > > > >
> > > > >      if(!enc->codec_tag || enc->codec_tag > 0xffff)
> > > > >          return -1;
> > > > > @@ -292,8 +293,16 @@
> > > > >      put_le32(pb, enc->sample_rate);
> > > > >      if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id ==
> > CODEC_ID_MP3
> > > > || enc->codec_id == CODEC_ID_GSM_MS) {
> > > > >          bps = 0;
> > > > > +        if (enc->codec_id == CODEC_ID_MP2) {
> > > > > +            pre_size = 22; /* wav_extra_size */
> > > > > +        } else if(enc->codec_id == CODEC_ID_MP3) {
> > > > > +            pre_size = 12; /* wav_extra_size */
> > > > > +        } else
> > > > > +            pre_size = 2; /* wav_extra_size */
> > > > >      } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV ||
> > enc->codec_id
> > > > == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 ||
> > > > enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { //
> > > > >          bps = 4;
> > > > > +        if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV)
> > > > > +            pre_size = 2; /* wav_extra_size */
> > > > >      } else {
> > > > >          if (!(bps = av_get_bits_per_sample(enc->codec_id)))
> > > > >              bps = 16; // default to 16
> > > > > @@ -324,8 +333,15 @@
> > > > >      put_le32(pb, bytespersec); /* bytes per second */
> > > > >      put_le16(pb, blkalign); /* block align */
> > > > >      put_le16(pb, bps); /* bits per sample */
> > > > > +
> > > > > +    if (!pre_size && enc->extradata_size)
> > > > > +        pre_size = enc->extradata_size;
> > > > > +    if (pre_size)
> > > > > +        put_le16(pb, pre_size);
> > > > > +    else
> > > > > +        return hdrsize - 2;
> > > > > +
> > > > >      if (enc->codec_id == CODEC_ID_MP3) {
> > > > > -        put_le16(pb, 12); /* wav_extra_size */
> > > > >          hdrsize += 12;
> > > > >          put_le16(pb, 1); /* wID */
> > > > >          put_le32(pb, 2); /* fdwFlags */
> > > > > @@ -333,7 +349,6 @@
> > > > >          put_le16(pb, 1); /* nFramesPerBlock */
> > > > >          put_le16(pb, 1393); /* nCodecDelay */
> > > > >      } else if (enc->codec_id == CODEC_ID_MP2) {
> > > > > -        put_le16(pb, 22); /* wav_extra_size */
> > > > >          hdrsize += 22;
> > > > >          put_le16(pb, 2);  /* fwHeadLayer */
> > > > >          put_le32(pb, enc->bit_rate); /* dwHeadBitrate */
> > > > > @@ -344,15 +359,12 @@
> > > > >          put_le32(pb, 0);  /* dwPTSLow */
> > > > >          put_le32(pb, 0);  /* dwPTSHigh */
> > > > >      } else if (enc->codec_id == CODEC_ID_GSM_MS) {
> > > > > -        put_le16(pb, 2); /* wav_extra_size */
> > > > >          hdrsize += 2;
> > > > >          put_le16(pb, enc->frame_size); /* wSamplesPerBlock */
> > > > >      } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
> > > > > -        put_le16(pb, 2); /* wav_extra_size */
> > > > >          hdrsize += 2;
> > > > >          put_le16(pb, enc->frame_size); /* wSamplesPerBlock */
> > > > >      } else if(enc->extradata_size){
> > > > > -        put_le16(pb, enc->extradata_size);
> > > > >          put_buffer(pb, enc->extradata, enc->extradata_size);
> > > > >          hdrsize += enc->extradata_size;
> > > > >          if(hdrsize&1){
> > > >
> > > > uint8_t temp[256];
> > > > uint8_t *riff_extradata= temp;
> > > > uint8_t *riff_extradata_start= temp;
> > > >
> > > > if(codec_id == abc){
> > > >    bytestream_put_le16()
> > > >    ...
> > > > }else if ...
> > > > ...
> > > > } else if(enc->extradata_size){
> > > >     riff_extradata_start= enc->extradata;
> > > >    riff_extradata= enc->extradata + enc->extradata_size;
> > > > }
> > > >
> > > > if(waveformatext){
> > > >    ...
> > > > }else{
> > > >    ...
> > > > }
> > > > put_buffer(pb, riff_extradata, riff_extradata - riff_extradata_start);
> > > >
> > >
> > > here is the new patch.
> > > I'll submit the indent patch and extract some code lines later.
> >
> > patch ok if it works
> >
> >
> please ignore the former patch I submitted today.
> 
> I have fixed some bugs and created a new patch attached below.
> It's passed the current regression test and the output multi-channels files
> can palyed by windowsmediaplayer.

[...]
> +    waveformatextensible = enc->channels > 2 && enc->channel_layout;
> +    if (waveformatextensible) {
> +        put_le16(pb, 0xfffe);
> +    } else {
> +    put_le16(pb, enc->codec_tag);
> +    }
>  
> -    put_le16(pb, enc->codec_tag);

this looks strange


>      put_le16(pb, enc->channels);
>      put_le32(pb, enc->sample_rate);
>      if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
> @@ -326,43 +336,54 @@
>      put_le16(pb, blkalign); /* block align */
>      put_le16(pb, bps); /* bits per sample */
>      if (enc->codec_id == CODEC_ID_MP3) {
> -        put_le16(pb, 12); /* wav_extra_size */
>          hdrsize += 12;
> -        put_le16(pb, 1); /* wID */
> -        put_le32(pb, 2); /* fdwFlags */
> -        put_le16(pb, 1152); /* nBlockSize */
> -        put_le16(pb, 1); /* nFramesPerBlock */
> -        put_le16(pb, 1393); /* nCodecDelay */

> +        bytestream_put_le16(&riff_extradata, 1); /* wID */
> +        bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
> +        bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
> +        bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
> +        bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */

vertical align


[...]
>      } else if(enc->extradata_size){
> -        put_le16(pb, enc->extradata_size);
> -        put_buffer(pb, enc->extradata, enc->extradata_size);
> +        riff_extradata_start= enc->extradata;
> +        riff_extradata= enc->extradata + enc->extradata_size;
>          hdrsize += enc->extradata_size;
> -        if(hdrsize&1){
> -            hdrsize++;
> -            put_byte(pb, 0);
> -        }
>      } else {
>          hdrsize -= 2;
>      }
> +    if(waveformatextensible) {                      /* write WAVEFORMATEXTENSIBLE extensions */
> +        if (riff_extradata == riff_extradata_start)
> +            hdrsize += 2;
> +        hdrsize += 22;
> +        put_le16(pb, riff_extradata - riff_extradata_start + 22); /* 22 is WAVEFORMATEXTENSIBLE size */
> +        put_le16(pb, enc->bits_per_coded_sample);   /* ValidBitsPerSample || SamplesPerBlock || Reserved */
> +        put_le32(pb, enc->channel_layout);          /* dwChannelMask */
> +        put_le32(pb, enc->codec_tag);               /* GUID + next 3 */
> +        put_le32(pb, 0x00100000);
> +        put_le32(pb, 0xAA000080);
> +        put_le32(pb, 0x719B3800);
> +    } else if(riff_extradata - riff_extradata_start) {
> +        put_le16(pb, riff_extradata - riff_extradata_start);
> +    }

now its a mess again

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090405/a06c1012/attachment.pgp>



More information about the ffmpeg-devel mailing list