From patchwork Fri Jul 26 01:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 50741 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a830:0:b0:482:c625:d099 with SMTP id z16csp180525vqo; Thu, 25 Jul 2024 18:03:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXj4fA/IyCjRBzrTLtSr+nqonP8UJsTg9cxB69WFoTNDV/9nAL/1GghA7UH0Um8qyF9hzYReGkhEDroGKjjngyycQDq8GWKggF8bQ== X-Google-Smtp-Source: AGHT+IHDn8wvHX3prnWMuQAqrn89iOZGKOFST2QDVcylaFUHfPyaYZtSTMex9013su2yzkbGtwIb X-Received: by 2002:a2e:9e54:0:b0:2ef:2c86:4d49 with SMTP id 38308e7fff4ca-2f03db709aemr29339001fa.22.1721955793608; Thu, 25 Jul 2024 18:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721955793; cv=none; d=google.com; s=arc-20160816; b=z5sMCs6axuV87CRyeLLBoxEFuhags0JKb9hSIfM8AN+h/T0n7euCIjUC2ss7kPXxA3 PAXg0wJcuSSewB5hrUNgsPddqQq6iuTpstehz5F5iTkDnK8qhCYXoB9RU/ipI9flPfal 5qgiffrtZg34GoLc+DnSsjY0E4jOINPq1aX1zHZajPwoRUgkWNfu4he6W5rq3yvdYqdg s9GYEGsfnDQmJo6lPNI/sD3BE/ax83jbLHx4cjTKV+UHRBqDnsGaEiwTBpHcOuw3AXm/ fUAhHZ+3MbSOquXpDwSOLX10zxf/Uz76SAQswLVp72a2q1R7au5WHNUpHQzpQjonKAk/ 9cjQ== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=nIZilzVByVbZWtNEvtaamWQbGZA5RyUMSEifwk15H/A=; fh=i4ESP4ZRFDcfYfwXKWpOXjc2YhmIGuOsCfZUnwNO0gc=; b=P4fyBXdbMy5Ekd2q19fLWXpfrdbYvakkAj2D7mMfHTvkji6vp1JbUzGAa+anC0a6gQ yY4ls/8ZMTu5Nroj/HDP3DJ5fv2yY2+jtHhBRHQ78CvhP8hVGiehcFUQwfXKfWOUDZbb zhFyK4QMRpEx81ABERXEf78vMo5xI43hCJDBMvMWuQzsZd11rnFBT1sRO+OK7WeQL9Ra c5CE/+Kis+4fmQbyxij6XjoQIsXLF7SAJB29pzfoF0wPIXYYO43ipUa69iWcmhN/JSiR pBGHJtuoW0G0tRRlTaff5fzGJNzdJwJD7ms+688Z16gM1EnmqvUIGq0no3nB609ojxG0 Tucg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=K68cLLgF; 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 38308e7fff4ca-2f03d13ea1csi6630541fa.199.2024.07.25.18.03.13; Thu, 25 Jul 2024 18:03:13 -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=@intel.com header.s=Intel header.b=K68cLLgF; 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 BCBEE68D602; Fri, 26 Jul 2024 04:03:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39CCC68CDE5 for ; Fri, 26 Jul 2024 04:03:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721955787; x=1753491787; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=VP5Etrsvt54Yp+XluaheSakPXTAOoHT48b8C3b2LQXk=; b=K68cLLgFlVdngjca1avlvVRIhDEVK+rbAqbwIA+xkm4MCAp+j3YMhSOw Pd7x8TRCSV/vfXaJvbTC8kVlniZu9jjaoypGn3trCdXr1cdYk/13Nx/fa Rxx4y0AmMKpDDpebnZIyNdt/mNZX3edQBMyz3So5sVGyEtj4JpgOYZysq yIWOuCmajicHuJQdHfRu0SRUxB909zoIM4Dvn31ILJvrRIBjWFLUzQX2W FEyjAj0x5HCfGU3MAEMh4N/eKRq+Ik3vPuVTAswNdeGmghRSf7YLRH5Oj 1VA+9cNMQ75Z8S9hFIXV81kyriOQHAQm01761f2yCLArCNopIxk4yrwGX g==; X-CSE-ConnectionGUID: WE8mJPvpRMSpLg/ED9bAeg== X-CSE-MsgGUID: eEhWzEjzSN2Y4i8xUOf6Sw== X-IronPort-AV: E=McAfee;i="6700,10204,11144"; a="19425082" X-IronPort-AV: E=Sophos;i="6.09,237,1716274800"; d="scan'208";a="19425082" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2024 18:02:59 -0700 X-CSE-ConnectionGUID: Pdc0CRVISkSDDVTqqnhjdw== X-CSE-MsgGUID: WKETmobpT/a6GTmHjwav7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,237,1716274800"; d="scan'208";a="53177875" Received: from feiwan1-desk3.sh.intel.com ([10.238.208.39]) by fmviesa010.fm.intel.com with ESMTP; 25 Jul 2024 18:02:58 -0700 From: fei.w.wang-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Jul 2024 09:05:20 +0800 Message-Id: <20240726010522.1316432-1-fei.w.wang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavu/hwcontext_vaapi: Add option to allow to specify vendor id when init hw device 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 Cc: fei.w.wang@intel.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: b3eX/xAbRArE From: Fei Wang Vendor id will help to select desired device in case of kernel driver is unknow or unsupported, for vendor may support different kernel driver on different platforms. Signed-off-by: Fei Wang --- doc/ffmpeg.texi | 8 ++++++++ libavutil/hwcontext_vaapi.c | 29 +++++++++++++++++++++++++++++ libavutil/version.h | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 877edae3b3..842e92ad1a 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1458,6 +1458,11 @@ The following options are recognized: When @var{device} is not specified, use this option to specify the name of the kernel driver associated with the desired device. This option is available only when the hardware acceleration method @emph{drm} and @emph{vaapi} are enabled. +@item vendor_id +When @var{device} and @var{kernel_driver} are not specified, use this option to specify +the vendor id associated with the desired device. This option is available only when the +hardware acceleration method @emph{drm} and @emph{vaapi} are enabled and @emph{kernel_driver} +is not specified. @end table Examples: @@ -1473,6 +1478,9 @@ Create a vaapi device on DirectX adapter 1. @item -init_hw_device vaapi:,kernel_driver=i915 Create a vaapi device on a device associated with kernel driver @samp{i915}. + +@item -init_hw_device vaapi:,vendor_id=0x8086 +Create a vaapi device on a device associated with vendor id @samp{0x8086}. @end table @item vdpau diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 4cb25dd032..014541752a 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -1748,7 +1748,9 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, #if CONFIG_LIBDRM drmVersion *info; const AVDictionaryEntry *kernel_driver; + const AVDictionaryEntry *vendor_id; kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0); + vendor_id = av_dict_get(opts, "vendor_id", NULL, 0); #endif for (n = 0; n < max_devices; n++) { snprintf(path, sizeof(path), @@ -1803,6 +1805,33 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, close(priv->drm_fd); priv->drm_fd = -1; continue; + } else if (vendor_id) { + drmDevicePtr device; + char drm_vendor[8]; + if (drmGetDevice(priv->drm_fd, &device)) { + av_log(ctx, AV_LOG_VERBOSE, + "Failed to get DRM device info for device %d.\n", n); + close(priv->drm_fd); + priv->drm_fd = -1; + continue; + } + + snprintf(drm_vendor, sizeof(drm_vendor), "0x%x", device->deviceinfo.pci->vendor_id); + if (strcmp(vendor_id->value, drm_vendor)) { + av_log(ctx, AV_LOG_VERBOSE, "Ignoring device %d " + "with non-matching vendor id (%s).\n", + n, vendor_id->value); + drmFreeDevice(&device); + close(priv->drm_fd); + priv->drm_fd = -1; + continue; + } + av_log(ctx, AV_LOG_VERBOSE, "Trying to use " + "DRM render node for device %d, " + "with matching vendor id (%s).\n", + n, vendor_id->value); + drmFreeDevice(&device); + break; } drmFreeVersion(info); #endif diff --git a/libavutil/version.h b/libavutil/version.h index 814892a4d5..852eeef1d6 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 59 -#define LIBAVUTIL_VERSION_MINOR 28 +#define LIBAVUTIL_VERSION_MINOR 29 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \