From 73b16198b6cab1cdafa46143aae7a69e10e130fd Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Thu, 5 Jan 2012 22:12:35 +0100 Subject: [PATCH 01/29] electronicarts: check bytes per sample for validity Prevents division by zero. --- libavformat/electronicarts.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index 0facc8afba..01ba479fac 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -434,6 +434,11 @@ static int ea_read_header(AVFormatContext *s, ea->audio_codec = 0; return 1; } + if (ea->bytes <= 0) { + av_log(s, AV_LOG_ERROR, "Invalid number of bytes per sample: %d\n", ea->bytes); + ea->audio_codec = CODEC_ID_NONE; + return 1; + } /* initialize the audio decoder stream */ st = avformat_new_stream(s, NULL); From b18a0cc781b791912549504ca8a257f35a151c5e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 20 Dec 2011 22:06:35 +0100 Subject: [PATCH 02/29] indeo5: Fix null pointer dereference. Bug found by: Oana Stratulat Signed-off-by: Janne Grunau --- libavcodec/ivi_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/ivi_common.c b/libavcodec/ivi_common.c index 9cec0a83a2..eedcd28ada 100644 --- a/libavcodec/ivi_common.c +++ b/libavcodec/ivi_common.c @@ -611,6 +611,9 @@ void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch) const int16_t *src = plane->bands[0].buf; uint32_t pitch = plane->bands[0].pitch; + if (!src) + return; + for (y = 0; y < plane->height; y++) { for (x = 0; x < plane->width; x++) dst[x] = av_clip_uint8(src[x] + 128); From be540e0cb3ea9f9c7ac26eb0c0b7249344298caa Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Fri, 6 Jan 2012 01:21:36 +0100 Subject: [PATCH 03/29] indeo3: check motion vectors for validity Fixes null pointer dereferences in fuzzed files found by Oana Stratulat. Signed-off-by: Janne Grunau --- libavcodec/indeo3.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c index 46efbd86d2..d2b01f469a 100644 --- a/libavcodec/indeo3.c +++ b/libavcodec/indeo3.c @@ -89,6 +89,7 @@ typedef struct Indeo3DecodeContext { const uint8_t *next_cell_data; const uint8_t *last_byte; const int8_t *mc_vectors; + unsigned num_vectors; ///< number of motion vectors in mc_vectors int16_t width, height; uint32_t frame_num; ///< current frame number (zero-based) @@ -764,10 +765,16 @@ static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx, break; case INTER_DATA: if (!curr_cell.tree) { /* MC tree INTER code */ + unsigned mv_idx; /* get motion vector index and setup the pointer to the mv set */ if (!ctx->need_resync) ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3]; - curr_cell.mv_ptr = &ctx->mc_vectors[*(ctx->next_cell_data++) << 1]; + mv_idx = *(ctx->next_cell_data++) << 1; + if (mv_idx >= ctx->num_vectors) { + av_log(avctx, AV_LOG_ERROR, "motion vector index out of range\n"); + return AVERROR_INVALIDDATA; + } + curr_cell.mv_ptr = &ctx->mc_vectors[mv_idx]; curr_cell.tree = 1; /* enter the VQ tree */ UPDATE_BITPOS(8); } else { /* VQ tree DATA code */ @@ -797,15 +804,22 @@ static int decode_plane(Indeo3DecodeContext *ctx, AVCodecContext *avctx, int32_t strip_width) { Cell curr_cell; - int num_vectors; + unsigned num_vectors; /* each plane data starts with mc_vector_count field, */ /* an optional array of motion vectors followed by the vq data */ num_vectors = bytestream_get_le32(&data); - ctx->mc_vectors = num_vectors ? data : 0; - + if (num_vectors > 256) { + av_log(ctx->avctx, AV_LOG_ERROR, + "Read invalid number of motion vectors %d\n", num_vectors); + return AVERROR_INVALIDDATA; + } if (num_vectors * 2 >= data_size) return AVERROR_INVALIDDATA; + + ctx->num_vectors = num_vectors; + ctx->mc_vectors = num_vectors ? data : 0; + /* init the bitreader */ init_get_bits(&ctx->gb, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3); ctx->skip_bits = 0; From 867f923df48f6dec76eeff9ba0444a0cb9ff0441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 6 Jan 2012 03:05:27 +0200 Subject: [PATCH 04/29] libavcodec: Move apply_param_change up above avcodec_decode_video2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is in preparation to calling it from avcodec_decode_video2. Signed-off-by: Martin Storsjö --- libavcodec/utils.c | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index c845a310cd..a1d2a01266 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -842,6 +842,47 @@ int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, return ret; } +static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) +{ + int size = 0; + const uint8_t *data; + uint32_t flags; + + if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) + return; + + data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size); + if (!data || size < 4) + return; + flags = bytestream_get_le32(&data); + size -= 4; + if (size < 4) /* Required for any of the changes */ + return; + if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { + avctx->channels = bytestream_get_le32(&data); + size -= 4; + } + if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { + if (size < 8) + return; + avctx->channel_layout = bytestream_get_le64(&data); + size -= 8; + } + if (size < 4) + return; + if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { + avctx->sample_rate = bytestream_get_le32(&data); + size -= 4; + } + if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { + if (size < 8) + return; + avctx->width = bytestream_get_le32(&data); + avctx->height = bytestream_get_le32(&data); + size -= 8; + } +} + int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt) @@ -923,47 +964,6 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa } #endif -static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) -{ - int size = 0; - const uint8_t *data; - uint32_t flags; - - if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) - return; - - data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size); - if (!data || size < 4) - return; - flags = bytestream_get_le32(&data); - size -= 4; - if (size < 4) /* Required for any of the changes */ - return; - if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { - avctx->channels = bytestream_get_le32(&data); - size -= 4; - } - if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { - if (size < 8) - return; - avctx->channel_layout = bytestream_get_le64(&data); - size -= 8; - } - if (size < 4) - return; - if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { - avctx->sample_rate = bytestream_get_le32(&data); - size -= 4; - } - if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { - if (size < 8) - return; - avctx->width = bytestream_get_le32(&data); - avctx->height = bytestream_get_le32(&data); - size -= 8; - } -} - int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, From c5d907b6b03ef431b9901fc9090887b03fd7a09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 6 Jan 2012 03:06:25 +0200 Subject: [PATCH 05/29] libavcodec: Handle param change side data in avcodec_decode_video2, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also call avcodec_set_dimensions on dimension param change packets. Signed-off-by: Martin Storsjö --- libavcodec/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a1d2a01266..2bc1dcf5da 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -879,6 +879,7 @@ static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) return; avctx->width = bytestream_get_le32(&data); avctx->height = bytestream_get_le32(&data); + avcodec_set_dimensions(avctx, avctx->width, avctx->height); size -= 8; } } @@ -894,6 +895,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi return -1; avctx->pkt = avpkt; + apply_param_change(avctx, avpkt); if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){ if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME) From 17aa02b9a112398f8d9f74dcb3db55c31e91c8fe Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 6 Jan 2012 03:07:31 +0200 Subject: [PATCH 06/29] interplayvideo: Handle changed video dimensions on the fly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/interplayvideo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c index db98bec9c5..724f5f1850 100644 --- a/libavcodec/interplayvideo.c +++ b/libavcodec/interplayvideo.c @@ -1019,9 +1019,6 @@ static av_cold int ipvideo_decode_init(AVCodecContext *avctx) dsputil_init(&s->dsp, avctx); - /* decoding map contains 4 bits of information per 8x8 block */ - s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); - s->current_frame.data[0] = s->last_frame.data[0] = s->second_last_frame.data[0] = NULL; @@ -1036,6 +1033,9 @@ static int ipvideo_decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; IpvideoContext *s = avctx->priv_data; + /* decoding map contains 4 bits of information per 8x8 block */ + s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); + /* compressed buffer needs to be large enough to at least hold an entire * decoding map */ if (buf_size < s->decoding_map_size) @@ -1096,6 +1096,6 @@ AVCodec ff_interplay_video_decoder = { .init = ipvideo_decode_init, .close = ipvideo_decode_end, .decode = ipvideo_decode_frame, - .capabilities = CODEC_CAP_DR1, + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_PARAM_CHANGE, .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE video"), }; From 75146b8828b8393807835942091d2d4a4bf9e2b1 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 6 Jan 2012 03:09:06 +0200 Subject: [PATCH 07/29] ipmovie: Add param change side data if the video dimensions have changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/ipmovie.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index bd5ec30016..b91196b34c 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -89,6 +89,7 @@ typedef struct IPMVEContext { int64_t video_pts; uint32_t palette[256]; int has_palette; + int changed; unsigned int audio_bits; unsigned int audio_channels; @@ -168,6 +169,10 @@ static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb, } } + if (s->changed) { + ff_add_param_change(pkt, 0, 0, 0, s->video_width, s->video_height); + s->changed = 0; + } pkt->pos= s->decode_map_chunk_offset; avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET); s->decode_map_chunk_offset = 0; @@ -223,6 +228,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, int first_color, last_color; int audio_flags; unsigned char r, g, b; + unsigned int width, height; /* see if there are any pending packets */ chunk_type = load_ipmovie_packet(s, pb, pkt); @@ -379,8 +385,16 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, chunk_type = CHUNK_BAD; break; } - s->video_width = AV_RL16(&scratch[0]) * 8; - s->video_height = AV_RL16(&scratch[2]) * 8; + width = AV_RL16(&scratch[0]) * 8; + height = AV_RL16(&scratch[2]) * 8; + if (width != s->video_width) { + s->video_width = width; + s->changed++; + } + if (height != s->video_height) { + s->video_height = height; + s->changed++; + } if (opcode_version < 2 || !AV_RL16(&scratch[6])) { s->video_bpp = 8; } else { From 52e9854a83a1030b3c9012aee4332fe0d71f9382 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 6 Jan 2012 18:14:24 -0500 Subject: [PATCH 08/29] tta: fix 24-bit decoding. Decode to the correct output buffer. --- libavcodec/tta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/tta.c b/libavcodec/tta.c index 7ec5435a06..bc83bfdf1d 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -314,7 +314,7 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data, // decode directly to output buffer for 24-bit sample format if (s->bps == 3) - s->decode_buffer = data; + s->decode_buffer = s->frame.data[0]; // init per channel states for (i = 0; i < s->channels; i++) { From d8b33a99897f1faa8036fbdb6a6d48af9c10730f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 6 Jan 2012 17:30:05 +0100 Subject: [PATCH 09/29] tta: fix off be 1 error in the end detection. Fixes use of uninitialized values. Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavformat/tta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/tta.c b/libavformat/tta.c index 37a359bf70..f361ba5188 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -125,7 +125,7 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) int size, ret; // FIXME! - if (c->currentframe > c->totalframes) + if (c->currentframe >= c->totalframes) return -1; size = st->index_entries[c->currentframe].size; From 4b4acc544f9b7b8bedaae4613913e140f4430aa8 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 6 Jan 2012 17:34:22 +0100 Subject: [PATCH 10/29] tta: Fix returned error code at EOF Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavformat/tta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/tta.c b/libavformat/tta.c index f361ba5188..6bf097975a 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -126,7 +126,7 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) // FIXME! if (c->currentframe >= c->totalframes) - return -1; + return AVERROR_EOF; size = st->index_entries[c->currentframe].size; From 96219141e2b2a71fde4dca5505325d21f7cc10b7 Mon Sep 17 00:00:00 2001 From: Vitor Sessak Date: Tue, 3 Jan 2012 21:25:59 +0100 Subject: [PATCH 11/29] mpegaudiodec: Use clearer pointer math Signed-off-by: Ronald S. Bultje --- libavcodec/mpegaudiodec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 1b50f9fd92..cd7b7f5053 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -1411,7 +1411,7 @@ static void compute_imdct(MPADecodeContext *s, GranuleDef *g, } for (j = mdct_long_end; j < sblimit; j++) { /* select frequency inversion */ - win = mdct_win[2] + ((4 * 36) & -(j & 1)); + win = mdct_win[2 + (4 & -(j & 1))]; out_ptr = sb_samples + j; for (i = 0; i < 6; i++) { From 34093ba0819c8f00f024a49cc2cebe0400f020d4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 5 Jan 2012 23:34:09 -0500 Subject: [PATCH 12/29] g722enc: split encoding into separate functions for trellis vs. no trellis --- libavcodec/g722enc.c | 53 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index 1eed784a72..470770c413 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -117,13 +117,12 @@ static inline int encode_low(const struct G722Band* state, int xlow) return (diff < 0 ? (i < 2 ? 63 : 33) : 61) - i; } -static int g722_encode_trellis(AVCodecContext *avctx, - uint8_t *dst, int buf_size, void *data) +static void g722_encode_trellis(G722Context *c, int trellis, + uint8_t *dst, int nb_samples, + const int16_t *samples) { - G722Context *c = avctx->priv_data; - const int16_t *samples = data; int i, j, k; - int frontier = 1 << avctx->trellis; + int frontier = 1 << trellis; struct TrellisNode **nodes[2]; struct TrellisNode **nodes_next[2]; int pathn[2] = {0, 0}, froze = -1; @@ -139,7 +138,7 @@ static int g722_encode_trellis(AVCodecContext *avctx, nodes[i][0]->state = c->band[i]; } - for (i = 0; i < buf_size; i++) { + for (i = 0; i < nb_samples >> 1; i++) { int xlow, xhigh; struct TrellisNode *next[2]; int heap_pos[2] = {0, 0}; @@ -271,8 +270,28 @@ static int g722_encode_trellis(AVCodecContext *avctx, } c->band[0] = nodes[0][0]->state; c->band[1] = nodes[1][0]->state; +} - return i; +static av_always_inline void encode_byte(G722Context *c, uint8_t *dst, + const int16_t *samples) +{ + int xlow, xhigh, ilow, ihigh; + filter_samples(c, samples, &xlow, &xhigh); + ihigh = encode_high(&c->band[1], xhigh); + ilow = encode_low (&c->band[0], xlow); + ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor * + ff_g722_high_inv_quant[ihigh] >> 10, ihigh); + ff_g722_update_low_predictor(&c->band[0], ilow >> 2); + *dst = ihigh << 6 | ilow; +} + +static void g722_encode_no_trellis(G722Context *c, + uint8_t *dst, int nb_samples, + const int16_t *samples) +{ + int i; + for (i = 0; i < nb_samples; i += 2) + encode_byte(c, dst++, &samples[i]); } static int g722_encode_frame(AVCodecContext *avctx, @@ -280,22 +299,16 @@ static int g722_encode_frame(AVCodecContext *avctx, { G722Context *c = avctx->priv_data; const int16_t *samples = data; - int i; + int nb_samples; + + nb_samples = buf_size * 2; if (avctx->trellis) - return g722_encode_trellis(avctx, dst, buf_size, data); + g722_encode_trellis(c, avctx->trellis, dst, nb_samples, samples); + else + g722_encode_no_trellis(c, dst, nb_samples, samples); - for (i = 0; i < buf_size; i++) { - int xlow, xhigh, ihigh, ilow; - filter_samples(c, &samples[2*i], &xlow, &xhigh); - ihigh = encode_high(&c->band[1], xhigh); - ilow = encode_low(&c->band[0], xlow); - ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor * - ff_g722_high_inv_quant[ihigh] >> 10, ihigh); - ff_g722_update_low_predictor(&c->band[0], ilow >> 2); - *dst++ = ihigh << 6 | ilow; - } - return i; + return buf_size; } AVCodec ff_adpcm_g722_encoder = { From 77c5b66cbec5a04c846b0dd3997c898146334b60 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 6 Jan 2012 15:32:44 -0500 Subject: [PATCH 13/29] g722enc: set frame_size, and also handle an odd number of input samples The fate reference is updated because the previous test skipped a sample in each encode() call due each input frame having an odd number of samples. --- libavcodec/g722enc.c | 38 ++++++++++++++++++++++++++++++++++++-- tests/ref/acodec/g722 | 8 ++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index 470770c413..ceb18b46db 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -32,6 +32,10 @@ #define FREEZE_INTERVAL 128 +/* This is an arbitrary value. Allowing insanely large values leads to strange + problems, so we limit it to a reasonable value */ +#define MAX_FRAME_SIZE 32768 + static av_cold int g722_encode_init(AVCodecContext * avctx) { G722Context *c = avctx->priv_data; @@ -56,6 +60,29 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) } } + if (avctx->frame_size) { + /* validate frame size */ + if (avctx->frame_size & 1 || avctx->frame_size > MAX_FRAME_SIZE) { + int new_frame_size; + + if (avctx->frame_size == 1) + new_frame_size = 2; + else if (avctx->frame_size > MAX_FRAME_SIZE) + new_frame_size = MAX_FRAME_SIZE; + else + new_frame_size = avctx->frame_size - 1; + + av_log(avctx, AV_LOG_WARNING, "Requested frame size is not " + "allowed. Using %d instead of %d\n", new_frame_size, + avctx->frame_size); + avctx->frame_size = new_frame_size; + } + } else { + /* This is arbitrary. We use 320 because it's 20ms @ 16kHz, which is + a common packet size for VoIP applications */ + avctx->frame_size = 320; + } + return 0; } @@ -301,14 +328,20 @@ static int g722_encode_frame(AVCodecContext *avctx, const int16_t *samples = data; int nb_samples; - nb_samples = buf_size * 2; + nb_samples = avctx->frame_size - (avctx->frame_size & 1); if (avctx->trellis) g722_encode_trellis(c, avctx->trellis, dst, nb_samples, samples); else g722_encode_no_trellis(c, dst, nb_samples, samples); - return buf_size; + /* handle last frame with odd frame_size */ + if (nb_samples < avctx->frame_size) { + int16_t last_samples[2] = { samples[nb_samples], samples[nb_samples] }; + encode_byte(c, &dst[nb_samples >> 1], last_samples); + } + + return (avctx->frame_size + 1) >> 1; } AVCodec ff_adpcm_g722_encoder = { @@ -319,6 +352,7 @@ AVCodec ff_adpcm_g722_encoder = { .init = g722_encode_init, .close = g722_encode_close, .encode = g722_encode_frame, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME, .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, }; diff --git a/tests/ref/acodec/g722 b/tests/ref/acodec/g722 index a1fc72a3bb..6ea492ae45 100644 --- a/tests/ref/acodec/g722 +++ b/tests/ref/acodec/g722 @@ -1,4 +1,4 @@ -b380355e0360b4e50ee78f33fd60a0f5 *./tests/data/acodec/g722.wav -47991 ./tests/data/acodec/g722.wav -82fdd5bb059336e0550de7ba5947c5bb *./tests/data/g722.acodec.out.wav -stddev: 8860.44 PSNR: 17.38 MAXDIFF:33814 bytes: 191732/ 1058400 +1975cc4a3521e374b33ae042e182f6b6 *./tests/data/acodec/g722.wav +48053 ./tests/data/acodec/g722.wav +ade04cdcf249e6946395f109b077dd62 *./tests/data/g722.acodec.out.wav +stddev: 8841.24 PSNR: 17.40 MAXDIFF:36225 bytes: 191980/ 1058400 From cf1a259ad6eb7ad80fce1f2c2b86fda846e401c2 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 6 Jan 2012 16:01:07 -0500 Subject: [PATCH 14/29] g722enc: validate AVCodecContext.trellis --- libavcodec/g722enc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c index ceb18b46db..1cb0070649 100644 --- a/libavcodec/g722enc.c +++ b/libavcodec/g722enc.c @@ -36,6 +36,11 @@ problems, so we limit it to a reasonable value */ #define MAX_FRAME_SIZE 32768 +/* We clip the value of avctx->trellis to prevent data type overflows and + undefined behavior. Using larger values is insanely slow anyway. */ +#define MIN_TRELLIS 0 +#define MAX_TRELLIS 16 + static av_cold int g722_encode_init(AVCodecContext * avctx) { G722Context *c = avctx->priv_data; @@ -83,6 +88,17 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) avctx->frame_size = 320; } + if (avctx->trellis) { + /* validate trellis */ + if (avctx->trellis < MIN_TRELLIS || avctx->trellis > MAX_TRELLIS) { + int new_trellis = av_clip(avctx->trellis, MIN_TRELLIS, MAX_TRELLIS); + av_log(avctx, AV_LOG_WARNING, "Requested trellis value is not " + "allowed. Using %d instead of %d\n", new_trellis, + avctx->trellis); + avctx->trellis = new_trellis; + } + } + return 0; } From c262404d9886f1d2a85f57dbb6eaac4579a8147a Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Sat, 7 Jan 2012 09:29:30 -0800 Subject: [PATCH 15/29] Change the recent h264_mp4toannexb bitstream filter test to output to an elementary stream rather than a program stream. Signed-off-by: Ronald S. Bultje --- tests/fate/h264.mak | 2 +- tests/ref/fate/h264-bsf-mp4toannexb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak index 7c999fe54e..e33ffa58f2 100644 --- a/tests/fate/h264.mak +++ b/tests/fate/h264.mak @@ -356,4 +356,4 @@ fate-h264-conformance-sva_nl2_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conf fate-h264-interlace-crop: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264/interlaced_crop.mp4 -vframes 3 fate-h264-lossless: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264/lossless.h264 fate-h264-extreme-plane-pred: CMD = framemd5 -vsync 0 -i $(SAMPLES)/h264/extreme-plane-pred.h264 -fate-h264-bsf-mp4toannexb: CMD = md5 -i $(SAMPLES)/h264/interlaced_crop.mp4 -vcodec copy -bsf h264_mp4toannexb -f mpeg +fate-h264-bsf-mp4toannexb: CMD = md5 -i $(SAMPLES)/h264/interlaced_crop.mp4 -vcodec copy -bsf h264_mp4toannexb -f h264 diff --git a/tests/ref/fate/h264-bsf-mp4toannexb b/tests/ref/fate/h264-bsf-mp4toannexb index 6395f2437a..2049f39701 100644 --- a/tests/ref/fate/h264-bsf-mp4toannexb +++ b/tests/ref/fate/h264-bsf-mp4toannexb @@ -1 +1 @@ -503d34ff458a86387ab349c31726f19a +5f04c27cc6ee8625fe2405fb0f7da9a3 From f93843e9a05b4af618434cc271ecd9592c1354ae Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Sat, 7 Jan 2012 09:29:33 -0800 Subject: [PATCH 16/29] FATE: update xxan-wc4 test to a sample with more code coverage. The previous sample used for this test only contained type 0 frames. Replace it with a sample that also features type 1 frames. Code coverage: libavcodec/xxan.c: 72% -> 89% Signed-off-by: Ronald S. Bultje --- tests/fate/video.mak | 2 +- tests/ref/fate/xxan-wc4 | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/fate/video.mak b/tests/fate/video.mak index bae51d6d62..01dd306d1a 100644 --- a/tests/fate/video.mak +++ b/tests/fate/video.mak @@ -186,4 +186,4 @@ FATE_TESTS += fate-yop fate-yop: CMD = framecrc -i $(SAMPLES)/yop/test1.yop -pix_fmt rgb24 -an FATE_TESTS += fate-xxan-wc4 -fate-xxan-wc4: CMD = framecrc -i $(SAMPLES)/wc4-xan/wc4_2.avi -an -vframes 10 +fate-xxan-wc4: CMD = framecrc -i $(SAMPLES)/wc4-xan/wc4trailer-partial.avi -an diff --git a/tests/ref/fate/xxan-wc4 b/tests/ref/fate/xxan-wc4 index d31fbb697c..7fede0afc6 100644 --- a/tests/ref/fate/xxan-wc4 +++ b/tests/ref/fate/xxan-wc4 @@ -1,10 +1,21 @@ -0, 0, 79360, 0x877eb3ed -0, 6000, 79360, 0x9ff8707c -0, 12000, 79360, 0x144dec86 -0, 18000, 79360, 0x56d59588 -0, 24000, 79360, 0x2d20f8ce -0, 30000, 79360, 0x1a752c42 -0, 36000, 79360, 0x85705730 -0, 42000, 79360, 0xddea3741 -0, 48000, 79360, 0x46448efd -0, 54000, 79360, 0x27186e2b +0, 0, 79360, 0x3b0a7d1b +0, 6000, 79360, 0x740842c3 +0, 12000, 79360, 0x85160167 +0, 18000, 79360, 0xaf510e92 +0, 24000, 79360, 0x8e290bec +0, 30000, 79360, 0x51e981b0 +0, 36000, 79360, 0x16e52c60 +0, 42000, 79360, 0x66e1e60a +0, 48000, 79360, 0x40fa58f6 +0, 54000, 79360, 0x00388edd +0, 60000, 79360, 0xc74f95bf +0, 66000, 79360, 0xf446a3fd +0, 72000, 79360, 0x27b5eb60 +0, 78000, 79360, 0xea9266a2 +0, 84000, 79360, 0x7b6a7907 +0, 90000, 79360, 0x2be7d946 +0, 96000, 79360, 0x61881ee4 +0, 102000, 79360, 0x9214bd4f +0, 108000, 79360, 0xeb294afe +0, 114000, 79360, 0xc861ad55 +0, 120000, 79360, 0x3d3b6220 From 9689a1af6db1d0acdaad221a138e5c43ebc64ddc Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Sat, 7 Jan 2012 09:29:34 -0800 Subject: [PATCH 17/29] FATE: indeo4 video decoder test. Code coverage: libavcodec/indeo4.c: 0% -> 78% Signed-off-by: Ronald S. Bultje --- tests/fate/indeo.mak | 3 ++ tests/ref/fate/indeo4 | 100 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/ref/fate/indeo4 diff --git a/tests/fate/indeo.mak b/tests/fate/indeo.mak index df07392790..36bf21bd8f 100644 --- a/tests/fate/indeo.mak +++ b/tests/fate/indeo.mak @@ -4,5 +4,8 @@ fate-indeo2: CMD = framecrc -i $(SAMPLES)/rt21/VPAR0026.AVI FATE_TESTS += fate-indeo3 fate-indeo3: CMD = framecrc -i $(SAMPLES)/iv32/cubes.mov +FATE_TESTS += fate-indeo4 +fate-indeo4: CMD = framecrc -i $(SAMPLES)/iv41/indeo41-partial.avi -an + FATE_TESTS += fate-indeo5 fate-indeo5: CMD = framecrc -i $(SAMPLES)/iv50/Educ_Movie_DeadlyForce.avi -an diff --git a/tests/ref/fate/indeo4 b/tests/ref/fate/indeo4 new file mode 100644 index 0000000000..0f088ec7d9 --- /dev/null +++ b/tests/ref/fate/indeo4 @@ -0,0 +1,100 @@ +0, 0, 86400, 0x98f5e422 +0, 6000, 86400, 0x1864cb06 +0, 12000, 86400, 0xb09532ef +0, 18000, 86400, 0x3cd3dcdc +0, 24000, 86400, 0xe738847f +0, 30000, 86400, 0xc9b13afb +0, 36000, 86400, 0x5005d035 +0, 42000, 86400, 0x22f63e17 +0, 48000, 86400, 0x93391f02 +0, 54000, 86400, 0x264830fd +0, 60000, 86400, 0x8fff9f5f +0, 66000, 86400, 0x524997fe +0, 72000, 86400, 0x54e330f9 +0, 78000, 86400, 0x1d766a22 +0, 84000, 86400, 0x683a70ac +0, 90000, 86400, 0x553b7b3d +0, 96000, 86400, 0x822c79bc +0, 102000, 86400, 0xe1087a1c +0, 108000, 86400, 0xff397595 +0, 114000, 86400, 0x1b6b7717 +0, 120000, 86400, 0x6c5275c1 +0, 126000, 86400, 0x4e6a7189 +0, 132000, 86400, 0x285c6eba +0, 138000, 86400, 0xce647227 +0, 144000, 86400, 0xa0d07b1c +0, 150000, 86400, 0x5b567861 +0, 156000, 86400, 0x105873ec +0, 162000, 86400, 0x59267fa0 +0, 168000, 86400, 0xaeac839f +0, 174000, 86400, 0x2faf7402 +0, 180000, 86400, 0xc8547a30 +0, 186000, 86400, 0x3d357d49 +0, 192000, 86400, 0x75db6d6c +0, 198000, 86400, 0x9fbf68e9 +0, 204000, 86400, 0x56a64d26 +0, 210000, 86400, 0xce9e1f43 +0, 216000, 86400, 0xa4d7fddc +0, 222000, 86400, 0x3e20d77c +0, 228000, 86400, 0x4680661d +0, 234000, 86400, 0xf1b20af3 +0, 240000, 86400, 0xb79d8045 +0, 246000, 86400, 0x9479fc8a +0, 252000, 86400, 0x232965c3 +0, 258000, 86400, 0xd18bca17 +0, 264000, 86400, 0xb9064249 +0, 270000, 86400, 0xcc48ab34 +0, 276000, 86400, 0xe25018cd +0, 282000, 86400, 0x8da489ee +0, 288000, 86400, 0x90de0fc1 +0, 294000, 86400, 0x2428dcee +0, 300000, 86400, 0x4316e1ae +0, 306000, 86400, 0x2b25e54c +0, 312000, 86400, 0x736ce020 +0, 318000, 86400, 0x9a6be09a +0, 324000, 86400, 0x23bddbcd +0, 330000, 86400, 0x9368e465 +0, 336000, 86400, 0x1ae9bb87 +0, 342000, 86400, 0x4e591f32 +0, 348000, 86400, 0xba1bf9dc +0, 354000, 86400, 0x07f0aa60 +0, 360000, 86400, 0xf5a2cfa2 +0, 366000, 86400, 0xcba5fc18 +0, 372000, 86400, 0x858c0cfe +0, 378000, 86400, 0xac73ecd4 +0, 384000, 86400, 0xf41bf03c +0, 390000, 86400, 0x928ed146 +0, 396000, 86400, 0x9ff5990a +0, 402000, 86400, 0xc2fabc3d +0, 408000, 86400, 0x94af87a3 +0, 414000, 86400, 0x9bae514c +0, 420000, 86400, 0xe0da267a +0, 426000, 86400, 0x1d40f55c +0, 432000, 86400, 0xe6173b68 +0, 438000, 86400, 0x1445490d +0, 444000, 86400, 0x8d8753c1 +0, 450000, 86400, 0xe5a7779d +0, 456000, 86400, 0x3cfc66ef +0, 462000, 86400, 0xa5d45608 +0, 468000, 86400, 0x62f17be1 +0, 474000, 86400, 0xa64c84d3 +0, 480000, 86400, 0xf98162f0 +0, 486000, 86400, 0x0db77d9f +0, 492000, 86400, 0x0f0cbac9 +0, 498000, 86400, 0xb9934e97 +0, 504000, 86400, 0x7f8fa248 +0, 510000, 86400, 0xdfd96768 +0, 516000, 86400, 0x81b07919 +0, 522000, 86400, 0x66c11e9f +0, 528000, 86400, 0xd86eb114 +0, 534000, 86400, 0x67f20c1f +0, 540000, 86400, 0x66915de5 +0, 546000, 86400, 0x2b8aa76f +0, 552000, 86400, 0x85b5a3d2 +0, 558000, 86400, 0x80d29ed6 +0, 564000, 86400, 0x4d508e2c +0, 570000, 86400, 0x0d407374 +0, 576000, 86400, 0xd4068016 +0, 582000, 86400, 0x6ffab98f +0, 588000, 86400, 0x2360903d +0, 594000, 86400, 0x470e04a0 From 2907f88aeebabeada5ba4a2f2baab2153a9de0b2 Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Sat, 7 Jan 2012 09:29:32 -0800 Subject: [PATCH 18/29] FATE test: BMV demuxer and associated video and audio decoders. Code coverage: libavcodec/bmv.c: 0% -> 75% libavformat/bmv.c: 0% -> 85% Signed-off-by: Ronald S. Bultje --- tests/fate/demux.mak | 3 +++ tests/ref/fate/bmv | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/ref/fate/bmv diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak index 6202346c1e..5582492e10 100644 --- a/tests/fate/demux.mak +++ b/tests/fate/demux.mak @@ -10,6 +10,9 @@ fate-bink-demux: CMD = crc -i $(SAMPLES)/bink/Snd0a7d9b58.dee -vn -acodec copy FATE_TESTS += fate-bink-demux-video fate-bink-demux-video: CMD = framecrc -i $(SAMPLES)/bink/hol2br.bik +FATE_TESTS += fate-bmv +fate-bmv: CMD = framecrc -i $(SAMPLES)/bmv/SURFING-partial.BMV -pix_fmt rgb24 + FATE_TESTS += fate-caf fate-caf: CMD = crc -i $(SAMPLES)/caf/caf-pcm16.caf diff --git a/tests/ref/fate/bmv b/tests/ref/fate/bmv new file mode 100644 index 0000000000..4e461650e8 --- /dev/null +++ b/tests/ref/fate/bmv @@ -0,0 +1,42 @@ +0, 0, 823680, 0xddb8a306 +1, 0, 7424, 0x18540b36 +0, 7500, 823680, 0xa95375c8 +1, 7576, 7296, 0x5acd2484 +0, 15000, 823680, 0xa95375c8 +1, 15020, 7424, 0xa1bc5c5a +0, 22500, 823680, 0xb6f78afe +1, 22596, 7296, 0x71a02ad1 +0, 30000, 823680, 0xb6f78afe +1, 30041, 7424, 0x09cc32f2 +0, 37500, 823680, 0x45b9c8f0 +1, 37616, 7296, 0xa3451726 +0, 45000, 823680, 0x45b9c8f0 +1, 45061, 7296, 0x1eb40a18 +0, 52500, 823680, 0x7653d8e9 +1, 52506, 7424, 0xc55a2acf +0, 60000, 823680, 0x7653d8e9 +1, 60082, 7296, 0x5b9fad3f +0, 67500, 823680, 0xf1e2fd73 +1, 67527, 7424, 0xea651ae7 +0, 75000, 823680, 0xf1e2fd73 +1, 75102, 7296, 0x2bd5ddb6 +0, 82500, 823680, 0x6d2deab3 +1, 82547, 7424, 0xde4243b4 +0, 90000, 823680, 0x6d2deab3 +1, 90122, 7296, 0x358806d3 +0, 97500, 823680, 0x37fd33ce +1, 97567, 7296, 0x511a144e +0, 105000, 823680, 0x37fd33ce +1, 105012, 7424, 0x887a3e84 +0, 112500, 823680, 0x0a8e0ab9 +1, 112588, 7296, 0xfeae2a0c +0, 120000, 823680, 0x0a8e0ab9 +1, 120033, 7424, 0xa4ea5d22 +0, 127500, 823680, 0x991bb2b0 +1, 127608, 7296, 0xb3adf7fa +0, 135000, 823680, 0x991bb2b0 +1, 135053, 7424, 0xce995dcc +0, 142500, 823680, 0xb8397c8c +1, 142629, 7296, 0x5b4cf574 +0, 150000, 823680, 0xb8397c8c +1, 150073, 7296, 0x8a70eaf0 From 49a2aebc0013706f63720246530095112d5d30ae Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 7 Jan 2012 17:31:31 +0000 Subject: [PATCH 19/29] vqf: recognize more metadata chunks Do not create tags for non-char chunks. Create readable tag for DSIZ chunk. Signed-off-by: Ronald S. Bultje --- libavformat/vqf.c | 80 ++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/libavformat/vqf.c b/libavformat/vqf.c index 3e79299362..4f8f07c919 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -24,6 +24,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/dict.h" #include "libavutil/mathematics.h" +#include "riff.h" typedef struct VqfContext { int frame_bit_len; @@ -45,11 +46,11 @@ static int vqf_probe(AVProbeData *probe_packet) return AVPROBE_SCORE_MAX/2; } -static void add_metadata(AVFormatContext *s, const char *tag, +static void add_metadata(AVFormatContext *s, uint32_t tag, unsigned int tag_len, unsigned int remaining) { int len = FFMIN(tag_len, remaining); - char *buf; + char *buf, key[5] = {0}; if (len == UINT_MAX) return; @@ -59,9 +60,32 @@ static void add_metadata(AVFormatContext *s, const char *tag, return; avio_read(s->pb, buf, len); buf[len] = 0; - av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL); + AV_WL32(key, tag); + av_dict_set(&s->metadata, key, buf, AV_DICT_DONT_STRDUP_VAL); } +static const AVMetadataConv vqf_metadata_conv[] = { + { "(c) ", "copyright" }, + { "ARNG", "arranger" }, + { "AUTH", "author" }, + { "BAND", "band" }, + { "CDCT", "conductor" }, + { "COMT", "comment" }, + { "FILE", "filename" }, + { "GENR", "genre" }, + { "LABL", "publisher" }, + { "MUSC", "composer" }, + { "NAME", "title" }, + { "NOTE", "note" }, + { "PROD", "producer" }, + { "PRSN", "personnel" }, + { "REMX", "remixer" }, + { "SING", "singer" }, + { "TRCK", "track" }, + { "WORD", "words" }, + { 0 }, +}; + static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) { VqfContext *c = s->priv_data; @@ -110,41 +134,25 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->bit_rate = read_bitrate*1000; break; - case MKTAG('N','A','M','E'): - add_metadata(s, "title" , len, header_size); + case MKTAG('D','S','I','Z'): // size of compressed data + { + char buf[8] = {0}; + int size = avio_rb32(s->pb); + + snprintf(buf, sizeof(buf), "%d", size); + av_dict_set(&s->metadata, "size", buf, 0); + } break; - case MKTAG('(','c',')',' '): - add_metadata(s, "copyright", len, header_size); - break; - case MKTAG('A','U','T','H'): - add_metadata(s, "author" , len, header_size); - break; - case MKTAG('A','L','B','M'): - add_metadata(s, "album" , len, header_size); - break; - case MKTAG('T','R','C','K'): - add_metadata(s, "track" , len, header_size); - break; - case MKTAG('C','O','M','T'): - add_metadata(s, "comment" , len, header_size); - break; - case MKTAG('F','I','L','E'): - add_metadata(s, "filename" , len, header_size); - break; - case MKTAG('D','S','I','Z'): - add_metadata(s, "size" , len, header_size); - break; - case MKTAG('D','A','T','E'): - add_metadata(s, "date" , len, header_size); - break; - case MKTAG('G','E','N','R'): - add_metadata(s, "genre" , len, header_size); + case MKTAG('Y','E','A','R'): // recording date + case MKTAG('E','N','C','D'): // compression date + case MKTAG('E','X','T','R'): // reserved + case MKTAG('_','Y','M','H'): // reserved + case MKTAG('_','N','T','T'): // reserved + case MKTAG('_','I','D','3'): // reserved for ID3 tags + avio_skip(s->pb, FFMIN(len, header_size)); break; default: - av_log(s, AV_LOG_ERROR, "Unknown chunk: %c%c%c%c\n", - ((char*)&chunk_tag)[0], ((char*)&chunk_tag)[1], - ((char*)&chunk_tag)[2], ((char*)&chunk_tag)[3]); - avio_skip(s->pb, FFMIN(len, header_size)); + add_metadata(s, chunk_tag, len, header_size); break; } @@ -201,6 +209,8 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->extradata_size = 12; memcpy(st->codec->extradata, comm_chunk, 12); + ff_metadata_conv_ctx(s, NULL, vqf_metadata_conv); + return 0; } From 15f073ee6d7ae78acb7195fa12a64e621173e98b Mon Sep 17 00:00:00 2001 From: Mike Melanson Date: Sat, 7 Jan 2012 09:29:35 -0800 Subject: [PATCH 20/29] FATE: xmv-demux test; exercise the XMV demuxer without decoding the perceptual codecs inside. Code coverage: libavformat/xmv.c: 3% -> 91% Signed-off-by: Ronald S. Bultje --- tests/fate/demux.mak | 3 + tests/ref/fate/xmv-demux | 181 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 tests/ref/fate/xmv-demux diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak index 5582492e10..1e7d781e3c 100644 --- a/tests/fate/demux.mak +++ b/tests/fate/demux.mak @@ -81,3 +81,6 @@ fate-siff: CMD = framecrc -i $(SAMPLES)/SIFF/INTRO_B.VB -t 3 -pix_fmt rgb24 FATE_TESTS += fate-westwood-aud fate-westwood-aud: CMD = md5 -i $(SAMPLES)/westwood-aud/excellent.aud -f s16le + +FATE_TESTS += fate-xmv-demux +fate-xmv-demux: CMD = framecrc -i $(SAMPLES)/xmv/logos1p.fmv -vcodec copy -acodec copy diff --git a/tests/ref/fate/xmv-demux b/tests/ref/fate/xmv-demux new file mode 100644 index 0000000000..887b855d74 --- /dev/null +++ b/tests/ref/fate/xmv-demux @@ -0,0 +1,181 @@ +0, 0, 1508, 0xefceba48 +1, 0, 5976, 0xfa2c2db9 +1, 10841, 5976, 0x256b935c +1, 21682, 5976, 0xa78a9563 +1, 32522, 5976, 0x4ea056f4 +1, 43363, 5976, 0xda772d8d +1, 54204, 5976, 0xafacf7c9 +0, 57600, 108, 0x06713c96 +0, 61200, 952, 0xd306df7e +0, 64800, 2312, 0xaf316585 +1, 65045, 5976, 0xdeb003f4 +0, 68400, 3872, 0xfc1c527c +0, 72000, 20, 0xaffc0edd +0, 75600, 6600, 0xe1b66c7f +1, 75886, 2016, 0xa7380d36 +0, 79200, 6868, 0xd5b3f631 +1, 79543, 2016, 0xbc090bac +0, 82800, 8420, 0xf70ee33b +1, 83200, 2016, 0x6f8c164c +0, 86400, 13144, 0x9a54ef39 +1, 86857, 2016, 0x13b80e28 +0, 90000, 6340, 0xe55bf555 +1, 90514, 2016, 0xd40ff863 +0, 93600, 3736, 0x0b23f89f +1, 94171, 2016, 0x4d530ed7 +0, 97200, 2624, 0x79e2e451 +1, 97829, 2160, 0x0fbc37eb +0, 100800, 1860, 0x63886f11 +1, 101747, 13824, 0x82fb2602 +0, 104400, 1244, 0x74594601 +0, 108000, 564, 0xf4561dfb +0, 111600, 80, 0xbf8e2e30 +0, 115200, 20, 0xa0990c29 +1, 126824, 13824, 0x08771caf +1, 151902, 13824, 0xdf7d4a65 +1, 176980, 13896, 0x24bf3f47 +1, 202188, 3600, 0x9ad26b9f +1, 208718, 3600, 0x8c666fd6 +1, 215249, 3600, 0x305c6ca1 +1, 221780, 3600, 0x48b04e1e +0, 223200, 104, 0x12413980 +0, 226800, 796, 0x2e698ed3 +1, 228310, 3600, 0x8c915935 +0, 230400, 1808, 0x8b3e6e5e +0, 234000, 4712, 0xdbd51737 +1, 234841, 3600, 0xa8f45e01 +0, 237600, 5548, 0xee9c831c +0, 241200, 6152, 0x9c18ccc1 +1, 241371, 3816, 0xc64cc5ed +0, 244800, 6452, 0x7860462a +1, 248294, 1944, 0x0ac2e3f1 +0, 248400, 6676, 0xe1b1c9e4 +1, 251820, 1944, 0x2197dccd +0, 252000, 10904, 0x0bded7b7 +1, 255347, 1944, 0x0c02e77f +0, 255600, 12844, 0xe6d16cff +1, 258873, 1944, 0x675ee06a +0, 259200, 10920, 0xe114c46b +1, 262400, 2160, 0x0d803a8b +0, 262800, 5952, 0xb7464634 +1, 266318, 6696, 0xa7a0dfea +0, 266400, 4732, 0x2fa2e36d +0, 270000, 2592, 0xf54ddd57 +0, 273600, 1516, 0x4a1cd4d5 +0, 277200, 864, 0x49889afc +1, 278465, 6696, 0x59aa3145 +0, 280800, 468, 0x3932e6a4 +0, 284400, 116, 0x2b8341e6 +0, 288000, 16, 0x6a3109cf +1, 290612, 6696, 0x69be4d78 +1, 302759, 6696, 0x64064c67 +1, 314906, 6696, 0xc8536f98 +1, 327053, 6696, 0xc0ce5199 +1, 339200, 6768, 0x3b275c58 +1, 351478, 8856, 0x90e5b37c +0, 360000, 1508, 0xefceba48 +1, 367543, 8856, 0x86b33366 +1, 383608, 8856, 0x19e18797 +1, 399673, 8856, 0x0a0c7fbd +1, 415739, 8928, 0x4a9b2d42 +0, 417600, 100, 0x45023894 +0, 421200, 948, 0xa65ed345 +0, 424800, 2808, 0xd7285746 +0, 428400, 5372, 0x05794175 +1, 431935, 1512, 0xed8b3f4b +0, 432000, 11596, 0x8636eca7 +1, 434678, 1512, 0xa27d3891 +0, 435600, 11524, 0xe1f39be3 +1, 437420, 1512, 0xb0f13eb6 +0, 439200, 23392, 0xab053f05 +1, 440163, 1656, 0xe5a98324 +0, 442800, 4560, 0x03197d07 +1, 443167, 2232, 0x15445433 +0, 446400, 4440, 0x1cc361a2 +1, 447216, 2232, 0x5cb348a9 +0, 450000, 23688, 0x16030634 +1, 451265, 2232, 0xf10347da +0, 453600, 16132, 0xf0eca799 +1, 455314, 2448, 0x3e16a175 +0, 457200, 29896, 0x0c0988ea +1, 459755, 2520, 0x17e3ca2b +0, 460800, 19956, 0x0093aa0b +1, 464327, 1944, 0x35c2de84 +0, 464400, 16392, 0x8829a9ca +1, 467853, 1944, 0x55b4db40 +0, 468000, 16772, 0x9a4a546d +1, 471380, 2088, 0xdaae14b2 +0, 471600, 8920, 0xcd8ca203 +1, 475167, 1944, 0x92ccd37f +0, 475200, 9632, 0x53c1d37b +1, 478694, 1944, 0x70efede1 +0, 478800, 8976, 0xfe4da2cc +1, 482220, 1944, 0x7601d304 +0, 482400, 6680, 0x35348fe0 +1, 485747, 1944, 0x3922ebc2 +0, 486000, 9228, 0xcbf62b0c +1, 489273, 2160, 0xde462f2e +0, 489600, 5108, 0xd1d88511 +1, 493192, 1872, 0x467ac1d2 +0, 493200, 10016, 0xaff4b2b2 +1, 496588, 1872, 0xa1e4cd43 +0, 496800, 7468, 0x23e81ab8 +1, 499984, 1872, 0x1dceccc6 +0, 500400, 4172, 0x253cd05b +1, 503380, 1872, 0x2bbad2a5 +0, 504000, 8188, 0x7ede743f +1, 506776, 1872, 0xc603d44d +0, 507600, 2884, 0x2dec55a3 +1, 510171, 1872, 0x1b4cc261 +0, 511200, 3900, 0xd0666a18 +1, 513567, 1872, 0x10edd6cf +0, 514800, 2996, 0x9cc99b8c +1, 516963, 2376, 0xecdb9d61 +0, 518400, 2156, 0xae612776 +1, 521273, 2592, 0x5559eced +0, 522000, 3988, 0x0d2c9992 +0, 525600, 1512, 0x6281fc00 +1, 525976, 2592, 0x8848dfc7 +0, 529200, 6544, 0xb75c2562 +1, 530678, 2592, 0x4ca2d7da +0, 532800, 4108, 0xfb21efc9 +1, 535380, 2592, 0x285fd7e6 +0, 536400, 1096, 0x85922a37 +0, 540000, 9740, 0xe57d7647 +1, 540082, 2592, 0x2717e404 +0, 543600, 416, 0x61c2ea02 +1, 544784, 2592, 0xf106111a +0, 547200, 336, 0x1dc5ac1c +1, 549486, 2592, 0xd7d01119 +0, 550800, 204, 0x16f57017 +1, 554188, 2592, 0x550cfeda +0, 554400, 112, 0x78374234 +0, 558000, 40, 0x6cb21985 +1, 558890, 2592, 0x47ad00c4 +1, 563592, 2592, 0x39bbf306 +1, 568294, 3240, 0x69addfce +1, 574171, 21384, 0x254f63e0 +1, 612963, 21456, 0x2f7a9859 +0, 615600, 14420, 0x53324ca4 +0, 619200, 40, 0x10971420 +1, 651886, 37512, 0x6e962928 +1, 719935, 2736, 0x1dc91c69 +0, 720000, 24904, 0x15574f7e +1, 724898, 2736, 0x023434fd +1, 729861, 2736, 0x906f1541 +0, 734400, 1908, 0xccb2dd3c +1, 734824, 2736, 0x85a31102 +0, 738000, 4676, 0xbfa42b7e +1, 739788, 3024, 0x9296a5f3 +0, 741600, 3600, 0x87c9dc58 +0, 745200, 8184, 0x504a8e65 +1, 745273, 1944, 0x7bf4dedc +0, 748800, 9636, 0x2efb3006 +1, 748800, 1944, 0x4196c404 +1, 752327, 1944, 0xcda97c7a +0, 752400, 9580, 0x0fb6f4e8 +1, 755853, 1944, 0x5f4922b2 +0, 756000, 7840, 0xe996f564 +1, 759380, 2088, 0x37dfc157 +0, 759600, 4208, 0xe9c2fba2 +0, 763200, 556, 0x3f1e077c From 07837e4158f8cf478f5b270d6027af2b13ca1780 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 30 Dec 2011 19:35:45 -0500 Subject: [PATCH 21/29] avcodec: fix avcodec_encode_audio() documentation. the previous documentation indicated how many bytes are read from the input, not how many samples are read. --- libavcodec/avcodec.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index b139a8a9ea..c38bd275b8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4200,9 +4200,9 @@ void avsubtitle_free(AVSubtitle *sub); * Encode an audio frame from samples into buf. * * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large. - * However, for PCM audio the user will know how much space is needed - * because it depends on the value passed in buf_size as described - * below. In that case a lower value can be used. + * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user + * will know how much space is needed because it depends on the value passed + * in buf_size as described below. In that case a lower value can be used. * * @param avctx the codec context * @param[out] buf the output buffer @@ -4210,8 +4210,11 @@ void avsubtitle_free(AVSubtitle *sub); * @param[in] samples the input buffer containing the samples * The number of samples read from this buffer is frame_size*channels, * both of which are defined in avctx. - * For PCM audio the number of samples read from samples is equal to - * buf_size * input_sample_size / output_sample_size. + * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of + * samples read from samples is equal to: + * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id)) + * This also implies that av_get_bits_per_sample() must not return 0 for these + * codecs. * @return On error a negative value is returned, on success zero or the number * of bytes used to encode the data read from the input buffer. */ From 3f6aa85ed45c2e6d52c2d11fc7f41bf732d10c29 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sat, 7 Jan 2012 11:25:04 -0500 Subject: [PATCH 22/29] avcodec: attempt to clarify the CODEC_CAP_DELAY documentation --- libavcodec/avcodec.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index c38bd275b8..c195ad5b18 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -725,10 +725,22 @@ typedef struct RcOverride{ /* Codec can export data for HW decoding (XvMC). */ #define CODEC_CAP_HWACCEL 0x0010 /** - * Codec has a nonzero delay and needs to be fed with avpkt->data=NULL, + * Encoder or decoder requires flushing with NULL input at the end in order to + * give the complete and correct output. + * + * NOTE: If this flag is not set, the codec is guaranteed to never be fed with + * with NULL data. The user can still send NULL data to the public encode + * or decode function, but libavcodec will not pass it along to the codec + * unless this flag is set. + * + * Decoders: + * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL, * avpkt->size=0 at the end to get the delayed data until the decoder no longer - * returns frames. If this is not set, the codec is guaranteed to never be fed - * with NULL data. + * returns frames. + * + * Encoders: + * The encoder needs to be fed with NULL data at the end of encoding until the + * encoder no longer returns data. */ #define CODEC_CAP_DELAY 0x0020 /** From 8b1a26864c875c956bf16c4869eaa8b6c80cd9ff Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 30 Dec 2011 23:14:14 +0100 Subject: [PATCH 23/29] faq: Solutions for common problems with sample paths when running FATE. --- doc/faq.texi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/faq.texi b/doc/faq.texi index 8044200987..7c5373c437 100644 --- a/doc/faq.texi +++ b/doc/faq.texi @@ -359,4 +359,16 @@ to use them you have to append -D__STDC_CONSTANT_MACROS to your CXXFLAGS You have to implement a URLProtocol, see @file{libavformat/file.c} in Libav and @file{libmpdemux/demux_lavf.c} in MPlayer sources. +@section Why is @code{make fate} not running all tests? + +Make sure you have the fate-suite samples and the @code{SAMPLES} Make variable +or @code{FATE_SAMPLES} environment variable or the @code{--samples} +@command{configure} option is set to the right path. + +@section Why is @code{make fate} not finding the samples? + +Do you happen to have a @code{~} character in the samples path to indicate a +home directory? The value is used in ways where the shell cannot expand it, +causing FATE to not find files. Just replace @code{~} by the full path. + @bye From 079688b6cbd2944ab84d3539efcde161aa090fac Mon Sep 17 00:00:00 2001 From: Andrey Utkin Date: Sat, 7 Jan 2012 22:38:00 +0200 Subject: [PATCH 24/29] Disable annoying warning without changing behavior Signed-off-by: Ronald S. Bultje --- libavfilter/avfilter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 70efc5cd3c..cffcfcadc2 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -164,6 +164,7 @@ static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilt switch (src->type) { case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break; case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break; + default: break; } } From 3dc99a18d4ae2b9bcc96e00b7f589128717aec64 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 7 Jan 2012 19:07:42 +0100 Subject: [PATCH 25/29] cosmetics: drop some pointless parentheses --- libavcodec/ac3dec.c | 4 ++-- libavcodec/cavs.c | 4 ++-- libavcodec/cavsdec.c | 2 +- libavcodec/error_resilience.c | 8 ++++---- libavcodec/libdiracenc.c | 6 +++--- libavcodec/libschroedingerenc.c | 2 +- libavcodec/libxvidff.c | 6 +++--- libavcodec/mpeg12.c | 2 +- libavcodec/mpegvideo.c | 10 +++++----- libavcodec/ppc/mpegvideo_altivec.c | 8 ++++---- libavcodec/pthread.c | 2 +- libavcodec/tscc.c | 10 +++++----- libavcodec/vc1dec.c | 2 +- libavcodec/vorbisdec.c | 7 +++---- libavcodec/zmbv.c | 6 +++--- libavcodec/zmbvenc.c | 6 +++--- libavdevice/bktr.c | 2 +- libavdevice/timefilter.c | 2 +- libavfilter/vsrc_buffer.c | 2 +- libavformat/aviobuf.c | 2 +- libavformat/mtv.c | 2 +- libavformat/rmdec.c | 2 +- 22 files changed, 48 insertions(+), 49 deletions(-) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 83cfa0acc3..662ea91d1f 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -223,7 +223,7 @@ static int ac3_parse_header(AC3DecodeContext *s) int i; /* read the rest of the bsi. read twice for dual mono mode. */ - i = !(s->channel_mode); + i = !s->channel_mode; do { skip_bits(gbc, 5); // skip dialog normalization if (get_bits1(gbc)) @@ -792,7 +792,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) } /* dynamic range */ - i = !(s->channel_mode); + i = !s->channel_mode; do { if (get_bits1(gbc)) { s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)] - 1.0) * diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index 6f63c23628..9ff0e5165b 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -658,8 +658,8 @@ void ff_cavs_init_top_lines(AVSContext *h) { h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector)); h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y)); h->top_border_y = av_malloc((h->mb_width+1)*16); - h->top_border_u = av_malloc((h->mb_width)*10); - h->top_border_v = av_malloc((h->mb_width)*10); + h->top_border_u = av_malloc( h->mb_width * 10); + h->top_border_v = av_malloc( h->mb_width * 10); /* alloc space for co-located MVs and types */ h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(cavs_vector)); diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 514752afc9..2f4b6e3b14 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -490,7 +490,7 @@ static int decode_pic(AVSContext *h) { skip_bits(&s->gb,24);//time_code /* old sample clips were all progressive and no low_delay, bump stream revision if detected otherwise */ - if((s->low_delay) || !(show_bits(&s->gb,9) & 1)) + if (s->low_delay || !(show_bits(&s->gb,9) & 1)) h->stream_revision = 1; /* similarly test top_field_first and repeat_first_field */ else if(show_bits(&s->gb,11) & 3) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 39c0b2f622..855ae770ad 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -109,8 +109,8 @@ static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t for(y=0; y<8; y++){ int x; for(x=0; x<8; x++){ - dest_cb[x + y*(s->uvlinesize)]= dcu/8; - dest_cr[x + y*(s->uvlinesize)]= dcv/8; + dest_cb[x + y * s->uvlinesize] = dcu / 8; + dest_cr[x + y * s->uvlinesize] = dcv / 8; } } } @@ -1092,8 +1092,8 @@ void ff_er_frame_end(MpegEncContext *s){ for(y=0; y<8; y++){ int x; for(x=0; x<8; x++){ - dcu+=dest_cb[x + y*(s->uvlinesize)]; - dcv+=dest_cr[x + y*(s->uvlinesize)]; + dcu += dest_cb[x + y * s->uvlinesize]; + dcv += dest_cr[x + y * s->uvlinesize]; } } s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3; diff --git a/libavcodec/libdiracenc.c b/libavcodec/libdiracenc.c index 33dba2236a..156ba57718 100644 --- a/libavcodec/libdiracenc.c +++ b/libavcodec/libdiracenc.c @@ -136,7 +136,7 @@ static av_cold int libdirac_encode_init(AVCodecContext *avccontext) preset = GetDiracVideoFormatPreset(avccontext); /* initialize the encoder context */ - dirac_encoder_context_init(&(p_dirac_params->enc_ctx), preset); + dirac_encoder_context_init(&p_dirac_params->enc_ctx, preset); p_dirac_params->enc_ctx.src_params.chroma = GetDiracChromaFormat(avccontext->pix_fmt); @@ -199,7 +199,7 @@ static av_cold int libdirac_encode_init(AVCodecContext *avccontext) * irrespective of the type of source material */ p_dirac_params->enc_ctx.enc_params.picture_coding_mode = 1; - p_dirac_params->p_encoder = dirac_encoder_init(&(p_dirac_params->enc_ctx), + p_dirac_params->p_encoder = dirac_encoder_init(&p_dirac_params->enc_ctx, verbose); if (!p_dirac_params->p_encoder) { @@ -221,7 +221,7 @@ static void DiracFreeFrame(void *data) { DiracSchroEncodedFrame *enc_frame = data; - av_freep(&(enc_frame->p_encbuf)); + av_freep(&enc_frame->p_encbuf); av_free(enc_frame); } diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c index dec9c2a37e..2aadd3af3f 100644 --- a/libavcodec/libschroedingerenc.c +++ b/libavcodec/libschroedingerenc.c @@ -258,7 +258,7 @@ static void SchroedingerFreeFrame(void *data) { DiracSchroEncodedFrame *enc_frame = data; - av_freep(&(enc_frame->p_encbuf)); + av_freep(&enc_frame->p_encbuf); av_free(enc_frame); } diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c index d0f4ed39be..a11e4ac913 100644 --- a/libavcodec/libxvidff.c +++ b/libavcodec/libxvidff.c @@ -270,7 +270,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { rc2pass2.version = XVID_VERSION; rc2pass2.bitrate = avctx->bit_rate; - fd = ff_tempfile("xvidff.", &(x->twopassfile)); + fd = ff_tempfile("xvidff.", &x->twopassfile); if( fd == -1 ) { av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n"); @@ -414,7 +414,7 @@ static int xvid_encode_frame(AVCodecContext *avctx, char *tmp; struct xvid_context *x = avctx->priv_data; AVFrame *picture = data; - AVFrame *p = &(x->encoded_picture); + AVFrame *p = &x->encoded_picture; xvid_enc_frame_t xvid_enc_frame; xvid_enc_stats_t xvid_enc_stats; @@ -575,7 +575,7 @@ int xvid_strip_vol_header(AVCodecContext *avctx, } /* Less dangerous now, memmove properly copies the two chunks of overlapping data */ - memmove(frame, &(frame[vo_len]), frame_len - vo_len); + memmove(frame, &frame[vo_len], frame_len - vo_len); return frame_len - vo_len; } else return frame_len; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 2019512839..34857d61a6 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1235,7 +1235,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) /* low_delay may be forced, in this case we will have B-frames * that behave like P-frames. */ - avctx->has_b_frames = !(s->low_delay); + avctx->has_b_frames = !s->low_delay; assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO)); if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) { diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index a2aa257f89..e4c45886dc 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -705,8 +705,8 @@ av_cold int MPV_common_init(MpegEncContext *s) mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; /* set chroma shifts */ - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), - &(s->chroma_y_shift) ); + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift, + &s->chroma_y_shift); /* set default edge pos, will be overriden * in decode_header if needed */ @@ -2339,7 +2339,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } dct_linesize = linesize << s->interlaced_dct; - dct_offset =(s->interlaced_dct)? linesize : linesize*block_size; + dct_offset = s->interlaced_dct ? linesize : linesize * block_size; if(readable){ dest_y= s->dest[0]; @@ -2435,7 +2435,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], }else{ //chroma422 dct_linesize = uvlinesize << s->interlaced_dct; - dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8; + dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize * 8; add_dct(s, block[4], 4, dest_cb, dct_linesize); add_dct(s, block[5], 5, dest_cr, dct_linesize); @@ -2487,7 +2487,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], }else{ dct_linesize = uvlinesize << s->interlaced_dct; - dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8; + dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize * 8; s->dsp.idct_put(dest_cb, dct_linesize, block[4]); s->dsp.idct_put(dest_cr, dct_linesize, block[5]); diff --git a/libavcodec/ppc/mpegvideo_altivec.c b/libavcodec/ppc/mpegvideo_altivec.c index 2d3bf892a0..a033cd7372 100644 --- a/libavcodec/ppc/mpegvideo_altivec.c +++ b/libavcodec/ppc/mpegvideo_altivec.c @@ -268,10 +268,10 @@ static int dct_quantize_altivec(MpegEncContext* s, vec_ste(baseVector, 0, &oldBaseValue); qmat = (vector signed int*)s->q_intra_matrix[qscale]; - biasAddr = &(s->intra_quant_bias); + biasAddr = &s->intra_quant_bias; } else { qmat = (vector signed int*)s->q_inter_matrix[qscale]; - biasAddr = &(s->inter_quant_bias); + biasAddr = &s->inter_quant_bias; } // Load the bias vector (We add 0.5 to the bias so that we're @@ -361,8 +361,8 @@ static int dct_quantize_altivec(MpegEncContext* s, vector signed int max_q_int, min_q_int; vector signed short max_q, min_q; - LOAD4(max_q_int, &(s->max_qcoeff)); - LOAD4(min_q_int, &(s->min_qcoeff)); + LOAD4(max_q_int, &s->max_qcoeff); + LOAD4(min_q_int, &s->min_qcoeff); max_q = vec_pack(max_q_int, max_q_int); min_q = vec_pack(min_q_int, min_q_int); diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 2159a2572d..0688d9d8f0 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -829,7 +829,7 @@ static int frame_thread_init(AVCodecContext *avctx) err = AVERROR(ENOMEM); goto error; } - *(copy->internal) = *(src->internal); + *copy->internal = *src->internal; copy->internal->is_copy = 1; if (codec->init_thread_copy) diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c index 90d203dd77..ccf1048c9b 100644 --- a/libavcodec/tscc.c +++ b/libavcodec/tscc.c @@ -88,7 +88,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac return -1; } - zret = inflateReset(&(c->zstream)); + zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return -1; @@ -97,7 +97,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac c->zstream.avail_in = len; c->zstream.next_out = c->decomp_buf; c->zstream.avail_out = c->decomp_size; - zret = inflate(&(c->zstream), Z_FINISH); + zret = inflate(&c->zstream, Z_FINISH); // Z_DATA_ERROR means empty picture if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); @@ -143,7 +143,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->height = avctx->height; // Needed if zlib unused or init aborted before inflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); + memset(&c->zstream, 0, sizeof(z_stream)); switch(avctx->bits_per_coded_sample){ case 8: avctx->pix_fmt = PIX_FMT_PAL8; break; case 16: avctx->pix_fmt = PIX_FMT_RGB555; break; @@ -169,7 +169,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; - zret = inflateInit(&(c->zstream)); + zret = inflateInit(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return 1; @@ -193,7 +193,7 @@ static av_cold int decode_end(AVCodecContext *avctx) if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); - inflateEnd(&(c->zstream)); + inflateEnd(&c->zstream); return 0; } diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index bc8daed7af..fa952739bb 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -5342,7 +5342,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) if (v->profile == PROFILE_ADVANCED) avctx->level = v->level; - avctx->has_b_frames = !!(avctx->max_b_frames); + avctx->has_b_frames = !!avctx->max_b_frames; s->mb_width = (avctx->coded_width + 15) >> 4; s->mb_height = (avctx->coded_height + 15) >> 4; diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 70690ddb2c..e0c38c2360 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -816,8 +816,7 @@ static void create_map(vorbis_context *vc, unsigned floor_number) for (idx = 0; idx < n; ++idx) { map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) * - ((vf->bark_map_size) / - BARK(vf->rate / 2.0f))); + (vf->bark_map_size / BARK(vf->rate / 2.0f))); if (vf->bark_map_size-1 < map[idx]) map[idx] = vf->bark_map_size - 1; } @@ -975,7 +974,7 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) int headers_len = avccontext->extradata_size; uint8_t *header_start[3]; int header_len[3]; - GetBitContext *gb = &(vc->gb); + GetBitContext *gb = &vc->gb; int hdr_type, ret; vc->avccontext = avccontext; @@ -1615,7 +1614,7 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; vorbis_context *vc = avccontext->priv_data; - GetBitContext *gb = &(vc->gb); + GetBitContext *gb = &vc->gb; const float *channel_ptrs[255]; int i, len, ret; diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 321348024a..a36a844b1f 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -613,7 +613,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->bpp = avctx->bits_per_coded_sample; // Needed if zlib unused or init aborted before inflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); + memset(&c->zstream, 0, sizeof(z_stream)); avctx->pix_fmt = PIX_FMT_RGB24; c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64); @@ -630,7 +630,7 @@ static av_cold int decode_init(AVCodecContext *avctx) c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; - zret = inflateInit(&(c->zstream)); + zret = inflateInit(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return 1; @@ -654,7 +654,7 @@ static av_cold int decode_end(AVCodecContext *avctx) if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); - inflateEnd(&(c->zstream)); + inflateEnd(&c->zstream); av_freep(&c->cur); av_freep(&c->prev); diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c index 2230436f90..75fcffec8c 100644 --- a/libavcodec/zmbvenc.c +++ b/libavcodec/zmbvenc.c @@ -269,7 +269,7 @@ static av_cold int encode_init(AVCodecContext *avctx) } // Needed if zlib unused or init aborted before deflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); + memset(&c->zstream, 0, sizeof(z_stream)); c->comp_size = avctx->width * avctx->height + 1024 + ((avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * ((avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * 2 + 4; if ((c->work_buf = av_malloc(c->comp_size)) == NULL) { @@ -294,7 +294,7 @@ static av_cold int encode_init(AVCodecContext *avctx) c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; - zret = deflateInit(&(c->zstream), lvl); + zret = deflateInit(&c->zstream, lvl); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return -1; @@ -317,7 +317,7 @@ static av_cold int encode_end(AVCodecContext *avctx) av_freep(&c->comp_buf); av_freep(&c->work_buf); - deflateEnd(&(c->zstream)); + deflateEnd(&c->zstream); av_freep(&c->prev); return 0; diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index e6a1e8ba2d..8abe5ef18f 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -292,7 +292,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) if (bktr_init(s1->filename, width, height, s->standard, - &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) { + &s->video_fd, &s->tuner_fd, -1, 0.0) < 0) { ret = AVERROR(EIO); goto out; } diff --git a/libavdevice/timefilter.c b/libavdevice/timefilter.c index 332d33b5e8..136661a541 100644 --- a/libavdevice/timefilter.c +++ b/libavdevice/timefilter.c @@ -69,7 +69,7 @@ double ff_timefilter_update(TimeFilter *self, double system_time, double period) loop_error = system_time - self->cycle_time; /// update loop - self->cycle_time += FFMAX(self->feedback2_factor, 1.0/(self->count)) * loop_error; + self->cycle_time += FFMAX(self->feedback2_factor, 1.0 / self->count) * loop_error; self->clock_period += self->feedback3_factor * loop_error / period; } return self->cycle_time; diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 7ef19a1140..91465026c2 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -147,7 +147,7 @@ static int request_frame(AVFilterLink *link) static int poll_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - return !!(c->buf); + return !!c->buf; } AVFilter avfilter_vsrc_buffer = { diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index dbbbba5535..6cd2cefa7c 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -168,7 +168,7 @@ static void flush_buffer(AVIOContext *s) void avio_w8(AVIOContext *s, int b) { - *(s->buf_ptr)++ = b; + *s->buf_ptr++ = b; if (s->buf_ptr >= s->buf_end) flush_buffer(s); } diff --git a/libavformat/mtv.c b/libavformat/mtv.c index 4c3b082881..2243733812 100644 --- a/libavformat/mtv.c +++ b/libavformat/mtv.c @@ -53,7 +53,7 @@ typedef struct MTVDemuxContext { static int mtv_probe(AVProbeData *p) { /* Magic is 'AMV' */ - if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') + if (*p->buf != 'A' || *(p->buf + 1) != 'M' || *(p->buf + 2) != 'V') return 0; /* Check for nonzero in bpp and (width|height) header fields */ diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 66b6f8a876..75e4833c4c 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -661,7 +661,7 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, vst->videobufpos += len; rm->remaining_len-= len; - if(type == 2 || (vst->videobufpos) == vst->videobufsize){ + if (type == 2 || vst->videobufpos == vst->videobufsize) { vst->pkt.data[0] = vst->cur_slice-1; *pkt= vst->pkt; vst->pkt.data= NULL; From 52877251cfc309bd9d8b57905f6805222857aeb2 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 7 Jan 2012 19:17:15 +0100 Subject: [PATCH 26/29] build: Skip compiling network.h and rtsp.h if networking is not enabled. rtsp.h relies on network.h and the latter conditionally defines fallback OS structures that rely on configure tests, which are only run if networking is enabled. --- libavformat/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/Makefile b/libavformat/Makefile index 8c8a36d206..3902e89027 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -349,6 +349,8 @@ OBJS-$(CONFIG_TCP_PROTOCOL) += tcp.o OBJS-$(CONFIG_TLS_PROTOCOL) += tls.o OBJS-$(CONFIG_UDP_PROTOCOL) += udp.o +SKIPHEADERS-$(CONFIG_NETWORK) += network.h rtsp.h + EXAMPLES = metadata output TESTPROGS = seek TOOLS = pktdumper probetest From a7e3cb9d32366209015a395f1435323887e66d4f Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 7 Jan 2012 21:36:31 +0100 Subject: [PATCH 27/29] h264-test: Initialize AVCodecContext.av_class. This fixes a segfault on startup. Also remove a commented-out and completely unused variable. --- libavcodec/h264.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 82b7acd1ee..cee16e7577 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -4109,10 +4109,10 @@ int main(void){ uint8_t temp[SIZE]; PutBitContext pb; GetBitContext gb; -// int int_temp[10000]; DSPContext dsp; AVCodecContext avctx; + avctx.av_class = avcodec_get_class(); dsputil_init(&dsp, &avctx); init_put_bits(&pb, temp, SIZE); From 1be4b8ccbaf64e626ede8e3ab5628865db0bada2 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 7 Jan 2012 18:37:28 +0100 Subject: [PATCH 28/29] vp56: Drop unnecessary cabac.h #include. --- libavcodec/vp56.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h index ceb516d88d..0607e0d4ce 100644 --- a/libavcodec/vp56.h +++ b/libavcodec/vp56.h @@ -30,7 +30,6 @@ #include "dsputil.h" #include "get_bits.h" #include "bytestream.h" -#include "cabac.h" #include "vp56dsp.h" typedef struct vp56_context VP56Context; From badb195d139f15dc189dd3f78930c9cbfce89c24 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 7 Jan 2012 20:46:09 +0100 Subject: [PATCH 29/29] cabac: Move code only used within the CABAC test program into the test program. --- libavcodec/cabac.c | 25 +++++++++++++++++++++++++ libavcodec/cabac.h | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c index bcb242936e..466d6239dc 100644 --- a/libavcodec/cabac.c +++ b/libavcodec/cabac.c @@ -162,6 +162,31 @@ void ff_init_cabac_states(CABACContext *c){ #include "avcodec.h" #include "cabac.h" +static inline void put_cabac_bit(CABACContext *c, int b){ + put_bits(&c->pb, 1, b); + for(;c->outstanding_count; c->outstanding_count--){ + put_bits(&c->pb, 1, 1-b); + } +} + +static inline void renorm_cabac_encoder(CABACContext *c){ + while(c->range < 0x100){ + //FIXME optimize + if(c->low<0x100){ + put_cabac_bit(c, 0); + }else if(c->low<0x200){ + c->outstanding_count++; + c->low -= 0x100; + }else{ + put_cabac_bit(c, 1); + c->low -= 0x200; + } + + c->range+= c->range; + c->low += c->low; + } +} + static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h index b0d056def0..dda6348ea4 100644 --- a/libavcodec/cabac.h +++ b/libavcodec/cabac.h @@ -62,31 +62,6 @@ void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); void ff_init_cabac_states(CABACContext *c); -static inline void put_cabac_bit(CABACContext *c, int b){ - put_bits(&c->pb, 1, b); - for(;c->outstanding_count; c->outstanding_count--){ - put_bits(&c->pb, 1, 1-b); - } -} - -static inline void renorm_cabac_encoder(CABACContext *c){ - while(c->range < 0x100){ - //FIXME optimize - if(c->low<0x100){ - put_cabac_bit(c, 0); - }else if(c->low<0x200){ - c->outstanding_count++; - c->low -= 0x100; - }else{ - put_cabac_bit(c, 1); - c->low -= 0x200; - } - - c->range+= c->range; - c->low += c->low; - } -} - static void refill(CABACContext *c){ #if CABAC_BITS == 16 c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);