[FFmpeg-devel] [PATCH] hwcontext_vaapi: Add option to set driver name

Mark Thompson sw at jkqxz.net
Wed Nov 14 02:21:07 EET 2018


For example: -init_hw_device vaapi:/dev/dri/renderD128,driver=foo

This may be more convenient that using the environment variable, and allows
loading different drivers for different devices in the same process.
---
 libavutil/hwcontext_vaapi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 8624369bb9..eb3a78d181 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1469,6 +1469,8 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
 {
     VAAPIDevicePriv *priv;
     VADisplay display = NULL;
+    const AVDictionaryEntry *driver;
+    VAStatus vas;
 
     priv = av_mallocz(sizeof(*priv));
     if (!priv)
@@ -1530,6 +1532,17 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
         return AVERROR(EINVAL);
     }
 
+    driver = av_dict_get(opts, "driver", NULL, 0);
+    if (driver) {
+        vas = vaSetDriverName(display, driver->value);
+        if (vas != VA_STATUS_SUCCESS) {
+            av_log(ctx, AV_LOG_ERROR, "Failed to set driver name to "
+                   "%s: %d (%s).\n", driver->value, vas, vaErrorStr(vas));
+            vaTerminate(display);
+            return AVERROR_UNKNOWN;
+        }
+    }
+
     return vaapi_device_connect(ctx, display);
 }
 
-- 
2.19.1


More information about the ffmpeg-devel mailing list