diff options
author | James Almer <jamrial@gmail.com> | 2020-04-16 23:20:43 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2020-04-20 13:46:37 -0300 |
commit | 1b13023860a6ede2699153bcad0bbb8bb72f6e38 (patch) | |
tree | a6770084da817531fde89d63b0cee2fae4c1d588 | |
parent | 0fcf74f4357e949f5971d39b04a128103b8949bb (diff) | |
download | ffmpeg-1b13023860a6ede2699153bcad0bbb8bb72f6e38.tar.gz |
avcodec/qpeg: remove an unnecessary intermediary AVFrame
Decoding can be handled directly in the output frame.
Also ensure flushing cleans the reference frame in all cases.
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | libavcodec/qpeg.c | 22 |
1 files 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; } |