From: Gwenole Beauchesne Date: Wed, 24 Jul 2013 09:53:38 +0000 (+0200) Subject: libs: add gst_vaapi_video_format_from_string() helper. X-Git-Tag: 1.19.3~503^2~2484 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f34b6ffc60bfb87f03873c2d8ec2bebcfd3a5768;p=platform%2Fupstream%2Fgstreamer.git libs: add gst_vaapi_video_format_from_string() helper. 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. --- diff --git a/gst-libs/gst/vaapi/video-format.c b/gst-libs/gst/vaapi/video-format.c index e3bbecb..523e6fc 100644 --- a/gst-libs/gst/vaapi/video-format.c +++ b/gst-libs/gst/vaapi/video-format.c @@ -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 * diff --git a/gst-libs/gst/vaapi/video-format.h b/gst-libs/gst/vaapi/video-format.h index 84e9c75..fb2bb18 100644 --- a/gst-libs/gst/vaapi/video-format.h +++ b/gst-libs/gst/vaapi/video-format.h @@ -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);