2 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
4 * capsfilter-renegotiation.c: Unit test for capsfilter caps renegotiation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 /* Ideally this would be in core, but using videotestsrc makes it easier */
24 #include <gst/check/gstcheck.h>
26 #define FIRST_CAPS "video/x-raw-yuv,width=(int)480,height=(int)320"
27 #define SECOND_CAPS "video/x-raw-yuv,width=(int)120,height=(int)100"
28 #define THIRD_CAPS "video/x-raw-yuv,width=(int)[10,50],height=(int)[100,200]"
29 #define FOURTH_CAPS "video/x-raw-rgb,width=(int)300,height=(int)[25,75];" \
30 "video/x-raw-yuv,width=(int)[30,40]," \
31 "height=(int)[100,200],format=(fourcc)YUY2"
34 GstCaps *current_caps = NULL;
38 buffer_probe (GstPad * pad, GstMiniObject * obj, gpointer data)
42 GstElement *capsfilter = GST_ELEMENT (data);
45 buffer = GST_BUFFER (obj);
47 /* increment the buffer count and check if it is time to change the caps */
49 if (buffer_count == 50) {
50 /* change the caps to another one */
51 caps = gst_caps_from_string (SECOND_CAPS);
52 } else if (buffer_count == 100) {
53 /* change the caps to another one, this time unfixed */
54 caps = gst_caps_from_string (THIRD_CAPS);
55 } else if (buffer_count == 150) {
56 /* change the caps to another one,
57 * this time unfixed with multiple entries */
58 caps = gst_caps_from_string (FOURTH_CAPS);
62 g_object_set (capsfilter, "caps", caps, NULL);
63 gst_caps_unref (caps);
66 /* now check if the buffer caps has changed since last check */
67 buffer_caps = GST_BUFFER_CAPS (buffer);
68 if (current_caps == NULL && buffer_caps != NULL) {
69 /* probably the first caps, this is a change */
70 current_caps = gst_caps_copy (buffer_caps);
72 } else if (current_caps != NULL) {
73 if (buffer_caps == NULL) {
74 /* caps was set to NULL, we consider this a change */
75 gst_caps_unref (current_caps);
79 if (!gst_caps_is_equal (current_caps, buffer_caps)) {
81 gst_caps_unref (current_caps);
82 current_caps = gst_caps_copy (buffer_caps);
91 GST_START_TEST (test_capsfilter_renegotiation)
93 GstElement *capsfilter;
103 gst_caps_unref (current_caps);
106 pipeline = gst_parse_launch ("videotestsrc num-buffers=200 ! capsfilter "
107 "caps=\"" FIRST_CAPS "\" name=cf ! fakesink name=sink", NULL);
110 capsfilter = gst_bin_get_by_name (GST_BIN (pipeline), "cf");
111 g_assert (capsfilter);
113 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
116 pad = gst_element_get_static_pad (sink, "sink");
117 gst_pad_add_buffer_probe (pad, (GCallback) buffer_probe, capsfilter);
118 gst_object_unref (pad);
120 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
122 g_assert (gst_element_set_state (pipeline, GST_STATE_PLAYING) !=
123 GST_STATE_CHANGE_FAILURE);
125 msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
126 GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
128 g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
130 g_assert (caps_change == 4);
132 gst_element_set_state (pipeline, GST_STATE_NULL);
135 gst_caps_unref (current_caps);
136 gst_message_unref (msg);
137 g_object_unref (bus);
138 g_object_unref (G_OBJECT (pipeline));
144 capsfilter_renegotiation_suite (void)
146 Suite *s = suite_create ("CapsfilterRenegotiation");
147 TCase *tc_chain = tcase_create ("linear");
149 /* time out after 60s, not the default 3 */
150 tcase_set_timeout (tc_chain, 60);
152 suite_add_tcase (s, tc_chain);
153 tcase_add_test (tc_chain, test_capsfilter_renegotiation);
158 main (int argc, char **argv)
162 Suite *s = capsfilter_renegotiation_suite ();
163 SRunner *sr = srunner_create (s);
165 gst_check_init (&argc, &argv);
167 srunner_run_all (sr, CK_NORMAL);
168 nf = srunner_ntests_failed (sr);