libs: add gst_vaapi_video_format_from_string() helper.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 24 Jul 2013 09:53:38 +0000 (11:53 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 23 Aug 2013 17:00:38 +0000 (19:00 +0200)
Add gst_vaapi_video_format_from_string() helper function to convert from
a video format string representation to a suitable GstVideoFormat. This
is just an alias to gst_video_format_from_string() for GStreamer 1.0.x
builds, and a proper iteration over all GstVideoFormat string representations
otherwise for earlier GStreamer 0.10.x builds.

gst-libs/gst/vaapi/video-format.c
gst-libs/gst/vaapi/video-format.h

index e3bbecb..523e6fc 100644 (file)
@@ -140,6 +140,56 @@ get_map(GstVideoFormat format)
 }
 
 /**
+ * gst_vaapi_video_format_from_string:
+ * @str: a string representation of #GstVideoFormat
+ *
+ * Returns the #GstVideoFormat represented as the string @str.
+ *
+ * Return value: #GstVideoFormat for the string representation of
+ *   video format in @str.
+ */
+GstVideoFormat
+gst_vaapi_video_format_from_string(const gchar *str)
+{
+#if GST_CHECK_VERSION(1,0,0)
+    return gst_video_format_from_string(str);
+#else
+    GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
+
+    do {
+        /* Validate input string */
+        if (!str)
+            break;
+
+        /* Fast path: assume this represents a common fourcc value */
+        const guint32 fourcc = GST_MAKE_FOURCC(str[0], str[1], str[2], str[3]);
+        format = gst_video_format_from_fourcc(fourcc);
+        if (format != GST_VIDEO_FORMAT_UNKNOWN)
+            break;
+
+        /* Slow path: check through all registered enum values */
+        GEnumClass * const enum_class =
+            g_type_class_ref(GST_TYPE_VIDEO_FORMAT);
+        if (!enum_class)
+            break;
+
+        gchar * const video_format_str =
+            g_strdup_printf("GST_VIDEO_FORMAT_%s", str);
+        if (video_format_str) {
+            const GEnumValue * const enum_value =
+                g_enum_get_value_by_name(enum_class, video_format_str);
+
+            if (enum_value)
+                format = enum_value->value;
+            g_free(video_format_str);
+        }
+        g_type_class_unref(enum_class);
+    } while (0);
+    return format;
+#endif
+}
+
+/**
  * gst_vaapi_video_format_to_string:
  * @format: a #GstVideoFormat
  *
index 84e9c75..fb2bb18 100644 (file)
@@ -28,6 +28,9 @@
 
 G_BEGIN_DECLS
 
+GstVideoFormat
+gst_vaapi_video_format_from_string(const gchar *str);
+
 const char *
 gst_vaapi_video_format_to_string(GstVideoFormat format);