[FFmpeg-devel] [PATCH 13/16] vmdaudio: simplify vmdaudio_decode_frame() by handling block_type first, then making a single call to vmdaudio_loadsound().
Justin Ruggles
justin.ruggles
Tue Feb 22 23:39:44 CET 2011
On 02/22/2011 04:58 PM, Kostya wrote:
> On Tue, Feb 22, 2011 at 02:05:32PM -0500, Justin Ruggles wrote:
>>
>> This also adds output buffer size checks for AUDIO and SILENCE block types.
>> ---
>> libavcodec/vmdav.c | 24 ++++++++++++------------
>> 1 files changed, 12 insertions(+), 12 deletions(-)
>>
>
>> diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c
>> index 83173d0..92159f6 100644
>> --- a/libavcodec/vmdav.c
>> +++ b/libavcodec/vmdav.c
>> @@ -506,7 +506,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx,
>> const uint8_t *buf = avpkt->data;
>> int buf_size = avpkt->size;
>> VmdAudioContext *s = avctx->priv_data;
>> - int block_type;
>> + int block_type, silent_chunks;
>> unsigned char *output_samples = (unsigned char *)data;
>>
>> if (buf_size < 16) {
>> @@ -523,23 +523,23 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx,
>> buf += 16;
>> buf_size -= 16;
>>
>> - if (block_type == BLOCK_TYPE_AUDIO) {
>> - /* the chunk contains audio */
>> - *data_size = vmdaudio_loadsound(s, output_samples, buf, 0, buf_size);
>> - } else if (block_type == BLOCK_TYPE_INITIAL) {
>> - /* initial chunk, may contain audio and silence */
>> + silent_chunks = 0;
>> + if (block_type == BLOCK_TYPE_INITIAL) {
>> uint32_t flags = AV_RB32(buf);
>> - int silent_chunks = av_popcount(flags);
>> + silent_chunks = av_popcount(flags);
>> buf += 4;
>> buf_size -= 4;
>> - if(*data_size < (s->block_align*silent_chunks + buf_size) * 2)
>> - return -1;
>> - *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);
>> } else if (block_type == BLOCK_TYPE_SILENCE) {
>> - /* silent chunk */
>> - *data_size = vmdaudio_loadsound(s, output_samples, buf, 1, 0);
>> + silent_chunks = 1;
>> + buf_size = 0; // should already be zero but set it just to be sure
>> }
>>
>> + /* ensure output buffer is large enough */
>> + if (*data_size < (s->block_align*silent_chunks + buf_size) * 2)
>> + return -1;
>> +
>> + *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);
>> +
>> return avpkt->size;
>> }
>>
>
> will it work if initial block needs to interleave silent and non-silent chunks
> in order given by flags?
The structure of the patch will work. Just the silence handling would
have to be changed and flags would have to be passed to
vmdaudio_loadsound(). If you can figure it out, more power to you, but
everything I tried involving interleaving the silence with audio ended
up with silence in very obviously wrong places.
-Justin
More information about the ffmpeg-devel
mailing list