Debian Codegraph @

tests/check/ges/uriclip.c

raw
1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "test-utils.h"
21 #include <ges/ges.h>
22 #include <gst/check/gstcheck.h>
23
24 /* This test uri will eventually have to be fixed */
25 #define TEST_URI "http://nowhere/blahblahblah"
26
27
28 static gchar *av_uri;
29 static gchar *image_uri;
30 GMainLoop *mainloop;
31
32 typedef struct _AssetUri
33 {
34 const gchar *uri;
35 GESAsset *asset;
36 } AssetUri;
37
38 static void
39 asset_created_cb (GObject * source, GAsyncResult * res, gpointer udata)
40 {
41 GList *tracks, *tmp;
42 GESAsset *asset;
43 GESLayer *layer;
44 GESUriClip *tlfs;
45
46 GError *error = NULL;
47
48 asset = ges_asset_request_finish (res, &error);
49 ASSERT_OBJECT_REFCOUNT (asset, "1 for us + for the cache + 1 taken "
50 "by g_task", 3);
51 fail_unless (error == NULL);
52 fail_if (asset == NULL);
53 fail_if (g_strcmp0 (ges_asset_get_id (asset), av_uri));
54
55 layer = GES_LAYER (g_async_result_get_user_data (res));
56 tlfs = GES_URI_CLIP (ges_layer_add_asset (layer,
57 asset, 0, 0, GST_CLOCK_TIME_NONE, GES_TRACK_TYPE_UNKNOWN));
58 fail_unless (GES_IS_URI_CLIP (tlfs));
59 fail_if (g_strcmp0 (ges_uri_clip_get_uri (tlfs), av_uri));
60 assert_equals_uint64 (_DURATION (tlfs), GST_SECOND);
61
62 fail_unless (ges_clip_get_supported_formats
63 (GES_CLIP (tlfs)) & GES_TRACK_TYPE_VIDEO);
64 fail_unless (ges_clip_get_supported_formats
65 (GES_CLIP (tlfs)) & GES_TRACK_TYPE_AUDIO);
66
67 tracks = ges_timeline_get_tracks (ges_layer_get_timeline (layer));
68 for (tmp = tracks; tmp; tmp = tmp->next) {
69 GList *trackelements = ges_track_get_elements (GES_TRACK (tmp->data));
70
71 assert_equals_int (g_list_length (trackelements), 1);
72 fail_unless (GES_IS_VIDEO_URI_SOURCE (trackelements->data)
73 || GES_IS_AUDIO_URI_SOURCE (trackelements->data));
74 g_list_free_full (trackelements, gst_object_unref);
75 }
76 g_list_free_full (tracks, gst_object_unref);
77
78 gst_object_unref (asset);
79 g_main_loop_quit (mainloop);
80 }
81
82 GST_START_TEST (test_filesource_basic)
83 {
84 GESTimeline *timeline;
85 GESLayer *layer;
86
87 mainloop = g_main_loop_new (NULL, FALSE);
88
89 ges_init ();
90
91 timeline = ges_timeline_new_audio_video ();
92 fail_unless (timeline != NULL);
93
94 layer = ges_layer_new ();
95 fail_unless (layer != NULL);
96 fail_unless (ges_timeline_add_layer (timeline, layer));
97
98 ges_asset_request_async (GES_TYPE_URI_CLIP,
99 av_uri, NULL, asset_created_cb, layer);
100
101 g_main_loop_run (mainloop);
102 g_main_loop_unref (mainloop);
103 gst_object_unref (timeline);
104
105 ges_deinit ();
106 }
107
108 GST_END_TEST;
109
110 static gboolean
111 create_asset (AssetUri * asset_uri)
112 {
113 asset_uri->asset =
114 GES_ASSET (ges_uri_clip_asset_request_sync (asset_uri->uri, NULL));
115 g_main_loop_quit (mainloop);
116
117 return FALSE;
118 }
119
120 GST_START_TEST (test_filesource_properties)
121 {
122 GESClip *clip;
123 GESTrack *track;
124 AssetUri asset_uri;
125 GESTimeline *timeline;
126 GESUriClipAsset *asset;
127 GESLayer *layer;
128 GESTrackElement *trackelement;
129
130 ges_init ();
131
132 track = ges_track_new (GES_TRACK_TYPE_AUDIO, gst_caps_ref (GST_CAPS_ANY));
133 fail_unless (track != NULL);
134
135 layer = ges_layer_new ();
136 fail_unless (layer != NULL);
137 timeline = ges_timeline_new ();
138 fail_unless (GES_IS_TIMELINE (timeline));
139 fail_unless (ges_timeline_add_layer (timeline, layer));
140 fail_unless (ges_timeline_add_track (timeline, track));
141 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
142
143 mainloop = g_main_loop_new (NULL, FALSE);
144 asset_uri.uri = av_uri;
145 /* Right away request the asset synchronously */
146 g_timeout_add (1, (GSourceFunc) create_asset, &asset_uri);
147 g_main_loop_run (mainloop);
148
149 asset = GES_URI_CLIP_ASSET (asset_uri.asset);
150 fail_unless (GES_IS_ASSET (asset));
151 clip = ges_layer_add_asset (layer, GES_ASSET (asset),
152 42, 12, 51, GES_TRACK_TYPE_AUDIO);
153 ges_timeline_commit (timeline);
154 assert_is_type (clip, GES_TYPE_URI_CLIP);
155 assert_equals_uint64 (_START (clip), 42);
156 assert_equals_uint64 (_DURATION (clip), 51);
157 assert_equals_uint64 (_INPOINT (clip), 12);
158
159 assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1);
160 trackelement = GES_CONTAINER_CHILDREN (clip)->data;
161 fail_unless (trackelement != NULL);
162 fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement) ==
163 GES_TIMELINE_ELEMENT (clip));
164 fail_unless (ges_track_element_get_track (trackelement) == track);
165
166 /* Check that trackelement has the same properties */
167 assert_equals_uint64 (_START (trackelement), 42);
168 assert_equals_uint64 (_DURATION (trackelement), 51);
169 assert_equals_uint64 (_INPOINT (trackelement), 12);
170
171 /* And let's also check that it propagated correctly to GNonLin */
172 nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 12,
173 51, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
174
175 /* Change more properties, see if they propagate */
176 g_object_set (clip, "start", (guint64) 420, "duration", (guint64) 510,
177 "in-point", (guint64) 120, NULL);
178 ges_timeline_commit (timeline);
179 assert_equals_uint64 (_START (clip), 420);
180 assert_equals_uint64 (_DURATION (clip), 510);
181 assert_equals_uint64 (_INPOINT (clip), 120);
182 assert_equals_uint64 (_START (trackelement), 420);
183 assert_equals_uint64 (_DURATION (trackelement), 510);
184 assert_equals_uint64 (_INPOINT (trackelement), 120);
185
186 /* And let's also check that it propagated correctly to GNonLin */
187 nle_object_check (ges_track_element_get_nleobject (trackelement), 420, 510,
188 120, 510, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0, TRUE);
189
190 /* Test mute support */
191 g_object_set (clip, "mute", TRUE, NULL);
192 ges_timeline_commit (timeline);
193 nle_object_check (ges_track_element_get_nleobject (trackelement), 420, 510,
194 120, 510, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0, FALSE);
195 g_object_set (clip, "mute", FALSE, NULL);
196 ges_timeline_commit (timeline);
197 nle_object_check (ges_track_element_get_nleobject (trackelement), 420, 510,
198 120, 510, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0, TRUE);
199
200 ges_container_remove (GES_CONTAINER (clip),
201 GES_TIMELINE_ELEMENT (trackelement));
202
203 gst_object_unref (asset);
204 gst_object_unref (timeline);
205
206 ges_deinit ();
207 }
208
209 GST_END_TEST;
210
211 GST_START_TEST (test_filesource_images)
212 {
213 GESClip *clip;
214 GESAsset *asset;
215 GESTrack *a, *v;
216 GESUriClip *uriclip;
217 AssetUri asset_uri;
218 GESTimeline *timeline;
219 GESLayer *layer;
220 GESTrackElement *track_element;
221
222 ges_init ();
223
224 a = GES_TRACK (ges_audio_track_new ());
225 v = GES_TRACK (ges_video_track_new ());
226
227 layer = ges_layer_new ();
228 fail_unless (layer != NULL);
229 timeline = ges_timeline_new ();
230 fail_unless (timeline != NULL);
231 fail_unless (ges_timeline_add_layer (timeline, layer));
232 fail_unless (ges_timeline_add_track (timeline, a));
233 fail_unless (ges_timeline_add_track (timeline, v));
234 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
235
236 mainloop = g_main_loop_new (NULL, FALSE);
237 /* Right away request the asset synchronously */
238 asset_uri.uri = image_uri;
239 g_timeout_add (1, (GSourceFunc) create_asset, &asset_uri);
240 g_main_loop_run (mainloop);
241
242 asset = asset_uri.asset;
243 fail_unless (GES_IS_ASSET (asset));
244 fail_unless (ges_uri_clip_asset_is_image (GES_URI_CLIP_ASSET (asset)));
245 uriclip = GES_URI_CLIP (ges_asset_extract (asset, NULL));
246 fail_unless (GES_IS_URI_CLIP (uriclip));
247 fail_unless (ges_clip_get_supported_formats (GES_CLIP (uriclip)) ==
248 GES_TRACK_TYPE_VIDEO);
249 clip = GES_CLIP (uriclip);
250 fail_unless (ges_uri_clip_is_image (uriclip));
251 ges_timeline_element_set_duration (GES_TIMELINE_ELEMENT (clip),
252 1 * GST_SECOND);
253
254 /* the returned track element should be an image source */
255 /* the clip should not create any TrackElement in the audio track */
256 ges_layer_add_clip (layer, GES_CLIP (clip));
257 assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1);
258 track_element = GES_CONTAINER_CHILDREN (clip)->data;
259 fail_unless (track_element != NULL);
260 fail_unless (GES_TIMELINE_ELEMENT_PARENT (track_element) ==
261 GES_TIMELINE_ELEMENT (clip));
262 fail_unless (ges_track_element_get_track (track_element) == v);
263 fail_unless (GES_IS_VIDEO_URI_SOURCE (track_element));
264
265 ASSERT_OBJECT_REFCOUNT (track_element, "1 in track, 1 in clip 2 in timeline",
266 3);
267
268 gst_object_unref (asset);
269 gst_object_unref (timeline);
270
271 ges_deinit ();
272 }
273
274 GST_END_TEST;
275
276
277 static Suite *
278 ges_suite (void)
279 {
280 Suite *s = suite_create ("ges-filesource");
281 TCase *tc_chain = tcase_create ("filesource");
282
283 suite_add_tcase (s, tc_chain);
284
285 tcase_add_test (tc_chain, test_filesource_basic);
286 tcase_add_test (tc_chain, test_filesource_images);
287 tcase_add_test (tc_chain, test_filesource_properties);
288
289 return s;
290 }
291
292 int
293 main (int argc, char **argv)
294 {
295 int nf;
296
297 Suite *s;
298
299 gst_check_init (&argc, &argv);
300
301 s = ges_suite ();
302
303 av_uri = ges_test_get_audio_video_uri ();
304 image_uri = ges_test_get_image_uri ();
305
306 nf = gst_check_run_suite (s, "ges", __FILE__);
307
308 g_free (av_uri);
309 g_free (image_uri);
310
311 return nf;
312 }