1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
5 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 * @short_description: Base Class for objects in a GESLayer
28 * A #GESClip is a 'natural' object which controls one or more
29 * #GESTrackElement(s) in one or more #GESTrack(s).
31 * Keeps a reference to the #GESTrackElement(s) it created and
32 * sets/updates their properties.
40 #include "ges-internal.h"
44 static GList *ges_clip_create_track_elements_func (GESClip * clip,
46 static gboolean _ripple (GESTimelineElement * element, GstClockTime start);
47 static gboolean _ripple_end (GESTimelineElement * element, GstClockTime end);
48 static gboolean _roll_start (GESTimelineElement * element, GstClockTime start);
49 static gboolean _roll_end (GESTimelineElement * element, GstClockTime end);
50 static gboolean _trim (GESTimelineElement * element, GstClockTime start);
51 static void _compute_height (GESContainer * container);
53 struct _GESClipPrivate
61 GList *copied_track_elements;
62 GESLayer *copied_layer;
64 /* The formats supported by this Clip */
65 GESTrackType supportedformats;
68 typedef struct _CheckTrack
71 GESTrackElement *source;
78 PROP_SUPPORTED_FORMATS,
82 static GParamSpec *properties[PROP_LAST];
84 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GESClip, ges_clip, GES_TYPE_CONTAINER);
86 /****************************************************
87 * Listen to our children *
88 ****************************************************/
90 /* @min_priority: The absolute minimum priority a child of @container should have
91 * @max_priority: The absolute maximum priority a child of @container should have
94 _get_priority_range (GESContainer * container, guint32 * min_priority,
95 guint32 * max_priority)
97 GESLayer *layer = GES_CLIP (container)->priv->layer;
100 *min_priority = _PRIORITY (container) + layer->min_nle_priority;
101 *max_priority = layer->max_nle_priority;
103 *min_priority = _PRIORITY (container) + MIN_NLE_PRIO;
104 *max_priority = G_MAXUINT32;
109 _child_priority_changed_cb (GESTimelineElement * child,
110 GParamSpec * arg G_GNUC_UNUSED, GESContainer * container)
112 guint32 min_prio, max_prio;
114 GST_DEBUG_OBJECT (container, "TimelineElement %p priority changed to %i",
115 child, _PRIORITY (child));
117 if (container->children_control_mode == GES_CHILDREN_IGNORE_NOTIFIES)
121 _get_priority_range (container, &min_prio, &max_prio);
123 _ges_container_set_priority_offset (container, child,
124 min_prio - _PRIORITY (child));
127 /*****************************************************
129 * GESTimelineElement virtual methods implementation *
131 *****************************************************/
134 _set_start (GESTimelineElement * element, GstClockTime start)
137 GESContainer *container = GES_CONTAINER (element);
139 GST_DEBUG_OBJECT (element, "Setting children start, (initiated_move: %"
140 GST_PTR_FORMAT ")", container->initiated_move);
142 element->start = start;
143 g_object_notify (G_OBJECT (element), "start");
144 container->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
145 for (tmp = container->children; tmp; tmp = g_list_next (tmp)) {
146 GESTimelineElement *child = (GESTimelineElement *) tmp->data;
148 _set_start0 (GES_TIMELINE_ELEMENT (child), start);
150 container->children_control_mode = GES_CHILDREN_UPDATE;
156 _set_inpoint (GESTimelineElement * element, GstClockTime inpoint)
159 GESContainer *container = GES_CONTAINER (element);
161 container->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
162 for (tmp = container->children; tmp; tmp = g_list_next (tmp)) {
163 GESTimelineElement *child = (GESTimelineElement *) tmp->data;
165 if (child != container->initiated_move) {
166 _set_inpoint0 (child, inpoint);
169 container->children_control_mode = GES_CHILDREN_UPDATE;
175 _set_duration (GESTimelineElement * element, GstClockTime duration)
179 GESContainer *container = GES_CONTAINER (element);
181 container->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
182 for (tmp = container->children; tmp; tmp = g_list_next (tmp)) {
183 GESTimelineElement *child = (GESTimelineElement *) tmp->data;
185 if (child != container->initiated_move)
186 _set_duration0 (GES_TIMELINE_ELEMENT (child), duration);
188 container->children_control_mode = GES_CHILDREN_UPDATE;
194 _set_max_duration (GESTimelineElement * element, GstClockTime maxduration)
198 for (tmp = GES_CONTAINER (element)->children; tmp; tmp = g_list_next (tmp))
199 ges_timeline_element_set_max_duration (GES_TIMELINE_ELEMENT (tmp->data),
206 _set_priority (GESTimelineElement * element, guint32 priority)
209 guint32 min_prio, max_prio;
211 GESContainer *container = GES_CONTAINER (element);
213 _get_priority_range (container, &min_prio, &max_prio);
215 container->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
216 for (tmp = container->children; tmp; tmp = g_list_next (tmp)) {
217 guint32 track_element_prio;
218 GESTimelineElement *child = (GESTimelineElement *) tmp->data;
219 gint off = _ges_container_get_priority_offset (container, child);
222 if (off >= LAYER_HEIGHT) {
223 GST_ERROR ("%s child %s as a priority offset %d >= LAYER_HEIGHT %d"
224 " ==> clamping it to 0", GES_TIMELINE_ELEMENT_NAME (element),
225 GES_TIMELINE_ELEMENT_NAME (child), off, LAYER_HEIGHT);
229 /* We need to remove our current priority from @min_prio
230 * as it is the absolute minimum priority @child could have
231 * before we set @container to @priority.
233 track_element_prio = min_prio - _PRIORITY (container) + priority - off;
235 if (track_element_prio > max_prio) {
236 GST_WARNING ("%p priority of %i, is outside of the its containing "
237 "layer space. (%d/%d) setting it to the maximum it can be",
238 container, priority, min_prio - _PRIORITY (container) + priority,
241 track_element_prio = max_prio;
243 _set_priority0 (child, track_element_prio);
245 container->children_control_mode = GES_CHILDREN_UPDATE;
246 _compute_height (container);
252 _get_layer_priority (GESTimelineElement * element)
254 GESClip *clip = GES_CLIP (element);
256 if (clip->priv->layer == NULL)
257 return GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY;
259 return ges_layer_get_priority (clip->priv->layer);
262 /****************************************************
264 * GESContainer virtual methods implementation *
266 ****************************************************/
269 _compute_height (GESContainer * container)
272 guint32 min_prio = G_MAXUINT32, max_prio = 0;
274 if (container->children == NULL) {
275 /* FIXME Why not 0! */
276 _ges_container_set_height (container, 1);
280 /* Go over all childs and check if height has changed */
281 for (tmp = container->children; tmp; tmp = tmp->next) {
282 guint tck_priority = _PRIORITY (tmp->data);
284 if (tck_priority < min_prio)
285 min_prio = tck_priority;
286 if (tck_priority > max_prio)
287 max_prio = tck_priority;
290 _ges_container_set_height (container, max_prio - min_prio + 1);
294 _add_child (GESContainer * container, GESTimelineElement * element)
297 guint max_prio, min_prio;
298 GESClipPrivate *priv = GES_CLIP (container)->priv;
300 g_return_val_if_fail (GES_IS_TRACK_ELEMENT (element), FALSE);
302 /* First make sure we work with a sorted list of GESTimelineElement-s */
303 _ges_container_sort_children (container);
305 /* If the TrackElement is an effect:
306 * - We add it on top of the list of TrackEffect
307 * - We put all TrackElements present in the Clip
308 * which are not BaseEffect on top of them
309 * FIXME: Let the full control over priorities to the user
311 _get_priority_range (container, &min_prio, &max_prio);
312 if (GES_IS_BASE_EFFECT (element)) {
313 GESChildrenControlMode mode = container->children_control_mode;
315 GST_DEBUG_OBJECT (container, "Adding %ith effect: %" GST_PTR_FORMAT
316 " Priority %i", priv->nb_effects + 1, element,
317 min_prio + priv->nb_effects);
319 tmp = g_list_nth (GES_CONTAINER_CHILDREN (container), priv->nb_effects);
320 container->children_control_mode = GES_CHILDREN_UPDATE_OFFSETS;
321 for (; tmp; tmp = tmp->next) {
322 ges_timeline_element_set_priority (GES_TIMELINE_ELEMENT (tmp->data),
323 GES_TIMELINE_ELEMENT_PRIORITY (tmp->data) + 1);
326 _set_priority0 (element, min_prio + priv->nb_effects);
327 container->children_control_mode = mode;
330 /* We add the track element on top of the effect list */
331 _set_priority0 (element, min_prio + priv->nb_effects);
334 /* We set the timing value of the child to ours, we avoid infinite loop
335 * making sure the container ignore notifies from the child */
336 container->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
337 _set_start0 (element, GES_TIMELINE_ELEMENT_START (container));
338 _set_inpoint0 (element, GES_TIMELINE_ELEMENT_INPOINT (container));
339 _set_duration0 (element, GES_TIMELINE_ELEMENT_DURATION (container));
340 container->children_control_mode = GES_CHILDREN_UPDATE;
346 _remove_child (GESContainer * container, GESTimelineElement * element)
348 if (GES_IS_BASE_EFFECT (element)) {
349 GES_CLIP (container)->priv->nb_effects--;
352 GST_FIXME_OBJECT (container, "We should set other children prios");
358 _child_added (GESContainer * container, GESTimelineElement * element)
360 g_signal_connect (G_OBJECT (element), "notify::priority",
361 G_CALLBACK (_child_priority_changed_cb), container);
363 _child_priority_changed_cb (element, NULL, container);
364 _compute_height (container);
368 _child_removed (GESContainer * container, GESTimelineElement * element)
370 g_signal_handlers_disconnect_by_func (element, _child_priority_changed_cb,
373 if (GES_IS_BASE_EFFECT (element)) {
376 GESChildrenControlMode mode = container->children_control_mode;
378 GST_DEBUG_OBJECT (container, "Resyncing effects priority.");
380 container->children_control_mode = GES_CHILDREN_UPDATE_OFFSETS;
381 tmp = GES_CONTAINER_CHILDREN (container);
383 ges_timeline_element_get_priority (GES_TIMELINE_ELEMENT (element));
384 for (; tmp; tmp = tmp->next) {
385 if (ges_timeline_element_get_priority (GES_TIMELINE_ELEMENT (tmp->data)) >
387 ges_timeline_element_set_priority (GES_TIMELINE_ELEMENT (tmp->data),
388 GES_TIMELINE_ELEMENT_PRIORITY (tmp->data) - 1);
392 container->children_control_mode = mode;
395 _compute_height (container);
399 add_clip_to_list (gpointer key, gpointer clip, GList ** list)
401 *list = g_list_prepend (*list, gst_object_ref (clip));
405 _ungroup (GESContainer * container, gboolean recursive)
408 GESTrackType track_type;
409 GESTrackElement *track_element;
411 gboolean first_obj = TRUE;
412 GList *tmp, *children, *ret = NULL;
413 GESClip *clip = GES_CLIP (container);
414 GESTimelineElement *element = GES_TIMELINE_ELEMENT (container);
415 GESLayer *layer = clip->priv->layer;
416 GHashTable *_tracktype_clip = g_hash_table_new (g_int_hash, g_int_equal);
418 /* If there is no TrackElement, just return @container in a list */
419 if (GES_CONTAINER_CHILDREN (container) == NULL) {
420 GST_DEBUG ("No TrackElement, simply returning");
421 return g_list_prepend (ret, container);
424 /* We need a copy of the current list of tracks */
425 children = ges_container_get_children (container, FALSE);
426 for (tmp = children; tmp; tmp = tmp->next) {
427 track_element = GES_TRACK_ELEMENT (tmp->data);
428 track_type = ges_track_element_get_track_type (track_element);
430 tmpclip = g_hash_table_lookup (_tracktype_clip, &track_type);
431 if (tmpclip == NULL) {
432 if (G_UNLIKELY (first_obj == TRUE)) {
436 tmpclip = GES_CLIP (ges_timeline_element_copy (element, FALSE));
438 /* Add new container to the same layer as @container */
439 ges_clip_set_moving_from_layer (tmpclip, TRUE);
440 ges_layer_add_clip (layer, tmpclip);
441 ges_clip_set_moving_from_layer (tmpclip, FALSE);
445 g_hash_table_insert (_tracktype_clip, &track_type, tmpclip);
446 ges_clip_set_supported_formats (tmpclip, track_type);
449 /* Move trackelement to the container it is supposed to land into */
450 if (tmpclip != clip) {
451 /* We need to bump the refcount to avoid the object to be destroyed */
452 gst_object_ref (track_element);
453 ges_container_remove (container, GES_TIMELINE_ELEMENT (track_element));
454 ges_container_add (GES_CONTAINER (tmpclip),
455 GES_TIMELINE_ELEMENT (track_element));
456 gst_object_unref (track_element);
459 g_list_free_full (children, gst_object_unref);
460 g_hash_table_foreach (_tracktype_clip, (GHFunc) add_clip_to_list, &ret);
461 g_hash_table_unref (_tracktype_clip);
466 static GESContainer *
467 _group (GList * containers)
469 CheckTrack *tracks = NULL;
470 GESTimeline *timeline = NULL;
471 GESTrackType supported_formats;
472 GESLayer *layer = NULL;
473 GList *tmp, *tmpclip, *tmpelement;
474 GstClockTime start, inpoint, duration;
476 GESAsset *asset = NULL;
477 GESContainer *ret = NULL;
478 guint nb_tracks = 0, i = 0;
480 start = inpoint = duration = GST_CLOCK_TIME_NONE;
485 /* First check if all the containers are clips, if they
486 * all have the same start/inpoint/duration and are in the same
489 * We also need to make sure that all source have been created by the
490 * same asset, keep the information */
491 for (tmp = containers; tmp; tmp = tmp->next) {
493 GESTimeline *tmptimeline;
494 GESContainer *tmpcontainer;
495 GESTimelineElement *element;
497 tmpcontainer = GES_CONTAINER (tmp->data);
498 element = GES_TIMELINE_ELEMENT (tmp->data);
499 if (GES_IS_CLIP (element) == FALSE) {
500 GST_DEBUG ("Can only work with clips");
503 clip = GES_CLIP (tmp->data);
504 tmptimeline = GES_TIMELINE_ELEMENT_TIMELINE (element);
508 start = _START (tmpcontainer);
509 inpoint = _INPOINT (tmpcontainer);
510 duration = _DURATION (tmpcontainer);
511 timeline = tmptimeline;
512 layer = clip->priv->layer;
513 nb_tracks = g_list_length (GES_TIMELINE_GET_TRACKS (timeline));
514 tracks = g_new0 (CheckTrack, nb_tracks);
516 for (tmptrack = GES_TIMELINE_GET_TRACKS (timeline); tmptrack;
517 tmptrack = tmptrack->next) {
518 tracks[i].track = tmptrack->data;
522 if (start != _START (tmpcontainer) ||
523 inpoint != _INPOINT (tmpcontainer) ||
524 duration != _DURATION (tmpcontainer) || clip->priv->layer != layer) {
525 GST_INFO ("All children must have the same start, inpoint, duration "
526 " and be in the same layer");
532 for (tmp2 = GES_CONTAINER_CHILDREN (tmp->data); tmp2; tmp2 = tmp2->next) {
533 GESTrackElement *track_element = GES_TRACK_ELEMENT (tmp2->data);
535 if (GES_IS_SOURCE (track_element)) {
538 for (i = 0; i < nb_tracks; i++) {
539 if (tracks[i].track ==
540 ges_track_element_get_track (track_element)) {
541 if (tracks[i].source) {
542 GST_INFO ("Can not link clips with various source for a "
547 tracks[i].source = track_element;
558 /* Then check that all sources have been created by the same asset,
559 * otherwise we can not group */
560 for (i = 0; i < nb_tracks; i++) {
561 if (tracks[i].source == NULL) {
562 GST_FIXME ("Check what to do here as we might end up having a mess");
567 /* FIXME Check what to do if we have source that have no assets */
570 ges_extractable_get_asset (GES_EXTRACTABLE
571 (ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (tracks
576 ges_extractable_get_asset (GES_EXTRACTABLE
577 (ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (tracks
579 GST_INFO ("Can not link clips with source coming from different assets");
585 /* And now pass all TrackElements to the first clip,
586 * and remove others from the layer (updating the supported formats) */
587 ret = containers->data;
588 supported_formats = GES_CLIP (ret)->priv->supportedformats;
589 for (tmpclip = containers->next; tmpclip; tmpclip = tmpclip->next) {
590 GESClip *cclip = tmpclip->data;
591 GList *children = ges_container_get_children (GES_CONTAINER (cclip), FALSE);
593 for (tmpelement = children; tmpelement; tmpelement = tmpelement->next) {
594 GESTimelineElement *celement = GES_TIMELINE_ELEMENT (tmpelement->data);
596 ges_container_remove (GES_CONTAINER (cclip), celement);
597 ges_container_add (ret, celement);
599 supported_formats = supported_formats |
600 ges_track_element_get_track_type (GES_TRACK_ELEMENT (celement));
602 g_list_free_full (children, gst_object_unref);
604 ges_layer_remove_clip (layer, tmpclip->data);
607 ges_clip_set_supported_formats (GES_CLIP (ret), supported_formats);
619 _edit (GESContainer * container, GList * layers,
620 gint new_layer_priority, GESEditMode mode, GESEdge edge, guint64 position)
622 GESTimeline *timeline = GES_TIMELINE_ELEMENT_TIMELINE (container);
623 GESTimelineElement *element = GES_TIMELINE_ELEMENT (container);
625 if (!G_UNLIKELY (GES_CONTAINER_CHILDREN (container))) {
626 GST_WARNING_OBJECT (container, "Trying to edit, but not containing"
627 "any TrackElement yet.");
632 GST_WARNING_OBJECT (container, "Trying to edit, but not in any"
638 case GES_EDIT_MODE_RIPPLE:
639 return timeline_ripple_object (timeline, element,
641 0 ? GES_TIMELINE_ELEMENT_LAYER_PRIORITY (container) :
642 new_layer_priority, layers, edge, position);
643 case GES_EDIT_MODE_TRIM:
644 return timeline_trim_object (timeline, element,
646 0 ? GES_TIMELINE_ELEMENT_LAYER_PRIORITY (container) :
647 new_layer_priority, layers, edge, position);
648 case GES_EDIT_MODE_NORMAL:
649 return timeline_move_object (timeline, element,
651 0 ? GES_TIMELINE_ELEMENT_LAYER_PRIORITY (container) :
652 new_layer_priority, layers, edge, position);
653 case GES_EDIT_MODE_ROLL:
654 return timeline_roll_object (timeline, element, layers, edge, position);
655 case GES_EDIT_MODE_SLIDE:
656 GST_ERROR ("Sliding not implemented.");
663 _deep_copy (GESTimelineElement * element, GESTimelineElement * copy)
666 GESClip *self = GES_CLIP (element), *ccopy = GES_CLIP (copy);
668 for (tmp = GES_CONTAINER_CHILDREN (element); tmp; tmp = tmp->next) {
669 ccopy->priv->copied_track_elements =
670 g_list_append (ccopy->priv->copied_track_elements,
671 ges_timeline_element_copy (tmp->data, TRUE));
674 if (self->priv->copied_layer)
675 ccopy->priv->copied_layer = g_object_ref (self->priv->copied_layer);
676 else if (self->priv->layer)
677 ccopy->priv->copied_layer = g_object_ref (self->priv->layer);
680 static GESTimelineElement *
681 _paste (GESTimelineElement * element, GESTimelineElement * ref,
682 GstClockTime paste_position)
685 GESClip *self = GES_CLIP (element);
686 GESClip *nclip = GES_CLIP (ges_timeline_element_copy (element, FALSE));
688 if (self->priv->copied_layer)
689 nclip->priv->copied_layer = g_object_ref (self->priv->copied_layer);
691 ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (nclip), paste_position);
692 if (self->priv->copied_layer) {
693 if (!ges_layer_add_clip (self->priv->copied_layer, nclip)) {
694 GST_INFO ("%" GES_FORMAT " could not be pasted to %" GST_TIME_FORMAT,
695 GES_ARGS (element), GST_TIME_ARGS (paste_position));
696 gst_object_unref (nclip);
703 for (tmp = self->priv->copied_track_elements; tmp; tmp = tmp->next) {
704 GESTrackElement *new_trackelement, *trackelement =
705 GES_TRACK_ELEMENT (tmp->data);
708 GES_TRACK_ELEMENT (ges_timeline_element_copy (GES_TIMELINE_ELEMENT
709 (trackelement), FALSE));
710 if (new_trackelement == NULL) {
711 GST_WARNING_OBJECT (trackelement, "Could not create a copy");
715 ges_container_add (GES_CONTAINER (nclip),
716 GES_TIMELINE_ELEMENT (new_trackelement));
718 ges_track_element_copy_properties (GES_TIMELINE_ELEMENT (trackelement),
719 GES_TIMELINE_ELEMENT (new_trackelement));
721 ges_track_element_copy_bindings (trackelement, new_trackelement,
722 GST_CLOCK_TIME_NONE);
725 return GES_TIMELINE_ELEMENT (nclip);
729 _lookup_child (GESTimelineElement * self, const gchar * prop_name,
730 GObject ** child, GParamSpec ** pspec)
734 if (GES_TIMELINE_ELEMENT_CLASS (ges_clip_parent_class)->lookup_child (self,
735 prop_name, child, pspec))
738 for (tmp = GES_CONTAINER_CHILDREN (self); tmp; tmp = tmp->next) {
739 if (ges_timeline_element_lookup_child (tmp->data, prop_name, child, pspec))
746 /****************************************************
748 * GObject virtual methods implementation *
750 ****************************************************/
752 ges_clip_get_property (GObject * object, guint property_id,
753 GValue * value, GParamSpec * pspec)
755 GESClip *clip = GES_CLIP (object);
757 switch (property_id) {
759 g_value_set_object (value, clip->priv->layer);
761 case PROP_SUPPORTED_FORMATS:
762 g_value_set_flags (value, clip->priv->supportedformats);
765 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
770 ges_clip_set_property (GObject * object, guint property_id,
771 const GValue * value, GParamSpec * pspec)
773 GESClip *clip = GES_CLIP (object);
775 switch (property_id) {
776 case PROP_SUPPORTED_FORMATS:
777 ges_clip_set_supported_formats (clip, g_value_get_flags (value));
780 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
785 ges_clip_dispose (GObject * object)
787 GESClip *self = GES_CLIP (object);
789 g_list_free_full (self->priv->copied_track_elements, g_object_unref);
790 self->priv->copied_track_elements = NULL;
791 g_clear_object (&self->priv->copied_layer);
793 G_OBJECT_CLASS (ges_clip_parent_class)->dispose (object);
798 ges_clip_class_init (GESClipClass * klass)
800 GObjectClass *object_class = G_OBJECT_CLASS (klass);
801 GESContainerClass *container_class = GES_CONTAINER_CLASS (klass);
802 GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
804 object_class->get_property = ges_clip_get_property;
805 object_class->set_property = ges_clip_set_property;
806 object_class->dispose = ges_clip_dispose;
807 klass->create_track_elements = ges_clip_create_track_elements_func;
808 klass->create_track_element = NULL;
811 * GESClip:supported-formats:
813 * The formats supported by the clip.
815 properties[PROP_SUPPORTED_FORMATS] = g_param_spec_flags ("supported-formats",
816 "Supported formats", "Formats supported by the file",
817 GES_TYPE_TRACK_TYPE, GES_TRACK_TYPE_AUDIO | GES_TRACK_TYPE_VIDEO,
818 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
820 g_object_class_install_property (object_class, PROP_SUPPORTED_FORMATS,
821 properties[PROP_SUPPORTED_FORMATS]);
826 * The GESLayer where this clip is being used. If you want to connect to its
827 * notify signal you should connect to it with g_signal_connect_after as the
828 * signal emission can be stop in the first fase.
830 properties[PROP_LAYER] = g_param_spec_object ("layer", "Layer",
831 "The GESLayer where this clip is being used.",
832 GES_TYPE_LAYER, G_PARAM_READABLE);
833 g_object_class_install_property (object_class, PROP_LAYER,
834 properties[PROP_LAYER]);
836 element_class->ripple = _ripple;
837 element_class->ripple_end = _ripple_end;
838 element_class->roll_start = _roll_start;
839 element_class->roll_end = _roll_end;
840 element_class->trim = _trim;
841 element_class->set_start = _set_start;
842 element_class->set_duration = _set_duration;
843 element_class->set_inpoint = _set_inpoint;
844 element_class->set_priority = _set_priority;
845 element_class->set_max_duration = _set_max_duration;
846 element_class->paste = _paste;
847 element_class->deep_copy = _deep_copy;
848 element_class->lookup_child = _lookup_child;
849 element_class->get_layer_priority = _get_layer_priority;
851 container_class->add_child = _add_child;
852 container_class->remove_child = _remove_child;
853 container_class->child_removed = _child_removed;
854 container_class->child_added = _child_added;
855 container_class->ungroup = _ungroup;
856 container_class->group = _group;
857 container_class->grouping_priority = G_MAXUINT;
858 container_class->edit = _edit;
862 ges_clip_init (GESClip * self)
864 self->priv = ges_clip_get_instance_private (self);
865 self->priv->layer = NULL;
866 self->priv->nb_effects = 0;
870 * ges_clip_create_track_element:
871 * @clip: The origin #GESClip
872 * @type: The #GESTrackType to create a #GESTrackElement for.
874 * Creates a #GESTrackElement for the provided @type. The clip
875 * keep a reference to the newly created trackelement, you therefore need to
876 * call @ges_container_remove when you are done with it.
878 * Returns: (transfer none) (nullable): A #GESTrackElement. Returns NULL if
879 * the #GESTrackElement could not be created.
882 ges_clip_create_track_element (GESClip * clip, GESTrackType type)
885 GESTrackElement *res;
887 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
889 GST_DEBUG_OBJECT (clip, "Creating track element for %s",
890 ges_track_type_name (type));
891 if (!(type & clip->priv->supportedformats)) {
892 GST_DEBUG_OBJECT (clip, "We don't support this track type %i", type);
896 class = GES_CLIP_GET_CLASS (clip);
898 if (G_UNLIKELY (class->create_track_element == NULL)) {
899 GST_ERROR ("No 'create_track_element' implementation available fo type %s",
900 G_OBJECT_TYPE_NAME (clip));
904 res = class->create_track_element (clip, type);
910 * ges_clip_create_track_elements:
911 * @clip: The origin #GESClip
912 * @type: The #GESTrackType to create each #GESTrackElement for.
914 * Creates all #GESTrackElements supported by this clip for the track type.
916 * Returns: (element-type GESTrackElement) (transfer full): A #GList of
917 * newly created #GESTrackElement-s
921 ges_clip_create_track_elements (GESClip * clip, GESTrackType type)
923 GList *result = NULL, *tmp, *children;
925 guint max_prio, min_prio;
926 gboolean readding_effects_only = TRUE;
928 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
930 klass = GES_CLIP_GET_CLASS (clip);
932 if (!(klass->create_track_elements)) {
933 GST_WARNING ("no GESClip::create_track_elements implentation");
937 GST_DEBUG_OBJECT (clip, "Creating TrackElements for type: %s",
938 ges_track_type_name (type));
939 children = ges_container_get_children (GES_CONTAINER (clip), TRUE);
940 for (tmp = children; tmp; tmp = tmp->next) {
941 GESTrackElement *child = GES_TRACK_ELEMENT (tmp->data);
943 if (!ges_track_element_get_track (child)
944 && ges_track_element_get_track_type (child) & type) {
946 GST_DEBUG_OBJECT (clip, "Removing for reusage: %" GST_PTR_FORMAT, child);
947 result = g_list_append (result, g_object_ref (child));
948 ges_container_remove (GES_CONTAINER (clip), tmp->data);
949 if (!GES_IS_BASE_EFFECT (child))
950 readding_effects_only = FALSE;
953 g_list_free_full (children, gst_object_unref);
955 if (readding_effects_only) {
956 result = g_list_concat (result, klass->create_track_elements (clip, type));
959 _get_priority_range (GES_CONTAINER (clip), &min_prio, &max_prio);
960 for (tmp = result; tmp; tmp = tmp->next) {
961 GESTimelineElement *elem = tmp->data;
963 _set_start0 (elem, GES_TIMELINE_ELEMENT_START (clip));
964 _set_inpoint0 (elem, GES_TIMELINE_ELEMENT_INPOINT (clip));
965 _set_duration0 (elem, GES_TIMELINE_ELEMENT_DURATION (clip));
967 if (GST_CLOCK_TIME_IS_VALID (GES_TIMELINE_ELEMENT_MAX_DURATION (clip)))
968 ges_timeline_element_set_max_duration (GES_TIMELINE_ELEMENT (elem),
969 GES_TIMELINE_ELEMENT_MAX_DURATION (clip));
971 _set_priority0 (elem, min_prio + clip->priv->nb_effects);
973 ges_container_add (GES_CONTAINER (clip), elem);
980 * default implementation of GESClipClass::create_track_elements
983 ges_clip_create_track_elements_func (GESClip * clip, GESTrackType type)
985 GESTrackElement *result;
987 GST_DEBUG_OBJECT (clip, "Creating trackelement for track: %s",
988 ges_track_type_name (type));
989 result = ges_clip_create_track_element (clip, type);
991 GST_DEBUG ("Did not create track element");
995 return g_list_append (NULL, result);
999 ges_clip_set_layer (GESClip * clip, GESLayer * layer)
1001 if (layer == clip->priv->layer)
1004 clip->priv->layer = layer;
1006 GST_DEBUG ("clip:%p, layer:%p", clip, layer);
1008 /* We do not want to notify the setting of layer = NULL when
1009 * it is actually the result of a move between layer (as we know
1010 * that it will be added to another layer right after, and this
1011 * is what imports here.) */
1012 if (!ELEMENT_FLAG_IS_SET (clip, GES_CLIP_IS_MOVING))
1013 g_object_notify_by_pspec (G_OBJECT (clip), properties[PROP_LAYER]);
1017 * ges_clip_set_moving_from_layer:
1019 * @is_moving: %TRUE if you want to start moving @clip to another layer
1020 * %FALSE when you finished moving it.
1022 * Sets the clip in a moving to layer state. You might rather use the
1023 * ges_clip_move_to_layer function to move #GESClip-s
1024 * from a layer to another.
1027 ges_clip_set_moving_from_layer (GESClip * clip, gboolean is_moving)
1029 g_return_if_fail (GES_IS_CLIP (clip));
1032 ELEMENT_SET_FLAG (clip, GES_CLIP_IS_MOVING);
1034 ELEMENT_UNSET_FLAG (clip, GES_CLIP_IS_MOVING);
1038 * ges_clip_is_moving_from_layer:
1041 * Tells you if the clip is currently moving from a layer to another.
1042 * You might rather use the ges_clip_move_to_layer function to
1043 * move #GESClip-s from a layer to another.
1045 * Returns: %TRUE if @clip is currently moving from its current layer
1049 ges_clip_is_moving_from_layer (GESClip * clip)
1051 g_return_val_if_fail (GES_IS_CLIP (clip), FALSE);
1053 return ELEMENT_FLAG_IS_SET (clip, GES_CLIP_IS_MOVING);
1057 * ges_clip_move_to_layer:
1059 * @layer: the new #GESLayer
1061 * Moves @clip to @layer. If @clip is not in any layer, it adds it to
1062 * @layer, else, it removes it from its current layer, and adds it to @layer.
1064 * Returns: %TRUE if @clip could be moved %FALSE otherwize
1067 ges_clip_move_to_layer (GESClip * clip, GESLayer * layer)
1070 GESLayer *current_layer;
1072 g_return_val_if_fail (GES_IS_CLIP (clip), FALSE);
1073 g_return_val_if_fail (GES_IS_LAYER (layer), FALSE);
1075 ELEMENT_SET_FLAG (clip, GES_CLIP_IS_MOVING);
1077 && !timeline_tree_can_move_element (timeline_get_tree (layer->timeline),
1078 GES_TIMELINE_ELEMENT (clip),
1079 ges_layer_get_priority (layer),
1080 GES_TIMELINE_ELEMENT_START (clip),
1081 GES_TIMELINE_ELEMENT_DURATION (clip), NULL)) {
1082 GST_INFO_OBJECT (layer, "Clip %" GES_FORMAT " can't move to layer %d",
1083 GES_ARGS (clip), ges_layer_get_priority (layer));
1084 ELEMENT_UNSET_FLAG (clip, GES_CLIP_IS_MOVING);
1088 current_layer = clip->priv->layer;
1090 if (current_layer == NULL) {
1091 GST_DEBUG ("Not moving %p, only adding it to %p", clip, layer);
1093 return ges_layer_add_clip (layer, clip);
1096 GST_DEBUG_OBJECT (clip, "moving to layer %p, priority: %d", layer,
1097 ges_layer_get_priority (layer));
1099 gst_object_ref (clip);
1100 ret = ges_layer_remove_clip (current_layer, clip);
1103 ELEMENT_UNSET_FLAG (clip, GES_CLIP_IS_MOVING);
1104 gst_object_unref (clip);
1108 ret = ges_layer_add_clip (layer, clip);
1109 ELEMENT_UNSET_FLAG (clip, GES_CLIP_IS_MOVING);
1111 gst_object_unref (clip);
1112 g_object_notify_by_pspec (G_OBJECT (clip), properties[PROP_LAYER]);
1115 return ret && (clip->priv->layer == layer);
1119 * ges_clip_find_track_element:
1121 * @track: (allow-none): a #GESTrack or NULL
1122 * @type: a #GType indicating the type of track element you are looking
1123 * for or %G_TYPE_NONE if you do not care about the track type.
1125 * Finds the #GESTrackElement controlled by @clip that is used in @track. You
1126 * may optionally specify a GType to further narrow search criteria.
1128 * Note: If many objects match, then the one with the highest priority will be
1131 * Returns: (transfer full) (nullable): The #GESTrackElement used by @track,
1132 * else %NULL. Unref after usage
1136 ges_clip_find_track_element (GESClip * clip, GESTrack * track, GType type)
1139 GESTrackElement *otmp;
1141 GESTrackElement *ret = NULL;
1143 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
1144 g_return_val_if_fail (!(track == NULL && type == G_TYPE_NONE), NULL);
1146 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = g_list_next (tmp)) {
1147 otmp = (GESTrackElement *) tmp->data;
1149 if ((type != G_TYPE_NONE) && !G_TYPE_CHECK_INSTANCE_TYPE (tmp->data, type))
1152 if ((track == NULL) || (ges_track_element_get_track (otmp) == track)) {
1153 ret = GES_TRACK_ELEMENT (tmp->data);
1154 gst_object_ref (ret);
1163 * ges_clip_get_layer:
1166 * Get the #GESLayer to which this clip belongs.
1168 * Returns: (transfer full) (nullable): The #GESLayer where this @clip is being
1169 * used, or %NULL if it is not used on any layer. The caller should unref it
1173 ges_clip_get_layer (GESClip * clip)
1175 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
1177 if (clip->priv->layer != NULL)
1178 gst_object_ref (G_OBJECT (clip->priv->layer));
1180 return clip->priv->layer;
1184 * ges_clip_get_top_effects:
1185 * @clip: The origin #GESClip
1187 * Get effects applied on @clip
1189 * Returns: (transfer full) (element-type GESTrackElement): a #GList of the
1190 * #GESBaseEffect that are applied on @clip order by ascendant priorities.
1191 * The refcount of the objects will be increased. The user will have to
1192 * unref each #GESBaseEffect and free the #GList.
1195 ges_clip_get_top_effects (GESClip * clip)
1200 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
1202 GST_DEBUG_OBJECT (clip, "Getting the %i top effects", clip->priv->nb_effects);
1205 for (tmp = GES_CONTAINER_CHILDREN (clip), i = 0;
1206 i < clip->priv->nb_effects; tmp = tmp->next, i++) {
1207 ret = g_list_append (ret, gst_object_ref (tmp->data));
1210 return g_list_sort (ret, (GCompareFunc) element_start_compare);
1214 * ges_clip_get_top_effect_index:
1215 * @clip: The origin #GESClip
1216 * @effect: The #GESBaseEffect we want to get the top index from
1218 * Gets the index position of an effect.
1220 * Returns: The top index of the effect, -1 if something went wrong.
1223 ges_clip_get_top_effect_index (GESClip * clip, GESBaseEffect * effect)
1225 guint max_prio, min_prio;
1227 g_return_val_if_fail (GES_IS_CLIP (clip), -1);
1228 g_return_val_if_fail (GES_IS_BASE_EFFECT (effect), -1);
1230 _get_priority_range (GES_CONTAINER (clip), &min_prio, &max_prio);
1232 return GES_TIMELINE_ELEMENT_PRIORITY (effect) - min_prio;
1235 /* TODO 2.0 remove as it is Deprecated */
1237 ges_clip_get_top_effect_position (GESClip * clip, GESBaseEffect * effect)
1239 return ges_clip_get_top_effect_index (clip, effect);
1242 /* TODO 2.0 remove as it is Deprecated */
1244 ges_clip_set_top_effect_priority (GESClip * clip,
1245 GESBaseEffect * effect, guint newpriority)
1247 return ges_clip_set_top_effect_index (clip, effect, newpriority);
1251 * ges_clip_set_top_effect_index:
1252 * @clip: The origin #GESClip
1253 * @effect: The #GESBaseEffect to move
1254 * @newindex: the new index at which to move the @effect inside this
1257 * This is a convenience method that lets you set the index of a top effect.
1259 * Returns: %TRUE if @effect was successfuly moved, %FALSE otherwise.
1262 ges_clip_set_top_effect_index (GESClip * clip, GESBaseEffect * effect,
1267 guint current_prio, min_prio, max_prio;
1268 GESTrackElement *track_element;
1270 g_return_val_if_fail (GES_IS_CLIP (clip), FALSE);
1272 track_element = GES_TRACK_ELEMENT (effect);
1273 current_prio = _PRIORITY (track_element);
1275 _get_priority_range (GES_CONTAINER (clip), &min_prio, &max_prio);
1277 newindex = newindex + min_prio;
1278 /* We don't change the priority */
1279 if (current_prio == newindex)
1282 if (G_UNLIKELY (GES_CLIP (GES_TIMELINE_ELEMENT_PARENT (track_element)) !=
1286 if (newindex > (clip->priv->nb_effects - 1 + min_prio)) {
1287 GST_DEBUG ("You are trying to make %p not a top effect", effect);
1291 if (current_prio > clip->priv->nb_effects + min_prio) {
1292 GST_ERROR ("%p is not a top effect", effect);
1296 _ges_container_sort_children (GES_CONTAINER (clip));
1297 if (_PRIORITY (track_element) < newindex)
1302 GST_DEBUG_OBJECT (clip, "Setting top effect %" GST_PTR_FORMAT "priority: %i",
1305 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next) {
1306 GESTrackElement *tmpo = GES_TRACK_ELEMENT (tmp->data);
1307 guint tck_priority = _PRIORITY (tmpo);
1309 if (tmpo == track_element)
1312 if ((inc == +1 && tck_priority >= newindex) ||
1313 (inc == -1 && tck_priority <= newindex)) {
1314 _set_priority0 (GES_TIMELINE_ELEMENT (tmpo), tck_priority + inc);
1317 _set_priority0 (GES_TIMELINE_ELEMENT (track_element), newindex);
1324 * @clip: the #GESClip to split
1325 * @position: a #GstClockTime representing the timeline position at which to split
1327 * The function modifies @clip, and creates another #GESClip so we have two
1328 * clips at the end, splitted at the time specified by @position, as a position
1329 * in the timeline (not in the clip to be split). For example, if
1330 * ges_clip_split is called on a 4-second clip playing from 0:01.00 until
1331 * 0:05.00, with a split position of 0:02.00, this will result in one clip of 1
1332 * second and one clip of 3 seconds, not in two clips of 2 seconds.
1334 * The newly created clip will be added to the same layer as @clip is in. This
1335 * implies that @clip must be in a #GESLayer for the operation to be possible.
1337 * This method supports clips playing at a different tempo than one second per
1338 * second. For example, splitting a clip with a #GESEffect 'pitch tempo=1.5'
1339 * four seconds after it starts, will set the inpoint of the new clip to six
1340 * seconds after that of the clip to split. For this, the rate-changing
1341 * property must be registered using @ges_effect_class_register_rate_property;
1342 * for the 'pitch' plugin, this is already done.
1344 * Returns: (transfer none) (nullable): The newly created #GESClip resulting
1345 * from the splitting or %NULL if the clip can't be split.
1348 ges_clip_split (GESClip * clip, guint64 position)
1351 GESClip *new_object;
1352 GstClockTime start, inpoint, duration, old_duration, new_duration;
1353 gdouble media_duration_factor;
1355 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
1356 g_return_val_if_fail (clip->priv->layer, NULL);
1357 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (position), NULL);
1359 duration = _DURATION (clip);
1360 start = _START (clip);
1361 inpoint = _INPOINT (clip);
1363 if (position >= start + duration || position <= start) {
1364 GST_WARNING_OBJECT (clip, "Can not split %" GST_TIME_FORMAT
1365 " out of boundaries", GST_TIME_ARGS (position));
1369 GST_DEBUG_OBJECT (clip, "Spliting at %" GST_TIME_FORMAT,
1370 GST_TIME_ARGS (position));
1372 /* Create the new Clip */
1373 new_object = GES_CLIP (ges_timeline_element_copy (GES_TIMELINE_ELEMENT (clip),
1376 GST_DEBUG_OBJECT (new_object, "New 'splitted' clip");
1377 /* Set new timing properties on the Clip */
1378 media_duration_factor =
1379 ges_timeline_element_get_media_duration_factor (GES_TIMELINE_ELEMENT
1381 new_duration = duration + start - position;
1382 old_duration = position - start;
1383 _set_start0 (GES_TIMELINE_ELEMENT (new_object), position);
1384 _set_inpoint0 (GES_TIMELINE_ELEMENT (new_object),
1385 inpoint + old_duration * media_duration_factor);
1386 _set_duration0 (GES_TIMELINE_ELEMENT (new_object), new_duration);
1388 _DURATION (clip) = old_duration;
1389 g_object_notify (G_OBJECT (clip), "duration");
1391 /* We do not want the timeline to create again TrackElement-s */
1392 ges_clip_set_moving_from_layer (new_object, TRUE);
1393 ges_layer_add_clip (clip->priv->layer, new_object);
1394 ges_clip_set_moving_from_layer (new_object, FALSE);
1396 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next) {
1397 GESTrackElement *new_trackelement, *trackelement =
1398 GES_TRACK_ELEMENT (tmp->data);
1401 GES_TRACK_ELEMENT (ges_timeline_element_copy (GES_TIMELINE_ELEMENT
1402 (trackelement), FALSE));
1403 if (new_trackelement == NULL) {
1404 GST_WARNING_OBJECT (trackelement, "Could not create a copy");
1408 /* Set 'new' track element timing propeties */
1409 _set_start0 (GES_TIMELINE_ELEMENT (new_trackelement), position);
1410 _set_inpoint0 (GES_TIMELINE_ELEMENT (new_trackelement),
1411 inpoint + old_duration * media_duration_factor);
1412 _set_duration0 (GES_TIMELINE_ELEMENT (new_trackelement), new_duration);
1414 ges_container_add (GES_CONTAINER (new_object),
1415 GES_TIMELINE_ELEMENT (new_trackelement));
1416 ges_track_element_copy_properties (GES_TIMELINE_ELEMENT (trackelement),
1417 GES_TIMELINE_ELEMENT (new_trackelement));
1419 ges_track_element_copy_bindings (trackelement, new_trackelement,
1420 position - start + inpoint);
1423 ELEMENT_SET_FLAG (clip, GES_TIMELINE_ELEMENT_SET_SIMPLE);
1424 _DURATION (clip) = duration;
1425 _set_duration0 (GES_TIMELINE_ELEMENT (clip), old_duration);
1426 ELEMENT_UNSET_FLAG (clip, GES_TIMELINE_ELEMENT_SET_SIMPLE);
1432 * ges_clip_set_supported_formats:
1433 * @clip: the #GESClip to set supported formats on
1434 * @supportedformats: the #GESTrackType defining formats supported by @clip
1436 * Sets the formats supported by the file.
1439 ges_clip_set_supported_formats (GESClip * clip, GESTrackType supportedformats)
1441 g_return_if_fail (GES_IS_CLIP (clip));
1443 clip->priv->supportedformats = supportedformats;
1447 * ges_clip_get_supported_formats:
1448 * @clip: the #GESClip
1450 * Get the formats supported by @clip.
1452 * Returns: The formats supported by @clip.
1455 ges_clip_get_supported_formats (GESClip * clip)
1457 g_return_val_if_fail (GES_IS_CLIP (clip), GES_TRACK_TYPE_UNKNOWN);
1459 return clip->priv->supportedformats;
1463 _ripple (GESTimelineElement * element, GstClockTime start)
1465 return ges_container_edit (GES_CONTAINER (element), NULL,
1466 ges_timeline_element_get_layer_priority (element),
1467 GES_EDIT_MODE_RIPPLE, GES_EDGE_NONE, start);
1471 _ripple_end (GESTimelineElement * element, GstClockTime end)
1473 return ges_container_edit (GES_CONTAINER (element), NULL,
1474 ges_timeline_element_get_layer_priority (element),
1475 GES_EDIT_MODE_RIPPLE, GES_EDGE_END, end);
1479 _roll_start (GESTimelineElement * element, GstClockTime start)
1481 return ges_container_edit (GES_CONTAINER (element), NULL,
1482 ges_timeline_element_get_layer_priority (element),
1483 GES_EDIT_MODE_ROLL, GES_EDGE_START, start);
1487 _roll_end (GESTimelineElement * element, GstClockTime end)
1489 return ges_container_edit (GES_CONTAINER (element), NULL,
1490 ges_timeline_element_get_layer_priority (element),
1491 GES_EDIT_MODE_ROLL, GES_EDGE_END, end);
1495 _trim (GESTimelineElement * element, GstClockTime start)
1497 return ges_container_edit (GES_CONTAINER (element), NULL, -1,
1498 GES_EDIT_MODE_TRIM, GES_EDGE_START, start);
1502 * ges_clip_add_asset:
1504 * @asset: a #GESAsset with #GES_TYPE_TRACK_ELEMENT as extractable_type
1506 * Extracts a #GESTrackElement from @asset and adds it to the @clip.
1507 * Should only be called in order to add operations to a #GESClip,
1508 * ni other cases TrackElement are added automatically when adding the
1509 * #GESClip/#GESAsset to a layer.
1511 * Takes a reference on @track_element.
1513 * Returns: (transfer none)(allow-none): Created #GESTrackElement or NULL
1514 * if an error happened
1517 ges_clip_add_asset (GESClip * clip, GESAsset * asset)
1519 GESTrackElement *element;
1521 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
1522 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
1523 g_return_val_if_fail (g_type_is_a (ges_asset_get_extractable_type
1524 (asset), GES_TYPE_TRACK_ELEMENT), NULL);
1526 element = GES_TRACK_ELEMENT (ges_asset_extract (asset, NULL));
1528 if (!ges_container_add (GES_CONTAINER (clip), GES_TIMELINE_ELEMENT (element)))
1536 * ges_clip_find_track_elements:
1538 * @track: (allow-none): a #GESTrack or NULL
1539 * @track_type: a #GESTrackType indicating the type of tracks in which elements
1540 * should be searched.
1541 * @type: a #GType indicating the type of track element you are looking
1542 * for or %G_TYPE_NONE if you do not care about the track type.
1544 * Finds all the #GESTrackElement controlled by @clip that is used in @track. You
1545 * may optionally specify a GType to further narrow search criteria.
1547 * Returns: (transfer full) (element-type GESTrackElement): a #GList of the
1548 * #GESTrackElement contained in @clip.
1549 * The refcount of the objects will be increased. The user will have to
1550 * unref each #GESTrackElement and free the #GList.
1554 ges_clip_find_track_elements (GESClip * clip, GESTrack * track,
1555 GESTrackType track_type, GType type)
1559 GESTrackElement *otmp;
1560 GESTrackElement *foundElement;
1564 g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
1565 g_return_val_if_fail (!(track == NULL && type == G_TYPE_NONE &&
1566 track_type == GES_TRACK_TYPE_UNKNOWN), NULL);
1568 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = g_list_next (tmp)) {
1569 otmp = (GESTrackElement *) tmp->data;
1571 if ((type != G_TYPE_NONE) && !G_TYPE_CHECK_INSTANCE_TYPE (tmp->data, type))
1574 tmptrack = ges_track_element_get_track (otmp);
1575 if (((track != NULL && tmptrack == track)) ||
1576 (track_type != GES_TRACK_TYPE_UNKNOWN
1577 && ges_track_element_get_track_type (otmp) == track_type)) {
1579 foundElement = GES_TRACK_ELEMENT (tmp->data);
1581 ret = g_list_append (ret, gst_object_ref (foundElement));