plugin: util: add helper function to detect profiles in caps.
authorHe Junyan <junyan.he@hotmail.com>
Wed, 8 Jan 2020 07:07:36 +0000 (15:07 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 14 Jan 2020 11:36:18 +0000 (11:36 +0000)
gst/vaapi/gstvaapipluginutil.c
gst/vaapi/gstvaapipluginutil.h

index dd7cb81..4db9b77 100644 (file)
@@ -1008,3 +1008,66 @@ gst_vaapi_codecs_has_codec (GArray * codecs, GstVaapiCodec codec)
   }
   return FALSE;
 }
+
+/**
+ * gst_vaapi_h26x_encoder_get_profiles_from_caps:
+ * @caps: a #GstCaps to detect
+ * @func: a #GstVaapiStrToProfileFunc
+ *
+ * This function will detect all profile strings in @caps and
+ * return the according GstVaapiProfile in array. This can just
+ * work for h264 and h265 now.
+ *
+ * Return: A #GArray of @GstVaapiProfile if succeed, %NULL if fail.
+ **/
+GArray *
+gst_vaapi_h26x_encoder_get_profiles_from_caps (GstCaps * caps,
+    GstVaapiStrToProfileFunc func)
+{
+  guint i, j;
+  GstVaapiProfile profile;
+  GArray *profiles = NULL;
+
+  if (!caps)
+    return NULL;
+
+  profiles = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfile));
+  if (!profiles)
+    return NULL;
+
+  for (i = 0; i < gst_caps_get_size (caps); i++) {
+    GstStructure *const structure = gst_caps_get_structure (caps, i);
+    const GValue *const value = gst_structure_get_value (structure, "profile");
+
+    if (value && G_VALUE_HOLDS_STRING (value)) {
+      const gchar *str = g_value_get_string (value);
+      if (str) {
+        profile = func (str);
+        if (profile != GST_VAAPI_PROFILE_UNKNOWN)
+          g_array_append_val (profiles, profile);
+      }
+    } else if (value && GST_VALUE_HOLDS_LIST (value)) {
+      const GValue *v;
+      const gchar *str;
+      for (j = 0; j < gst_value_list_get_size (value); j++) {
+        v = gst_value_list_get_value (value, j);
+        if (!v || !G_VALUE_HOLDS_STRING (v))
+          continue;
+
+        str = g_value_get_string (v);
+        if (str) {
+          profile = func (str);
+          if (profile != GST_VAAPI_PROFILE_UNKNOWN)
+            g_array_append_val (profiles, profile);
+        }
+      }
+    }
+  }
+
+  if (profiles->len == 0) {
+    g_array_unref (profiles);
+    profiles = NULL;
+  }
+
+  return profiles;
+}
index bba668b..8ceb7ee 100644 (file)
@@ -29,6 +29,9 @@
 #include <gst/vaapi/gstvaapisurface.h>
 #include "gstvaapivideomemory.h"
 
+typedef GstVaapiProfile (*GstVaapiStrToProfileFunc) (const gchar * str);
+
+
 G_GNUC_INTERNAL
 gboolean
 gst_vaapi_ensure_display (GstElement * element, GstVaapiDisplayType type);
@@ -152,4 +155,9 @@ G_GNUC_INTERNAL
 gboolean
 gst_vaapi_codecs_has_codec (GArray * codecs, GstVaapiCodec codec);
 
+G_GNUC_INTERNAL
+GArray *
+gst_vaapi_h26x_encoder_get_profiles_from_caps (GstCaps * caps,
+    GstVaapiStrToProfileFunc func);
+
 #endif /* GST_VAAPI_PLUGIN_UTIL_H */