From patchwork Mon May 18 20:29:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19757 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 B546744B915 for ; Mon, 18 May 2020 23:31:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C91468AA7E; Mon, 18 May 2020 23:31:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8ABD46808B0 for ; Mon, 18 May 2020 23:30:53 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id k13so11292203wrx.3 for ; Mon, 18 May 2020 13:30:53 -0700 (PDT) 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=yDiDYzXtmrm3gnaI3s8UZZS+XU3yKpum18Q75TAqsLM=; b=YkekvYoT/wHOYgWySyeXGR2pOMsq/0TISIrElJ43fItf2JOGNYxkzISsytFc3Cka9K fPpLO09oniST3Pwx1ok3QwCsB9GZ1DRKxEreNFj/vf1cVFnovsLSuFVg5Jk2TLeO/d0/ h3pZRR9PIAaUZ4aj8RoCjUDTKXdPo9jxChLZTa9fuUON/qdRajhu/QQRBucmbx2m1rKg FijD7uuk7bFvkkAiOhTPSounaGhzxW20xIQAoMxH0LG051f4C0Xf2wFxM8jE9x8//rjS kC06O2q77E5E4dw4heYqn21ysLgDWNap+yp6jAfkMKeiRzgaoKzY863+xCLg3EImNYa9 RALA== 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=yDiDYzXtmrm3gnaI3s8UZZS+XU3yKpum18Q75TAqsLM=; b=GJ97q7OphgSEz3gvUO6DGDv+9rg5KP1ueos1FPdW+4pbh/0xdTOUj8ris9OYp1NII3 UHC8mwhqc3OapLPzBfaTk7CFUKnyIpOoSrm3aNe6Ty9zeQ+vlkh3BTcuXFxp3/DcuNDm ac4JdEAPizgJnqRBp9O0g2Qq5ec0IEnHSeot0xmqbwdtvSYcHBLDxq4oKR0ZhLM3hAMN MkIjXQGqngho37yYa0TlDNeGgy3fVWuhVE6F6YG6gGD9wtljt+QBFZ36UXSIBkKRUSEC VglBn87JRGXc9hQq2JAra5abvmu9d7fGGZamowd/xaKNLJpDsC3dPfjd7TwwYFXvw4KV 6O2g== X-Gm-Message-State: AOAM533rfUGAJxCJ2PAvdft/bEJuMeblW7R+KK6Nxb36ip5ixAOnqNUn c3P5mW3exlrpuxOM/TQLc6w8otY+IwY7Ug== X-Google-Smtp-Source: ABdhPJxh4LjKOr5jk9LN0/0PXWQjc8SJMn9BlEQxQ7l+mEVbztvDm3FsEWE7TapTLePIBrturl9z2w== X-Received: by 2002:a5d:4801:: with SMTP id l1mr20893752wrq.235.1589833852528; Mon, 18 May 2020 13:30:52 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:30:52 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:26 +0100 Message-Id: <20200518202934.49601-1-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200415130741.27263-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 1/9] fftools/qsv: add device initialization from string 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin Signed-off-by: Artem Galin --- fftools/ffmpeg_opt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 60bb437ea7..83f1b53e9d 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -558,7 +558,11 @@ static int opt_init_hw_device(void *optctx, const char *opt, const char *arg) printf("\n"); exit_program(0); } else { - return hw_device_init_from_string(arg, NULL); + int err; + if (!arg) + return AVERROR(ENOMEM); + err = hw_device_init_from_string(arg, NULL); + return err; } } From patchwork Mon May 18 20:29:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19765 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bac9:0:0:0:0:0 with SMTP id a9csp3078892ybk; Mon, 18 May 2020 13:31:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK70nqWpaOwl2DQmf/FUrWnV8p6pxOica6RFOn3A0LNBIM1MrgQ4dz/QWEluk3AS1ebINJ X-Received: by 2002:adf:e4d0:: with SMTP id v16mr21779010wrm.294.1589833876420; Mon, 18 May 2020 13:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589833876; cv=none; d=google.com; s=arc-20160816; b=aD2nyEcCZVTWYJXRgksXYfLksRtJoFFrqwPNoc9nHH5ezQg6CZOeu87JOhXeR4j07g UcS7XP4InjXm5LhLsy36WxKj+FBBvGlcK4ebpRo5AaxHyi+lUiRRXAm1saKBrw+HqVUI ggY59CHLkvSkddpcr90NkTh1NW8k5GYvmzXyjMJTzJsYfKKRnFMQvCGoGM4j87bQl9cb +kxZFBZZXe77Tv0OAZOeA6wK+VtG2mebz6Gdh5NLJZPhXRXnlt6rCfLnZImdPLAxrmqn 05HpKcEfLF+z3504i8KeQrgYhRSWGV9X2pF2LqFyOnjleZNO9FFrmCH1ARu/WxMpMGnu 9DiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=PmRmNEx84q4WzldDfPPbzTsP6Dz+nQdnF0eejIgC2Gk=; b=NeSu15D6nj1yyODBzKe+0ch4NGorI+N1gbyZzcfJehEPU47k/svvesQKPVJGLthTfE Lv61OiqWWoyWeQAfyaqmQD8As1ME41Dlyg0ahZjXJHU35LzncDncvXU+VxJ7X62LNZ0F Pn+PiCpv50fpCgdD25g9mrVEpcotuu1smhLrdhRIHYWCzpvpxdF39MuTGfzIPbewPWf9 nGtEYGlsIRMkWD2hfLciVfcA60ZmKhOcCX+XBVT6mLQCSTujEKE15uxihVaoOHhdWER1 a/zDvj+TmTk1gDyomUDw3GwfGYnQe0Yph0DF+vDCJ9TxPHtMtwV+bGSjNPRL5shXgTRr ntVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WzOH5Zyu; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y18si11726474wrm.528.2020.05.18.13.31.16; Mon, 18 May 2020 13:31:16 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WzOH5Zyu; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BDD068AABE; Mon, 18 May 2020 23:31:03 +0300 (EEST) 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 CBB1F68AA92 for ; Mon, 18 May 2020 23:30:55 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id h4so801264wmb.4 for ; Mon, 18 May 2020 13:30:55 -0700 (PDT) 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=J2/3DBV2RGiSE2/ITrlryXNF7/V2EdLxCAUkbnrwSXg=; b=WzOH5Zyuu92Q2gMIpP5aY3C13vAxGfmsZVu8jxYlQiOulGDZy4NXEx3CfBL1SRBpkX Eirxba9fWtTOUUKxJ5FGy3C/peYB4OpOb0vCoj2kIA72SMhYcUOrxZvAFqONmYIlcb9N jypWD5o0uf9ulUVOYSXhSFVr0gAvWlZ0D1oeKskNwVlSnw+WHnzzQBsSLYBlL1ReGbn9 ihUG6GgdwH/1kCGcANkvcf2+p6EszwRuBsOLs64rzUpr69ZvuMr90LV6aMxy4b7AHiWP U7wiS8knH9yYKGeMJ1Q114vUUlxrQdRoDqeKQNzYAxSo+WHn7qGkRBTqxIJv3O6lic7o cLWQ== 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=J2/3DBV2RGiSE2/ITrlryXNF7/V2EdLxCAUkbnrwSXg=; b=BEThedSubjm9A9K2iEu5izJdqm5TwooAIF/hTJbwFqZxD1UwzgAFvEs39dQheolZ8R 5GtBoiSKRtVXvWvZcAHvFUxe4C2PszD0lIh4yswhd0x90KSr2mALOVIKZG7+35wLd9Ts tTV0V1NiBoKgqNy7vvc9Ix3GIbezxy8Ea1n7kDKWlIOoyHn4b/ZIwN4/FiN4oH26OQGF UZz3oBm95eu9RGvCsGIxWkVsEyoyyMfk5LIlk/aVZOd7RzzSojohf6cuWS/GZ2ylXdyF fELnhtY+1wBATWDNYBdeHEO/b0RlBXV7pLrvMX83HPB5oZex0kuvdhJ7nuB7hIQJcaHn qI7g== X-Gm-Message-State: AOAM530SZK2K2TgF1ktZtVYXQMz+Ano851McZZYrxe9yl90hoToRUAgo 3fSJEKIQRo/A1x9OwGKT3eOTmYsVSIXd0Q== X-Received: by 2002:a1c:19c1:: with SMTP id 184mr1129504wmz.29.1589833854912; Mon, 18 May 2020 13:30:54 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:30:54 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:27 +0100 Message-Id: <20200518202934.49601-2-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 2/9] 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tzRyPUaYM+jM Content-Length: 8053 From: Artem Galin 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 17720070f1..ef57b92a9f 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 @@ -239,7 +241,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; @@ -380,7 +384,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 }; @@ -469,7 +477,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; } @@ -646,7 +654,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, @@ -679,7 +687,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; } @@ -687,24 +701,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) @@ -713,13 +722,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 6489836a67..370ab464e7 100644 --- a/libavcodec/qsv_internal.h +++ b/libavcodec/qsv_internal.h @@ -60,7 +60,7 @@ typedef struct QSVMid { AVBufferRef *hw_frames_ref; - mfxHDL handle; + mfxHDLPair handle_pair; AVFrame *locked_frame; AVFrame *hw_frame; From patchwork Mon May 18 20:29:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19758 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 0E69A44B999 for ; Mon, 18 May 2020 23:31:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E675C68AAA0; Mon, 18 May 2020 23:31:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E586968AABE for ; Mon, 18 May 2020 23:30:57 +0300 (EEST) Received: by mail-wr1-f53.google.com with SMTP id e16so13362635wra.7 for ; Mon, 18 May 2020 13:30:57 -0700 (PDT) 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=o3bD31JcMTkeRtYb38PH9wQO7yDSaQXf6zOYWbBbDQY=; b=Fy7nfNoe0VnWZWx8H4cY1LhTR44Wksgb0Pwj8SirywcG2GkWOvgPeC8wttihQVnf48 jSqsm9k/bGyLvyTfbJE2sJU7VOO6UGiBXS5bRaSJMbyybAbipCICFvNkbzkdCioboJ8f Q0Z0H9LZCkT/vvr1TB6gqBV/2DY8kTqUx22Tyqaje/ryyDgqbYYZTeV2yjtcVseDcOwZ nI11FboN/7QjF3/Ejtxh8d7XVY6+X5YVhcG2ics+qEDctagTU+u1ZcyNBdayA4H5yLM/ tmuGKnBg0PWtmJr0yDJjIE/PU5oJIQmtfmWxhY3E5LkjA9jy/Yc9/cjjIGPKKjYrIYgT f6sQ== 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=o3bD31JcMTkeRtYb38PH9wQO7yDSaQXf6zOYWbBbDQY=; b=OqqciHOnaGZ8uzn2oy6U0lmehkAfh084Rip2WmrpKGchK1V0lQ1dMmsBRRGS6nvnct Z5KGV0ydVcYa834fnRMXc4HLUQsDIupetgCarftZDRvQarASSq6nTLZX3rjSQEmXzm6z 5w8TsTdMQ9qiR/OgCXj15izKugvafV6o+S2OQ4VBs1kIyzwvjdxxW6nwC+A4NQGTGXdD BO3ef+y7E7L9UFlXPje0TWAQzJA28DTUcGqqjf40KpxInJR91d45KSdayG9QzNKr04LV Rb6FceIYPXiXz4pNNWmldJOeCgYgm2vPa+JeI2Au7YNDC1qDGC1MZqIi7eOshomP6U7z NquA== X-Gm-Message-State: AOAM533aOFt7szuSnL1jTQz6E6xSKM4g0AwXsy/NAVXXCy17RT7MrBqK 3wW8mDDAkI8K37aHFqwR1IaOecsIX+6iAw== X-Google-Smtp-Source: ABdhPJws5/2dAKs4Z5ace91w67qlA3qnRpCD5mbVyfKPW6XQZLnOqnklVnoj/6MqgUygdypc8z8QoA== X-Received: by 2002:a5d:5492:: with SMTP id h18mr21345270wrv.35.1589833856665; Mon, 18 May 2020 13:30:56 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:30:56 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:28 +0100 Message-Id: <20200518202934.49601-3-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 3/9] libavutil/hwcontext_d3d11va: adding the vendor option to d3d11va device creation 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin Example: --init_hw_device d3d11va:,vendor=0x8086 qsv_device option is still works and has higher priority over vendor option. Signed-off-by: Artem Galin hwctx; HRESULT hr; + AVDictionaryEntry *e; IDXGIAdapter *pAdapter = NULL; ID3D10Multithread *pMultithread; UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT; + int adapter = -1; + long int vendor_id = -1; int is_debug = !!av_dict_get(opts, "debug", NULL, 0); int ret; @@ -539,13 +542,45 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, return AVERROR_UNKNOWN; } + e = av_dict_get(opts, "vendor", NULL, 0); + if (e) { + vendor_id = strtol(e->value, NULL, 0); + } + if (device) { + adapter = atoi(device); + } + + if (adapter >= 0 || vendor_id != -1) { IDXGIFactory2 *pDXGIFactory; hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory); if (SUCCEEDED(hr)) { - int adapter = atoi(device); - if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter))) + if (adapter < 0) { + int adapter_cnt = 0; + while (IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter_cnt++, &pAdapter) != DXGI_ERROR_NOT_FOUND) { + DXGI_ADAPTER_DESC adapter_desc; + hr = IDXGIAdapter2_GetDesc(pAdapter, &adapter_desc); + if (FAILED(hr)) { + av_log(ctx, AV_LOG_ERROR, "IDXGIAdapter2_GetDesc returned error with adapter id %d\n", adapter_cnt); + continue; + } + + if (adapter_desc.VendorId == vendor_id) { + break; + } + + if (adapter) + IDXGIAdapter_Release(pAdapter); + } + if (adapter_cnt < 0) { + av_log(ctx, AV_LOG_ERROR, "Failed to find d3d11va adapter by vendor id %ld\n", vendor_id); + IDXGIFactory2_Release(pDXGIFactory); + return AVERROR_UNKNOWN; + } + } else { + if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter))) pAdapter = NULL; + } IDXGIFactory2_Release(pDXGIFactory); } } From patchwork Mon May 18 20:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19759 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 D953344B999 for ; Mon, 18 May 2020 23:31:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF55368AB55; Mon, 18 May 2020 23:31:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE47C68AAD8 for ; Mon, 18 May 2020 23:30:59 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id l11so13454095wru.0 for ; Mon, 18 May 2020 13:30:59 -0700 (PDT) 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=ZRW8KmboK4k8fBQH3bxH6ZaBJ/SkrobWzorz/LbUyxQ=; b=KNm8WptQfSzX4WCjyWSkzaF659mV2fc0u2J5fapsItSW1u2hZ7fhX2Sk9XddCpJvDt Ay9xfB+wToSDXQrfhveFfC1nYoU4aUXcYEYYWVOdGgMy+LNsIDvKcCgRlKlU00nrEwxq GqkFHNXNb3DdjoZek/VliJTQLemRWL4v0WRP7YWBaIYUrJ/0EsyILuIsveD4cAB3eCFB nb/xsjJayH+Mjs8TIWVgTW5Wk1lgoqkFv0NUHoxyrdxKvVxVBCHzovId+hZuPAHC/mA6 wBg096F8Xrme5C3Z5Xp6R7bcPeg4LErJk9vy+4E9qw4YvLGcD1wuE8biZX73c7TsWmef Qinw== 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=ZRW8KmboK4k8fBQH3bxH6ZaBJ/SkrobWzorz/LbUyxQ=; b=qeoC/FNP1eJ3h2uYy+qs2KS1FvzdjF9LQ4Hepm0cuV0R8pQwovC+kq8OH2XFy+bj9h oMnqtXSio2SLolGL3KTjuBsIVJeij1D6Cx5zUH/EQTUp2aso9h5NrlF5Unlb732a7OF+ Fcn4aYQkDRjJgeRI4+cTqgK95s1FrXVniBQ9sd/MuzVG7APgoZOdv9re3Wu8GbzIwkSl 5Ma1ARrF1M+dtMxyfKVK7fmmxoQFAfTfWKXBxoZoyIkm9DbocNwO0UoKUONxZoOEbPEk 0ws/6Rh4F0096kAmcpcDRtDawe9m8HfAzrEvE5Q5TzOb01u16FwiwiHKu6SZDTQLE12P 0eiw== X-Gm-Message-State: AOAM531shZJDlIw1uNVDXD4je6BBGFnxZ3Cr7LZ2PCaGyRUM3eEZG0tu 3vx9B0lvDskksFBj4vX1SWF7hZZolixC0A== X-Google-Smtp-Source: ABdhPJz/gt6ITwC6gkMGsOrgOxjG8zzCyJANyx2xbvYU2tPw6zT/kK/Apl0B15Et7nB/bMWzLmC/og== X-Received: by 2002:adf:9482:: with SMTP id 2mr20778864wrr.328.1589833858737; Mon, 18 May 2020 13:30:58 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:30:58 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:29 +0100 Message-Id: <20200518202934.49601-4-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 4/9] 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin 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 4306c6e3b9..f6dba898b5 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: { @@ -1215,7 +1414,9 @@ fail: static int qsv_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *child_device_ctx, 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); } @@ -1266,7 +1467,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 Mon May 18 20:29:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19760 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 ECFB644B999 for ; Mon, 18 May 2020 23:31:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D76CB68AB91; Mon, 18 May 2020 23:31:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5EA5668AAF0 for ; Mon, 18 May 2020 23:31:01 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id j5so13418351wrq.2 for ; Mon, 18 May 2020 13:31:01 -0700 (PDT) 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=kv4s0LJpIN6NG5yVRpwdIrY4s2hHgz84vGlLecsRg9s=; b=DyIe19ixqyjCPqsR78doNQqT4UvZ4onCJhUzs+SBD7JLEeH1TeN+ekHjjLyV6x2cSJ T36RmabKRrUrjAUiyszg2zLEHK0liY8brG9XNafWFogCHaGENwdNgfQ7ZnXkv0LAw89/ YDkT2L1C7UO2y1ZwjWIKrGp5WCwZPatfDAXybKXO2X+qOZTCXB53CjLGS0uvWS9Y4DSN qEguCFzYl0jNO5alJRg4knj7+WdLBppOGYuEiXQf8XygC0dQqXg62ZfI3x7VQz+d4XpB rj04xMVtUlmsQ8Rbf+trv5mRiL77GLaO/oB1F29OUTYDcIFYO3mcrkA4JPpnMUVPOcGl eRiA== 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=kv4s0LJpIN6NG5yVRpwdIrY4s2hHgz84vGlLecsRg9s=; b=m7MDFu6W48qSvVNCu5lOejOBKmnfyQAMvM3QkRyrULZIKzFAaC4gMadFlX+qwsmV2I 3vIAg38VWk5M38XLaVDwPE14pazV5dM5O7EnRT5LWI4VuKX7MOMtkit+4OrmPj1GbvME Ueuwx+9O+pmJ8dU5mB0+EjqkRKI3ztzCnsyMQgHVYn6ADWg1NXhuEm5SNB0yDhhpd5tP /3aE98EYGXC5bGX0YC6oZmLuQPu/YC70n9ggYV2OV4zfUdYSppF1wiXyEd7AGJigGEMG StW/9WwbaiUsIEoxuLYz+wFHqdkZ+QI+wrS1nCX2QCPmukf73giSwK/CsfrTZlx0zaE7 3Dhw== X-Gm-Message-State: AOAM5310W8sZa+ggrfAp0vfAiPHsK05fXKPe97wXmwZTt2AxoQgt0ABc OHdH7DBrJLu0WsLSkYIk812m7wYCN5bo9g== X-Google-Smtp-Source: ABdhPJynKcAkL1xt+zZaZig120AD7fn6Kv/QQdeCn+cLclyLKs6S1X0sGsXhLStCstSawkCM0Mu6Lw== X-Received: by 2002:a05:6000:1048:: with SMTP id c8mr21714822wrx.1.1589833860524; Mon, 18 May 2020 13:31:00 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:30:59 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:30 +0100 Message-Id: <20200518202934.49601-5-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 5/9] 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin 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 --- libavutil/hwcontext_qsv.c | 59 +++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index f6dba898b5..488655b686 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1439,28 +1439,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 Mon May 18 20:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19762 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 6D77944B999 for ; Mon, 18 May 2020 23:31:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5B27568ABB0; Mon, 18 May 2020 23:31:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 391E768AB21 for ; Mon, 18 May 2020 23:31:03 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id w7so13317749wre.13 for ; Mon, 18 May 2020 13:31:03 -0700 (PDT) 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=2zR7tse0m8cqwv9MQrSeF4dg3gGu7wdaw0xnfuxFJ+M=; b=Z19Xq4C+64VPIniV7vAJQ5S9XMb6QKmJVLCtl8AyGnn/rSqG7/v7Iofd7kc9lWdSsO 1+lqflBTu5qn/j5yAVFmr3LKgFZM7NGV+0O0lJNPGbp5GsscRhNbYaQ+L27ysRJS/pBe C+DUVTLqTcM5RCTLIne1begDaO35SgJdWN5pBM4uAkwTjoprdxvn4D451ehk1ClVi0o0 P54gu79bpY/mCLV3HBiYkIYWgDrH6eUXMa4fmrom1IZihLCpp0wYcQdv9ONQm8AKw3vm pSl1DQugV8lq73ZpWq2SoPSb94Uw+fDiEFjheBgPQFkh6+HfEcPJO8MfykeV+E59yrS0 BjxQ== 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=2zR7tse0m8cqwv9MQrSeF4dg3gGu7wdaw0xnfuxFJ+M=; b=Z6oOyWLGo5iLEK4IgP8jGvW+pa+eqsaO+lCOQsNJgIAim/dgTIySy4tCPLZenQCqc5 fk3LaUvpsdG+xr2o2P04ziOnCf3wsX58Jw9tsbnGPn12pBE7h7c7xDOoVDyFAHmVtCvz fbyVfPl2cY666FILuXPcd+HtLh+bPXpByeik82F16Gh66ipnw6PltOdAgqLL9h/urXcx ufT8up7yGxNH/dQotdYfXEYhUsS0wbJGdM7A4pG+zAUGk4dAepMg0FqqxsXDXzbq/fr/ cK+pkwqPOmp42m9b+sUfsf+4Y8ui2OgMrJw5p4isBfkULaP0lbHI0efU7WOnpXkvGBJx 5A4A== X-Gm-Message-State: AOAM530yeSIPjXZ0UHoeWs/q6YUkV+lwBS+zsD5GQIH2G95uDsLIa+yL 6e5A2Ussj1nrEb1sT2DxTHP8tOUYeR9P5g== X-Google-Smtp-Source: ABdhPJz80/ynQUUD5NJDpenVPfoooV7XQcof6BrQe68X+owYmUhQ/GUajDuVJjM7Nl8+Q4FmI1XsYQ== X-Received: by 2002:a5d:55c5:: with SMTP id i5mr21528844wrw.402.1589833862249; Mon, 18 May 2020 13:31:02 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:31:01 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:31 +0100 Message-Id: <20200518202934.49601-6-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 6/9] libavutil/hwcontext_qsv: pass vendor option to child device 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin Signed-off-by: Artem Galin --- libavutil/hwcontext_qsv.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 488655b686..e75d4b7c24 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1475,6 +1475,11 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, #endif #if CONFIG_D3D11VA case AV_HWDEVICE_TYPE_D3D11VA: + { + e = av_dict_get(opts, "vendor", NULL, 0); + if(e) + av_dict_set(&child_device_opts, "vendor", e->value, 0); + } break; #endif #if CONFIG_DXVA2 From patchwork Mon May 18 20:29:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19764 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 3C06744B999 for ; Mon, 18 May 2020 23:31:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 16CDC68ABD5; Mon, 18 May 2020 23:31:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F2F8C68ABC4 for ; Mon, 18 May 2020 23:31:04 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id k13so11292658wrx.3 for ; Mon, 18 May 2020 13:31:04 -0700 (PDT) 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=nVmcODXny2sPtqELhYK7+ySCBdEi5kYcLPFkZPJ89xU=; b=HwuGgznbGeP1D1BWCOVDl1Wg/NyTfpJo1tTYR4FTPzyYdTAJh6w2RRnkR/8JOqPESg suJu9270O9O4dSD7Mw+Aro8QKb36s7rZ5vUot9guAxd4XE+tw7oKf1nng3s1y6URldIO 0joLlRqO9FB/lIlb0lxkaK9I5Af924z2foGle7UC7TxPJpztcEMLYzTX0xO1CqClXg5w Qj6R8sPkeRTvYZZvNJYH2OJmEOT0OcfoSXoC2CGNl92rAoQ7uMwCxgzrEmaNrRxHjXAj kKxhRj3ixQP3khrxetq5U2Vio3ZTrs1UV4HcAj+os2TtYe1ikUwhLj+yFTzEEidxZ4ZB JwsQ== 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=nVmcODXny2sPtqELhYK7+ySCBdEi5kYcLPFkZPJ89xU=; b=U+7PkxOOr9ve6LUWJw72nP4Lhaz3cdYmI2GKBQ91uK9eaOwGdB/zBDj2TtVtGufS1k W4DD32X+7EN3oFvwuxjKDr0mx9bf2sTww9amI150Szu3UbmGCZ18EIBj/92jvXUSBZ9m zRxFDvhz5PTL4+IJbg8v6SGLvG2Izzyr3GAEWgl1JP3D4dHf7tGIZ4aUuQsXZBAgIHHw 65+hL35lFJeFf9k9M+GuWVKIy2v8TsSSunghDB8ca3Z1QVdrP3B9Q+9R9tRnnCLfRyzj duoP2JA9RsvX6HfZpfnXarERsC0rmTaE9t7W4nIVCZ3V1GAA4BDBEC//5rSDX4cOCCbm eBVQ== X-Gm-Message-State: AOAM533H8/1S64R8qy4pFV6f4SEF6OJJHEeTazzK/ggXkkGgANq3TJij rboCECbGGqoWqoHbkTFnwdarcg+mDUnsvg== X-Google-Smtp-Source: ABdhPJzYAPe8c67uJv3H0YrrT2NOIuDzoet7OBcXwC0h8cgdT60BEjPCOkJS1bL+7lqZDYMONRhDGA== X-Received: by 2002:a5d:4447:: with SMTP id x7mr20921208wrr.424.1589833864111; Mon, 18 May 2020 13:31:04 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:31:03 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:32 +0100 Message-Id: <20200518202934.49601-7-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 7/9] 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin 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 Mon May 18 20:29:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19761 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 997CF44B999 for ; Mon, 18 May 2020 23:31:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 87FA568AB99; Mon, 18 May 2020 23:31:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BA3468AAF0 for ; Mon, 18 May 2020 23:31:06 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id e16so13363069wra.7 for ; Mon, 18 May 2020 13:31:06 -0700 (PDT) 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=nT3IXd4acEuTkpLK7R9r4RddG2KQlkDY1oqdMBZ/Eug=; b=ShpfL/DhHpWG9tsFQl+B8yxinQxuXKAmifzKKkeJ77w+k8DATWHxA5PWjoIdtD0qQF l5OXMk3faNslk/mGFbY6090uTrwQ7TPJ8P5xNrehL4ufn+OyrRS27/Mjyhyu/u4K8Equ cC35xnl9vUvbCxgge5ShrKW7pFbfHnfy+3/ouydG/0x+mpknq0aJ4La8EFQ/DCJ284w0 niKPrR0tmMAThSOZjHCMR3eiFYaWrpozQVuMv96zX91TJxaVq7/r6Ya2YYbqfTDcTuVx ak7twoCgK/lw9xcISqY9zIsMKM2EtDkSALHBTj5R4rXcD/aDjiJ39cGzEZYFcRR3AIJU bQug== 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=nT3IXd4acEuTkpLK7R9r4RddG2KQlkDY1oqdMBZ/Eug=; b=OAD3GXb647mOj+QKZM2QDFyr9aI3S1qenuntByuJWjQy0GXK+UV5Ug3U/+Y97+QPJc lnL2JLgq52D+RgkvZzkc128j72vEwVXNxfOD1N9I7qeyCCP6KmgEyrr82wCswATPnvVd CWtGyuw5/FwWsJZ1MFvzFsGNWZbrbMFpINLhNy/Nf1l1HJLlaiwqW8l538o9pY8Okkua LwGKN4H/G1Gaafj1K4t6gp6sNJ93di2THPV1CYGAUzmGDCglfub3uFCC52mcEaULAfCk B06+KTHIst0+UzJavKW669KbFAU7x4+8Ckk4IBVP+Ktf3c0wsveczv/c6q3XjOR4f9EC cVRQ== X-Gm-Message-State: AOAM532o5z2fy/IoYexH++kpKimm5ZysJZamz3ZISxOpXh7/Kjbc1r8L B9Gv7V10egbUiTjHROcC1/zBucwLJ1VhEg== X-Google-Smtp-Source: ABdhPJxuAXwq9B9aJEx3krOC71DQMkHw0WHjZWhB/EmEJy+/w6PvxwtNGm1B08hc1SybQ+zNwTz1ww== X-Received: by 2002:a5d:4801:: with SMTP id l1mr20894578wrq.235.1589833865683; Mon, 18 May 2020 13:31:05 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:31:05 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:33 +0100 Message-Id: <20200518202934.49601-8-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 8/9] 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin 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 Mon May 18 20:29:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 19763 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 4216544B999 for ; Mon, 18 May 2020 23:31:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2280F68ABC2; Mon, 18 May 2020 23:31:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E55D668ABB0 for ; Mon, 18 May 2020 23:31:08 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id u188so975079wmu.1 for ; Mon, 18 May 2020 13:31:08 -0700 (PDT) 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=B/VxyoN9Ia/dACDO1xEWJ6JCQ8bC5a9VbCAqVTF4TI4=; b=WknOe/5qtCOg+HQq4mS1HWdqtzSbllrXynic0LTz2GbhvOFBd7mkJpzDKwdWaLO7Vy zYghl3DYHsTtcIgysoquCVdZWt0VZUjPxtAujYv8T5atFmv0bkHcFcrKqFhpIrhtCqtg EyxYxNwJO8ijym+IKboPXzNfBWg6JDj8O7GIgMWK0AsCLsdaXSNbTs+zAWBf3qYN/8AJ VQI6ik31ijZurg6SEnTmE1qALqHfzbRfNu8SYTI9HvXNDkH6fvdt3+Z+Mr+81RH3Dhnk 1DOMw2SRkACbZRMh6qlpAGMvKwcIlPXlXO/uFTUQeIFykVoOoDyK86ilwbtEy7DSA8+1 z2nA== 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=B/VxyoN9Ia/dACDO1xEWJ6JCQ8bC5a9VbCAqVTF4TI4=; b=otWLmn+ZtGs18UXApP9ISnW1fuRwgJ0iBm+M7bBTGdGZObPHeVlD+7DgsXLhIYjILC vDXQrSY6XGuCSL2a1wSAIoODomfb5jkGhQ3a1aPMN+OBPzr28hiQwHEd4vP8Njmo7WeR elQhbXUdiRHdQAqdCB0NTyt7sBhAhtFzb5666bIH+4LemgTaGUI7MNJMIJ/4SZLGV67B CrnqolnugV7unqV6XhlqaP1KiGqzElqXXmmCDI1jQ3vTlpISu5v6UlHV/ib8Ad+oVicR JjANRyU/BrCSvYvYCSy/kxVKifiyNCvi8bk69+CBXwREIyIeIFdKxjJkNrTG4zYgLmLt /p/w== X-Gm-Message-State: AOAM533KLRn5YIas0CzbHQA32nnuTWOsPQ1wPpV9YBpZxG3L+mvLZO4+ PTZOl+DWO7yILSdbyAdZmT52FHCO4BVR9A== X-Google-Smtp-Source: ABdhPJzWVMGei/tNHhqZ4mkqIu0+zuOASfZr1mGt2zqyTK7L77dc/L9+Q6eedWlfwvgKZsFm+9xEmA== X-Received: by 2002:a05:600c:2c0c:: with SMTP id q12mr1219306wmg.36.1589833867783; Mon, 18 May 2020 13:31:07 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:3e2e:7400:bc2c:26b1:105a:3e19]) by smtp.googlemail.com with ESMTPSA id q4sm884330wma.9.2020.05.18.13.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 13:31:07 -0700 (PDT) From: artem.galin@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 21:29:34 +0100 Message-Id: <20200518202934.49601-9-artem.galin@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518202934.49601-1-artem.galin@gmail.com> References: <20200415130741.27263-1-artem.galin@gmail.com> <20200518202934.49601-1-artem.galin@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 9/9] 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 , robux4@ycbcr.xyz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Artem Galin 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; }