[FFmpeg-cvslog] twinvq: set block align for codecs and use it in size checks
Kostya Shishkov
git at videolan.org
Mon Aug 26 14:53:26 CEST 2013
ffmpeg | branch: master | Kostya Shishkov <kostya.shishkov at gmail.com> | Sat Aug 24 15:00:08 2013 +0200| [9e7b62f0fb7462a902330fcc82cf596388f0187b] | committer: Kostya Shishkov
twinvq: set block align for codecs and use it in size checks
This both allows factoring out size check for both MetaSound and TwinVQ-VQF
decoders and fixes the situation when there are several MetaSound frames
stuffed together (that happens in 8kHz @ 8kbps MetaSound in ASF for example).
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9e7b62f0fb7462a902330fcc82cf596388f0187b
---
libavcodec/metasound.c | 9 +++------
libavcodec/twinvq.c | 8 +++++++-
libavcodec/twinvqdec.c | 9 +++------
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/libavcodec/metasound.c b/libavcodec/metasound.c
index b124536..88cbff6 100644
--- a/libavcodec/metasound.c
+++ b/libavcodec/metasound.c
@@ -170,12 +170,6 @@ static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
GetBitContext gb;
int i, j, k;
- if (buf_size * 8 < avctx->bit_rate * mtab->size / avctx->sample_rate) {
- av_log(avctx, AV_LOG_ERROR,
- "Frame too small (%d bytes). Truncated file?\n", buf_size);
- return AVERROR(EINVAL);
- }
-
init_get_bits(&gb, buf, buf_size * 8);
bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS);
@@ -323,6 +317,9 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
+ avctx->block_align = (avctx->bit_rate * tctx->mtab->size
+ / avctx->sample_rate + 7) / 8;
+
tctx->codec = TWINVQ_CODEC_METASOUND;
tctx->read_bitstream = metasound_read_bitstream;
tctx->dec_bark_env = dec_bark_env;
diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c
index 17dea79..24f5747 100644
--- a/libavcodec/twinvq.c
+++ b/libavcodec/twinvq.c
@@ -491,6 +491,12 @@ int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data,
out = (float **)frame->extended_data;
}
+ if (buf_size < avctx->block_align) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Frame too small (%d bytes). Truncated file?\n", buf_size);
+ return AVERROR(EINVAL);
+ }
+
if ((ret = tctx->read_bitstream(avctx, tctx, buf, buf_size)) < 0)
return ret;
@@ -508,7 +514,7 @@ int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data,
*got_frame_ptr = 1;
- return buf_size;
+ return avctx->block_align;
}
/**
diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c
index 259a9d6..a88b6ff 100644
--- a/libavcodec/twinvqdec.c
+++ b/libavcodec/twinvqdec.c
@@ -258,12 +258,6 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
GetBitContext gb;
int i, j, k;
- if (buf_size * 8 < avctx->bit_rate * mtab->size / avctx->sample_rate + 8) {
- av_log(avctx, AV_LOG_ERROR,
- "Frame too small (%d bytes). Truncated file?\n", buf_size);
- return AVERROR(EINVAL);
- }
-
init_get_bits(&gb, buf, buf_size * 8);
skip_bits(&gb, get_bits(&gb, 8));
@@ -398,6 +392,9 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx)
return -1;
}
+ avctx->block_align = (avctx->bit_rate * tctx->mtab->size
+ / avctx->sample_rate + 15) / 8;
+
tctx->codec = TWINVQ_CODEC_VQF;
tctx->read_bitstream = twinvq_read_bitstream;
tctx->dec_bark_env = dec_bark_env;
More information about the ffmpeg-cvslog
mailing list