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", 0, G_MAXUINT64, G_MAXUINT64,
312 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 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
341 GES_TYPE_TRACK_OBJECT, GESTrackObjectPrivate);
343 /* Sane default values */
344 self->priv->pending_start = 0;
345 self->priv->pending_inpoint = 0;
346 self->priv->pending_duration = GST_SECOND;
347 self->priv->pending_priority = 1;
348 self->priv->pending_active = TRUE;
349 self->priv->locked = TRUE;
350 self->priv->properties_hashtable = NULL;
353 static inline gboolean
354 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start)
356 GST_DEBUG ("object:%p, start:%" GST_TIME_FORMAT,
357 object, GST_TIME_ARGS (start));
359 if (object->priv->gnlobject != NULL) {
360 if (G_UNLIKELY (start == object->start))
363 g_object_set (object->priv->gnlobject, "start", start, NULL);
365 object->priv->pending_start = start;
370 * ges_track_object_set_start:
371 * @object: a #GESTrackObject
372 * @start: the start position (in #GstClockTime)
374 * Sets the position of the object in the container #GESTrack.
377 ges_track_object_set_start (GESTrackObject * object, guint64 start)
379 if (ges_track_object_set_start_internal (object, start))
380 #if GLIB_CHECK_VERSION(2,26,0)
381 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_START]);
383 g_object_notify (G_OBJECT (object), "start");
387 static inline gboolean
388 ges_track_object_set_inpoint_internal (GESTrackObject * object, guint64 inpoint)
391 GST_DEBUG ("object:%p, inpoint:%" GST_TIME_FORMAT,
392 object, GST_TIME_ARGS (inpoint));
394 if (object->priv->gnlobject != NULL) {
395 if (G_UNLIKELY (inpoint == object->inpoint))
398 g_object_set (object->priv->gnlobject, "media-start", inpoint, NULL);
400 object->priv->pending_inpoint = inpoint;
406 * ges_track_object_set_inpoint:
407 * @object: a #GESTrackObject
408 * @inpoint: the in-point (in #GstClockTime)
410 * Set the offset within the contents of this #GESTrackObject
413 ges_track_object_set_inpoint (GESTrackObject * object, guint64 inpoint)
415 if (ges_track_object_set_inpoint_internal (object, inpoint))
416 #if GLIB_CHECK_VERSION(2,26,0)
417 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_INPOINT]);
419 g_object_notify (G_OBJECT (object), "in-point");
423 static inline gboolean
424 ges_track_object_set_duration_internal (GESTrackObject * object,
427 GST_DEBUG ("object:%p, duration:%" GST_TIME_FORMAT,
428 object, GST_TIME_ARGS (duration));
430 if (object->priv->gnlobject != NULL) {
431 if (G_UNLIKELY (duration == object->duration))
434 g_object_set (object->priv->gnlobject, "duration", duration,
435 "media-duration", duration, NULL);
437 object->priv->pending_duration = duration;
442 * ges_track_object_set_duration:
443 * @object: a #GESTrackObject
444 * @duration: the duration (in #GstClockTime)
446 * Set the duration which will be used in the container #GESTrack
447 * starting from the 'in-point'
450 ges_track_object_set_duration (GESTrackObject * object, guint64 duration)
452 if (ges_track_object_set_duration_internal (object, duration))
453 #if GLIB_CHECK_VERSION(2,26,0)
454 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_DURATION]);
456 g_object_notify (G_OBJECT (object), "duration");
460 static inline gboolean
461 ges_track_object_set_priority_internal (GESTrackObject * object,
464 GST_DEBUG ("object:%p, priority:%" G_GUINT32_FORMAT, object, priority);
466 if (object->priv->gnlobject != NULL) {
467 if (G_UNLIKELY (priority == object->priority))
470 g_object_set (object->priv->gnlobject, "priority", priority, NULL);
472 object->priv->pending_priority = priority;
477 * ges_track_object_set_priority:
478 * @object: a #GESTrackObject
479 * @priority: the priority
481 * Sets the priority of the object withing the containing #GESTrack.
482 * If two objects intersect over the same region of time, the priority
483 * property is used to decide which one takes precedence.
485 * The highest priority (that supercedes everything) is 0, and then
486 * lowering priorities go in increasing numerical value (with G_MAXUINT32
487 * being the lowest priority).
490 ges_track_object_set_priority (GESTrackObject * object, guint32 priority)
492 if (ges_track_object_set_priority_internal (object, priority))
493 #if GLIB_CHECK_VERSION(2,26,0)
494 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_PRIORITY]);
496 g_object_notify (G_OBJECT (object), "priority");
502 * ges_track_object_set_active:
503 * @object: a #GESTrackObject
504 * @active: visibility
506 * Sets the usage of the @object. If @active is %TRUE, the object will be used for
507 * playback and rendering, else it will be ignored.
509 * Returns: %TRUE if the property was toggled, else %FALSE
512 ges_track_object_set_active (GESTrackObject * object, gboolean active)
514 GST_DEBUG ("object:%p, active:%d", object, active);
516 if (object->priv->gnlobject != NULL) {
517 if (G_UNLIKELY (active == object->active))
520 g_object_set (object->priv->gnlobject, "active", active, NULL);
522 object->priv->pending_active = active;
526 /* Callbacks from the GNonLin object */
528 gnlobject_start_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
529 GESTrackObject * obj)
532 GESTrackObjectClass *klass;
534 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
536 g_object_get (gnlobject, "start", &start, NULL);
538 GST_DEBUG ("gnlobject start : %" GST_TIME_FORMAT " current : %"
539 GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (obj->start));
541 if (start != obj->start) {
543 if (klass->start_changed)
544 klass->start_changed (obj, start);
549 gst_element_prop_changed_cb (GstElement * element, GParamSpec * arg
550 G_GNUC_UNUSED, GESTrackObject * obj)
552 g_signal_emit (obj, ges_track_object_signals[DEEP_NOTIFY], 0,
553 GST_ELEMENT (element), arg);
557 connect_signal (gpointer key, gpointer value, gpointer user_data)
559 gchar *signame = g_strconcat ("notify::", G_PARAM_SPEC (key)->name, NULL);
561 g_signal_connect (G_OBJECT (value),
562 signame, G_CALLBACK (gst_element_prop_changed_cb),
563 GES_TRACK_OBJECT (user_data));
569 connect_properties_signals (GESTrackObject * object)
571 if (G_UNLIKELY (!object->priv->properties_hashtable)) {
572 GST_WARNING ("The properties_hashtable hasn't been set");
576 g_hash_table_foreach (object->priv->properties_hashtable,
577 (GHFunc) connect_signal, object);
581 /* Callbacks from the GNonLin object */
583 gnlobject_media_start_cb (GstElement * gnlobject,
584 GParamSpec * arg G_GNUC_UNUSED, GESTrackObject * obj)
587 GESTrackObjectClass *klass;
589 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
591 g_object_get (gnlobject, "media-start", &start, NULL);
593 GST_DEBUG ("gnlobject in-point : %" GST_TIME_FORMAT " current : %"
594 GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (obj->inpoint));
596 if (start != obj->inpoint) {
597 obj->inpoint = start;
598 if (klass->media_start_changed)
599 klass->media_start_changed (obj, start);
604 gnlobject_priority_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
605 GESTrackObject * obj)
608 GESTrackObjectClass *klass;
610 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
612 g_object_get (gnlobject, "priority", &priority, NULL);
614 GST_DEBUG ("gnlobject priority : %d current : %d", priority, obj->priority);
616 if (priority != obj->priority) {
617 obj->priority = priority;
618 if (klass->gnl_priority_changed)
619 klass->gnl_priority_changed (obj, priority);
624 gnlobject_duration_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
625 GESTrackObject * obj)
628 GESTrackObjectClass *klass;
630 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
632 g_object_get (gnlobject, "duration", &duration, NULL);
634 GST_DEBUG ("gnlobject duration : %" GST_TIME_FORMAT " current : %"
635 GST_TIME_FORMAT, GST_TIME_ARGS (duration), GST_TIME_ARGS (obj->duration));
637 if (duration != obj->duration) {
638 obj->duration = duration;
639 if (klass->duration_changed)
640 klass->duration_changed (obj, duration);
645 gnlobject_active_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
646 GESTrackObject * obj)
649 GESTrackObjectClass *klass;
651 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
653 g_object_get (gnlobject, "active", &active, NULL);
655 GST_DEBUG ("gnlobject active : %d current : %d", active, obj->active);
657 if (active != obj->active) {
658 obj->active = active;
659 if (klass->active_changed)
660 klass->active_changed (obj, active);
665 /* default 'create_gnl_object' virtual method implementation */
667 ges_track_object_create_gnl_object_func (GESTrackObject * self)
669 GESTrackObjectClass *klass = NULL;
670 GstElement *child = NULL;
671 GstElement *gnlobject;
673 klass = GES_TRACK_OBJECT_GET_CLASS (self);
675 if (G_UNLIKELY (self->priv->gnlobject != NULL))
676 goto already_have_gnlobject;
678 if (G_UNLIKELY (klass->gnlobject_factorytype == NULL))
681 GST_DEBUG ("Creating a supporting gnlobject of type '%s'",
682 klass->gnlobject_factorytype);
684 gnlobject = gst_element_factory_make (klass->gnlobject_factorytype, NULL);
686 if (G_UNLIKELY (gnlobject == NULL))
689 if (klass->create_element) {
690 GST_DEBUG ("Calling subclass 'create_element' vmethod");
691 child = klass->create_element (self);
693 if (G_UNLIKELY (!child))
696 if (!gst_bin_add (GST_BIN (gnlobject), child))
699 GST_DEBUG ("Succesfully got the element to put in the gnlobject");
700 self->priv->element = child;
709 already_have_gnlobject:
711 GST_ERROR ("Already controlling a GnlObject %s",
712 GST_ELEMENT_NAME (self->priv->gnlobject));
718 GST_ERROR ("No GESTrackObject::gnlobject_factorytype implementation!");
724 GST_ERROR ("Error creating a gnlobject of type '%s'",
725 klass->gnlobject_factorytype);
731 GST_ERROR ("create_element returned NULL");
732 gst_object_unref (gnlobject);
738 GST_ERROR ("Error adding the contents to the gnlobject");
739 gst_object_unref (child);
740 gst_object_unref (gnlobject);
746 ensure_gnl_object (GESTrackObject * object)
748 GESTrackObjectClass *class;
749 GstElement *gnlobject;
750 GHashTable *props_hash;
753 if (object->priv->gnlobject && object->priv->valid)
756 /* 1. Create the GnlObject */
757 GST_DEBUG ("Creating GnlObject");
759 class = GES_TRACK_OBJECT_GET_CLASS (object);
761 if (G_UNLIKELY (class->create_gnl_object == NULL)) {
762 GST_ERROR ("No 'create_gnl_object' implementation !");
766 GST_DEBUG ("Calling virtual method");
768 /* call the create_gnl_object virtual method */
769 gnlobject = class->create_gnl_object (object);
771 if (G_UNLIKELY (gnlobject == NULL)) {
773 ("'create_gnl_object' implementation returned TRUE but no GnlObject is available");
777 object->priv->gnlobject = gnlobject;
779 /* 2. Fill in the GnlObject */
781 GST_DEBUG ("Got a valid GnlObject, now filling it in");
783 if (object->priv->timelineobj)
784 res = ges_timeline_object_fill_track_object (object->priv->timelineobj,
785 object, object->priv->gnlobject);
790 /* Connect to property notifications */
791 /* FIXME : remember the signalids so we can remove them later on !!! */
792 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::start",
793 G_CALLBACK (gnlobject_start_cb), object);
794 g_signal_connect (G_OBJECT (object->priv->gnlobject),
795 "notify::media-start", G_CALLBACK (gnlobject_media_start_cb), object);
796 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::duration",
797 G_CALLBACK (gnlobject_duration_cb), object);
798 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::priority",
799 G_CALLBACK (gnlobject_priority_cb), object);
800 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::active",
801 G_CALLBACK (gnlobject_active_cb), object);
803 /* Set some properties on the GnlObject */
804 g_object_set (object->priv->gnlobject,
805 "caps", ges_track_get_caps (object->priv->track),
806 "duration", object->priv->pending_duration,
807 "media-duration", object->priv->pending_duration,
808 "start", object->priv->pending_start,
809 "media-start", object->priv->pending_inpoint,
810 "priority", object->priv->pending_priority,
811 "active", object->priv->pending_active, NULL);
813 /* We feed up the props_hashtable if possible */
814 if (class->get_props_hastable) {
815 props_hash = class->get_props_hastable (object);
817 if (props_hash == NULL) {
818 GST_DEBUG ("'get_props_hastable' implementation returned TRUE but no"
819 "properties_hashtable is available");
821 object->priv->properties_hashtable = props_hash;
822 connect_properties_signals (object);
829 object->priv->valid = res;
831 GST_DEBUG ("Returning res:%d", res);
838 ges_track_object_set_track (GESTrackObject * object, GESTrack * track)
840 GST_DEBUG ("object:%p, track:%p", object, track);
842 object->priv->track = track;
844 if (object->priv->track)
845 return ensure_gnl_object (object);
851 * ges_track_object_get_track:
852 * @object: a #GESTrackObject
854 * Get the #GESTrack to which this object belongs.
856 * Returns: (transfer none): The #GESTrack to which this object belongs. Can be %NULL if it
857 * is not in any track
860 ges_track_object_get_track (GESTrackObject * object)
862 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
864 return object->priv->track;
868 * ges_track_object_set_timeline_object:
869 * @object: The #GESTrackObject to set the parent to
870 * @tlobject: The #GESTimelineObject, parent of @tlobj or %NULL
872 * Set the #GESTimelineObject to which @object belongs.
875 ges_track_object_set_timeline_object (GESTrackObject * object,
876 GESTimelineObject * tlobject)
878 GST_DEBUG ("object:%p, timeline-object:%p", object, tlobject);
880 object->priv->timelineobj = tlobject;
884 * ges_track_object_get_timeline_object:
885 * @object: a #GESTrackObject
887 * Get the #GESTimelineObject which is controlling this track object
889 * Returns: (transfer none): the #GESTimelineObject which is controlling
893 ges_track_object_get_timeline_object (GESTrackObject * object)
895 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
897 return object->priv->timelineobj;
901 * ges_track_object_get_gnlobject:
902 * @object: a #GESTrackObject
904 * Get the GNonLin object this object is controlling.
906 * Returns: (transfer none): the GNonLin object this object is controlling.
909 ges_track_object_get_gnlobject (GESTrackObject * object)
911 return object->priv->gnlobject;
915 * ges_track_object_get_element:
916 * @object: a #GESTrackObject
918 * Get the #GstElement this track object is controlling within GNonLin.
920 * Returns: (transfer none): the #GstElement this track object is controlling
924 ges_track_object_get_element (GESTrackObject * object)
926 return object->priv->element;
930 ges_track_object_set_locked_internal (GESTrackObject * object, gboolean locked)
932 object->priv->locked = locked;
936 * ges_track_object_set_locked:
937 * @object: a #GESTrackObject
938 * @locked: whether the object is lock to its parent
940 * Set the locking status of the @object in relationship to its controlling
941 * #GESTimelineObject. If @locked is %TRUE, then this object will move synchronously
942 * with its controlling #GESTimelineObject.
945 ges_track_object_set_locked (GESTrackObject * object, gboolean locked)
947 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
949 GST_DEBUG_OBJECT (object, "%s object", locked ? "Locking" : "Unlocking");
951 ges_track_object_set_locked_internal (object, locked);
952 #if GLIB_CHECK_VERSION(2,26,0)
953 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_LOCKED]);
955 g_object_notify (G_OBJECT (object), "locked");
961 * ges_track_object_is_locked:
962 * @object: a #GESTrackObject
964 * Let you know if object us locked or not (moving synchronously).
966 * Returns: %TRUE if the object is moving synchronously to its controlling
967 * #GESTimelineObject, else %FALSE.
970 ges_track_object_is_locked (GESTrackObject * object)
972 return object->priv->locked;
976 * ges_track_object_get_start:
977 * @object: a #GESTrackObject
979 * Get the position of the object in the container #GESTrack.
981 * Returns: the start position (in #GstClockTime)
986 ges_track_object_get_start (GESTrackObject * object)
988 if (G_UNLIKELY (object->priv->gnlobject == NULL))
989 return object->priv->pending_start;
991 return object->start;
995 * ges_track_object_get_inpoint:
996 * @object: a #GESTrackObject
998 * Get the offset within the contents of this #GESTrackObject
1000 * Returns: the in-point (in #GstClockTime)
1005 ges_track_object_get_inpoint (GESTrackObject * object)
1007 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1008 return object->priv->pending_inpoint;
1010 return object->inpoint;
1014 * ges_track_object_get_duration:
1015 * @object: a #GESTrackObject
1017 * Get the duration which will be used in the container #GESTrack
1018 * starting from the 'in-point'
1020 * Returns: the duration (in #GstClockTime)
1025 ges_track_object_get_duration (GESTrackObject * object)
1027 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1028 return object->priv->pending_duration;
1030 return object->duration;
1034 * ges_track_object_get_priority:
1035 * @object: a #GESTrackObject
1037 * Get the priority of the object withing the containing #GESTrack.
1039 * Returns: the priority of @object
1044 ges_track_object_get_priority (GESTrackObject * object)
1046 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1047 return object->priv->pending_priority;
1049 return object->priority;
1053 * ges_track_object_is_active:
1054 * @object: a #GESTrackObject
1056 * Lets you know if @object will be used for playback and rendering,
1059 * Returns: %TRUE if @object is active, %FALSE otherwize
1064 ges_track_object_is_active (GESTrackObject * object)
1066 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1067 return object->priv->pending_active;
1069 return object->active;
1073 * ges_track_object_lookup_child:
1074 * @object: object to lookup the property in
1075 * @prop_name: name of the property to look up. You can specify the name of the
1076 * class as such: "ClassName::property-name", to guarantee that you get the
1077 * proper GParamSpec in case various GstElement-s contain the same property
1078 * name. If you don't do so, you will get the first element found, having
1079 * this property and the and the corresponding GParamSpec.
1080 * @element: (out) (allow-none) (transfer full): pointer to a #GstElement that
1081 * takes the real object to set property on
1082 * @pspec: (out) (allow-none) (transfer full): pointer to take the #GParamSpec
1083 * describing the property
1085 * Looks up which @element and @pspec would be effected by the given @name. If various
1086 * contained elements have this property name you will get the first one, unless you
1087 * specify the class name in @name.
1089 * Returns: TRUE if @element and @pspec could be found. FALSE otherwise. In that
1090 * case the values for @pspec and @element are not modified. Unref @element after
1096 ges_track_object_lookup_child (GESTrackObject * object, const gchar * prop_name,
1097 GstElement ** element, GParamSpec ** pspec)
1099 GHashTableIter iter;
1100 gpointer key, value;
1101 gchar **names, *name, *classename;
1103 GESTrackObjectPrivate *priv = object->priv;
1108 names = g_strsplit (prop_name, "::", 2);
1109 if (names[1] != NULL) {
1110 classename = names[0];
1115 g_hash_table_iter_init (&iter, priv->properties_hashtable);
1116 while (g_hash_table_iter_next (&iter, &key, &value)) {
1117 if (g_strcmp0 (G_PARAM_SPEC (key)->name, name) == 0) {
1118 if (classename == NULL ||
1119 g_strcmp0 (G_OBJECT_TYPE_NAME (G_OBJECT (value)), classename) == 0) {
1120 GST_DEBUG ("The %s property from %s has been found", name, classename);
1122 *element = g_object_ref (value);
1124 *pspec = g_param_spec_ref (key);
1136 * ges_track_object_set_child_property_by_pspec:
1137 * @object: a #GESTrackObject
1138 * @pspec: The #GParamSpec that specifies the property you want to set
1141 * Sets a property of a child of @object.
1146 ges_track_object_set_child_property_by_pspec (GESTrackObject * object,
1147 GParamSpec * pspec, GValue * value)
1149 GstElement *element;
1151 GESTrackObjectPrivate *priv = object->priv;
1153 if (!priv->properties_hashtable)
1154 goto prop_hash_not_set;
1156 element = g_hash_table_lookup (priv->properties_hashtable, pspec);
1160 g_object_set_property (G_OBJECT (element), pspec->name, value);
1166 GST_ERROR ("The %s property doesn't exist", pspec->name);
1171 GST_DEBUG ("The child properties haven't been set on %p", object);
1177 * ges_track_object_set_child_property_valist:
1178 * @object: The #GESTrackObject parent object
1179 * @first_property_name: The name of the first property to set
1180 * @var_args: value for the first property, followed optionally by more
1181 * name/return location pairs, followed by NULL
1183 * Sets a property of a child of @object. If there are various child elements
1184 * that have the same property name, you can distinguish them using the following
1185 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1186 * corresponding property of the first element found will be set.
1191 ges_track_object_set_child_property_valist (GESTrackObject * object,
1192 const gchar * first_property_name, va_list var_args)
1196 GstElement *element;
1198 gchar *error = NULL;
1199 GValue value = { 0, };
1201 g_return_if_fail (G_IS_OBJECT (object));
1203 name = first_property_name;
1205 /* Note: This part is in big part copied from the gst_child_object_set_valist
1208 /* iterate over pairs */
1210 if (!ges_track_object_lookup_child (object, name, &element, &pspec))
1213 #if GLIB_CHECK_VERSION(2,23,3)
1214 G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args,
1215 G_VALUE_NOCOPY_CONTENTS, &error);
1217 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1218 G_VALUE_COLLECT (&value, var_args, G_VALUE_NOCOPY_CONTENTS, &error);
1224 g_object_set_property (G_OBJECT (element), pspec->name, &value);
1226 g_object_unref (element);
1227 g_value_unset (&value);
1229 name = va_arg (var_args, gchar *);
1235 GST_WARNING ("No property %s in OBJECT\n", name);
1240 GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
1242 g_value_unset (&value);
1248 * ges_track_object_set_child_property:
1249 * @object: The #GESTrackObject parent object
1250 * @first_property_name: The name of the first property to set
1251 * @...: value for the first property, followed optionally by more
1252 * name/return location pairs, followed by NULL
1254 * Sets a property of a child of @object. If there are various child elements
1255 * that have the same property name, you can distinguish them using the following
1256 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1257 * corresponding property of the first element found will be set.
1262 ges_track_object_set_child_property (GESTrackObject * object,
1263 const gchar * first_property_name, ...)
1267 va_start (var_args, first_property_name);
1268 ges_track_object_set_child_property_valist (object, first_property_name,
1274 * ges_track_object_get_child_property_valist:
1275 * @object: The #GESTrackObject parent object
1276 * @first_property_name: The name of the first property to get
1277 * @var_args: value for the first property, followed optionally by more
1278 * name/return location pairs, followed by NULL
1280 * Gets a property of a child of @object. If there are various child elements
1281 * that have the same property name, you can distinguish them using the following
1282 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1283 * corresponding property of the first element found will be set.
1288 ges_track_object_get_child_property_valist (GESTrackObject * object,
1289 const gchar * first_property_name, va_list var_args)
1292 gchar *error = NULL;
1293 GValue value = { 0, };
1295 GstElement *element;
1297 g_return_if_fail (G_IS_OBJECT (object));
1299 name = first_property_name;
1301 /* This part is in big part copied from the gst_child_object_get_valist method */
1303 if (!ges_track_object_lookup_child (object, name, &element, &pspec))
1306 g_value_init (&value, pspec->value_type);
1307 g_object_get_property (G_OBJECT (element), pspec->name, &value);
1308 g_object_unref (element);
1310 G_VALUE_LCOPY (&value, var_args, 0, &error);
1313 g_value_unset (&value);
1314 name = va_arg (var_args, gchar *);
1320 GST_WARNING ("no property %s in object", name);
1325 GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
1327 g_value_unset (&value);
1333 * ges_track_object_list_children_properties:
1334 * @object: The #GESTrackObject to get the list of children properties from
1335 * @n_properties: return location for the length of the returned array
1337 * Gets an array of #GParamSpec* for all configurable properties of the
1338 * children of @object.
1340 * Returns: (transfer full) (array): an array of #GParamSpec* which should be freed after use or
1341 * %NULL if something went wrong
1346 ges_track_object_list_children_properties (GESTrackObject * object,
1347 guint * n_properties)
1349 GESTrackObjectClass *class;
1351 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
1353 class = GES_TRACK_OBJECT_GET_CLASS (object);
1355 return class->list_children_properties (object, n_properties);
1359 * ges_track_object_get_child_property:
1360 * @object: The origin #GESTrackObject
1361 * @first_property_name: The name of the first property to get
1362 * @...: return location for the first property, followed optionally by more
1363 * name/return location pairs, followed by NULL
1365 * Gets properties of a child of @object.
1370 ges_track_object_get_child_property (GESTrackObject * object,
1371 const gchar * first_property_name, ...)
1375 va_start (var_args, first_property_name);
1376 ges_track_object_get_child_property_valist (object, first_property_name,
1382 * ges_track_object_get_child_property_by_pspec:
1383 * @object: a #GESTrackObject
1384 * @pspec: The #GParamSpec that specifies the property you want to get
1385 * @value: return location for the value
1387 * Gets a property of a child of @object.
1392 ges_track_object_get_child_property_by_pspec (GESTrackObject * object,
1393 GParamSpec * pspec, GValue * value)
1395 GstElement *element;
1397 GESTrackObjectPrivate *priv = object->priv;
1399 if (!priv->properties_hashtable)
1400 goto prop_hash_not_set;
1402 element = g_hash_table_lookup (priv->properties_hashtable, pspec);
1406 g_object_get_property (G_OBJECT (element), pspec->name, value);
1412 GST_ERROR ("The %s property doesn't exist", pspec->name);
1417 GST_ERROR ("The child properties haven't been set on %p", object);
1422 static GParamSpec **
1423 default_list_children_properties (GESTrackObject * object, guint * n_properties)
1425 GParamSpec **pspec, *spec;
1426 GHashTableIter iter;
1427 gpointer key, value;
1431 if (!object->priv->properties_hashtable)
1432 goto prop_hash_not_set;
1434 *n_properties = g_hash_table_size (object->priv->properties_hashtable);
1435 pspec = g_new (GParamSpec *, *n_properties);
1437 g_hash_table_iter_init (&iter, object->priv->properties_hashtable);
1438 while (g_hash_table_iter_next (&iter, &key, &value)) {
1439 spec = G_PARAM_SPEC (key);
1440 pspec[i] = g_param_spec_ref (spec);
1449 GST_ERROR ("The child properties haven't been set on %p", object);
1455 * ges_track_object_get_max_duration:
1456 * @object: The #GESTrackObject to retrieve max duration from
1458 * Get the max duration of @object.
1460 * Returns: The max duration of @object
1465 ges_track_object_get_max_duration (GESTrackObject * object)
1467 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), 0);
1469 return object->priv->maxduration;
1473 * ges_track_object_set_max_duration:
1474 * @object: The #GESTrackObject to retrieve max duration from
1475 * @maxduration: The maximum duration of @object
1477 * Returns: Set the max duration of @object
1482 ges_track_object_set_max_duration (GESTrackObject * object, guint64 maxduration)
1484 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
1486 object->priv->maxduration = maxduration;