Debian Codegraph @

tests/check/ges/test-utils.h

raw
1 /**
2 * Gstreamer Editing Services
3 *
4 * Copyright (C) <2012> Thibault Saunier <[email protected]>
5 *
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.
10 *
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.
15 *
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.
20 */
21 #pragma once
22
23 #include <ges/ges.h>
24 #include <gst/check/gstcheck.h>
25 #include "../../../ges/ges-internal.h"
26
27 GESPipeline * ges_test_create_pipeline (GESTimeline *timeline);
28 /* The first 2 NLE priorities are used for:
29 * 0- The Mixing element
30 * 1- The Gaps
31 */
32 #define MIN_NLE_PRIO 2
33 #define TRANSITIONS_HEIGHT 1
34 #define LAYER_HEIGHT 1000
35
36 gchar * ges_test_get_tmp_uri (const gchar * filename);
37 gchar * ges_test_get_audio_only_uri (void);
38 gchar * ges_test_get_audio_video_uri (void);
39 gchar * ges_test_get_image_uri (void);
40 gchar * ges_test_file_uri (const gchar *filename);
41
42 void check_destroyed (GObject *object_to_unref, GObject *first_object, ...) G_GNUC_NULL_TERMINATED;
43 gchar * ges_test_file_name (const gchar *filename);
44 gboolean
45 ges_generate_test_file_audio_video (const gchar * filedest,
46 const gchar * audio_enc,
47 const gchar * video_enc,
48 const gchar * mux, const gchar * video_pattern, const gchar * audio_wave);
49 gboolean
50 play_timeline (GESTimeline * timeline);
51
52 GParamSpec **
53 append_children_properties (GParamSpec ** list, GESTimelineElement * element, guint * num_props);
54 void
55 free_children_properties (GParamSpec ** list, guint num_props);
56
57 #define nle_object_check(nleobj, start, duration, mstart, mduration, priority, active) { \
58 guint64 pstart, inpoint; \
59 gint64 pdur; \
60 guint pprio; \
61 gboolean pact; \
62 g_object_get (nleobj, "start", &pstart, "duration", &pdur, \
63 "inpoint", &inpoint, "priority", &pprio, "active", &pact, \
64 NULL); \
65 assert_equals_uint64 (pstart, start); \
66 assert_equals_int64 (pdur, duration); \
67 assert_equals_uint64 (inpoint, mstart); \
68 assert_equals_int (pprio, priority); \
69 assert_equals_int (pact, active); \
70 }
71
72 /* copied from nle */
73 #define fail_error_message(msg) \
74 G_STMT_START { \
75 GError *error; \
76 gst_message_parse_error(msg, &error, NULL); \
77 fail_unless(FALSE, "Error Message from %s : %s", \
78 GST_OBJECT_NAME (GST_MESSAGE_SRC(msg)), error->message); \
79 g_error_free (error); \
80 } G_STMT_END;
81
82 #define assert_is_type(object, type) \
83 G_STMT_START { \
84 fail_unless (g_type_is_a(G_OBJECT_TYPE(object), type), \
85 "%s is not a %s", G_OBJECT_TYPE_NAME(object), \
86 g_type_name (type)); \
87 } G_STMT_END;
88
89 #define _START(obj) GES_TIMELINE_ELEMENT_START (obj)
90 #define _DURATION(obj) GES_TIMELINE_ELEMENT_DURATION (obj)
91 #define _INPOINT(obj) GES_TIMELINE_ELEMENT_INPOINT (obj)
92 #define _MAX_DURATION(obj) GES_TIMELINE_ELEMENT_MAX_DURATION (obj)
93 #define _PRIORITY(obj) GES_TIMELINE_ELEMENT_PRIORITY (obj)
94 #ifndef _END
95 #define _END(obj) (_START(obj) + _DURATION(obj))
96 #endif
97
98 void ges_test_check_object_props (const gchar * file, gint line,
99 gpointer element, GstClockTime start, GstClockTime inpoint,
100 GstClockTime duration, GstClockTime max_duration,
101 gboolean check_max_duration);
102
103 #define CHECK_OBJECT_PROPS(obj, start, inpoint, duration) \
104 ges_test_check_object_props (__FILE__, __LINE__, obj, start, inpoint, \
105 duration, GST_CLOCK_TIME_NONE, FALSE)
106
107 #define CHECK_OBJECT_PROPS_MAX(obj, start, inpoint, duration, max_duration) \
108 ges_test_check_object_props (__FILE__, __LINE__, obj, start, inpoint, \
109 duration, max_duration, TRUE)
110
111 #define __assert_timeline_element_set(obj, prop, val) \
112 fail_unless (ges_timeline_element_set_ ## prop ( \
113 GES_TIMELINE_ELEMENT (obj), val), "Could not set the " # prop \
114 " of " #obj "(%s) to " #val, GES_TIMELINE_ELEMENT_NAME (obj))
115
116 #define __fail_timeline_element_set(obj, prop, val) \
117 fail_if (ges_timeline_element_set_ ## prop ( \
118 GES_TIMELINE_ELEMENT (obj), val), "Setting the " # prop \
119 " of " #obj "(%s) to " #val " did not fail as expected", \
120 GES_TIMELINE_ELEMENT_NAME (obj))
121
122
123 #define assert_set_start(obj, val) \
124 __assert_timeline_element_set (obj, start, val)
125
126 #define assert_set_duration(obj, val) \
127 __assert_timeline_element_set (obj, duration, val)
128
129 #define assert_set_inpoint(obj, val) \
130 __assert_timeline_element_set (obj, inpoint, val)
131
132 #define assert_set_max_duration(obj, val) \
133 __assert_timeline_element_set (obj, max_duration, val)
134
135
136 #define assert_fail_set_start(obj, val) \
137 __fail_timeline_element_set (obj, start, val)
138
139 #define assert_fail_set_duration(obj, val) \
140 __fail_timeline_element_set (obj, duration, val)
141
142 #define assert_fail_set_inpoint(obj, val) \
143 __fail_timeline_element_set (obj, inpoint, val)
144
145 #define assert_fail_set_max_duration(obj, val) \
146 __fail_timeline_element_set (obj, max_duration, val)
147
148
149 #define assert_num_in_track(track, val) \
150 { \
151 GList *tmp = ges_track_get_elements (track); \
152 guint length = g_list_length (tmp); \
153 fail_unless (length == val, "Track %" GST_PTR_FORMAT \
154 " contains %u track elements, rather than %u", track, length, val); \
155 g_list_free_full (tmp, gst_object_unref); \
156 }
157
158 #define assert_num_children(clip, cmp) \
159 { \
160 guint num_children = g_list_length (GES_CONTAINER_CHILDREN (clip)); \
161 fail_unless (cmp == num_children, \
162 "clip %s contains %u children rather than %u", \
163 GES_TIMELINE_ELEMENT_NAME (clip), num_children, cmp); \
164 }
165
166 /* assert that the time property (start, duration or in-point) is the
167 * same as @cmp for the clip and all its children */
168 #define assert_clip_children_time_val(clip, property, cmp) \
169 { \
170 GList *tmp; \
171 GstClockTime read_val; \
172 gchar *name = GES_TIMELINE_ELEMENT (clip)->name; \
173 gboolean is_inpoint = (g_strcmp0 (property, "in-point") == 0); \
174 g_object_get (clip, property, &read_val, NULL); \
175 fail_unless (read_val == cmp, "The %s property for clip %s is %" \
176 GST_TIME_FORMAT ", rather than the expected value of %" \
177 GST_TIME_FORMAT, property, name, GST_TIME_ARGS (read_val), \
178 GST_TIME_ARGS (cmp)); \
179 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp != NULL; \
180 tmp = tmp->next) { \
181 GESTimelineElement *child = tmp->data; \
182 g_object_get (child, property, &read_val, NULL); \
183 if (!is_inpoint || ges_track_element_has_internal_source ( \
184 GES_TRACK_ELEMENT (child))) \
185 fail_unless (read_val == cmp, "The %s property for the child %s " \
186 "of clip %s is %" GST_TIME_FORMAT ", rather than the expected" \
187 " value of %" GST_TIME_FORMAT, property, child->name, name, \
188 GST_TIME_ARGS (read_val), GST_TIME_ARGS (cmp)); \
189 else \
190 fail_unless (read_val == 0, "The %s property for the child %s " \
191 "of clip %s is %" GST_TIME_FORMAT ", rather than 0", \
192 property, child->name, name, GST_TIME_ARGS (read_val)); \
193 } \
194 }
195
196 #define check_layer(clip, layer_prio) { \
197 fail_unless (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip) == (layer_prio), \
198 "%s in layer %d instead of %d", GES_TIMELINE_ELEMENT_NAME (clip), \
199 GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip), layer_prio); \
200 }
201
202 #define assert_layer(clip, layer) \
203 { \
204 GESLayer *tmp_layer = ges_clip_get_layer (GES_CLIP (clip)); \
205 fail_unless (tmp_layer == GES_LAYER (layer), "clip %s belongs to " \
206 "layer %u (timeline %" GST_PTR_FORMAT ") rather than layer %u " \
207 "(timeline %" GST_PTR_FORMAT ")", \
208 tmp_layer ? ges_layer_get_priority (tmp_layer) : 0, \
209 tmp_layer ? tmp_layer->timeline : NULL, \
210 layer ? ges_layer_get_priority (GES_LAYER (layer)) : 0, \
211 layer ? GES_LAYER (layer)->timeline : NULL); \
212 if (tmp_layer) \
213 gst_object_unref (tmp_layer); \
214 if (layer) { \
215 GList *layer_clips = ges_layer_get_clips (GES_LAYER (layer)); \
216 fail_unless (g_list_find (layer_clips, clip), "clip %s not found " \
217 "in layer %u (timeline %" GST_PTR_FORMAT ")", \
218 ges_layer_get_priority (GES_LAYER (layer)), layer->timeline); \
219 g_list_free_full (layer_clips, gst_object_unref); \
220 } \
221 }
222
223 /* test that the two property lists contain the same properties the same
224 * number of times */
225 #define assert_property_list_match(list1, len1, list2, len2) \
226 { \
227 gboolean *found_count_in_list2; \
228 guint *count_list1; \
229 guint i, j; \
230 found_count_in_list2 = g_new0 (gboolean, len1); \
231 count_list1 = g_new0 (guint, len1); \
232 for (i = 0; i < len1; i++) { \
233 found_count_in_list2[i] = 0; \
234 count_list1[i] = 0; \
235 for (j = 0; j < len1; j++) { \
236 if (list1[i] == list1[j]) \
237 count_list1[i] ++; \
238 } \
239 } \
240 for (j = 0; j < len2; j++) { \
241 guint count_list2 = 0; \
242 guint found_count_in_list1 = 0; \
243 GParamSpec *prop = list2[j]; \
244 for (i = 0; i < len2; i++) { \
245 if (list2[i] == prop) \
246 count_list2 ++; \
247 } \
248 for (i = 0; i < len1; i++) { \
249 if (list1[i] == prop) { \
250 found_count_in_list2[i] ++; \
251 found_count_in_list1 ++; \
252 } \
253 } \
254 fail_unless (found_count_in_list1 == count_list2, \
255 "Found property '%s' %u times, rather than %u times, in " #list1, \
256 prop->name, found_count_in_list1, count_list2); \
257 } \
258 /* make sure we found each one once */ \
259 for (i = 0; i < len1; i++) { \
260 GParamSpec *prop = list1[i]; \
261 fail_unless (found_count_in_list2[i] == count_list1[i], \
262 "Found property '%s' %u times, rather than %u times, in " #list2, \
263 prop->name, found_count_in_list2[i], count_list1[i]); \
264 } \
265 g_free (found_count_in_list2); \
266 g_free (count_list1); \
267 }
268
269 #define assert_equal_children_properties(el1, el2) \
270 { \
271 guint i, num1, num2; \
272 const gchar *name1 = GES_TIMELINE_ELEMENT_NAME (el1); \
273 const gchar *name2 = GES_TIMELINE_ELEMENT_NAME (el2); \
274 GParamSpec **el_props1 = ges_timeline_element_list_children_properties ( \
275 GES_TIMELINE_ELEMENT (el1), &num1); \
276 GParamSpec **el_props2 = ges_timeline_element_list_children_properties ( \
277 GES_TIMELINE_ELEMENT (el2), &num2); \
278 assert_property_list_match (el_props1, num1, el_props2, num2); \
279 \
280 for (i = 0; i < num1; i++) { \
281 gchar *ser1, *ser2; \
282 GParamSpec *prop = el_props1[i]; \
283 GValue val1 = G_VALUE_INIT, val2 = G_VALUE_INIT; \
284 /* name property can be different */ \
285 if (g_strcmp0 (prop->name, "name") == 0) \
286 continue; \
287 if (g_strcmp0 (prop->name, "parent") == 0) \
288 continue; \
289 if (g_strcmp0 (prop->name, "zorder") == 0) \
290 continue; \
291 g_value_init (&val1, prop->value_type); \
292 g_value_init (&val2, prop->value_type); \
293 ges_timeline_element_get_child_property_by_pspec ( \
294 GES_TIMELINE_ELEMENT (el1), prop, &val1); \
295 ges_timeline_element_get_child_property_by_pspec ( \
296 GES_TIMELINE_ELEMENT (el2), prop, &val2); \
297 ser1 = gst_value_serialize (&val1); \
298 ser2 = gst_value_serialize (&val2); \
299 fail_unless (gst_value_compare (&val1, &val2) == GST_VALUE_EQUAL, \
300 "Child property '%s' for %s does not match that for %s (%s vs %s)", \
301 prop->name, name1, name2, ser1, ser2); \
302 g_free (ser1); \
303 g_free (ser2); \
304 g_value_unset (&val1); \
305 g_value_unset (&val2); \
306 } \
307 free_children_properties (el_props1, num1); \
308 free_children_properties (el_props2, num2); \
309 }
310
311 #define assert_equal_bindings(el1, el2) \
312 { \
313 guint i, num1, num2; \
314 const gchar *name1 = GES_TIMELINE_ELEMENT_NAME (el1); \
315 const gchar *name2 = GES_TIMELINE_ELEMENT_NAME (el2); \
316 GParamSpec **props1 = ges_timeline_element_list_children_properties ( \
317 GES_TIMELINE_ELEMENT (el1), &num1); \
318 GParamSpec **props2 = ges_timeline_element_list_children_properties ( \
319 GES_TIMELINE_ELEMENT (el2), &num2); \
320 assert_property_list_match (props1, num1, props2, num2); \
321 \
322 for (i = 0; i < num1; i++) { \
323 const gchar *prop = props1[i]->name; \
324 GstTimedValue *timed_vals1, *timed_vals2; \
325 gsize n_timed_vals1, n_timed_vals2; \
326 GObject *object1, *object2; \
327 gboolean abs1, abs2; \
328 GstControlSource *source1, *source2; \
329 GstInterpolationMode mode1, mode2; \
330 GstControlBinding *binding1, *binding2; \
331 gsize j; \
332 \
333 binding1 = ges_track_element_get_control_binding ( \
334 GES_TRACK_ELEMENT (el1), prop); \
335 binding2 = ges_track_element_get_control_binding ( \
336 GES_TRACK_ELEMENT (el2), prop); \
337 if (binding1 == NULL) { \
338 fail_unless (binding2 == NULL, "%s has a binding for property " \
339 " '%s', whilst %s does not", name2, prop, name1); \
340 continue; \
341 } \
342 if (binding2 == NULL) { \
343 fail_unless (binding1 == NULL, "%s has a binding for property " \
344 "'%s', whilst %s does not", name1, prop, name2); \
345 continue; \
346 } \
347 \
348 fail_unless (G_OBJECT_TYPE (binding1) == GST_TYPE_DIRECT_CONTROL_BINDING, \
349 "%s binding for property '%s' is not a direct control binding, " \
350 "so cannot be handled", prop, name1); \
351 fail_unless (G_OBJECT_TYPE (binding2) == GST_TYPE_DIRECT_CONTROL_BINDING, \
352 "%s binding for property '%s' is not a direct control binding, " \
353 "so cannot be handled", prop, name2); \
354 \
355 g_object_get (G_OBJECT (binding1), "control-source", &source1, \
356 "absolute", &abs1, "object", &object1, NULL); \
357 g_object_get (G_OBJECT (binding2), "control-source", &source2, \
358 "absolute", &abs2, "object", &object2, NULL); \
359 \
360 fail_unless (G_OBJECT_TYPE (object1) == G_OBJECT_TYPE (object2), \
361 "The child object for property '%s' for %s and %s correspond " \
362 "to different object types (%s vs %s)", prop, name1, name2, \
363 G_OBJECT_TYPE_NAME (object1), G_OBJECT_TYPE_NAME (object2)); \
364 gst_object_unref (object1); \
365 gst_object_unref (object2); \
366 \
367 fail_unless (abs1 == abs2, "control biding for property '%s' " \
368 " is %s absolute for %s, but %s absolute for %s", prop, \
369 abs1 ? "" : "not", name1, abs2 ? "" : "not", name2); \
370 \
371 fail_unless (GST_IS_INTERPOLATION_CONTROL_SOURCE (source1), \
372 "%s does not have an interpolation control source for " \
373 "property '%s', so cannot be handled", name1, prop); \
374 fail_unless (GST_IS_INTERPOLATION_CONTROL_SOURCE (source2), \
375 "%s does not have an interpolation control source for " \
376 "property '%s', so cannot be handled", name2, prop); \
377 g_object_get (G_OBJECT (source1), "mode", &mode1, NULL); \
378 g_object_get (G_OBJECT (source2), "mode", &mode2, NULL); \
379 fail_unless (mode1 == mode2, "control source for property '%s' " \
380 "has different modes for %s and %s (%i vs %i)", prop, \
381 name1, name2, mode1, mode2); \
382 \
383 timed_vals1 = gst_timed_value_control_source_list_control_points ( \
384 GST_TIMED_VALUE_CONTROL_SOURCE (source1), &n_timed_vals1); \
385 timed_vals2 = gst_timed_value_control_source_list_control_points ( \
386 GST_TIMED_VALUE_CONTROL_SOURCE (source2), &n_timed_vals2); \
387 \
388 fail_unless (n_timed_vals1 == n_timed_vals2, \
389 "Different number of timed values for property '%s' for %s and " \
390 "%s (%lu vs %lu)", prop, name1, name2, n_timed_vals1, \
391 n_timed_vals2); \
392 \
393 for (j = 0; j < n_timed_vals1; j++) { \
394 GstTimedValue *val1 = &timed_vals1[j]; \
395 GstTimedValue *val2 = &timed_vals2[j]; \
396 fail_unless (val1->timestamp == val2->timestamp && \
397 val1->value == val2->value, "The %luth timed value for property " \
398 "'%s' is different for %s and %s: (%" G_GUINT64_FORMAT ": %g) vs " \
399 "(%" G_GUINT64_FORMAT ": %g)", j, prop, name1, name2, \
400 val1->timestamp, val1->value, val2->timestamp, val2->value); \
401 } \
402 \
403 g_free (timed_vals1); \
404 g_free (timed_vals2); \
405 gst_object_unref (source1); \
406 gst_object_unref (source2); \
407 } \
408 free_children_properties (props1, num1); \
409 free_children_properties (props2, num2); \
410 }
411
412 #define assert_GESError(error, error_code) \
413 { \
414 fail_unless (error); \
415 fail_unless (error->domain == GES_ERROR); \
416 assert_equals_int (error->code, error_code); \
417 g_error_free (error); \
418 error = NULL; \
419 }
420
421 void print_timeline(GESTimeline *timeline);