aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ac3dec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-03-23 02:42:56 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-03-23 02:42:56 +0100
commit4fa0e24736bff7d7fbdfb36ed578a1db166817d4 (patch)
tree3e74e32f82b02ff498320e07424d330473f44fd3 /libavcodec/ac3dec.c
parent4952afff75bc60df9c842bc248f1da8fe57e04a6 (diff)
parentee26abf2a4884bb56959bac8215758195776c553 (diff)
downloadffmpeg-4fa0e24736bff7d7fbdfb36ed578a1db166817d4.tar.gz
Merge remote-tracking branch 'newdev/master'
* newdev/master: (33 commits) Fix an infinite loop when RoQ encoded generated a frame with a size greater than the maximum valid size. Add kbdwin.o to AC3 decoder Detect byte-swapped AC-3 and support decoding it directly. cosmetics: indentation Always copy input data for AC3 decoder. ac3enc: make sym_quant() branch-free cosmetics: indentation Add a CPU flag for the Atom processor. id3v2: skip broken tags with invalid size id3v2: don't explicitly skip padding Make sure kbhit() is in conio.h fate: update wmv8-drm reference vc1: make P-frame deblock filter bit-exact. configure: Add the -D parameter to the dlltool command amr: Set the AVFMT_GENERIC_INDEX flag amr: Set the pkt->pos field properly to the start of the packet amr: Set the codec->bit_rate field based on the last packet rtsp: Specify unicast for TCP interleaved streams, too Set the correct target for mingw64 dlltool applehttp: Change the variable for stream position in seconds into int64_t ... Conflicts: ffmpeg.c ffplay.c libavcodec/ac3dec.c libavformat/avio.h libavformat/id3v2.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/ac3dec.c')
-rw-r--r--libavcodec/ac3dec.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 094b2615ff..7f12d9cba0 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -208,6 +208,11 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
}
s->downmixed = 1;
+ /* allocate context input buffer */
+ s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->input_buffer)
+ return AVERROR(ENOMEM);
+
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
}
@@ -1306,26 +1311,17 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
int blk, ch, err;
const uint8_t *channel_map;
const float *output[AC3_MAX_CHANNELS];
- // if it seems to be byte-swapped AC-3 (aka DNET)
- int is_swapped = buf_size >= 2 && AV_RB16(buf) == 0x770B;
-
- /* initialize the GetBitContext with the start of valid AC-3 Frame */
- if (is_swapped || avctx->error_recognition >= FF_ER_CAREFUL) {
- /* allocate context input buffer */
- if (!s->input_buffer)
- s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!s->input_buffer)
- return AVERROR(ENOMEM);
- /* copy input buffer to decoder context to avoid reading past the end
- of the buffer, which can be caused by a damaged input stream. */
- if (is_swapped) {
- int cnt = FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) >> 1;
- s->dsp.bswap16_buf((uint16_t *)s->input_buffer, (const uint16_t *)buf, cnt);
- } else
+ /* copy input buffer to decoder context to avoid reading past the end
+ of the buffer, which can be caused by a damaged input stream. */
+ if (buf_size >= 2 && AV_RB16(buf) == 0x770B) {
+ // seems to be byte-swapped AC-3
+ int cnt = FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) >> 1;
+ s->dsp.bswap16_buf((uint16_t *)s->input_buffer, (const uint16_t *)buf, cnt);
+ } else
memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE));
- buf = s->input_buffer;
- }
+ buf = s->input_buffer;
+ /* initialize the GetBitContext with the start of valid AC-3 Frame */
init_get_bits(&s->gbc, buf, buf_size * 8);
/* parse the syncinfo */