From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 36E6E42F9C for ; Fri, 13 Jan 2023 04:38:58 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C32368BAA0; Fri, 13 Jan 2023 06:38:56 +0200 (EET) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 961B368A4DB for ; Fri, 13 Jan 2023 06:38:48 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673584733; x=1705120733; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=rGzDWpvnhf5OaSF9njuUZicZdIuvht4W8a/1UIPEfGE=; b=FPim+duQ1D2nCSZlJTeCZPc1PFoPV3q6Cgyojo9fux0oKm0woRVrZDwu aWHZBEdyDZHpBaOTf0pbQRZqaWGXA10TRHbzlDw1IiYoqlFlPaDjrNyRG SeKkSmG/zBlO1LDPXQvurhnbP5phI6HaNr0xRasoYBcY4UgrhR56NJBaQ XfvgB04WLm68Z8ZFV/nGWnFTtcsgsy8iKJrbmLigxLxFNqOH6da2OiTtt nDr/Q+qagA8mJUJH9lL1eyCtf5inO1PaOYCsLAoq4SexkXwAbSKFX89P3 zXolUpmflriL4i0UodG6sZNplRMd6i+AuuTgO/IzpmtsLk+19FUilSE6w g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="386259200" X-IronPort-AV: E=Sophos;i="5.97,212,1669104000"; d="scan'208";a="386259200" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 20:38:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="651400827" X-IronPort-AV: E=Sophos;i="5.97,212,1669104000"; d="scan'208";a="651400827" Received: from xhh-tgl64.sh.intel.com ([10.238.2.19]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 20:38:44 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Jan 2023 12:38:30 +0800 Message-Id: <20230113043831.2389116-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/vaapi: remove duplicated code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Haihao Xiang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Haihao Xiang Add a ff_ function to handle mulitple pipeline parameters. No functional changes. Signed-off-by: Haihao Xiang --- libavfilter/vaapi_vpp.c | 90 ++++++++++++++++-------- libavfilter/vaapi_vpp.h | 5 ++ libavfilter/vf_overlay_vaapi.c | 122 +++------------------------------ 3 files changed, 77 insertions(+), 140 deletions(-) diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c index 1610df4c85..a323dab8b8 100644 --- a/libavfilter/vaapi_vpp.c +++ b/libavfilter/vaapi_vpp.c @@ -588,17 +588,53 @@ int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, return 0; } +static int vaapi_vpp_render_single_pipeline_buffer(AVFilterContext *avctx, + VAProcPipelineParameterBuffer *params, + VABufferID *params_id) +{ + VAAPIVPPContext *ctx = avctx->priv; + VAStatus vas; -int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, - VAProcPipelineParameterBuffer *params, - AVFrame *output_frame) + vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, + VAProcPipelineParameterBufferType, + sizeof(*params), 1, params, params_id); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: " + "%d (%s).\n", vas, vaErrorStr(vas)); + *params_id = VA_INVALID_ID; + + return AVERROR(EIO); + } + av_log(avctx, AV_LOG_DEBUG, "Pipeline parameter buffer is %#x.\n", *params_id); + + vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, params_id, 1); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to render parameter buffer: " + "%d (%s).\n", vas, vaErrorStr(vas)); + return AVERROR(EIO); + } + + return 0; +} + +int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx, + VAProcPipelineParameterBuffer *params_list, + int cout, + AVFrame *output_frame) { VAAPIVPPContext *ctx = avctx->priv; VASurfaceID output_surface; - VABufferID params_id; + VABufferID *params_ids; VAStatus vas; int err; + params_ids = (VABufferID *)av_malloc_array(cout, sizeof(VABufferID)); + if (!params_ids) + return AVERROR(ENOMEM); + + for (int i = 0; i < cout; i++) + params_ids[i] = VA_INVALID_ID; + output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; vas = vaBeginPicture(ctx->hwctx->display, @@ -610,25 +646,10 @@ int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, goto fail; } - vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, - VAProcPipelineParameterBufferType, - sizeof(*params), 1, params, ¶ms_id); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; - } - av_log(avctx, AV_LOG_DEBUG, "Pipeline parameter buffer is %#x.\n", - params_id); - - vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, - ¶ms_id, 1); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to render parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; + for (int i = 0; i < cout; i++) { + err = vaapi_vpp_render_single_pipeline_buffer(avctx, ¶ms_list[i], ¶ms_ids[i]); + if (err) + goto fail_after_begin; } vas = vaEndPicture(ctx->hwctx->display, ctx->va_context); @@ -641,14 +662,17 @@ int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { - vas = vaDestroyBuffer(ctx->hwctx->display, params_id); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - // And ignore. + for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) { + vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: " + "%d (%s).\n", vas, vaErrorStr(vas)); + // And ignore. + } } } + av_freep(¶ms_ids); return 0; // We want to make sure that if vaBeginPicture has been called, we also @@ -656,13 +680,21 @@ int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, // do something else nasty, but once we're in this failure case there // isn't much else we can do. fail_after_begin: - vaRenderPicture(ctx->hwctx->display, ctx->va_context, ¶ms_id, 1); + vaRenderPicture(ctx->hwctx->display, ctx->va_context, ¶ms_ids[0], 1); fail_after_render: vaEndPicture(ctx->hwctx->display, ctx->va_context); fail: + av_freep(¶ms_ids); return err; } +int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, + VAProcPipelineParameterBuffer *params, + AVFrame *output_frame) +{ + return ff_vaapi_vpp_render_pictures(avctx, params, 1, output_frame); +} + void ff_vaapi_vpp_ctx_init(AVFilterContext *avctx) { int i; diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h index c3da91717c..ead07036dc 100644 --- a/libavfilter/vaapi_vpp.h +++ b/libavfilter/vaapi_vpp.h @@ -83,4 +83,9 @@ int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, AVFrame *output_frame); +int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx, + VAProcPipelineParameterBuffer *params_list, + int count, + AVFrame *output_frame); + #endif /* AVFILTER_VAAPI_VPP_H */ diff --git a/libavfilter/vf_overlay_vaapi.c b/libavfilter/vf_overlay_vaapi.c index 307f3cf7fc..79cf66d068 100644 --- a/libavfilter/vf_overlay_vaapi.c +++ b/libavfilter/vf_overlay_vaapi.c @@ -159,106 +159,6 @@ static int overlay_vaapi_build_filter_params(AVFilterContext *avctx) return 0; } -static int overlay_vaapi_render_picture(AVFilterContext *avctx, - VAProcPipelineParameterBuffer *params, - VAProcPipelineParameterBuffer *subpic_params, - AVFrame *output_frame) -{ - VAAPIVPPContext *ctx = avctx->priv; - VASurfaceID output_surface; - VABufferID params_id; - VABufferID subpic_params_id; - VAStatus vas; - int err = 0; - - output_surface = (VASurfaceID)(uintptr_t)output_frame->data[3]; - - vas = vaBeginPicture(ctx->hwctx->display, - ctx->va_context, output_surface); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to attach new picture: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail; - } - - vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, - VAProcPipelineParameterBufferType, - sizeof(*params), 1, params, ¶ms_id); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; - } - av_log(avctx, AV_LOG_DEBUG, "Pipeline parameter buffer is %#x.\n", - params_id); - - - vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, - ¶ms_id, 1); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to render parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; - } - - if (subpic_params) { - vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, - VAProcPipelineParameterBufferType, - sizeof(*subpic_params), 1, subpic_params, &subpic_params_id); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to create parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; - } - av_log(avctx, AV_LOG_DEBUG, "Pipeline subpic parameter buffer is %#x.\n", - subpic_params_id); - - vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, - &subpic_params_id, 1); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to render subpic parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_begin; - } - } - - vas = vaEndPicture(ctx->hwctx->display, ctx->va_context); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to start picture processing: " - "%d (%s).\n", vas, vaErrorStr(vas)); - err = AVERROR(EIO); - goto fail_after_render; - } - - if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks & - AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { - vas = vaDestroyBuffer(ctx->hwctx->display, params_id); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: " - "%d (%s).\n", vas, vaErrorStr(vas)); - // And ignore. - } - } - - return 0; - - // We want to make sure that if vaBeginPicture has been called, we also - // call vaRenderPicture and vaEndPicture. These calls may well fail or - // do something else nasty, but once we're in this failure case there - // isn't much else we can do. -fail_after_begin: - vaRenderPicture(ctx->hwctx->display, ctx->va_context, ¶ms_id, 1); -fail_after_render: - vaEndPicture(ctx->hwctx->display, ctx->va_context); -fail: - return err; -} - static int overlay_vaapi_blend(FFFrameSync *fs) { AVFilterContext *avctx = fs->parent; @@ -267,7 +167,7 @@ static int overlay_vaapi_blend(FFFrameSync *fs) VAAPIVPPContext *vpp_ctx = avctx->priv; AVFrame *input_main, *input_overlay; AVFrame *output; - VAProcPipelineParameterBuffer params, subpic_params; + VAProcPipelineParameterBuffer params[2]; VABlendState blend_state = { 0 }; /**< Blend State */ VARectangle overlay_region, output_region; int err; @@ -296,7 +196,7 @@ static int overlay_vaapi_blend(FFFrameSync *fs) if (err < 0) goto fail; - err = ff_vaapi_vpp_init_params(avctx, ¶ms, + err = ff_vaapi_vpp_init_params(avctx, ¶ms[0], input_main, output); if (err < 0) goto fail; @@ -308,11 +208,11 @@ static int overlay_vaapi_blend(FFFrameSync *fs) .height = output->height, }; - params.filters = &vpp_ctx->filter_buffers[0]; - params.num_filters = vpp_ctx->nb_filter_buffers; + params[0].filters = &vpp_ctx->filter_buffers[0]; + params[0].num_filters = vpp_ctx->nb_filter_buffers; - params.output_region = &output_region; - params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; + params[0].output_region = &output_region; + params[0].output_background_color = VAAPI_VPP_BACKGROUND_BLACK; if (input_overlay) { av_log(avctx, AV_LOG_DEBUG, "Filter overlay: %s, %ux%u (%"PRId64").\n", @@ -333,17 +233,17 @@ static int overlay_vaapi_blend(FFFrameSync *fs) "will crop the overlay image according based on the main image.\n"); } - memcpy(&subpic_params, ¶ms, sizeof(subpic_params)); + memcpy(¶ms[1], ¶ms[0], sizeof(params[0])); blend_state.flags = ctx->blend_flags; blend_state.global_alpha = ctx->blend_alpha; - subpic_params.blend_state = &blend_state; + params[1].blend_state = &blend_state; - subpic_params.surface = (VASurfaceID)(uintptr_t)input_overlay->data[3]; - subpic_params.output_region = &overlay_region; + params[1].surface = (VASurfaceID)(uintptr_t)input_overlay->data[3]; + params[1].output_region = &overlay_region; } - err = overlay_vaapi_render_picture(avctx, ¶ms, input_overlay ? &subpic_params : NULL, output); + err = ff_vaapi_vpp_render_pictures(avctx, params, input_overlay ? 2 : 1, output); if (err < 0) goto fail; -- 2.25.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".