From 4a8a35bc1ffe5a5f06393e81b8c22aa22fd28496 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/4] cinepak: use the AVFrame API properly. --- libavcodec/cinepak.c | 128 ++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c index 3167a23eb5..caf14cbfcf 100644 --- a/libavcodec/cinepak.c +++ b/libavcodec/cinepak.c @@ -58,7 +58,7 @@ typedef struct { typedef struct CinepakContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; const unsigned char *data; int size; @@ -138,14 +138,14 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip, for (y=strip->y1; y < strip->y2; y+=4) { - iy[0] = strip->x1 + (y * s->frame.linesize[0]); - iy[1] = iy[0] + s->frame.linesize[0]; - iy[2] = iy[1] + s->frame.linesize[0]; - iy[3] = iy[2] + s->frame.linesize[0]; - iu[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[1]); - iu[1] = iu[0] + s->frame.linesize[1]; - iv[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[2]); - iv[1] = iv[0] + s->frame.linesize[2]; + iy[0] = strip->x1 + (y * s->frame->linesize[0]); + iy[1] = iy[0] + s->frame->linesize[0]; + iy[2] = iy[1] + s->frame->linesize[0]; + iy[3] = iy[2] + s->frame->linesize[0]; + iu[0] = (strip->x1/2) + ((y/2) * s->frame->linesize[1]); + iu[1] = iu[0] + s->frame->linesize[1]; + iv[0] = (strip->x1/2) + ((y/2) * s->frame->linesize[2]); + iv[1] = iv[0] + s->frame->linesize[2]; for (x=strip->x1; x < strip->x2; x+=4) { if ((chunk_id & 0x01) && !(mask >>= 1)) { @@ -172,40 +172,40 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip, return AVERROR_INVALIDDATA; codebook = &strip->v1_codebook[*data++]; - s->frame.data[0][iy[0] + 0] = codebook->y0; - s->frame.data[0][iy[0] + 1] = codebook->y0; - s->frame.data[0][iy[1] + 0] = codebook->y0; - s->frame.data[0][iy[1] + 1] = codebook->y0; + s->frame->data[0][iy[0] + 0] = codebook->y0; + s->frame->data[0][iy[0] + 1] = codebook->y0; + s->frame->data[0][iy[1] + 0] = codebook->y0; + s->frame->data[0][iy[1] + 1] = codebook->y0; if (!s->palette_video) { - s->frame.data[1][iu[0]] = codebook->u; - s->frame.data[2][iv[0]] = codebook->v; + s->frame->data[1][iu[0]] = codebook->u; + s->frame->data[2][iv[0]] = codebook->v; } - s->frame.data[0][iy[0] + 2] = codebook->y1; - s->frame.data[0][iy[0] + 3] = codebook->y1; - s->frame.data[0][iy[1] + 2] = codebook->y1; - s->frame.data[0][iy[1] + 3] = codebook->y1; + s->frame->data[0][iy[0] + 2] = codebook->y1; + s->frame->data[0][iy[0] + 3] = codebook->y1; + s->frame->data[0][iy[1] + 2] = codebook->y1; + s->frame->data[0][iy[1] + 3] = codebook->y1; if (!s->palette_video) { - s->frame.data[1][iu[0] + 1] = codebook->u; - s->frame.data[2][iv[0] + 1] = codebook->v; + s->frame->data[1][iu[0] + 1] = codebook->u; + s->frame->data[2][iv[0] + 1] = codebook->v; } - s->frame.data[0][iy[2] + 0] = codebook->y2; - s->frame.data[0][iy[2] + 1] = codebook->y2; - s->frame.data[0][iy[3] + 0] = codebook->y2; - s->frame.data[0][iy[3] + 1] = codebook->y2; + s->frame->data[0][iy[2] + 0] = codebook->y2; + s->frame->data[0][iy[2] + 1] = codebook->y2; + s->frame->data[0][iy[3] + 0] = codebook->y2; + s->frame->data[0][iy[3] + 1] = codebook->y2; if (!s->palette_video) { - s->frame.data[1][iu[1]] = codebook->u; - s->frame.data[2][iv[1]] = codebook->v; + s->frame->data[1][iu[1]] = codebook->u; + s->frame->data[2][iv[1]] = codebook->v; } - s->frame.data[0][iy[2] + 2] = codebook->y3; - s->frame.data[0][iy[2] + 3] = codebook->y3; - s->frame.data[0][iy[3] + 2] = codebook->y3; - s->frame.data[0][iy[3] + 3] = codebook->y3; + s->frame->data[0][iy[2] + 2] = codebook->y3; + s->frame->data[0][iy[2] + 3] = codebook->y3; + s->frame->data[0][iy[3] + 2] = codebook->y3; + s->frame->data[0][iy[3] + 3] = codebook->y3; if (!s->palette_video) { - s->frame.data[1][iu[1] + 1] = codebook->u; - s->frame.data[2][iv[1] + 1] = codebook->v; + s->frame->data[1][iu[1] + 1] = codebook->u; + s->frame->data[2][iv[1] + 1] = codebook->v; } } else if (flag & mask) { @@ -213,43 +213,43 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip, return AVERROR_INVALIDDATA; codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[0] + 0] = codebook->y0; - s->frame.data[0][iy[0] + 1] = codebook->y1; - s->frame.data[0][iy[1] + 0] = codebook->y2; - s->frame.data[0][iy[1] + 1] = codebook->y3; + s->frame->data[0][iy[0] + 0] = codebook->y0; + s->frame->data[0][iy[0] + 1] = codebook->y1; + s->frame->data[0][iy[1] + 0] = codebook->y2; + s->frame->data[0][iy[1] + 1] = codebook->y3; if (!s->palette_video) { - s->frame.data[1][iu[0]] = codebook->u; - s->frame.data[2][iv[0]] = codebook->v; + s->frame->data[1][iu[0]] = codebook->u; + s->frame->data[2][iv[0]] = codebook->v; } codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[0] + 2] = codebook->y0; - s->frame.data[0][iy[0] + 3] = codebook->y1; - s->frame.data[0][iy[1] + 2] = codebook->y2; - s->frame.data[0][iy[1] + 3] = codebook->y3; + s->frame->data[0][iy[0] + 2] = codebook->y0; + s->frame->data[0][iy[0] + 3] = codebook->y1; + s->frame->data[0][iy[1] + 2] = codebook->y2; + s->frame->data[0][iy[1] + 3] = codebook->y3; if (!s->palette_video) { - s->frame.data[1][iu[0] + 1] = codebook->u; - s->frame.data[2][iv[0] + 1] = codebook->v; + s->frame->data[1][iu[0] + 1] = codebook->u; + s->frame->data[2][iv[0] + 1] = codebook->v; } codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[2] + 0] = codebook->y0; - s->frame.data[0][iy[2] + 1] = codebook->y1; - s->frame.data[0][iy[3] + 0] = codebook->y2; - s->frame.data[0][iy[3] + 1] = codebook->y3; + s->frame->data[0][iy[2] + 0] = codebook->y0; + s->frame->data[0][iy[2] + 1] = codebook->y1; + s->frame->data[0][iy[3] + 0] = codebook->y2; + s->frame->data[0][iy[3] + 1] = codebook->y3; if (!s->palette_video) { - s->frame.data[1][iu[1]] = codebook->u; - s->frame.data[2][iv[1]] = codebook->v; + s->frame->data[1][iu[1]] = codebook->u; + s->frame->data[2][iv[1]] = codebook->v; } codebook = &strip->v4_codebook[*data++]; - s->frame.data[0][iy[2] + 2] = codebook->y0; - s->frame.data[0][iy[2] + 3] = codebook->y1; - s->frame.data[0][iy[3] + 2] = codebook->y2; - s->frame.data[0][iy[3] + 3] = codebook->y3; + s->frame->data[0][iy[2] + 2] = codebook->y0; + s->frame->data[0][iy[2] + 3] = codebook->y1; + s->frame->data[0][iy[3] + 2] = codebook->y2; + s->frame->data[0][iy[3] + 3] = codebook->y3; if (!s->palette_video) { - s->frame.data[1][iu[1] + 1] = codebook->u; - s->frame.data[2][iv[1] + 1] = codebook->v; + s->frame->data[1][iu[1] + 1] = codebook->u; + s->frame->data[2][iv[1] + 1] = codebook->v; } } @@ -414,7 +414,9 @@ static av_cold int cinepak_decode_init(AVCodecContext *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; } @@ -430,7 +432,7 @@ static int cinepak_decode_frame(AVCodecContext *avctx, s->data = buf; s->size = buf_size; - if ((ret = ff_reget_buffer(avctx, &s->frame))) { + if ((ret = ff_reget_buffer(avctx, s->frame))) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } @@ -438,7 +440,7 @@ static int cinepak_decode_frame(AVCodecContext *avctx, if (s->palette_video) { const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { - s->frame.palette_has_changed = 1; + s->frame->palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } } @@ -446,9 +448,9 @@ static int cinepak_decode_frame(AVCodecContext *avctx, cinepak_decode(s); if (s->palette_video) - memcpy (s->frame.data[1], s->pal, AVPALETTE_SIZE); + memcpy (s->frame->data[1], s->pal, AVPALETTE_SIZE); - if ((ret = av_frame_ref(data, &s->frame)) < 0) + if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; *got_frame = 1; @@ -461,7 +463,7 @@ static av_cold int cinepak_decode_end(AVCodecContext *avctx) { CinepakContext *s = avctx->priv_data; - av_frame_unref(&s->frame); + av_frame_free(&s->frame); return 0; } From 845020ed89caca12af3470289af9c9626e71e0ea Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 2/4] cljr: use the AVFrame API properly. --- libavcodec/cljr.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index f6dbb768a0..ad0f729768 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -98,16 +98,18 @@ AVCodec ff_cljr_decoder = { #endif #if CONFIG_CLJR_ENCODER -typedef struct CLJRContext { - AVFrame picture; -} CLJRContext; - static av_cold int encode_init(AVCodecContext *avctx) { - CLJRContext * const a = avctx->priv_data; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); - avctx->coded_frame = &a->picture; + return 0; +} +static av_cold int encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); return 0; } @@ -155,9 +157,9 @@ AVCodec ff_cljr_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_CLJR, - .priv_data_size = sizeof(CLJRContext), .init = encode_init, .encode2 = encode_frame, + .close = encode_close, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV411P, AV_PIX_FMT_NONE }, }; From 224b6edd8beacdb46f90c1ff23a35d3523a54728 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 3/4] qtrle: use the AVFrame API properly. --- libavcodec/qtrle.c | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c index f41569ad0a..28f1720aea 100644 --- a/libavcodec/qtrle.c +++ b/libavcodec/qtrle.c @@ -41,7 +41,7 @@ typedef struct QtrleContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; GetByteContext g; uint32_t pal[256]; @@ -58,10 +58,10 @@ static void qtrle_decode_1bpp(QtrleContext *s, int row_ptr, int lines_to_change) { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char pi0, pi1; /* 2 8-pixel values */ - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; int skip; row_ptr -= row_inc; @@ -110,10 +110,10 @@ static inline void qtrle_decode_2n4bpp(QtrleContext *s, int row_ptr, { int rle_code, i; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char pi[16]; /* 16 palette indices */ - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; int num_pixels = (bpp == 4) ? 8 : 16; while (lines_to_change--) { @@ -166,10 +166,10 @@ static void qtrle_decode_8bpp(QtrleContext *s, int row_ptr, int lines_to_change) { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char pi1, pi2, pi3, pi4; /* 4 palette indexes */ - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (4 * (bytestream2_get_byte(&s->g) - 1)); @@ -216,10 +216,10 @@ static void qtrle_decode_16bpp(QtrleContext *s, int row_ptr, int lines_to_change { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned short rgb16; - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 2; @@ -260,10 +260,10 @@ static void qtrle_decode_24bpp(QtrleContext *s, int row_ptr, int lines_to_change { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned char r, g, b; - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 3; @@ -307,10 +307,10 @@ static void qtrle_decode_32bpp(QtrleContext *s, int row_ptr, int lines_to_change { int rle_code; int pixel_ptr; - int row_inc = s->frame.linesize[0]; + int row_inc = s->frame->linesize[0]; unsigned int argb; - unsigned char *rgb = s->frame.data[0]; - int pixel_limit = s->frame.linesize[0] * s->avctx->height; + unsigned char *rgb = s->frame->data[0]; + int pixel_limit = s->frame->linesize[0] * s->avctx->height; while (lines_to_change--) { pixel_ptr = row_ptr + (bytestream2_get_byte(&s->g) - 1) * 4; @@ -385,7 +385,9 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - avcodec_get_frame_defaults(&s->frame); + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); return 0; } @@ -401,7 +403,7 @@ static int qtrle_decode_frame(AVCodecContext *avctx, int ret; bytestream2_init(&s->g, avpkt->data, avpkt->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; } @@ -428,7 +430,7 @@ static int qtrle_decode_frame(AVCodecContext *avctx, start_line = 0; height = s->avctx->height; } - row_ptr = s->frame.linesize[0] * start_line; + row_ptr = s->frame->linesize[0] * start_line; switch (avctx->bits_per_coded_sample) { case 1: @@ -476,16 +478,16 @@ static int qtrle_decode_frame(AVCodecContext *avctx, const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { - s->frame.palette_has_changed = 1; + s->frame->palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } /* make the palette available on the way out */ - memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); } done: - if ((ret = av_frame_ref(data, &s->frame)) < 0) + if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; *got_frame = 1; @@ -497,7 +499,7 @@ static av_cold int qtrle_decode_end(AVCodecContext *avctx) { QtrleContext *s = avctx->priv_data; - av_frame_unref(&s->frame); + av_frame_free(&s->frame); return 0; } From a639ea7f4bc44bf6bfa452675558a342924a66a9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 4/4] escape124: use the AVFrame API properly. --- libavcodec/escape124.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c index 4e4b9080e4..30f22e0031 100644 --- a/libavcodec/escape124.c +++ b/libavcodec/escape124.c @@ -42,7 +42,7 @@ typedef struct CodeBook { } CodeBook; typedef struct Escape124Context { - AVFrame frame; + AVFrame *frame; unsigned num_superblocks; @@ -67,6 +67,10 @@ static av_cold int escape124_decode_init(AVCodecContext *avctx) s->num_superblocks = ((unsigned)avctx->width / 8) * ((unsigned)avctx->height / 8); + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); + return 0; } @@ -78,7 +82,7 @@ static av_cold int escape124_decode_close(AVCodecContext *avctx) for (i = 0; i < 3; i++) av_free(s->codebooks[i].blocks); - av_frame_unref(&s->frame); + av_frame_free(&s->frame); return 0; } @@ -229,13 +233,13 @@ static int escape124_decode_frame(AVCodecContext *avctx, // Leave last frame unchanged // FIXME: Is this necessary? I haven't seen it in any real samples if (!(frame_flags & 0x114) || !(frame_flags & 0x7800000)) { - if (!s->frame.data[0]) + if (!s->frame->data[0]) return AVERROR_INVALIDDATA; av_log(NULL, AV_LOG_DEBUG, "Skipping frame\n"); *got_frame = 1; - if ((ret = av_frame_ref(frame, &s->frame)) < 0) + if ((ret = av_frame_ref(frame, s->frame)) < 0) return ret; return frame_size; @@ -276,8 +280,8 @@ static int escape124_decode_frame(AVCodecContext *avctx, new_frame_data = (uint16_t*)frame->data[0]; new_stride = frame->linesize[0] / 2; - old_frame_data = (uint16_t*)s->frame.data[0]; - old_stride = s->frame.linesize[0] / 2; + old_frame_data = (uint16_t*)s->frame->data[0]; + old_stride = s->frame->linesize[0] / 2; for (superblock_index = 0; superblock_index < s->num_superblocks; superblock_index++) { @@ -356,8 +360,8 @@ static int escape124_decode_frame(AVCodecContext *avctx, "Escape sizes: %i, %i, %i\n", frame_size, buf_size, get_bits_count(&gb) / 8); - av_frame_unref(&s->frame); - if ((ret = av_frame_ref(&s->frame, frame)) < 0) + av_frame_unref(s->frame); + if ((ret = av_frame_ref(s->frame, frame)) < 0) return ret; *got_frame = 1;