[FFmpeg-devel] [PATCH 02/16] vmdaudio: remove duplicated code by merging mono and stereo decoding.

Justin Ruggles justin.ruggles
Tue Feb 22 21:46:31 CET 2011


On 02/22/2011 02:23 PM, Reimar D?ffinger wrote:

> On Tue, Feb 22, 2011 at 02:05:21PM -0500, Justin Ruggles wrote:
>> ---
>>  libavcodec/vmdav.c |   23 +----------------------
>>  1 files changed, 1 insertions(+), 22 deletions(-)
>>
> 
>> diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c
>> index c7f99db..cbe530d 100644
>> --- a/libavcodec/vmdav.c
>> +++ b/libavcodec/vmdav.c
>> @@ -475,19 +475,16 @@ static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data,
>>  static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data,
>>      const uint8_t *buf, int silence, int data_size)
>>  {
>> -    int bytes_decoded = 0;
>>      int i;
>>  
>>  //    if (silence)
>>  //        av_log(s->avctx, AV_LOG_INFO, "silent block!\n");
>> -    if (s->channels == 2) {
>>  
>> -        /* stereo handling */
>>          if (silence) {
>>              memset(data, 0, data_size * 2);
>>          } else {
>>              if (s->bits == 16)
>> -                vmdaudio_decode_audio(s, data, buf, data_size, 1);
>> +                vmdaudio_decode_audio(s, data, buf, data_size, s->channels == 2);
>>              else {
>>                  /* copy the data but convert it to signed */
>>                  for (i = 0; i < data_size; i++){
>> @@ -496,24 +493,6 @@ static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data,
>>                  }
>>              }
>>          }
>> -    } else {
>> -        bytes_decoded = data_size * 2;
>> -
>> -        /* mono handling */
>> -        if (silence) {
>> -            memset(data, 0, data_size * 2);
>> -        } else {
>> -            if (s->bits == 16) {
>> -                vmdaudio_decode_audio(s, data, buf, data_size, 0);
>> -            } else {
>> -                /* copy the data but convert it to signed */
>> -                for (i = 0; i < data_size; i++){
>> -                    *data++ = buf[i] + 0x80;
>> -                    *data++ = buf[i] + 0x80;
>> -                }
>> -            }
>> -        }
>> -    }
> 
> I don't really think it matters, but if vmdaudio_decode_audio gets inlined it is possible
> that the previous code would be significantly faster.


No, it doesn't really matter.  After the patch set is applied I can
remove that parameter and just add the check to vmdaudio_decode_audio().

Somewhat related to this, vmdaudio_decode_audio() and the table that
goes with it should really be shared with dpcm.c since it is identical
to CODEC_ID_SOL_DPCM with codec_tag == 3.  I haven't done this yet
because I'm waiting for some 16-bit VMD files from Mike Melanson so I
can test it.  All of the VMD samples on mplayerhq are 8-bit.

-Justin



More information about the ffmpeg-devel mailing list