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>
This commit is contained in:
James Almer 2020-04-16 23:20:43 -03:00
parent 0fcf74f435
commit 1b13023860

View File

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