1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
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.
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.
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.
22 * SECTION: gestransitionclip
23 * @title: GESTransitionClip
24 * @short_description: Transition from one clip to another in a GESLayer
26 * Creates an object that mixes together the two underlying objects, A and B.
27 * The A object is assumed to have a higher prioirity (lower number) than the
28 * B object. At the transition in point, only A will be visible, and by the
29 * end only B will be visible.
31 * The shape of the video transition depends on the value of the "vtype"
32 * property. The default value is "crossfade". For audio, only "crossfade" is
35 * The ID of the ExtractableType is the nickname of the vtype property value. Note
36 * that this value can be changed after creation and the GESExtractable.asset value
37 * will be updated when needed.
41 #include "ges-internal.h"
43 struct _GESTransitionClipPrivate
45 GSList *video_transitions;
47 const gchar *vtype_name;
55 static GESTrackElement *_create_track_element (GESClip
56 * self, GESTrackType type);
57 static void _child_added (GESContainer * container,
58 GESTimelineElement * element);
59 static void _child_removed (GESContainer * container,
60 GESTimelineElement * element);
62 /* Internal methods */
64 ges_transition_clip_update_vtype_internal (GESClip *
65 self, GESVideoStandardTransitionType value, gboolean set_asset)
69 GEnumClass *enum_class;
70 const gchar *asset_id = NULL;
71 GESTransitionClip *trself = GES_TRANSITION_CLIP (self);
73 enum_class = g_type_class_peek (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
74 for (index = 0; index < enum_class->n_values; index++) {
75 if (enum_class->values[index].value == value) {
76 asset_id = enum_class->values[index].value_nick;
81 if (asset_id == NULL) {
82 GST_WARNING_OBJECT (self, "Wrong transition type value: %i can not set it",
88 for (tmp = trself->priv->video_transitions; tmp; tmp = tmp->next) {
89 if (!ges_video_transition_set_transition_type
90 (GES_VIDEO_TRANSITION (tmp->data), value))
94 trself->vtype = value;
95 trself->priv->vtype_name = asset_id;
98 /* We already checked the value, so we can be sure no error will accured */
99 ges_extractable_set_asset (GES_EXTRACTABLE (self),
100 ges_asset_request (GES_TYPE_TRANSITION_CLIP, asset_id, NULL));
104 /* GESExtractable interface overrides */
106 extractable_get_parameters_from_id (const gchar * id, guint * n_params)
108 GEnumClass *enum_class =
109 g_type_class_peek (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
110 GParameter *params = g_new0 (GParameter, 1);
111 GEnumValue *value = g_enum_get_value_by_nick (enum_class, id);
113 params[0].name = "vtype";
114 g_value_init (¶ms[0].value, GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
115 g_value_set_enum (¶ms[0].value, value->value);
122 extractable_check_id (GType type, const gchar * id)
125 GEnumClass *enum_class;
126 enum_class = g_type_class_peek (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
128 for (index = 0; index < enum_class->n_values; index++) {
129 if (g_strcmp0 (enum_class->values[index].value_nick, id) == 0)
130 return g_strdup (id);
137 extractable_get_id (GESExtractable * self)
140 GEnumClass *enum_class;
141 guint value = GES_TRANSITION_CLIP (self)->vtype;
143 enum_class = g_type_class_peek (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
144 for (index = 0; index < enum_class->n_values; index++) {
145 if (enum_class->values[index].value == value)
146 return g_strdup (enum_class->values[index].value_nick);
153 extractable_set_asset (GESExtractable * self, GESAsset * asset)
155 GEnumClass *enum_class;
156 GESVideoStandardTransitionType value;
157 GESTransitionClip *trans = GES_TRANSITION_CLIP (self);
158 const gchar *vtype = ges_asset_get_id (asset);
160 if (!(ges_clip_get_supported_formats (GES_CLIP (self)) &
161 GES_TRACK_TYPE_VIDEO)) {
165 /* Update the transition type if we actually changed it */
166 if (g_strcmp0 (vtype, trans->priv->vtype_name)) {
169 value = GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE;
170 enum_class = g_type_class_peek (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE);
172 /* Find the in value in use */
173 for (index = 0; index < enum_class->n_values; index++) {
174 if (g_strcmp0 (enum_class->values[index].value_nick, vtype) == 0) {
175 value = enum_class->values[index].value;
179 ges_transition_clip_update_vtype_internal (GES_CLIP (self), value, FALSE);
186 ges_extractable_interface_init (GESExtractableInterface * iface)
188 iface->check_id = (GESExtractableCheckId) extractable_check_id;
189 iface->get_id = extractable_get_id;
190 iface->get_parameters_from_id = extractable_get_parameters_from_id;
191 iface->can_update_asset = TRUE;
192 iface->set_asset_full = extractable_set_asset;
195 G_DEFINE_TYPE_WITH_CODE (GESTransitionClip,
196 ges_transition_clip, GES_TYPE_BASE_TRANSITION_CLIP,
197 G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
198 ges_extractable_interface_init));
201 ges_transition_clip_get_property (GObject * object,
202 guint property_id, GValue * value, GParamSpec * pspec)
204 GESTransitionClip *self = GES_TRANSITION_CLIP (object);
205 switch (property_id) {
207 g_value_set_enum (value, self->vtype);
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
215 ges_transition_clip_set_property (GObject * object,
216 guint property_id, const GValue * value, GParamSpec * pspec)
218 GESClip *self = GES_CLIP (object);
220 switch (property_id) {
222 ges_transition_clip_update_vtype_internal (self,
223 g_value_get_enum (value), TRUE);
226 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
231 ges_transition_clip_class_init (GESTransitionClipClass * klass)
233 GObjectClass *object_class = G_OBJECT_CLASS (klass);
234 GESClipClass *timobj_class = GES_CLIP_CLASS (klass);
235 GESContainerClass *container_class = GES_CONTAINER_CLASS (klass);
237 g_type_class_add_private (klass, sizeof (GESTransitionClipPrivate));
239 object_class->get_property = ges_transition_clip_get_property;
240 object_class->set_property = ges_transition_clip_set_property;
243 * GESTransitionClip:vtype:
245 * a #GESVideoStandardTransitionType representing the wipe to use
247 g_object_class_install_property (object_class, PROP_VTYPE,
248 g_param_spec_enum ("vtype", "VType",
249 "The SMPTE video wipe to use, or 0 for crossfade",
250 GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE,
251 GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE,
252 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
254 container_class->child_added = _child_added;
255 container_class->child_removed = _child_removed;
257 timobj_class->create_track_element = _create_track_element;
261 ges_transition_clip_init (GESTransitionClip * self)
264 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
265 GES_TYPE_TRANSITION_CLIP, GESTransitionClipPrivate);
267 self->vtype = GES_VIDEO_STANDARD_TRANSITION_TYPE_NONE;
268 self->priv->vtype_name = NULL;
272 _child_removed (GESContainer * container, GESTimelineElement * element)
274 GESTransitionClipPrivate *priv = GES_TRANSITION_CLIP (container)->priv;
276 /* If this is called, we should be sure the trackelement exists */
277 if (GES_IS_VIDEO_TRANSITION (element)) {
278 GST_DEBUG_OBJECT (container, "%" GST_PTR_FORMAT " removed", element);
279 priv->video_transitions = g_slist_remove (priv->video_transitions, element);
280 gst_object_unref (element);
285 _child_added (GESContainer * container, GESTimelineElement * element)
287 GESTransitionClipPrivate *priv = GES_TRANSITION_CLIP (container)->priv;
289 if (GES_IS_VIDEO_TRANSITION (element)) {
290 GST_DEBUG_OBJECT (container, "%" GST_PTR_FORMAT " added", element);
291 priv->video_transitions =
292 g_slist_prepend (priv->video_transitions, gst_object_ref (element));
296 static GESTrackElement *
297 _create_track_element (GESClip * clip, GESTrackType type)
299 GESTransitionClip *transition = (GESTransitionClip *) clip;
300 GESTrackElement *res = NULL;
301 GESTrackType supportedformats;
303 GST_DEBUG ("Creating a GESTransition");
305 supportedformats = ges_clip_get_supported_formats (clip);
306 if (type == GES_TRACK_TYPE_VIDEO) {
307 if (supportedformats == GES_TRACK_TYPE_UNKNOWN ||
308 supportedformats & GES_TRACK_TYPE_VIDEO) {
309 GESVideoTransition *trans;
311 trans = ges_video_transition_new ();
312 ges_video_transition_set_transition_type (trans, transition->vtype);
314 res = GES_TRACK_ELEMENT (trans);
316 GST_DEBUG ("Not creating transition as video track not on"
317 " supportedformats");
320 } else if (type == GES_TRACK_TYPE_AUDIO) {
322 if (supportedformats == GES_TRACK_TYPE_UNKNOWN ||
323 supportedformats & GES_TRACK_TYPE_AUDIO)
324 res = GES_TRACK_ELEMENT (ges_audio_transition_new ());
326 GST_DEBUG ("Not creating transition as audio track"
327 " not on supportedformats");
330 GST_WARNING ("Transitions don't handle this track type");
336 * ges_transition_clip_new:
337 * @vtype: the type of transition to create
339 * Creates a new #GESTransitionClip.
341 * Returns: (transfer floating) (nullable): a newly created #GESTransitionClip,
342 * or %NULL if something went wrong.
345 ges_transition_clip_new (GESVideoStandardTransitionType vtype)
349 GESTransitionClip *ret = NULL;
352 G_ENUM_CLASS (g_type_class_ref (GES_VIDEO_STANDARD_TRANSITION_TYPE_TYPE));
354 GST_ERROR ("Could not find the StandarTransitionType enum class");
358 value = g_enum_get_value (klass, vtype);
360 GST_ERROR ("Could not find enum value for %i", vtype);
364 ret = ges_transition_clip_new_for_nick (((gchar *) value->value_nick));
365 g_type_class_unref (klass);
371 * ges_transition_clip_new_for_nick:
372 * @nick: a string representing the type of transition to create
374 * Creates a new #GESTransitionClip for the provided @nick.
376 * Returns: (transfer floating) (nullable): The newly created #GESTransitionClip,
377 * or %NULL if something went wrong
381 ges_transition_clip_new_for_nick (gchar * nick)
383 GESTransitionClip *ret = NULL;
384 GESAsset *asset = ges_asset_request (GES_TYPE_TRANSITION_CLIP, nick, NULL);
387 ret = GES_TRANSITION_CLIP (ges_asset_extract (asset, NULL));
389 gst_object_unref (asset);
391 GST_WARNING ("No asset found for nick: %s", nick);