avcodec/thread: Don't use ThreadFrame when unnecessary

The majority of frame-threaded decoders (mainly the intra-only)
need exactly one part of ThreadFrame: The AVFrame. They don't
need the owners nor the progress, yet they had to use it because
ff_thread_(get|release)_buffer() requires it.

This commit changes this and makes these functions work with ordinary
AVFrames; the decoders that need the extra fields for progress
use ff_thread_(get|release)_ext_buffer() which work exactly
as ff_thread_(get|release)_buffer() used to do.

This also avoids some unnecessary allocations of progress AVBuffers,
namely for H.264 and HEVC film grain frames: These frames are not
used for synchronization and therefore don't need a ThreadFrame.

Also move the ThreadFrame structure as well as ff_thread_ref_frame()
to threadframe.h, the header for frame-threaded decoders with
inter-frame dependencies.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-02-06 14:49:23 +01:00
parent f025b8e110
commit 02220b88fc
59 changed files with 252 additions and 283 deletions

View file

@ -1042,7 +1042,7 @@ static int dxv_decode(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
DXVContext *ctx = avctx->priv_data;
ThreadFrame tframe;
AVFrame *const frame = data;
GetByteContext *gbc = &ctx->gbc;
int (*decompress_tex)(AVCodecContext *avctx);
const char *msgcomp, *msgtext;
@ -1211,18 +1211,17 @@ static int dxv_decode(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA;
}
tframe.f = data;
ret = ff_thread_get_buffer(avctx, &tframe, 0);
ret = ff_thread_get_buffer(avctx, frame, 0);
if (ret < 0)
return ret;
/* Now decompress the texture with the standard functions. */
avctx->execute2(avctx, decompress_texture_thread,
tframe.f, NULL, ctx->slice_count);
frame, NULL, ctx->slice_count);
/* Frame is ready to be output. */
tframe.f->pict_type = AV_PICTURE_TYPE_I;
tframe.f->key_frame = 1;
frame->pict_type = AV_PICTURE_TYPE_I;
frame->key_frame = 1;
*got_frame = 1;
return avpkt->size;