| 1 |
/* GStreamer Editing Services |
| 2 |
* |
| 3 |
* Copyright (C) <2012> Thibault Saunier <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public |
| 16 |
* License along with this library; if not, write to the |
| 17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 18 |
* Boston, MA 02111-1307, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "test-utils.h" |
| 22 |
#include <ges/ges.h> |
| 23 |
#include <gst/check/gstcheck.h> |
| 24 |
#include <gst/controller/gstdirectcontrolbinding.h> |
| 25 |
#include <gst/controller/gstinterpolationcontrolsource.h> |
| 26 |
|
| 27 |
GMainLoop *mainloop; |
| 28 |
|
| 29 |
static void |
| 30 |
project_loaded_cb (GESProject * project, GESTimeline * timeline, |
| 31 |
GMainLoop * mainloop) |
| 32 |
{ |
| 33 |
g_main_loop_quit (mainloop); |
| 34 |
} |
| 35 |
|
| 36 |
GST_START_TEST (test_project_simple) |
| 37 |
{ |
| 38 |
gchar *id; |
| 39 |
GESProject *project; |
| 40 |
GESTimeline *timeline; |
| 41 |
|
| 42 |
ges_init (); |
| 43 |
|
| 44 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 45 |
project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, NULL, NULL)); |
| 46 |
fail_unless (GES_IS_PROJECT (project)); |
| 47 |
assert_equals_string (ges_asset_get_id (GES_ASSET (project)), "project-0"); |
| 48 |
g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, mainloop); |
| 49 |
|
| 50 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), NULL)); |
| 51 |
g_main_loop_run (mainloop); |
| 52 |
|
| 53 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 54 |
id = ges_extractable_get_id (GES_EXTRACTABLE (timeline)); |
| 55 |
assert_equals_string (id, "project-0"); |
| 56 |
ASSERT_OBJECT_REFCOUNT (timeline, "We own the only ref", 1); |
| 57 |
|
| 58 |
g_free (id); |
| 59 |
gst_object_unref (project); |
| 60 |
gst_object_unref (timeline); |
| 61 |
g_main_loop_unref (mainloop); |
| 62 |
g_signal_handlers_disconnect_by_func (project, (GCallback) project_loaded_cb, |
| 63 |
mainloop); |
| 64 |
|
| 65 |
ges_deinit (); |
| 66 |
} |
| 67 |
|
| 68 |
GST_END_TEST; |
| 69 |
|
| 70 |
static void |
| 71 |
asset_removed_add_cb (GESProject * project, GESAsset * asset, gboolean * called) |
| 72 |
{ |
| 73 |
*called = TRUE; |
| 74 |
} |
| 75 |
|
| 76 |
static void |
| 77 |
asset_created_cb (GObject * source, GAsyncResult * res, GESAsset ** asset) |
| 78 |
{ |
| 79 |
GError *error = NULL; |
| 80 |
*asset = ges_asset_request_finish (res, &error); |
| 81 |
|
| 82 |
fail_unless (error == NULL); |
| 83 |
g_main_loop_quit (mainloop); |
| 84 |
} |
| 85 |
|
| 86 |
GST_START_TEST (test_project_add_assets) |
| 87 |
{ |
| 88 |
GESProject *project; |
| 89 |
GESAsset *asset; |
| 90 |
gboolean added_cb_called = FALSE; |
| 91 |
gboolean removed_cb_called = FALSE; |
| 92 |
|
| 93 |
ges_init (); |
| 94 |
|
| 95 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 96 |
project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, NULL, NULL)); |
| 97 |
fail_unless (GES_IS_PROJECT (project)); |
| 98 |
|
| 99 |
g_signal_connect (project, "asset-added", |
| 100 |
(GCallback) asset_removed_add_cb, &added_cb_called); |
| 101 |
g_signal_connect (project, "asset-removed", |
| 102 |
(GCallback) asset_removed_add_cb, &removed_cb_called); |
| 103 |
|
| 104 |
ges_asset_request_async (GES_TYPE_TEST_CLIP, NULL, NULL, |
| 105 |
(GAsyncReadyCallback) asset_created_cb, &asset); |
| 106 |
g_main_loop_run (mainloop); |
| 107 |
g_main_loop_unref (mainloop); |
| 108 |
|
| 109 |
fail_unless (GES_IS_ASSET (asset)); |
| 110 |
|
| 111 |
fail_unless (ges_project_add_asset (project, asset)); |
| 112 |
fail_unless (added_cb_called); |
| 113 |
ASSERT_OBJECT_REFCOUNT (project, "The project", 2); |
| 114 |
ASSERT_OBJECT_REFCOUNT (asset, "The asset (1 for project and one for " |
| 115 |
"us + 1 cache)", 3); |
| 116 |
|
| 117 |
fail_unless (ges_project_remove_asset (project, asset)); |
| 118 |
fail_unless (removed_cb_called); |
| 119 |
|
| 120 |
g_signal_handlers_disconnect_by_func (project, |
| 121 |
(GCallback) asset_removed_add_cb, &added_cb_called); |
| 122 |
g_signal_handlers_disconnect_by_func (project, |
| 123 |
(GCallback) asset_removed_add_cb, &removed_cb_called); |
| 124 |
|
| 125 |
gst_object_unref (asset); |
| 126 |
gst_object_unref (project); |
| 127 |
ASSERT_OBJECT_REFCOUNT (asset, "The asset (1 ref in cache)", 1); |
| 128 |
ASSERT_OBJECT_REFCOUNT (project, "The project (1 ref in cache)", 1); |
| 129 |
|
| 130 |
ges_deinit (); |
| 131 |
} |
| 132 |
|
| 133 |
GST_END_TEST; |
| 134 |
|
| 135 |
static void |
| 136 |
error_loading_asset_cb (GESProject * project, GError * error, gchar * id, |
| 137 |
GType extractable_type, GMainLoop * mainloop) |
| 138 |
{ |
| 139 |
fail_unless (g_error_matches (error, GST_PARSE_ERROR, |
| 140 |
GST_PARSE_ERROR_NO_SUCH_ELEMENT)); |
| 141 |
g_main_loop_quit (mainloop); |
| 142 |
} |
| 143 |
|
| 144 |
GST_START_TEST (test_project_unexistant_effect) |
| 145 |
{ |
| 146 |
GESProject *project; |
| 147 |
gboolean added_cb_called = FALSE; |
| 148 |
gboolean removed_cb_called = FALSE; |
| 149 |
|
| 150 |
ges_init (); |
| 151 |
|
| 152 |
project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, NULL, NULL)); |
| 153 |
fail_unless (GES_IS_PROJECT (project)); |
| 154 |
|
| 155 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 156 |
g_signal_connect (project, "asset-added", |
| 157 |
(GCallback) asset_removed_add_cb, &added_cb_called); |
| 158 |
g_signal_connect (project, "asset-removed", |
| 159 |
(GCallback) asset_removed_add_cb, &removed_cb_called); |
| 160 |
g_signal_connect (project, "error-loading-asset", |
| 161 |
(GCallback) error_loading_asset_cb, mainloop); |
| 162 |
|
| 163 |
fail_unless (ges_project_create_asset (project, "nowaythiselementexists", |
| 164 |
GES_TYPE_EFFECT)); |
| 165 |
g_main_loop_run (mainloop); |
| 166 |
|
| 167 |
/* And.... try again! */ |
| 168 |
fail_if (ges_project_create_asset (project, "nowaythiselementexists", |
| 169 |
GES_TYPE_EFFECT)); |
| 170 |
|
| 171 |
fail_if (added_cb_called); |
| 172 |
fail_if (removed_cb_called); |
| 173 |
|
| 174 |
ASSERT_OBJECT_REFCOUNT (project, "The project", 2); |
| 175 |
gst_object_unref (project); |
| 176 |
g_main_loop_unref (mainloop); |
| 177 |
|
| 178 |
ASSERT_OBJECT_REFCOUNT (project, "The project (1 ref in cache)", 1); |
| 179 |
|
| 180 |
ges_deinit (); |
| 181 |
} |
| 182 |
|
| 183 |
GST_END_TEST; |
| 184 |
|
| 185 |
static void |
| 186 |
asset_added_cb (GESProject * project, GESAsset * asset) |
| 187 |
{ |
| 188 |
gchar *uri = ges_test_file_uri ("audio_video.ogg"); |
| 189 |
GstDiscovererInfo *info; |
| 190 |
|
| 191 |
if (ges_asset_get_extractable_type (asset) == GES_TYPE_EFFECT) { |
| 192 |
assert_equals_string (ges_asset_get_id (asset), "video agingtv"); |
| 193 |
} else { |
| 194 |
info = ges_uri_clip_asset_get_info (GES_URI_CLIP_ASSET (asset)); |
| 195 |
fail_unless (GST_IS_DISCOVERER_INFO (info)); |
| 196 |
assert_equals_string (ges_asset_get_id (asset), uri); |
| 197 |
} |
| 198 |
|
| 199 |
g_free (uri); |
| 200 |
} |
| 201 |
|
| 202 |
static gchar * |
| 203 |
_set_new_uri (GESProject * project, GError * error, GESAsset * wrong_asset) |
| 204 |
{ |
| 205 |
fail_unless (!g_strcmp0 (ges_asset_get_id (wrong_asset), |
| 206 |
"file:///test/not/exisiting")); |
| 207 |
|
| 208 |
return ges_test_file_uri ("audio_video.ogg"); |
| 209 |
} |
| 210 |
|
| 211 |
static void |
| 212 |
_test_project (GESProject * project, GESTimeline * timeline) |
| 213 |
{ |
| 214 |
guint a_meta; |
| 215 |
gchar *media_uri; |
| 216 |
GESTrack *track; |
| 217 |
const GList *profiles; |
| 218 |
GstEncodingContainerProfile *profile; |
| 219 |
GList *tracks, *tmp, *tmptrackelement, *clips; |
| 220 |
|
| 221 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 222 |
assert_equals_int (g_list_length (timeline->layers), 2); |
| 223 |
|
| 224 |
assert_equals_string (ges_meta_container_get_string (GES_META_CONTAINER |
| 225 |
(project), "name"), "Example project"); |
| 226 |
clips = ges_layer_get_clips (GES_LAYER (timeline->layers->data)); |
| 227 |
fail_unless (ges_meta_container_get_uint (GES_META_CONTAINER |
| 228 |
(timeline->layers->data), "a", &a_meta)); |
| 229 |
assert_equals_int (a_meta, 3); |
| 230 |
assert_equals_int (g_list_length (clips), 1); |
| 231 |
media_uri = ges_test_file_uri ("audio_video.ogg"); |
| 232 |
assert_equals_string (ges_asset_get_id (ges_extractable_get_asset |
| 233 |
(GES_EXTRACTABLE (clips->data))), media_uri); |
| 234 |
g_free (media_uri); |
| 235 |
g_list_free_full (clips, gst_object_unref); |
| 236 |
|
| 237 |
/* Check tracks and the objects they contain */ |
| 238 |
tracks = ges_timeline_get_tracks (timeline); |
| 239 |
assert_equals_int (g_list_length (tracks), 2); |
| 240 |
for (tmp = tracks; tmp; tmp = tmp->next) { |
| 241 |
GList *trackelements; |
| 242 |
track = GES_TRACK (tmp->data); |
| 243 |
|
| 244 |
trackelements = ges_track_get_elements (track); |
| 245 |
GST_DEBUG_OBJECT (track, "Testing track"); |
| 246 |
switch (track->type) { |
| 247 |
case GES_TRACK_TYPE_VIDEO: |
| 248 |
assert_equals_int (g_list_length (trackelements), 2); |
| 249 |
for (tmptrackelement = trackelements; tmptrackelement; |
| 250 |
tmptrackelement = tmptrackelement->next) { |
| 251 |
GESTrackElement *trackelement = |
| 252 |
GES_TRACK_ELEMENT (tmptrackelement->data); |
| 253 |
|
| 254 |
if (GES_IS_BASE_EFFECT (trackelement)) { |
| 255 |
guint nb_scratch_lines; |
| 256 |
|
| 257 |
ges_timeline_element_get_child_properties (tmptrackelement->data, |
| 258 |
"scratch-lines", &nb_scratch_lines, NULL); |
| 259 |
assert_equals_int (nb_scratch_lines, 12); |
| 260 |
|
| 261 |
nle_object_check (ges_track_element_get_nleobject (trackelement), |
| 262 |
0, 1000000000, 0, 1000000000, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, |
| 263 |
TRUE); |
| 264 |
} else { |
| 265 |
nle_object_check (ges_track_element_get_nleobject (trackelement), |
| 266 |
0, 1000000000, 0, 1000000000, |
| 267 |
MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1, TRUE); |
| 268 |
} |
| 269 |
} |
| 270 |
break; |
| 271 |
case GES_TRACK_TYPE_AUDIO: |
| 272 |
assert_equals_int (g_list_length (trackelements), 2); |
| 273 |
break; |
| 274 |
default: |
| 275 |
g_assert_true (1); |
| 276 |
} |
| 277 |
|
| 278 |
g_list_free_full (trackelements, gst_object_unref); |
| 279 |
|
| 280 |
} |
| 281 |
g_list_free_full (tracks, gst_object_unref); |
| 282 |
|
| 283 |
/* Now test the encoding profile */ |
| 284 |
profiles = ges_project_list_encoding_profiles (project); |
| 285 |
assert_equals_int (g_list_length ((GList *) profiles), 1); |
| 286 |
profile = profiles->data; |
| 287 |
fail_unless (GST_IS_ENCODING_CONTAINER_PROFILE (profile)); |
| 288 |
profiles = gst_encoding_container_profile_get_profiles (profile); |
| 289 |
assert_equals_int (g_list_length ((GList *) profiles), 2); |
| 290 |
} |
| 291 |
|
| 292 |
static void |
| 293 |
_add_properties (GESTimeline * timeline) |
| 294 |
{ |
| 295 |
GList *tracks; |
| 296 |
GList *tmp; |
| 297 |
|
| 298 |
tracks = ges_timeline_get_tracks (timeline); |
| 299 |
for (tmp = tracks; tmp; tmp = tmp->next) { |
| 300 |
GESTrack *track; |
| 301 |
GList *track_elements; |
| 302 |
GList *tmp_tck; |
| 303 |
|
| 304 |
track = GES_TRACK (tmp->data); |
| 305 |
switch (track->type) { |
| 306 |
case GES_TRACK_TYPE_VIDEO: |
| 307 |
track_elements = ges_track_get_elements (track); |
| 308 |
|
| 309 |
for (tmp_tck = track_elements; tmp_tck; tmp_tck = tmp_tck->next) { |
| 310 |
GESTrackElement *element = GES_TRACK_ELEMENT (tmp_tck->data); |
| 311 |
|
| 312 |
/* Adding keyframes */ |
| 313 |
if (GES_IS_EFFECT (element)) { |
| 314 |
GstControlSource *source; |
| 315 |
GstControlBinding *tmp_binding, *binding; |
| 316 |
|
| 317 |
source = gst_interpolation_control_source_new (); |
| 318 |
|
| 319 |
/* Check binding creation and replacement */ |
| 320 |
binding = |
| 321 |
ges_track_element_get_control_binding (element, |
| 322 |
"scratch-lines"); |
| 323 |
fail_unless (binding == NULL); |
| 324 |
ges_track_element_set_control_source (element, |
| 325 |
source, "scratch-lines", "direct"); |
| 326 |
tmp_binding = |
| 327 |
ges_track_element_get_control_binding (element, |
| 328 |
"scratch-lines"); |
| 329 |
fail_unless (tmp_binding != NULL); |
| 330 |
ges_track_element_set_control_source (element, |
| 331 |
source, "scratch-lines", "direct"); |
| 332 |
binding = |
| 333 |
ges_track_element_get_control_binding (element, |
| 334 |
"scratch-lines"); |
| 335 |
fail_unless (binding != tmp_binding); |
| 336 |
|
| 337 |
|
| 338 |
g_object_set (source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL); |
| 339 |
gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE |
| 340 |
(source), 0 * GST_SECOND, 0.); |
| 341 |
gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE |
| 342 |
(source), 5 * GST_SECOND, 0.); |
| 343 |
gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE |
| 344 |
(source), 10 * GST_SECOND, 1.); |
| 345 |
|
| 346 |
gst_object_unref (source); |
| 347 |
} else if (GES_IS_VIDEO_SOURCE (element)) { |
| 348 |
/* Adding children properties */ |
| 349 |
gint posx = 42; |
| 350 |
ges_timeline_element_set_child_properties (GES_TIMELINE_ELEMENT |
| 351 |
(element), "posx", posx, NULL); |
| 352 |
ges_timeline_element_get_child_properties (GES_TIMELINE_ELEMENT |
| 353 |
(element), "posx", &posx, NULL); |
| 354 |
fail_unless_equals_int (posx, 42); |
| 355 |
} |
| 356 |
|
| 357 |
} |
| 358 |
g_list_free_full (track_elements, g_object_unref); |
| 359 |
break; |
| 360 |
default: |
| 361 |
break; |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
g_list_free_full (tracks, g_object_unref); |
| 366 |
} |
| 367 |
|
| 368 |
static void |
| 369 |
_check_properties (GESTimeline * timeline) |
| 370 |
{ |
| 371 |
GList *tracks; |
| 372 |
GList *tmp; |
| 373 |
|
| 374 |
tracks = ges_timeline_get_tracks (timeline); |
| 375 |
for (tmp = tracks; tmp; tmp = tmp->next) { |
| 376 |
GESTrack *track; |
| 377 |
GList *track_elements; |
| 378 |
GList *tmp_tck; |
| 379 |
|
| 380 |
track = GES_TRACK (tmp->data); |
| 381 |
switch (track->type) { |
| 382 |
case GES_TRACK_TYPE_VIDEO: |
| 383 |
track_elements = ges_track_get_elements (track); |
| 384 |
|
| 385 |
for (tmp_tck = track_elements; tmp_tck; tmp_tck = tmp_tck->next) { |
| 386 |
GESTrackElement *element = GES_TRACK_ELEMENT (tmp_tck->data); |
| 387 |
/* Checking keyframes */ |
| 388 |
if (GES_IS_EFFECT (element)) { |
| 389 |
GstControlBinding *binding; |
| 390 |
GstControlSource *source; |
| 391 |
GstTimedValue *timed_values; |
| 392 |
gsize n_values; |
| 393 |
GstTimedValue *value; |
| 394 |
|
| 395 |
binding = |
| 396 |
ges_track_element_get_control_binding (element, |
| 397 |
"scratch-lines"); |
| 398 |
fail_unless (binding != NULL); |
| 399 |
g_object_get (binding, "control-source", &source, NULL); |
| 400 |
fail_unless (source != NULL); |
| 401 |
|
| 402 |
/* Now check keyframe position */ |
| 403 |
timed_values = |
| 404 |
gst_timed_value_control_source_list_control_points |
| 405 |
(GST_TIMED_VALUE_CONTROL_SOURCE (source), &n_values); |
| 406 |
value = &timed_values[0]; |
| 407 |
fail_unless (value->value == 0.); |
| 408 |
fail_unless (value->timestamp == 0 * GST_SECOND); |
| 409 |
value = &timed_values[1]; |
| 410 |
fail_unless (value->value == 0.); |
| 411 |
fail_unless (value->timestamp == 5 * GST_SECOND); |
| 412 |
value = &timed_values[2]; |
| 413 |
fail_unless (value->value == 1.); |
| 414 |
fail_unless (value->timestamp == 10 * GST_SECOND); |
| 415 |
g_free (timed_values); |
| 416 |
gst_object_unref (source); |
| 417 |
} |
| 418 |
/* Checking children properties */ |
| 419 |
else if (GES_IS_VIDEO_SOURCE (element)) { |
| 420 |
/* Init 'posx' with a wrong value */ |
| 421 |
gint posx = 27; |
| 422 |
ges_timeline_element_get_child_properties (GES_TIMELINE_ELEMENT |
| 423 |
(element), "posx", &posx, NULL); |
| 424 |
fail_unless_equals_int (posx, 42); |
| 425 |
} |
| 426 |
} |
| 427 |
g_list_free_full (track_elements, g_object_unref); |
| 428 |
break; |
| 429 |
default: |
| 430 |
break; |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
g_list_free_full (tracks, g_object_unref); |
| 435 |
} |
| 436 |
|
| 437 |
GST_START_TEST (test_project_add_properties) |
| 438 |
{ |
| 439 |
GESProject *project; |
| 440 |
GESTimeline *timeline; |
| 441 |
gchar *uri; |
| 442 |
|
| 443 |
ges_init (); |
| 444 |
|
| 445 |
uri = ges_test_file_uri ("test-properties.xges"); |
| 446 |
project = ges_project_new (uri); |
| 447 |
g_free (uri); |
| 448 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 449 |
|
| 450 |
/* Connect the signals */ |
| 451 |
g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, mainloop); |
| 452 |
g_signal_connect (project, "missing-uri", (GCallback) _set_new_uri, NULL); |
| 453 |
|
| 454 |
/* Now extract a timeline from it */ |
| 455 |
GST_LOG ("Loading project"); |
| 456 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), NULL)); |
| 457 |
|
| 458 |
g_main_loop_run (mainloop); |
| 459 |
|
| 460 |
GST_LOG ("Test first loading"); |
| 461 |
|
| 462 |
|
| 463 |
_add_properties (timeline); |
| 464 |
|
| 465 |
uri = ges_test_get_tmp_uri ("test-properties-save.xges"); |
| 466 |
fail_unless (ges_project_save (project, timeline, uri, NULL, TRUE, NULL)); |
| 467 |
gst_object_unref (timeline); |
| 468 |
gst_object_unref (project); |
| 469 |
|
| 470 |
project = ges_project_new (uri); |
| 471 |
g_free (uri); |
| 472 |
|
| 473 |
ASSERT_OBJECT_REFCOUNT (project, "Our + cache", 2); |
| 474 |
|
| 475 |
g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, mainloop); |
| 476 |
|
| 477 |
GST_LOG ("Loading saved project"); |
| 478 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), NULL)); |
| 479 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 480 |
|
| 481 |
g_main_loop_run (mainloop); |
| 482 |
|
| 483 |
_check_properties (timeline); |
| 484 |
|
| 485 |
g_signal_handlers_disconnect_by_func (project, (GCallback) project_loaded_cb, |
| 486 |
mainloop); |
| 487 |
g_signal_handlers_disconnect_by_func (project, (GCallback) asset_added_cb, |
| 488 |
NULL); |
| 489 |
|
| 490 |
gst_object_unref (timeline); |
| 491 |
gst_object_unref (project); |
| 492 |
g_main_loop_unref (mainloop); |
| 493 |
|
| 494 |
/* discovery cleanup may be delayed */ |
| 495 |
g_usleep (G_USEC_PER_SEC * 2); |
| 496 |
while (g_main_context_iteration (NULL, FALSE)) |
| 497 |
continue; |
| 498 |
|
| 499 |
ges_deinit (); |
| 500 |
} |
| 501 |
|
| 502 |
GST_END_TEST; |
| 503 |
|
| 504 |
GST_START_TEST (test_project_load_xges) |
| 505 |
{ |
| 506 |
gboolean saved; |
| 507 |
GESProject *loaded_project, *saved_project; |
| 508 |
GESTimeline *timeline; |
| 509 |
GESAsset *formatter_asset; |
| 510 |
gchar *uri; |
| 511 |
GList *tmp; |
| 512 |
|
| 513 |
ges_init (); |
| 514 |
|
| 515 |
uri = ges_test_file_uri ("test-project.xges"); |
| 516 |
loaded_project = ges_project_new (uri); |
| 517 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 518 |
fail_unless (GES_IS_PROJECT (loaded_project)); |
| 519 |
|
| 520 |
/* Connect the signals */ |
| 521 |
g_signal_connect (loaded_project, "asset-added", (GCallback) asset_added_cb, |
| 522 |
NULL); |
| 523 |
g_signal_connect (loaded_project, "loaded", (GCallback) project_loaded_cb, |
| 524 |
mainloop); |
| 525 |
|
| 526 |
/* Make sure we update the project's dummy URL to some actual URL */ |
| 527 |
g_signal_connect (loaded_project, "missing-uri", (GCallback) _set_new_uri, |
| 528 |
NULL); |
| 529 |
|
| 530 |
/* Now extract a timeline from it */ |
| 531 |
GST_LOG ("Loading project"); |
| 532 |
timeline = |
| 533 |
GES_TIMELINE (ges_asset_extract (GES_ASSET (loaded_project), NULL)); |
| 534 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 535 |
tmp = ges_project_get_loading_assets (loaded_project); |
| 536 |
assert_equals_int (g_list_length (tmp), 1); |
| 537 |
g_list_free_full (tmp, g_object_unref); |
| 538 |
|
| 539 |
g_main_loop_run (mainloop); |
| 540 |
GST_LOG ("Test first loading"); |
| 541 |
_test_project (loaded_project, timeline); |
| 542 |
g_free (uri); |
| 543 |
|
| 544 |
uri = ges_test_get_tmp_uri ("test-project_TMP.xges"); |
| 545 |
formatter_asset = ges_asset_request (GES_TYPE_FORMATTER, "ges", NULL); |
| 546 |
saved = |
| 547 |
ges_project_save (loaded_project, timeline, uri, formatter_asset, TRUE, |
| 548 |
NULL); |
| 549 |
fail_unless (saved); |
| 550 |
gst_object_unref (timeline); |
| 551 |
|
| 552 |
saved_project = ges_project_new (uri); |
| 553 |
ASSERT_OBJECT_REFCOUNT (saved_project, "Our + cache", 2); |
| 554 |
g_signal_connect (saved_project, "asset-added", (GCallback) asset_added_cb, |
| 555 |
NULL); |
| 556 |
g_signal_connect (saved_project, "loaded", (GCallback) project_loaded_cb, |
| 557 |
mainloop); |
| 558 |
|
| 559 |
GST_LOG ("Loading saved project"); |
| 560 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (saved_project), NULL)); |
| 561 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 562 |
g_main_loop_run (mainloop); |
| 563 |
_test_project (saved_project, timeline); |
| 564 |
|
| 565 |
fail_unless (ges_meta_container_get_string (GES_META_CONTAINER |
| 566 |
(loaded_project), GES_META_FORMAT_VERSION)); |
| 567 |
fail_unless_equals_string (ges_meta_container_get_string (GES_META_CONTAINER |
| 568 |
(loaded_project), GES_META_FORMAT_VERSION), |
| 569 |
ges_meta_container_get_string (GES_META_CONTAINER (loaded_project), |
| 570 |
GES_META_FORMAT_VERSION)); |
| 571 |
|
| 572 |
g_signal_handlers_disconnect_by_func (saved_project, |
| 573 |
(GCallback) project_loaded_cb, mainloop); |
| 574 |
g_signal_handlers_disconnect_by_func (saved_project, |
| 575 |
(GCallback) asset_added_cb, NULL); |
| 576 |
|
| 577 |
g_free (uri); |
| 578 |
gst_object_unref (timeline); |
| 579 |
gst_object_unref (saved_project); |
| 580 |
gst_object_unref (loaded_project); |
| 581 |
g_main_loop_unref (mainloop); |
| 582 |
|
| 583 |
ASSERT_OBJECT_REFCOUNT (saved_project, "Still 1 ref for asset cache", 1); |
| 584 |
|
| 585 |
/* discovery cleanup may be delayed */ |
| 586 |
g_usleep (G_USEC_PER_SEC * 2); |
| 587 |
while (g_main_context_iteration (NULL, FALSE)) |
| 588 |
continue; |
| 589 |
|
| 590 |
ges_deinit (); |
| 591 |
} |
| 592 |
|
| 593 |
GST_END_TEST; |
| 594 |
|
| 595 |
GST_START_TEST (test_project_auto_transition) |
| 596 |
{ |
| 597 |
GList *layers, *tmp; |
| 598 |
GESProject *project; |
| 599 |
GESTimeline *timeline; |
| 600 |
GESLayer *layer = NULL; |
| 601 |
GESAsset *formatter_asset; |
| 602 |
gboolean saved; |
| 603 |
gchar *tmpuri, *uri; |
| 604 |
|
| 605 |
ges_init (); |
| 606 |
|
| 607 |
uri = ges_test_file_uri ("test-auto-transition.xges"); |
| 608 |
project = ges_project_new (uri); |
| 609 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 610 |
fail_unless (GES_IS_PROJECT (project)); |
| 611 |
|
| 612 |
/* Connect the signals */ |
| 613 |
g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, mainloop); |
| 614 |
g_signal_connect (project, "missing-uri", (GCallback) _set_new_uri, NULL); |
| 615 |
|
| 616 |
/* Now extract a timeline from it */ |
| 617 |
GST_LOG ("Loading project"); |
| 618 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), NULL)); |
| 619 |
|
| 620 |
g_main_loop_run (mainloop); |
| 621 |
|
| 622 |
/* Check timeline and layers auto-transition, must be FALSE */ |
| 623 |
fail_if (ges_timeline_get_auto_transition (timeline)); |
| 624 |
layers = ges_timeline_get_layers (timeline); |
| 625 |
for (tmp = layers; tmp; tmp = tmp->next) { |
| 626 |
layer = tmp->data; |
| 627 |
fail_if (ges_layer_get_auto_transition (layer)); |
| 628 |
} |
| 629 |
|
| 630 |
g_list_free_full (layers, gst_object_unref); |
| 631 |
g_free (uri); |
| 632 |
|
| 633 |
/* Set timeline and layers auto-transition to TRUE */ |
| 634 |
ges_timeline_set_auto_transition (timeline, TRUE); |
| 635 |
|
| 636 |
tmpuri = ges_test_get_tmp_uri ("test-auto-transition-save.xges"); |
| 637 |
formatter_asset = ges_asset_request (GES_TYPE_FORMATTER, "ges", NULL); |
| 638 |
saved = |
| 639 |
ges_project_save (project, timeline, tmpuri, formatter_asset, TRUE, NULL); |
| 640 |
fail_unless (saved); |
| 641 |
|
| 642 |
gst_object_unref (timeline); |
| 643 |
gst_object_unref (project); |
| 644 |
|
| 645 |
project = ges_project_new (tmpuri); |
| 646 |
|
| 647 |
ASSERT_OBJECT_REFCOUNT (project, "Our + cache", 2); |
| 648 |
|
| 649 |
g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, mainloop); |
| 650 |
|
| 651 |
GST_LOG ("Loading saved project"); |
| 652 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), NULL)); |
| 653 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 654 |
|
| 655 |
g_main_loop_run (mainloop); |
| 656 |
|
| 657 |
/* Check timeline and layers auto-transition, must be TRUE */ |
| 658 |
fail_unless (ges_timeline_get_auto_transition (timeline)); |
| 659 |
layers = ges_timeline_get_layers (timeline); |
| 660 |
for (tmp = layers; tmp; tmp = tmp->next) { |
| 661 |
layer = tmp->data; |
| 662 |
fail_unless (ges_layer_get_auto_transition (layer)); |
| 663 |
} |
| 664 |
|
| 665 |
g_signal_handlers_disconnect_by_func (project, (GCallback) project_loaded_cb, |
| 666 |
mainloop); |
| 667 |
g_signal_handlers_disconnect_by_func (project, (GCallback) asset_added_cb, |
| 668 |
NULL); |
| 669 |
|
| 670 |
g_free (tmpuri); |
| 671 |
g_list_free_full (layers, gst_object_unref); |
| 672 |
gst_object_unref (timeline); |
| 673 |
gst_object_unref (project); |
| 674 |
g_main_loop_unref (mainloop); |
| 675 |
|
| 676 |
/* discovery cleanup may be delayed */ |
| 677 |
g_usleep (G_USEC_PER_SEC * 2); |
| 678 |
while (g_main_context_iteration (NULL, FALSE)) |
| 679 |
continue; |
| 680 |
|
| 681 |
ges_deinit (); |
| 682 |
} |
| 683 |
|
| 684 |
GST_END_TEST; |
| 685 |
|
| 686 |
/* FIXME This test does not pass for some bad reason */ |
| 687 |
#if 0 |
| 688 |
static void |
| 689 |
project_loaded_now_play_cb (GESProject * project, GESTimeline * timeline) |
| 690 |
{ |
| 691 |
GstBus *bus; |
| 692 |
GstMessage *message; |
| 693 |
gboolean carry_on = TRUE; |
| 694 |
|
| 695 |
GESPipeline *pipeline = ges_pipeline_new (); |
| 696 |
|
| 697 |
fail_unless (ges_pipeline_set_timeline (pipeline, timeline)); |
| 698 |
|
| 699 |
bus = gst_element_get_bus (GST_ELEMENT (pipeline)); |
| 700 |
fail_if (gst_element_set_state (GST_ELEMENT (pipeline), |
| 701 |
GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE); |
| 702 |
|
| 703 |
GST_DEBUG ("Let's poll the bus"); |
| 704 |
|
| 705 |
while (carry_on) { |
| 706 |
message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10); |
| 707 |
if (message) { |
| 708 |
GST_ERROR ("GOT MESSAGE: %" GST_PTR_FORMAT, message); |
| 709 |
switch (GST_MESSAGE_TYPE (message)) { |
| 710 |
case GST_MESSAGE_EOS: |
| 711 |
/* we should check if we really finished here */ |
| 712 |
GST_WARNING ("Got an EOS, we did not even start!"); |
| 713 |
carry_on = FALSE; |
| 714 |
fail_if (TRUE); |
| 715 |
break; |
| 716 |
case GST_MESSAGE_SEGMENT_START: |
| 717 |
case GST_MESSAGE_SEGMENT_DONE: |
| 718 |
/* We shouldn't see any segement messages, since we didn't do a segment seek */ |
| 719 |
GST_WARNING ("Saw a Segment start/stop"); |
| 720 |
fail_if (TRUE); |
| 721 |
break; |
| 722 |
case GST_MESSAGE_ERROR: |
| 723 |
fail_error_message (message); |
| 724 |
break; |
| 725 |
case GST_MESSAGE_ASYNC_DONE: |
| 726 |
GST_DEBUG ("prerolling done"); |
| 727 |
carry_on = FALSE; |
| 728 |
break; |
| 729 |
default: |
| 730 |
break; |
| 731 |
} |
| 732 |
gst_mini_object_unref (GST_MINI_OBJECT (message)); |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
fail_if (gst_element_set_state (GST_ELEMENT (pipeline), |
| 737 |
GST_STATE_READY) == GST_STATE_CHANGE_FAILURE); |
| 738 |
gst_object_unref (pipeline); |
| 739 |
g_main_loop_quit (mainloop); |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
GST_START_TEST (test_load_xges_and_play) |
| 744 |
{ |
| 745 |
GESProject *project; |
| 746 |
GESTimeline *timeline; |
| 747 |
gchar *uri = ges_test_file_uri ("test-project_TMP.xges"); |
| 748 |
|
| 749 |
project = ges_project_new (uri); |
| 750 |
fail_unless (GES_IS_PROJECT (project)); |
| 751 |
|
| 752 |
mainloop = g_main_loop_new (NULL, FALSE); |
| 753 |
/* Connect the signals */ |
| 754 |
g_signal_connect (project, "loaded", (GCallback) project_loaded_now_play_cb, |
| 755 |
NULL); |
| 756 |
|
| 757 |
/* Now extract a timeline from it */ |
| 758 |
timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), NULL)); |
| 759 |
fail_unless (GES_IS_TIMELINE (timeline)); |
| 760 |
|
| 761 |
g_main_loop_run (mainloop); |
| 762 |
|
| 763 |
g_free (uri); |
| 764 |
gst_object_unref (project); |
| 765 |
gst_object_unref (timeline); |
| 766 |
g_main_loop_unref (mainloop); |
| 767 |
} |
| 768 |
|
| 769 |
GST_END_TEST; |
| 770 |
#endif |
| 771 |
|
| 772 |
static Suite * |
| 773 |
ges_suite (void) |
| 774 |
{ |
| 775 |
Suite *s = suite_create ("ges-project"); |
| 776 |
TCase *tc_chain = tcase_create ("project"); |
| 777 |
|
| 778 |
suite_add_tcase (s, tc_chain); |
| 779 |
|
| 780 |
tcase_add_test (tc_chain, test_project_simple); |
| 781 |
tcase_add_test (tc_chain, test_project_add_assets); |
| 782 |
tcase_add_test (tc_chain, test_project_load_xges); |
| 783 |
tcase_add_test (tc_chain, test_project_add_properties); |
| 784 |
tcase_add_test (tc_chain, test_project_auto_transition); |
| 785 |
/*tcase_add_test (tc_chain, test_load_xges_and_play); */ |
| 786 |
tcase_add_test (tc_chain, test_project_unexistant_effect); |
| 787 |
|
| 788 |
return s; |
| 789 |
} |
| 790 |
|
| 791 |
GST_CHECK_MAIN (ges); |