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.
29 #include <gst/check/gstcheck.h>
30 #include <gst/check/gstbufferstraw.h>
32 #ifndef GST_DISABLE_PARSE
34 /* this tests a gdp-serialized tag from audiotestsrc being sent only once
35 * to clients of multifdsink */
37 static int n_tags = 0;
40 tag_event_probe_cb (GstPad * pad, GstEvent * event, GMainLoop * loop)
42 switch (GST_EVENT_TYPE (event)) {
46 fail_if (n_tags > 1, "More than 1 tag received");
51 g_main_loop_quit (loop);
61 GST_START_TEST (test_multifdsink_gdp_tag)
64 GstElement *src, *sink, *depay;
69 loop = g_main_loop_new (NULL, FALSE);
71 p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! gdppay"
72 " ! multifdsink name=p1sink", NULL);
74 p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
75 " ! fakesink name=p2sink signal-handoffs=True", NULL);
78 fail_if (pipe (pfd) == -1);
81 gst_element_set_state (p1, GST_STATE_READY);
83 sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
84 g_signal_emit_by_name (sink, "add", pfd[1], NULL);
85 gst_object_unref (sink);
87 src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
88 g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
89 gst_object_unref (src);
91 depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
92 fail_if (depay == NULL);
94 pad = gst_element_get_static_pad (depay, "src");
95 fail_unless (pad != NULL, "Could not get pad out of depay");
96 gst_object_unref (depay);
98 gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
100 gst_element_set_state (p1, GST_STATE_PLAYING);
101 gst_element_set_state (p2, GST_STATE_PLAYING);
103 g_main_loop_run (loop);
105 assert_equals_int (n_tags, 1);
107 gst_element_set_state (p1, GST_STATE_NULL);
108 gst_object_unref (p1);
109 gst_element_set_state (p2, GST_STATE_NULL);
110 gst_object_unref (p2);
116 /* this tests gdp-serialized Vorbis header pages being sent only once
117 * to clients of multifdsink; the gdp depayloader should deserialize
118 * exactly three in_caps buffers for the three header packets */
120 static int n_in_caps = 0;
123 buffer_probe_cb (GstPad * pad, GstBuffer * buffer)
125 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) {
132 gboolean found = FALSE;
136 caps = gst_buffer_get_caps (buffer);
137 s = gst_caps_get_structure (caps, 0);
138 fail_unless (gst_structure_has_field (s, "streamheader"));
139 sh = gst_structure_get_value (s, "streamheader");
140 buffers = g_value_peek_pointer (sh);
141 assert_equals_int (buffers->len, 3);
144 for (i = 0; i < 3; ++i) {
147 val = &g_array_index (buffers, GValue, i);
148 buf = g_value_peek_pointer (val);
149 fail_unless (GST_IS_BUFFER (buf));
150 if (GST_BUFFER_SIZE (buf) == GST_BUFFER_SIZE (buffer)) {
151 if (memcmp (GST_BUFFER_DATA (buf), GST_BUFFER_DATA (buffer),
152 GST_BUFFER_SIZE (buffer)) == 0) {
157 fail_unless (found, "Did not find incoming IN_CAPS buffer %p on caps",
160 gst_caps_unref (caps);
166 GST_START_TEST (test_multifdsink_gdp_vorbisenc)
169 GstElement *src, *sink, *depay;
174 loop = g_main_loop_new (NULL, FALSE);
176 p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! audioconvert "
177 " ! vorbisenc ! gdppay ! multifdsink name=p1sink", NULL);
178 fail_if (p1 == NULL);
179 p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
180 " ! fakesink name=p2sink signal-handoffs=True", NULL);
181 fail_if (p2 == NULL);
183 fail_if (pipe (pfd) == -1);
186 gst_element_set_state (p1, GST_STATE_READY);
188 sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
189 g_signal_emit_by_name (sink, "add", pfd[1], NULL);
190 gst_object_unref (sink);
192 src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
193 g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
194 gst_object_unref (src);
196 depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
197 fail_if (depay == NULL);
199 pad = gst_element_get_static_pad (depay, "src");
200 fail_unless (pad != NULL, "Could not get pad out of depay");
201 gst_object_unref (depay);
203 gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
204 gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL);
206 gst_element_set_state (p1, GST_STATE_PLAYING);
207 gst_element_set_state (p2, GST_STATE_PLAYING);
209 g_main_loop_run (loop);
211 assert_equals_int (n_in_caps, 3);
213 gst_element_set_state (p1, GST_STATE_NULL);
214 gst_object_unref (p1);
215 gst_element_set_state (p2, GST_STATE_NULL);
216 gst_object_unref (p2);
220 #endif /* HAVE_VORBIS */
222 #endif /* #ifndef GST_DISABLE_PARSE */
225 streamheader_suite (void)
227 Suite *s = suite_create ("streamheader");
228 TCase *tc_chain = tcase_create ("general");
230 suite_add_tcase (s, tc_chain);
231 #ifndef GST_DISABLE_PARSE
232 tcase_add_test (tc_chain, test_multifdsink_gdp_tag);
234 tcase_add_test (tc_chain, test_multifdsink_gdp_vorbisenc);
242 main (int argc, char **argv)
246 Suite *s = streamheader_suite ();
247 SRunner *sr = srunner_create (s);
249 gst_check_init (&argc, &argv);
251 srunner_run_all (sr, CK_NORMAL);
252 nf = srunner_ntests_failed (sr);