From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/vaapi_av1: Use ProgressFrames Date: Fri, 19 Apr 2024 18:07:34 +0200 Message-ID: <AS8P250MB0744B942017200AB7A73DBF08F0D2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB074434FCF48B2095E6D088D48F0D2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> The rationale here is exactly the same as for using them for AV1: It avoids av_frame_ref() when putting the same frame into multiple reference slots. (In case av_frame_ref() failed, the context would be left in an inconsistent state that claimed that an AVFrame was valid (i.e. not blank), when in fact it was not valid.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/vaapi_av1.c | 61 +++++++++++------------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c index 1f563483b9..20651a0ac2 100644 --- a/libavcodec/vaapi_av1.c +++ b/libavcodec/vaapi_av1.c @@ -18,17 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/frame.h" #include "hwaccel_internal.h" #include "vaapi_decode.h" #include "internal.h" #include "av1dec.h" -#include "thread.h" - -typedef struct VAAPIAV1FrameRef { - AVFrame *frame; - int valid; -} VAAPIAV1FrameRef; +#include "progressframe.h" typedef struct VAAPIAV1DecContext { VAAPIDecodeContext base; @@ -40,8 +34,8 @@ typedef struct VAAPIAV1DecContext { * applying film grain here. And current_display_picture will be * used to apply film grain and push to downstream. */ - VAAPIAV1FrameRef ref_tab[AV1_NUM_REF_FRAMES]; - AVFrame *tmp_frame; + ProgressFrame ref_tab[AV1_NUM_REF_FRAMES]; + ProgressFrame tmp_frame; } VAAPIAV1DecContext; static VASurfaceID vaapi_av1_surface_id(AV1Frame *vf) @@ -70,32 +64,14 @@ static int8_t vaapi_av1_get_bit_depth_idx(AVCodecContext *avctx) return bit_depth == 8 ? 0 : bit_depth == 10 ? 1 : 2; } -static int vaapi_av1_decode_init(AVCodecContext *avctx) -{ - VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; - - ctx->tmp_frame = av_frame_alloc(); - if (!ctx->tmp_frame) - return AVERROR(ENOMEM); - - for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) { - ctx->ref_tab[i].frame = av_frame_alloc(); - if (!ctx->ref_tab[i].frame) - return AVERROR(ENOMEM); - ctx->ref_tab[i].valid = 0; - } - - return ff_vaapi_decode_init(avctx); -} - static int vaapi_av1_decode_uninit(AVCodecContext *avctx) { VAAPIAV1DecContext *ctx = avctx->internal->hwaccel_priv_data; - av_frame_free(&ctx->tmp_frame); + ff_progress_frame_unref(&ctx->tmp_frame); for (int i = 0; i < FF_ARRAY_ELEMS(ctx->ref_tab); i++) - av_frame_free(&ctx->ref_tab[i].frame); + ff_progress_frame_unref(&ctx->ref_tab[i]); return ff_vaapi_decode_uninit(avctx); } @@ -125,12 +101,12 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, goto fail; if (apply_grain) { - if (ctx->tmp_frame->buf[0]) - av_frame_unref(ctx->tmp_frame); - err = ff_thread_get_buffer(avctx, ctx->tmp_frame, AV_GET_BUFFER_FLAG_REF); + ff_progress_frame_unref(&ctx->tmp_frame); + err = ff_progress_frame_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); + pic->output_surface = ff_vaapi_get_surface_id(ctx->tmp_frame.f); } else { pic->output_surface = ff_vaapi_get_surface_id(s->cur_frame.f); } @@ -265,8 +241,8 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx, if (pic_param.pic_info_fields.bits.frame_type == AV1_FRAME_KEY && frame_header->show_frame) 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) : + pic_param.ref_frame_map[i] = ctx->ref_tab[i].f ? + ff_vaapi_get_surface_id(ctx->ref_tab[i].f) : vaapi_av1_surface_id(&s->ref[i]); } for (int i = 0; i < AV1_REFS_PER_FRAME; i++) { @@ -370,17 +346,10 @@ 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->buf[0]) - av_frame_unref(ctx->ref_tab[i].frame); + ff_progress_frame_unref(&ctx->ref_tab[i]); - if (apply_grain) { - ret = av_frame_ref(ctx->ref_tab[i].frame, ctx->tmp_frame); - if (ret < 0) - return ret; - ctx->ref_tab[i].valid = 1; - } else { - ctx->ref_tab[i].valid = 0; - } + if (apply_grain) + ff_progress_frame_ref(&ctx->ref_tab[i], &ctx->tmp_frame); } } @@ -431,7 +400,7 @@ const FFHWAccel ff_av1_vaapi_hwaccel = { .end_frame = vaapi_av1_end_frame, .decode_slice = vaapi_av1_decode_slice, .frame_priv_data_size = sizeof(VAAPIDecodePicture), - .init = vaapi_av1_decode_init, + .init = ff_vaapi_decode_init, .uninit = vaapi_av1_decode_uninit, .frame_params = ff_vaapi_common_frame_params, .priv_data_size = sizeof(VAAPIAV1DecContext), -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2024-04-19 16:08 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-19 15:58 [FFmpeg-devel] [PATCH 1/5] avcodec/progressframe: Explain how unnamed union can simplify accesses Andreas Rheinhardt 2024-04-19 16:07 ` [FFmpeg-devel] [PATCH 2/5] avcodec/hevcdec: Use union for AVFrame* and ProgressFrame Andreas Rheinhardt 2024-04-19 16:07 ` [FFmpeg-devel] [PATCH 3/5] avcodec/av1dec: Use ProgressFrames Andreas Rheinhardt 2024-04-20 20:22 ` James Almer 2024-04-19 16:07 ` [FFmpeg-devel] [PATCH 4/5] avcodec/av1dec: Make av1_frame_replace() out of av1_frame_ref() Andreas Rheinhardt 2024-04-19 16:07 ` Andreas Rheinhardt [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB0744B942017200AB7A73DBF08F0D2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git