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.
This commit is contained in:
Gwenole Beauchesne 2013-07-24 11:53:38 +02:00
parent 8ffe11a9df
commit f34b6ffc60
2 changed files with 53 additions and 0 deletions

View file

@ -139,6 +139,56 @@ get_map(GstVideoFormat format)
return NULL;
}
/**
* 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

View 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);