From patchwork Mon Jul 25 04:11:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 36949 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1814842pzb; Sun, 24 Jul 2022 21:14:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s418YFwnEGjgE1ULG61bjm9nGXAdXHlpTXZrW0Mvltx7EF0oSktErE8isx51iIo/956ikK X-Received: by 2002:a17:907:a0c7:b0:72f:b205:112 with SMTP id hw7-20020a170907a0c700b0072fb2050112mr8412517ejc.559.1658722449381; Sun, 24 Jul 2022 21:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658722449; cv=none; d=google.com; s=arc-20160816; b=EBi5B/c6rpObyENabMEwpNmtjODc/eowbOKxPFBzAkPCEUaZ3ivNLyv5uLmEZyGV77 vQaB/JDIS0xxq0l9Qo2nYjSicXMoZcfqO54LY9GW/4OLJyHXXIwNpsnhK3ZHgQe/yuiK y9sLr/+oHMn4qS7W+6mx772HhDAlSFEMUChHw6U+xKqFFEd92/iuXV3gzLiHTDX/Lkym /lBP7dj0cRd59+f6qRSNIeXvTjAdhmDTSOo27LbidjazY15PE7NYzX5EYtTGmsG2aghv w/gWIzxroVsa9UKi/NfYuYvgWEiDPuNnAD1zEvsWzD+WRg9XcgTmiJxDEiAjkB+HgJMg eAuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=u4qOwk32lYrcVieAD2JB5l1qfLD0btKPj+g7zURtKE4=; b=pwU8FQVZEYQbQJCYl+WzJfPewtlEVIYIz0We6OLs759i7Zn1+jBj0kE6MClr9mv6cL F89m3nwK6ajOhVx6E4U3FDLUkQ1Isn7WsHGAZe1MIjXUSCallnLSwNiHHtDf5jrqzTvY tLTmxIXbAZxiJPXJDFsus87TNnt+DaXTWBW3swbCU3y97Xvs3YcCWMzWvZ0BOOTpiiRe oC01hZtnkGSFh1yyIMapidThKx5WlwAaO6zImPv6BvzkVGeNAu5gmz0athrvI/3p5t8k 73FcSEjQ0J4AjD/2fzIV1oyruGr1/VDD0BAmfJHj5ZJqV+rEk8d6sBdA2/KS2iBNTH1x 9sGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=MyGh05VH; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gb15-20020a170907960f00b007269f720fb5si12678718ejc.530.2022.07.24.21.14.09; Sun, 24 Jul 2022 21:14:09 -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=@intel.com header.s=Intel header.b=MyGh05VH; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75DD768B887; Mon, 25 Jul 2022 07:12:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 13AC868B845 for ; Mon, 25 Jul 2022 07:12:20 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658722341; x=1690258341; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Nxs9rrCrG3wqHr3V3+jdBIPZLzcb05JL2RA9v5AxCIs=; b=MyGh05VH88UQhFrIXUWPh0XX/C8GWp8bdsS7JO31miISwo+h7t1QaqwR WvuGbuv+QVL0KG6OXV63VuN7KlB4w5DqOAsSQgNWSX5DjGyzBr8xwS1lC QAEIkMasGFjkZ561OoJDHmRVqvS7c4nhyNyLU29i/GT3SA3N82GVo0EB6 G4aMgkqGyCwgaJzPCpc2zVnjpvBpwAVALgreWHeL0LYR7FjCGqSJpNCYX mNZevGGlzOOptJPkL0UTqVHzvKL7oBM08ICBEJAyzo9FxzSoFjGqd1hWC OZjzYLj3wgM8PGJ9wxSKqkDgNYcZY25VVrhQsCrynO47We1b+zAei2Mt7 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10418"; a="274468246" X-IronPort-AV: E=Sophos;i="5.93,191,1654585200"; d="scan'208";a="274468246" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2022 21:12:17 -0700 X-IronPort-AV: E=Sophos;i="5.93,191,1654585200"; d="scan'208";a="596544050" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2022 21:12:15 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Jul 2022 12:11:50 +0800 Message-Id: <20220725041151.7710-13-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220725041151.7710-1-haihao.xiang@intel.com> References: <20220725041151.7710-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v12 12/13] lavfi/qsv: create mfx session using oneVPL for qsv filters 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JycTVwFZmyP3 From: Haihao Xiang Use the mfxLoader handle in qsv hwdevice to create mfx session for qsv filters. This is in preparation for oneVPL support --- libavfilter/qsvvpp.c | 109 ++++++++++++++++++++++++++++--- libavfilter/qsvvpp.h | 5 ++ libavfilter/vf_deinterlace_qsv.c | 13 ++-- libavfilter/vf_scale_qsv.c | 11 ++-- 4 files changed, 115 insertions(+), 23 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 3f984fd5f9..5068ce0d5a 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -23,8 +23,6 @@ #include "libavutil/common.h" #include "libavutil/mathematics.h" -#include "libavutil/hwcontext.h" -#include "libavutil/hwcontext_qsv.h" #include "libavutil/time.h" #include "libavutil/pixdesc.h" @@ -32,6 +30,12 @@ #include "qsvvpp.h" #include "video.h" +#if QSV_ONEVPL +#include +#else +#define MFXUnload(a) do { } while(0) +#endif + #define IS_VIDEO_MEMORY(mode) (mode & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \ MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) #if QSV_HAVE_OPAQUE @@ -614,13 +618,10 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) } /* create a "slave" session with those same properties, to be used for vpp */ - ret = MFXInit(impl, &ver, &s->session); - if (ret < 0) - return ff_qsvvpp_print_error(avctx, ret, "Error initializing a session"); - else if (ret > 0) { - ff_qsvvpp_print_warning(avctx, ret, "Warning in session initialization"); - return AVERROR_UNKNOWN; - } + ret = ff_qsvvpp_create_mfx_session(avctx, device_hwctx->loader, impl, &ver, + &s->session); + if (ret) + return ret; if (handle) { ret = MFXVideoCORE_SetHandle(s->session, handle_type, handle); @@ -906,3 +907,93 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr return 0; } + +#if QSV_ONEVPL + +int ff_qsvvpp_create_mfx_session(void *ctx, + void *loader, + mfxIMPL implementation, + mfxVersion *pver, + mfxSession *psession) +{ + mfxStatus sts; + mfxSession session = NULL; + uint32_t impl_idx = 0; + + av_log(ctx, AV_LOG_VERBOSE, + "Use Intel(R) oneVPL to create MFX session with the specified MFX loader\n"); + + if (!loader) { + av_log(ctx, AV_LOG_ERROR, "Invalid MFX Loader handle\n"); + return AVERROR(EINVAL); + } + + while (1) { + /* Enumerate all implementations */ + mfxImplDescription *impl_desc; + + sts = MFXEnumImplementations(loader, impl_idx, + MFX_IMPLCAPS_IMPLDESCSTRUCTURE, + (mfxHDL *)&impl_desc); + /* Failed to find an available implementation */ + if (sts == MFX_ERR_NOT_FOUND) + break; + else if (sts != MFX_ERR_NONE) { + impl_idx++; + continue; + } + + sts = MFXCreateSession(loader, impl_idx, &session); + MFXDispReleaseImplDescription(loader, impl_desc); + if (sts == MFX_ERR_NONE) + break; + + impl_idx++; + } + + if (sts < 0) + return ff_qsvvpp_print_error(ctx, sts, + "Error creating a MFX session"); + else if (sts > 0) { + ff_qsvvpp_print_warning(ctx, sts, + "Warning in MFX session creation"); + return AVERROR_UNKNOWN; + } + + *psession = session; + + return 0; +} + +#else + +int ff_qsvvpp_create_mfx_session(void *ctx, + void *loader, + mfxIMPL implementation, + mfxVersion *pver, + mfxSession *psession) +{ + mfxSession session = NULL; + mfxStatus sts; + + av_log(ctx, AV_LOG_VERBOSE, + "Use Intel(R) Media SDK to create MFX session, API version is " + "%d.%d, the required implementation version is %d.%d\n", + MFX_VERSION_MAJOR, MFX_VERSION_MINOR, pver->Major, pver->Minor); + + *psession = NULL; + sts = MFXInit(implementation, pver, &session); + if (sts < 0) + return ff_qsvvpp_print_error(ctx, sts, + "Error initializing an MFX session"); + else if (sts > 0) { + ff_qsvvpp_print_warning(ctx, sts, "Warning in MFX session initialization"); + return AVERROR_UNKNOWN; + } + + *psession = session; + + return 0; +} + +#endif diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h index 3e7d56021b..a8cfcc565a 100644 --- a/libavfilter/qsvvpp.h +++ b/libavfilter/qsvvpp.h @@ -28,6 +28,8 @@ #include "avfilter.h" #include "libavutil/fifo.h" +#include "libavutil/hwcontext.h" +#include "libavutil/hwcontext_qsv.h" #define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads)) #define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads)) @@ -122,4 +124,7 @@ int ff_qsvvpp_print_error(void *log_ctx, mfxStatus err, int ff_qsvvpp_print_warning(void *log_ctx, mfxStatus err, const char *warning_string); +int ff_qsvvpp_create_mfx_session(void *ctx, void *loader, mfxIMPL implementation, + mfxVersion *pver, mfxSession *psession); + #endif /* AVFILTER_QSVVPP_H */ diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c index 50f9156d14..3065d6ac95 100644 --- a/libavfilter/vf_deinterlace_qsv.c +++ b/libavfilter/vf_deinterlace_qsv.c @@ -163,7 +163,7 @@ static int init_out_session(AVFilterContext *ctx) mfxIMPL impl; mfxVideoParam par; mfxStatus err; - int i; + int i, ret; #if QSV_HAVE_OPAQUE opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); @@ -198,13 +198,10 @@ static int init_out_session(AVFilterContext *ctx) /* create a "slave" session with those same properties, to be used for * actual deinterlacing */ - err = MFXInit(impl, &ver, &s->session); - if (err < 0) - return ff_qsvvpp_print_error(ctx, err, "Error initializing a session for deinterlacing"); - else if (err > 0) { - ff_qsvvpp_print_warning(ctx, err, "Warning in session initialization"); - return AVERROR_UNKNOWN; - } + ret = ff_qsvvpp_create_mfx_session(ctx, device_hwctx->loader, impl, &ver, + &s->session); + if (ret) + return ret; if (handle) { err = MFXVideoCORE_SetHandle(s->session, handle_type, handle); diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index fa0152d785..758e730f78 100644 --- a/libavfilter/vf_scale_qsv.c +++ b/libavfilter/vf_scale_qsv.c @@ -278,7 +278,7 @@ static int init_out_session(AVFilterContext *ctx) mfxIMPL impl; mfxVideoParam par; mfxStatus err; - int i; + int i, ret; #if QSV_HAVE_OPAQUE opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME); @@ -315,11 +315,10 @@ static int init_out_session(AVFilterContext *ctx) /* create a "slave" session with those same properties, to be used for * actual scaling */ - err = MFXInit(impl, &ver, &s->session); - if (err != MFX_ERR_NONE) { - av_log(ctx, AV_LOG_ERROR, "Error initializing a session for scaling\n"); - return AVERROR_UNKNOWN; - } + ret = ff_qsvvpp_create_mfx_session(ctx, device_hwctx->loader, impl, &ver, + &s->session); + if (ret) + return ret; if (handle) { err = MFXVideoCORE_SetHandle(s->session, handle_type, handle);