summaryrefslogtreecommitdiff
path: root/libavcodec/vaapi_av1.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-02-06 14:49:23 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-02-09 17:22:35 +0100
commit02220b88fc38ef9dd4f2d519f5d3e4151258b60c (patch)
tree5ab09d5c019a822c0a839c6076bccff670986867 /libavcodec/vaapi_av1.c
parentf025b8e110b36c1cdb4fb56c4cd57aeca1767b5b (diff)
downloadffmpeg-02220b88fc38ef9dd4f2d519f5d3e4151258b60c.tar.gz
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>
Diffstat (limited to 'libavcodec/vaapi_av1.c')
-rw-r--r--libavcodec/vaapi_av1.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 5985493b8d..63374c31c9 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -18,14 +18,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/frame.h"
#include "libavutil/pixdesc.h"
#include "hwconfig.h"
#include "vaapi_decode.h"
#include "internal.h"
#include "av1dec.h"
+#include "thread.h"
typedef struct VAAPIAV1FrameRef {
- ThreadFrame frame;
+ AVFrame *frame;
int valid;
} VAAPIAV1FrameRef;
@@ -40,13 +42,13 @@ typedef struct VAAPIAV1DecContext {
* used to apply film grain and push to downstream.
*/
VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES];
- ThreadFrame tmp_frame;
+ AVFrame *tmp_frame;
} VAAPIAV1DecContext;
static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf)
{
if (vf)
- return ff_vaapi_get_surface_id(vf->tf.f);
+ return ff_vaapi_get_surface_id(vf->f);
else
return VA_INVALID_SURFACE;
}
@@ -73,16 +75,16 @@ static int vaapi_av1_decode_init(AVCodecContext *avctx)
{
VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
- ctx->tmp_frame.f = av_frame_alloc();
- if (!ctx->tmp_frame.f) {
+ ctx->tmp_frame = av_frame_alloc();
+ if (!ctx->tmp_frame) {
av_log(avctx, AV_LOG_ERROR,
"Failed to allocate frame.\n");
return AVERROR(ENOMEM);
}
for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) {
- ctx->ref_tab[i].frame.f = av_frame_alloc();
- if (!ctx->ref_tab[i].frame.f) {
+ ctx->ref_tab[i].frame = av_frame_alloc();
+ if (!ctx->ref_tab[i].frame) {
av_log(avctx, AV_LOG_ERROR,
"Failed to allocate reference table frame %d.\n", i);
return AVERROR(ENOMEM);
@@ -97,14 +99,14 @@ static int vaapi_av1_decode_uninit(AVCodecContext *avctx)
{
VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data;
- if (ctx->tmp_frame.f->buf[0])
- ff_thread_release_buffer(avctx, &ctx->tmp_frame);
- av_frame_free(&ctx->tmp_frame.f);
+ if (ctx->tmp_frame->buf[0])
+ ff_thread_release_buffer(avctx, ctx->tmp_frame);
+ av_frame_free(&ctx->tmp_frame);
for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) {
- if (ctx->ref_tab[i].frame.f->buf[0])
- ff_thread_release_buffer(avctx, &ctx->ref_tab[i].frame);
- av_frame_free(&ctx->ref_tab[i].frame.f);
+ if (ctx->ref_tab[i].frame->buf[0])
+ ff_thread_release_buffer(avctx, ctx->ref_tab[i].frame);
+ av_frame_free(&ctx->ref_tab[i].frame);
}
return ff_vaapi_decode_uninit(avctx);
@@ -135,12 +137,12 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
goto fail;
if (apply_grain) {
- if (ctx->tmp_frame.f->buf[0])
- ff_thread_release_buffer(avctx, &ctx->tmp_frame);
- err = ff_thread_get_buffer(avctx, &ctx->tmp_frame, AV_GET_BUFFER_FLAG_REF);
+ if (ctx->tmp_frame->buf[0])
+ ff_thread_release_buffer(avctx, ctx->tmp_frame);
+ err = ff_thread_get_buffer(avctx, ctx->tmp_frame, AV_GET_BUFFER_FLAG_REF);
if (err < 0)
goto fail;
- pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame.f);
+ pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame);
} else {
pic->output_surface = vaapi_av1_surface_id(&s->cur_frame);
}
@@ -276,7 +278,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
pic_param.ref_frame_map[i] = VA_INVALID_ID;
else
pic_param.ref_frame_map[i] = ctx->ref_tab[i].valid ?
- ff_vaapi_get_surface_id(ctx->ref_tab[i].frame.f) :
+ ff_vaapi_get_surface_id(ctx->ref_tab[i].frame) :
vaapi_av1_surface_id(&s->ref[i]);
}
for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
@@ -380,11 +382,11 @@ static int vaapi_av1_end_frame(AVCodecContext *avctx)
for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
if (header->refresh_frame_flags & (1 << i)) {
- if (ctx->ref_tab[i].frame.f->buf[0])
- ff_thread_release_buffer(avctx, &ctx->ref_tab[i].frame);
+ if (ctx->ref_tab[i].frame->buf[0])
+ ff_thread_release_buffer(avctx, ctx->ref_tab[i].frame);
if (apply_grain) {
- ret = ff_thread_ref_frame(&ctx->ref_tab[i].frame, &ctx->tmp_frame);
+ ret = av_frame_ref(ctx->ref_tab[i].frame, ctx->tmp_frame);
if (ret < 0)
return ret;
ctx->ref_tab[i].valid = 1;