[FFmpeg-devel,7/7] hwcontext_qsv: Try to select a matching VAAPI device by default

Submitted by Mark Thompson on May 6, 2019, 2:49 p.m.

Details

Message ID 20190506144928.28501-7-sw@jkqxz.net
State Accepted
Commit 468f00384338dc201c5ae8b00229afff703d1d25
Headers show

Commit Message

Mark Thompson May 6, 2019, 2:49 p.m.
Tries to find a device backed by the i915 kernel driver and loads the iHD
VAAPI driver to use with it.  This reduces confusion on machines with
multiple DRM devices and removes the surprising requirement to set the
LIBVA_DRIVER_NAME environment variable to use libmfx at all.
---
 libavutil/hwcontext_qsv.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Zhong Li May 21, 2019, 5:41 a.m.
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf

> Of Mark Thompson

> Sent: Monday, May 6, 2019 10:49 PM

> To: ffmpeg-devel@ffmpeg.org

> Subject: [FFmpeg-devel] [PATCH 7/7] hwcontext_qsv: Try to select a

> matching VAAPI device by default

> 

> Tries to find a device backed by the i915 kernel driver and loads the iHD

> VAAPI driver to use with it.  This reduces confusion on machines with

> multiple DRM devices and removes the surprising requirement to set the

> LIBVA_DRIVER_NAME environment variable to use libmfx at all.

> ---

>  libavutil/hwcontext_qsv.c | 15 ++++++++++++---

>  1 file changed, 12 insertions(+), 3 deletions(-)

> 

> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index

> 49b5952cef..59e4ed9157 100644

> --- a/libavutil/hwcontext_qsv.c

> +++ b/libavutil/hwcontext_qsv.c

> @@ -1206,6 +1206,7 @@ static int qsv_device_create(AVHWDeviceContext

> *ctx, const char *device,

>      QSVDevicePriv *priv;

>      enum AVHWDeviceType child_device_type;

>      AVHWDeviceContext *child_device;

> +    AVDictionary *child_device_opts;

>      AVDictionaryEntry *e;

> 

>      mfxIMPL impl;

> @@ -1220,9 +1221,17 @@ static int

> qsv_device_create(AVHWDeviceContext *ctx, const char *device,

> 

>      e = av_dict_get(opts, "child_device", NULL, 0);

> 

> -    if (CONFIG_VAAPI)

> +    child_device_opts = NULL;

> +    if (CONFIG_VAAPI) {

>          child_device_type = AV_HWDEVICE_TYPE_VAAPI;

> -    else if (CONFIG_DXVA2)

> +        // libmfx does not actually implement VAAPI properly, rather it

> +        // depends on the specific behaviour of a matching iHD driver

> when

> +        // used on recent Intel hardware.  Set options to the VAAPI

> device

> +        // creation so that we should pick a usable setup by default if

> +        // possible, even when multiple devices and drivers are available.

> +        av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);

> +        av_dict_set(&child_device_opts, "driver",        "iHD",  0);

> +    } else if (CONFIG_DXVA2)

>          child_device_type = AV_HWDEVICE_TYPE_DXVA2;

>      else {

>          av_log(ctx, AV_LOG_ERROR, "No supported child device type is

> enabled\n"); @@ -1230,7 +1239,7 @@ static int

> qsv_device_create(AVHWDeviceContext *ctx, const char *device,

>      }

> 

>      ret = av_hwdevice_ctx_create(&priv->child_device_ctx,

> child_device_type,

> -                                 e ? e->value : NULL, NULL, 0);

> +                                 e ? e->value : NULL,

> + child_device_opts, 0);

>      if (ret < 0)

>          return ret;

> 

> --

> 2.20.1


LGTM and tested. Thanks!

Patch hide | download patch | download mbox

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 49b5952cef..59e4ed9157 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1206,6 +1206,7 @@  static int qsv_device_create(AVHWDeviceContext *ctx, const char *device,
     QSVDevicePriv *priv;
     enum AVHWDeviceType child_device_type;
     AVHWDeviceContext *child_device;
+    AVDictionary *child_device_opts;
     AVDictionaryEntry *e;
 
     mfxIMPL impl;
@@ -1220,9 +1221,17 @@  static int qsv_device_create(AVHWDeviceContext *ctx, const char *device,
 
     e = av_dict_get(opts, "child_device", NULL, 0);
 
-    if (CONFIG_VAAPI)
+    child_device_opts = NULL;
+    if (CONFIG_VAAPI) {
         child_device_type = AV_HWDEVICE_TYPE_VAAPI;
-    else if (CONFIG_DXVA2)
+        // libmfx does not actually implement VAAPI properly, rather it
+        // depends on the specific behaviour of a matching iHD driver when
+        // used on recent Intel hardware.  Set options to the VAAPI device
+        // creation so that we should pick a usable setup by default if
+        // possible, even when multiple devices and drivers are available.
+        av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);
+        av_dict_set(&child_device_opts, "driver",        "iHD",  0);
+    } else if (CONFIG_DXVA2)
         child_device_type = AV_HWDEVICE_TYPE_DXVA2;
     else {
         av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n");
@@ -1230,7 +1239,7 @@  static int qsv_device_create(AVHWDeviceContext *ctx, const char *device,
     }
 
     ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type,
-                                 e ? e->value : NULL, NULL, 0);
+                                 e ? e->value : NULL, child_device_opts, 0);
     if (ret < 0)
         return ret;