3 * unit test for streamheader handling
5 * Copyright (C) 2007 Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
26 #include <gst/check/gstbufferstraw.h>
28 #ifndef GST_DISABLE_PARSE
30 /* this tests a gdp-serialized tag from audiotestsrc being sent only once
31 * to clients of multifdsink */
33 static int n_tags = 0;
36 tag_event_probe_cb (GstPad * pad, GstEvent * event, GMainLoop * loop)
38 switch (GST_EVENT_TYPE (event)) {
42 fail_if (n_tags > 1, "More than 1 tag received");
47 g_main_loop_quit (loop);
57 GST_START_TEST (test_multifdsink_gdp_tag)
60 GstElement *src, *sink, *depay;
65 loop = g_main_loop_new (NULL, FALSE);
67 p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! gdppay"
68 " ! multifdsink name=p1sink", NULL);
70 p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
71 " ! fakesink name=p2sink signal-handoffs=True", NULL);
74 fail_if (pipe (pfd) == -1);
77 gst_element_set_state (p1, GST_STATE_READY);
79 sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
80 g_signal_emit_by_name (sink, "add", pfd[1], NULL);
81 gst_object_unref (sink);
83 src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
84 g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
85 gst_object_unref (src);
87 depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
88 fail_if (depay == NULL);
90 pad = gst_element_get_pad (depay, "src");
91 fail_unless (pad != NULL, "Could not get pad out of depay");
92 gst_object_unref (depay);
94 gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
96 gst_element_set_state (p1, GST_STATE_PLAYING);
97 gst_element_set_state (p2, GST_STATE_PLAYING);
99 g_main_loop_run (loop);
101 assert_equals_int (n_tags, 1);
106 /* this tests gdp-serialized Vorbis header pages being sent only once
107 * to clients of multifdsink; the gdp depayloader should deserialize
108 * exactly three in_caps buffers for the three header packets */
110 static int n_in_caps = 0;
112 buffer_probe_cb (GstPad * pad, GstBuffer * buffer)
114 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) {
121 gboolean found = FALSE;
125 caps = gst_buffer_get_caps (buffer);
126 s = gst_caps_get_structure (caps, 0);
127 fail_unless (gst_structure_has_field (s, "streamheader"));
128 sh = gst_structure_get_value (s, "streamheader");
129 buffers = g_value_peek_pointer (sh);
130 assert_equals_int (buffers->len, 3);
133 for (i = 0; i < 3; ++i) {
136 val = &g_array_index (buffers, GValue, i);
137 buf = g_value_peek_pointer (val);
138 fail_unless (GST_IS_BUFFER (buf));
139 if (GST_BUFFER_SIZE (buf) == GST_BUFFER_SIZE (buffer)) {
140 if (memcmp (GST_BUFFER_DATA (buf), GST_BUFFER_DATA (buffer),
141 GST_BUFFER_SIZE (buffer)) == 0) {
146 fail_unless (found, "Did not find incoming IN_CAPS buffer %p on caps",
153 GST_START_TEST (test_multifdsink_gdp_vorbisenc)
156 GstElement *src, *sink, *depay;
161 loop = g_main_loop_new (NULL, FALSE);
163 p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! audioconvert "
164 " ! vorbisenc ! gdppay ! multifdsink name=p1sink", NULL);
165 fail_if (p1 == NULL);
166 p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
167 " ! fakesink name=p2sink signal-handoffs=True", NULL);
168 fail_if (p2 == NULL);
170 fail_if (pipe (pfd) == -1);
173 gst_element_set_state (p1, GST_STATE_READY);
175 sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
176 g_signal_emit_by_name (sink, "add", pfd[1], NULL);
177 gst_object_unref (sink);
179 src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
180 g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
181 gst_object_unref (src);
183 depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
184 fail_if (depay == NULL);
186 pad = gst_element_get_pad (depay, "src");
187 fail_unless (pad != NULL, "Could not get pad out of depay");
188 gst_object_unref (depay);
190 gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
191 gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL);
193 gst_element_set_state (p1, GST_STATE_PLAYING);
194 gst_element_set_state (p2, GST_STATE_PLAYING);
196 g_main_loop_run (loop);
198 //FIXME: here's the bug
199 //assert_equals_int (n_in_caps, 3);
205 #endif /* #ifndef GST_DISABLE_PARSE */
208 streamheader_suite (void)
210 Suite *s = suite_create ("streamheader");
211 TCase *tc_chain = tcase_create ("general");
213 suite_add_tcase (s, tc_chain);
214 #ifndef GST_DISABLE_PARSE
215 tcase_add_test (tc_chain, test_multifdsink_gdp_tag);
216 tcase_add_test (tc_chain, test_multifdsink_gdp_vorbisenc);
223 main (int argc, char **argv)
227 Suite *s = streamheader_suite ();
228 SRunner *sr = srunner_create (s);
230 gst_check_init (&argc, &argv);
232 srunner_run_all (sr, CK_NORMAL);
233 nf = srunner_ntests_failed (sr);