History

lavu/hwcontext_vaapi: Add option to allow to specify vendor id when init hw device

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.

Fei Wang committed 2 years ago

Commit dbd74ba1 parent c3902343 files · +38 −1Browse files

Unified · Split

3 files
  1. doc/ffmpeg.texi +8 −0
  2. libavutil/hwcontext_vaapi.c +29 −0
  3. libavutil/version.h +1 −1
doc/ffmpeg.texi+8−0
@@ -1458,6 +1458,11 @@ The following options are recognized: · 1457 unmodified lines
14581458 When @var{device} is not specified, use this option to specify the name of the kernel
14591459 driver associated with the desired device. This option is available only when
14601460 the hardware acceleration method @emph{drm} and @emph{vaapi} are enabled.
1461+@item vendor_id
1462+When @var{device} and @var{kernel_driver} are not specified, use this option to specify
1463+the vendor id associated with the desired device. This option is available only when the
1464+hardware acceleration method @emph{drm} and @emph{vaapi} are enabled and @emph{kernel_driver}
1465+is not specified.
14611466 @end table
14621467
14631468 Examples:
@@ -1473,6 +1478,9 @@ Create a vaapi device on DirectX adapter 1. · 9 unmodified lines
14731478
14741479 @item -init_hw_device vaapi:,kernel_driver=i915
14751480 Create a vaapi device on a device associated with kernel driver @samp{i915}.
1481+
1482+@item -init_hw_device vaapi:,vendor_id=0x8086
1483+Create a vaapi device on a device associated with vendor id @samp{0x8086}.
14761484 @end table
14771485
14781486 @item vdpau
libavutil/hwcontext_vaapi.c+29−0
@@ -1748,7 +1748,9 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, · 1747 unmodified lines
17481748 #if CONFIG_LIBDRM
17491749 drmVersion *info;
17501750 const AVDictionaryEntry *kernel_driver;
1751+ const AVDictionaryEntry *vendor_id;
17511752 kernel_driver = av_dict_get(opts, "kernel_driver", NULL, 0);
1753+ vendor_id = av_dict_get(opts, "vendor_id", NULL, 0);
17521754 #endif
17531755 for (n = 0; n < max_devices; n++) {
17541756 snprintf(path, sizeof(path),
@@ -1803,6 +1805,33 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, · 48 unmodified lines
18031805 close(priv->drm_fd);
18041806 priv->drm_fd = -1;
18051807 continue;
1808+ } else if (vendor_id) {
1809+ drmDevicePtr device;
1810+ char drm_vendor[8];
1811+ if (drmGetDevice(priv->drm_fd, &device)) {
1812+ av_log(ctx, AV_LOG_VERBOSE,
1813+ "Failed to get DRM device info for device %d.\n", n);
1814+ close(priv->drm_fd);
1815+ priv->drm_fd = -1;
1816+ continue;
1817+ }
1818+
1819+ snprintf(drm_vendor, sizeof(drm_vendor), "0x%x", device->deviceinfo.pci->vendor_id);
1820+ if (strcmp(vendor_id->value, drm_vendor)) {
1821+ av_log(ctx, AV_LOG_VERBOSE, "Ignoring device %d "
1822+ "with non-matching vendor id (%s).\n",
1823+ n, vendor_id->value);
1824+ drmFreeDevice(&device);
1825+ close(priv->drm_fd);
1826+ priv->drm_fd = -1;
1827+ continue;
1828+ }
1829+ av_log(ctx, AV_LOG_VERBOSE, "Trying to use "
1830+ "DRM render node for device %d, "
1831+ "with matching vendor id (%s).\n",
1832+ n, vendor_id->value);
1833+ drmFreeDevice(&device);
1834+ break;
18061835 }
18071836 drmFreeVersion(info);
18081837 #endif
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 59
82−#define LIBAVUTIL_VERSION_MINOR 32
82+#define LIBAVUTIL_VERSION_MINOR 33
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t