2 * Gstreamer Editing Services
4 * Copyright (C) <2012> Thibault Saunier <thibault.saunier@collabora.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include "test-utils.h"
25 typedef struct _DestroyedObjectStruct
29 } DestroyedObjectStruct;
32 ges_test_get_audio_only_uri (void)
35 GFile *cfile, *fdir, *f_audio_only;
37 cfile = g_file_new_for_path (__FILE__);
38 fdir = g_file_get_parent (cfile);
40 f_audio_only = g_file_get_child (fdir, "audio_only.ogg");
41 uri = g_file_get_uri (f_audio_only);
43 gst_object_unref (cfile);
44 gst_object_unref (fdir);
45 gst_object_unref (f_audio_only);
51 ges_test_get_audio_video_uri (void)
53 return ges_test_file_uri ("audio_video.ogg");
57 ges_test_get_image_uri (void)
59 return ges_test_file_uri ("image.png");
63 ges_test_file_uri (const gchar * filename)
67 path = g_build_filename (GES_TEST_FILES_PATH, filename, NULL);
68 uri = gst_filename_to_uri (path, NULL);
76 ges_test_create_pipeline (GESTimeline * timeline)
78 GESPipeline *pipeline;
80 pipeline = ges_pipeline_new ();
81 fail_unless (ges_pipeline_set_timeline (pipeline, timeline));
83 g_object_set (pipeline, "audio-sink", gst_element_factory_make ("fakesink",
84 "test-audiofakesink"), "video-sink",
85 gst_element_factory_make ("fakesink", "test-videofakesink"), NULL);
91 ges_test_file_name (const gchar * filename)
93 return g_strjoin ("/", "file:/", g_get_current_dir (), filename, NULL);
97 ges_generate_test_file_audio_video (const gchar * filedest,
98 const gchar * audio_enc,
99 const gchar * video_enc,
100 const gchar * mux, const gchar * video_pattern, const gchar * audio_wave)
102 GError *error = NULL;
103 GstElement *pipeline;
107 gboolean done = FALSE;
108 gboolean ret = FALSE;
110 if (g_file_test (filedest, G_FILE_TEST_EXISTS)) {
111 GST_INFO ("The file %s already existed.", filedest);
115 pipeline_str = g_strdup_printf ("audiotestsrc num-buffers=430 wave=%s "
116 "%c %s ! %s name=m ! filesink location= %s/%s "
117 "videotestsrc pattern=%s num-buffers=300 ! %s ! m.",
119 audio_enc ? '!' : ' ',
120 audio_enc ? audio_enc : "",
121 mux, g_get_current_dir (), filedest, video_pattern, video_enc);
123 pipeline = gst_parse_launch (pipeline_str, &error);
125 if (pipeline == NULL)
128 g_free (pipeline_str);
130 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
131 gst_bus_add_signal_watch (bus);
133 gst_element_set_state (pipeline, GST_STATE_PLAYING);
136 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_CLOCK_TIME_NONE);
137 if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS) {
140 } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
144 gst_message_parse_error (message, &err, &debug);
147 GST_ERROR ("Got error %s from %s fron the bus while generation: %s"
148 "debug infos: %s", GST_OBJECT_NAME (message->src), err->message,
149 debug ? debug : "none", filedest);
150 g_clear_error (&err);
155 gst_bus_remove_signal_watch (bus);
156 gst_object_unref (bus);
158 gst_element_set_state (pipeline, GST_STATE_NULL);
159 gst_object_unref (pipeline);
165 weak_notify (DestroyedObjectStruct * destroyed, GObject ** object)
167 destroyed->destroyed = TRUE;
171 check_destroyed (GObject * object_to_unref, GObject * first_object, ...)
174 GList *objs = NULL, *tmp;
175 DestroyedObjectStruct *destroyed = g_slice_new0 (DestroyedObjectStruct);
177 destroyed->object = object_to_unref;
178 g_object_weak_ref (object_to_unref, (GWeakNotify) weak_notify, destroyed);
179 objs = g_list_prepend (objs, destroyed);
184 object = first_object;
186 va_start (varargs, first_object);
188 destroyed = g_slice_new0 (DestroyedObjectStruct);
189 destroyed->object = object;
190 g_object_weak_ref (object, (GWeakNotify) weak_notify, destroyed);
191 objs = g_list_prepend (objs, destroyed);
192 object = va_arg (varargs, GObject *);
196 gst_object_unref (object_to_unref);
198 for (tmp = objs; tmp; tmp = tmp->next) {
199 fail_unless (((DestroyedObjectStruct *) tmp->data)->destroyed == TRUE,
200 "%p is not destroyed", ((DestroyedObjectStruct *) tmp->data)->object);
201 g_slice_free (DestroyedObjectStruct, tmp->data);
208 my_bus_callback (GstBus * bus, GstMessage * message, GMainLoop * loop)
210 switch (GST_MESSAGE_TYPE (message)) {
211 case GST_MESSAGE_ERROR:{
215 gst_message_parse_error (message, &err, &debug);
217 g_assert_no_error (err);
220 g_main_loop_quit (loop);
223 case GST_MESSAGE_EOS:
225 g_main_loop_quit (loop);
228 /* unhandled message */
235 play_timeline (GESTimeline * timeline)
238 GESPipeline *pipeline;
239 GMainLoop *loop = g_main_loop_new (NULL, FALSE);
241 ges_timeline_commit (timeline);
242 pipeline = ges_pipeline_new ();
244 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
245 gst_bus_add_watch (bus, (GstBusFunc) my_bus_callback, loop);
246 gst_object_unref (bus);
248 ges_pipeline_set_timeline (pipeline, timeline);
249 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
250 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, -1);
252 g_main_loop_run (loop);
254 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
255 gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, -1);
257 gst_object_unref (pipeline);
263 ges_test_get_tmp_uri (const gchar * filename)
265 gchar *location, *uri;
267 location = g_build_filename (g_get_tmp_dir (), filename, NULL);
269 uri = g_strconcat ("file://", location, NULL);