From patchwork Tue Nov 3 18:45:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23366 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 35418447AF5 for ; Tue, 3 Nov 2020 20:47:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D6A268B606; Tue, 3 Nov 2020 20:47:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72B58688083 for ; Tue, 3 Nov 2020 20:47:48 +0200 (EET) Received: by mail-wr1-f47.google.com with SMTP id g12so19570137wrp.10 for ; Tue, 03 Nov 2020 10:47:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NBkd6D6v92RCr6as/dx9Gm0vi34zshrkiPyoHTtDOco=; b=m3h8uJ0K7PSVB/MK90axTu4gAFnepASDce1xJICfCfc+H+M6A+C1ELb/3pbXSFEd1y czKBV51sDjpuDnLwe+EZuJ9QOr3rxynK/M/yTdaGtKfBMCzSeCqRZLVYoucbVXdhY60O 9ZDUkFuc6SNENAes5h3KT34zgptqtlaH/g+6ajL7RAT+JAO8eu56/kaAjSPmfDhmXg68 z6zZJudYd8B5YqBY/uIkFX1mbEUeCghedV6zDw8B4OaSTdw4hIW4la3mALq26CSs5CWx 0BLUbq7vqWWKuXudTM82cTupIuqgGSOkH1ul1rt+bdxFzGjemt1Rl5wt4EkhmQ36yFxW VCGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NBkd6D6v92RCr6as/dx9Gm0vi34zshrkiPyoHTtDOco=; b=OfYMXZZrFvqWzq6K45JFJoRFG/SblYg3OHuw4022zm4BaoE7ddciQ6YDtjqlkf/cSp vrRaUXFhRLdi0Zk04dI9QVyTdMkRPDxSbiCVUruztgAlHcMqO1SLrTIov7RJPs9BfvJA HUz170DQHSWf1+dKgnL3Qu2yWhPhqEreHX71FHZCvZmQKN6oA+U5v8mthOG+EqeQQu2k xeqwXLoTkr1j+Yz9lUPIU3hnLR8dENB3LzRNE/C8lb98ANk7cIn4As4T45AbKgTKwSyX pnXX9DqxYL2cGrNUZUvKyZD83xgS2XiQaOfzJJXEEAeN2mBr0e7+9UEG6B6KQ06fhryJ lPUA== X-Gm-Message-State: AOAM53067jGVu1eJ+tkIq7tp3nnPy8bnvhqWUbqCQf1qm0uPM23/9dhP iMzdrTGOGZ/UxBLvwq0ZKoxXXKQd4WHIJw== X-Google-Smtp-Source: ABdhPJxQQ/s6wC5rB4ceQi/coh9X2cKj8oDep4UjiM4nj2K9FhD4GzR6lrP9R8kc/VBdQU+gBMy2/A== X-Received: by 2002:a5d:4a05:: with SMTP id m5mr2293184wrq.273.1604429267162; Tue, 03 Nov 2020 10:47:47 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:46 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:50 +0000 Message-Id: <20201103184557.18444-1-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 1/8] libavcodec/qsv: enabling d3d11va support, added mfxhdlpair X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adding DX11 relevant device type checks and adjusting callbacks with proper MediaSDK pair type support. Extending structure for proper MediaSDK pair type support. Signed-off-by: Artem Galin --- libavcodec/qsv.c | 53 ++++++++++++++++++++++++++------------- libavcodec/qsv_internal.h | 2 +- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 6e3154e1a3..d9d7c2cb43 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -36,6 +36,8 @@ #include "avcodec.h" #include "qsv_internal.h" +#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) + #if QSV_VERSION_ATLEAST(1, 12) #include "mfx/mfxvp8.h" #endif @@ -243,7 +245,9 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame) int i; for (i = 0; i < ctx->nb_mids; i++) { QSVMid *mid = &ctx->mids[i]; - if (mid->handle == frame->surface.Data.MemId) + mfxHDLPair *pair = (mfxHDLPair*)frame->surface.Data.MemId; + if ((mid->handle_pair->first == pair->first) && + (mid->handle_pair->second == pair->second)) return i; } return AVERROR_BUG; @@ -383,7 +387,11 @@ static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs) int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, const char *load_plugins, int gpu_copy) { +#if CONFIG_D3D11VA + mfxIMPL impl = MFX_IMPL_AUTO_ANY | MFX_IMPL_VIA_D3D11; +#else mfxIMPL impl = MFX_IMPL_AUTO_ANY; +#endif mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } }; mfxInitParam init_par = { MFX_IMPL_AUTO_ANY }; @@ -472,7 +480,7 @@ static AVBufferRef *qsv_create_mids(AVBufferRef *hw_frames_ref) for (i = 0; i < nb_surfaces; i++) { QSVMid *mid = &mids[i]; - mid->handle = frames_hwctx->surfaces[i].Data.MemId; + mid->handle_pair = (mfxHDLPair*)frames_hwctx->surfaces[i].Data.MemId; mid->hw_frames_ref = hw_frames_ref1; } @@ -649,7 +657,7 @@ static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) goto fail; qsv_mid->surf.Info = hw_frames_hwctx->surfaces[0].Info; - qsv_mid->surf.Data.MemId = qsv_mid->handle; + qsv_mid->surf.Data.MemId = qsv_mid->handle_pair; /* map the data to the system memory */ ret = av_hwframe_map(qsv_mid->locked_frame, qsv_mid->hw_frame, @@ -682,7 +690,13 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) { QSVMid *qsv_mid = (QSVMid*)mid; - *hdl = qsv_mid->handle; + mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; + mfxHDLPair *pair_src = (mfxHDLPair*)qsv_mid->handle_pair; + + pair_dst->first = pair_src->first; + + if (pair_src->second != (mfxMemId)MFX_INFINITE) + pair_dst->second = pair_src->second; return MFX_ERR_NONE; } @@ -690,24 +704,19 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, AVBufferRef *device_ref, const char *load_plugins, int gpu_copy) { - static const mfxHandleType handle_types[] = { - MFX_HANDLE_VA_DISPLAY, - MFX_HANDLE_D3D9_DEVICE_MANAGER, - MFX_HANDLE_D3D11_DEVICE, - }; AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)device_ref->data; AVQSVDeviceContext *device_hwctx = device_ctx->hwctx; mfxSession parent_session = device_hwctx->session; mfxInitParam init_par = { MFX_IMPL_AUTO_ANY }; mfxHDL handle = NULL; + int hw_handle_supported = 0; mfxSession session; mfxVersion ver; mfxIMPL impl; mfxHandleType handle_type; mfxStatus err; - - int i, ret; + int ret; err = MFXQueryIMPL(parent_session, &impl); if (err == MFX_ERR_NONE) @@ -716,13 +725,23 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, return ff_qsv_print_error(avctx, err, "Error querying the session attributes"); - for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) { - err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle); - if (err == MFX_ERR_NONE) { - handle_type = handle_types[i]; - break; + if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_VA_DISPLAY; + hw_handle_supported = 1; + } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D11_DEVICE; + hw_handle_supported = 1; + } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; + hw_handle_supported = 1; + } + + if (hw_handle_supported) { + err = MFXVideoCORE_GetHandle(parent_session, handle_type, &handle); + if (err != MFX_ERR_NONE) { + return ff_qsv_print_error(avctx, err, + "Error getting handle session"); } - handle = NULL; } if (!handle) { av_log(avctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved " diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h index 6b2fbbe252..10b08f0f9a 100644 --- a/libavcodec/qsv_internal.h +++ b/libavcodec/qsv_internal.h @@ -62,7 +62,7 @@ typedef struct QSVMid { AVBufferRef *hw_frames_ref; - mfxHDL handle; + mfxHDLPair *handle_pair; AVFrame *locked_frame; AVFrame *hw_frame; From patchwork Tue Nov 3 18:45:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23372 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DEBF94498C1 for ; Tue, 3 Nov 2020 21:12:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B8FFA68B698; Tue, 3 Nov 2020 21:12:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D5A36800D2 for ; Tue, 3 Nov 2020 21:12:36 +0200 (EET) Received: by mail-ej1-f65.google.com with SMTP id s25so11902338ejy.6 for ; Tue, 03 Nov 2020 11:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vWOk2QzdLRl2go9av5V+KStG/26WMIDU8hpDZaKd4U0=; b=DJGznL898zedl0CzkQ0NwPhWlDYISSznTwKeCtdQItxIzf9V4FQ2tLuKkF+VQ8U1e0 me8UE//jMGXeLtUH4QYUV9187zDUU7ftdLk30FXGXikABOhO4Aq7OM/02W6sEvwV2aSW ga5u76qTCeu5TV7URqbvU8uSKERO9nkzO3h/ZSDOmBDQfP/a3zzVHqyKfYwuIRYem18d peK17v38BwnxXC3LdsLP22Kd8T8cZKy8k8Z9VeAj0h5ENW2XhZVdYT97hv+vPpqmaCl7 c+EcW/SBXeFpakXEDPy9ByKqO6Or4nhW5Oo+8yZh7svsQy3FmhxuTnBtPKbhrgY7nTou dl/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vWOk2QzdLRl2go9av5V+KStG/26WMIDU8hpDZaKd4U0=; b=C/p4wWPtQMORhwrUO5ZWeq18QLxgdW/I2Aar1YXxr9E06fGvyld3xm2VEa+H0jEeD7 XDzfrHnUGirzqUmwJdpSTMXL9vwyqtnIY3boAMtkM3f5zDEpmNNI8ExeBBbDwfyty59C s7XNgEI5xYAQXXgRStNZhL2f8D1BGfv5jDmAtcfs+TMjL3/G4xPT+3WxVrRxmR3ZJjSz glpw4owGGVfN4yhYucAPQup9/4X6VIw1sjzWjl3AFI9FSHI7Lm/bDiq+KfC/RC7RozTw 3KsvlOrBm8Qt/Iz2W7WWFajAAQuMTvTWBozs6vwTVTk9RwZDiiyc1pBGPVaasZtXYlSy C/MA== X-Gm-Message-State: AOAM532VLwMZJWhz578sO4YHiw2L0f7DzKevUE5eptgnL+pr3ZdG7k8A JtxNyk0kaLvO3nq54CI63n8BMgUkcWyL2Q== X-Google-Smtp-Source: ABdhPJxxeN8tlnc8mlHJxlI2oWpC9TaH9kXz/dgNRr8yDbtMrzqS/EZH4OLf9hUVLFW8Um8ZaqGp6Q== X-Received: by 2002:adf:df91:: with SMTP id z17mr26863779wrl.379.1604429271586; Tue, 03 Nov 2020 10:47:51 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:51 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:51 +0000 Message-Id: <20201103184557.18444-2-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 2/8] libavutil/hwcontext_qsv: supporting d3d11va device type X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This enables usage of non-powered/headless GPU, better HDR support. Pool of resources is allocated as one texture with array of slices. Signed-off-by: Artem Galin --- libavutil/hwcontext_qsv.c | 323 +++++++++++++++++++++++++++++++------- 1 file changed, 262 insertions(+), 61 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 35a944f8f8..1f5a3d1c57 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -27,9 +27,13 @@ #include #endif +#define COBJMACROS #if CONFIG_VAAPI #include "hwcontext_vaapi.h" #endif +#if CONFIG_D3D11VA +#include "hwcontext_d3d11va.h" +#endif #if CONFIG_DXVA2 #include "hwcontext_dxva2.h" #endif @@ -48,6 +52,8 @@ (MFX_VERSION_MAJOR > (MAJOR) || \ MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR)) +#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) + typedef struct QSVDevicePriv { AVBufferRef *child_device_ctx; } QSVDevicePriv; @@ -74,6 +80,7 @@ typedef struct QSVFramesContext { AVBufferRef *child_frames_ref; mfxFrameSurface1 *surfaces_internal; + mfxHDLPair *handle_pairs_internal; int nb_surfaces_used; // used in the frame allocator for non-opaque surfaces @@ -85,20 +92,6 @@ typedef struct QSVFramesContext { mfxExtBuffer *ext_buffers[1]; } QSVFramesContext; -static const struct { - mfxHandleType handle_type; - enum AVHWDeviceType device_type; - enum AVPixelFormat pix_fmt; -} supported_handle_types[] = { -#if CONFIG_VAAPI - { MFX_HANDLE_VA_DISPLAY, AV_HWDEVICE_TYPE_VAAPI, AV_PIX_FMT_VAAPI }, -#endif -#if CONFIG_DXVA2 - { MFX_HANDLE_D3D9_DEVICE_MANAGER, AV_HWDEVICE_TYPE_DXVA2, AV_PIX_FMT_DXVA2_VLD }, -#endif - { 0 }, -}; - static const struct { enum AVPixelFormat pix_fmt; uint32_t fourcc; @@ -131,24 +124,11 @@ static int qsv_device_init(AVHWDeviceContext *ctx) { AVQSVDeviceContext *hwctx = ctx->hwctx; QSVDeviceContext *s = ctx->internal->priv; - + int hw_handle_supported = 0; + mfxHandleType handle_type; + enum AVHWDeviceType device_type; + enum AVPixelFormat pix_fmt; mfxStatus err; - int i; - - for (i = 0; supported_handle_types[i].handle_type; i++) { - err = MFXVideoCORE_GetHandle(hwctx->session, supported_handle_types[i].handle_type, - &s->handle); - if (err == MFX_ERR_NONE) { - s->handle_type = supported_handle_types[i].handle_type; - s->child_device_type = supported_handle_types[i].device_type; - s->child_pix_fmt = supported_handle_types[i].pix_fmt; - break; - } - } - if (!s->handle) { - av_log(ctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved " - "from the session\n"); - } err = MFXQueryIMPL(hwctx->session, &s->impl); if (err == MFX_ERR_NONE) @@ -158,6 +138,41 @@ static int qsv_device_init(AVHWDeviceContext *ctx) return AVERROR_UNKNOWN; } + if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(s->impl)) { +#if CONFIG_VAAPI + handle_type = MFX_HANDLE_VA_DISPLAY; + device_type = AV_HWDEVICE_TYPE_VAAPI; + pix_fmt = AV_PIX_FMT_VAAPI; + hw_handle_supported = 1; +#endif + } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(s->impl)) { +#if CONFIG_D3D11VA + handle_type = MFX_HANDLE_D3D11_DEVICE; + device_type = AV_HWDEVICE_TYPE_D3D11VA; + pix_fmt = AV_PIX_FMT_D3D11; + hw_handle_supported = 1; +#endif + } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(s->impl)) { +#if CONFIG_DXVA2 + handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; + device_type = AV_HWDEVICE_TYPE_DXVA2; + pix_fmt = AV_PIX_FMT_DXVA2_VLD; + hw_handle_supported = 1; +#endif + } + + if (hw_handle_supported) { + err = MFXVideoCORE_GetHandle(hwctx->session, handle_type, &s->handle); + if (err == MFX_ERR_NONE) { + s->handle_type = handle_type; + s->child_device_type = device_type; + s->child_pix_fmt = pix_fmt; + } + } + if (!s->handle) { + av_log(ctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved " + "from the session\n"); + } return 0; } @@ -187,6 +202,7 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) av_freep(&s->mem_ids); av_freep(&s->surface_ptrs); av_freep(&s->surfaces_internal); + av_freep(&s->handle_pairs_internal); av_buffer_unref(&s->child_frames_ref); } @@ -202,6 +218,8 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, int size) if (s->nb_surfaces_used < hwctx->nb_surfaces) { s->nb_surfaces_used++; + av_buffer_create((uint8_t*)(s->handle_pairs_internal + s->nb_surfaces_used - 1), + sizeof(*s->handle_pairs_internal), qsv_pool_release_dummy, NULL, 0); return av_buffer_create((uint8_t*)(s->surfaces_internal + s->nb_surfaces_used - 1), sizeof(*hwctx->surfaces), qsv_pool_release_dummy, NULL, 0); } @@ -241,6 +259,13 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx) child_device_hwctx->display = (VADisplay)device_priv->handle; } #endif +#if CONFIG_D3D11VA + if (child_device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { + AVD3D11VADeviceContext *child_device_hwctx = child_device_ctx->hwctx; + ID3D11Device_AddRef((ID3D11Device*)device_priv->handle); + child_device_hwctx->device = (ID3D11Device*)device_priv->handle; + } +#endif #if CONFIG_DXVA2 if (child_device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) { AVDXVA2DeviceContext *child_device_hwctx = child_device_ctx->hwctx; @@ -267,6 +292,17 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx) child_frames_ctx->width = FFALIGN(ctx->width, 16); child_frames_ctx->height = FFALIGN(ctx->height, 16); +#if CONFIG_D3D11VA + if (child_device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { + AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx; + if (hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) + child_frames_hwctx->BindFlags = D3D11_BIND_RENDER_TARGET; + else + child_frames_hwctx->BindFlags = D3D11_BIND_DECODER; + if (hwctx->frame_type & MFX_MEMTYPE_SHARED_RESOURCE) + child_frames_hwctx->MiscFlags = D3D11_RESOURCE_MISC_SHARED; + } +#endif #if CONFIG_DXVA2 if (child_device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) { AVDXVA2FramesContext *child_frames_hwctx = child_frames_ctx->hwctx; @@ -286,16 +322,41 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx) #if CONFIG_VAAPI if (child_device_ctx->type == AV_HWDEVICE_TYPE_VAAPI) { AVVAAPIFramesContext *child_frames_hwctx = child_frames_ctx->hwctx; - for (i = 0; i < ctx->initial_pool_size; i++) - s->surfaces_internal[i].Data.MemId = child_frames_hwctx->surface_ids + i; + for (i = 0; i < ctx->initial_pool_size; i++) { + s->handle_pairs_internal[i].first = child_frames_hwctx->surface_ids + i; + s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; + s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; + } hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; } #endif +#if CONFIG_D3D11VA + if (child_device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { + AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx; + for (i = 0; i < ctx->initial_pool_size; i++) { + s->handle_pairs_internal[i].first = (mfxMemId)child_frames_hwctx->texture; + if(child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { + s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; + } else { + s->handle_pairs_internal[i].second = (mfxMemId)i; + } + s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; + } + if (child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { + hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET; + } else { + hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; + } + } +#endif #if CONFIG_DXVA2 if (child_device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) { AVDXVA2FramesContext *child_frames_hwctx = child_frames_ctx->hwctx; - for (i = 0; i < ctx->initial_pool_size; i++) - s->surfaces_internal[i].Data.MemId = (mfxMemId)child_frames_hwctx->surfaces[i]; + for (i = 0; i < ctx->initial_pool_size; i++) { + s->handle_pairs_internal[i].first = (mfxMemId)child_frames_hwctx->surfaces[i]; + s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; + s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; + } if (child_frames_hwctx->surface_type == DXVA2_VideoProcessorRenderTarget) hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET; else @@ -360,6 +421,11 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc) return AVERROR(EINVAL); } + s->handle_pairs_internal = av_mallocz_array(ctx->initial_pool_size, + sizeof(*s->handle_pairs_internal)); + if (!s->handle_pairs_internal) + return AVERROR(ENOMEM); + s->surfaces_internal = av_mallocz_array(ctx->initial_pool_size, sizeof(*s->surfaces_internal)); if (!s->surfaces_internal) @@ -433,7 +499,13 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) { - *hdl = mid; + mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; + mfxHDLPair *pair_src = (mfxHDLPair*)mid; + + pair_dst->first = pair_src->first; + + if (pair_src->second != (mfxMemId)MFX_INFINITE) + pair_dst->second = pair_src->second; return MFX_ERR_NONE; } @@ -626,13 +698,29 @@ static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx, sizeof(*dst_hwctx->surface_ids)); if (!dst_hwctx->surface_ids) return AVERROR(ENOMEM); - for (i = 0; i < src_hwctx->nb_surfaces; i++) - dst_hwctx->surface_ids[i] = - *(VASurfaceID*)src_hwctx->surfaces[i].Data.MemId; + for (i = 0; i < src_hwctx->nb_surfaces; i++) { + mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->surfaces[i].Data.MemId; + dst_hwctx->surface_ids[i] = *(VASurfaceID*)pair->first; + } dst_hwctx->nb_surfaces = src_hwctx->nb_surfaces; } break; #endif +#if CONFIG_D3D11VA + case AV_HWDEVICE_TYPE_D3D11VA: + { + AVD3D11VAFramesContext *dst_hwctx = dst_ctx->hwctx; + mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->surfaces[i].Data.MemId; + dst_hwctx->texture = (ID3D11Texture2D*)pair->first; + if (src_hwctx->frame_type & MFX_MEMTYPE_SHARED_RESOURCE) + dst_hwctx->MiscFlags = D3D11_RESOURCE_MISC_SHARED; + if (src_hwctx->frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET) + dst_hwctx->BindFlags = D3D11_BIND_DECODER; + else + dst_hwctx->BindFlags = D3D11_BIND_RENDER_TARGET; + } + break; +#endif #if CONFIG_DXVA2 case AV_HWDEVICE_TYPE_DXVA2: { @@ -641,9 +729,10 @@ static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx, sizeof(*dst_hwctx->surfaces)); if (!dst_hwctx->surfaces) return AVERROR(ENOMEM); - for (i = 0; i < src_hwctx->nb_surfaces; i++) - dst_hwctx->surfaces[i] = - (IDirect3DSurface9*)src_hwctx->surfaces[i].Data.MemId; + for (i = 0; i < src_hwctx->nb_surfaces; i++) { + mfxHDLPair *pair = (mfxHDLPair*)src_hwctx->surfaces[i].Data.MemId; + dst_hwctx->surfaces[i] = (IDirect3DSurface9*)pair->first; + } dst_hwctx->nb_surfaces = src_hwctx->nb_surfaces; if (src_hwctx->frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET) dst_hwctx->surface_type = DXVA2_VideoDecoderRenderTarget; @@ -677,13 +766,27 @@ static int qsv_map_from(AVHWFramesContext *ctx, switch (child_frames_ctx->device_ctx->type) { #if CONFIG_VAAPI case AV_HWDEVICE_TYPE_VAAPI: - child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)surf->Data.MemId; + { + mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId; + child_data = pair->first; break; + } +#endif +#if CONFIG_D3D11VA + case AV_HWDEVICE_TYPE_D3D11VA: + { + mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId; + child_data = pair->first; + break; + } #endif #if CONFIG_DXVA2 case AV_HWDEVICE_TYPE_DXVA2: - child_data = surf->Data.MemId; + { + mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId; + child_data = pair->first; break; + } #endif default: return AVERROR(ENOSYS); @@ -697,7 +800,14 @@ static int qsv_map_from(AVHWFramesContext *ctx, dst->width = src->width; dst->height = src->height; - dst->data[3] = child_data; + + if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { + mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId; + dst->data[0] = pair->first; + dst->data[1] = pair->second; + } else { + dst->data[3] = child_data; + } return 0; } @@ -720,7 +830,14 @@ static int qsv_map_from(AVHWFramesContext *ctx, dummy->format = child_frames_ctx->format; dummy->width = src->width; dummy->height = src->height; - dummy->data[3] = child_data; + + if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { + mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId; + dummy->data[0] = pair->first; + dummy->data[1] = pair->second; + } else { + dummy->data[3] = child_data; + } ret = av_hwframe_map(dst, dummy, flags); @@ -978,35 +1095,81 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, AVQSVFramesContext *dst_hwctx = dst_ctx->hwctx; int i; + if (src_ctx->initial_pool_size == 0) { + av_log(dst_ctx, AV_LOG_ERROR, "Only fixed-size pools can be " + "mapped to QSV frames.\n"); + return AVERROR(EINVAL); + } + switch (src_ctx->device_ctx->type) { #if CONFIG_VAAPI case AV_HWDEVICE_TYPE_VAAPI: { AVVAAPIFramesContext *src_hwctx = src_ctx->hwctx; + s->handle_pairs_internal = av_mallocz_array(src_ctx->initial_pool_size, sizeof(*s->handle_pairs_internal)); + if (!s->handle_pairs_internal) + return AVERROR(ENOMEM); s->surfaces_internal = av_mallocz_array(src_hwctx->nb_surfaces, sizeof(*s->surfaces_internal)); if (!s->surfaces_internal) return AVERROR(ENOMEM); for (i = 0; i < src_hwctx->nb_surfaces; i++) { qsv_init_surface(dst_ctx, &s->surfaces_internal[i]); - s->surfaces_internal[i].Data.MemId = src_hwctx->surface_ids + i; + s->handle_pairs_internal[i].first = src_hwctx->surface_ids + i; + s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; + s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; } dst_hwctx->nb_surfaces = src_hwctx->nb_surfaces; dst_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; } break; #endif +#if CONFIG_D3D11VA + case AV_HWDEVICE_TYPE_D3D11VA: + { + AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx; + s->handle_pairs_internal = av_mallocz_array(src_ctx->initial_pool_size, sizeof(*s->handle_pairs_internal)); + if (!s->handle_pairs_internal) + return AVERROR(ENOMEM); + s->surfaces_internal = av_mallocz_array(src_ctx->initial_pool_size, + sizeof(*s->surfaces_internal)); + if (!s->surfaces_internal) + return AVERROR(ENOMEM); + for (i = 0; i < src_ctx->initial_pool_size; i++) { + qsv_init_surface(dst_ctx, &s->surfaces_internal[i]); + s->handle_pairs_internal[i].first = (mfxMemId)src_hwctx->texture; + if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { + s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; + } else { + s->handle_pairs_internal[i].second = (mfxMemId)i; + } + s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; + } + dst_hwctx->nb_surfaces = src_ctx->initial_pool_size; + if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { + dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET; + } else { + dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; + } + } + break; +#endif #if CONFIG_DXVA2 case AV_HWDEVICE_TYPE_DXVA2: { AVDXVA2FramesContext *src_hwctx = src_ctx->hwctx; + s->handle_pairs_internal = av_mallocz_array(src_ctx->initial_pool_size, sizeof(*s->handle_pairs_internal)); + if (!s->handle_pairs_internal) + return AVERROR(ENOMEM); s->surfaces_internal = av_mallocz_array(src_hwctx->nb_surfaces, sizeof(*s->surfaces_internal)); if (!s->surfaces_internal) return AVERROR(ENOMEM); for (i = 0; i < src_hwctx->nb_surfaces; i++) { qsv_init_surface(dst_ctx, &s->surfaces_internal[i]); - s->surfaces_internal[i].Data.MemId = (mfxMemId)src_hwctx->surfaces[i]; + s->handle_pairs_internal[i].first = (mfxMemId)src_hwctx->surfaces[i]; + s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; + s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; } dst_hwctx->nb_surfaces = src_hwctx->nb_surfaces; if (src_hwctx->surface_type == DXVA2_VideoProcessorRenderTarget) @@ -1029,21 +1192,44 @@ static int qsv_map_to(AVHWFramesContext *dst_ctx, AVFrame *dst, const AVFrame *src, int flags) { AVQSVFramesContext *hwctx = dst_ctx->hwctx; - int i, err; + int i, err, index = -1; - for (i = 0; i < hwctx->nb_surfaces; i++) { + for (i = 0; i < hwctx->nb_surfaces && index < 0; i++) { + switch(src->format) { #if CONFIG_VAAPI - if (*(VASurfaceID*)hwctx->surfaces[i].Data.MemId == - (VASurfaceID)(uintptr_t)src->data[3]) - break; + case AV_PIX_FMT_VAAPI: + { + mfxHDLPair *pair = (mfxHDLPair*)hwctx->surfaces[i].Data.MemId; + if (pair->first == src->data[3]) { + index = i; + break; + } + } +#endif +#if CONFIG_D3D11VA + case AV_PIX_FMT_D3D11: + { + mfxHDLPair *pair = (mfxHDLPair*)hwctx->surfaces[i].Data.MemId; + if (pair->first == src->data[0] + && pair->second == src->data[1]) { + index = i; + break; + } + } #endif #if CONFIG_DXVA2 - if ((IDirect3DSurface9*)hwctx->surfaces[i].Data.MemId == - (IDirect3DSurface9*)(uintptr_t)src->data[3]) - break; + case AV_PIX_FMT_DXVA2_VLD: + { + mfxHDLPair *pair = (mfxHDLPair*)hwctx->surfaces[i].Data.MemId; + if (pair->first == src->data[3]) { + index = i; + break; + } + } #endif + } } - if (i >= hwctx->nb_surfaces) { + if (index < 0) { av_log(dst_ctx, AV_LOG_ERROR, "Trying to map from a surface which " "is not in the mapped frames context.\n"); return AVERROR(EINVAL); @@ -1056,7 +1242,7 @@ static int qsv_map_to(AVHWFramesContext *dst_ctx, dst->width = src->width; dst->height = src->height; - dst->data[3] = (uint8_t*)&hwctx->surfaces[i]; + dst->data[3] = (uint8_t*)&hwctx->surfaces[index]; return 0; } @@ -1098,7 +1284,7 @@ static void qsv_device_free(AVHWDeviceContext *ctx) av_freep(&priv); } -static mfxIMPL choose_implementation(const char *device) +static mfxIMPL choose_implementation(const char *device, enum AVHWDeviceType child_device_type) { static const struct { const char *name; @@ -1127,6 +1313,10 @@ static mfxIMPL choose_implementation(const char *device) impl = strtol(device, NULL, 0); } + if ( (child_device_type == AV_HWDEVICE_TYPE_D3D11VA) && (impl != MFX_IMPL_SOFTWARE) ) { + impl |= MFX_IMPL_VIA_D3D11; + } + return impl; } @@ -1153,6 +1343,15 @@ static int qsv_device_derive_from_child(AVHWDeviceContext *ctx, } break; #endif +#if CONFIG_D3D11VA + case AV_HWDEVICE_TYPE_D3D11VA: + { + AVD3D11VADeviceContext *child_device_hwctx = child_device_ctx->hwctx; + handle_type = MFX_HANDLE_D3D11_DEVICE; + handle = (mfxHDL)child_device_hwctx->device; + } + break; +#endif #if CONFIG_DXVA2 case AV_HWDEVICE_TYPE_DXVA2: { @@ -1216,7 +1415,9 @@ static int qsv_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *child_device_ctx, AVDictionary *opts, int flags) { - return qsv_device_derive_from_child(ctx, MFX_IMPL_HARDWARE_ANY, + mfxIMPL impl; + impl = choose_implementation("hw_any", child_device_ctx->type); + return qsv_device_derive_from_child(ctx, impl, child_device_ctx, flags); } @@ -1267,7 +1468,7 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, child_device = (AVHWDeviceContext*)priv->child_device_ctx->data; - impl = choose_implementation(device); + impl = choose_implementation(device, child_device_type); return qsv_device_derive_from_child(ctx, impl, child_device, 0); } From patchwork Tue Nov 3 18:45:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23374 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 868CA44A9C4 for ; Tue, 3 Nov 2020 21:19:57 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64D9068B6CB; Tue, 3 Nov 2020 21:19:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67B23687EB0 for ; Tue, 3 Nov 2020 21:19:51 +0200 (EET) Received: by mail-ed1-f67.google.com with SMTP id a10so2376364edt.12 for ; Tue, 03 Nov 2020 11:19:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N/CECbmD9fEpR+nRNwXZy1LskyAIQDNMwNPjTdr+IY8=; b=Tg6lY3ZW4LRLbPCzf8nSgAcTwllK/8RZ+cfNWYOOPZbJs5+fgSPv9NrcsVtPsiFVrE KzcUQqgodM1HQE6G4e5dH2RSKtgLkYkzGbE+JBZPKbWF+vvTAVV14MY9WaqUCDGy5gHD mWDIP1Ep4P4Wxr3zgdrSY28epndbexNR4ax3Tc5Pd7KoXZMESgsSg8sxuxPG2EOWQ1RD dJDT/VI3JsFyBwUxClfkyzxjQPzZV1XFHgcVboAw2lcCYTmmyjQ22Atq9RJ7XwZZ8gtP wo+BHoeX5Bp+zlseQiSAOoq8pHtrxqHiZ541sLt1nRIWMXNgs/X6IfEGGbavjr00QIIj 3NFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N/CECbmD9fEpR+nRNwXZy1LskyAIQDNMwNPjTdr+IY8=; b=pRbpV+5Gjy9TAT5Bb0mDI5PusvmH8gYWAlld4VcNYLoEZa1GPYe4N60yABt7olTtYR 58fcm/+x/R1eto8yiNoEgP4VX9vRztP+pCu36+LFmVlDWFyQTJyQmf5F94ivMQ9r+OD4 gw0P2pXYLuLxn9etuPFNNg7ubVAcgmX2uppjdyYs4iRUiI7L0kxwLJpi7D3eb2OLrouJ ANDDG9An83ev5a6YAIsO+iD5cuDXP+3c/tTti7kb15ficYpgIsAoN3C3Ob8+AETNvKn+ UlBloAb0U781pOnv7WWEBRbxb5tqf8zdM3eAcrhUhHmmmcoJZ8XolKOMs6y9ijqq9SyQ UiKA== X-Gm-Message-State: AOAM533u2jmluTwL4trw4iPYCVdLgyu7NXbHX/ENmdqGhLGKumDA2Hfd YRX/hTeyFfMXgIJofTNNVxaxX00X2Nq+1w== X-Google-Smtp-Source: ABdhPJzd+a92SSpETa4rvH6AcGTke9Ob/ANf4ml679wozdzEeiwGn+vezIc5bT4NtqBwstUkOCxBxw== X-Received: by 2002:adf:9b8e:: with SMTP id d14mr29394039wrc.360.1604429272986; Tue, 03 Nov 2020 10:47:52 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:52 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:52 +0000 Message-Id: <20201103184557.18444-3-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 3/8] libavutil/hwcontext_qsv: enabling d3d11va usage by default, add usage child_device_type argument X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Makes selection of d3d11va device type by default and over DirectX 9, which might break users with older drivers/systems. DCH driver with Gen6th support should be still fine. Decode, encode, transcode have been validated. child_device_type option is responsible for d3d11va/dxva2 device selection Usage examples: DirectX 11 -init_hw_device qsv:hw,child_device_type=d3d11va DirectX 9 is still supported but requires explicit selection -init_hw_device qsv:hw,child_device_type=dxva2 Signed-off-by: Artem Galin --- doc/ffmpeg.texi | 20 ++++++++++++- libavutil/hwcontext_qsv.c | 59 +++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 95d6463685..2fa99813c6 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -974,6 +974,9 @@ device type: @item dxva2 @var{device} is the number of the Direct3D 9 display adapter. +@item d3d11va +@var{device} is the number of the Direct3D 11 display adapter. + @item vaapi @var{device} is either an X11 display name or a DRM render node. If not specified, it will attempt to open the default X11 display (@emph{$DISPLAY}) @@ -997,9 +1000,21 @@ If not specified, it will attempt to open the default X11 display (@emph{$DISPLA @end table If not specified, @samp{auto_any} is used. (Note that it may be easier to achieve the desired result for QSV by creating the -platform-appropriate subdevice (@samp{dxva2} or @samp{vaapi}) and then deriving a +platform-appropriate subdevice (@samp{dxva2} or @samp{d3d11va} or @samp{vaapi}) and then deriving a QSV device from that.) +Alternatively, @samp{child_device_type} helps to choose platform-appropriate subdevice type. +On Windows @samp{d3d11va} is used as default subdevice type. + +Examples: +@table @emph +@item -init_hw_device qsv:hw,child_device_type=d3d11va +Choose the GPU subdevice with type @samp{d3d11va} and create QSV device with @samp{MFX_IMPL_HARDWARE}. + +@item -init_hw_device qsv:hw,child_device_type=dxva2 +Choose the GPU subdevice with type @samp{dxva2} and create QSV device with @samp{MFX_IMPL_HARDWARE}. +@end table + @item opencl @var{device} selects the platform and device as @emph{platform_index.device_index}. @@ -1102,6 +1117,9 @@ Use VDPAU (Video Decode and Presentation API for Unix) hardware acceleration. @item dxva2 Use DXVA2 (DirectX Video Acceleration) hardware acceleration. +@item d3d11va +Use D3D11VA (DirectX Video Acceleration) hardware acceleration. + @item vaapi Use VAAPI (Video Acceleration API) hardware acceleration. diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 1f5a3d1c57..c0a71c9822 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1440,28 +1440,59 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, ctx->user_opaque = priv; ctx->free = qsv_device_free; - e = av_dict_get(opts, "child_device", NULL, 0); - - child_device_opts = NULL; - if (CONFIG_VAAPI) { + e = av_dict_get(opts, "child_device_type", NULL, 0); + if (e) { + child_device_type = av_hwdevice_find_type_by_name(e ? e->value : NULL); + if (child_device_type == AV_HWDEVICE_TYPE_NONE) { + av_log(ctx, AV_LOG_ERROR, "Unknown child device type " + "\"%s\".\n", e ? e->value : NULL); + return AVERROR(EINVAL); + } + } else if (CONFIG_VAAPI) { child_device_type = AV_HWDEVICE_TYPE_VAAPI; - // libmfx does not actually implement VAAPI properly, rather it - // depends on the specific behaviour of a matching iHD driver when - // used on recent Intel hardware. Set options to the VAAPI device - // creation so that we should pick a usable setup by default if - // possible, even when multiple devices and drivers are available. - av_dict_set(&child_device_opts, "kernel_driver", "i915", 0); - av_dict_set(&child_device_opts, "driver", "iHD", 0); - } else if (CONFIG_DXVA2) + } else if (CONFIG_D3D11VA) { + child_device_type = AV_HWDEVICE_TYPE_D3D11VA; + } else if (CONFIG_DXVA2) { child_device_type = AV_HWDEVICE_TYPE_DXVA2; - else { + } else { av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); return AVERROR(ENOSYS); } + child_device_opts = NULL; + switch (child_device_type) { +#if CONFIG_VAAPI + case AV_HWDEVICE_TYPE_VAAPI: + { + // libmfx does not actually implement VAAPI properly, rather it + // depends on the specific behaviour of a matching iHD driver when + // used on recent Intel hardware. Set options to the VAAPI device + // creation so that we should pick a usable setup by default if + // possible, even when multiple devices and drivers are available. + av_dict_set(&child_device_opts, "kernel_driver", "i915", 0); + av_dict_set(&child_device_opts, "driver", "iHD", 0); + } + break; +#endif +#if CONFIG_D3D11VA + case AV_HWDEVICE_TYPE_D3D11VA: + break; +#endif +#if CONFIG_DXVA2 + case AV_HWDEVICE_TYPE_DXVA2: + break; +#endif + default: + { + av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); + return AVERROR(ENOSYS); + } + break; + } + + e = av_dict_get(opts, "child_device", NULL, 0); ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type, e ? e->value : NULL, child_device_opts, 0); - av_dict_free(&child_device_opts); if (ret < 0) return ret; From patchwork Tue Nov 3 18:45:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23373 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1605C449A23 for ; Tue, 3 Nov 2020 21:13:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E9D8468B6CB; Tue, 3 Nov 2020 21:13:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1AD1168AC9B for ; Tue, 3 Nov 2020 21:13:05 +0200 (EET) Received: by mail-ej1-f66.google.com with SMTP id cw8so12286519ejb.8 for ; Tue, 03 Nov 2020 11:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pKrnCKWAkAKyvgsAX4sdedDTJsaoCyAIeyYtfw7KZaw=; b=LYXkr9XTJJGFBjt9ntonZrpci+6O6hZoF95aoBeJn0AUdAaHWYpXm5Q+QkIGGKTIch Q1wIFoCBE3c7KBz+4mHgfK1o+6fOIx2oHu6Aw7KVtbzYCgq98qnwY1e8S2rqiDAnL0D1 kmnkUCwHsgDAiiG0KFKNAvuxH2ORn4u1kLNJ2mxWUi/l3S4wKkTBNpFGSIbKigsP7TvJ whEskobAh+PE/+2jnMezKu3W0YXewRKpE0+OaAGtupasSZ1AR07JxdpstQDcOWAQGHpR wO0W/kAxeFaPXd4FYY9C9dnRTdNi5frJM6QWneMhuB2U5p+5Vq4uIxzDiunGl2ze1had aedg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pKrnCKWAkAKyvgsAX4sdedDTJsaoCyAIeyYtfw7KZaw=; b=Gm1109YwqIfBUv3e0eG5mIJVxboUHtZSZcsUkaf0f4US8IGMwRlRNfmpp8xg9zuuM3 eLiGZtM8veRGt9ifSBq2ap8z22CiYhQGKL17K3xX+wFD1VbgshLU0Bhm1W/d44xWeA27 RX6CJCT1w+WWyIdfKdXP+CcDgAa/KANonSaKlduJPRuWiuiiN59ZwxZvqKMbUsCzsd4k G+VOF09cCj0UXmOpFuCV6f7B42iSEMoKs+F5C5cUJahExjgi1gxX1WX9DnBoYggBN204 0c/aS/re6P8HZ9zI5f21C6nQQ6nfz4ra4914GSt1OlMjHFeDIvKGyNCt0aMd1g7LhPC+ udlg== X-Gm-Message-State: AOAM5325G3pPuIpWCRbEiQNrcHVyoMQqM+BX4L2h9lY9Fq3uPF7xA9dk Kg+IDJ6AytDBMJLXdeSzd5i7YFjIxOxB1A== X-Google-Smtp-Source: ABdhPJy62p35OjfWU24y8SuLh7mFkAu049A8dlpIjEVJElhT/POyXi2Dj8vc4YGYto7GOtGKF/m21g== X-Received: by 2002:a05:6000:107:: with SMTP id o7mr27420047wrx.354.1604429274269; Tue, 03 Nov 2020 10:47:54 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:53 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:53 +0000 Message-Id: <20201103184557.18444-4-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 4/8] libavutil/hwcontext_d3d11va: adding more texture information to the D3D11 hwcontext API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Microsoft VideoProcessor requires texture with D3DUSAGE_RENDERTARGET flag as output. There is no way to allocate array of textures with D3D11_BIND_RENDER_TARGET flag and .ArraySize > 2 by ID3D11Device_CreateTexture2D due to the Microsoft limitation. Adding AVD3D11FrameDescriptors array to store array of single textures instead of texture with multiple slices resolves this. Signed-off-by: Artem Galin --- libavutil/hwcontext_d3d11va.c | 24 ++++++++++++++++++----- libavutil/hwcontext_d3d11va.h | 9 +++++++++ libavutil/hwcontext_qsv.c | 37 +++++++++++++++++++++++------------ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c index c8ae58f908..1f95eae24a 100644 --- a/libavutil/hwcontext_d3d11va.c +++ b/libavutil/hwcontext_d3d11va.c @@ -72,6 +72,7 @@ static av_cold void load_functions(void) } typedef struct D3D11VAFramesContext { + int nb_surfaces; int nb_surfaces_used; DXGI_FORMAT format; @@ -112,6 +113,8 @@ static void d3d11va_frames_uninit(AVHWFramesContext *ctx) if (s->staging_texture) ID3D11Texture2D_Release(s->staging_texture); s->staging_texture = NULL; + + av_freep(&frames_hwctx->texture_infos); } static int d3d11va_frames_get_constraints(AVHWDeviceContext *ctx, @@ -152,15 +155,21 @@ static void free_texture(void *opaque, uint8_t *data) av_free(data); } -static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index) +static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *tex, int index) { AVBufferRef *buf; - AVD3D11FrameDescriptor *desc = av_mallocz(sizeof(*desc)); + AVD3D11FrameDescriptor *desc = av_mallocz(sizeof(*desc)); + D3D11VAFramesContext *s = ctx->internal->priv; + AVD3D11VAFramesContext *frames_hwctx = ctx->hwctx; if (!desc) { ID3D11Texture2D_Release(tex); return NULL; } + frames_hwctx->texture_infos[s->nb_surfaces_used].texture = tex; + frames_hwctx->texture_infos[s->nb_surfaces_used].index = index; + s->nb_surfaces_used++; + desc->texture = tex; desc->index = index; @@ -199,7 +208,7 @@ static AVBufferRef *d3d11va_alloc_single(AVHWFramesContext *ctx) return NULL; } - return wrap_texture_buf(tex, 0); + return wrap_texture_buf(ctx, tex, 0); } static AVBufferRef *d3d11va_pool_alloc(void *opaque, int size) @@ -220,7 +229,7 @@ static AVBufferRef *d3d11va_pool_alloc(void *opaque, int size) } ID3D11Texture2D_AddRef(hwctx->texture); - return wrap_texture_buf(hwctx->texture, s->nb_surfaces_used++); + return wrap_texture_buf(ctx, hwctx->texture, s->nb_surfaces_used); } static int d3d11va_frames_init(AVHWFramesContext *ctx) @@ -267,7 +276,7 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx) av_log(ctx, AV_LOG_ERROR, "User-provided texture has mismatching parameters\n"); return AVERROR(EINVAL); } - } else if (texDesc.ArraySize > 0) { + } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) && texDesc.ArraySize > 0) { hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &hwctx->texture); if (FAILED(hr)) { av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr); @@ -275,6 +284,11 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx) } } + hwctx->texture_infos = av_mallocz_array(ctx->initial_pool_size, sizeof(*hwctx->texture_infos)); + if (!hwctx->texture_infos) + return AVERROR(ENOMEM); + s->nb_surfaces = ctx->initial_pool_size; + ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor), ctx, d3d11va_pool_alloc, NULL); if (!ctx->internal->pool_internal) diff --git a/libavutil/hwcontext_d3d11va.h b/libavutil/hwcontext_d3d11va.h index 9f91e9b1b6..77d2d72f1b 100644 --- a/libavutil/hwcontext_d3d11va.h +++ b/libavutil/hwcontext_d3d11va.h @@ -164,6 +164,15 @@ typedef struct AVD3D11VAFramesContext { * This field is ignored/invalid if a user-allocated texture is provided. */ UINT MiscFlags; + + /** + * In case if texture structure member above is not NULL contains the same texture + * pointer for all elements and different indexes into the array texture. + * In case if texture structure member above is NULL, all elements contains + * pointers to separate non-array textures and 0 indexes. + * This field is ignored/invalid if a user-allocated texture is provided. + */ + AVD3D11FrameDescriptor *texture_infos; } AVD3D11VAFramesContext; #endif /* AVUTIL_HWCONTEXT_D3D11VA_H */ diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index c0a71c9822..b4fa1d845e 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -120,6 +120,23 @@ static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt) return 0; } +#if CONFIG_D3D11VA +static uint32_t qsv_get_d3d11va_bind_flags(int mem_type) +{ + uint32_t bind_flags = 0; + + if ((mem_type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (mem_type & MFX_MEMTYPE_INTERNAL_FRAME)) + bind_flags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER; + else + bind_flags = D3D11_BIND_DECODER; + + if ((MFX_MEMTYPE_FROM_VPPOUT & mem_type) || (MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & mem_type)) + bind_flags = D3D11_BIND_RENDER_TARGET; + + return bind_flags; +} +#endif + static int qsv_device_init(AVHWDeviceContext *ctx) { AVQSVDeviceContext *hwctx = ctx->hwctx; @@ -295,12 +312,11 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx) #if CONFIG_D3D11VA if (child_device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx; - if (hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) - child_frames_hwctx->BindFlags = D3D11_BIND_RENDER_TARGET; - else - child_frames_hwctx->BindFlags = D3D11_BIND_DECODER; + if (hwctx->frame_type == 0) + hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET; if (hwctx->frame_type & MFX_MEMTYPE_SHARED_RESOURCE) child_frames_hwctx->MiscFlags = D3D11_RESOURCE_MISC_SHARED; + child_frames_hwctx->BindFlags = qsv_get_d3d11va_bind_flags(hwctx->frame_type); } #endif #if CONFIG_DXVA2 @@ -334,11 +350,11 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx) if (child_device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) { AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx; for (i = 0; i < ctx->initial_pool_size; i++) { - s->handle_pairs_internal[i].first = (mfxMemId)child_frames_hwctx->texture; + s->handle_pairs_internal[i].first = (mfxMemId)child_frames_hwctx->texture_infos[i].texture; if(child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; } else { - s->handle_pairs_internal[i].second = (mfxMemId)i; + s->handle_pairs_internal[i].second = (mfxMemId)child_frames_hwctx->texture_infos[i].index; } s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; } @@ -714,10 +730,7 @@ static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx, dst_hwctx->texture = (ID3D11Texture2D*)pair->first; if (src_hwctx->frame_type & MFX_MEMTYPE_SHARED_RESOURCE) dst_hwctx->MiscFlags = D3D11_RESOURCE_MISC_SHARED; - if (src_hwctx->frame_type == MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET) - dst_hwctx->BindFlags = D3D11_BIND_DECODER; - else - dst_hwctx->BindFlags = D3D11_BIND_RENDER_TARGET; + dst_hwctx->BindFlags = qsv_get_d3d11va_bind_flags(src_hwctx->frame_type); } break; #endif @@ -1137,11 +1150,11 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, return AVERROR(ENOMEM); for (i = 0; i < src_ctx->initial_pool_size; i++) { qsv_init_surface(dst_ctx, &s->surfaces_internal[i]); - s->handle_pairs_internal[i].first = (mfxMemId)src_hwctx->texture; + s->handle_pairs_internal[i].first = (mfxMemId)src_hwctx->texture_infos[i].texture; if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { s->handle_pairs_internal[i].second = (mfxMemId)MFX_INFINITE; } else { - s->handle_pairs_internal[i].second = (mfxMemId)i; + s->handle_pairs_internal[i].second = (mfxMemId)src_hwctx->texture_infos[i].index; } s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; } From patchwork Tue Nov 3 18:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23370 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4D4894486F8 for ; Tue, 3 Nov 2020 20:56:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A0C368B66C; Tue, 3 Nov 2020 20:56:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C79F468AA85 for ; Tue, 3 Nov 2020 20:55:59 +0200 (EET) Received: by mail-ej1-f67.google.com with SMTP id o9so23671580ejg.1 for ; Tue, 03 Nov 2020 10:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IVP760uBZfXy6Tyt9Ctc0mRMVdekJxk7WFzjrYBbr34=; b=XVuwxf3AYZRcCDBC0DELHtfaVwpBtk7pnccu1gTbxYKFWMxnqfPDD9WH/GWYL67xQv xnQvC7NzlIHnsQcl8wewxYE3rASQwsfZrUy2ajqAmbWRlY6/4oJNOb5zuVoVMidj9lIW vbot8MJNqbVG55CRz0Aa+loIHE4VogNrRxQM+MtLh7LTfx8lonUI2JSenrxL3fNSeqvU zUvWIOfaLCLEI4GHLgqjqdBnMP4wCh+zqRsdIIs1pJbibUOeUAMtzxzbxQMZNWWMn4Cg ANX01TnMNKyuA50qyVJ30unL2842Vi7lj7YdnzDBVzd1K/P75OuXjKgvPS9dA+/P6eO4 +25g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IVP760uBZfXy6Tyt9Ctc0mRMVdekJxk7WFzjrYBbr34=; b=FPRrE09EsTnfW/A/HaTWQUd4s43UfBd3f8im0piMYrzTGxQEK1chijsaEZivg0W2BE wf/rcEenhI00Rq67cqCMCzMUm4kVAOfRLoc+Lib0uTeo6EORQUazBJXg3d2AgWQbFVuo x/vD0moROmpwNRVUOTiMvFUYwAb4RadU4htzTphtN8ZcIXNIZqCbIcOEloF3Cvy1TdfL w2eCLx+AWscb+/2Vqb15LrOg1coUF6CPdyMKRzk115FdVWG1ioJe2z/jUJwnSpgxEVJJ O2aDHRhiugBvr8zX9PTLwd5Tj5nT163bIJezyWFRidNQnX5VWwihaXlYDN1v6u68qmfe lcAQ== X-Gm-Message-State: AOAM532Eai+Yx1QbuT2vQZ/ncnwoExPy28GlJ0T1mRs1eUM6Jv+RuS5P DHVbZMjyAkdkMlRslekmzHSFwTXzyYb5lA== X-Google-Smtp-Source: ABdhPJxugIe7t4fCuqN5/B36z5Kxi8r1u/4am5y70LQYCZMtnul02JvDrf0kETUuEHZp5jGWdWqsQQ== X-Received: by 2002:adf:f247:: with SMTP id b7mr29780241wrp.56.1604429275544; Tue, 03 Nov 2020 10:47:55 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:55 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:54 +0000 Message-Id: <20201103184557.18444-5-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 5/8] libavfilter/qsvvpp: enabling d3d11va support, added mfxhdlpair X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adding DX11 relevant device type checks and adjusting callback with proper MediaSDK pair type support. Signed-off-by: Artem Galin --- libavfilter/qsvvpp.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index 8d5ff2eb65..0d3f7fb2f9 100644 --- a/libavfilter/qsvvpp.c +++ b/libavfilter/qsvvpp.c @@ -36,6 +36,7 @@ MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME) #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY) +#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) typedef struct QSVFrame { AVFrame *frame; @@ -68,12 +69,6 @@ struct QSVVPPContext { int nb_ext_buffers; }; -static const mfxHandleType handle_types[] = { - MFX_HANDLE_VA_DISPLAY, - MFX_HANDLE_D3D9_DEVICE_MANAGER, - MFX_HANDLE_D3D11_DEVICE, -}; - static const AVRational default_tb = { 1, 90000 }; /* functions for frameAlloc */ @@ -129,7 +124,13 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) { - *hdl = mid; + mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; + mfxHDLPair *pair_src = (mfxHDLPair*)mid; + + pair_dst->first = pair_src->first; + + if (pair_src->second != (mfxMemId)MFX_INFINITE) + pair_dst->second = pair_src->second; return MFX_ERR_NONE; } @@ -497,14 +498,18 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) return AVERROR_UNKNOWN; } - for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) { - ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle); - if (ret == MFX_ERR_NONE) { - handle_type = handle_types[i]; - break; - } + if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_VA_DISPLAY; + } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D11_DEVICE; + } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; + } else { + av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n"); + return AVERROR_UNKNOWN; } + ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle); if (ret != MFX_ERR_NONE) { av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n"); return AVERROR_UNKNOWN; From patchwork Tue Nov 3 18:45:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23368 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1B218447BBA for ; Tue, 3 Nov 2020 20:48:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 045D968B67A; Tue, 3 Nov 2020 20:48:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9FD668B67D for ; Tue, 3 Nov 2020 20:47:57 +0200 (EET) Received: by mail-wr1-f54.google.com with SMTP id x7so19619750wrl.3 for ; Tue, 03 Nov 2020 10:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rmr+Z8YJessS6VVHupwwcoZZ1MIxfp1Z59u0dLWT13Q=; b=jaC4MqEFcBocxnEKHEyAv+gKjZq1uHkGQ2AgxKC1RyQzUjUtPLAvximzfwaFXltSss 7YlaBRD6jLVqCtDueDK0DlxT4gDne4vDAfcCGQqQfu3GVfMg2S9/SStuBHHkSeh3hByz kfALCgLmjbAwvyIixmtq3mNjsN7r3XN4Sdim0A7XWn0an6iAji3fGqJCHvs2i3cJB9DE Wh/hJXVJaNTUeWZ3i5s7IkW81kko0EaHPNmM6W4bgCe2wQ9sA1iq1yCbHiXvoXor0wRC AZrMpr3IXIYVQu1kdV1f6hoy1NbkKHxGmfuiEKj6iG+GovBN64nT1OKvO+QiYCYxWiW3 YxAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rmr+Z8YJessS6VVHupwwcoZZ1MIxfp1Z59u0dLWT13Q=; b=icAAucLvsdoczmwHDKtElzdY7/zALihrAQBpQX+InubSbAoxjpMRHupJJUk4K/Ar2A ClplcgzLiM1wBPbjcixJztQtZUGFOItvWLxcvSbIKscV1slQIwvvcbw/76ntQy0knGu3 eJmo7EuRq03t6Y6sSfyelkcq5md4XF0MAF5QS/cH/pj0gORUySpuCbKMdKPR/gt2CiPj 8yz7RP16Jnl43pT0faYnJ7aqoMPL5v0CAgtjlMgK49SKlhuakaufzKcYisY7V2Ilad2Q BNjz3SAQJvqWNmIrZ7IIRekk6Aq5PFY3jdVwGcQ2X1odu/oHpuka9eTW1vRCyd+i5KGI M8fA== X-Gm-Message-State: AOAM533/jc6f24nWqYQesUkrif6sx7oeNDYP0KCdVuNOMQfkTzmXiI4G 302tRe/g8Y2rM/o/KLhU/RwwqlzBpSHBWw== X-Google-Smtp-Source: ABdhPJwqDTwMRXn1w8MI2mUdNmnAtHTS6wHbfxc3xOHJExbIHzezt4DkBkUmlcWHL7UmV5tIqBaNIA== X-Received: by 2002:adf:e9c9:: with SMTP id l9mr2148205wrn.124.1604429276869; Tue, 03 Nov 2020 10:47:56 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:56 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:55 +0000 Message-Id: <20201103184557.18444-6-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 6/8] libavfilter/vf_scale_qsv: enabling d3d11va support, added mfxhdlpair X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adding DX11 relevant device type checks and adjusting callback with proper MediaSDK pair type support. Signed-off-by: Artem Galin --- libavfilter/vf_scale_qsv.c | 43 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index 5064dcbb60..47701c20d0 100644 --- a/libavfilter/vf_scale_qsv.c +++ b/libavfilter/vf_scale_qsv.c @@ -70,6 +70,7 @@ enum var_name { }; #define QSV_HAVE_SCALING_CONFIG QSV_VERSION_ATLEAST(1, 19) +#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) typedef struct QSVScaleContext { const AVClass *class; @@ -264,16 +265,16 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) { - *hdl = mid; + mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; + mfxHDLPair *pair_src = (mfxHDLPair*)mid; + + pair_dst->first = pair_src->first; + + if (pair_src->second != (mfxMemId)MFX_INFINITE) + pair_dst->second = pair_src->second; return MFX_ERR_NONE; } -static const mfxHandleType handle_types[] = { - MFX_HANDLE_VA_DISPLAY, - MFX_HANDLE_D3D9_DEVICE_MANAGER, - MFX_HANDLE_D3D11_DEVICE, -}; - static int init_out_session(AVFilterContext *ctx) { @@ -292,28 +293,32 @@ static int init_out_session(AVFilterContext *ctx) mfxIMPL impl; mfxVideoParam par; mfxStatus err; - int i; + int ret, i; s->num_ext_buf = 0; /* extract the properties of the "master" session given to us */ - err = MFXQueryIMPL(device_hwctx->session, &impl); - if (err == MFX_ERR_NONE) - err = MFXQueryVersion(device_hwctx->session, &ver); - if (err != MFX_ERR_NONE) { + ret = MFXQueryIMPL(device_hwctx->session, &impl); + if (ret == MFX_ERR_NONE) + ret = MFXQueryVersion(device_hwctx->session, &ver); + if (ret != MFX_ERR_NONE) { av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n"); return AVERROR_UNKNOWN; } - for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) { - err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle); - if (err == MFX_ERR_NONE) { - handle_type = handle_types[i]; - break; - } + if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_VA_DISPLAY; + } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D11_DEVICE; + } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; + } else { + av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n"); + return AVERROR_UNKNOWN; } - if (err != MFX_ERR_NONE) { + ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle); + if (ret != MFX_ERR_NONE) { av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n"); return AVERROR_UNKNOWN; } From patchwork Tue Nov 3 18:45:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23369 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5516544ABB4 for ; Tue, 3 Nov 2020 20:54:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A26A68B606; Tue, 3 Nov 2020 20:54:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 328D568096F for ; Tue, 3 Nov 2020 20:54:09 +0200 (EET) Received: by mail-ed1-f67.google.com with SMTP id o20so1378493eds.3 for ; Tue, 03 Nov 2020 10:54:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kWgdWq1tPdhITSPMASLpMG35uA+W2SfvCTBDZg3w2ss=; b=Cu+BeC4PtnA79abluQ/ukWqWMnN8M0rrlqycWeYNfEPNDX5fvrw+373HSGkObyZXQ8 CrqIp7FFiI8ff+Smw9ql15297EEu7IJVm1fCtsoHxNIQ/scm7Jtf9QgtWnN+blY46fwC SL9xvCWsaPfCJV+JU2bHJpNnziidm/rjP5J0lkndI6cAe/RmLktkCADaBni7+8DROky+ 2xPwJAZeQOQApNd/h2Z9bkA37X3JhVRRmpfykhfK9iiDLHdAVRdDzD5UzeLJl4mIfhvh YvhtvgA+zhs97W3iaIH6pkxhF5MNgq73nlKBUsFkB3GC/eWCo8PmjnR6WZzNwNeVE5uR nv2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kWgdWq1tPdhITSPMASLpMG35uA+W2SfvCTBDZg3w2ss=; b=AmPndVqLPg2Yaftl0VtZUQoaw7W2PVLpfnTUiLONw2cKDpozDHZHh6HX7XnTZ1OUVE 1Hi92l0JK9CcKeAwyY/mRokr3wsKksoscbAJC7eWbfE5ME11A1qDRtZ/GFfxlSkYOsSj s1RxBjndIUcOLgyz7uEiR+GfNBLVDnxfTJlYbgDhN8WfxEadqlTjRjcCPphty6T+DfTv hmRXTPCVROlVx5r73tt7ZGgGBPd34j3qkYAR8vONg1KZ19yCwfdDU2qmRT9hDwQlLSLA vFunhpc7gGskrTFr+STvdr5dhS7UQwJ9B2UTu+j0GNUvgGqi/0bGHBg1FWkAIH6SAUnl iv0A== X-Gm-Message-State: AOAM532JnSI2ieMDcr9mXiBf7JzO/iNEeqi2sZAe/VFfC9XT5RvXRNRp mGbS/A9F6I9+xdfP7W2kWK8IrFypKtOnig== X-Google-Smtp-Source: ABdhPJwE73DoluDllCcCGVT3hPPRNPuYRgJaM4QF2VAFcJFfJFncPKBSJQyKbRTRf5g3CohkjwXNvw== X-Received: by 2002:adf:ec50:: with SMTP id w16mr27601549wrn.265.1604429278267; Tue, 03 Nov 2020 10:47:58 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:57 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:56 +0000 Message-Id: <20201103184557.18444-7-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 7/8] libavfilter/vf_scale_qsv: add MFX_MEMTYPE_FROM_VPPOUT flag to frame_type X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" In case of DX11 device type, Media SDK is sensitive to these flags. Signed-off-by: Artem Galin --- libavfilter/vf_scale_qsv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index 47701c20d0..9eb59325c3 100644 --- a/libavfilter/vf_scale_qsv.c +++ b/libavfilter/vf_scale_qsv.c @@ -207,7 +207,7 @@ static int init_out_pool(AVFilterContext *ctx, out_frames_ctx->sw_format = out_format; out_frames_ctx->initial_pool_size = 4; - out_frames_hwctx->frame_type = in_frames_hwctx->frame_type; + out_frames_hwctx->frame_type = in_frames_hwctx->frame_type | MFX_MEMTYPE_FROM_VPPOUT; ret = ff_filter_init_hw_frames(ctx, outlink, 32); if (ret < 0) From patchwork Tue Nov 3 18:45:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23371 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5653D4486F8 for ; Tue, 3 Nov 2020 20:56:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3BC5068B650; Tue, 3 Nov 2020 20:56:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A71FF68AEBC for ; Tue, 3 Nov 2020 20:56:12 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id e2so322381wme.1 for ; Tue, 03 Nov 2020 10:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jLGvs8RksZMDXQ1s4wXJk6hENWlH4DFQIBoOxgPcmxg=; b=AL0Gx6B1lqHes6KdMh98CwVE2Qc5kJjDox7HyzG+PQg4HBayx57LNdYYFCE9LnyTNH PfZewIvmTlAUjuvWel3WCFJgr/4Pud9h33fTU7nGtDBqgI1s0zmt2ptk3MlviMSjAeG6 szv6gp8yefSETn1M8nnjPsXtvvAwuLk/OUe3Dj9pIOswLdLDoh/6dLibHiE6CGZ0TFQG OTK9+HFuHiybb88WtBGHjJsKBrsbnDg7zVgYAlndKf/WRwRQQNnDcOD11HcSCiAwqHPP 8AgvG/IR3OLdI6XtC9ewD2thfAtMvx8FS2FlEVCewG6/oS06X+gl0l9URTf/nww6Jg/4 jJOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jLGvs8RksZMDXQ1s4wXJk6hENWlH4DFQIBoOxgPcmxg=; b=BCxaSLUvjPyctOE5SLJN1XGVSwVyW3juzzbxtz1xGZWB/JEx6pzomQrWC+gYtsOB8D wCJo3L4tVHqiAWDq7xIBtoAS+7qAvdS65AYtRxRZBOoMcbqLsMY9UpMyaSDfh5plhN1w OTCXPK8BX0XHR2B5B1q639N10B8kkf3EHL2liyr8i7zswE0UVYMMfsqxHwAbeEMI0S4v dDFsEDUnCi+dbjuCAw7FEVf72Gv6V4xQFIJg6+p+XTo22SrNEXtlTIAzO837213yOL4i hU8+hVejw8fRBKkYunnhqzXxAeSQdc7rg0977KVKBF6z46726Bthy52cvEuS5SyfmMFx NWjQ== X-Gm-Message-State: AOAM530TJbCJE/wNGOlseVaTWacwvGV699GtWW/DxTB62r5dtuZKpMiN b3AAC5l+tBotgGOJvJVIfNgtRrTxgqN24A== X-Google-Smtp-Source: ABdhPJyJQfco5TJNL2JB6/0uaqN4Genj9f6lIxCQhHULW34rOYRvWUsjy17gxwPqS9q/TKfOtLFa7w== X-Received: by 2002:a1c:b346:: with SMTP id c67mr576003wmf.60.1604429279605; Tue, 03 Nov 2020 10:47:59 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:59 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:57 +0000 Message-Id: <20201103184557.18444-8-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 8/8] libavfilter/vf_deinterlace_qsv: enabling d3d11va support, added mfxhdlpair X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adding DX11 relevant device type checks and adjusting callback with proper MediaSDK pair type support. Signed-off-by: Artem Galin --- libavfilter/vf_deinterlace_qsv.c | 44 ++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c index 80217c8419..f7f9d916db 100644 --- a/libavfilter/vf_deinterlace_qsv.c +++ b/libavfilter/vf_deinterlace_qsv.c @@ -42,6 +42,8 @@ #include "internal.h" #include "video.h" +#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) + enum { QSVDEINT_MORE_OUTPUT = 1, QSVDEINT_MORE_INPUT, @@ -157,16 +159,16 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr) static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl) { - *hdl = mid; + mfxHDLPair *pair_dst = (mfxHDLPair*)hdl; + mfxHDLPair *pair_src = (mfxHDLPair*)mid; + + pair_dst->first = pair_src->first; + + if (pair_src->second != (mfxMemId)MFX_INFINITE) + pair_dst->second = pair_src->second; return MFX_ERR_NONE; } -static const mfxHandleType handle_types[] = { - MFX_HANDLE_VA_DISPLAY, - MFX_HANDLE_D3D9_DEVICE_MANAGER, - MFX_HANDLE_D3D11_DEVICE, -}; - static int init_out_session(AVFilterContext *ctx) { @@ -183,26 +185,30 @@ static int init_out_session(AVFilterContext *ctx) mfxIMPL impl; mfxVideoParam par; mfxStatus err; - int i; + int ret, i; /* extract the properties of the "master" session given to us */ - err = MFXQueryIMPL(device_hwctx->session, &impl); - if (err == MFX_ERR_NONE) - err = MFXQueryVersion(device_hwctx->session, &ver); - if (err != MFX_ERR_NONE) { + ret = MFXQueryIMPL(device_hwctx->session, &impl); + if (ret == MFX_ERR_NONE) + ret = MFXQueryVersion(device_hwctx->session, &ver); + if (ret != MFX_ERR_NONE) { av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n"); return AVERROR_UNKNOWN; } - for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) { - err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], &handle); - if (err == MFX_ERR_NONE) { - handle_type = handle_types[i]; - break; - } + if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_VA_DISPLAY; + } else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D11_DEVICE; + } else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) { + handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; + } else { + av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n"); + return AVERROR_UNKNOWN; } - if (err != MFX_ERR_NONE) { + ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle); + if (ret != MFX_ERR_NONE) { av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n"); return AVERROR_UNKNOWN; }