diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2011-10-27 14:36:41 -0400 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2011-11-01 21:23:03 -0400 |
commit | c8d36d254e298a51ea569b2557451d26499d0f88 (patch) | |
tree | 395fee50ef22c6111a58a18ce8b279b91413d09c /libavcodec/g726.c | |
parent | e61a670b53f4578ab06c2a2d0452518384ac00e5 (diff) | |
download | ffmpeg-c8d36d254e298a51ea569b2557451d26499d0f88.tar.gz |
g726: pre-calculate the number of output samples.
Allows for checking output buffer size and simplification of decoding loop.
Diffstat (limited to 'libavcodec/g726.c')
-rw-r--r-- | libavcodec/g726.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 6cd8c936ac..6ff3288a67 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -377,16 +377,24 @@ static int g726_decode_frame(AVCodecContext *avctx, G726Context *c = avctx->priv_data; int16_t *samples = data; GetBitContext gb; + int out_samples, out_size; + + out_samples = buf_size * 8 / c->code_size; + out_size = out_samples * av_get_bytes_per_sample(avctx->sample_fmt); + if (*data_size < out_size) { + av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); + return AVERROR(EINVAL); + } init_get_bits(&gb, buf, buf_size * 8); - while (get_bits_count(&gb) + c->code_size <= buf_size*8) + while (out_samples--) *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); - if(buf_size*8 != get_bits_count(&gb)) + if (get_bits_left(&gb) > 0) av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); - *data_size = (uint8_t*)samples - (uint8_t*)data; + *data_size = out_size; return buf_size; } |