diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-10-30 01:33:41 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-10-30 01:33:41 +0200 |
commit | d17e7070a099af04a1dc7bc9ddd82f67bfcf9827 (patch) | |
tree | 4be589d09939bead88ef3d4e1d5e90fe0348af6c /libavcodec/dca.c | |
parent | 1af3571e05522df4e71a5b33de05bdb9e953a6c4 (diff) | |
parent | 7d1b17b83330aefe2f32a66fe84effe46ae51014 (diff) | |
download | ffmpeg-d17e7070a099af04a1dc7bc9ddd82f67bfcf9827.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (51 commits)
cin audio: use sign_extend() instead of casting to int16_t
cin audio: restructure decoding loop to avoid a separate counter variable
cin audio: use local variable for delta value
cin audio: remove unneeded cast from void*
cin audio: validate the channel count
cin audio: remove unneeded AVCodecContext pointer from CinAudioContext
dsicin: fix several audio-related fields in the CIN demuxer
flacdec: use av_get_bytes_per_sample() to get sample size
dca: handle errors from dca_decode_block()
dca: return error if the frame header is invalid
dca: return proper error codes instead of -1
utvideo: handle empty Huffman trees
binkaudio: change short to int16_t
binkaudio: only decode one block at a time.
binkaudio: store interleaved overlap samples in BinkAudioContext.
binkaudio: pre-calculate quantization factors
binkaudio: add some buffer overread checks.
atrac3: support float or int16 output using request_sample_fmt
atrac3: add CODEC_CAP_SUBFRAMES capability
atrac3: return appropriate error codes instead of -1
...
Conflicts:
libavcodec/atrac1.c
libavcodec/dca.c
libavformat/mov.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/dca.c')
-rw-r--r-- | libavcodec/dca.c | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/libavcodec/dca.c b/libavcodec/dca.c index 5cf5b2629a..37977e5c55 100644 --- a/libavcodec/dca.c +++ b/libavcodec/dca.c @@ -528,15 +528,15 @@ static int dca_parse_frame_header(DCAContext * s) s->sample_blocks = get_bits(&s->gb, 7) + 1; s->frame_size = get_bits(&s->gb, 14) + 1; if (s->frame_size < 95) - return -1; + return AVERROR_INVALIDDATA; s->amode = get_bits(&s->gb, 6); s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)]; if (!s->sample_rate) - return -1; + return AVERROR_INVALIDDATA; s->bit_rate_index = get_bits(&s->gb, 5); s->bit_rate = dca_bit_rates[s->bit_rate_index]; if (!s->bit_rate) - return -1; + return AVERROR_INVALIDDATA; s->downmix = get_bits(&s->gb, 1); s->dynrange = get_bits(&s->gb, 1); @@ -626,7 +626,7 @@ static int dca_subframe_header(DCAContext * s, int base_channel, int block_index int j, k; if (get_bits_left(&s->gb) < 0) - return -1; + return AVERROR_INVALIDDATA; if (!base_channel) { s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1; @@ -658,7 +658,7 @@ static int dca_subframe_header(DCAContext * s, int base_channel, int block_index else if (s->bitalloc_huffman[j] == 7) { av_log(s->avctx, AV_LOG_ERROR, "Invalid bit allocation index\n"); - return -1; + return AVERROR_INVALIDDATA; } else { s->bitalloc[j][k] = get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); @@ -667,7 +667,7 @@ static int dca_subframe_header(DCAContext * s, int base_channel, int block_index if (s->bitalloc[j][k] > 26) { // av_log(s->avctx,AV_LOG_DEBUG,"bitalloc index [%i][%i] too big (%i)\n", // j, k, s->bitalloc[j][k]); - return -1; + return AVERROR_INVALIDDATA; } } } @@ -685,7 +685,7 @@ static int dca_subframe_header(DCAContext * s, int base_channel, int block_index } if (get_bits_left(&s->gb) < 0) - return -1; + return AVERROR_INVALIDDATA; for (j = base_channel; j < s->prim_channels; j++) { const uint32_t *scale_table; @@ -723,7 +723,7 @@ static int dca_subframe_header(DCAContext * s, int base_channel, int block_index } if (get_bits_left(&s->gb) < 0) - return -1; + return AVERROR_INVALIDDATA; /* Scale factors for joint subband coding */ for (j = base_channel; j < s->prim_channels; j++) { @@ -1055,7 +1055,7 @@ static int decode_blockcode(int code, int levels, int *values) return 0; else { av_log(NULL, AV_LOG_ERROR, "ERROR: block code look-up failed\n"); - return -1; + return AVERROR_INVALIDDATA; } } #endif @@ -1096,7 +1096,7 @@ static int dca_subsubframe(DCAContext * s, int base_channel, int block_index) for (k = base_channel; k < s->prim_channels; k++) { if (get_bits_left(&s->gb) < 0) - return -1; + return AVERROR_INVALIDDATA; for (l = 0; l < s->vq_start_subband[k]; l++) { int m; @@ -1275,12 +1275,13 @@ static int dca_subframe_footer(DCAContext * s, int base_channel) static int dca_decode_block(DCAContext * s, int base_channel, int block_index) { + int ret; /* Sanity check */ if (s->current_subframe >= s->subframes) { av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i", s->current_subframe, s->subframes); - return -1; + return AVERROR_INVALIDDATA; } if (!s->current_subsubframe) { @@ -1288,16 +1289,16 @@ static int dca_decode_block(DCAContext * s, int base_channel, int block_index) av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\n"); #endif /* Read subframe header */ - if (dca_subframe_header(s, base_channel, block_index)) - return -1; + if ((ret = dca_subframe_header(s, base_channel, block_index))) + return ret; } /* Read subsubframe */ #ifdef TRACE av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\n"); #endif - if (dca_subsubframe(s, base_channel, block_index)) - return -1; + if ((ret = dca_subsubframe(s, base_channel, block_index))) + return ret; /* Update state */ s->current_subsubframe++; @@ -1310,8 +1311,8 @@ static int dca_decode_block(DCAContext * s, int base_channel, int block_index) av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\n"); #endif /* Read subframe footer */ - if (dca_subframe_footer(s, base_channel)) - return -1; + if ((ret = dca_subframe_footer(s, base_channel))) + return ret; } return 0; @@ -1354,7 +1355,7 @@ static int dca_convert_bitstream(const uint8_t * src, int src_size, uint8_t * ds flush_put_bits(&pb); return (put_bits_count(&pb) + 7) >> 3; default: - return -1; + return AVERROR_INVALIDDATA; } } @@ -1637,7 +1638,7 @@ static int dca_decode_frame(AVCodecContext * avctx, int lfe_samples; int num_core_channels = 0; - int i; + int i, ret; float *samples_flt = data; int16_t *samples_s16 = data; int out_size; @@ -1650,16 +1651,15 @@ static int dca_decode_frame(AVCodecContext * avctx, s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE); - if (s->dca_buffer_size == -1) { + if (s->dca_buffer_size == AVERROR_INVALIDDATA) { av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n"); - return -1; + return AVERROR_INVALIDDATA; } init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); - if (dca_parse_frame_header(s) < 0) { + if ((ret = dca_parse_frame_header(s)) < 0) { //seems like the frame is corrupt, try with the next one - *data_size=0; - return buf_size; + return ret; } //set AVCodec values with parsed data avctx->sample_rate = s->sample_rate; @@ -1669,7 +1669,10 @@ static int dca_decode_frame(AVCodecContext * avctx, s->profile = FF_PROFILE_DTS; for (i = 0; i < (s->sample_blocks / 8); i++) { - dca_decode_block(s, 0, i); + if ((ret = dca_decode_block(s, 0, i))) { + av_log(avctx, AV_LOG_ERROR, "error decoding block\n"); + return ret; + } } /* record number of core channels incase less than max channels are requested */ @@ -1725,7 +1728,10 @@ static int dca_decode_frame(AVCodecContext * avctx, dca_parse_audio_coding_header(s, s->xch_base_channel); for (i = 0; i < (s->sample_blocks / 8); i++) { - dca_decode_block(s, s->xch_base_channel, i); + if ((ret = dca_decode_block(s, s->xch_base_channel, i))) { + av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\n"); + continue; + } } s->xch_present = 1; @@ -1799,7 +1805,7 @@ static int dca_decode_frame(AVCodecContext * avctx, if (channels > !!s->lfe && s->channel_order_tab[channels - 1 - !!s->lfe] < 0) - return -1; + return AVERROR_INVALIDDATA; if (avctx->request_channels == 2 && s->prim_channels > 2) { channels = 2; @@ -1812,7 +1818,7 @@ static int dca_decode_frame(AVCodecContext * avctx, } } else { av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode); - return -1; + return AVERROR_INVALIDDATA; } if (avctx->channels != channels) { @@ -1824,7 +1830,7 @@ static int dca_decode_frame(AVCodecContext * avctx, out_size = 256 / 8 * s->sample_blocks * channels * av_get_bytes_per_sample(avctx->sample_fmt); if (*data_size < out_size) - return -1; + return AVERROR(EINVAL); *data_size = out_size; /* filter to get final output */ |