From patchwork Wed Jul 20 08:40:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 36866 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp2255623pzb; Wed, 20 Jul 2022 01:42:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vDCHjARDwJS0fTI1ZiTmxc7tjf5zIOq2NbKVQkAtJ/z8K30d3Z+gfPsT8Wr9LDpvoV0pCn X-Received: by 2002:a05:6402:274c:b0:43a:9204:95fb with SMTP id z12-20020a056402274c00b0043a920495fbmr50287447edd.259.1658306541229; Wed, 20 Jul 2022 01:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658306541; cv=none; d=google.com; s=arc-20160816; b=0HuYgldroRwVT598JH1F8tl+3/99+7ssQI0EopkSco89S7+7OvMYw04K8JtJtyrWFV qhZPBbe0tJPZe1yNTMyeIp7RK3UlXjcZziHNL5UhNVKp5jADs8ywIB1aOOwqv0HxbZIC soZWAh8vfeGTR0QcYciRSM5uGdmHyq08HrSBVuoEhM4UU1aLvxh5X8nDV3utRjD2pEZr SNVxcXInnxBs+6Y49QeogC5zp5vZdUv+ErwGPnHfO/R2IENdXdpbVXW2DYZr8qJXtYCk 1XvOUFrO9md8pPDUcIbNGvhizCk6ABsDZHMa1bWSWJPuTK7RbqTMvT+XiXDkMguXjdL9 /PMA== 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=Gk4hvD7aUhgSpMGeVqsiWviqsjKNMbkfLxZEeKhbRMk5BPvyTligP2p8I5JZSLpxXz TXb2+O5mJJcU4QbFVRZSbBacVO0pZifDypgmi8vJFHs2xO/uguCSpvJdYfWb9qQBsBNI 6YAUdz5lAKzSApaLSOoof1zLxJzf/ts9WNVjCItET7WEWFgf9gD2BWpucnFz6NBfKzk+ Hl19m9GcpeF+opBSe2fNE6Yw9ifh3QmKuvptCV/FBG2X5gzMVKdhrBqwjzo8CANxqhMm +Tc36OjWpGUFaYSeLFL26ErFWIG29ekb/s8y/OFs8rz+QM0PLcAkApeh9h7QzmdxSTRD DNBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=kjWhIjYe; 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 sb13-20020a1709076d8d00b0072ac1a55095si17806351ejc.6.2022.07.20.01.42.20; Wed, 20 Jul 2022 01:42:21 -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=kjWhIjYe; 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 58CB368B8B2; Wed, 20 Jul 2022 11:40:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7A52068B864 for ; Wed, 20 Jul 2022 11:40:43 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658306443; x=1689842443; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Nxs9rrCrG3wqHr3V3+jdBIPZLzcb05JL2RA9v5AxCIs=; b=kjWhIjYei0teiSaIYNacyLPSUaPclA377x5Kl4jj9PcgV5Yl+IZyLYaE b1lKweKta7cJ4xLi2j0URGJlWh2JgM9XsA5e1E4P9CWFXMfuOpg6W1Qjd 1JeJQw89ooKt1JmkONrPtkIoc05snnhGo+YLhJR9jYMdFOxmseRu9vQSD xOuTiB3hDdFsrQtdaryD2gWQt2yH5WHgb6+LLtMgIYNeZbfIAUeQQcNmK YSLrToS1QWgaZW+FE25a7ocDfw3BqKV+iyrjS+4OiLbEfA64hjvhjdJgF 1dQRY2ORb9w7mGBi0TTHJ+hLlL0MqDqvrKGTsPbv+D8Xa8bIWyGEvxDTf Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10413"; a="348412560" X-IronPort-AV: E=Sophos;i="5.92,286,1650956400"; d="scan'208";a="348412560" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2022 01:40:42 -0700 X-IronPort-AV: E=Sophos;i="5.92,286,1650956400"; d="scan'208";a="625574725" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2022 01:40:41 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Jul 2022 16:40:05 +0800 Message-Id: <20220720084006.5033-13-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220720084006.5033-1-haihao.xiang@intel.com> References: <20220720084006.5033-1-haihao.xiang@intel.com> Subject: [FFmpeg-devel] [PATCH v11 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: TG4vlelyblXf 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);