From 78c6c9d6c1ac4f2041854bb3715460681d589fb1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/4] pngenc: use the AVFrame API properly. --- libavcodec/pngenc.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index f39fadd4c6..f58f7158a3 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -37,7 +37,6 @@ typedef struct PNGEncContext { uint8_t *bytestream; uint8_t *bytestream_start; uint8_t *bytestream_end; - AVFrame picture; int filter_type; @@ -231,7 +230,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { PNGEncContext *s = avctx->priv_data; - AVFrame * const p= &s->picture; + const AVFrame * const p = pict; int bit_depth, color_type, y, len, row_size, ret, is_progressive; int bits_per_pixel, pass_row_size, enc_row_size, max_packet_size; int compression_level; @@ -241,10 +240,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *rgba_buf = NULL; uint8_t *top_buf = NULL; - *p = *pict; - p->pict_type= AV_PICTURE_TYPE_I; - p->key_frame= 1; - is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT); switch(avctx->pix_fmt) { case AV_PIX_FMT_RGB32: @@ -444,8 +439,13 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, static av_cold int png_enc_init(AVCodecContext *avctx){ PNGEncContext *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); + + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; + ff_dsputil_init(&s->dsp, avctx); s->filter_type = av_clip(avctx->prediction_method, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED); @@ -455,6 +455,12 @@ static av_cold int png_enc_init(AVCodecContext *avctx){ return 0; } +static av_cold int png_enc_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + AVCodec ff_png_encoder = { .name = "png", .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"), @@ -462,6 +468,7 @@ AVCodec ff_png_encoder = { .id = AV_CODEC_ID_PNG, .priv_data_size = sizeof(PNGEncContext), .init = png_enc_init, + .close = png_enc_close, .encode2 = encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB32, AV_PIX_FMT_PAL8, AV_PIX_FMT_GRAY8, From f26f71139faf3dfd23d0b7738178f233fe64247d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 2/4] tiffenc: use the AVFrame API properly. --- libavcodec/tiffenc.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c index 528673b234..4cbc51746d 100644 --- a/libavcodec/tiffenc.c +++ b/libavcodec/tiffenc.c @@ -50,7 +50,6 @@ static const uint8_t type_sizes2[6] = { typedef struct TiffEncoderContext { AVClass *class; ///< for private options AVCodecContext *avctx; - AVFrame picture; int width; ///< picture width int height; ///< picture height @@ -184,9 +183,9 @@ static int encode_strip(TiffEncoderContext *s, const int8_t *src, } } -static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum) +static void pack_yuv(TiffEncoderContext *s, const AVFrame *p, + uint8_t *dst, int lnum) { - AVFrame *p = &s->picture; int i, j, k; int w = (s->width - 1) / s->subsampling[0] + 1; uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]]; @@ -205,7 +204,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { TiffEncoderContext *s = avctx->priv_data; - AVFrame *const p = &s->picture; + const AVFrame *const p = pict; int i; uint8_t *ptr; uint8_t *offset; @@ -223,11 +222,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->avctx = avctx; - *p = *pict; - p->pict_type = AV_PICTURE_TYPE_I; - p->key_frame = 1; - avctx->coded_frame = &s->picture; - s->width = avctx->width; s->height = avctx->height; s->subsampling[0] = 1; @@ -349,7 +343,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, zn = 0; for (j = 0; j < s->rps; j++) { if (is_yuv) { - pack_yuv(s, yuv_line, j); + pack_yuv(s, p, yuv_line, j); memcpy(zbuf + zn, yuv_line, bytes_per_row); j += s->subsampling[1] - 1; } else @@ -384,7 +378,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, strip_offsets[i / s->rps] = ptr - pkt->data; } if (is_yuv) { - pack_yuv(s, yuv_line, i); + pack_yuv(s, p, yuv_line, i); ret = encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr); i += s->subsampling[1] - 1; } else @@ -470,6 +464,24 @@ fail: return ret; } +static av_cold int encode_init(AVCodecContext *avctx) +{ + 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; + + return 0; +} + +static av_cold int encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + #define OFFSET(x) offsetof(TiffEncoderContext, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -496,6 +508,8 @@ AVCodec ff_tiff_encoder = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_TIFF, .priv_data_size = sizeof(TiffEncoderContext), + .init = encode_init, + .close = encode_close, .encode2 = encode_frame, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48LE, AV_PIX_FMT_PAL8, From fb26d761676ffbf3394b767b9c199947c160c344 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 3/4] targaenc: use the AVFrame API properly. --- libavcodec/targaenc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c index 610621fcc3..7679029643 100644 --- a/libavcodec/targaenc.c +++ b/libavcodec/targaenc.c @@ -29,10 +29,6 @@ #include "rle.h" #include "targa.h" -typedef struct TargaContext { - AVFrame picture; -} TargaContext; - /** * RLE compress the image, with maximum size of out_size * @param outbuf Output buffer @@ -154,23 +150,29 @@ static int targa_encode_frame(AVCodecContext *avctx, AVPacket *pkt, static av_cold int targa_encode_init(AVCodecContext *avctx) { - TargaContext *s = avctx->priv_data; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); - avcodec_get_frame_defaults(&s->picture); - s->picture.key_frame= 1; - s->picture.pict_type = AV_PICTURE_TYPE_I; - avctx->coded_frame= &s->picture; + avctx->coded_frame->key_frame = 1; + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; return 0; } +static av_cold int targa_encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + AVCodec ff_targa_encoder = { .name = "targa", .long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_TARGA, - .priv_data_size = sizeof(TargaContext), .init = targa_encode_init, + .close = targa_encode_close, .encode2 = targa_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_BGR24, AV_PIX_FMT_BGRA, AV_PIX_FMT_RGB555LE, AV_PIX_FMT_GRAY8, From 45bde93eefa78c1bdb0936109fbd2e2fb27fbfe7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 4/4] sunrastenc: use the AVFrame API properly. --- libavcodec/sunrastenc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavcodec/sunrastenc.c b/libavcodec/sunrastenc.c index 58d0fb8d31..25ae9bd039 100644 --- a/libavcodec/sunrastenc.c +++ b/libavcodec/sunrastenc.c @@ -25,7 +25,6 @@ #include "sunrast.h" typedef struct SUNRASTContext { - AVFrame picture; PutByteContext p; int depth; ///< depth of pixel int length; ///< length (bytes) of image @@ -154,7 +153,10 @@ static av_cold int sunrast_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - avctx->coded_frame = &s->picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + avctx->coded_frame->key_frame = 1; avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; s->maptype = RMT_NONE; @@ -207,6 +209,12 @@ static int sunrast_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return 0; } +static av_cold int sunrast_encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + static const AVCodecDefault sunrast_defaults[] = { { "coder", "rle" }, { NULL }, @@ -219,6 +227,7 @@ AVCodec ff_sunrast_encoder = { .id = AV_CODEC_ID_SUNRAST, .priv_data_size = sizeof(SUNRASTContext), .init = sunrast_encode_init, + .close = sunrast_encode_close, .encode2 = sunrast_encode_frame, .defaults = sunrast_defaults, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_BGR24,