From 42d40fd28cea925a87c8ad2d34e9c2e2c1821171 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/4] truemotion1: use the AVFrame API properly. --- libavcodec/truemotion1.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libavcodec/truemotion1.c b/libavcodec/truemotion1.c index f7be92fb43..c1a39c2166 100644 --- a/libavcodec/truemotion1.c +++ b/libavcodec/truemotion1.c @@ -44,7 +44,7 @@ typedef struct TrueMotion1Context { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; const uint8_t *buf; int size; @@ -400,7 +400,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s) if (s->w != s->avctx->width || s->h != s->avctx->height || new_pix_fmt != s->avctx->pix_fmt) { - av_frame_unref(&s->frame); + av_frame_unref(s->frame); s->avctx->sample_aspect_ratio = (AVRational){ 1 << width_shift, 1 }; s->avctx->pix_fmt = new_pix_fmt; @@ -469,7 +469,9 @@ static av_cold int truemotion1_decode_init(AVCodecContext *avctx) // else // avctx->pix_fmt = AV_PIX_FMT_RGB555; - avcodec_get_frame_defaults(&s->frame); + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); /* there is a vertical predictor for each pixel in a line; each vertical * predictor is 0 to start with */ @@ -594,7 +596,7 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) unsigned int horiz_pred; unsigned int *vert_pred; unsigned int *current_pixel_pair; - unsigned char *current_line = s->frame.data[0]; + unsigned char *current_line = s->frame->data[0]; int keyframe = s->flags & FLAG_KEYFRAME; /* these variables are for managing the stream of macroblock change bits */ @@ -708,7 +710,7 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) if (((y + 1) & 3) == 0) mb_change_bits += s->mb_change_bits_row_size; - current_line += s->frame.linesize[0]; + current_line += s->frame->linesize[0]; } } @@ -720,7 +722,7 @@ static void truemotion1_decode_24bit(TrueMotion1Context *s) unsigned int horiz_pred; unsigned int *vert_pred; unsigned int *current_pixel_pair; - unsigned char *current_line = s->frame.data[0]; + unsigned char *current_line = s->frame->data[0]; int keyframe = s->flags & FLAG_KEYFRAME; /* these variables are for managing the stream of macroblock change bits */ @@ -834,7 +836,7 @@ static void truemotion1_decode_24bit(TrueMotion1Context *s) if (((y + 1) & 3) == 0) mb_change_bits += s->mb_change_bits_row_size; - current_line += s->frame.linesize[0]; + current_line += s->frame->linesize[0]; } } @@ -853,7 +855,7 @@ static int truemotion1_decode_frame(AVCodecContext *avctx, if ((ret = truemotion1_decode_header(s)) < 0) return ret; - if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0) { + if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -864,7 +866,7 @@ static int truemotion1_decode_frame(AVCodecContext *avctx, truemotion1_decode_16bit(s); } - if ((ret = av_frame_ref(data, &s->frame)) < 0) + if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; *got_frame = 1; @@ -877,7 +879,7 @@ static av_cold int truemotion1_decode_end(AVCodecContext *avctx) { TrueMotion1Context *s = avctx->priv_data; - av_frame_unref(&s->frame); + av_frame_free(&s->frame); av_free(s->vert_pred); return 0; From 32f7cf9bc38abbdca6f2d7c2e8c37c01f843ecab Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 2/4] truemotion2: use the AVFrame API properly. --- libavcodec/truemotion2.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index 5d9408d166..e41d7a39e3 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -58,7 +58,7 @@ enum TM2_BLOCKS { typedef struct TM2Context { AVCodecContext *avctx; - AVFrame pic; + AVFrame *pic; GetBitContext gb; DSPContext dsp; @@ -838,7 +838,7 @@ static int decode_frame(AVCodecContext *avctx, TM2Context * const l = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size & ~3; - AVFrame * const p = &l->pic; + AVFrame * const p = l->pic; int offset = TM2_HEADER_SIZE; int i, t, ret; uint8_t *swbuf; @@ -883,7 +883,7 @@ static int decode_frame(AVCodecContext *avctx, l->cur = !l->cur; *got_frame = 1; - ret = av_frame_ref(data, &l->pic); + ret = av_frame_ref(data, l->pic); av_free(swbuf); return (ret < 0) ? ret : buf_size; @@ -900,9 +900,12 @@ static av_cold int decode_init(AVCodecContext *avctx) } l->avctx = avctx; - avcodec_get_frame_defaults(&l->pic); avctx->pix_fmt = AV_PIX_FMT_BGR24; + l->pic = av_frame_alloc(); + if (!l->pic) + return AVERROR(ENOMEM); + ff_dsputil_init(&l->dsp, avctx); l->last = av_malloc(4 * sizeof(*l->last) * (w >> 2)); @@ -952,7 +955,6 @@ static av_cold int decode_init(AVCodecContext *avctx) static av_cold int decode_end(AVCodecContext *avctx) { TM2Context * const l = avctx->priv_data; - AVFrame *pic = &l->pic; int i; av_free(l->last); @@ -968,7 +970,7 @@ static av_cold int decode_end(AVCodecContext *avctx) av_free(l->V2_base); } - av_frame_unref(pic); + av_frame_free(&l->pic); return 0; } From 68af7f54a6cdd876fe2264de896779fffce51fd3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 3/4] smc: use the AVFrame API properly. --- libavcodec/smc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libavcodec/smc.c b/libavcodec/smc.c index d28597b733..46903ab2af 100644 --- a/libavcodec/smc.c +++ b/libavcodec/smc.c @@ -46,7 +46,7 @@ typedef struct SmcContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; GetByteContext gb; @@ -81,7 +81,7 @@ static void smc_decode_stream(SmcContext *s) { int width = s->avctx->width; int height = s->avctx->height; - int stride = s->frame.linesize[0]; + int stride = s->frame->linesize[0]; int i; int chunk_size; int buf_size = (int) (s->gb.buffer_end - s->gb.buffer_start); @@ -92,9 +92,9 @@ static void smc_decode_stream(SmcContext *s) unsigned int color_flags_b; unsigned int flag_mask; - unsigned char *pixels = s->frame.data[0]; + unsigned char *pixels = s->frame->data[0]; - int image_size = height * s->frame.linesize[0]; + int image_size = height * s->frame->linesize[0]; int row_ptr = 0; int pixel_ptr = 0; int pixel_x, pixel_y; @@ -112,7 +112,7 @@ static void smc_decode_stream(SmcContext *s) int color_octet_index = 0; /* make the palette available */ - memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); bytestream2_skip(&s->gb, 1); chunk_size = bytestream2_get_be24(&s->gb); @@ -417,7 +417,9 @@ static av_cold int smc_decode_init(AVCodecContext *avctx) s->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_PAL8; - avcodec_get_frame_defaults(&s->frame); + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); return 0; } @@ -434,20 +436,20 @@ static int smc_decode_frame(AVCodecContext *avctx, bytestream2_init(&s->gb, buf, buf_size); - if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0) { + if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } if (pal) { - s->frame.palette_has_changed = 1; + s->frame->palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } smc_decode_stream(s); *got_frame = 1; - if ((ret = av_frame_ref(data, &s->frame)) < 0) + if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; /* always report that the buffer was completely consumed */ @@ -458,7 +460,7 @@ static av_cold int smc_decode_end(AVCodecContext *avctx) { SmcContext *s = avctx->priv_data; - av_frame_unref(&s->frame); + av_frame_free(&s->frame); return 0; } From 508b37557bf36eae83c18e64d42f27b44a321d81 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 4/4] tiertexseqv: use the AVFrame API properly. --- libavcodec/tiertexseqv.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/libavcodec/tiertexseqv.c b/libavcodec/tiertexseqv.c index fe963eff41..33b257954f 100644 --- a/libavcodec/tiertexseqv.c +++ b/libavcodec/tiertexseqv.c @@ -32,7 +32,7 @@ typedef struct SeqVideoContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; } SeqVideoContext; @@ -93,14 +93,14 @@ static const unsigned char *seq_decode_op1(SeqVideoContext *seq, src = seq_unpack_rle_block(src, src_end, block, sizeof(block)); for (b = 0; b < 8; b++) { memcpy(dst, &block[b * 8], 8); - dst += seq->frame.linesize[0]; + dst += seq->frame->linesize[0]; } break; case 2: src = seq_unpack_rle_block(src, src_end, block, sizeof(block)); for (i = 0; i < 8; i++) { for (b = 0; b < 8; b++) - dst[b * seq->frame.linesize[0]] = block[i * 8 + b]; + dst[b * seq->frame->linesize[0]] = block[i * 8 + b]; ++dst; } break; @@ -117,7 +117,7 @@ static const unsigned char *seq_decode_op1(SeqVideoContext *seq, for (b = 0; b < 8; b++) { for (i = 0; i < 8; i++) dst[i] = color_table[get_bits(&gb, bits)]; - dst += seq->frame.linesize[0]; + dst += seq->frame->linesize[0]; } } @@ -137,7 +137,7 @@ static const unsigned char *seq_decode_op2(SeqVideoContext *seq, for (i = 0; i < 8; i++) { memcpy(dst, src, 8); src += 8; - dst += seq->frame.linesize[0]; + dst += seq->frame->linesize[0]; } return src; @@ -154,7 +154,7 @@ static const unsigned char *seq_decode_op3(SeqVideoContext *seq, if (src_end - src < 2) return NULL; pos = *src++; - offset = ((pos >> 3) & 7) * seq->frame.linesize[0] + (pos & 7); + offset = ((pos >> 3) & 7) * seq->frame->linesize[0] + (pos & 7); dst[offset] = *src++; } while (!(pos & 0x80)); @@ -173,7 +173,7 @@ static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int flags = *data++; if (flags & 1) { - palette = (uint32_t *)seq->frame.data[1]; + palette = (uint32_t *)seq->frame->data[1]; if (data_end - data < 256 * 3) return AVERROR_INVALIDDATA; for (i = 0; i < 256; i++) { @@ -181,7 +181,7 @@ static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int c[j] = (*data << 2) | (*data >> 4); palette[i] = AV_RB24(c); } - seq->frame.palette_has_changed = 1; + seq->frame->palette_has_changed = 1; } if (flags & 2) { @@ -190,7 +190,7 @@ static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int init_get_bits(&gb, data, 128 * 8); data += 128; for (y = 0; y < 128; y += 8) for (x = 0; x < 256; x += 8) { - dst = &seq->frame.data[0][y * seq->frame.linesize[0] + x]; + dst = &seq->frame->data[0][y * seq->frame->linesize[0] + x]; op = get_bits(&gb, 2); switch (op) { case 1: @@ -217,7 +217,9 @@ static av_cold int seqvideo_decode_init(AVCodecContext *avctx) seq->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_PAL8; - avcodec_get_frame_defaults(&seq->frame); + seq->frame = av_frame_alloc(); + if (!seq->frame) + return AVERROR(ENOMEM); return 0; } @@ -232,7 +234,7 @@ static int seqvideo_decode_frame(AVCodecContext *avctx, SeqVideoContext *seq = avctx->priv_data; - if ((ret = ff_reget_buffer(avctx, &seq->frame)) < 0) { + if ((ret = ff_reget_buffer(avctx, seq->frame)) < 0) { av_log(seq->avctx, AV_LOG_ERROR, "tiertexseqvideo: reget_buffer() failed\n"); return ret; } @@ -240,7 +242,7 @@ static int seqvideo_decode_frame(AVCodecContext *avctx, if (seqvideo_decode(seq, buf, buf_size)) return AVERROR_INVALIDDATA; - if ((ret = av_frame_ref(data, &seq->frame)) < 0) + if ((ret = av_frame_ref(data, seq->frame)) < 0) return ret; *got_frame = 1; @@ -251,7 +253,7 @@ static av_cold int seqvideo_decode_end(AVCodecContext *avctx) { SeqVideoContext *seq = avctx->priv_data; - av_frame_unref(&seq->frame); + av_frame_free(&seq->frame); return 0; }