From 13e9cc9ce0646ba8e31d837b5e6372ec80fa7a73 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/2] a64multienc: use the AVFrame API properly. --- libavcodec/a64enc.h | 3 --- libavcodec/a64multienc.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/a64enc.h b/libavcodec/a64enc.h index d5f8e9ac99..65c1d30951 100644 --- a/libavcodec/a64enc.h +++ b/libavcodec/a64enc.h @@ -34,9 +34,6 @@ #define C64YRES 200 typedef struct A64Context { - /* general variables */ - AVFrame picture; - /* variables for multicolor modes */ AVLFG randctx; int mc_lifetime; diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c index f2c6c4a357..11d6e2c300 100644 --- a/libavcodec/a64multienc.c +++ b/libavcodec/a64multienc.c @@ -165,6 +165,7 @@ static void render_charset(AVCodecContext *avctx, uint8_t *charset, static av_cold int a64multi_close_encoder(AVCodecContext *avctx) { A64Context *c = avctx->priv_data; + av_frame_free(&avctx->coded_frame); av_free(c->mc_meta_charset); av_free(c->mc_best_cb); av_free(c->mc_charset); @@ -216,8 +217,12 @@ static av_cold int a64multi_init_encoder(AVCodecContext *avctx) AV_WB32(avctx->extradata, c->mc_lifetime); AV_WB32(avctx->extradata + 16, INTERLACED); - avcodec_get_frame_defaults(&c->picture); - avctx->coded_frame = &c->picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) { + a64multi_close_encoder(avctx); + return AVERROR(ENOMEM); + } + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->key_frame = 1; if (!avctx->codec_tag) @@ -247,7 +252,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { A64Context *c = avctx->priv_data; - AVFrame *const p = &c->picture; + AVFrame *const p = avctx->coded_frame; int frame; int x, y; From 6139f481ac9feb1bee4e7d04789fb15d7f24ebbf Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 2/2] asvenc: use the AVFrame API properly. --- libavcodec/asv.c | 1 - libavcodec/asv.h | 1 - libavcodec/asvenc.c | 33 ++++++++++++++++++--------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/libavcodec/asv.c b/libavcodec/asv.c index f6788c9245..9e3a023cc5 100644 --- a/libavcodec/asv.c +++ b/libavcodec/asv.c @@ -89,6 +89,5 @@ av_cold void ff_asv_common_init(AVCodecContext *avctx) { a->mb_width2 = (avctx->width + 0) / 16; a->mb_height2 = (avctx->height + 0) / 16; - avctx->coded_frame= &a->picture; a->avctx= avctx; } diff --git a/libavcodec/asv.h b/libavcodec/asv.h index 228bd18186..3e56857d22 100644 --- a/libavcodec/asv.h +++ b/libavcodec/asv.h @@ -38,7 +38,6 @@ typedef struct ASV1Context{ AVCodecContext *avctx; DSPContext dsp; - AVFrame picture; PutBitContext pb; GetBitContext gb; ScanTable scantable; diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c index 9dd5e08312..40257f0c7f 100644 --- a/libavcodec/asvenc.c +++ b/libavcodec/asvenc.c @@ -147,14 +147,16 @@ static inline int encode_mb(ASV1Context *a, int16_t block[6][64]){ return 0; } -static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){ +static inline void dct_get(ASV1Context *a, const AVFrame *frame, + int mb_x, int mb_y) +{ int16_t (*block)[64]= a->block; - int linesize= a->picture.linesize[0]; + int linesize = frame->linesize[0]; int i; - uint8_t *ptr_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; - uint8_t *ptr_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; - uint8_t *ptr_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; + uint8_t *ptr_y = frame->data[0] + (mb_y * 16* linesize ) + mb_x * 16; + uint8_t *ptr_cb = frame->data[1] + (mb_y * 8 * frame->linesize[1]) + mb_x * 8; + uint8_t *ptr_cr = frame->data[2] + (mb_y * 8 * frame->linesize[2]) + mb_x * 8; a->dsp.get_pixels(block[0], ptr_y , linesize); a->dsp.get_pixels(block[1], ptr_y + 8, linesize); @@ -164,8 +166,8 @@ static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){ a->dsp.fdct(block[i]); if(!(a->avctx->flags&CODEC_FLAG_GRAY)){ - a->dsp.get_pixels(block[4], ptr_cb, a->picture.linesize[1]); - a->dsp.get_pixels(block[5], ptr_cr, a->picture.linesize[2]); + a->dsp.get_pixels(block[4], ptr_cb, frame->linesize[1]); + a->dsp.get_pixels(block[5], ptr_cr, frame->linesize[2]); for(i=4; i<6; i++) a->dsp.fdct(block[i]); } @@ -175,7 +177,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { ASV1Context * const a = avctx->priv_data; - AVFrame * const p= &a->picture; int size, ret; int mb_x, mb_y; @@ -188,13 +189,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, init_put_bits(&a->pb, pkt->data, pkt->size); - *p = *pict; - p->pict_type= AV_PICTURE_TYPE_I; - p->key_frame= 1; - for(mb_y=0; mb_ymb_height2; mb_y++){ for(mb_x=0; mb_xmb_width2; mb_x++){ - dct_get(a, mb_x, mb_y); + dct_get(a, pict, mb_x, mb_y); encode_mb(a, a->block); } } @@ -202,7 +199,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, if(a->mb_width2 != a->mb_width){ mb_x= a->mb_width2; for(mb_y=0; mb_ymb_height2; mb_y++){ - dct_get(a, mb_x, mb_y); + dct_get(a, pict, mb_x, mb_y); encode_mb(a, a->block); } } @@ -210,7 +207,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, if(a->mb_height2 != a->mb_height){ mb_y= a->mb_height2; for(mb_x=0; mb_xmb_width; mb_x++){ - dct_get(a, mb_x, mb_y); + dct_get(a, pict, mb_x, mb_y); encode_mb(a, a->block); } } @@ -242,6 +239,12 @@ static av_cold int encode_init(AVCodecContext *avctx){ int i; const int scale= avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2; + 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_asv_common_init(avctx); if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE;