mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-23 11:19:55 +00:00
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:
parent
0fcf74f435
commit
1b13023860
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user