From 85383d139a54ebd9d8e8bb7d6dc6b0e03bc769ca Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 08:09:01 +0100 Subject: [PATCH 1/9] 4xm: eliminate a pointless indirection --- libavcodec/4xm.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index 446c085f1b..d924a78652 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -877,16 +877,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, return buf_size; } - -static av_cold void common_init(AVCodecContext *avctx) -{ - FourXContext * const f = avctx->priv_data; - - ff_dsputil_init(&f->dsp, avctx); - - f->avctx = avctx; -} - static av_cold int decode_init(AVCodecContext *avctx) { FourXContext * const f = avctx->priv_data; @@ -897,7 +887,8 @@ static av_cold int decode_init(AVCodecContext *avctx) } f->version = AV_RL32(avctx->extradata) >> 16; - common_init(avctx); + ff_dsputil_init(&f->dsp, avctx); + f->avctx = avctx; init_vlcs(f); if (f->version > 2) From f7d15d2f42d99df3a3c2448dd91e436f8fb005f4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 08:23:11 +0100 Subject: [PATCH 2/9] 4xm: operate with pointers to AVFrames instead of whole structs. This is more correct and avoids breaking extended_data. --- libavcodec/4xm.c | 52 +++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index d924a78652..094e8518e4 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -131,7 +131,7 @@ typedef struct CFrameBuffer { typedef struct FourXContext { AVCodecContext *avctx; DSPContext dsp; - AVFrame current_picture, last_picture; + AVFrame *current_picture, *last_picture; GetBitContext pre_gb; ///< ac/dc prefix GetBitContext gb; GetByteContext g; @@ -262,9 +262,9 @@ static void init_mv(FourXContext *f) for (i = 0; i < 256; i++) { if (f->version > 1) - f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture.linesize[0] / 2; + f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture->linesize[0] / 2; else - f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture.linesize[0] / 2; + f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture->linesize[0] / 2; } } @@ -341,7 +341,7 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int code = get_vlc2(&f->gb, block_type_vlc[1 - (f->version > 1)][index].table, BLOCK_TYPE_VLC_BITS, 1); - uint16_t *start = (uint16_t *)f->last_picture.data[0]; + uint16_t *start = (uint16_t *)f->last_picture->data[0]; uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w); assert(code >= 0 && code <= 6); @@ -390,9 +390,9 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length) int x, y; const int width = f->avctx->width; const int height = f->avctx->height; - uint16_t *src = (uint16_t *)f->last_picture.data[0]; - uint16_t *dst = (uint16_t *)f->current_picture.data[0]; - const int stride = f->current_picture.linesize[0] >> 1; + uint16_t *src = (uint16_t *)f->last_picture->data[0]; + uint16_t *dst = (uint16_t *)f->current_picture->data[0]; + const int stride = f->current_picture->linesize[0] >> 1; unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset; @@ -497,9 +497,9 @@ static int decode_i_block(FourXContext *f, DCTELEM *block) static inline void idct_put(FourXContext *f, int x, int y) { DCTELEM (*block)[64] = f->block; - int stride = f->current_picture.linesize[0] >> 1; + int stride = f->current_picture->linesize[0] >> 1; int i; - uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x; + uint16_t *dst = ((uint16_t*)f->current_picture->data[0]) + y * stride + x; for (i = 0; i < 4; i++) { block[i][0] += 0x80 * 8 * 8; @@ -653,8 +653,8 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length) const int width = f->avctx->width; const int height = f->avctx->height; const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4); - uint16_t *dst = (uint16_t*)f->current_picture.data[0]; - const int stride = f->current_picture.linesize[0]>>1; + uint16_t *dst = (uint16_t*)f->current_picture->data[0]; + const int stride = f->current_picture->linesize[0]>>1; GetByteContext g3; if (length < mbs * 8) { @@ -821,9 +821,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, frame_size = buf_size - 12; } - FFSWAP(AVFrame, f->current_picture, f->last_picture); + FFSWAP(AVFrame*, f->current_picture, f->last_picture); - p = &f->current_picture; + p = f->current_picture; avctx->coded_frame = p; // alternatively we would have to use our own buffer management @@ -847,13 +847,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, if ((ret = decode_i_frame(f, buf, frame_size)) < 0) return ret; } else if (frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")) { - if (!f->last_picture.data[0]) { - f->last_picture.reference = 1; - if ((ret = ff_get_buffer(avctx, &f->last_picture)) < 0) { + if (!f->last_picture->data[0]) { + f->last_picture->reference = 1; + if ((ret = ff_get_buffer(avctx, f->last_picture)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - memset(f->last_picture.data[0], 0, avctx->height * FFABS(f->last_picture.linesize[0])); + memset(f->last_picture->data[0], 0, avctx->height * FFABS(f->last_picture->linesize[0])); } p->pict_type = AV_PICTURE_TYPE_P; @@ -896,6 +896,14 @@ static av_cold int decode_init(AVCodecContext *avctx) else avctx->pix_fmt = AV_PIX_FMT_BGR555; + f->current_picture = avcodec_alloc_frame(); + f->last_picture = avcodec_alloc_frame(); + if (!f->current_picture || !f->last_picture) { + avcodec_free_frame(&f->current_picture); + avcodec_free_frame(&f->last_picture); + return AVERROR(ENOMEM); + } + return 0; } @@ -912,10 +920,12 @@ static av_cold int decode_end(AVCodecContext *avctx) f->cfrm[i].allocated_size = 0; } ff_free_vlc(&f->pre_vlc); - if (f->current_picture.data[0]) - avctx->release_buffer(avctx, &f->current_picture); - if (f->last_picture.data[0]) - avctx->release_buffer(avctx, &f->last_picture); + if (f->current_picture->data[0]) + avctx->release_buffer(avctx, f->current_picture); + if (f->last_picture->data[0]) + avctx->release_buffer(avctx, f->last_picture); + avcodec_free_frame(&f->current_picture); + avcodec_free_frame(&f->last_picture); return 0; } From 313da47aa1f28aba3a81b0f4c9c23fd29df1070a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 08:59:03 +0100 Subject: [PATCH 3/9] 8bps: return meaningful error codes. --- libavcodec/8bps.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c index 8f0692c4ba..ceed13f5b8 100644 --- a/libavcodec/8bps.c +++ b/libavcodec/8bps.c @@ -69,15 +69,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, unsigned int px_inc; unsigned int planes = c->planes; unsigned char *planemap = c->planemap; + int ret; if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); c->pic.reference = 0; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; - if (ff_get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } /* Set data pointer after line lengths */ @@ -101,14 +102,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, /* Decode a row of this plane */ while (dlen > 0) { if (dp + 1 >= buf + buf_size) - return -1; + return AVERROR_INVALIDDATA; if ((count = *dp++) <= 127) { count++; dlen -= count + 1; if (pixptr + count * px_inc > pixptr_end) break; if (dp + count > buf + buf_size) - return -1; + return AVERROR_INVALIDDATA; while (count--) { *pixptr = *dp++; pixptr += px_inc; @@ -185,7 +186,7 @@ static av_cold int decode_init(AVCodecContext *avctx) default: av_log(avctx, AV_LOG_ERROR, "Error: Unsupported color depth: %u.\n", avctx->bits_per_coded_sample); - return -1; + return AVERROR_INVALIDDATA; } return 0; From 18009e60d273eb2e0184926812778e06985bf48e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 09:11:07 +0100 Subject: [PATCH 4/9] aasc: return meaningful error codes. --- libavcodec/aasc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/aasc.c b/libavcodec/aasc.c index 47d25d0d09..7759c71a2f 100644 --- a/libavcodec/aasc.c +++ b/libavcodec/aasc.c @@ -56,13 +56,13 @@ static int aasc_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AascContext *s = avctx->priv_data; - int compr, i, stride; + int compr, i, stride, ret; s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->reget_buffer(avctx, &s->frame)) { + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } compr = AV_RL32(buf); @@ -82,7 +82,7 @@ static int aasc_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr); - return -1; + return AVERROR_INVALIDDATA; } *got_frame = 1; From b622e2b540ea12207b8704822530cf325c2be13a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 14:01:50 +0100 Subject: [PATCH 5/9] anm: return meaningful error codes --- libavcodec/anm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/anm.c b/libavcodec/anm.c index d08ed8d140..af148a6fd0 100644 --- a/libavcodec/anm.c +++ b/libavcodec/anm.c @@ -44,7 +44,7 @@ static av_cold int decode_init(AVCodecContext *avctx) s->frame.reference = 1; bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size); if (bytestream2_get_bytes_left(&s->gb) < 16 * 8 + 4 * 256) - return -1; + return AVERROR_INVALIDDATA; bytestream2_skipu(&s->gb, 16 * 8); for (i = 0; i < 256; i++) @@ -111,11 +111,11 @@ static int decode_frame(AVCodecContext *avctx, AnmContext *s = avctx->priv_data; const int buf_size = avpkt->size; uint8_t *dst, *dst_end; - int count; + int count, ret; - if(avctx->reget_buffer(avctx, &s->frame) < 0){ + if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0){ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } dst = s->frame.data[0]; dst_end = s->frame.data[0] + s->frame.linesize[0]*avctx->height; From b3b17f780029150e71ec7db7e7b1fa42e49d3865 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 14:29:53 +0100 Subject: [PATCH 6/9] ansi: return a meaningful error code --- libavcodec/ansi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/ansi.c b/libavcodec/ansi.c index 861d4e57e4..0b2e93d74b 100644 --- a/libavcodec/ansi.c +++ b/libavcodec/ansi.c @@ -401,8 +401,8 @@ static int decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_WARNING, "args overflow (%i)\n", s->nb_args); if (s->nb_args < MAX_NB_ARGS && s->args[s->nb_args]) s->nb_args++; - if (execute_code(avctx, buf[0]) < 0) - return -1; + if ((ret = execute_code(avctx, buf[0])) < 0) + return ret; s->state = STATE_NORMAL; } break; From 38de3365ca7e1e35fba87b8e0e119fdccc629669 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 14:59:40 +0100 Subject: [PATCH 7/9] asvdec: return meaningful error codes. --- libavcodec/asvdec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c index 16722a9192..f36fa7f31f 100644 --- a/libavcodec/asvdec.c +++ b/libavcodec/asvdec.c @@ -111,7 +111,7 @@ static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]) break; if (ccp < 0 || i >= 10) { av_log(a->avctx, AV_LOG_ERROR, "coded coeff pattern damaged\n"); - return -1; + return AVERROR_INVALIDDATA; } if (ccp & 8) @@ -213,15 +213,15 @@ static int decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; AVFrame *picture = data; AVFrame * const p = &a->picture; - int mb_x, mb_y; + int mb_x, mb_y, ret; if (p->data[0]) avctx->release_buffer(avctx, p); p->reference = 0; - if (ff_get_buffer(avctx, p) < 0) { + if ((ret = ff_get_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -243,8 +243,8 @@ static int decode_frame(AVCodecContext *avctx, for (mb_y = 0; mb_y < a->mb_height2; mb_y++) { for (mb_x = 0; mb_x < a->mb_width2; mb_x++) { - if (decode_mb(a, a->block) < 0) - return -1; + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, mb_x, mb_y); } @@ -253,8 +253,8 @@ static int decode_frame(AVCodecContext *avctx, if (a->mb_width2 != a->mb_width) { mb_x = a->mb_width2; for (mb_y = 0; mb_y < a->mb_height2; mb_y++) { - if (decode_mb(a, a->block) < 0) - return -1; + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, mb_x, mb_y); } @@ -263,8 +263,8 @@ static int decode_frame(AVCodecContext *avctx, if (a->mb_height2 != a->mb_height) { mb_y = a->mb_height2; for (mb_x = 0; mb_x < a->mb_width; mb_x++) { - if (decode_mb(a, a->block) < 0) - return -1; + if ((ret = decode_mb(a, a->block)) < 0) + return ret; idct_put(a, mb_x, mb_y); } From 620faee5d1069a29c2c73aeed1e8485f21565b34 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 15:11:23 +0100 Subject: [PATCH 8/9] aura: return meaningful error codes. --- libavcodec/aura.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/aura.c b/libavcodec/aura.c index 4960bf8d54..7256dc8274 100644 --- a/libavcodec/aura.c +++ b/libavcodec/aura.c @@ -39,7 +39,7 @@ static av_cold int aura_decode_init(AVCodecContext *avctx) s->avctx = avctx; /* width needs to be divisible by 4 for this codec to work */ if (avctx->width & 0x3) - return -1; + return AVERROR(EINVAL); avctx->pix_fmt = AV_PIX_FMT_YUV422P; return 0; @@ -52,7 +52,7 @@ static int aura_decode_frame(AVCodecContext *avctx, AuraDecodeContext *s = avctx->priv_data; uint8_t *Y, *U, *V; uint8_t val; - int x, y; + int x, y, ret; const uint8_t *buf = pkt->data; /* prediction error tables (make it clear that they are signed values) */ @@ -61,7 +61,7 @@ static int aura_decode_frame(AVCodecContext *avctx, if (pkt->size != 48 + avctx->height * avctx->width) { av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n", pkt->size, 48 + avctx->height * avctx->width); - return -1; + return AVERROR_INVALIDDATA; } /* pixel data starts 48 bytes in, after 3x16-byte tables */ @@ -72,9 +72,9 @@ static int aura_decode_frame(AVCodecContext *avctx, s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; s->frame.reference = 0; - if (ff_get_buffer(avctx, &s->frame) < 0) { + if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } Y = s->frame.data[0]; From e83c1e2d0bedb5d4fa9ab351126b2ecc552f1355 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Nov 2012 16:09:39 +0100 Subject: [PATCH 9/9] avs: return meaningful error codes. --- libavcodec/avs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/avs.c b/libavcodec/avs.c index 98a53f20bc..71b8b0c283 100644 --- a/libavcodec/avs.c +++ b/libavcodec/avs.c @@ -54,14 +54,14 @@ avs_decode_frame(AVCodecContext * avctx, AVFrame *const p = &avs->picture; const uint8_t *table, *vect; uint8_t *out; - int i, j, x, y, stride, vect_w = 3, vect_h = 3; + int i, j, x, y, stride, ret, vect_w = 3, vect_h = 3; AvsVideoSubType sub_type; AvsBlockType type; GetBitContext change_map; - if (avctx->reget_buffer(avctx, p)) { + if ((ret = avctx->reget_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } p->reference = 1; p->pict_type = AV_PICTURE_TYPE_P; @@ -94,7 +94,7 @@ avs_decode_frame(AVCodecContext * avctx, } if (type != AVS_VIDEO) - return -1; + return AVERROR_INVALIDDATA; switch (sub_type) { case AVS_I_FRAME: @@ -116,7 +116,7 @@ avs_decode_frame(AVCodecContext * avctx, break; default: - return -1; + return AVERROR_INVALIDDATA; } if (buf_end - buf < 256 * vect_w * vect_h)