From: Guillaume Desmottes Date: Wed, 27 May 2020 13:41:43 +0000 (+0200) Subject: video: add gst_video_make_raw_caps() X-Git-Tag: 1.19.3~511^2~607 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84e0689d58f2c98614fc7d75620af78b0204b309;p=platform%2Fupstream%2Fgstreamer.git video: add gst_video_make_raw_caps() More binding friendly version of GST_VIDEO_CAPS_MAKE(). Part-of: --- diff --git a/gst-libs/gst/video/video-format.c b/gst-libs/gst/video/video-format.c index 1127bf8..d12162d 100644 --- a/gst-libs/gst/video/video-format.c +++ b/gst-libs/gst/video/video-format.c @@ -7093,3 +7093,86 @@ gst_video_formats_raw (guint * len) *len = all->n; return all->formats; } + +/** + * gst_video_make_raw_caps: + * @formats: (array length=len) (nullable): an array of raw #GstVideoFormat, or %NULL + * @len: the size of @formats + * + * Return a generic raw video caps for formats defined in @formats. + * If @formats is %NULL returns a caps for all the supported raw video formats, + * see gst_video_formats_raw(). + * + * Returns: (transfer full): a video @GstCaps + * Since: 1.18 + */ +GstCaps * +gst_video_make_raw_caps (const GstVideoFormat formats[], guint len) +{ + return gst_video_make_raw_caps_with_features (formats, len, NULL); +} + +/** + * gst_video_make_raw_caps_with_features: + * @formats: (array length=len) (nullable): an array of raw #GstVideoFormat, or %NULL + * @len: the size of @formats + * @features: (transfer full) (allow-none): the #GstCapsFeatures to set on the caps + * + * Return a generic raw video caps for formats defined in @formats with features + * @features. + * If @formats is %NULL returns a caps for all the supported video formats, + * see gst_video_formats_raw(). + * + * Returns: (transfer full): a video @GstCaps + * Since: 1.18 + */ +GstCaps * +gst_video_make_raw_caps_with_features (const GstVideoFormat formats[], + guint len, GstCapsFeatures * features) +{ + GstStructure *s; + GValue format = G_VALUE_INIT; + GstCaps *caps; + + g_return_val_if_fail ((formats && len > 0) || (!formats && len == 0), NULL); + + if (!formats) { + formats = gst_video_formats_raw (&len); + } + + if (len > 1) { + guint i; + + g_value_init (&format, GST_TYPE_LIST); + + for (i = 0; i < len; i++) { + GValue v = G_VALUE_INIT; + + g_return_val_if_fail (formats[i] != GST_VIDEO_FORMAT_UNKNOWN + && formats[i] != GST_VIDEO_FORMAT_ENCODED, NULL); + + g_value_init (&v, G_TYPE_STRING); + g_value_set_static_string (&v, gst_video_format_to_string (formats[i])); + gst_value_list_append_and_take_value (&format, &v); + } + } else { + g_value_init (&format, G_TYPE_STRING); + + g_value_set_static_string (&format, + gst_video_format_to_string (formats[0])); + } + + s = gst_structure_new ("video/x-raw", + "width", GST_TYPE_INT_RANGE, 1, G_MAXINT, + "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, + "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); + + gst_structure_take_value (s, "format", &format); + + caps = gst_caps_new_full (s, NULL); + + if (features) + gst_caps_set_features (caps, 0, features); + + return caps; +} diff --git a/gst-libs/gst/video/video-format.h b/gst-libs/gst/video/video-format.h index a2aacd4..c73513c 100644 --- a/gst-libs/gst/video/video-format.h +++ b/gst-libs/gst/video/video-format.h @@ -625,6 +625,13 @@ const GstVideoFormat * gst_video_formats_raw (guint * len); "height = " GST_VIDEO_SIZE_RANGE ", " \ "framerate = " GST_VIDEO_FPS_RANGE +GST_VIDEO_API +GstCaps * gst_video_make_raw_caps (const GstVideoFormat formats[], guint len); + +GST_VIDEO_API +GstCaps * gst_video_make_raw_caps_with_features (const GstVideoFormat formats[], guint len, + GstCapsFeatures * features); + G_END_DECLS #endif /* __GST_VIDEO_FORMAT_H__ */ diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c index 62572d7..f33f56a 100644 --- a/tests/check/libs/video.c +++ b/tests/check/libs/video.c @@ -3786,6 +3786,43 @@ GST_START_TEST (test_video_flags) GST_END_TEST; +GST_START_TEST (test_video_make_raw_caps) +{ + GstCaps *caps, *expected; + GstVideoFormat f1[] = { GST_VIDEO_FORMAT_NV12 }; + GstVideoFormat f2[] = { GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV16 }; + + caps = gst_video_make_raw_caps (f1, G_N_ELEMENTS (f1)); + expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("NV12")); + fail_unless (gst_caps_is_equal (caps, expected)); + gst_caps_unref (caps); + gst_caps_unref (expected); + + caps = gst_video_make_raw_caps (f2, G_N_ELEMENTS (f2)); + expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("{ NV12, NV16 }")); + fail_unless (gst_caps_is_equal (caps, expected)); + gst_caps_unref (caps); + gst_caps_unref (expected); + + caps = gst_video_make_raw_caps (NULL, 0); + expected = gst_caps_from_string (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL)); + fail_unless (gst_caps_is_equal (caps, expected)); + gst_caps_unref (caps); + gst_caps_unref (expected); + + caps = + gst_video_make_raw_caps_with_features (NULL, 0, + gst_caps_features_new_any ()); + expected = + gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES ("ANY", + GST_VIDEO_FORMATS_ALL)); + fail_unless (gst_caps_is_equal (caps, expected)); + gst_caps_unref (caps); + gst_caps_unref (expected); +} + +GST_END_TEST; + static Suite * video_suite (void) { @@ -3837,6 +3874,7 @@ video_suite (void) tcase_add_test (tc_chain, test_video_info_align); tcase_add_test (tc_chain, test_video_meta_align); tcase_add_test (tc_chain, test_video_flags); + tcase_add_test (tc_chain, test_video_make_raw_caps); return s; }