From patchwork Thu Aug 1 04:45:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 14176 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 7BB90449FBA for ; Thu, 1 Aug 2019 07:46:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4746868A8CA; Thu, 1 Aug 2019 07:46:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D201689ADA for ; Thu, 1 Aug 2019 07:46:10 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2019 21:46:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,333,1559545200"; d="scan'208";a="177672846" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by orsmga006.jf.intel.com with ESMTP; 31 Jul 2019 21:46:07 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Aug 2019 12:45:22 +0800 Message-Id: <1564634722-506-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] lavu/hwcontext_vaapi: cope with race map for YUV420P 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: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" There is a race condition for AV_PIX_FMT_YUV420P when mapping from pix_fmt to fourcc, both VA_FOURCC_I420 and VA_FOURCC_YV12 could be find by pix_fmt. Currently, vaapi_get_image_format will go through the query results of pix_fmt and returned the first matched result according to the declared order in driver.This may leads to a wrong image_format. Modify to find image_format via fourcc. Fix vaapi CSC to I420: ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f rawvideo -pix_fmt nv12 -s:v 1280x720 -i NV12.yuv -vf 'format=nv12,hwupload,scale_vaapi=format=yuv420p,hwdownload,format=yuv420p' -f rawvideo -vsync passthrough -vframes 10 -y aa.yuv Signed-off-by: Linjie Fu --- libavutil/hwcontext_vaapi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index cf11764..64f14de 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -63,6 +63,7 @@ typedef struct VAAPIDevicePriv { typedef struct VAAPISurfaceFormat { enum AVPixelFormat pix_fmt; VAImageFormat image_format; + unsigned int fourcc; } VAAPISurfaceFormat; typedef struct VAAPIDeviceContext { @@ -171,15 +172,21 @@ static int vaapi_get_image_format(AVHWDeviceContext *hwdev, VAImageFormat **image_format) { VAAPIDeviceContext *ctx = hwdev->internal->priv; + VAAPIFormatDescriptor *desc; int i; + desc = vaapi_format_from_pix_fmt(pix_fmt); + if (!desc || !image_format) + goto fail; + for (i = 0; i < ctx->nb_formats; i++) { - if (ctx->formats[i].pix_fmt == pix_fmt) { - if (image_format) - *image_format = &ctx->formats[i].image_format; + if (ctx->formats[i].fourcc == desc->fourcc) { + *image_format = &ctx->formats[i].image_format; return 0; } } + +fail: return AVERROR(EINVAL); } @@ -368,6 +375,7 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev) av_log(hwdev, AV_LOG_DEBUG, "Format %#x -> %s.\n", fourcc, av_get_pix_fmt_name(pix_fmt)); ctx->formats[ctx->nb_formats].pix_fmt = pix_fmt; + ctx->formats[ctx->nb_formats].fourcc = fourcc; ctx->formats[ctx->nb_formats].image_format = image_list[i]; ++ctx->nb_formats; }