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

Mark Thompson sw at jkqxz.net
Wed Nov 14 23:25:00 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.
---
On 14/11/18 12:05, Michael Niedermayer wrote:
> On Wed, Nov 14, 2018 at 12:21:07AM +0000, Mark Thompson wrote:
>> ...
>> +        vas = vaSetDriverName(display, driver->value);
> 
> this breaks build here on ubuntu:
> 
> CC	libavutil/hwcontext_vaapi.o
> libavutil/hwcontext_vaapi.c: In function ‘vaapi_device_create’:
> libavutil/hwcontext_vaapi.c:1537:9: error: implicit declaration of function ‘vaSetDriverName’ [-Werror=implicit-function-declaration]
>          vas = vaSetDriverName(display, driver->value);
>          ^
> cc1: some warnings being treated as errors
> make: *** [libavutil/hwcontext_vaapi.o] Error 1
> make: Target `all' not remade because of errors.

Ah, apologies - that API is newer than I thought.

Here's a new version with suitable guards.

Thanks,

- Mark


 libavutil/hwcontext_vaapi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 8624369bb9..4a4ecc44d7 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1469,6 +1469,7 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
 {
     VAAPIDevicePriv *priv;
     VADisplay display = NULL;
+    const AVDictionaryEntry *driver;
 
     priv = av_mallocz(sizeof(*priv));
     if (!priv)
@@ -1530,6 +1531,25 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device,
         return AVERROR(EINVAL);
     }
 
+    driver = av_dict_get(opts, "driver", NULL, 0);
+    if (driver) {
+#if VA_CHECK_VERSION(0, 38, 0)
+        VAStatus vas;
+        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;
+        }
+#else
+        av_log(ctx, AV_LOG_WARNING, "Driver name setting is not "
+               "supported with this VAAPI version.\n");
+        vaTerminate(display);
+        return AVERROR(ENOSYS);
+#endif
+    }
+
     return vaapi_device_connect(ctx, display);
 }
 
-- 
2.19.1


More information about the ffmpeg-devel mailing list