video: add gst_video_make_raw_caps()

More binding friendly version of GST_VIDEO_CAPS_MAKE().

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/676>
This commit is contained in:
Guillaume Desmottes 2020-05-27 15:41:43 +02:00 committed by GStreamer Merge Bot
parent f42e67c639
commit 84e0689d58
3 changed files with 128 additions and 0 deletions

View file

@ -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;
}

View file

@ -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__ */

View file

@ -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;
}