summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Santos <thiagoss@osg.samsung.com>2016-02-23 12:17:59 -0300
committerThiago Santos <thiagoss@osg.samsung.com>2016-02-25 11:43:43 -0300
commit7d948b025a3d4cfaedd156418266eaa607ab1f16 (patch)
tree4c0f3f0f7a7093f36aa0c071774b77b1cd28734a
parentf231598370ebc4364d16eab1c7e3dbdd7001668a (diff)
tests: compositor: add tests for caps queries
Verifies that proper caps are returned based on what downstream restricts.
-rw-r--r--tests/check/elements/compositor.c149
1 files changed, 80 insertions, 69 deletions
diff --git a/tests/check/elements/compositor.c b/tests/check/elements/compositor.c
index cf50e1532..0f5aad4a5 100644
--- a/tests/check/elements/compositor.c
+++ b/tests/check/elements/compositor.c
@@ -45,6 +45,24 @@
static GMainLoop *main_loop;
+static GstCaps *
+_compositor_get_all_supported_caps (void)
+{
+ return gst_caps_from_string (GST_VIDEO_CAPS_MAKE
+ (" { AYUV, BGRA, ARGB, RGBA, ABGR, Y444, Y42B, YUY2, UYVY, "
+ " YVYU, I420, YV12, NV12, NV21, Y41B, RGB, BGR, xRGB, xBGR, "
+ " RGBx, BGRx } "));
+}
+
+static GstCaps *
+_compositor_get_non_alpha_supported_caps (void)
+{
+ return gst_caps_from_string (GST_VIDEO_CAPS_MAKE
+ (" { Y444, Y42B, YUY2, UYVY, "
+ " YVYU, I420, YV12, NV12, NV21, Y41B, RGB, BGR, xRGB, xBGR, "
+ " RGBx, BGRx } "));
+}
+
/* make sure downstream gets a CAPS event before buffers are sent */
GST_START_TEST (test_caps)
{
@@ -283,73 +301,73 @@ create_video_buffer (GstCaps * caps, gint ts_in_seconds)
return buf;
}
-#define MODE_ALL 1
-#define MODE_NON_ALPHA 2
-/* mostly copied from videoaggregator */
-static inline GstCaps *
-_get_non_alpha_caps_from_caps (GstCaps * caps)
+GST_START_TEST (test_caps_query)
{
- GstCaps *result;
- guint i, size;
-
- size = gst_caps_get_size (caps);
- result = gst_caps_new_empty ();
- for (i = 0; i < size; i++) {
- GstStructure *s = gst_caps_get_structure (caps, i);
- const GValue *formats = gst_structure_get_value (s, "format");
- GValue new_formats = { 0, };
- gboolean has_format = FALSE;
-
- /* FIXME what to do if formats are missing? */
- if (formats) {
- const GstVideoFormatInfo *info;
-
- if (GST_VALUE_HOLDS_LIST (formats)) {
- guint list_size = gst_value_list_get_size (formats);
- guint index;
-
- g_value_init (&new_formats, GST_TYPE_LIST);
-
- for (index = 0; index < list_size; index++) {
- const GValue *list_item = gst_value_list_get_value (formats, index);
-
- info =
- gst_video_format_get_info (gst_video_format_from_string
- (g_value_get_string (list_item)));
- if (!GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
- has_format = TRUE;
- gst_value_list_append_value (&new_formats, list_item);
- }
- }
-
- } else if (G_VALUE_HOLDS_STRING (formats)) {
- info =
- gst_video_format_get_info (gst_video_format_from_string
- (g_value_get_string (formats)));
- if (!GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
- has_format = TRUE;
- gst_value_init_and_copy (&new_formats, formats);
- }
+ GstElement *compositor, *capsfilter, *sink;
+ GstElement *pipeline;
+ gboolean res;
+ GstStateChangeReturn state_res;
+ GstPad *sinkpad;
+ GstCaps *caps, *restriction_caps;
+ GstCaps *all_caps, *non_alpha_caps;
- } else {
- g_assert_not_reached ();
- GST_WARNING ("Unexpected type for video 'format' field: %s",
- G_VALUE_TYPE_NAME (formats));
- }
+ /* initial setup */
+ all_caps = _compositor_get_all_supported_caps ();
+ non_alpha_caps = _compositor_get_non_alpha_supported_caps ();
- if (has_format) {
- s = gst_structure_copy (s);
- gst_structure_take_value (s, "format", &new_formats);
- gst_caps_append_structure (result, s);
- }
+ compositor = gst_element_factory_make ("compositor", "compositor");
+ capsfilter = gst_element_factory_make ("capsfilter", "out-cf");
+ sink = gst_element_factory_make ("fakesink", "sink");
+ pipeline = gst_pipeline_new ("test-pipeline");
- }
- }
+ gst_bin_add_many (GST_BIN (pipeline), compositor, capsfilter, sink, NULL);
+ res = gst_element_link (compositor, capsfilter);
+ fail_unless (res == TRUE, NULL);
+ res = gst_element_link (capsfilter, sink);
+ fail_unless (res == TRUE, NULL);
+
+ sinkpad = gst_element_get_request_pad (compositor, "sink_%u");
+
+ state_res = gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ fail_if (state_res == GST_STATE_CHANGE_FAILURE);
- return result;
+ /* try an unrestricted caps query, should return all formats */
+ caps = gst_pad_query_caps (sinkpad, NULL);
+ fail_unless (gst_caps_is_equal (caps, all_caps));
+ gst_caps_unref (caps);
+
+ /* now restrict downstream to a single alpha format, it should still
+ * be able to convert anything else to it */
+ restriction_caps = gst_caps_from_string ("video/x-raw, format=(string)AYUV");
+ g_object_set (capsfilter, "caps", restriction_caps, NULL);
+ caps = gst_pad_query_caps (sinkpad, NULL);
+ fail_unless (gst_caps_is_equal (caps, all_caps));
+ gst_caps_unref (caps);
+ gst_caps_unref (restriction_caps);
+
+ /* now restrict downstream to a non-alpha format, it should
+ * be able to accept non-alpha formats */
+ restriction_caps = gst_caps_from_string ("video/x-raw, format=(string)I420");
+ g_object_set (capsfilter, "caps", restriction_caps, NULL);
+ caps = gst_pad_query_caps (sinkpad, NULL);
+ fail_unless (gst_caps_is_equal (caps, non_alpha_caps));
+ gst_caps_unref (caps);
+ gst_caps_unref (restriction_caps);
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_element_release_request_pad (compositor, sinkpad);
+ gst_object_unref (sinkpad);
+ gst_object_unref (pipeline);
+ gst_caps_unref (all_caps);
+ gst_caps_unref (non_alpha_caps);
}
+GST_END_TEST;
+
+#define MODE_ALL 1
+#define MODE_NON_ALPHA 2
+
static void
run_late_caps_query_test (GstCaps * input_caps, GstCaps * output_allowed_caps,
gint expected_caps_mode)
@@ -363,16 +381,8 @@ run_late_caps_query_test (GstCaps * input_caps, GstCaps * output_allowed_caps,
GstSegment segment;
GstCaps *caps, *all_caps, *non_alpha_caps;
- all_caps =
- gst_caps_from_string (GST_VIDEO_CAPS_MAKE
- (" { AYUV, BGRA, ARGB, RGBA, ABGR, Y444, Y42B, YUY2, UYVY, "
- " YVYU, I420, YV12, NV12, NV21, Y41B, RGB, BGR, xRGB, xBGR, "
- " RGBx, BGRx } "));
- non_alpha_caps =
- gst_caps_from_string (GST_VIDEO_CAPS_MAKE
- (" { Y444, Y42B, YUY2, UYVY, "
- " YVYU, I420, YV12, NV12, NV21, Y41B, RGB, BGR, xRGB, xBGR, "
- " RGBx, BGRx } "));
+ all_caps = _compositor_get_all_supported_caps ();
+ non_alpha_caps = _compositor_get_non_alpha_supported_caps ();
compositor = gst_element_factory_make ("compositor", "compositor");
capsfilter = gst_element_factory_make ("capsfilter", "out-cf");
@@ -1870,6 +1880,7 @@ compositor_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_caps);
tcase_add_test (tc_chain, test_event);
+ tcase_add_test (tc_chain, test_caps_query);
tcase_add_test (tc_chain, test_late_caps_query);
tcase_add_test (tc_chain, test_play_twice);
tcase_add_test (tc_chain, test_play_twice_then_add_and_play_again);