From c898ffceebcf7723e3d4805bf03cd890f4ba50fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 4 May 2021 15:50:59 -0400 Subject: [PATCH] video: Add API to parse the image orientation from a GstTagList Part-of: --- .../gst-libs/gst/video/video.c | 49 +++++++++++++++++++ .../gst-libs/gst/video/video.h | 5 ++ 2 files changed, 54 insertions(+) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video.c b/subprojects/gst-plugins-base/gst-libs/gst/video/video.c index 21cc5a157c..4e20baa6c8 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/video.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video.c @@ -237,3 +237,52 @@ gst_video_orientation_method_get_type (void) return (GType) video_orientation_method_type; } + +/** + * gst_video_orientation_from_tag: + * @taglist: A #GstTagList + * @method: The location where to return the orientation. + * + * Parses the "image-orientation" tag and transforms it into the + * #GstVideoOrientationMethod enum. + * + * Returns: TRUE if there was a valid "image-orientation" tag in the taglist. + * + * Since: 1.20 + */ +gboolean +gst_video_orientation_from_tag (GstTagList * taglist, + GstVideoOrientationMethod * method) +{ + gchar *orientation; + gboolean ret = TRUE; + + g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE); + g_return_val_if_fail (method != NULL, FALSE); + + if (!gst_tag_list_get_string (taglist, "image-orientation", &orientation)) + return FALSE; + + if (!g_strcmp0 ("rotate-0", orientation)) + *method = GST_VIDEO_ORIENTATION_IDENTITY; + else if (!g_strcmp0 ("rotate-90", orientation)) + *method = GST_VIDEO_ORIENTATION_90R; + else if (!g_strcmp0 ("rotate-180", orientation)) + *method = GST_VIDEO_ORIENTATION_180; + else if (!g_strcmp0 ("rotate-270", orientation)) + *method = GST_VIDEO_ORIENTATION_90L; + else if (!g_strcmp0 ("flip-rotate-0", orientation)) + *method = GST_VIDEO_ORIENTATION_HORIZ; + else if (!g_strcmp0 ("flip-rotate-90", orientation)) + *method = GST_VIDEO_ORIENTATION_UR_LL; + else if (!g_strcmp0 ("flip-rotate-180", orientation)) + *method = GST_VIDEO_ORIENTATION_VERT; + else if (!g_strcmp0 ("flip-rotate-270", orientation)) + *method = GST_VIDEO_ORIENTATION_UL_LR; + else + ret = FALSE; + + g_free (orientation); + + return ret; +} diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/video.h b/subprojects/gst-plugins-base/gst-libs/gst/video/video.h index 24a3a7319f..a1a6d1a422 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/video.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/video.h @@ -172,6 +172,11 @@ GstSample * gst_video_convert_sample (GstSample * sample, GstClockTime timeout, GError ** error); + +GST_VIDEO_API +gboolean gst_video_orientation_from_tag (GstTagList * taglist, + GstVideoOrientationMethod * method); + G_END_DECLS #include