From bcdea21675dac424daa4f4b356f1c0d5ac525fdb Mon Sep 17 00:00:00 2001 From: Haihao Xiang Date: Mon, 12 Jun 2023 16:14:47 +0800 Subject: [PATCH] lavfi/qsvvpp: postpone vpp session initialization So there is a chance to update vpp parameters per frame Signed-off-by: Haihao Xiang --- libavfilter/qsvvpp.c | 38 +++++++++++++++++++++++++++++++------- libavfilter/qsvvpp.h | 1 + 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index d168ab5d1d..f2e8e5fd73 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -835,6 +835,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam *param) /* Print output memory mode */ ff_qsvvpp_print_iopattern(avctx, s->vpp_param.IOPattern & 0xF0, "VPP"); + /* Validate VPP params, but don't initial VPP session here */ ret = MFXVideoVPP_Query(s->session, &s->vpp_param, &s->vpp_param); if (ret < 0) { ret = ff_qsvvpp_print_error(avctx, ret, "Error querying VPP params"); @@ -842,13 +843,6 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam *param) } else if (ret > 0) ff_qsvvpp_print_warning(avctx, ret, "Warning When querying VPP params"); - ret = MFXVideoVPP_Init(s->session, &s->vpp_param); - if (ret < 0) { - ret = ff_qsvvpp_print_error(avctx, ret, "Failed to create a qsvvpp"); - goto failed; - } else if (ret > 0) - ff_qsvvpp_print_warning(avctx, ret, "Warning When creating qsvvpp"); - return 0; failed: @@ -857,6 +851,31 @@ failed: return ret; } +static int qsvvpp_init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) +{ + int ret; + + if (s->vpp_initted) + return 0; + + /* Query VPP params again, including params for frame */ + ret = MFXVideoVPP_Query(s->session, &s->vpp_param, &s->vpp_param); + if (ret < 0) + return ff_qsvvpp_print_error(avctx, ret, "Error querying VPP params"); + else if (ret > 0) + ff_qsvvpp_print_warning(avctx, ret, "Warning When querying VPP params"); + + ret = MFXVideoVPP_Init(s->session, &s->vpp_param); + if (ret < 0) + return ff_qsvvpp_print_error(avctx, ret, "Failed to create a qsvvpp"); + else if (ret > 0) + ff_qsvvpp_print_warning(avctx, ret, "Warning When creating qsvvpp"); + + s->vpp_initted = 1; + + return 0; +} + int ff_qsvvpp_close(AVFilterContext *avctx) { QSVVPPContext *s = avctx->priv; @@ -865,6 +884,7 @@ int ff_qsvvpp_close(AVFilterContext *avctx) MFXVideoVPP_Close(s->session); MFXClose(s->session); s->session = NULL; + s->vpp_initted = 0; } /* release all the resources */ @@ -920,6 +940,10 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr return AVERROR(ENOMEM); } + ret = qsvvpp_init_vpp_session(ctx, s); + if (ret) + return ret; + do { ret = MFXVideoVPP_RunFrameVPPAsync(s->session, &in_frame->surface, &out_frame->surface, NULL, &sync); diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h index 073c89fe70..fba5f037d4 100644 --- a/libavfilter/qsvvpp.h +++ b/libavfilter/qsvvpp.h @@ -90,6 +90,7 @@ typedef struct QSVVPPContext { AVFifo *async_fifo; mfxVersion ver; + int vpp_initted; } QSVVPPContext; typedef struct QSVVPPCrop {