From 6a08d7fcc528aad1aff7a1e1e4ae9edd4f8048f2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/4] sgienc: use the AVFrame API properly. --- libavcodec/sgienc.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/libavcodec/sgienc.c b/libavcodec/sgienc.c index 6a595c75fb..902437f34d 100644 --- a/libavcodec/sgienc.c +++ b/libavcodec/sgienc.c @@ -28,16 +28,11 @@ #define SGI_SINGLE_CHAN 2 #define SGI_MULTI_CHAN 3 -typedef struct SgiContext { - AVFrame picture; -} SgiContext; - static av_cold int encode_init(AVCodecContext *avctx) { - SgiContext *s = avctx->priv_data; - - avcodec_get_frame_defaults(&s->picture); - avctx->coded_frame = &s->picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); return 0; } @@ -45,16 +40,14 @@ static av_cold int encode_init(AVCodecContext *avctx) static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { - SgiContext *s = avctx->priv_data; - AVFrame * const p = &s->picture; + const AVFrame * const p = frame; uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf, *buf; int x, y, z, length, tablesize, ret; unsigned int width, height, depth, dimension; unsigned char *end_buf; - *p = *frame; - p->pict_type = AV_PICTURE_TYPE_I; - p->key_frame = 1; + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; width = avctx->width; height = avctx->height; @@ -170,14 +163,20 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, return 0; } +static av_cold int encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + AVCodec ff_sgi_encoder = { .name = "sgi", .long_name = NULL_IF_CONFIG_SMALL("SGI image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_SGI, - .priv_data_size = sizeof(SgiContext), .init = encode_init, .encode2 = encode_frame, + .close = encode_close, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE }, From 2a85a192c710a4e4588ea831c042548838301bf9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 2/4] bmpenc: use the AVFrame API properly. --- libavcodec/bmp.h | 4 ---- libavcodec/bmpenc.c | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libavcodec/bmp.h b/libavcodec/bmp.h index ab11523379..a472f59d3c 100644 --- a/libavcodec/bmp.h +++ b/libavcodec/bmp.h @@ -24,10 +24,6 @@ #include "avcodec.h" -typedef struct BMPContext { - AVFrame picture; -} BMPContext; - typedef enum { BMP_RGB =0, BMP_RLE8 =1, diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c index 44e18cc193..a14fc61c15 100644 --- a/libavcodec/bmpenc.c +++ b/libavcodec/bmpenc.c @@ -31,11 +31,6 @@ static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F }; static const uint32_t rgb444_masks[] = { 0x0F00, 0x00F0, 0x000F }; static av_cold int bmp_encode_init(AVCodecContext *avctx){ - BMPContext *s = avctx->priv_data; - - avcodec_get_frame_defaults(&s->picture); - avctx->coded_frame = &s->picture; - switch (avctx->pix_fmt) { case AV_PIX_FMT_BGR24: avctx->bits_per_coded_sample = 24; @@ -61,22 +56,25 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){ return -1; } + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + return 0; } static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { - BMPContext *s = avctx->priv_data; - AVFrame * const p = &s->picture; + const AVFrame * const p = pict; int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize, ret; const uint32_t *pal = NULL; int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB; int bit_count = avctx->bits_per_coded_sample; uint8_t *ptr, *buf; - *p = *pict; - p->pict_type= AV_PICTURE_TYPE_I; - p->key_frame= 1; + + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; switch (avctx->pix_fmt) { case AV_PIX_FMT_RGB444: compression = BMP_BITFIELDS; @@ -159,14 +157,20 @@ static int bmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, return 0; } +static av_cold int bmp_encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + AVCodec ff_bmp_encoder = { .name = "bmp", .long_name = NULL_IF_CONFIG_SMALL("BMP (Windows and OS/2 bitmap)"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_BMP, - .priv_data_size = sizeof(BMPContext), .init = bmp_encode_init, .encode2 = bmp_encode_frame, + .close = bmp_encode_close, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB565, From 4e7e8055a7b63b91d7d29ec7eb65711d2d3432be Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 3/4] dpxenc: use the AVFrame API properly. --- libavcodec/dpxenc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c index 83a70a614a..22329338a9 100644 --- a/libavcodec/dpxenc.c +++ b/libavcodec/dpxenc.c @@ -26,7 +26,6 @@ #include "internal.h" typedef struct DPXContext { - AVFrame picture; int big_endian; int bits_per_component; int descriptor; @@ -36,7 +35,10 @@ static av_cold int encode_init(AVCodecContext *avctx) { DPXContext *s = avctx->priv_data; - avctx->coded_frame = &s->picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->key_frame = 1; @@ -173,6 +175,12 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, return 0; } +static av_cold int encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + AVCodec ff_dpx_encoder = { .name = "dpx", .long_name = NULL_IF_CONFIG_SMALL("DPX image"), @@ -181,6 +189,7 @@ AVCodec ff_dpx_encoder = { .priv_data_size = sizeof(DPXContext), .init = encode_init, .encode2 = encode_frame, + .close = encode_close, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, From e4155f15b35c4272a235f5521d2dc6c2aabdd462 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 4/4] eamad: use the AVFrame API properly. --- libavcodec/eamad.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c index 5de28c72da..22070a45f7 100644 --- a/libavcodec/eamad.c +++ b/libavcodec/eamad.c @@ -45,7 +45,7 @@ typedef struct MadContext { AVCodecContext *avctx; DSPContext dsp; - AVFrame last_frame; + AVFrame *last_frame; GetBitContext gb; void *bitstream_buf; unsigned int bitstream_buf_size; @@ -65,6 +65,11 @@ static av_cold int decode_init(AVCodecContext *avctx) ff_init_scantable_permutation(s->dsp.idct_permutation, FF_NO_IDCT_PERM); ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); ff_mpeg12_init_vlcs(); + + s->last_frame = av_frame_alloc(); + if (!s->last_frame) + return AVERROR(ENOMEM); + return 0; } @@ -84,14 +89,14 @@ static inline void comp_block(MadContext *t, AVFrame *frame, if (j < 4) { comp(frame->data[0] + (mb_y*16 + ((j&2)<<2))*frame->linesize[0] + mb_x*16 + ((j&1)<<3), frame->linesize[0], - t->last_frame.data[0] + (mb_y*16 + ((j&2)<<2) + mv_y)*t->last_frame.linesize[0] + mb_x*16 + ((j&1)<<3) + mv_x, - t->last_frame.linesize[0], add); + t->last_frame->data[0] + (mb_y*16 + ((j&2)<<2) + mv_y)*t->last_frame->linesize[0] + mb_x*16 + ((j&1)<<3) + mv_x, + t->last_frame->linesize[0], add); } else if (!(t->avctx->flags & CODEC_FLAG_GRAY)) { int index = j - 3; comp(frame->data[index] + (mb_y*8)*frame->linesize[index] + mb_x * 8, frame->linesize[index], - t->last_frame.data[index] + (mb_y * 8 + (mv_y/2))*t->last_frame.linesize[index] + mb_x * 8 + (mv_x/2), - t->last_frame.linesize[index], add); + t->last_frame->data[index] + (mb_y * 8 + (mv_y/2))*t->last_frame->linesize[index] + mb_x * 8 + (mv_x/2), + t->last_frame->linesize[index], add); } } @@ -250,7 +255,7 @@ static int decode_frame(AVCodecContext *avctx, buf += 16; if (avctx->width != width || avctx->height != height) { - av_frame_unref(&s->last_frame); + av_frame_unref(s->last_frame); if ((ret = ff_set_dimensions(avctx, width, height)) < 0) return ret; } @@ -260,17 +265,17 @@ static int decode_frame(AVCodecContext *avctx, return ret; } - if (inter && !s->last_frame.data[0]) { + if (inter && !s->last_frame->data[0]) { av_log(avctx, AV_LOG_WARNING, "Missing reference frame.\n"); - ret = ff_get_buffer(avctx, &s->last_frame, AV_GET_BUFFER_FLAG_REF); + ret = ff_get_buffer(avctx, s->last_frame, AV_GET_BUFFER_FLAG_REF); if (ret < 0) return ret; - memset(s->last_frame.data[0], 0, s->last_frame.height * - s->last_frame.linesize[0]); - memset(s->last_frame.data[1], 0x80, s->last_frame.height / 2 * - s->last_frame.linesize[1]); - memset(s->last_frame.data[2], 0x80, s->last_frame.height / 2 * - s->last_frame.linesize[2]); + memset(s->last_frame->data[0], 0, s->last_frame->height * + s->last_frame->linesize[0]); + memset(s->last_frame->data[1], 0x80, s->last_frame->height / 2 * + s->last_frame->linesize[1]); + memset(s->last_frame->data[2], 0x80, s->last_frame->height / 2 * + s->last_frame->linesize[2]); } av_fast_padded_malloc(&s->bitstream_buf, &s->bitstream_buf_size, @@ -287,8 +292,8 @@ static int decode_frame(AVCodecContext *avctx, *got_frame = 1; if (chunk_type != MADe_TAG) { - av_frame_unref(&s->last_frame); - if ((ret = av_frame_ref(&s->last_frame, frame)) < 0) + av_frame_unref(s->last_frame); + if ((ret = av_frame_ref(s->last_frame, frame)) < 0) return ret; } @@ -298,7 +303,7 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_end(AVCodecContext *avctx) { MadContext *t = avctx->priv_data; - av_frame_unref(&t->last_frame); + av_frame_free(&t->last_frame); av_free(t->bitstream_buf); return 0; }