plugins: add helper for detecting VA surfaces in caps.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 20 Aug 2014 09:30:41 +0000 (11:30 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Thu, 21 Aug 2014 07:36:36 +0000 (09:36 +0200)
Introduce new gst_caps_has_vaapi_surface() helper function to detect
whether the supplied caps has VA surfaces. With GStreamer >= 1.2, this
implies a check for memory:VASurface caps features, and format=ENCODED
for earlier versions of GStreamer.

gst/vaapi/gstvaapipluginutil.c
gst/vaapi/gstvaapipluginutil.h

index 7c3e354..2c3a3cd 100644 (file)
@@ -612,3 +612,47 @@ gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip)
 #endif
   return TRUE;
 }
+
+/* Checks whether the supplied caps contain VA surfaces */
+gboolean
+gst_caps_has_vaapi_surface (GstCaps * caps)
+{
+  gboolean found_caps = FALSE;
+  guint i, num_structures;
+
+  g_return_val_if_fail (caps != NULL, FALSE);
+
+  num_structures = gst_caps_get_size (caps);
+  if (num_structures < 1)
+    return FALSE;
+
+#if GST_CHECK_VERSION(1,1,0)
+  for (i = 0; i < num_structures && !found_caps; i++) {
+    GstCapsFeatures *const features = gst_caps_get_features (caps, i);
+
+#if GST_CHECK_VERSION(1,3,0)
+    /* Skip ANY features, we need an exact match for correct evaluation */
+    if (gst_caps_features_is_any (features))
+      continue;
+#endif
+
+    found_caps = gst_caps_features_contains (features,
+        GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE);
+  }
+#else
+  for (i = 0; i < num_structures && !found_caps; i++) {
+    GstStructure *const structure = gst_caps_get_structure (caps, i);
+    GstCaps *test_caps;
+    GstVideoInfo vi;
+
+    test_caps = gst_caps_new_full (gst_structure_copy (structure), NULL);
+    if (!test_caps)
+      continue;
+
+    found_caps = gst_video_info_from_caps (&vi, test_caps) &&
+        GST_VIDEO_INFO_FORMAT (&vi) == GST_VIDEO_FORMAT_ENCODED;
+    gst_caps_unref (test_caps);
+  }
+#endif
+  return found_caps;
+}
index 4fc7450..6380a11 100644 (file)
@@ -109,4 +109,8 @@ G_GNUC_INTERNAL
 gboolean
 gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip);
 
+G_GNUC_INTERNAL
+gboolean
+gst_caps_has_vaapi_surface (GstCaps * caps);
+
 #endif /* GST_VAAPI_PLUGIN_UTIL_H */