3 * unit test for audiotestsrc basetime handling
5 * Copyright (C) 2009 Maemo Multimedia <multimedia at maemo 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.
27 #include <gst/check/gstcheck.h>
29 #ifndef GST_DISABLE_PARSE
31 static GstClockTime old_ts = GST_CLOCK_TIME_NONE;
34 break_mainloop (gpointer data)
38 loop = (GMainLoop *) data;
39 g_main_loop_quit (loop);
45 buffer_probe_cb (GstPad * pad, GstBuffer * buffer)
47 if (old_ts != GST_CLOCK_TIME_NONE) {
48 fail_unless (GST_BUFFER_TIMESTAMP (buffer) != old_ts,
49 "Two buffers had same timestamp");
51 old_ts = GST_BUFFER_TIMESTAMP (buffer);
56 GST_START_TEST (test_basetime_calculation)
59 GstElement *asrc, *asink;
63 /* Don't run with osxaudiosrc . This is because libcheck runs the actual
64 * test in a forked process and causes havoc with osx's API. */
65 if (G_UNLIKELY (!g_ascii_strcasecmp (DEFAULT_AUDIOSRC, "osxaudiosrc")))
68 loop = g_main_loop_new (NULL, FALSE);
70 /* The "main" pipeline */
71 p1 = gst_parse_launch ("fakesrc ! fakesink", NULL);
74 /* Create a sub-bin that is activated only in "certain situations" */
75 asrc = gst_element_factory_make (DEFAULT_AUDIOSRC, NULL);
77 GST_WARNING ("Cannot run test. test audio source %s not available",
79 gst_element_set_state (p1, GST_STATE_NULL);
80 gst_object_unref (p1);
83 asink = gst_element_factory_make ("fakesink", NULL);
85 bin = gst_bin_new ("audiobin");
86 gst_bin_add_many (GST_BIN (bin), asrc, asink, NULL);
87 gst_element_link (asrc, asink);
89 gst_bin_add (GST_BIN (p1), bin);
90 gst_element_set_state (p1, GST_STATE_READY);
92 pad = gst_element_get_static_pad (asink, "sink");
93 fail_unless (pad != NULL, "Could not get pad out of sink");
95 gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL);
96 gst_element_set_locked_state (bin, TRUE);
98 /* Run main pipeline first */
99 gst_element_set_state (p1, GST_STATE_PLAYING);
100 g_timeout_add (2 * 1000, break_mainloop, loop);
101 g_main_loop_run (loop);
103 /* Now activate the audio pipeline */
104 gst_element_set_locked_state (bin, FALSE);
105 gst_element_set_state (p1, GST_STATE_PAUSED);
107 /* Normally our custom audiobin would send this message */
108 gst_element_post_message (asrc,
109 gst_message_new_clock_provide (GST_OBJECT (asrc), NULL, TRUE));
111 /* At this point a new clock is selected */
112 gst_element_set_state (p1, GST_STATE_PLAYING);
114 g_timeout_add (2 * 1000, break_mainloop, loop);
115 g_main_loop_run (loop);
117 gst_object_unref (pad);
118 gst_element_set_state (p1, GST_STATE_NULL);
119 gst_object_unref (p1);
124 #endif /* #ifndef GST_DISABLE_PARSE */
127 baseaudiosrc_suite (void)
129 Suite *s = suite_create ("baseaudiosrc");
130 TCase *tc_chain = tcase_create ("general");
133 tcase_set_timeout (tc_chain, 6);
134 suite_add_tcase (s, tc_chain);
136 #ifndef GST_DISABLE_PARSE
137 tcase_add_test (tc_chain, test_basetime_calculation);
144 main (int argc, char **argv)
148 Suite *s = baseaudiosrc_suite ();
149 SRunner *sr = srunner_create (s);
151 gst_check_init (&argc, &argv);
153 srunner_run_all (sr, CK_NORMAL);
154 nf = srunner_ntests_failed (sr);