| 1 |
|
| 2 |
/* GStreamer Editing Services |
| 3 |
* Copyright (C) 2010 Edward Hervey <[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., 51 Franklin St, Fifth Floor, |
| 18 |
* Boston, MA 02110-1301, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "test-utils.h" |
| 22 |
#include <ges/ges.h> |
| 23 |
#include <gst/check/gstcheck.h> |
| 24 |
|
| 25 |
/* This test uri will eventually have to be fixed */ |
| 26 |
#define TEST_URI "blahblahblah" |
| 27 |
|
| 28 |
GST_START_TEST (test_transition_basic) |
| 29 |
{ |
| 30 |
GESTrack *track; |
| 31 |
GESTimeline *timeline; |
| 32 |
GESLayer *layer; |
| 33 |
GESTransitionClip *tr1, *tr2; |
| 34 |
GESTrackElement *trackelement; |
| 35 |
|
| 36 |
ges_init (); |
| 37 |
|
| 38 |
track = GES_TRACK (ges_video_track_new ()); |
| 39 |
layer = ges_layer_new (); |
| 40 |
timeline = ges_timeline_new (); |
| 41 |
fail_unless (track != NULL); |
| 42 |
fail_unless (layer != NULL); |
| 43 |
fail_unless (timeline != NULL); |
| 44 |
fail_unless (ges_timeline_add_layer (timeline, layer)); |
| 45 |
fail_unless (ges_timeline_add_track (timeline, track)); |
| 46 |
ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1); |
| 47 |
|
| 48 |
tr1 = ges_transition_clip_new (GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE); |
| 49 |
fail_unless (tr1 != 0); |
| 50 |
fail_unless (tr1->vtype == GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE); |
| 51 |
|
| 52 |
tr2 = ges_transition_clip_new_for_nick ((gchar *) "bar-wipe-lr"); |
| 53 |
fail_unless (tr2 != 0); |
| 54 |
fail_unless (tr2->vtype == 1); |
| 55 |
|
| 56 |
/* Make sure track element is created and vtype is set */ |
| 57 |
fail_unless (ges_layer_add_clip (layer, GES_CLIP (tr2))); |
| 58 |
assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (tr2)), 1); |
| 59 |
trackelement = GES_CONTAINER_CHILDREN (tr2)->data; |
| 60 |
fail_unless (trackelement != NULL); |
| 61 |
fail_unless (ges_video_transition_get_transition_type |
| 62 |
(GES_VIDEO_TRANSITION (trackelement)) == 1); |
| 63 |
|
| 64 |
gst_object_unref (tr1); |
| 65 |
gst_object_unref (timeline); |
| 66 |
|
| 67 |
ges_deinit (); |
| 68 |
} |
| 69 |
|
| 70 |
GST_END_TEST; |
| 71 |
|
| 72 |
GST_START_TEST (test_transition_properties) |
| 73 |
{ |
| 74 |
GESClip *clip; |
| 75 |
GESTrack *track; |
| 76 |
GESTimeline *timeline; |
| 77 |
GESLayer *layer; |
| 78 |
GESTrackElement *trackelement; |
| 79 |
|
| 80 |
ges_init (); |
| 81 |
|
| 82 |
clip = GES_CLIP (ges_transition_clip_new |
| 83 |
(GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE)); |
| 84 |
|
| 85 |
track = GES_TRACK (ges_video_track_new ()); |
| 86 |
layer = ges_layer_new (); |
| 87 |
timeline = ges_timeline_new (); |
| 88 |
fail_unless (track != NULL); |
| 89 |
fail_unless (layer != NULL); |
| 90 |
fail_unless (timeline != NULL); |
| 91 |
fail_unless (ges_timeline_add_layer (timeline, layer)); |
| 92 |
fail_unless (ges_timeline_add_track (timeline, track)); |
| 93 |
ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1); |
| 94 |
|
| 95 |
/* Set some properties */ |
| 96 |
g_object_set (clip, "start", (guint64) 42, "duration", (guint64) 51, |
| 97 |
"in-point", (guint64) 12, NULL); |
| 98 |
|
| 99 |
assert_equals_uint64 (_START (clip), 42); |
| 100 |
assert_equals_uint64 (_DURATION (clip), 51); |
| 101 |
assert_equals_uint64 (_INPOINT (clip), 12); |
| 102 |
|
| 103 |
fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip))); |
| 104 |
ges_timeline_commit (timeline); |
| 105 |
assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1); |
| 106 |
trackelement = GES_CONTAINER_CHILDREN (clip)->data; |
| 107 |
fail_unless (trackelement != NULL); |
| 108 |
|
| 109 |
/* Check that trackelement has the same properties */ |
| 110 |
assert_equals_uint64 (_START (trackelement), 42); |
| 111 |
assert_equals_uint64 (_DURATION (trackelement), 51); |
| 112 |
/* in-point is 0 since it does not have has-internal-source */ |
| 113 |
assert_equals_uint64 (_INPOINT (trackelement), 0); |
| 114 |
|
| 115 |
/* And let's also check that it propagated correctly to GNonLin */ |
| 116 |
nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 0, |
| 117 |
51, MIN_NLE_PRIO, TRUE); |
| 118 |
|
| 119 |
/* Change more properties, see if they propagate */ |
| 120 |
g_object_set (clip, "start", (guint64) 420, "duration", (guint64) 510, |
| 121 |
"in-point", (guint64) 120, NULL); |
| 122 |
ges_timeline_commit (timeline); |
| 123 |
assert_equals_uint64 (_START (clip), 420); |
| 124 |
assert_equals_uint64 (_DURATION (clip), 510); |
| 125 |
assert_equals_uint64 (_INPOINT (clip), 120); |
| 126 |
assert_equals_uint64 (_START (trackelement), 420); |
| 127 |
assert_equals_uint64 (_DURATION (trackelement), 510); |
| 128 |
assert_equals_uint64 (_INPOINT (trackelement), 0); |
| 129 |
|
| 130 |
/* And let's also check that it propagated correctly to GNonLin */ |
| 131 |
nle_object_check (ges_track_element_get_nleobject (trackelement), 420, 510, |
| 132 |
0, 510, MIN_NLE_PRIO + 0, TRUE); |
| 133 |
|
| 134 |
/* test changing vtype */ |
| 135 |
GST_DEBUG ("Setting to crossfade"); |
| 136 |
g_object_set (clip, "vtype", GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE, |
| 137 |
NULL); |
| 138 |
assert_equals_int (GES_TRANSITION_CLIP (clip)->vtype, |
| 139 |
GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE); |
| 140 |
assert_equals_int (ges_video_transition_get_transition_type |
| 141 |
(GES_VIDEO_TRANSITION (trackelement)), |
| 142 |
GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE); |
| 143 |
|
| 144 |
/* Check that changing from crossfade to anything else fails (it should |
| 145 |
* still be using crossfade */ |
| 146 |
GST_DEBUG ("Setting back to 1 (should fail)"); |
| 147 |
g_object_set (clip, "vtype", 1, NULL); |
| 148 |
|
| 149 |
assert_equals_int (GES_TRANSITION_CLIP (clip)->vtype, 1); |
| 150 |
assert_equals_int (ges_video_transition_get_transition_type |
| 151 |
(GES_VIDEO_TRANSITION (trackelement)), 1); |
| 152 |
|
| 153 |
GST_DEBUG ("Removing clip from layer"); |
| 154 |
gst_object_ref (clip); /* We do not want it to be destroyed */ |
| 155 |
ges_layer_remove_clip (layer, clip); |
| 156 |
|
| 157 |
g_object_set (clip, "vtype", 1, NULL); |
| 158 |
GST_DEBUG ("Read it to the layer"); |
| 159 |
fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip))); |
| 160 |
g_object_unref (clip); |
| 161 |
assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1); |
| 162 |
trackelement = GES_CONTAINER_CHILDREN (clip)->data; |
| 163 |
fail_unless (trackelement != NULL); |
| 164 |
|
| 165 |
/* The new track element should have taken the previously set transition |
| 166 |
* type (in this case 1) */ |
| 167 |
GST_DEBUG ("Setting to vtype:1"); |
| 168 |
assert_equals_int (ges_video_transition_get_transition_type |
| 169 |
(GES_VIDEO_TRANSITION (trackelement)), 1); |
| 170 |
assert_equals_int (GES_TRANSITION_CLIP (clip)->vtype, 1); |
| 171 |
|
| 172 |
check_destroyed (G_OBJECT (timeline), G_OBJECT (track), clip, NULL); |
| 173 |
|
| 174 |
ges_deinit (); |
| 175 |
} |
| 176 |
|
| 177 |
GST_END_TEST; |
| 178 |
|
| 179 |
static void |
| 180 |
notify_vtype_cb (GESTransitionClip * clip, GParamSpec * pspec, |
| 181 |
GESVideoStandardTransitionType * vtype) |
| 182 |
{ |
| 183 |
g_object_get (clip, "vtype", vtype, NULL); |
| 184 |
} |
| 185 |
|
| 186 |
GST_START_TEST (test_transition_notify_vtype) |
| 187 |
{ |
| 188 |
GESTransitionClip *tclip; |
| 189 |
GESAsset *asset; |
| 190 |
GESVideoStandardTransitionType vtype = |
| 191 |
GES_VIDEO_STANDARD_TRANSITION_TYPE_NONE; |
| 192 |
|
| 193 |
tclip = ges_transition_clip_new (vtype); |
| 194 |
g_signal_connect (tclip, "notify::vtype", G_CALLBACK (notify_vtype_cb), |
| 195 |
&vtype); |
| 196 |
|
| 197 |
g_object_set (tclip, "vtype", GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE, |
| 198 |
NULL); |
| 199 |
assert_equals_int (vtype, GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE); |
| 200 |
|
| 201 |
asset = ges_asset_request (GES_TYPE_TRANSITION_CLIP, "fade-in", NULL); |
| 202 |
g_assert_true (ges_extractable_set_asset (GES_EXTRACTABLE (tclip), asset)); |
| 203 |
assert_equals_int (vtype, GES_VIDEO_STANDARD_TRANSITION_TYPE_FADE_IN); |
| 204 |
|
| 205 |
gst_object_unref (asset); |
| 206 |
gst_object_unref (tclip); |
| 207 |
} |
| 208 |
|
| 209 |
GST_END_TEST; |
| 210 |
|
| 211 |
static Suite * |
| 212 |
ges_suite (void) |
| 213 |
{ |
| 214 |
Suite *s = suite_create ("ges-transition"); |
| 215 |
TCase *tc_chain = tcase_create ("transition"); |
| 216 |
|
| 217 |
suite_add_tcase (s, tc_chain); |
| 218 |
|
| 219 |
tcase_add_test (tc_chain, test_transition_basic); |
| 220 |
tcase_add_test (tc_chain, test_transition_properties); |
| 221 |
tcase_add_test (tc_chain, test_transition_notify_vtype); |
| 222 |
|
| 223 |
return s; |
| 224 |
} |
| 225 |
|
| 226 |
GST_CHECK_MAIN (ges); |