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

zhentan feng spyfeng
Fri Apr 3 16:49:24 CEST 2009


2009/4/3 zhentan feng <spyfeng at gmail.com>

> Hi
>
> 2009/4/3 Michael Niedermayer <michaelni at gmx.at>
>
> On Fri, Apr 03, 2009 at 01:25:37AM +0800, zhentan feng wrote:
>> [...]
>> > new patch attached below.
>> >
>> > zhentan
>> > --
>> > Best wishes~
>>
>> > Index: libavformat/riff.c
>> > ===================================================================
>> > --- libavformat/riff.c        (revision 18184)
>> > +++ libavformat/riff.c        (working copy)
>> > @@ -282,18 +282,34 @@
>> >  int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
>> >  {
>> >      int bps, blkalign, bytespersec;
>> > +    int waveformatextensible;
>> >      int hdrsize = 18;
>> > +    int pre_size = 0;
>> >
>> >      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 = 22; /* 22 is the size of
>> WAVEFORMATEXTENSIBLE-WAVEFORMATEX */
>> > +    } else
>> > +        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 (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 +340,30 @@
>> >      put_le32(pb, bytespersec); /* bytes per second */
>> >      put_le16(pb, blkalign); /* block align */
>> >      put_le16(pb, bps); /* bits per sample */
>> > +
>> > +    if (pre_size) {
>> > +        if (waveformatextensible && pre_size == 22) {
>> > +            put_le16(pb, pre_size + enc->extradata_size);
>> > +        } else
>> > +            put_le16(pb, pre_size);
>> > +    } else {
>> > +        if (enc->extradata_size) {
>> > +            put_le16(pb, enc->extradata_size);
>> > +        } else
>> > +            return hdrsize - 2;
>> > +    }
>> > +
>>
>> this is still a mess
>> [...]
>
>
> According to the suggestion from Ronald.
> I'll submmit the patch step by step.
>
> this patch calculate the size of the extradata_size before write extradata.
> then I'll submitt the patch for adding waveformatextensible.
> this would be more readable and keep my head cool :)
>


1,move_code_lines.patch move the code lines up and down for the next patch.
2,add_waveformatextensible.patch add the WAVEFORMATEXTENSIBLE struct for
wav.
3,indent.patch

thanks
zhentan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: move_code_lines.patch
Type: application/octet-stream
Size: 1051 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090403/9e8036cd/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add_waveformatextensible.patch
Type: application/octet-stream
Size: 1549 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090403/9e8036cd/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: indent.patch
Type: application/octet-stream
Size: 312 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090403/9e8036cd/attachment-0002.obj>



More information about the ffmpeg-devel mailing list