1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */
5 * Copyright (C) 2013 Thibault Saunier <tsaunier@gnome.org>
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.
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.
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/>.";
21 #include "test-utils.h"
23 #include <gst/check/gstcheck.h>
25 #include <ges/ges-smart-adder.h>
27 static GMainLoop *main_loop;
29 GST_START_TEST (simple_smart_adder_test)
31 GstPad *requested_pad;
32 GstPadTemplate *template = NULL;
33 GESTrack *track = GES_TRACK (ges_audio_track_new ());
34 GstElement *smart_adder = ges_smart_adder_new (track);
36 fail_unless (GES_IS_SMART_ADDER (smart_adder));
37 fail_unless (GST_IS_ELEMENT (smart_adder));
38 fail_unless (GST_IS_ELEMENT (GES_SMART_ADDER (smart_adder)->adder));
39 fail_unless (GST_IS_PAD (GES_SMART_ADDER (smart_adder)->srcpad));
42 gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (smart_adder),
44 fail_unless (template != NULL);
45 requested_pad = gst_element_request_pad (GST_ELEMENT (smart_adder),
46 template, NULL, NULL);
47 fail_unless (GST_IS_PAD (requested_pad));
49 gst_object_unref (smart_adder);
50 gst_object_unref (track);
56 message_received_cb (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
58 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
59 GST_MESSAGE_SRC (message), message);
60 switch (GST_MESSAGE_TYPE (message)) {
62 /* we should check if we really finished here */
63 GST_WARNING ("Got an EOS");
64 g_main_loop_quit (main_loop);
66 case GST_MESSAGE_SEGMENT_START:
67 case GST_MESSAGE_SEGMENT_DONE:
68 /* We shouldn't see any segement messages, since we didn't do a segment seek */
69 GST_WARNING ("Saw a Segment start/stop");
71 g_main_loop_quit (main_loop);
73 case GST_MESSAGE_ERROR:
74 fail_error_message (message);
75 g_main_loop_quit (main_loop);
81 GST_START_TEST (simple_audio_mixed_with_pipeline)
87 GESLayer *layer, *layer1;
88 GESTrack *track = GES_TRACK (ges_audio_track_new ());
89 GESTimeline *timeline = ges_timeline_new ();
90 GESTimelinePipeline *pipeline = ges_test_create_pipeline (timeline);
92 ges_timeline_add_track (timeline, track);
93 layer = ges_timeline_append_layer (timeline);
94 layer1 = ges_timeline_append_layer (timeline);
96 asset = GES_ASSET (ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL));
98 GST_DEBUG ("Setting volume on the layer");
99 ges_meta_container_set_float (GES_META_CONTAINER (layer), GES_META_VOLUME,
102 tmpclip = ges_layer_add_asset (layer, asset, 0, 0, 1 * GST_SECOND,
103 GES_TRACK_TYPE_AUDIO);
104 ges_audio_test_source_set_volume (GES_CONTAINER_CHILDREN (tmpclip)->data,
106 ges_audio_test_source_set_freq (GES_CONTAINER_CHILDREN (tmpclip)->data, 550);
108 tmpclip = ges_layer_add_asset (layer1, asset, 0, 0, 2 * GST_SECOND,
109 GES_TRACK_TYPE_AUDIO);
111 ges_audio_test_source_set_volume (GES_CONTAINER_CHILDREN (tmpclip)->data, 1);
113 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
114 main_loop = g_main_loop_new (NULL, FALSE);
116 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
117 g_signal_connect (bus, "message", (GCallback) message_received_cb, pipeline);
118 fail_if (gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING)
119 == GST_STATE_CHANGE_FAILURE);
120 message = gst_bus_timed_pop_filtered (bus, 5 * GST_SECOND,
121 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
123 if (message == NULL) {
124 fail_unless ("No message after 5 seconds" == NULL);
126 } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR)
127 fail_error_message (message);
129 GST_INFO ("running main loop");
130 g_main_loop_run (main_loop);
131 g_main_loop_unref (main_loop);
134 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
135 gst_object_unref (pipeline);
140 GST_START_TEST (audio_video_mixed_with_pipeline)
146 GESLayer *layer, *layer1;
147 GESTrack *track = GES_TRACK (ges_video_track_new ());
148 GESTrack *track_audio = GES_TRACK (ges_audio_track_new ());
149 GESTimeline *timeline = ges_timeline_new ();
150 GESTimelinePipeline *pipeline = ges_test_create_pipeline (timeline);
152 ges_timeline_add_track (timeline, track);
153 ges_timeline_add_track (timeline, track_audio);
154 layer = ges_timeline_append_layer (timeline);
155 layer1 = ges_timeline_append_layer (timeline);
157 asset = GES_ASSET (ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL));
160 ges_layer_add_asset (layer, asset, 0 * GST_SECOND, 0, 2 * GST_SECOND,
161 GES_TRACK_TYPE_UNKNOWN);
163 ges_test_clip_set_vpattern (GES_TEST_CLIP (tmpclip), 18);
166 ges_layer_add_asset (layer1, asset, 1 * GST_SECOND, 0, 5 * GST_SECOND,
167 GES_TRACK_TYPE_UNKNOWN);
169 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
170 main_loop = g_main_loop_new (NULL, FALSE);
172 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
173 g_signal_connect (bus, "message", (GCallback) message_received_cb, pipeline);
174 fail_if (gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING)
175 == GST_STATE_CHANGE_FAILURE);
177 message = gst_bus_timed_pop_filtered (bus, 5 * GST_SECOND,
178 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
180 if (message == NULL) {
181 fail_unless ("No message after 5 seconds" == NULL);
183 } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR)
184 fail_error_message (message);
186 GST_INFO ("running main loop");
187 g_main_loop_run (main_loop);
188 g_main_loop_unref (main_loop);
191 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
192 gst_object_unref (pipeline);
200 Suite *s = suite_create ("Smart mixers");
201 TCase *tc_chain = tcase_create ("smart-mixers");
203 suite_add_tcase (s, tc_chain);
205 tcase_add_test (tc_chain, simple_smart_adder_test);
206 tcase_add_test (tc_chain, simple_audio_mixed_with_pipeline);
207 tcase_add_test (tc_chain, audio_video_mixed_with_pipeline);
213 main (int argc, char **argv)
217 Suite *s = ges_suite ();
218 SRunner *sr = srunner_create (s);
220 gst_check_init (&argc, &argv);
223 srunner_run_all (sr, CK_NORMAL);
224 nf = srunner_ntests_failed (sr);