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., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:ges-track-object
23 * @short_description: Base Class for objects contained in a #GESTrack
25 * #GESTrackObject is the Base Class for any object that can be contained in a
28 * It contains the basic information as to the location of the object within
29 * its container, like the start position, the in-point, the duration and the
33 #include "ges-internal.h"
34 #include "ges-track-object.h"
35 #include "ges-timeline-object.h"
36 #include <gobject/gvaluecollector.h>
38 G_DEFINE_ABSTRACT_TYPE (GESTrackObject, ges_track_object,
39 G_TYPE_INITIALLY_UNOWNED);
41 struct _GESTrackObjectPrivate
43 /* These fields are only used before the gnlobject is available */
44 guint64 pending_start;
45 guint64 pending_inpoint;
46 guint64 pending_duration;
47 guint32 pending_priority;
48 gboolean pending_active;
50 GstElement *gnlobject; /* The GnlObject */
51 GstElement *element; /* The element contained in the gnlobject (can be NULL) */
53 /* We keep a link between properties name and elements internally
54 * The hashtable should look like
55 * {GParamaSpec ---> element,}*/
56 GHashTable *properties_hashtable;
58 GESTimelineObject *timelineobj;
65 gboolean locked; /* If TRUE, then moves in sync with its controlling
66 * GESTimelineObject */
82 static GParamSpec *properties[PROP_LAST];
90 static guint ges_track_object_signals[LAST_SIGNAL] = { 0 };
92 static GstElement *ges_track_object_create_gnl_object_func (GESTrackObject *
95 static void gnlobject_start_cb (GstElement * gnlobject, GParamSpec * arg
96 G_GNUC_UNUSED, GESTrackObject * obj);
98 static void gnlobject_media_start_cb (GstElement * gnlobject, GParamSpec * arg
99 G_GNUC_UNUSED, GESTrackObject * obj);
101 static void gnlobject_priority_cb (GstElement * gnlobject, GParamSpec * arg
102 G_GNUC_UNUSED, GESTrackObject * obj);
104 static void gnlobject_duration_cb (GstElement * gnlobject, GParamSpec * arg
105 G_GNUC_UNUSED, GESTrackObject * obj);
107 static void gnlobject_active_cb (GstElement * gnlobject, GParamSpec * arg
108 G_GNUC_UNUSED, GESTrackObject * obj);
110 static void connect_properties_signals (GESTrackObject * object);
111 static void connect_signal (gpointer key, gpointer value, gpointer user_data);
112 static void gst_element_prop_changed_cb (GstElement * element, GParamSpec * arg
113 G_GNUC_UNUSED, GESTrackObject * obj);
115 static inline gboolean
116 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start);
117 static inline gboolean
118 ges_track_object_set_inpoint_internal (GESTrackObject * object,
120 static inline gboolean ges_track_object_set_duration_internal (GESTrackObject *
121 object, guint64 duration);
122 static inline gboolean ges_track_object_set_priority_internal (GESTrackObject *
123 object, guint32 priority);
125 ges_track_object_set_locked_internal (GESTrackObject * object, gboolean locked);
127 static GParamSpec **default_list_children_properties (GESTrackObject * object,
128 guint * n_properties);
131 ges_track_object_get_property (GObject * object, guint property_id,
132 GValue * value, GParamSpec * pspec)
134 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
136 switch (property_id) {
138 g_value_set_uint64 (value, ges_track_object_get_start (tobj));
141 g_value_set_uint64 (value, ges_track_object_get_inpoint (tobj));
144 g_value_set_uint64 (value, ges_track_object_get_duration (tobj));
147 g_value_set_uint (value, ges_track_object_get_priority (tobj));
150 g_value_set_boolean (value, ges_track_object_is_active (tobj));
153 g_value_set_boolean (value, ges_track_object_is_locked (tobj));
155 case PROP_MAX_DURATION:
156 g_value_set_uint64 (value, tobj->priv->maxduration);
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
164 ges_track_object_set_property (GObject * object, guint property_id,
165 const GValue * value, GParamSpec * pspec)
167 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
169 switch (property_id) {
171 ges_track_object_set_start_internal (tobj, g_value_get_uint64 (value));
174 ges_track_object_set_inpoint_internal (tobj, g_value_get_uint64 (value));
177 ges_track_object_set_duration_internal (tobj, g_value_get_uint64 (value));
180 ges_track_object_set_priority_internal (tobj, g_value_get_uint (value));
183 ges_track_object_set_active (tobj, g_value_get_boolean (value));
186 ges_track_object_set_locked_internal (tobj, g_value_get_boolean (value));
188 case PROP_MAX_DURATION:
189 ges_track_object_set_max_duration (tobj, g_value_get_uint64 (value));
192 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
197 ges_track_object_dispose (GObject * object)
199 GESTrackObjectPrivate *priv = GES_TRACK_OBJECT (object)->priv;
200 if (priv->properties_hashtable)
201 g_hash_table_destroy (priv->properties_hashtable);
203 G_OBJECT_CLASS (ges_track_object_parent_class)->dispose (object);
207 ges_track_object_finalize (GObject * object)
209 G_OBJECT_CLASS (ges_track_object_parent_class)->finalize (object);
213 ges_track_object_class_init (GESTrackObjectClass * klass)
215 GObjectClass *object_class = G_OBJECT_CLASS (klass);
217 g_type_class_add_private (klass, sizeof (GESTrackObjectPrivate));
219 object_class->get_property = ges_track_object_get_property;
220 object_class->set_property = ges_track_object_set_property;
221 object_class->dispose = ges_track_object_dispose;
222 object_class->finalize = ges_track_object_finalize;
225 * GESTrackObject:start
227 * The position of the object in the container #GESTrack (in nanoseconds).
229 properties[PROP_START] = g_param_spec_uint64 ("start", "Start",
230 "The position in the container", 0, G_MAXUINT64, 0, G_PARAM_READWRITE);
231 g_object_class_install_property (object_class, PROP_START,
232 properties[PROP_START]);
235 * GESTrackObject:in-point
237 * The in-point at which this #GESTrackObject will start outputting data
238 * from its contents (in nanoseconds).
240 * Ex: an in-point of 5 seconds means that the first outputted buffer will
241 * be the one located 5 seconds in the controlled resource.
243 properties[PROP_INPOINT] =
244 g_param_spec_uint64 ("in-point", "In-point", "The in-point", 0,
245 G_MAXUINT64, 0, G_PARAM_READWRITE);
246 g_object_class_install_property (object_class, PROP_INPOINT,
247 properties[PROP_INPOINT]);
250 * GESTrackObject:duration
252 * The duration (in nanoseconds) which will be used in the container #GESTrack
253 * starting from 'in-point'.
256 properties[PROP_DURATION] =
257 g_param_spec_uint64 ("duration", "Duration", "The duration to use", 0,
258 G_MAXUINT64, GST_SECOND, G_PARAM_READWRITE);
259 g_object_class_install_property (object_class, PROP_DURATION,
260 properties[PROP_DURATION]);
263 * GESTrackObject:priority
265 * The priority of the object within the containing #GESTrack.
266 * If two objects intersect over the same region of time, the @priority
267 * property is used to decide which one takes precedence.
269 * The highest priority (that supercedes everything) is 0, and then lowering
270 * priorities go in increasing numerical value (with #G_MAXUINT64 being the
273 properties[PROP_PRIORITY] = g_param_spec_uint ("priority", "Priority",
274 "The priority of the object", 0, G_MAXUINT, 0, G_PARAM_READWRITE);
275 g_object_class_install_property (object_class, PROP_PRIORITY,
276 properties[PROP_PRIORITY]);
279 * GESTrackObject:active
281 * Whether the object should be taken into account in the #GESTrack output.
282 * If #FALSE, then its contents will not be used in the resulting track.
284 properties[PROP_ACTIVE] =
285 g_param_spec_boolean ("active", "Active", "Use object in output", TRUE,
287 g_object_class_install_property (object_class, PROP_ACTIVE,
288 properties[PROP_ACTIVE]);
291 * GESTrackObject:locked
293 * If %TRUE, then moves in sync with its controlling #GESTimelineObject
295 properties[PROP_LOCKED] =
296 g_param_spec_boolean ("locked", "Locked",
297 "Moves in sync with its controling TimelineObject", TRUE,
299 g_object_class_install_property (object_class, PROP_LOCKED,
300 properties[PROP_LOCKED]);
303 * GESTrackObject:max-duration:
305 * The maximum duration (in nanoseconds) of the #GESTrackObject.
309 g_object_class_install_property (object_class, PROP_MAX_DURATION,
310 g_param_spec_uint64 ("max-duration", "Maximum duration",
311 "The duration of the object", GST_CLOCK_TIME_NONE, G_MAXUINT64,
312 G_MAXUINT64, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
315 * GESTrackObject::deep-notify:
316 * @track_object: a #GESTrackObject
317 * @prop_object: the object that originated the signal
318 * @prop: the property that changed
320 * The deep notify signal is used to be notified of property changes of all
321 * the childs of @track_object
325 ges_track_object_signals[DEEP_NOTIFY] =
326 g_signal_new ("deep-notify", G_TYPE_FROM_CLASS (klass),
327 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED |
328 G_SIGNAL_NO_HOOKS, 0, NULL, NULL, g_cclosure_marshal_generic,
329 G_TYPE_NONE, 2, GST_TYPE_ELEMENT, G_TYPE_PARAM);
331 klass->create_gnl_object = ges_track_object_create_gnl_object_func;
332 /* There is no 'get_props_hashtable' default implementation */
333 klass->get_props_hastable = NULL;
334 klass->list_children_properties = default_list_children_properties;
338 ges_track_object_init (GESTrackObject * self)
340 GESTrackObjectPrivate *priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
341 GES_TYPE_TRACK_OBJECT, GESTrackObjectPrivate);
343 /* Sane default values */
344 priv->pending_start = 0;
345 priv->pending_inpoint = 0;
346 priv->pending_duration = GST_SECOND;
347 priv->pending_priority = 1;
348 priv->pending_active = TRUE;
350 priv->properties_hashtable = NULL;
351 priv->maxduration = GST_CLOCK_TIME_NONE;
354 static inline gboolean
355 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start)
357 GST_DEBUG ("object:%p, start:%" GST_TIME_FORMAT,
358 object, GST_TIME_ARGS (start));
360 if (object->priv->gnlobject != NULL) {
361 if (G_UNLIKELY (start == object->start))
364 g_object_set (object->priv->gnlobject, "start", start, NULL);
366 object->priv->pending_start = start;
371 * ges_track_object_set_start:
372 * @object: a #GESTrackObject
373 * @start: the start position (in #GstClockTime)
375 * Sets the position of the object in the container #GESTrack.
378 ges_track_object_set_start (GESTrackObject * object, guint64 start)
380 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
382 if (ges_track_object_set_start_internal (object, start))
383 #if GLIB_CHECK_VERSION(2,26,0)
384 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_START]);
386 g_object_notify (G_OBJECT (object), "start");
390 static inline gboolean
391 ges_track_object_set_inpoint_internal (GESTrackObject * object, guint64 inpoint)
394 GST_DEBUG ("object:%p, inpoint:%" GST_TIME_FORMAT,
395 object, GST_TIME_ARGS (inpoint));
397 if (object->priv->gnlobject != NULL) {
398 if (G_UNLIKELY (inpoint == object->inpoint))
401 g_object_set (object->priv->gnlobject, "media-start", inpoint, NULL);
403 object->priv->pending_inpoint = inpoint;
409 * ges_track_object_set_inpoint:
410 * @object: a #GESTrackObject
411 * @inpoint: the in-point (in #GstClockTime)
413 * Set the offset within the contents of this #GESTrackObject
416 ges_track_object_set_inpoint (GESTrackObject * object, guint64 inpoint)
418 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
420 if (ges_track_object_set_inpoint_internal (object, inpoint))
421 #if GLIB_CHECK_VERSION(2,26,0)
422 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_INPOINT]);
424 g_object_notify (G_OBJECT (object), "in-point");
428 static inline gboolean
429 ges_track_object_set_duration_internal (GESTrackObject * object,
432 GESTrackObjectPrivate *priv = object->priv;
434 GST_DEBUG ("object:%p, duration:%" GST_TIME_FORMAT,
435 object, GST_TIME_ARGS (duration));
437 if (GST_CLOCK_TIME_IS_VALID (priv->maxduration) &&
438 duration > object->inpoint + priv->maxduration)
439 duration = priv->maxduration - object->inpoint;
441 if (priv->gnlobject != NULL) {
442 if (G_UNLIKELY (duration == object->duration))
445 g_object_set (priv->gnlobject, "duration", duration,
446 "media-duration", duration, NULL);
448 priv->pending_duration = duration;
454 * ges_track_object_set_duration:
455 * @object: a #GESTrackObject
456 * @duration: the duration (in #GstClockTime)
458 * Set the duration which will be used in the container #GESTrack
459 * starting from the 'in-point'
462 ges_track_object_set_duration (GESTrackObject * object, guint64 duration)
464 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
466 if (ges_track_object_set_duration_internal (object, duration))
467 #if GLIB_CHECK_VERSION(2,26,0)
468 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_DURATION]);
470 g_object_notify (G_OBJECT (object), "duration");
474 static inline gboolean
475 ges_track_object_set_priority_internal (GESTrackObject * object,
478 GST_DEBUG ("object:%p, priority:%" G_GUINT32_FORMAT, object, priority);
480 if (object->priv->gnlobject != NULL) {
481 if (G_UNLIKELY (priority == object->priority))
484 g_object_set (object->priv->gnlobject, "priority", priority, NULL);
486 object->priv->pending_priority = priority;
491 * ges_track_object_set_priority:
492 * @object: a #GESTrackObject
493 * @priority: the priority
495 * Sets the priority of the object withing the containing #GESTrack.
496 * If two objects intersect over the same region of time, the priority
497 * property is used to decide which one takes precedence.
499 * The highest priority (that supercedes everything) is 0, and then
500 * lowering priorities go in increasing numerical value (with G_MAXUINT32
501 * being the lowest priority).
504 ges_track_object_set_priority (GESTrackObject * object, guint32 priority)
506 if (ges_track_object_set_priority_internal (object, priority))
507 #if GLIB_CHECK_VERSION(2,26,0)
508 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_PRIORITY]);
510 g_object_notify (G_OBJECT (object), "priority");
516 * ges_track_object_set_active:
517 * @object: a #GESTrackObject
518 * @active: visibility
520 * Sets the usage of the @object. If @active is %TRUE, the object will be used for
521 * playback and rendering, else it will be ignored.
523 * Returns: %TRUE if the property was toggled, else %FALSE
526 ges_track_object_set_active (GESTrackObject * object, gboolean active)
528 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE);
530 GST_DEBUG ("object:%p, active:%d", object, active);
532 if (object->priv->gnlobject != NULL) {
533 if (G_UNLIKELY (active == object->active))
536 g_object_set (object->priv->gnlobject, "active", active, NULL);
538 object->priv->pending_active = active;
542 /* Callbacks from the GNonLin object */
544 gnlobject_start_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
545 GESTrackObject * obj)
548 GESTrackObjectClass *klass;
550 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
552 g_object_get (gnlobject, "start", &start, NULL);
554 GST_DEBUG ("gnlobject start : %" GST_TIME_FORMAT " current : %"
555 GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (obj->start));
557 if (start != obj->start) {
559 if (klass->start_changed)
560 klass->start_changed (obj, start);
565 gst_element_prop_changed_cb (GstElement * element, GParamSpec * arg
566 G_GNUC_UNUSED, GESTrackObject * obj)
568 g_signal_emit (obj, ges_track_object_signals[DEEP_NOTIFY], 0,
569 GST_ELEMENT (element), arg);
573 connect_signal (gpointer key, gpointer value, gpointer user_data)
575 gchar *signame = g_strconcat ("notify::", G_PARAM_SPEC (key)->name, NULL);
577 g_signal_connect (G_OBJECT (value),
578 signame, G_CALLBACK (gst_element_prop_changed_cb),
579 GES_TRACK_OBJECT (user_data));
585 connect_properties_signals (GESTrackObject * object)
587 if (G_UNLIKELY (!object->priv->properties_hashtable)) {
588 GST_WARNING ("The properties_hashtable hasn't been set");
592 g_hash_table_foreach (object->priv->properties_hashtable,
593 (GHFunc) connect_signal, object);
597 /* Callbacks from the GNonLin object */
599 gnlobject_media_start_cb (GstElement * gnlobject,
600 GParamSpec * arg G_GNUC_UNUSED, GESTrackObject * obj)
603 GESTrackObjectClass *klass;
605 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
607 g_object_get (gnlobject, "media-start", &start, NULL);
609 GST_DEBUG ("gnlobject in-point : %" GST_TIME_FORMAT " current : %"
610 GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (obj->inpoint));
612 if (start != obj->inpoint) {
613 obj->inpoint = start;
614 if (klass->media_start_changed)
615 klass->media_start_changed (obj, start);
620 gnlobject_priority_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
621 GESTrackObject * obj)
624 GESTrackObjectClass *klass;
626 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
628 g_object_get (gnlobject, "priority", &priority, NULL);
630 GST_DEBUG ("gnlobject priority : %d current : %d", priority, obj->priority);
632 if (priority != obj->priority) {
633 obj->priority = priority;
634 if (klass->gnl_priority_changed)
635 klass->gnl_priority_changed (obj, priority);
640 gnlobject_duration_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
641 GESTrackObject * obj)
644 GESTrackObjectClass *klass;
646 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
648 g_object_get (gnlobject, "duration", &duration, NULL);
650 GST_DEBUG_OBJECT (gnlobject, "duration : %" GST_TIME_FORMAT " current : %"
651 GST_TIME_FORMAT, GST_TIME_ARGS (duration), GST_TIME_ARGS (obj->duration));
653 if (duration != obj->duration) {
654 obj->duration = duration;
655 if (klass->duration_changed)
656 klass->duration_changed (obj, duration);
661 gnlobject_active_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
662 GESTrackObject * obj)
665 GESTrackObjectClass *klass;
667 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
669 g_object_get (gnlobject, "active", &active, NULL);
671 GST_DEBUG ("gnlobject active : %d current : %d", active, obj->active);
673 if (active != obj->active) {
674 obj->active = active;
675 if (klass->active_changed)
676 klass->active_changed (obj, active);
681 /* default 'create_gnl_object' virtual method implementation */
683 ges_track_object_create_gnl_object_func (GESTrackObject * self)
685 GESTrackObjectClass *klass = NULL;
686 GstElement *child = NULL;
687 GstElement *gnlobject;
689 klass = GES_TRACK_OBJECT_GET_CLASS (self);
691 if (G_UNLIKELY (self->priv->gnlobject != NULL))
692 goto already_have_gnlobject;
694 if (G_UNLIKELY (klass->gnlobject_factorytype == NULL))
697 GST_DEBUG ("Creating a supporting gnlobject of type '%s'",
698 klass->gnlobject_factorytype);
700 gnlobject = gst_element_factory_make (klass->gnlobject_factorytype, NULL);
702 if (G_UNLIKELY (gnlobject == NULL))
705 if (klass->create_element) {
706 GST_DEBUG ("Calling subclass 'create_element' vmethod");
707 child = klass->create_element (self);
709 if (G_UNLIKELY (!child))
712 if (!gst_bin_add (GST_BIN (gnlobject), child))
715 GST_DEBUG ("Succesfully got the element to put in the gnlobject");
716 self->priv->element = child;
725 already_have_gnlobject:
727 GST_ERROR ("Already controlling a GnlObject %s",
728 GST_ELEMENT_NAME (self->priv->gnlobject));
734 GST_ERROR ("No GESTrackObject::gnlobject_factorytype implementation!");
740 GST_ERROR ("Error creating a gnlobject of type '%s'",
741 klass->gnlobject_factorytype);
747 GST_ERROR ("create_element returned NULL");
748 gst_object_unref (gnlobject);
754 GST_ERROR ("Error adding the contents to the gnlobject");
755 gst_object_unref (child);
756 gst_object_unref (gnlobject);
762 ensure_gnl_object (GESTrackObject * object)
764 GESTrackObjectClass *class;
765 GstElement *gnlobject;
766 GHashTable *props_hash;
769 if (object->priv->gnlobject && object->priv->valid)
772 /* 1. Create the GnlObject */
773 GST_DEBUG ("Creating GnlObject");
775 class = GES_TRACK_OBJECT_GET_CLASS (object);
777 if (G_UNLIKELY (class->create_gnl_object == NULL)) {
778 GST_ERROR ("No 'create_gnl_object' implementation !");
782 GST_DEBUG ("Calling virtual method");
784 /* 2. Fill in the GnlObject */
785 if (object->priv->gnlobject == NULL) {
787 /* call the create_gnl_object virtual method */
788 gnlobject = class->create_gnl_object (object);
790 if (G_UNLIKELY (gnlobject == NULL)) {
792 ("'create_gnl_object' implementation returned TRUE but no GnlObject is available");
796 GST_DEBUG_OBJECT (object, "Got a valid GnlObject, now filling it in");
798 object->priv->gnlobject = gnlobject;
800 if (object->priv->timelineobj)
801 res = ges_timeline_object_fill_track_object (object->priv->timelineobj,
802 object, object->priv->gnlobject);
807 /* Connect to property notifications */
808 /* FIXME : remember the signalids so we can remove them later on !!! */
809 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::start",
810 G_CALLBACK (gnlobject_start_cb), object);
811 g_signal_connect (G_OBJECT (object->priv->gnlobject),
812 "notify::media-start", G_CALLBACK (gnlobject_media_start_cb), object);
813 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::duration",
814 G_CALLBACK (gnlobject_duration_cb), object);
815 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::priority",
816 G_CALLBACK (gnlobject_priority_cb), object);
817 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::active",
818 G_CALLBACK (gnlobject_active_cb), object);
820 /* Set some properties on the GnlObject */
821 g_object_set (object->priv->gnlobject,
822 "duration", object->priv->pending_duration,
823 "media-duration", object->priv->pending_duration,
824 "start", object->priv->pending_start,
825 "media-start", object->priv->pending_inpoint,
826 "priority", object->priv->pending_priority,
827 "active", object->priv->pending_active, NULL);
829 if (object->priv->track != NULL)
830 g_object_set (object->priv->gnlobject,
831 "caps", ges_track_get_caps (object->priv->track), NULL);
833 /* We feed up the props_hashtable if possible */
834 if (class->get_props_hastable) {
835 props_hash = class->get_props_hastable (object);
837 if (props_hash == NULL) {
838 GST_DEBUG ("'get_props_hastable' implementation returned TRUE but no"
839 "properties_hashtable is available");
841 object->priv->properties_hashtable = props_hash;
842 connect_properties_signals (object);
849 object->priv->valid = res;
851 GST_DEBUG ("Returning res:%d", res);
858 ges_track_object_set_track (GESTrackObject * object, GESTrack * track)
860 GST_DEBUG ("object:%p, track:%p", object, track);
862 object->priv->track = track;
864 if (object->priv->track) {
865 /* If we already have a gnlobject, we just set its caps properly */
866 if (object->priv->gnlobject) {
867 g_object_set (object->priv->gnlobject,
868 "caps", ges_track_get_caps (object->priv->track), NULL);
871 return ensure_gnl_object (object);
879 * ges_track_object_get_track:
880 * @object: a #GESTrackObject
882 * Get the #GESTrack to which this object belongs.
884 * Returns: (transfer none): The #GESTrack to which this object belongs. Can be %NULL if it
885 * is not in any track
888 ges_track_object_get_track (GESTrackObject * object)
890 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
892 return object->priv->track;
896 * ges_track_object_set_timeline_object:
897 * @object: The #GESTrackObject to set the parent to
898 * @tlobject: The #GESTimelineObject, parent of @tlobj or %NULL
900 * Set the #GESTimelineObject to which @object belongs.
903 ges_track_object_set_timeline_object (GESTrackObject * object,
904 GESTimelineObject * tlobject)
906 GST_DEBUG ("object:%p, timeline-object:%p", object, tlobject);
908 object->priv->timelineobj = tlobject;
912 * ges_track_object_get_timeline_object:
913 * @object: a #GESTrackObject
915 * Get the #GESTimelineObject which is controlling this track object
917 * Returns: (transfer none): the #GESTimelineObject which is controlling
921 ges_track_object_get_timeline_object (GESTrackObject * object)
923 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
925 return object->priv->timelineobj;
929 * ges_track_object_get_gnlobject:
930 * @object: a #GESTrackObject
932 * Get the GNonLin object this object is controlling.
934 * Returns: (transfer none): the GNonLin object this object is controlling.
937 ges_track_object_get_gnlobject (GESTrackObject * object)
939 return object->priv->gnlobject;
943 * ges_track_object_get_element:
944 * @object: a #GESTrackObject
946 * Get the #GstElement this track object is controlling within GNonLin.
948 * Returns: (transfer none): the #GstElement this track object is controlling
952 ges_track_object_get_element (GESTrackObject * object)
954 return object->priv->element;
958 ges_track_object_set_locked_internal (GESTrackObject * object, gboolean locked)
960 object->priv->locked = locked;
964 * ges_track_object_set_locked:
965 * @object: a #GESTrackObject
966 * @locked: whether the object is lock to its parent
968 * Set the locking status of the @object in relationship to its controlling
969 * #GESTimelineObject. If @locked is %TRUE, then this object will move synchronously
970 * with its controlling #GESTimelineObject.
973 ges_track_object_set_locked (GESTrackObject * object, gboolean locked)
975 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
977 GST_DEBUG_OBJECT (object, "%s object", locked ? "Locking" : "Unlocking");
979 ges_track_object_set_locked_internal (object, locked);
980 #if GLIB_CHECK_VERSION(2,26,0)
981 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_LOCKED]);
983 g_object_notify (G_OBJECT (object), "locked");
989 * ges_track_object_is_locked:
990 * @object: a #GESTrackObject
992 * Let you know if object us locked or not (moving synchronously).
994 * Returns: %TRUE if the object is moving synchronously to its controlling
995 * #GESTimelineObject, else %FALSE.
998 ges_track_object_is_locked (GESTrackObject * object)
1000 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE);
1002 return object->priv->locked;
1006 * ges_track_object_get_start:
1007 * @object: a #GESTrackObject
1009 * Get the position of the object in the container #GESTrack.
1011 * Returns: the start position (in #GstClockTime) or #GST_CLOCK_TIME_NONE
1012 * if something went wrong.
1017 ges_track_object_get_start (GESTrackObject * object)
1019 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), GST_CLOCK_TIME_NONE);
1021 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1022 return object->priv->pending_start;
1024 return object->start;
1028 * ges_track_object_get_inpoint:
1029 * @object: a #GESTrackObject
1031 * Get the offset within the contents of this #GESTrackObject
1033 * Returns: the in-point (in #GstClockTime) or #GST_CLOCK_TIME_NONE
1034 * if something went wrong.
1039 ges_track_object_get_inpoint (GESTrackObject * object)
1041 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), GST_CLOCK_TIME_NONE);
1043 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1044 return object->priv->pending_inpoint;
1046 return object->inpoint;
1050 * ges_track_object_get_duration:
1051 * @object: a #GESTrackObject
1053 * Get the duration which will be used in the container #GESTrack
1054 * starting from the 'in-point'
1056 * Returns: the duration (in #GstClockTime) or #GST_CLOCK_TIME_NONE
1057 * if something went wrong.
1062 ges_track_object_get_duration (GESTrackObject * object)
1064 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), GST_CLOCK_TIME_NONE);
1066 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1067 return object->priv->pending_duration;
1069 return object->duration;
1073 * ges_track_object_get_priority:
1074 * @object: a #GESTrackObject
1076 * Get the priority of the object withing the containing #GESTrack.
1078 * Returns: the priority of @object or -1 if something went wrong
1083 ges_track_object_get_priority (GESTrackObject * object)
1085 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), -1);
1087 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1088 return object->priv->pending_priority;
1090 return object->priority;
1094 * ges_track_object_is_active:
1095 * @object: a #GESTrackObject
1097 * Lets you know if @object will be used for playback and rendering,
1100 * Returns: %TRUE if @object is active, %FALSE otherwize
1105 ges_track_object_is_active (GESTrackObject * object)
1107 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE);
1109 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1110 return object->priv->pending_active;
1112 return object->active;
1116 * ges_track_object_lookup_child:
1117 * @object: object to lookup the property in
1118 * @prop_name: name of the property to look up. You can specify the name of the
1119 * class as such: "ClassName::property-name", to guarantee that you get the
1120 * proper GParamSpec in case various GstElement-s contain the same property
1121 * name. If you don't do so, you will get the first element found, having
1122 * this property and the and the corresponding GParamSpec.
1123 * @element: (out) (allow-none) (transfer full): pointer to a #GstElement that
1124 * takes the real object to set property on
1125 * @pspec: (out) (allow-none) (transfer full): pointer to take the #GParamSpec
1126 * describing the property
1128 * Looks up which @element and @pspec would be effected by the given @name. If various
1129 * contained elements have this property name you will get the first one, unless you
1130 * specify the class name in @name.
1132 * Returns: TRUE if @element and @pspec could be found. FALSE otherwise. In that
1133 * case the values for @pspec and @element are not modified. Unref @element after
1139 ges_track_object_lookup_child (GESTrackObject * object, const gchar * prop_name,
1140 GstElement ** element, GParamSpec ** pspec)
1142 GHashTableIter iter;
1143 gpointer key, value;
1144 gchar **names, *name, *classename;
1146 GESTrackObjectPrivate *priv;
1148 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE);
1150 priv = object->priv;
1155 names = g_strsplit (prop_name, "::", 2);
1156 if (names[1] != NULL) {
1157 classename = names[0];
1162 g_hash_table_iter_init (&iter, priv->properties_hashtable);
1163 while (g_hash_table_iter_next (&iter, &key, &value)) {
1164 if (g_strcmp0 (G_PARAM_SPEC (key)->name, name) == 0) {
1165 if (classename == NULL ||
1166 g_strcmp0 (G_OBJECT_TYPE_NAME (G_OBJECT (value)), classename) == 0) {
1167 GST_DEBUG ("The %s property from %s has been found", name, classename);
1169 *element = g_object_ref (value);
1171 *pspec = g_param_spec_ref (key);
1183 * ges_track_object_set_child_property_by_pspec:
1184 * @object: a #GESTrackObject
1185 * @pspec: The #GParamSpec that specifies the property you want to set
1188 * Sets a property of a child of @object.
1193 ges_track_object_set_child_property_by_pspec (GESTrackObject * object,
1194 GParamSpec * pspec, GValue * value)
1196 GstElement *element;
1197 GESTrackObjectPrivate *priv;
1199 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1201 priv = object->priv;
1203 if (!priv->properties_hashtable)
1204 goto prop_hash_not_set;
1206 element = g_hash_table_lookup (priv->properties_hashtable, pspec);
1210 g_object_set_property (G_OBJECT (element), pspec->name, value);
1216 GST_ERROR ("The %s property doesn't exist", pspec->name);
1221 GST_DEBUG ("The child properties haven't been set on %p", object);
1227 * ges_track_object_set_child_property_valist:
1228 * @object: The #GESTrackObject parent object
1229 * @first_property_name: The name of the first property to set
1230 * @var_args: value for the first property, followed optionally by more
1231 * name/return location pairs, followed by NULL
1233 * Sets a property of a child of @object. If there are various child elements
1234 * that have the same property name, you can distinguish them using the following
1235 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1236 * corresponding property of the first element found will be set.
1241 ges_track_object_set_child_property_valist (GESTrackObject * object,
1242 const gchar * first_property_name, va_list var_args)
1246 GstElement *element;
1248 gchar *error = NULL;
1249 GValue value = { 0, };
1251 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1253 name = first_property_name;
1255 /* Note: This part is in big part copied from the gst_child_object_set_valist
1258 /* iterate over pairs */
1260 if (!ges_track_object_lookup_child (object, name, &element, &pspec))
1263 #if GLIB_CHECK_VERSION(2,23,3)
1264 G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args,
1265 G_VALUE_NOCOPY_CONTENTS, &error);
1267 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1268 G_VALUE_COLLECT (&value, var_args, G_VALUE_NOCOPY_CONTENTS, &error);
1274 g_object_set_property (G_OBJECT (element), pspec->name, &value);
1276 g_object_unref (element);
1277 g_value_unset (&value);
1279 name = va_arg (var_args, gchar *);
1285 GST_WARNING ("No property %s in OBJECT\n", name);
1290 GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
1292 g_value_unset (&value);
1298 * ges_track_object_set_child_property:
1299 * @object: The #GESTrackObject parent object
1300 * @first_property_name: The name of the first property to set
1301 * @...: value for the first property, followed optionally by more
1302 * name/return location pairs, followed by NULL
1304 * Sets a property of a child of @object. If there are various child elements
1305 * that have the same property name, you can distinguish them using the following
1306 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1307 * corresponding property of the first element found will be set.
1312 ges_track_object_set_child_property (GESTrackObject * object,
1313 const gchar * first_property_name, ...)
1317 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1319 va_start (var_args, first_property_name);
1320 ges_track_object_set_child_property_valist (object, first_property_name,
1326 * ges_track_object_get_child_property_valist:
1327 * @object: The #GESTrackObject parent object
1328 * @first_property_name: The name of the first property to get
1329 * @var_args: value for the first property, followed optionally by more
1330 * name/return location pairs, followed by NULL
1332 * Gets a property of a child of @object. If there are various child elements
1333 * that have the same property name, you can distinguish them using the following
1334 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1335 * corresponding property of the first element found will be set.
1340 ges_track_object_get_child_property_valist (GESTrackObject * object,
1341 const gchar * first_property_name, va_list var_args)
1344 gchar *error = NULL;
1345 GValue value = { 0, };
1347 GstElement *element;
1349 g_return_if_fail (G_IS_OBJECT (object));
1351 name = first_property_name;
1353 /* This part is in big part copied from the gst_child_object_get_valist method */
1355 if (!ges_track_object_lookup_child (object, name, &element, &pspec))
1358 g_value_init (&value, pspec->value_type);
1359 g_object_get_property (G_OBJECT (element), pspec->name, &value);
1360 g_object_unref (element);
1362 G_VALUE_LCOPY (&value, var_args, 0, &error);
1365 g_value_unset (&value);
1366 name = va_arg (var_args, gchar *);
1372 GST_WARNING ("no property %s in object", name);
1377 GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
1379 g_value_unset (&value);
1385 * ges_track_object_list_children_properties:
1386 * @object: The #GESTrackObject to get the list of children properties from
1387 * @n_properties: return location for the length of the returned array
1389 * Gets an array of #GParamSpec* for all configurable properties of the
1390 * children of @object.
1392 * Returns: (transfer full) (array): an array of #GParamSpec* which should be freed after use or
1393 * %NULL if something went wrong
1398 ges_track_object_list_children_properties (GESTrackObject * object,
1399 guint * n_properties)
1401 GESTrackObjectClass *class;
1403 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
1405 class = GES_TRACK_OBJECT_GET_CLASS (object);
1407 return class->list_children_properties (object, n_properties);
1411 * ges_track_object_get_child_property:
1412 * @object: The origin #GESTrackObject
1413 * @first_property_name: The name of the first property to get
1414 * @...: return location for the first property, followed optionally by more
1415 * name/return location pairs, followed by NULL
1417 * Gets properties of a child of @object.
1422 ges_track_object_get_child_property (GESTrackObject * object,
1423 const gchar * first_property_name, ...)
1427 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1429 va_start (var_args, first_property_name);
1430 ges_track_object_get_child_property_valist (object, first_property_name,
1436 * ges_track_object_get_child_property_by_pspec:
1437 * @object: a #GESTrackObject
1438 * @pspec: The #GParamSpec that specifies the property you want to get
1439 * @value: return location for the value
1441 * Gets a property of a child of @object.
1446 ges_track_object_get_child_property_by_pspec (GESTrackObject * object,
1447 GParamSpec * pspec, GValue * value)
1449 GstElement *element;
1450 GESTrackObjectPrivate *priv;
1452 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1454 priv = object->priv;
1456 if (!priv->properties_hashtable)
1457 goto prop_hash_not_set;
1459 element = g_hash_table_lookup (priv->properties_hashtable, pspec);
1463 g_object_get_property (G_OBJECT (element), pspec->name, value);
1469 GST_ERROR ("The %s property doesn't exist", pspec->name);
1474 GST_ERROR ("The child properties haven't been set on %p", object);
1479 static GParamSpec **
1480 default_list_children_properties (GESTrackObject * object, guint * n_properties)
1482 GParamSpec **pspec, *spec;
1483 GHashTableIter iter;
1484 gpointer key, value;
1488 if (!object->priv->properties_hashtable)
1489 goto prop_hash_not_set;
1491 *n_properties = g_hash_table_size (object->priv->properties_hashtable);
1492 pspec = g_new (GParamSpec *, *n_properties);
1494 g_hash_table_iter_init (&iter, object->priv->properties_hashtable);
1495 while (g_hash_table_iter_next (&iter, &key, &value)) {
1496 spec = G_PARAM_SPEC (key);
1497 pspec[i] = g_param_spec_ref (spec);
1506 GST_ERROR ("The child properties haven't been set on %p", object);
1512 * ges_track_object_get_max_duration:
1513 * @object: The #GESTrackObject to retrieve max duration from
1515 * Get the max duration of @object.
1517 * Returns: The max duration of @object
1522 ges_track_object_get_max_duration (GESTrackObject * object)
1524 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), 0);
1526 return object->priv->maxduration;
1530 * ges_track_object_set_max_duration:
1531 * @object: The #GESTrackObject to retrieve max duration from
1532 * @maxduration: The maximum duration of @object
1534 * Returns: Set the max duration of @object
1539 ges_track_object_set_max_duration (GESTrackObject * object, guint64 maxduration)
1541 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1543 object->priv->maxduration = maxduration;
1547 * ges_track_object_copy:
1548 * @object: The #GESTrackObject to copy
1549 * @deep: whether we want to create the gnlobject and copy it properties
1553 * Returns: The newly create #GESTrackObject, copied from @object
1558 ges_track_object_copy (GESTrackObject * object, gboolean deep)
1560 GESTrackObject *ret = NULL;
1563 guint n, n_specs, n_params;
1566 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
1569 g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &n_specs);
1570 params = g_new0 (GParameter, n_specs);
1573 for (n = 0; n < n_specs; ++n) {
1574 if (g_strcmp0 (specs[n]->name, "parent") &&
1575 (specs[n]->flags & G_PARAM_READWRITE) == G_PARAM_READWRITE) {
1576 params[n_params].name = g_intern_string (specs[n]->name);
1577 g_value_init (¶ms[n_params].value, specs[n]->value_type);
1578 g_object_get_property (G_OBJECT (object), specs[n]->name,
1579 ¶ms[n_params].value);
1584 ret = g_object_newv (G_TYPE_FROM_INSTANCE (object), n_params, params);
1593 ensure_gnl_object (ret);
1594 specs = ges_track_object_list_children_properties (object, &n_specs);
1595 for (n = 0; n < n_specs; ++n) {
1596 g_value_init (&val, specs[n]->value_type);
1597 g_object_get_property (G_OBJECT (object), specs[n]->name, &val);
1598 ges_track_object_set_child_property_by_pspec (ret, specs[n], &val);
1599 g_value_unset (&val);
1609 * ges_track_object_edit:
1610 * @object: the #GESTrackObject to edit
1611 * @layers: (element-type GESTimelineLayer): The layers you want the edit to
1612 * happen in, %NULL means that the edition is done in all the
1613 * #GESTimelineLayers contained in the current timeline.
1614 * FIXME: This is not implemented yet.
1615 * @mode: The #GESEditMode in which the editition will happen.
1616 * @edge: The #GESEdge the edit should happen on.
1617 * @position: The position at which to edit @object (in nanosecond)
1619 * Edit @object in the different exisiting #GESEditMode modes. In the case of
1620 * slide, and roll, you need to specify a #GESEdge
1622 * Returns: %TRUE if the object as been edited properly, %FALSE if an error
1628 ges_track_object_edit (GESTrackObject * object,
1629 GList * layers, GESEditMode mode, GESEdge edge, guint64 position)
1631 GESTrack *track = ges_track_object_get_track (object);
1632 GESTimeline *timeline;
1634 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE);
1636 if (G_UNLIKELY (!track)) {
1637 GST_WARNING_OBJECT (object, "Trying to edit in %d mode but not in"
1638 "any Track yet.", mode);
1640 } else if (position < 0) {
1641 GST_DEBUG_OBJECT (object, "Trying to move before 0, not moving");
1645 timeline = GES_TIMELINE (ges_track_get_timeline (track));
1647 if (G_UNLIKELY (!timeline)) {
1648 GST_WARNING_OBJECT (object, "Trying to edit in %d mode but not in"
1649 "track %p no in any timeline yet.", mode, track);
1654 case GES_EDIT_MODE_NORMAL:
1655 timeline_move_object (timeline, object, layers, edge, position);
1657 case GES_EDIT_MODE_TRIM:
1658 timeline_trim_object (timeline, object, layers, edge, position);
1660 case GES_EDIT_MODE_RIPPLE:
1661 timeline_ripple_object (timeline, object, layers, edge, position);
1663 case GES_EDIT_MODE_ROLL:
1664 timeline_roll_object (timeline, object, layers, edge, position);
1666 case GES_EDIT_MODE_SLIDE:
1667 timeline_slide_object (timeline, object, layers, edge, position);
1670 GST_ERROR ("Unkown edit mode: %d", mode);