tests:ges: Take TIMEOUT_FACTOR into account
[platform/upstream/gstreamer.git] / subprojects / gst-editing-services / tests / check / ges / mixers.c
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-  */
2 /*
3  * gst-editing-services
4  *
5  * Copyright (C) 2013 Thibault Saunier <tsaunier@gnome.org>
6  *
7  * gst-editing-services is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published
9  * by the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * gst-editing-services is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.";
19  *
20  */
21 #include "test-utils.h"
22 #include <ges/ges.h>
23 #include <gst/check/gstcheck.h>
24
25 #include <ges/ges-smart-adder.h>
26
27 static GMainLoop *main_loop;
28
29 GST_START_TEST (simple_smart_adder_test)
30 {
31   GstPad *requested_pad;
32   GstPadTemplate *template = NULL;
33   GESTrack *track;
34   GstElement *smart_adder;
35
36   ges_init ();
37
38   track = GES_TRACK (ges_audio_track_new ());
39   smart_adder = ges_smart_adder_new (track);
40
41   fail_unless (GES_IS_SMART_ADDER (smart_adder));
42   fail_unless (GST_IS_ELEMENT (smart_adder));
43   fail_unless (GST_IS_ELEMENT (GES_SMART_ADDER (smart_adder)->adder));
44   fail_unless (GST_IS_PAD (GES_SMART_ADDER (smart_adder)->srcpad));
45
46   template =
47       gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (smart_adder),
48       "sink_%u");
49   fail_unless (template != NULL);
50   requested_pad = gst_element_request_pad (GST_ELEMENT (smart_adder),
51       template, NULL, NULL);
52   fail_unless (GST_IS_PAD (requested_pad));
53
54   gst_object_unref (requested_pad);
55   gst_object_unref (smart_adder);
56   gst_object_unref (track);
57
58   ges_deinit ();
59 }
60
61 GST_END_TEST;
62
63 static void
64 message_received_cb (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
65 {
66   GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
67       GST_MESSAGE_SRC (message), message);
68   switch (GST_MESSAGE_TYPE (message)) {
69     case GST_MESSAGE_EOS:
70       /* we should check if we really finished here */
71       GST_WARNING ("Got an EOS");
72       g_main_loop_quit (main_loop);
73       break;
74     case GST_MESSAGE_SEGMENT_START:
75     case GST_MESSAGE_SEGMENT_DONE:
76       /* We shouldn't see any segement messages, since we didn't do a segment seek */
77       GST_WARNING ("Saw a Segment start/stop");
78       fail_if (TRUE);
79       g_main_loop_quit (main_loop);
80       break;
81     case GST_MESSAGE_ERROR:
82       fail_error_message (message);
83       g_main_loop_quit (main_loop);
84     default:
85       break;
86   }
87 }
88
89 GST_START_TEST (simple_audio_mixed_with_pipeline)
90 {
91   GstBus *bus;
92   GESAsset *asset;
93   GESClip *tmpclip;
94   GstMessage *message;
95   GESLayer *layer, *layer1;
96   GESTrack *track;
97   GESTimeline *timeline;
98   GESPipeline *pipeline;
99   GstClockTime timeout = 5 * GST_SECOND;
100   const gchar *timeout_factor_str = g_getenv ("TIMEOUT_FACTOR");
101
102   ges_init ();
103
104   track = GES_TRACK (ges_audio_track_new ());
105   timeline = ges_timeline_new ();
106   pipeline = ges_test_create_pipeline (timeline);
107
108   ges_timeline_add_track (timeline, track);
109   layer = ges_timeline_append_layer (timeline);
110   layer1 = ges_timeline_append_layer (timeline);
111
112   asset = GES_ASSET (ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL));
113
114   GST_DEBUG ("Setting volume on the layer");
115   ges_meta_container_set_float (GES_META_CONTAINER (layer), GES_META_VOLUME,
116       1.5);
117
118   tmpclip = ges_layer_add_asset (layer, asset, 0, 0, 1 * GST_SECOND,
119       GES_TRACK_TYPE_AUDIO);
120   ges_audio_test_source_set_volume (GES_CONTAINER_CHILDREN (tmpclip)->data,
121       1.0);
122   ges_audio_test_source_set_freq (GES_CONTAINER_CHILDREN (tmpclip)->data, 550);
123
124   tmpclip = ges_layer_add_asset (layer1, asset, 0, 0, 2 * GST_SECOND,
125       GES_TRACK_TYPE_AUDIO);
126   g_object_unref (asset);
127
128   ges_audio_test_source_set_volume (GES_CONTAINER_CHILDREN (tmpclip)->data, 1);
129
130   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
131   main_loop = g_main_loop_new (NULL, FALSE);
132
133   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
134   g_signal_connect (bus, "message", (GCallback) message_received_cb, pipeline);
135   fail_if (gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING)
136       == GST_STATE_CHANGE_FAILURE);
137   if (timeout_factor_str) {
138     gint factor = g_ascii_strtoll (timeout_factor_str, NULL, 10);
139     if (factor)
140       timeout *= factor;
141   }
142   message = gst_bus_timed_pop_filtered (bus, timeout,
143       GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
144
145   if (message == NULL) {
146     fail_unless ("Timed out" == NULL);
147     goto done;
148   } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR)
149     fail_error_message (message);
150
151   gst_message_unref (message);
152   GST_INFO ("running main loop");
153   g_main_loop_run (main_loop);
154   g_main_loop_unref (main_loop);
155
156 done:
157   gst_bus_remove_signal_watch (bus);
158   gst_object_unref (bus);
159   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
160   gst_object_unref (pipeline);
161
162   ges_deinit ();
163 }
164
165 GST_END_TEST;
166
167 GST_START_TEST (audio_video_mixed_with_pipeline)
168 {
169   GstBus *bus;
170   GESAsset *asset;
171   GESClip *tmpclip;
172   GstMessage *message;
173   GESLayer *layer, *layer1;
174   GESTrack *track;
175   GESTrack *track_audio;
176   GESTimeline *timeline;
177   GESPipeline *pipeline;
178
179   ges_init ();
180
181   track = GES_TRACK (ges_video_track_new ());
182   track_audio = GES_TRACK (ges_audio_track_new ());
183   timeline = ges_timeline_new ();
184   pipeline = ges_test_create_pipeline (timeline);
185
186   ges_timeline_add_track (timeline, track);
187   ges_timeline_add_track (timeline, track_audio);
188   layer = ges_timeline_append_layer (timeline);
189   layer1 = ges_timeline_append_layer (timeline);
190
191   asset = GES_ASSET (ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL));
192
193   tmpclip =
194       ges_layer_add_asset (layer, asset, 0 * GST_SECOND, 0, 2 * GST_SECOND,
195       GES_TRACK_TYPE_UNKNOWN);
196
197   ges_test_clip_set_vpattern (GES_TEST_CLIP (tmpclip), 18);
198
199   tmpclip =
200       ges_layer_add_asset (layer1, asset, 1 * GST_SECOND, 0, 5 * GST_SECOND,
201       GES_TRACK_TYPE_UNKNOWN);
202   g_object_unref (asset);
203
204   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
205   main_loop = g_main_loop_new (NULL, FALSE);
206
207   gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
208   g_signal_connect (bus, "message", (GCallback) message_received_cb, pipeline);
209   fail_if (gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING)
210       == GST_STATE_CHANGE_FAILURE);
211
212   message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
213       GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
214
215   if (message == NULL) {
216     fail_unless ("No message after 5 seconds" == NULL);
217     goto done;
218   } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR)
219     fail_error_message (message);
220
221   gst_message_unref (message);
222   GST_INFO ("running main loop");
223   g_main_loop_run (main_loop);
224   g_main_loop_unref (main_loop);
225
226 done:
227   gst_bus_remove_signal_watch (bus);
228   gst_object_unref (bus);
229   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
230   gst_object_unref (pipeline);
231
232   ges_deinit ();
233 }
234
235 GST_END_TEST;
236
237 static Suite *
238 ges_suite (void)
239 {
240   Suite *s = suite_create ("Smart mixers");
241   TCase *tc_chain = tcase_create ("smart-mixers");
242
243   suite_add_tcase (s, tc_chain);
244
245   tcase_add_test (tc_chain, simple_smart_adder_test);
246   tcase_add_test (tc_chain, simple_audio_mixed_with_pipeline);
247   tcase_add_test (tc_chain, audio_video_mixed_with_pipeline);
248
249   return s;
250 }
251
252 GST_CHECK_MAIN (ges);