aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/hwcontext_vaapi.c
diff options
context:
space:
mode:
authorFei Wang <fei.w.wang@intel.com>2024-07-26 09:05:20 +0800
committerHaihao Xiang <haihao.xiang@intel.com>2024-08-09 13:40:24 +0800
commitdbd74ba3c8f2a11f6ce6c177acfd3bbf1c0ba763 (patch)
tree20ce5a712cfe2adecb561f723ef7073a8ad2a7b5 /libavutil/hwcontext_vaapi.c
parentc390234da2e3c7a8884f5592f0b9b4928c482b3e (diff)
downloadffmpeg-dbd74ba3c8f2a11f6ce6c177acfd3bbf1c0ba763.tar.gz
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. Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Diffstat (limited to 'libavutil/hwcontext_vaapi.c')
-rw-r--r--libavutil/hwcontext_vaapi.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 15fd84aa40..95aa38d9d2 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