Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / check / pipelines / basetime.c
1 /* GStreamer
2  *
3  * unit test for audiotestsrc basetime handling
4  *
5  * Copyright (C) 2009 Maemo Multimedia <multimedia at maemo dot org>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gst/check/gstcheck.h>
28
29 #ifndef GST_DISABLE_PARSE
30
31 static GstClockTime old_ts = GST_CLOCK_TIME_NONE;
32
33 static gboolean
34 break_mainloop (gpointer data)
35 {
36   GMainLoop *loop;
37
38   loop = (GMainLoop *) data;
39   g_main_loop_quit (loop);
40
41   return FALSE;
42 }
43
44 static gboolean
45 buffer_probe_cb (GstPad * pad, GstBuffer * buffer)
46 {
47   if (old_ts != GST_CLOCK_TIME_NONE) {
48     fail_unless (GST_BUFFER_TIMESTAMP (buffer) != old_ts,
49         "Two buffers had same timestamp");
50   }
51   old_ts = GST_BUFFER_TIMESTAMP (buffer);
52
53   return TRUE;
54 }
55
56 GST_START_TEST (test_basetime_calculation)
57 {
58   GstElement *p1, *bin;
59   GstElement *asrc, *asink;
60   GstPad *pad;
61   GMainLoop *loop;
62
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")))
66     return;
67
68   loop = g_main_loop_new (NULL, FALSE);
69
70   /* The "main" pipeline */
71   p1 = gst_parse_launch ("fakesrc ! fakesink", NULL);
72   fail_if (p1 == NULL);
73
74   /* Create a sub-bin that is activated only in "certain situations" */
75   asrc = gst_element_factory_make (DEFAULT_AUDIOSRC, NULL);
76   if (asrc == NULL) {
77     GST_WARNING ("Cannot run test. test audio source %s not available",
78         DEFAULT_AUDIOSRC);
79     gst_element_set_state (p1, GST_STATE_NULL);
80     gst_object_unref (p1);
81     return;
82   }
83   asink = gst_element_factory_make ("fakesink", NULL);
84
85   bin = gst_bin_new ("audiobin");
86   gst_bin_add_many (GST_BIN (bin), asrc, asink, NULL);
87   gst_element_link (asrc, asink);
88
89   gst_bin_add (GST_BIN (p1), bin);
90   gst_element_set_state (p1, GST_STATE_READY);
91
92   pad = gst_element_get_static_pad (asink, "sink");
93   fail_unless (pad != NULL, "Could not get pad out of sink");
94
95   gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL);
96   gst_element_set_locked_state (bin, TRUE);
97
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);
102
103   /* Now activate the audio pipeline */
104   gst_element_set_locked_state (bin, FALSE);
105   gst_element_set_state (p1, GST_STATE_PAUSED);
106
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));
110
111   /* At this point a new clock is selected */
112   gst_element_set_state (p1, GST_STATE_PLAYING);
113
114   g_timeout_add (2 * 1000, break_mainloop, loop);
115   g_main_loop_run (loop);
116
117   gst_object_unref (pad);
118   gst_element_set_state (p1, GST_STATE_NULL);
119   gst_object_unref (p1);
120 }
121
122 GST_END_TEST;
123
124 #endif /* #ifndef GST_DISABLE_PARSE */
125
126 static Suite *
127 baseaudiosrc_suite (void)
128 {
129   Suite *s = suite_create ("baseaudiosrc");
130   TCase *tc_chain = tcase_create ("general");
131
132   /* timeout 6 sec */
133   tcase_set_timeout (tc_chain, 6);
134   suite_add_tcase (s, tc_chain);
135
136 #ifndef GST_DISABLE_PARSE
137   tcase_add_test (tc_chain, test_basetime_calculation);
138 #endif
139
140   return s;
141 }
142
143 int
144 main (int argc, char **argv)
145 {
146   int nf;
147
148   Suite *s = baseaudiosrc_suite ();
149   SRunner *sr = srunner_create (s);
150
151   gst_check_init (&argc, &argv);
152
153   srunner_run_all (sr, CK_NORMAL);
154   nf = srunner_ntests_failed (sr);
155   srunner_free (sr);
156
157   return nf;
158 }