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 GstClockTime new_ts = GST_BUFFER_TIMESTAMP (buffer);
49 GST_LOG ("ts = %" GST_TIME_FORMAT, GST_TIME_ARGS (new_ts));
50 if (old_ts != GST_CLOCK_TIME_NONE) {
51 fail_unless (new_ts != old_ts,
52 "Two buffers had same timestamp: %" GST_TIME_FORMAT,
53 GST_TIME_ARGS (old_ts));
60 GST_START_TEST (test_basetime_calculation)
63 GstElement *asrc, *asink;
67 loop = g_main_loop_new (NULL, FALSE);
69 /* The "main" pipeline */
70 p1 = gst_parse_launch ("fakesrc ! fakesink", NULL);
73 /* Create a sub-bin that is activated only in "certain situations" */
74 asrc = gst_element_factory_make ("audiotestsrc", NULL);
76 GST_WARNING ("Cannot run test. 'audiotestsrc' not available");
77 gst_element_set_state (p1, GST_STATE_NULL);
78 gst_object_unref (p1);
81 asink = gst_element_factory_make ("fakesink", NULL);
83 bin = gst_bin_new ("audiobin");
84 gst_bin_add_many (GST_BIN (bin), asrc, asink, NULL);
85 gst_element_link (asrc, asink);
87 gst_bin_add (GST_BIN (p1), bin);
88 gst_element_set_state (p1, GST_STATE_READY);
90 pad = gst_element_get_static_pad (asink, "sink");
91 fail_unless (pad != NULL, "Could not get pad out of sink");
93 gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL);
94 gst_element_set_locked_state (bin, TRUE);
96 /* Run main pipeline first */
97 gst_element_set_state (p1, GST_STATE_PLAYING);
98 g_timeout_add (2 * 1000, break_mainloop, loop);
99 g_main_loop_run (loop);
101 /* Now activate the audio pipeline */
102 gst_element_set_locked_state (bin, FALSE);
103 gst_element_set_state (p1, GST_STATE_PAUSED);
105 /* Normally our custom audiobin would send this message */
106 gst_element_post_message (asrc,
107 gst_message_new_clock_provide (GST_OBJECT (asrc), NULL, TRUE));
109 /* At this point a new clock is selected */
110 gst_element_set_state (p1, GST_STATE_PLAYING);
112 g_timeout_add (2 * 1000, break_mainloop, loop);
113 g_main_loop_run (loop);
115 gst_object_unref (pad);
116 gst_element_set_state (p1, GST_STATE_NULL);
117 gst_object_unref (p1);
119 g_main_loop_unref (loop);
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);