]> git.sesse.net Git - ffmpeg/commitdiff
hwcontext_vaapi: Add driver quirks to the hwdevice
authorMark Thompson <sw@jkqxz.net>
Sun, 12 Jun 2016 16:20:25 +0000 (17:20 +0100)
committerMark Thompson <sw@jkqxz.net>
Sat, 2 Jul 2016 13:09:54 +0000 (14:09 +0100)
The driver being used is detected inside av_hwdevice_ctx_init() and
the quirks field then set from a table of known device.  If this
behaviour is unwanted, the user can also set the quirks field
manually.

Also adds the Intel i965 driver quirk (it does not destroy parameter
buffers used in a call to vaRenderPicture()) and detects that driver
to set it.

doc/APIchanges
libavutil/hwcontext_vaapi.c
libavutil/hwcontext_vaapi.h
libavutil/version.h

index 8b5a33511d7a9ef32dc3bc1c2d3e3423061a5105..d9e83bc43b4219b84f24ec58ae1cd0b631c1c752 100644 (file)
@@ -13,6 +13,10 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2016-xx-xx - xxxxxxx - lavu 55.19.0 - hwcontext_vaapi.h
+  Add driver quirks field to VAAPI-specific hwdevice and enum with
+  members AV_VAAPI_DRIVER_QUIRK_* to represent its values.
+
 2016-xx-xx - xxxxxxx - lavu 55.18.0 - pixdesc.h
   Add AV_PIX_FMT_P010(LE/BE).
 
index ee5ce5d07533dc3df222b8f14e4ceff7c521efc2..506545cc28d3c2399a423ac7c856309985163d63 100644 (file)
@@ -263,12 +263,25 @@ fail:
     return err;
 }
 
+static const struct {
+    const char *friendly_name;
+    const char *match_string;
+    unsigned int quirks;
+} vaapi_driver_quirks_table[] = {
+    {
+        "Intel i965 (Quick Sync)",
+        "i965",
+        AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
+    },
+};
+
 static int vaapi_device_init(AVHWDeviceContext *hwdev)
 {
     VAAPIDeviceContext *ctx = hwdev->internal->priv;
     AVVAAPIDeviceContext *hwctx = hwdev->hwctx;
     VAImageFormat *image_list = NULL;
     VAStatus vas;
+    const char *vendor_string;
     int err, i, image_count;
     enum AVPixelFormat pix_fmt;
     unsigned int fourcc;
@@ -310,6 +323,32 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
         }
     }
 
+    if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_USER_SET) {
+        av_log(hwdev, AV_LOG_VERBOSE, "Not detecting driver: "
+               "quirks set by user.\n");
+    } else {
+        // Detect the driver in use and set quirk flags if necessary.
+        vendor_string = vaQueryVendorString(hwctx->display);
+        hwctx->driver_quirks = 0;
+        if (vendor_string) {
+            for (i = 0; i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table); i++) {
+                if (strstr(vendor_string,
+                           vaapi_driver_quirks_table[i].match_string)) {
+                    av_log(hwdev, AV_LOG_VERBOSE, "Matched \"%s\" as known "
+                           "driver \"%s\".\n", vendor_string,
+                           vaapi_driver_quirks_table[i].friendly_name);
+                    hwctx->driver_quirks |=
+                        vaapi_driver_quirks_table[i].quirks;
+                    break;
+                }
+            }
+            if (!(i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table))) {
+                av_log(hwdev, AV_LOG_VERBOSE, "Unknown driver \"%s\", "
+                       "assuming standard behaviour.\n", vendor_string);
+            }
+        }
+    }
+
     av_free(image_list);
     return 0;
 fail:
index 1c87f5db5e564fd7f32184ef55fb549a567cd8c9..0ac4caa5bb446a6aee27add1124bf21445b4a256 100644 (file)
  * with the data pointer set to a VASurfaceID.
  */
 
+enum {
+    /**
+     * The quirks field has been set by the user and should not be detected
+     * automatically by av_hwdevice_ctx_init().
+     */
+    AV_VAAPI_DRIVER_QUIRK_USER_SET = (1 << 0),
+    /**
+     * The driver does not destroy parameter buffers when they are used by
+     * vaRenderPicture().  Additional code will be required to destroy them
+     * separately afterwards.
+     */
+    AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS = (1 << 1),
+};
+
 /**
  * VAAPI connection details.
  *
@@ -43,6 +57,14 @@ typedef struct AVVAAPIDeviceContext {
      * The VADisplay handle, to be filled by the user.
      */
     VADisplay display;
+    /**
+     * Driver quirks to apply - this is filled by av_hwdevice_ctx_init(),
+     * with reference to a table of known drivers, unless the
+     * AV_VAAPI_DRIVER_QUIRK_USER_SET bit is already present.  The user
+     * may need to refer to this field when performing any later
+     * operations using VAAPI with the same VADisplay.
+     */
+    unsigned int driver_quirks;
 } AVVAAPIDeviceContext;
 
 /**
index 6cd42a62760762d90d3967b0cbb25d539ff42a96..1f38c6378bd55b8804be5fd87f94f7d8a466fa81 100644 (file)
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 18
+#define LIBAVUTIL_VERSION_MINOR 19
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \