From 372262853b31cfde542ce1e3e1c154e590e35476 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/4] libschroedingerenc: use the AVFrame API properly. --- libavcodec/libschroedingerenc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c index e4789ee7c2..11cc0ebd31 100644 --- a/libavcodec/libschroedingerenc.c +++ b/libavcodec/libschroedingerenc.c @@ -49,9 +49,6 @@ typedef struct SchroEncoderParams { /** Schroedinger frame format */ SchroFrameFormat frame_format; - /** frame being encoded */ - AVFrame picture; - /** frame size */ int frame_size; @@ -164,7 +161,9 @@ static av_cold int libschroedinger_encode_init(AVCodecContext *avctx) avctx->width, avctx->height); - avctx->coded_frame = &p_schro_params->picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); if (!avctx->gop_size) { schro_encoder_setting_set_double(p_schro_params->encoder, @@ -432,6 +431,8 @@ static int libschroedinger_encode_close(AVCodecContext *avctx) /* Free the video format structure. */ av_freep(&p_schro_params->format); + av_frame_free(&avctx->coded_frame); + return 0; } From 7ca97aa7ee469b6ca8552f489f20c071aa652ab1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 14:57:55 +0100 Subject: [PATCH 2/4] roqvideo: remove unused variables --- libavcodec/roqvideo.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/roqvideo.h b/libavcodec/roqvideo.h index eed2f226fe..3f000225e9 100644 --- a/libavcodec/roqvideo.h +++ b/libavcodec/roqvideo.h @@ -44,7 +44,6 @@ struct RoqTempData; typedef struct RoqContext { AVCodecContext *avctx; - AVFrame frames[2]; AVFrame *last_frame; AVFrame *current_frame; int first_frame; From 863a670e483daaf7c4646e4636d56ac25b539c8f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 3/4] pcxenc: use the AVFrame API properly. --- libavcodec/pcxenc.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/libavcodec/pcxenc.c b/libavcodec/pcxenc.c index 4c08fba8bb..4bf7377f19 100644 --- a/libavcodec/pcxenc.c +++ b/libavcodec/pcxenc.c @@ -30,22 +30,26 @@ #include "bytestream.h" #include "internal.h" -typedef struct PCXContext { - AVFrame picture; -} PCXContext; - static const uint32_t monoblack_pal[16] = { 0x000000, 0xFFFFFF }; static av_cold int pcx_encode_init(AVCodecContext *avctx) { - PCXContext *s = avctx->priv_data; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); - avcodec_get_frame_defaults(&s->picture); - avctx->coded_frame = &s->picture; + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; return 0; } +static av_cold int pcx_encode_close(AVCodecContext *avctx) +{ + av_frame_free(&avctx->coded_frame); + return 0; +} + /** * PCX run-length encoder * @param dst output buffer @@ -99,8 +103,6 @@ static int pcx_rle_encode( uint8_t *dst, int dst_size, static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { - PCXContext *s = avctx->priv_data; - AVFrame *const pict = &s->picture; const uint8_t *buf_end; uint8_t *buf; @@ -108,10 +110,6 @@ static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const uint32_t *pal = NULL; const uint8_t *src; - *pict = *frame; - pict->pict_type = AV_PICTURE_TYPE_I; - pict->key_frame = 1; - if (avctx->width > 65535 || avctx->height > 65535) { av_log(avctx, AV_LOG_ERROR, "image dimensions do not fit in 16 bits\n"); return -1; @@ -130,7 +128,7 @@ static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, case AV_PIX_FMT_PAL8: bpp = 8; nplanes = 1; - pal = (uint32_t *)pict->data[1]; + pal = (uint32_t *)frame->data[1]; break; case AV_PIX_FMT_MONOBLACK: bpp = 1; @@ -172,7 +170,7 @@ static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, while (buf - pkt->data < 128) *buf++= 0; - src = pict->data[0]; + src = frame->data[0]; for (y = 0; y < avctx->height; y++) { if ((written = pcx_rle_encode(buf, buf_end - buf, @@ -181,7 +179,7 @@ static int pcx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, return -1; } buf += written; - src += pict->linesize[0]; + src += frame->linesize[0]; } if (nplanes == 1 && bpp == 8) { @@ -207,8 +205,8 @@ AVCodec ff_pcx_encoder = { .long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_PCX, - .priv_data_size = sizeof(PCXContext), .init = pcx_encode_init, + .close = pcx_encode_close, .encode2 = pcx_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_RGB24, From ffe04c330335add4c6d70ab0bb98e6b3f4f7abfa Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 4/4] libxvid: use the AVFrame API properly. --- libavcodec/libxvid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 9a07207e3e..fe68c8ebcc 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -54,7 +54,6 @@ struct xvid_context { int me_flags; /**< Motion Estimation flags */ int qscale; /**< Do we use constant scale? */ int quicktime_format; /**< Are we in a QT-based format? */ - AVFrame encoded_picture; /**< Encoded frame information */ char *twopassbuffer; /**< Character buffer for two-pass */ char *old_twopassbuffer; /**< Old character buffer (two-pass) */ char *twopassfile; /**< second pass temp file name */ @@ -606,7 +605,9 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { } x->encoder_handle = xvid_enc_create.handle; - avctx->coded_frame = &x->encoded_picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); return 0; } @@ -617,7 +618,7 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int xerr, i, ret, user_packet = !!pkt->data; char *tmp; struct xvid_context *x = avctx->priv_data; - AVFrame *p = &x->encoded_picture; + AVFrame *p = avctx->coded_frame; int mb_width = (avctx->width + 15) / 16; int mb_height = (avctx->height + 15) / 16; @@ -633,7 +634,6 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, /* Start setting up the frame */ xvid_enc_frame.version = XVID_VERSION; xvid_enc_stats.version = XVID_VERSION; - *p = *picture; /* Let Xvid know where to put the frame. */ xvid_enc_frame.bitstream = pkt->data;