From patchwork Fri Dec 10 05:38:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 32253 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1348350iog; Thu, 9 Dec 2021 21:38:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzFQEH0dAtmSIAdM3UN5gK5cMEkpXwuVQARYfc3xd6Fn78bB0QSYIH8TZ7ZioQVTa/0w63 X-Received: by 2002:a17:907:2d10:: with SMTP id gs16mr20455355ejc.353.1639114713741; Thu, 09 Dec 2021 21:38:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639114713; cv=none; d=google.com; s=arc-20160816; b=jUyE1pbSk4yFRcObW/VB8jfmmdMgrZ8pttcH3NnzBG1keIcB/VhCeKJgNpdTvQgdDb T4mr7fHUkRdTbmplFz/wE/Az5MPS048dghYiRd1IAXO0G6OoTivOFEq00gRGGz6u29Tn RcfpL0htqMErdeI3khQTuzOKIpi+lZmWKKf1sStkTUcpFAg0a6zwg6z8AfU7t1MRmS28 9RWRGnppDGp3M/bI865dY8An5Q28jqqCM5+cDSjLykaoA6CgSDaTF9y5Ti/20VUQ1hUh QMNQwEMCzVZcOLUlp9eRIIzYXMRjqZZSbEx/PqEpwtsstiJWV6aei0dKo6MCc0+P6336 e3dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=Bg2o7pCCTtYm3WYaKb2IoCXTAFdbdRv90XQI2Jj7jfU=; b=fBK4r146TF8KYj/SvAHrcw2XrznxSqodUvpngv6r1bgn3TYM3qJ5kDhn48w43/5rMi FbMjegvJtrLIK8iaGovtGHod/gM/5P6DbFo40bCNs710mt58THI6jemWPqJaAvZ9NrzG lR6knPdGvZiFoTb0outy4iB/dYr54M0WYRSoDqWNM3jTBJsCQ1QucE0UOm3EULJDVTT5 8gH4JIy+stpDaf2doqyHSAuThs2WTV6N4nYwpUTFtKnTid0o0mMaCzK62sLrLhsA5xYo HM8FY6uMDxewCVdJkR7QpxGNuHccVHpJ/yU+OUCU/mOggYJcE0OQdY7uTrkHOFMFjmPj w5QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=mh2IbPbq; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z9si4041835edc.426.2021.12.09.21.38.32; Thu, 09 Dec 2021 21:38:33 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=mh2IbPbq; 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=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 53E0568AD86; Fri, 10 Dec 2021 07:38:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7117668A59F for ; Fri, 10 Dec 2021 07:38:21 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1639114706; x=1670650706; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=RzNg75RP5h4qCVvbQA5kGCoXWuoRaE+gBXWNlPmNQQU=; b=mh2IbPbqLz4r9q7lMK00HmSoIDesyFnC12KQs2JMRXPnVMEAsfQwxT56 W0j/960VCJva3B+/64nUsqTU7TClMycMl9zf5Ggo8fUWqiv/k1aOyYv76 ZF7wdgXkoJWkrZcymuLPcgzDE9KeJK1Wu/81szAotYx/JeH3MGyyY+rqT pmcyK8aqmhSVwPnDZK4tUcjVdq8TQKinZ2GS3Bsu8ydhNeybpso9rugto m5/sTBXuauEaQrssxEvd9lop6tJjFFYs+pzw/7GxFyvZ1n9+lZEaG0Y4/ RXRzOMkNaYWrGGhiZe01eQ5HPRea5UBwEPfCL7pp4Gpqq5fbq/DdJ6jMv w==; X-IronPort-AV: E=McAfee;i="6200,9189,10193"; a="218301976" X-IronPort-AV: E=Sophos;i="5.88,194,1635231600"; d="scan'208";a="218301976" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2021 21:38:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,194,1635231600"; d="scan'208";a="612811638" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga004.jf.intel.com with ESMTP; 09 Dec 2021 21:38:18 -0800 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Fri, 10 Dec 2021 13:38:17 +0800 Message-Id: <20211210053818.3815652-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH V3 1/2] libavcodec/vaapi_decode: fix the problem that init_pool_size < nb_surface X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4CKYRzgQt+K4 For vaapi if the init_pool_size is not zero, the pool size is fixed. This means max surfaces is init_pool_size, but when mapping vaapi frame to qsv frame, the init_pool_size < nb_surface. The cause is that vaapi_decode_make_config() config the init_pool_size and it is called twice. The first time is to init frame_context and the second time is to init codec. On the second time the init_pool_size is changed to original value so the init_pool_size is lower than the reall size because pool_size used to initialize frame_context need to plus thread_count and 3 (guarantee 4 base work surfaces). Now add code to make sure init_pool_size is only set once. Now the following commandline works: ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \ -hwaccel_output_format vaapi -i input.264 \ -vf "hwmap=derive_device=qsv,format=qsv" \ -c:v h264_qsv output.264 Signed-off-by: Wenbin Chen --- libavcodec/vaapi_decode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 665af370ed..da0e72b10b 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -650,7 +650,7 @@ int ff_vaapi_decode_init(AVCodecContext *avctx) ctx->hwctx = ctx->device->hwctx; err = vaapi_decode_make_config(avctx, ctx->frames->device_ref, - &ctx->va_config, avctx->hw_frames_ctx); + &ctx->va_config, NULL); if (err) goto fail; From patchwork Fri Dec 10 05:38:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 32254 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1348499iog; Thu, 9 Dec 2021 21:38:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxW9uJNSGRpBAQkqVtMKZlhMyAe/DMbcwYANMvgriBuPV79oSNm4vjcF9EbygteVjqjcGPd X-Received: by 2002:a17:907:d9f:: with SMTP id go31mr21825680ejc.412.1639114724377; Thu, 09 Dec 2021 21:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639114724; cv=none; d=google.com; s=arc-20160816; b=o47GIFd8qKYLHoyY2p5rDh/r97/AnH6ibJTdLiMxCd2o2g1BAQV+EmBtRdi9vLL1kZ 3kT1w2vPAP7+mIPqB22QOel25Yo6AXDfJvdgAeaAk2Quq1vHKReFHTPlGrJ7fL1yUqQC ELP0hijY3izQGcb6EVxdWw7Fqh6c2ssp5B0ythW0C+IKYDgG75WSI5lc8W2L5oD/r/Xr 6Ls9kLy2Ij+a8GJlXCFC4gGiNxi7yQ+i7xVUpi498z6FUxZeq0btWzKW/EVdalahJX1F 2ZGJkn2vbTD47Z5tqXt/7ytcs7aUeIhOwPkrnXqf0P6yVNayqpM3HCskZm84+h2wEyGD siQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=YUZRkNS219edC1ivq1QQH8F3hEA2jYTTsW9TsDA9OTY=; b=b8O+9rBmoC/803ywmaBaRxVTaX8xi/0FpLpW9dBmh3ANJxhySqmP+IN+x98/9dI+Dq J07GrwIJX7kza0Yn4FleQFeuwErT+MuDIL0PGLdycxFarpSN0DoonPGf9WnaBfjrAM44 FQ2bkfZ7G0JTVynMCdANrjHF0KO7RufCaEcPmRovo6SFZZMEskiVmEB6/8VWu1CRHogW aSwdcJoyPZtM/FdTOxAs4sVRIg01n9xP+aIWq/DD0KATy/sVsdGljtBC/y9rVPmaPO02 kZethfLv9PkVLfjYxDNPgNAKYCRODHkYrZTpzl3/4Bj5hxiXDP/z6Oqusgk3z2DP7oj+ JBDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=ibaKVgni; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sa24si3814147ejc.312.2021.12.09.21.38.43; Thu, 09 Dec 2021 21:38:44 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=ibaKVgni; 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=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8936768ADB0; Fri, 10 Dec 2021 07:38:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CCD468ADD0 for ; Fri, 10 Dec 2021 07:38:27 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1639114712; x=1670650712; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=iLzoDy7tZpvhEd1KOv12UOzxWh35EhUHbKUcc1T+aws=; b=ibaKVgni6u2r9jimwQ8qgnrLHJ04HxPaevZca0h0EZ5cgCWHQvq3xTwQ I4zhJ5E+g2QuHEBAJgGWBjJtFd6LUuvPq0QTv75TWw/dLpI7+VvakvC5M WrddalHdNvc48QqRfNhxWxDG6ETGw//XC93oxIaca2zH+rEpx5hu7Y64o g6L7GUdTBoAdqFzpmjhi+NStQkZoykFde9XeeG88EkMX71rJKmMFjVQRU +SIo9VgHobjbbPQ+dzfeNETIbaUKje7K4j8PgXOrc4uJE1lA+ukszqilI 6r2BhzTbpvasYslcrzvRYNoKq8D3S8Fkd2l9AToG5WWS9wLLcltRu4Jsj A==; X-IronPort-AV: E=McAfee;i="6200,9189,10193"; a="218301977" X-IronPort-AV: E=Sophos;i="5.88,194,1635231600"; d="scan'208";a="218301977" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2021 21:38:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,194,1635231600"; d="scan'208";a="612811640" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga004.jf.intel.com with ESMTP; 09 Dec 2021 21:38:19 -0800 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Fri, 10 Dec 2021 13:38:18 +0800 Message-Id: <20211210053818.3815652-2-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210053818.3815652-1-wenbin.chen@intel.com> References: <20211210053818.3815652-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH V3 2/2] libavutil/hwcontext_opencl: fix a bug for mapping qsv frame to opencl X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KNKuwYwsF4M4 From: nyanmisaka mfxHDLPair was added to qsv, so modify qsv->opencl map function as well. Now the following commandline works: ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128 \ -init_hw_device qsv=qs@va -init_hw_device opencl=ocl@va -filter_hw_device ocl \ -hwaccel qsv -hwaccel_output_format qsv -hwaccel_device qs -c:v h264_qsv \ -i input.264 -vf "hwmap=derive_device=opencl,format=opencl,avgblur_opencl, \ hwmap=derive_device=qsv:reverse=1:extra_hw_frames=32,format=qsv" \ -c:v h264_qsv output.264 Signed-off-by: nyanmisaka Signed-off-by: Wenbin Chen --- libavutil/hwcontext_opencl.c | 3 ++- libavutil/hwcontext_qsv.h | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c index 26a3a24593..ab812999cd 100644 --- a/libavutil/hwcontext_opencl.c +++ b/libavutil/hwcontext_opencl.c @@ -48,6 +48,7 @@ #if HAVE_OPENCL_VAAPI_INTEL_MEDIA #if CONFIG_LIBMFX #include +#include "hwcontext_qsv.h" #endif #include #include @@ -2249,7 +2250,7 @@ static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst, #if CONFIG_LIBMFX if (src->format == AV_PIX_FMT_QSV) { mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->data[3]; - va_surface = *(VASurfaceID*)mfx_surface->Data.MemId; + va_surface = *MFXSURFACEP_TO_VASURFACEP(mfx_surface); } else #endif if (src->format == AV_PIX_FMT_VAAPI) { diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h index b98d611cfc..957df01ef1 100644 --- a/libavutil/hwcontext_qsv.h +++ b/libavutil/hwcontext_qsv.h @@ -29,6 +29,11 @@ * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 struct. */ +#if CONFIG_VAAPI +#define MFXSURFACEP_TO_VASURFACEP(surf) \ + (VASurfaceID*)(((mfxHDLPair*)surf->Data.MemId)->first) +#endif + /** * This struct is allocated as AVHWDeviceContext.hwctx */