summaryrefslogtreecommitdiff
path: root/libavcodec/imc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-11-03 02:01:37 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-11-03 02:16:26 +0100
commit988f585fcb1cfb40fe4b706c32b31594b536bba0 (patch)
tree659b8d9f4daf4ce497b42c83f7adb45725fa4f65 /libavcodec/imc.c
parent0b3e9d5dc61bb705d93db1e87d78d8d5131905c6 (diff)
parent594b54b51e9f3af8aac18184d634b85a836b42b6 (diff)
downloadffmpeg-988f585fcb1cfb40fe4b706c32b31594b536bba0.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: (44 commits) replacement Indeo 3 decoder gsm demuxer: do not allocate packet twice. flvenc: use first packet delay as global delay. ac3enc: doxygen update. imc: return error codes instead of 0 for error conditions. imc: return meaningful error codes instead of -1 imc: do not set channel layout for stereo imc: validate channel count imc: check for ff_fft_init() failure imc: check output buffer size before decoding imc: use DSPContext.bswap16_buf() to byte-swap packet data rtsp: add allowed_media_types option libgsm: add flush function to reset the decoder state when seeking libgsm: simplify decoding by using a loop gsm: log error message when packet is too small libgsmdec: do not needlessly set *data_size to 0 gsmdec: do not needlessly set *data_size to 0 gsmdec: add flush function to reset the decoder state when seeking libgsmdec: check output buffer size before decoding gsmdec: log error message when output buffer is too small. ... Conflicts: Changelog ffplay.c libavcodec/indeo3.c libavcodec/mjpeg_parser.c libavcodec/vp3.c libavformat/cutils.c libavformat/id3v2.c libavutil/parseutils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/imc.c')
-rw-r--r--libavcodec/imc.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index f08efe46ec..bb6f095875 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -104,10 +104,15 @@ static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2];
static av_cold int imc_decode_init(AVCodecContext * avctx)
{
- int i, j;
+ int i, j, ret;
IMCContext *q = avctx->priv_data;
double r1, r2;
+ if (avctx->channels != 1) {
+ av_log_ask_for_sample(avctx, "Number of channels is not supported\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
q->decoder_reset = 1;
for(i = 0; i < BANDS; i++)
@@ -156,10 +161,13 @@ static av_cold int imc_decode_init(AVCodecContext * avctx)
}
q->one_div_log2 = 1/log(2);
- ff_fft_init(&q->fft, 7, 1);
+ if ((ret = ff_fft_init(&q->fft, 7, 1))) {
+ av_log(avctx, AV_LOG_INFO, "FFT init failed\n");
+ return ret;
+ }
dsputil_init(&q->dsp, avctx);
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
- avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+ avctx->channel_layout = AV_CH_LAYOUT_MONO;
return 0;
}
@@ -336,7 +344,7 @@ static int bit_allocation (IMCContext* q, int stream_format_code, int freebits,
indx = 2;
if (indx == -1)
- return -1;
+ return AVERROR_INVALIDDATA;
q->flcoeffs4[i] = q->flcoeffs4[i] + xTab[(indx*2 + (q->flcoeffs1[i] < highest)) * 2 + flag];
}
@@ -595,7 +603,7 @@ static int inverse_quant_coeff (IMCContext* q, int stream_format_code) {
middle_value = max_size >> 1;
if (q->codewords[j] >= max_size || q->codewords[j] < 0)
- return -1;
+ return AVERROR_INVALIDDATA;
if (cw_len >= 4){
quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
@@ -628,7 +636,7 @@ static int imc_get_coeffs (IMCContext* q) {
if (get_bits_count(&q->gb) + cw_len > 512){
//av_log(NULL,0,"Band %i coeff %i cw_len %i\n",i,j,cw_len);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if(cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j]))
@@ -651,18 +659,24 @@ static int imc_decode_frame(AVCodecContext * avctx,
IMCContext *q = avctx->priv_data;
int stream_format_code;
- int imc_hdr, i, j;
+ int imc_hdr, i, j, out_size, ret;
int flag;
int bits, summer;
int counter, bitscount;
- uint16_t buf16[IMC_BLOCK_SIZE / 2];
+ LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]);
if (buf_size < IMC_BLOCK_SIZE) {
av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
- for(i = 0; i < IMC_BLOCK_SIZE / 2; i++)
- buf16[i] = av_bswap16(((const uint16_t*)buf)[i]);
+
+ out_size = COEFFS * 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);
+ }
+
+ q->dsp.bswap16_buf(buf16, (const uint16_t*)buf, IMC_BLOCK_SIZE / 2);
q->out_samples = data;
init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
@@ -672,13 +686,13 @@ static int imc_decode_frame(AVCodecContext * avctx,
if (imc_hdr != IMC_FRAME_ID) {
av_log(avctx, AV_LOG_ERROR, "imc frame header check failed!\n");
av_log(avctx, AV_LOG_ERROR, "got %x instead of 0x21.\n", imc_hdr);
- return -1;
+ return AVERROR_INVALIDDATA;
}
stream_format_code = get_bits(&q->gb, 3);
if(stream_format_code & 1){
av_log(avctx, AV_LOG_ERROR, "Stream code format %X is not supported\n", stream_format_code);
- return -1;
+ return AVERROR_INVALIDDATA;
}
// av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code);
@@ -738,10 +752,11 @@ static int imc_decode_frame(AVCodecContext * avctx,
}
}
- if(bit_allocation (q, stream_format_code, 512 - bitscount - get_bits_count(&q->gb), flag) < 0) {
+ if((ret = bit_allocation (q, stream_format_code,
+ 512 - bitscount - get_bits_count(&q->gb), flag)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
q->decoder_reset = 1;
- return -1;
+ return ret;
}
for(i = 0; i < BANDS; i++) {
@@ -795,20 +810,20 @@ static int imc_decode_frame(AVCodecContext * avctx,
if(imc_get_coeffs(q) < 0) {
av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n");
q->decoder_reset = 1;
- return 0;
+ return AVERROR_INVALIDDATA;
}
if(inverse_quant_coeff(q, stream_format_code) < 0) {
av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
q->decoder_reset = 1;
- return 0;
+ return AVERROR_INVALIDDATA;
}
memset(q->skipFlags, 0, sizeof(q->skipFlags));
imc_imdct256(q);
- *data_size = COEFFS * sizeof(float);
+ *data_size = out_size;
return IMC_BLOCK_SIZE;
}