From patchwork Tue Feb 8 03:05:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 34159 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp415857iov; Mon, 7 Feb 2022 19:06:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqbwoqHnD+4TNczNR9iiIBDpPlbTJVQP6ufvEXcZzdP2LnsHGwm2IsQt0ji4wmwwTERkhR X-Received: by 2002:a17:907:60cf:: with SMTP id hv15mr1931296ejc.488.1644289567433; Mon, 07 Feb 2022 19:06:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644289567; cv=none; d=google.com; s=arc-20160816; b=Qc7DZJNCSrUlQRq5nzGSm+O9JLXADMCUJZk2hUJmHOf9NYotFu0f6+JAJOX07WjgMt Liylah8NkFpclccObYEFx/hTURmfovXbSm5hUg+a4LwA4Hfcc1DYO2jEvpVXbSRmFud1 3wztfM5jSW3MYybYXXU4Ts59umAeELyoRT9LqfjhV52rMUFwByHPs4y9Y7bQ62YSPsLd sZRaWQw4yuL++U+2j9I53u+yOBq0vV+Nt0L8qToMVfuocTGwALgIUMO7hcRJ/YcLe+gL 0fsOUZz1Uv0ZTIm8oeqWWH8RL3s0BtM6+ZAh7FcxFADje3mxq55iV1jDlc63P6oAzPHF n+TA== 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=IRUc/qPOHoZuCtUoSyDJ/nygSFEiLE39MBBMV8ZCtPc=; b=UdUgMr7lIVwpidfxkGUTW0dIUgZSAE1qlq58/HV43REdcgn2c/2BozVUDdCsQ9nBl3 uSnsagMdvZgXfcaMRgUBuozZRNaZtFsxY6aIEs2jPfZfE5SB92IyZ1Hzx4A17jsOVzpw CHluJyXLGTOdAuimxEBw63OHmMzdRmor2YsAeBO0KoPo5ffhSTFRrALgXVj2vLZeCYWX bK+CiXSoHqX9a/bdrspAbnhx3gbjuTqX0L3I5TYzblUoEwfPPcCKJ8nESqxAZYsTv5xW Y3oWmKawJZZhrsyF1xISdEo56Wj5wbb8kpmGLxlpgFu41mBfUXQ5y0gGM0yLga66LTeo eSpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=E8LbtOFv; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id en11si7112050edb.551.2022.02.07.19.06.06; Mon, 07 Feb 2022 19:06:07 -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=E8LbtOFv; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1331668B115; Tue, 8 Feb 2022 05:06:02 +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 7B39868ADD4 for ; Tue, 8 Feb 2022 05:05:54 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644289559; x=1675825559; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=QiCNCp/gDTlUbYKcz3Uzdh5pokNLv3YzLCRiV5eancc=; b=E8LbtOFvn+bydCVDeUtewVagV/dRsG5rhCxdmxux6oMqiSzdsgTTtC49 qHPYkvBK8wai/0uvjdDfy0W73JAYme/SpUmXq1lGxAwI9F0T6hLEhUdXV MvADxIOR4teMeYCIxFg0tPko/q+61tVJFSKlfjDrte6sr08g5kyjQKJa2 qQaD4LSb1JLXsBQgJjPp5WViJnIvxjKDkRBQvOCm4E1Tf++hzityemJ8p w5M8vwiGd+Cik6mBefgm2QTz5PdqWvMFZgCk4Vi8zZIvMhhjv/owmXM9I +N/dxaW011la4dwATF1VHuBwS27q0Mp31ybKZeQ90xJxquGmx33kTw2nu w==; X-IronPort-AV: E=McAfee;i="6200,9189,10251"; a="228829619" X-IronPort-AV: E=Sophos;i="5.88,351,1635231600"; d="scan'208";a="228829619" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2022 19:05:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,351,1635231600"; d="scan'208";a="628742453" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga002.fm.intel.com with ESMTP; 07 Feb 2022 19:05:51 -0800 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Feb 2022 11:05:47 +0800 Message-Id: <20220208030549.340748-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH V3 1/3] libavcodec/vaapi_encode: Add new API adaption to vaapi_encode 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: OxeaixE3uDl8 Add vaSyncBuffer to VAAPI encoder. Old version API vaSyncSurface wait surface to complete. When surface is used for multiple operation, it waits all operations to finish. vaSyncBuffer only wait one channel to finish. Add wait param to vaapi_encode_wait() to prepare for the async_depth option. "wait=1" means wait until operation ready. "wait=0" means query operation's status. If it is ready return 0, if it is still in progress return EAGAIN. Signed-off-by: Wenbin Chen --- libavcodec/vaapi_encode.c | 47 +++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 3bf379b1a0..b87b58a42b 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -134,7 +134,8 @@ static int vaapi_encode_make_misc_param_buffer(AVCodecContext *avctx, } static int vaapi_encode_wait(AVCodecContext *avctx, - VAAPIEncodePicture *pic) + VAAPIEncodePicture *pic, + uint8_t wait) { VAAPIEncodeContext *ctx = avctx->priv_data; VAStatus vas; @@ -150,11 +151,43 @@ static int vaapi_encode_wait(AVCodecContext *avctx, "(input surface %#x).\n", pic->display_order, pic->encode_order, pic->input_surface); - vas = vaSyncSurface(ctx->hwctx->display, pic->input_surface); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Failed to sync to picture completion: " - "%d (%s).\n", vas, vaErrorStr(vas)); +#if VA_CHECK_VERSION(1, 9, 0) + // Try vaSyncBuffer. + vas = vaSyncBuffer(ctx->hwctx->display, + pic->output_buffer, + wait ? VA_TIMEOUT_INFINITE : 0); + if (vas == VA_STATUS_ERROR_TIMEDOUT) { + return AVERROR(EAGAIN); + } else if (vas != VA_STATUS_SUCCESS && vas != VA_STATUS_ERROR_UNIMPLEMENTED) { + av_log(avctx, AV_LOG_ERROR, "Failed to sync to output buffer completion: " + "%d (%s).\n", vas, vaErrorStr(vas)); return AVERROR(EIO); + } else if (vas == VA_STATUS_ERROR_UNIMPLEMENTED) + // If vaSyncBuffer is not implemented, try old version API. +#endif + { + if (!wait) { + VASurfaceStatus surface_status; + vas = vaQuerySurfaceStatus(ctx->hwctx->display, + pic->input_surface, + &surface_status); + if (vas == VA_STATUS_SUCCESS && + surface_status != VASurfaceReady && + surface_status != VASurfaceSkipped) { + return AVERROR(EAGAIN); + } else if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to query surface status: " + "%d (%s).\n", vas, vaErrorStr(vas)); + return AVERROR(EIO); + } + } else { + vas = vaSyncSurface(ctx->hwctx->display, pic->input_surface); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to sync to picture completion: " + "%d (%s).\n", vas, vaErrorStr(vas)); + return AVERROR(EIO); + } + } } // Input is definitely finished with now. @@ -633,7 +666,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, uint8_t *ptr; int err; - err = vaapi_encode_wait(avctx, pic); + err = vaapi_encode_wait(avctx, pic, 1); if (err < 0) return err; @@ -695,7 +728,7 @@ fail: static int vaapi_encode_discard(AVCodecContext *avctx, VAAPIEncodePicture *pic) { - vaapi_encode_wait(avctx, pic); + vaapi_encode_wait(avctx, pic, 1); if (pic->output_buffer_ref) { av_log(avctx, AV_LOG_DEBUG, "Discard output for pic "