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

zhentan feng spyfeng
Thu Apr 2 13:28:13 CEST 2009


Hi

2009/4/2 Michael Niedermayer <michaelni at gmx.at>

> [...]
> > Index: libavformat/riff.c
> > ===================================================================
> > --- libavformat/riff.c        (revision 18184)
> > +++ libavformat/riff.c        (working copy)
> > @@ -282,18 +282,37 @@
> >  int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
> >  {
> >      int bps, blkalign, bytespersec;
> > +    int waveformatextensible;
> >      int hdrsize = 18;
> > +    int pre_size;
> >
> >      if(!enc->codec_tag || enc->codec_tag > 0xffff)
> >          return -1;
> >
> > -    put_le16(pb, enc->codec_tag);
> > +    waveformatextensible = enc->channels > 2 && enc->channel_layout;
> > +    if (waveformatextensible) {
> > +        put_le16(pb, 0xfffe);
> > +        pre_size = enc->extradata_size;
>
> > +    }
> > +    else
>
> these should be on the same line in K&R style
>
>
> > +        put_le16(pb, enc->codec_tag);
> > +
> >      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) {
> >          bps = 0;
> > +        if (waveformatextensible) {
> > +            if (enc->codec_id == CODEC_ID_MP2)
> > +                pre_size = 22;
> > +            else if(enc->codec_id == CODEC_ID_MP3)
> > +                pre_size = 12;
> > +            else
> > +                pre_size = 2;
> > +        }
> >      } 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 (waveformatextensible && enc->codec_id ==
> CODEC_ID_ADPCM_IMA_WAV)
> > +            pre_size = 2;
> >      } else {
> >          if (!(bps = av_get_bits_per_sample(enc->codec_id)))
> >              bps = 16; // default to 16
> > @@ -324,8 +343,21 @@
> >      put_le32(pb, bytespersec); /* bytes per second */
> >      put_le16(pb, blkalign); /* block align */
> >      put_le16(pb, bps); /* bits per sample */
> > +
> > +    if (waveformatextensible) {                     /* write
> WAVEFORMATEXTENSIBLE extensions */
> > +        put_le16(pb, pre_size + 22);       /* 22 is the size of
> WAVEFORMATEXTENSIBLE-WAVEFORMATEX */
> > +        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);
> > +        hdrsize += 22;
> > +    }
> > +
> >      if (enc->codec_id == CODEC_ID_MP3) {
> > -        put_le16(pb, 12); /* wav_extra_size */
> > +        if (!waveformatextensible)
> > +            put_le16(pb, 12); /* wav_extra_size */
> >          hdrsize += 12;
> >          put_le16(pb, 1); /* wID */
> >          put_le32(pb, 2); /* fdwFlags */
> > @@ -333,7 +365,8 @@
> >          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 */
> > +        if (!waveformatextensible)
> > +            put_le16(pb, 22); /* wav_extra_size */
> >          hdrsize += 22;
> >          put_le16(pb, 2);  /* fwHeadLayer */
> >          put_le32(pb, enc->bit_rate); /* dwHeadBitrate */
> > @@ -344,15 +377,18 @@
> >          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 */
> > +        if (!waveformatextensible)
> > +            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 */
> > +        if (!waveformatextensible)
> > +            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);
> > +        if (!waveformatextensible)
> > +            put_le16(pb, enc->extradata_size);
> >          put_buffer(pb, enc->extradata, enc->extradata_size);
> >          hdrsize += enc->extradata_size;
> >          if(hdrsize&1){
>
> iam sorry but this is a unmaintainable mess
>
> There are 2 parts, first the waveformatextensible header, and second the
> extradata.
> The extradata has a bunch of special cases that write things differently
> from just extradata. But in the end it just writes
> * the size of all
> * optionally the waveformatextensible header
> * extadata
>
> this can be done without having 8 special cases added for
> waveformatextensible
>
> [...]
>

here is the new patch attached below.

zhentan
-- 
Best wishes~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: waveformatextensible_09.patch
Type: application/octet-stream
Size: 3620 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090402/e4f86467/attachment.obj>



More information about the ffmpeg-devel mailing list