From patchwork Fri Jan 7 03:58:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 33137 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp55877iog; Thu, 6 Jan 2022 19:58:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1xvVUCGNs06qmIaMse0RUwShQs5mDydLLrWwlDJrHVi6lEtGAVGiMAwwXau2a3UjY5KO5 X-Received: by 2002:a17:907:6d9b:: with SMTP id sb27mr49279028ejc.1.1641527935199; Thu, 06 Jan 2022 19:58:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641527935; cv=none; d=google.com; s=arc-20160816; b=sz1tJg4olXHZ9fNX9wjQZsnvV+3NexPNJqJRfpA4EQMXrOHinDu9qViOna3Ip9UaT+ cUgjXrnl7lhob9igbegqsWRzLx2D+BFEzGhQKFYRSnAxB/Nr+fbp3D/p3x0BgdRJDnI9 QpsajJnHVuhGzh6oQqvwlNjgfAMTHKLqxT6RWn2YMCb9uDT1NUmlUEsSzwgRISphDL0R g5yT4Oas22umyrP+BfPfeUGtE6MWnbuFgFdDcSaZjEFCyfLFPqszwwI6cnuLjC9WrFFF r/0ZZmbmGdQpT0N38dnbBcfQOTN0tyMErKlL6oVSO59FwvcojVXFEX8KDgSklRA6ElNL OVIQ== 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:from:references :in-reply-to:message-id:dkim-signature:delivered-to; bh=h7R4+gRQYx6Gf8cO5ecOo3jmQQRiLhv6oDax+52az9A=; b=M6S4tEOGgnxVJDg3btTAAzVJ7WT63uOmoIq5a5DtKawvEyoDNQsg3QmD7SU3wMKo1C tcM7RSwyL4QvO1cCXYaw+sD70kza/1eFrNUjhxTylbbE3F/ku5iv4i5fevQsRubu1pRp k3EagydXlYuYORtCazteICEy6L0oQ/dcd5qT3N0Ke6Xve1TJWvzNQHg84wucnNa1HnxF 7z9AIAnIGRlaWmIuCOVA7iRsB5Kgpg3DoxeUrnRwFYKAQ29TDA9D0OszJfyDpnNLtMKz 1OSWs1aGMa0VGFhJL1IEVPQ+Z05LcaaOuS+jZgmF97nGpTS9Na9nIPB/I917ph8lFiVM b7ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=obOU+u4U; 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 w4si1843637eji.925.2022.01.06.19.58.54; Thu, 06 Jan 2022 19:58:55 -0800 (PST) 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=obOU+u4U; 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 0EBF668AE4E; Fri, 7 Jan 2022 05:58:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B820C68A637 for ; Fri, 7 Jan 2022 05:58:40 +0200 (EET) Received: by mail-pg1-f177.google.com with SMTP id t32so4368707pgm.7; Thu, 06 Jan 2022 19:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=UVnYNVuJvIc1ZYykKr80YQj7wUsG0sSpqJQQPETNWRA=; b=obOU+u4UpUw5fDZye3OPX8JKmCMb5MSgmx8wWhwFDjJn3YwmW7OIb4py7NEk6OlcPo E50M6UynZO167TMtNrJDJ+B2oXMca0kPEIarx5hJT+lhMSXzo3KURCupmdRjY8sRpeRA Px7TrpZXBARVP/Ax39KFYhpkFOVa99Ogq4krx/QiVW6PEeN610/d+tgJAOt3sTdE6DEJ 54SwUEr+tw6yVT+LEFQ4BfANqJHMd52UQTfqqe10WoDvDjCn99Ut4q2kD5lOgNEVyGT0 /bSlC/m9QzMAQ9IINIJ27ASuUWzxyIBzm0lLUeJSwdaGDIUQwX7Fk9XDvx60ZTTuEd6+ CsNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=UVnYNVuJvIc1ZYykKr80YQj7wUsG0sSpqJQQPETNWRA=; b=shhWuCJ6obfeMKoys8hq54CYBVbk1+YD/2Usa6Cux1SWTVjxf0baF7S5PrEmC3rCfR iZd1k0VWBVzy98OyYzZXzi2Q6pQ18kKNTCohwDE8hx3SZCpz8kjLXUHD6QoYJLx9k42p OnMbfmi/Ot7eqy63tAEY9ouLHPeCf2Ml7HfNay47POEe7hm9YuRYNGtW2oDfjwSnSo3E LMh1KLJ5MvKWhCAli5QEMjZTz7tB3gn2dqlB4on4Xgk9Jqu7EkSJnpGeh4I6ru/kX3HN +alQWL2jrrVMMAPKve0qrtZ4UhkbzQvcO3FQ0JPYJx+PEeS0fN9bI15kSDQbSJu67xoc OkXw== X-Gm-Message-State: AOAM533chVTpg3DEyRG7cU3JH5OvycqI0vkX3v4Wx+LW2ml7B9YvkJc+ UU4bZML76sfd+LwbDvkdim2Zdy7kINsF8w== X-Received: by 2002:a63:4712:: with SMTP id u18mr55238160pga.330.1641527918939; Thu, 06 Jan 2022 19:58:38 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id 185sm3839419pfe.26.2022.01.06.19.58.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jan 2022 19:58:38 -0800 (PST) Message-Id: In-Reply-To: References: From: ffmpegagent Date: Fri, 07 Jan 2022 03:58:37 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3] avfilter/vpp_qsv: fix regression on older api versions (e.g. 1.11) 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" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QYiZAAJM8SFa From: softworkz Commit 8b83dad82512a6948b63408f964463b063ad24c9 introduced a regression in a way that scaling via vpp_qsv doesn't work any longer for devices with an MSDK runtime version lower than 1.19. This is true for older CPUs which are stuck at 1.11. The commit added checks for the compile-sdk version but it didn't test for the runtime version. Signed-off-by: softworkz --- avfilter/vpp_qsv: fix regression on older api versions (e.g. 1.11) Fix a recently introduced regression when using QSV VPP. v2: Fixed commit message wrapping v3: Use different way to acquire runtime version Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-15%2Fsoftworkz%2Fqsv_vpp_regression-v3 Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-15/softworkz/qsv_vpp_regression-v3 Pull-Request: https://github.com/ffstaging/FFmpeg/pull/15 Range-diff vs v2: 1: ccede9d840 ! 1: cbf53d8ef4 avfilter/vpp_qsv: fix regression on older api versions (e.g. 1.11) @@ Commit message Signed-off-by: softworkz ## libavfilter/vf_vpp_qsv.c ## +@@ + #include "libavutil/opt.h" + #include "libavutil/eval.h" + #include "libavutil/hwcontext.h" ++#include "libavutil/hwcontext_qsv.h" + #include "libavutil/pixdesc.h" + #include "libavutil/mathematics.h" + @@ libavfilter/vf_vpp_qsv.c: static const AVOption options[] = { { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS }, @@ libavfilter/vf_vpp_qsv.c: static const AVOption options[] = { { NULL } }; +@@ libavfilter/vf_vpp_qsv.c: static int config_input(AVFilterLink *inlink) + return 0; + } + ++static int get_mfx_version(const AVFilterContext *ctx, mfxVersion *mfx_version) ++{ ++ const AVFilterLink *inlink = ctx->inputs[0]; ++ AVBufferRef *device_ref; ++ AVHWDeviceContext *device_ctx; ++ AVQSVDeviceContext *device_hwctx; ++ ++ if (inlink->hw_frames_ctx) { ++ AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data; ++ device_ref = frames_ctx->device_ref; ++ } else if (ctx->hw_device_ctx) { ++ device_ref = ctx->hw_device_ctx; ++ } else { ++ // Unavailable hw context doesn't matter in pass-through mode, ++ // so don't error here but let runtime version checks fail by setting to 0.0 ++ mfx_version->Major = 0; ++ mfx_version->Minor = 0; ++ return 0; ++ } ++ ++ device_ctx = (AVHWDeviceContext *)device_ref->data; ++ device_hwctx = device_ctx->hwctx; ++ ++ return MFXQueryVersion(device_hwctx->session, mfx_version); ++} ++ + static int config_output(AVFilterLink *outlink) + { + AVFilterContext *ctx = outlink->src; @@ libavfilter/vf_vpp_qsv.c: static int config_output(AVFilterLink *outlink) QSVVPPParam param = { NULL }; QSVVPPCrop crop = { 0 }; @@ libavfilter/vf_vpp_qsv.c: static int config_output(AVFilterLink *outlink) param.ext_buf = ext_buf; param.async_depth = vpp->async_depth; -+ if (MFXQueryVersion(vpp->qsv->session, &mfx_version) < 0) { ++ if (get_mfx_version(ctx, &mfx_version) < 0) { + av_log(ctx, AV_LOG_ERROR, "Failed to query mfx version.\n"); + return AVERROR(EINVAL); + } libavfilter/vf_vpp_qsv.c | 59 ++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 12 deletions(-) base-commit: 242ed971cb005157488b9a21942d9fb4be4d0347 diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index ab58a5777e..ca7033cdde 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -26,6 +26,7 @@ #include "libavutil/opt.h" #include "libavutil/eval.h" #include "libavutil/hwcontext.h" +#include "libavutil/hwcontext_qsv.h" #include "libavutil/pixdesc.h" #include "libavutil/mathematics.h" @@ -139,8 +140,9 @@ static const AVOption options[] = { { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS }, { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS }, { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = FLAGS }, +#ifdef QSV_HAVE_SCALING_CONFIG { "scale_mode", "scale mode: 0=auto, 1=low power, 2=high quality", OFFSET(scale_mode), AV_OPT_TYPE_INT, { .i64 = MFX_SCALING_MODE_DEFAULT }, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, .flags = FLAGS, "scale mode" }, - +#endif { NULL } }; @@ -297,6 +299,32 @@ static int config_input(AVFilterLink *inlink) return 0; } +static int get_mfx_version(const AVFilterContext *ctx, mfxVersion *mfx_version) +{ + const AVFilterLink *inlink = ctx->inputs[0]; + AVBufferRef *device_ref; + AVHWDeviceContext *device_ctx; + AVQSVDeviceContext *device_hwctx; + + if (inlink->hw_frames_ctx) { + AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data; + device_ref = frames_ctx->device_ref; + } else if (ctx->hw_device_ctx) { + device_ref = ctx->hw_device_ctx; + } else { + // Unavailable hw context doesn't matter in pass-through mode, + // so don't error here but let runtime version checks fail by setting to 0.0 + mfx_version->Major = 0; + mfx_version->Minor = 0; + return 0; + } + + device_ctx = (AVHWDeviceContext *)device_ref->data; + device_hwctx = device_ctx->hwctx; + + return MFXQueryVersion(device_hwctx->session, mfx_version); +} + static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; @@ -304,6 +332,7 @@ static int config_output(AVFilterLink *outlink) QSVVPPParam param = { NULL }; QSVVPPCrop crop = { 0 }; mfxExtBuffer *ext_buf[ENH_FILTERS_COUNT]; + mfxVersion mfx_version; AVFilterLink *inlink = ctx->inputs[0]; enum AVPixelFormat in_format; @@ -317,6 +346,11 @@ static int config_output(AVFilterLink *outlink) param.ext_buf = ext_buf; param.async_depth = vpp->async_depth; + if (get_mfx_version(ctx, &mfx_version) < 0) { + av_log(ctx, AV_LOG_ERROR, "Failed to query mfx version.\n"); + return AVERROR(EINVAL); + } + if (inlink->format == AV_PIX_FMT_QSV) { if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data) return AVERROR(EINVAL); @@ -467,19 +501,20 @@ static int config_output(AVFilterLink *outlink) #endif } - if (inlink->w != outlink->w || inlink->h != outlink->h) { #ifdef QSV_HAVE_SCALING_CONFIG - memset(&vpp->scale_conf, 0, sizeof(mfxExtVPPScaling)); - vpp->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING; - vpp->scale_conf.Header.BufferSz = sizeof(mfxExtVPPScaling); - vpp->scale_conf.ScalingMode = vpp->scale_mode; - - param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->scale_conf; -#else - av_log(ctx, AV_LOG_WARNING, "The QSV VPP Scale option is " - "not supported with this MSDK version.\n"); -#endif + if (inlink->w != outlink->w || inlink->h != outlink->h) { + if (QSV_RUNTIME_VERSION_ATLEAST(mfx_version, 1, 19)) { + memset(&vpp->scale_conf, 0, sizeof(mfxExtVPPScaling)); + vpp->scale_conf.Header.BufferId = MFX_EXTBUFF_VPP_SCALING; + vpp->scale_conf.Header.BufferSz = sizeof(mfxExtVPPScaling); + vpp->scale_conf.ScalingMode = vpp->scale_mode; + + param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->scale_conf; + } else + av_log(ctx, AV_LOG_WARNING, "The QSV VPP Scale option is " + "not supported with this MSDK version.\n"); } +#endif if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise || vpp->detail || vpp->procamp || vpp->rotate || vpp->hflip ||