[FFmpeg-devel] [PATCH 1/3] avcodec/qpeg: remove an unnecessary intermediary AVFrame

James Almer jamrial at gmail.com
Fri Apr 17 06:10:06 EEST 2020


Decoding can be handled directly in the output frame.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/qpeg.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index d4195c5f0b..3fde6381f2 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -30,7 +30,7 @@
 
 typedef struct QpegContext{
     AVCodecContext *avctx;
-    AVFrame *pic, *ref;
+    AVFrame *ref;
     uint32_t pal[256];
     GetByteContext buffer;
 } QpegContext;
@@ -267,7 +267,7 @@ static int decode_frame(AVCodecContext *avctx,
 {
     uint8_t ctable[128];
     QpegContext * const a = avctx->priv_data;
-    AVFrame * const p = a->pic;
+    AVFrame * const p = data;
     AVFrame * const ref = a->ref;
     uint8_t* outdata;
     int delta, ret;
@@ -281,9 +281,6 @@ static int decode_frame(AVCodecContext *avctx,
 
     bytestream2_init(&a->buffer, avpkt->data, avpkt->size);
 
-    av_frame_unref(ref);
-    av_frame_move_ref(ref, p);
-
     if ((ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF)) < 0)
         return ret;
     outdata = p->data[0];
@@ -307,7 +304,8 @@ static int decode_frame(AVCodecContext *avctx,
     }
     memcpy(p->data[1], a->pal, AVPALETTE_SIZE);
 
-    if ((ret = av_frame_ref(data, p)) < 0)
+    av_frame_unref(ref);
+    if ((ret = av_frame_ref(ref, p)) < 0)
         return ret;
 
     *got_frame      = 1;
@@ -320,6 +318,8 @@ static void decode_flush(AVCodecContext *avctx){
     int i, pal_size;
     const uint8_t *pal_src;
 
+    av_frame_unref(a->ref);
+
     pal_size = FFMIN(1024U, avctx->extradata_size);
     pal_src = avctx->extradata + avctx->extradata_size - pal_size;
 
@@ -331,7 +331,6 @@ static av_cold int decode_end(AVCodecContext *avctx)
 {
     QpegContext * const a = avctx->priv_data;
 
-    av_frame_free(&a->pic);
     av_frame_free(&a->ref);
 
     return 0;
@@ -343,14 +342,11 @@ static av_cold int decode_init(AVCodecContext *avctx){
     a->avctx = avctx;
     avctx->pix_fmt= AV_PIX_FMT_PAL8;
 
-    decode_flush(avctx);
-
-    a->pic = av_frame_alloc();
     a->ref = av_frame_alloc();
-    if (!a->pic || !a->ref) {
-        decode_end(avctx);
+    if (!a->ref)
         return AVERROR(ENOMEM);
-    }
+
+    decode_flush(avctx);
 
     return 0;
 }
-- 
2.26.0



More information about the ffmpeg-devel mailing list