From patchwork Mon Oct 31 06:20:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 39083 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8e01:b0:a3:a294:714c with SMTP id y1csp731581pzj; Sun, 30 Oct 2022 23:21:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6kWUkoSk/LHH7xnQujn5ji4vbuxVm5PALfZ4hP37Am1ohfi9yWuO9jD4pfO1rYZKQJOrrh X-Received: by 2002:a17:906:dac8:b0:741:545b:796a with SMTP id xi8-20020a170906dac800b00741545b796amr11309432ejb.240.1667197315845; Sun, 30 Oct 2022 23:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667197315; cv=none; d=google.com; s=arc-20160816; b=XJuwBbImuDFVXkWCWq3AvRbQMCjuvWIAsDrfpWqtEQIGMzoyGul4irwv+JluxSAwoN lSnuevgCNsxq6cwrWxfnbXmB3uBQ2Xigo59Oe5rsOt1XJ/Z5mK54Tj1x6mg8DsJD7Xoa g4zEELkw1CYTvpJQdhPMvl+SHPpG4CV0Hnp9+0O9PPckrzCE9FdbkjSQkTuSEnLxc3h3 l963lKn8Tlp5YjYNUAKe4WiEQJ4uM6uImG/vwa1lXIjwtr4D1KFfp7/7Don3QpCXx5Ma z+48zDAYZd7WtVkDBIEUqHjYxDIFaW3Mm+l9fLJ1iY3sLQOjEZv5j9wSB5AnVLaLGoUo kuZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=SiIaHJ0kbax8r06TeDjO1OeI/EQJQko5flIGhbF82KQ=; b=n1YUIdWTU2Jlb+CK9PLysxKc7NJyStz2beGjCAMw1hcfvn5bJAp0Y0O348R1a6PC6e i+R7bgrS+3iQp13+w0efMH+OUm5F01OmC5qw7yNYhOyVk6evDj7HxuSS/F2aiaiC+y3e B6Fio1AxkrxZ609Apz3c3vjfLoopobQ+5pGj2vm0CcV8pGV1RZpqsDJgUE1BrAuQUPdt 2FCX8Dum6uMTJS28xc4i+d18zo2SHHRN//Ta2q8i6FCt+P8UvXsidMc8kHS8VDndIdhR J7yWm0hzPFvisRv1A/EpOEO5j1/vgAi/3TGDtUixthygZLLGo6YRoIZlRE7PIWkiscXi yy5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=qAum52AJ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qk37-20020a1709077fa500b0078dce2b1985si7663310ejc.134.2022.10.30.23.21.55; Sun, 30 Oct 2022 23:21:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=qAum52AJ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 83EF568BE22; Mon, 31 Oct 2022 08:20:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 089A568BD3C for ; Mon, 31 Oct 2022 08:20:14 +0200 (EET) Received: by mail-pj1-f49.google.com with SMTP id d13-20020a17090a3b0d00b00213519dfe4aso9465164pjc.2; Sun, 30 Oct 2022 23:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=LJFrx32BhsR1JGS95uspSe/It+1V+hDKXLRZXKUA1Zs=; b=qAum52AJO1aqHWnUi9AEKcdvIe7NYroZ/43vvk/V6AAOLxSsvG9pWFCmqAnrgd8nRg eEyveNBftd4dgpLu55tblCQKi2FYFAnf9Y2PXP+y8YCLE4yVcHFGbjD0nBwXNxrL7qKX FIJ/iD1UTyojTxVxvzB0jRy3tOp3pdc1tKlPt6+MCg9Sxg9cJNoiQ60VOWRB3Nc11hvD PRi0O6wyYBMZVEECOApujhSRbaOJnwkEe/JVgaPTcHHc7wSKMuf2Yo7akyXJeb9T7qhU wd0CKSJVPCw0+XgSUM0YEYfBQ6D6IrvMgckGMunqp5xcEmiRY22pebq1msr6TsvMfBkk sAnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=LJFrx32BhsR1JGS95uspSe/It+1V+hDKXLRZXKUA1Zs=; b=iK2vzXonYJlHWp/iYBmsK0YXrpXyJcbbSeOf7HuE9zCdlj/YMgrFpGJAiW6a6Zr0wq uq2gkynKBkJJjL8HGYynYLlIyauoKY8VGE8lkYnlFK66eDPQAhqi8jK3j6guOm9JdaFr 37D0X/5BoAo/XQU84fv4ScvIYefs8K/uv8e9Gaf+JdENZZ9DllXbgysawFoZPAf/Il17 MU/BL9cuYbEg4j50CLcj9WsnMiURh5RAw2+22R3yf8FfDGRtEPNTvr8FSSFL07Li+fim b7GnS6IrXf0H8+AMdfR36m3ugtra8A71f5uFS0KbaA89qE8Y7x8LyGANGzSRwY/Q6M2W IMsg== X-Gm-Message-State: ACrzQf3y4GktktPbJkeY0ItErkjcMpJ4WP6MdKNG5x3QOFFUWv8zb/Ks X1xyfZ/9pI5/iO5c/Gfhbr81pcWGwTo= X-Received: by 2002:a17:902:c40a:b0:186:ba20:76fa with SMTP id k10-20020a170902c40a00b00186ba2076famr12699618plk.55.1667197212317; Sun, 30 Oct 2022 23:20:12 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b00174d9bbeda4sm3601049plk.197.2022.10.30.23.20.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Oct 2022 23:20:12 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Mon, 31 Oct 2022 06:20:00 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 04/11] avfilter/overlay_vaapi: handle secondary null input 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: softworkz , "Xiang, Haihao" , Gyan Doshi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: N5VI0nfQDVye From: softworkz Currently segfaults in this case. Signed-off-by: softworkz --- libavfilter/vf_overlay_vaapi.c | 94 ++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/libavfilter/vf_overlay_vaapi.c b/libavfilter/vf_overlay_vaapi.c index 66e736cce4..1281038c36 100644 --- a/libavfilter/vf_overlay_vaapi.c +++ b/libavfilter/vf_overlay_vaapi.c @@ -106,18 +106,6 @@ static int overlay_vaapi_render_picture(AVFilterContext *avctx, params_id); - 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, ¶ms_id, 1); if (vas != VA_STATUS_SUCCESS) { @@ -127,13 +115,27 @@ static int overlay_vaapi_render_picture(AVFilterContext *avctx, goto fail_after_begin; } - 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; + 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); @@ -177,7 +179,7 @@ static int overlay_vaapi_blend(FFFrameSync *fs) AVFrame *input_main, *input_overlay; AVFrame *output; VAProcPipelineParameterBuffer params, subpic_params; - VABlendState blend_state; /**< Blend State */ + VABlendState blend_state = { 0 }; /**< Blend State */ VARectangle overlay_region, output_region; int err; @@ -192,10 +194,6 @@ static int overlay_vaapi_blend(FFFrameSync *fs) av_get_pix_fmt_name(input_main->format), input_main->width, input_main->height, input_main->pts); - av_log(avctx, AV_LOG_DEBUG, "Filter overlay: %s, %ux%u (%"PRId64").\n", - av_get_pix_fmt_name(input_overlay->format), - input_overlay->width, input_overlay->height, input_overlay->pts); - if (vpp_ctx->va_context == VA_INVALID_ID) return AVERROR(EINVAL); @@ -214,13 +212,6 @@ static int overlay_vaapi_blend(FFFrameSync *fs) if (err < 0) goto fail; - overlay_region = (VARectangle) { - .x = ctx->overlay_ox, - .y = ctx->overlay_oy, - .width = ctx->overlay_ow ? ctx->overlay_ow : input_overlay->width, - .height = ctx->overlay_oh ? ctx->overlay_oh : input_overlay->height, - }; - output_region = (VARectangle) { .x = 0, .y = 0, @@ -228,29 +219,42 @@ static int overlay_vaapi_blend(FFFrameSync *fs) .height = output->height, }; - if (overlay_region.x + overlay_region.width > input_main->width || - overlay_region.y + overlay_region.height > input_main->height) { - av_log(ctx, AV_LOG_WARNING, - "The overlay image exceeds the scope of the main image, " - "will crop the overlay image according based on the main image.\n"); - } - params.filters = &vpp_ctx->filter_buffers[0]; params.num_filters = vpp_ctx->nb_filter_buffers; params.output_region = &output_region; params.output_background_color = VAAPI_VPP_BACKGROUND_BLACK; - memcpy(&subpic_params, ¶ms, sizeof(subpic_params)); + if (input_overlay) { + av_log(avctx, AV_LOG_DEBUG, "Filter overlay: %s, %ux%u (%"PRId64").\n", + av_get_pix_fmt_name(input_overlay->format), + input_overlay->width, input_overlay->height, input_overlay->pts); + + overlay_region = (VARectangle) { + .x = ctx->overlay_ox, + .y = ctx->overlay_oy, + .width = ctx->overlay_ow ? ctx->overlay_ow : input_overlay->width, + .height = ctx->overlay_oh ? ctx->overlay_oh : input_overlay->height, + }; + + if (overlay_region.x + overlay_region.width > input_main->width || + overlay_region.y + overlay_region.height > input_main->height) { + av_log(ctx, AV_LOG_WARNING, + "The overlay image exceeds the scope of the main image, " + "will crop the overlay image according based on the main image.\n"); + } + + memcpy(&subpic_params, ¶ms, sizeof(subpic_params)); - blend_state.flags = VA_BLEND_GLOBAL_ALPHA; - blend_state.global_alpha = ctx->alpha; - subpic_params.blend_state = &blend_state; + blend_state.flags = VA_BLEND_GLOBAL_ALPHA; + blend_state.global_alpha = ctx->alpha; + subpic_params.blend_state = &blend_state; - subpic_params.surface = (VASurfaceID)(uintptr_t)input_overlay->data[3]; - subpic_params.output_region = &overlay_region; + subpic_params.surface = (VASurfaceID)(uintptr_t)input_overlay->data[3]; + subpic_params.output_region = &overlay_region; + } - err = overlay_vaapi_render_picture(avctx, ¶ms, &subpic_params, output); + err = overlay_vaapi_render_picture(avctx, ¶ms, input_overlay ? &subpic_params : NULL, output); if (err < 0) goto fail;