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 "gesmarshal.h"
35 #include "ges-track-object.h"
36 #include "ges-timeline-object.h"
37 #include <gobject/gvaluecollector.h>
39 G_DEFINE_ABSTRACT_TYPE (GESTrackObject, ges_track_object,
40 G_TYPE_INITIALLY_UNOWNED);
42 struct _GESTrackObjectPrivate
44 /* These fields are only used before the gnlobject is available */
45 guint64 pending_start;
46 guint64 pending_inpoint;
47 guint64 pending_duration;
48 guint32 pending_priority;
49 gboolean pending_active;
51 GstElement *gnlobject; /* The GnlObject */
52 GstElement *element; /* The element contained in the gnlobject (can be NULL) */
54 /* We keep a link between properties name and elements internally
55 * The hashtable should look like
56 * {GParamaSpec ---> element,}*/
57 GHashTable *properties_hashtable;
59 GESTimelineObject *timelineobj;
64 gboolean locked; /* If TRUE, then moves in sync with its controlling
65 * GESTimelineObject */
79 static GParamSpec *properties[PROP_LAST];
87 static guint ges_track_object_signals[LAST_SIGNAL] = { 0 };
89 static GstElement *ges_track_object_create_gnl_object_func (GESTrackObject *
92 static void gnlobject_start_cb (GstElement * gnlobject, GParamSpec * arg
93 G_GNUC_UNUSED, GESTrackObject * obj);
95 static void gnlobject_media_start_cb (GstElement * gnlobject, GParamSpec * arg
96 G_GNUC_UNUSED, GESTrackObject * obj);
98 static void gnlobject_priority_cb (GstElement * gnlobject, GParamSpec * arg
99 G_GNUC_UNUSED, GESTrackObject * obj);
101 static void gnlobject_duration_cb (GstElement * gnlobject, GParamSpec * arg
102 G_GNUC_UNUSED, GESTrackObject * obj);
104 static void gnlobject_active_cb (GstElement * gnlobject, GParamSpec * arg
105 G_GNUC_UNUSED, GESTrackObject * obj);
107 static void connect_properties_signals (GESTrackObject * object);
108 static void connect_signal (gpointer key, gpointer value, gpointer user_data);
109 static void gst_element_prop_changed_cb (GstElement * element, GParamSpec * arg
110 G_GNUC_UNUSED, GESTrackObject * obj);
112 static inline gboolean
113 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start);
114 static inline gboolean
115 ges_track_object_set_inpoint_internal (GESTrackObject * object,
117 static inline gboolean ges_track_object_set_duration_internal (GESTrackObject *
118 object, guint64 duration);
119 static inline gboolean ges_track_object_set_priority_internal (GESTrackObject *
120 object, guint32 priority);
122 static GParamSpec **default_list_children_properties (GESTrackObject * object,
123 guint * n_properties);
126 ges_track_object_get_property (GObject * object, guint property_id,
127 GValue * value, GParamSpec * pspec)
129 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
131 switch (property_id) {
133 g_value_set_uint64 (value, ges_track_object_get_start (tobj));
136 g_value_set_uint64 (value, ges_track_object_get_inpoint (tobj));
139 g_value_set_uint64 (value, ges_track_object_get_duration (tobj));
142 g_value_set_uint (value, ges_track_object_get_priority (tobj));
145 g_value_set_boolean (value, ges_track_object_is_active (tobj));
148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
153 ges_track_object_set_property (GObject * object, guint property_id,
154 const GValue * value, GParamSpec * pspec)
156 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
158 switch (property_id) {
160 ges_track_object_set_start_internal (tobj, g_value_get_uint64 (value));
163 ges_track_object_set_inpoint_internal (tobj, g_value_get_uint64 (value));
166 ges_track_object_set_duration_internal (tobj, g_value_get_uint64 (value));
169 ges_track_object_set_priority_internal (tobj, g_value_get_uint (value));
172 ges_track_object_set_active (tobj, g_value_get_boolean (value));
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
180 ges_track_object_dispose (GObject * object)
182 GESTrackObjectPrivate *priv = GES_TRACK_OBJECT (object)->priv;
183 if (priv->properties_hashtable)
184 g_hash_table_destroy (priv->properties_hashtable);
186 G_OBJECT_CLASS (ges_track_object_parent_class)->dispose (object);
190 ges_track_object_finalize (GObject * object)
192 G_OBJECT_CLASS (ges_track_object_parent_class)->finalize (object);
196 ges_track_object_class_init (GESTrackObjectClass * klass)
198 GObjectClass *object_class = G_OBJECT_CLASS (klass);
200 g_type_class_add_private (klass, sizeof (GESTrackObjectPrivate));
202 object_class->get_property = ges_track_object_get_property;
203 object_class->set_property = ges_track_object_set_property;
204 object_class->dispose = ges_track_object_dispose;
205 object_class->finalize = ges_track_object_finalize;
208 * GESTrackObject:start
210 * The position of the object in the container #GESTrack (in nanoseconds).
212 properties[PROP_START] = g_param_spec_uint64 ("start", "Start",
213 "The position in the container", 0, G_MAXUINT64, 0, G_PARAM_READWRITE);
214 g_object_class_install_property (object_class, PROP_START,
215 properties[PROP_START]);
218 * GESTrackObject:in-point
220 * The in-point at which this #GESTrackObject will start outputting data
221 * from its contents (in nanoseconds).
223 * Ex: an in-point of 5 seconds means that the first outputted buffer will
224 * be the one located 5 seconds in the controlled resource.
226 properties[PROP_INPOINT] =
227 g_param_spec_uint64 ("in-point", "In-point", "The in-point", 0,
228 G_MAXUINT64, 0, G_PARAM_READWRITE);
229 g_object_class_install_property (object_class, PROP_INPOINT,
230 properties[PROP_INPOINT]);
233 * GESTrackObject:duration
235 * The duration (in nanoseconds) which will be used in the container #GESTrack
236 * starting from 'in-point'.
239 properties[PROP_DURATION] =
240 g_param_spec_uint64 ("duration", "Duration", "The duration to use", 0,
241 G_MAXUINT64, GST_SECOND, G_PARAM_READWRITE);
242 g_object_class_install_property (object_class, PROP_DURATION,
243 properties[PROP_DURATION]);
246 * GESTrackObject:priority
248 * The priority of the object within the containing #GESTrack.
249 * If two objects intersect over the same region of time, the @priority
250 * property is used to decide which one takes precedence.
252 * The highest priority (that supercedes everything) is 0, and then lowering
253 * priorities go in increasing numerical value (with #G_MAXUINT64 being the
256 properties[PROP_PRIORITY] = g_param_spec_uint ("priority", "Priority",
257 "The priority of the object", 0, G_MAXUINT, 0, G_PARAM_READWRITE);
258 g_object_class_install_property (object_class, PROP_PRIORITY,
259 properties[PROP_PRIORITY]);
262 * GESTrackObject:active
264 * Whether the object should be taken into account in the #GESTrack output.
265 * If #FALSE, then its contents will not be used in the resulting track.
267 properties[PROP_ACTIVE] =
268 g_param_spec_boolean ("active", "Active", "Use object in output", TRUE,
270 g_object_class_install_property (object_class, PROP_ACTIVE,
271 properties[PROP_ACTIVE]);
274 * GESTrackObject::deep-notify:
275 * @track_object: a #GESTrackObject
276 * @prop_object: the object that originated the signal
277 * @prop: the property that changed
279 * The deep notify signal is used to be notified of property changes of all
280 * the childs of @track_object
284 ges_track_object_signals[DEEP_NOTIFY] =
285 g_signal_new ("deep-notify", G_TYPE_FROM_CLASS (klass),
286 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED |
287 G_SIGNAL_NO_HOOKS, 0, NULL, NULL, gst_marshal_VOID__OBJECT_PARAM,
288 G_TYPE_NONE, 2, GST_TYPE_ELEMENT, G_TYPE_PARAM);
290 klass->create_gnl_object = ges_track_object_create_gnl_object_func;
291 /* There is no 'get_props_hashtable' default implementation */
292 klass->get_props_hastable = NULL;
293 klass->list_children_properties = default_list_children_properties;
297 ges_track_object_init (GESTrackObject * self)
299 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
300 GES_TYPE_TRACK_OBJECT, GESTrackObjectPrivate);
302 /* Sane default values */
303 self->priv->pending_start = 0;
304 self->priv->pending_inpoint = 0;
305 self->priv->pending_duration = GST_SECOND;
306 self->priv->pending_priority = 1;
307 self->priv->pending_active = TRUE;
308 self->priv->locked = TRUE;
309 self->priv->properties_hashtable = NULL;
312 static inline gboolean
313 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start)
315 GST_DEBUG ("object:%p, start:%" GST_TIME_FORMAT,
316 object, GST_TIME_ARGS (start));
318 if (object->priv->gnlobject != NULL) {
319 if (G_UNLIKELY (start == object->start))
322 g_object_set (object->priv->gnlobject, "start", start, NULL);
324 object->priv->pending_start = start;
329 * ges_track_object_set_start:
330 * @object: a #GESTrackObject
331 * @start: the start position (in #GstClockTime)
333 * Sets the position of the object in the container #GESTrack.
336 ges_track_object_set_start (GESTrackObject * object, guint64 start)
338 if (ges_track_object_set_start_internal (object, start))
339 #if GLIB_CHECK_VERSION(2,26,0)
340 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_START]);
342 g_object_notify (G_OBJECT (object), "start");
346 static inline gboolean
347 ges_track_object_set_inpoint_internal (GESTrackObject * object, guint64 inpoint)
350 GST_DEBUG ("object:%p, inpoint:%" GST_TIME_FORMAT,
351 object, GST_TIME_ARGS (inpoint));
353 if (object->priv->gnlobject != NULL) {
354 if (G_UNLIKELY (inpoint == object->inpoint))
357 g_object_set (object->priv->gnlobject, "media-start", inpoint, NULL);
359 object->priv->pending_inpoint = inpoint;
365 * ges_track_object_set_inpoint:
366 * @object: a #GESTrackObject
367 * @inpoint: the in-point (in #GstClockTime)
369 * Set the offset within the contents of this #GESTrackObject
372 ges_track_object_set_inpoint (GESTrackObject * object, guint64 inpoint)
374 if (ges_track_object_set_inpoint_internal (object, inpoint))
375 #if GLIB_CHECK_VERSION(2,26,0)
376 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_INPOINT]);
378 g_object_notify (G_OBJECT (object), "in-point");
382 static inline gboolean
383 ges_track_object_set_duration_internal (GESTrackObject * object,
386 GST_DEBUG ("object:%p, duration:%" GST_TIME_FORMAT,
387 object, GST_TIME_ARGS (duration));
389 if (object->priv->gnlobject != NULL) {
390 if (G_UNLIKELY (duration == object->duration))
393 g_object_set (object->priv->gnlobject, "duration", duration,
394 "media-duration", duration, NULL);
396 object->priv->pending_duration = duration;
401 * ges_track_object_set_duration:
402 * @object: a #GESTrackObject
403 * @duration: the duration (in #GstClockTime)
405 * Set the duration which will be used in the container #GESTrack
406 * starting from the 'in-point'
409 ges_track_object_set_duration (GESTrackObject * object, guint64 duration)
411 if (ges_track_object_set_duration_internal (object, duration))
412 #if GLIB_CHECK_VERSION(2,26,0)
413 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_DURATION]);
415 g_object_notify (G_OBJECT (object), "duration");
419 static inline gboolean
420 ges_track_object_set_priority_internal (GESTrackObject * object,
423 GST_DEBUG ("object:%p, priority:%" G_GUINT32_FORMAT, object, priority);
425 if (object->priv->gnlobject != NULL) {
426 if (G_UNLIKELY (priority == object->priority))
429 g_object_set (object->priv->gnlobject, "priority", priority, NULL);
431 object->priv->pending_priority = priority;
436 * ges_track_object_set_priority:
437 * @object: a #GESTrackObject
438 * @priority: the priority
440 * Sets the priority of the object withing the containing #GESTrack.
441 * If two objects intersect over the same region of time, the priority
442 * property is used to decide which one takes precedence.
444 * The highest priority (that supercedes everything) is 0, and then
445 * lowering priorities go in increasing numerical value (with G_MAXUINT32
446 * being the lowest priority).
449 ges_track_object_set_priority (GESTrackObject * object, guint32 priority)
451 if (ges_track_object_set_priority_internal (object, priority))
452 #if GLIB_CHECK_VERSION(2,26,0)
453 g_object_notify_by_pspec (G_OBJECT (object), properties[PROP_PRIORITY]);
455 g_object_notify (G_OBJECT (object), "priority");
461 * ges_track_object_set_active:
462 * @object: a #GESTrackObject
463 * @active: visibility
465 * Sets the usage of the @object. If @active is %TRUE, the object will be used for
466 * playback and rendering, else it will be ignored.
468 * Returns: %TRUE if the property was toggled, else %FALSE
471 ges_track_object_set_active (GESTrackObject * object, gboolean active)
473 GST_DEBUG ("object:%p, active:%d", object, active);
475 if (object->priv->gnlobject != NULL) {
476 if (G_UNLIKELY (active == object->active))
479 g_object_set (object->priv->gnlobject, "active", active, NULL);
481 object->priv->pending_active = active;
485 /* Callbacks from the GNonLin object */
487 gnlobject_start_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
488 GESTrackObject * obj)
491 GESTrackObjectClass *klass;
493 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
495 g_object_get (gnlobject, "start", &start, NULL);
497 GST_DEBUG ("gnlobject start : %" GST_TIME_FORMAT " current : %"
498 GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (obj->start));
500 if (start != obj->start) {
502 if (klass->start_changed)
503 klass->start_changed (obj, start);
508 gst_element_prop_changed_cb (GstElement * element, GParamSpec * arg
509 G_GNUC_UNUSED, GESTrackObject * obj)
511 g_signal_emit (obj, ges_track_object_signals[DEEP_NOTIFY], 0,
512 GST_ELEMENT (element), arg);
516 connect_signal (gpointer key, gpointer value, gpointer user_data)
518 gchar *signame = g_strconcat ("notify::", G_PARAM_SPEC (key)->name, NULL);
520 g_signal_connect (G_OBJECT (value),
521 signame, G_CALLBACK (gst_element_prop_changed_cb),
522 GES_TRACK_OBJECT (user_data));
528 connect_properties_signals (GESTrackObject * object)
530 if (G_UNLIKELY (!object->priv->properties_hashtable)) {
531 GST_WARNING ("The properties_hashtable hasn't been set");
535 g_hash_table_foreach (object->priv->properties_hashtable,
536 (GHFunc) connect_signal, object);
540 /* Callbacks from the GNonLin object */
542 gnlobject_media_start_cb (GstElement * gnlobject,
543 GParamSpec * arg G_GNUC_UNUSED, GESTrackObject * obj)
546 GESTrackObjectClass *klass;
548 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
550 g_object_get (gnlobject, "media-start", &start, NULL);
552 GST_DEBUG ("gnlobject in-point : %" GST_TIME_FORMAT " current : %"
553 GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (obj->inpoint));
555 if (start != obj->inpoint) {
556 obj->inpoint = start;
557 if (klass->media_start_changed)
558 klass->media_start_changed (obj, start);
563 gnlobject_priority_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
564 GESTrackObject * obj)
567 GESTrackObjectClass *klass;
569 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
571 g_object_get (gnlobject, "priority", &priority, NULL);
573 GST_DEBUG ("gnlobject priority : %d current : %d", priority, obj->priority);
575 if (priority != obj->priority) {
576 obj->priority = priority;
577 if (klass->gnl_priority_changed)
578 klass->gnl_priority_changed (obj, priority);
583 gnlobject_duration_cb (GstElement * gnlobject, GParamSpec * arg G_GNUC_UNUSED,
584 GESTrackObject * obj)
587 GESTrackObjectClass *klass;
589 klass = GES_TRACK_OBJECT_GET_CLASS (obj);
591 g_object_get (gnlobject, "duration", &duration, NULL);
593 GST_DEBUG ("gnlobject duration : %" GST_TIME_FORMAT " current : %"
594 GST_TIME_FORMAT, GST_TIME_ARGS (duration), GST_TIME_ARGS (obj->duration));
596 if (duration != obj->duration) {
597 obj->duration = duration;
598 if (klass->duration_changed)
599 klass->duration_changed (obj, duration);
604 gnlobject_active_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, "active", &active, NULL);
614 GST_DEBUG ("gnlobject active : %d current : %d", active, obj->active);
616 if (active != obj->active) {
617 obj->active = active;
618 if (klass->active_changed)
619 klass->active_changed (obj, active);
624 /* default 'create_gnl_object' virtual method implementation */
626 ges_track_object_create_gnl_object_func (GESTrackObject * self)
628 GESTrackObjectClass *klass = NULL;
629 GstElement *child = NULL;
630 GstElement *gnlobject;
632 klass = GES_TRACK_OBJECT_GET_CLASS (self);
634 if (G_UNLIKELY (self->priv->gnlobject != NULL))
635 goto already_have_gnlobject;
637 if (G_UNLIKELY (klass->gnlobject_factorytype == NULL))
640 GST_DEBUG ("Creating a supporting gnlobject of type '%s'",
641 klass->gnlobject_factorytype);
643 gnlobject = gst_element_factory_make (klass->gnlobject_factorytype, NULL);
645 if (G_UNLIKELY (gnlobject == NULL))
648 if (klass->create_element) {
649 GST_DEBUG ("Calling subclass 'create_element' vmethod");
650 child = klass->create_element (self);
652 if (G_UNLIKELY (!child))
655 if (!gst_bin_add (GST_BIN (gnlobject), child))
658 GST_DEBUG ("Succesfully got the element to put in the gnlobject");
659 self->priv->element = child;
668 already_have_gnlobject:
670 GST_ERROR ("Already controlling a GnlObject %s",
671 GST_ELEMENT_NAME (self->priv->gnlobject));
677 GST_ERROR ("No GESTrackObject::gnlobject_factorytype implementation!");
683 GST_ERROR ("Error creating a gnlobject of type '%s'",
684 klass->gnlobject_factorytype);
690 GST_ERROR ("create_element returned NULL");
691 gst_object_unref (gnlobject);
697 GST_ERROR ("Error adding the contents to the gnlobject");
698 gst_object_unref (child);
699 gst_object_unref (gnlobject);
705 ensure_gnl_object (GESTrackObject * object)
707 GESTrackObjectClass *class;
708 GstElement *gnlobject;
709 GHashTable *props_hash;
710 gboolean res = FALSE;
712 if (object->priv->gnlobject && object->priv->valid)
715 /* 1. Create the GnlObject */
716 GST_DEBUG ("Creating GnlObject");
718 class = GES_TRACK_OBJECT_GET_CLASS (object);
720 if (G_UNLIKELY (class->create_gnl_object == NULL)) {
721 GST_ERROR ("No 'create_gnl_object' implementation !");
725 GST_DEBUG ("Calling virtual method");
727 /* call the create_gnl_object virtual method */
728 gnlobject = class->create_gnl_object (object);
730 if (G_UNLIKELY (gnlobject == NULL)) {
732 ("'create_gnl_object' implementation returned TRUE but no GnlObject is available");
736 object->priv->gnlobject = gnlobject;
738 /* 2. Fill in the GnlObject */
740 GST_DEBUG ("Got a valid GnlObject, now filling it in");
743 ges_timeline_object_fill_track_object (object->priv->timelineobj,
744 object, object->priv->gnlobject);
746 /* Connect to property notifications */
747 /* FIXME : remember the signalids so we can remove them later on !!! */
748 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::start",
749 G_CALLBACK (gnlobject_start_cb), object);
750 g_signal_connect (G_OBJECT (object->priv->gnlobject),
751 "notify::media-start", G_CALLBACK (gnlobject_media_start_cb), object);
752 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::duration",
753 G_CALLBACK (gnlobject_duration_cb), object);
754 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::priority",
755 G_CALLBACK (gnlobject_priority_cb), object);
756 g_signal_connect (G_OBJECT (object->priv->gnlobject), "notify::active",
757 G_CALLBACK (gnlobject_active_cb), object);
759 /* Set some properties on the GnlObject */
760 g_object_set (object->priv->gnlobject,
761 "caps", ges_track_get_caps (object->priv->track),
762 "duration", object->priv->pending_duration,
763 "media-duration", object->priv->pending_duration,
764 "start", object->priv->pending_start,
765 "media-start", object->priv->pending_inpoint,
766 "priority", object->priv->pending_priority,
767 "active", object->priv->pending_active, NULL);
769 /* We feed up the props_hashtable if possible */
770 if (class->get_props_hastable) {
771 props_hash = class->get_props_hastable (object);
773 if (props_hash == NULL) {
774 GST_DEBUG ("'get_props_hastable' implementation returned TRUE but no"
775 "properties_hashtable is available");
777 object->priv->properties_hashtable = props_hash;
778 connect_properties_signals (object);
785 object->priv->valid = res;
787 GST_DEBUG ("Returning res:%d", res);
794 ges_track_object_set_track (GESTrackObject * object, GESTrack * track)
796 GST_DEBUG ("object:%p, track:%p", object, track);
798 object->priv->track = track;
800 if (object->priv->track)
801 return ensure_gnl_object (object);
807 * ges_track_object_get_track:
808 * @object: a #GESTrackObject
810 * Get the #GESTrack to which this object belongs.
812 * Returns: (transfer none): The #GESTrack to which this object belongs. Can be %NULL if it
813 * is not in any track
816 ges_track_object_get_track (GESTrackObject * object)
818 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
820 return object->priv->track;
825 ges_track_object_set_timeline_object (GESTrackObject * object,
826 GESTimelineObject * tlobj)
828 GST_DEBUG ("object:%p, timeline-object:%p", object, tlobj);
830 object->priv->timelineobj = tlobj;
834 * ges_track_object_get_timeline_object:
835 * @object: a #GESTrackObject
837 * Get the #GESTimelineObject which is controlling this track object
839 * Returns: (transfer none): the #GESTimelineObject which is controlling
843 ges_track_object_get_timeline_object (GESTrackObject * object)
845 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
847 return object->priv->timelineobj;
851 * ges_track_object_get_gnlobject:
852 * @object: a #GESTrackObject
854 * Get the GNonLin object this object is controlling.
856 * Returns: (transfer none): the GNonLin object this object is controlling.
859 ges_track_object_get_gnlobject (GESTrackObject * object)
861 return object->priv->gnlobject;
865 * ges_track_object_get_element:
866 * @object: a #GESTrackObject
868 * Get the #GstElement this track object is controlling within GNonLin.
870 * Returns: (transfer none): the #GstElement this track object is controlling
874 ges_track_object_get_element (GESTrackObject * object)
876 return object->priv->element;
880 * ges_track_object_set_locked:
881 * @object: a #GESTrackObject
882 * @locked: whether the object is lock to its parent
884 * Set the locking status of the @object in relationship to its controlling
885 * #GESTimelineObject. If @locked is %TRUE, then this object will move synchronously
886 * with its controlling #GESTimelineObject.
889 ges_track_object_set_locked (GESTrackObject * object, gboolean locked)
891 g_return_if_fail (GES_IS_TRACK_OBJECT (object));
893 GST_DEBUG_OBJECT (object, "%s object", locked ? "Locking" : "Unlocking");
895 object->priv->locked = locked;
899 * ges_track_object_is_locked:
900 * @object: a #GESTrackObject
902 * Let you know if object us locked or not (moving synchronously).
904 * Returns: %TRUE if the object is moving synchronously to its controlling
905 * #GESTimelineObject, else %FALSE.
908 ges_track_object_is_locked (GESTrackObject * object)
910 return object->priv->locked;
914 * ges_track_object_get_start:
915 * @object: a #GESTrackObject
917 * Get the position of the object in the container #GESTrack.
919 * Returns: the start position (in #GstClockTime)
924 ges_track_object_get_start (GESTrackObject * object)
926 if (G_UNLIKELY (object->priv->gnlobject == NULL))
927 return object->priv->pending_start;
929 return object->start;
933 * ges_track_object_get_inpoint:
934 * @object: a #GESTrackObject
936 * Get the offset within the contents of this #GESTrackObject
938 * Returns: the in-point (in #GstClockTime)
943 ges_track_object_get_inpoint (GESTrackObject * object)
945 if (G_UNLIKELY (object->priv->gnlobject == NULL))
946 return object->priv->pending_inpoint;
948 return object->inpoint;
952 * ges_track_object_get_duration:
953 * @object: a #GESTrackObject
955 * Get the duration which will be used in the container #GESTrack
956 * starting from the 'in-point'
958 * Returns: the duration (in #GstClockTime)
963 ges_track_object_get_duration (GESTrackObject * object)
965 if (G_UNLIKELY (object->priv->gnlobject == NULL))
966 return object->priv->pending_duration;
968 return object->duration;
972 * ges_track_object_get_priority:
973 * @object: a #GESTrackObject
975 * Get the priority of the object withing the containing #GESTrack.
977 * Returns: the priority of @object
982 ges_track_object_get_priority (GESTrackObject * object)
984 if (G_UNLIKELY (object->priv->gnlobject == NULL))
985 return object->priv->pending_priority;
987 return object->priority;
991 * ges_track_object_is_active:
992 * @object: a #GESTrackObject
994 * Lets you know if @object will be used for playback and rendering,
997 * Returns: %TRUE if @object is active, %FALSE otherwize
1002 ges_track_object_is_active (GESTrackObject * object)
1004 if (G_UNLIKELY (object->priv->gnlobject == NULL))
1005 return object->priv->pending_active;
1007 return object->active;
1011 * ges_track_object_lookup_child:
1012 * @object: object to lookup the property in
1013 * @prop_name: name of the property to look up. You can specify the name of the
1014 * class as such: "ClassName::property-name", to guarantee that you get the
1015 * proper GParamSpec in case various GstElement-s contain the same property
1016 * name. If you don't do so, you will get the first element found, having
1017 * this property and the and the corresponding GParamSpec.
1018 * @element: (out) (allow-none) (transfer full): pointer to a #GstElement that
1019 * takes the real object to set property on
1020 * @pspec: (out) (allow-none) (transfer full): pointer to take the #GParamSpec
1021 * describing the property
1023 * Looks up which @element and @pspec would be effected by the given @name. If various
1024 * contained elements have this property name you will get the first one, unless you
1025 * specify the class name in @name.
1027 * Returns: TRUE if @element and @pspec could be found. FALSE otherwise. In that
1028 * case the values for @pspec and @element are not modified. Unref @element after
1034 ges_track_object_lookup_child (GESTrackObject * object, const gchar * prop_name,
1035 GstElement ** element, GParamSpec ** pspec)
1037 GHashTableIter iter;
1038 gpointer key, value;
1039 gchar **names, *name, *classename;
1041 GESTrackObjectPrivate *priv = object->priv;
1046 names = g_strsplit (prop_name, "::", 2);
1047 if (names[1] != NULL) {
1048 classename = names[0];
1053 g_hash_table_iter_init (&iter, priv->properties_hashtable);
1054 while (g_hash_table_iter_next (&iter, &key, &value)) {
1055 if (g_strcmp0 (G_PARAM_SPEC (key)->name, name) == 0) {
1056 if (classename == NULL ||
1057 g_strcmp0 (G_OBJECT_TYPE_NAME (G_OBJECT (value)), classename) == 0) {
1058 GST_DEBUG ("The %s property from %s has been found", name, classename);
1060 *element = g_object_ref (value);
1062 *pspec = g_param_spec_ref (key);
1074 * ges_track_object_set_child_property_by_pspec:
1075 * @object: a #GESTrackObject
1076 * @pspec: The #GParamSpec that specifies the property you want to set
1079 * Sets a property of a child of @object.
1084 ges_track_object_set_child_property_by_pspec (GESTrackObject * object,
1085 GParamSpec * pspec, GValue * value)
1087 GstElement *element;
1089 GESTrackObjectPrivate *priv = object->priv;
1091 if (!priv->properties_hashtable)
1092 goto prop_hash_not_set;
1094 element = g_hash_table_lookup (priv->properties_hashtable, pspec);
1098 g_object_set_property (G_OBJECT (element), pspec->name, value);
1104 GST_ERROR ("The %s property doesn't exist", pspec->name);
1109 GST_DEBUG ("The child properties haven't been set on %p", object);
1115 * ges_track_object_set_child_property_valist:
1116 * @object: The #GESTrackObject parent object
1117 * @first_property_name: The name of the first property to set
1118 * @var_args: value for the first property, followed optionally by more
1119 * name/return location pairs, followed by NULL
1121 * Sets a property of a child of @object. If there are various child elements
1122 * that have the same property name, you can distinguish them using the following
1123 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1124 * corresponding property of the first element found will be set.
1129 ges_track_object_set_child_property_valist (GESTrackObject * object,
1130 const gchar * first_property_name, va_list var_args)
1134 GstElement *element;
1136 gchar *error = NULL;
1137 GValue value = { 0, };
1139 g_return_if_fail (G_IS_OBJECT (object));
1141 name = first_property_name;
1143 /* Note: This part is in big part copied from the gst_child_object_set_valist
1146 /* iterate over pairs */
1148 if (!ges_track_object_lookup_child (object, name, &element, &pspec))
1151 #if GLIB_CHECK_VERSION(2,23,3)
1152 G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args,
1153 G_VALUE_NOCOPY_CONTENTS, &error);
1155 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1156 G_VALUE_COLLECT (&value, var_args, G_VALUE_NOCOPY_CONTENTS, &error);
1162 g_object_set_property (G_OBJECT (element), pspec->name, &value);
1164 g_object_unref (element);
1165 g_value_unset (&value);
1167 name = va_arg (var_args, gchar *);
1173 GST_WARNING ("No property %s in OBJECT\n", name);
1178 GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
1180 g_value_unset (&value);
1186 * ges_track_object_set_child_property:
1187 * @object: The #GESTrackObject parent object
1188 * @first_property_name: The name of the first property to set
1189 * @...: value for the first property, followed optionally by more
1190 * name/return location pairs, followed by NULL
1192 * Sets a property of a child of @object. If there are various child elements
1193 * that have the same property name, you can distinguish them using the following
1194 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1195 * corresponding property of the first element found will be set.
1200 ges_track_object_set_child_property (GESTrackObject * object,
1201 const gchar * first_property_name, ...)
1205 va_start (var_args, first_property_name);
1206 ges_track_object_set_child_property_valist (object, first_property_name,
1212 * ges_track_object_get_child_property_valist:
1213 * @object: The #GESTrackObject parent object
1214 * @first_property_name: The name of the first property to get
1215 * @var_args: value for the first property, followed optionally by more
1216 * name/return location pairs, followed by NULL
1218 * Gets a property of a child of @object. If there are various child elements
1219 * that have the same property name, you can distinguish them using the following
1220 * syntax: 'ClasseName::property_name' as property name. If you don't, the
1221 * corresponding property of the first element found will be set.
1226 ges_track_object_get_child_property_valist (GESTrackObject * object,
1227 const gchar * first_property_name, va_list var_args)
1230 gchar *error = NULL;
1231 GValue value = { 0, };
1233 GstElement *element;
1235 g_return_if_fail (G_IS_OBJECT (object));
1237 name = first_property_name;
1239 /* This part is in big part copied from the gst_child_object_get_valist method */
1241 if (!ges_track_object_lookup_child (object, name, &element, &pspec))
1244 g_value_init (&value, pspec->value_type);
1245 g_object_get_property (G_OBJECT (element), pspec->name, &value);
1246 g_object_unref (element);
1248 G_VALUE_LCOPY (&value, var_args, 0, &error);
1251 g_value_unset (&value);
1252 name = va_arg (var_args, gchar *);
1258 GST_WARNING ("no property %s in object", name);
1263 GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
1265 g_value_unset (&value);
1271 * ges_track_object_list_children_properties:
1272 * @object: The #GESTrackObject to get the list of children properties from
1273 * @n_properties: return location for the length of the returned array
1275 * Gets an array of #GParamSpec* for all configurable properties of the
1276 * children of @object.
1278 * Returns: (transfer full) (array): an array of #GParamSpec* which should be freed after use or
1279 * %NULL if something went wrong
1284 ges_track_object_list_children_properties (GESTrackObject * object,
1285 guint * n_properties)
1287 GESTrackObjectClass *class;
1289 g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), NULL);
1291 class = GES_TRACK_OBJECT_GET_CLASS (object);
1293 return class->list_children_properties (object, n_properties);
1297 * ges_track_object_get_child_property:
1298 * @object: The origin #GESTrackObject
1299 * @first_property_name: The name of the first property to get
1300 * @...: return location for the first property, followed optionally by more
1301 * name/return location pairs, followed by NULL
1303 * Gets properties of a child of @object.
1308 ges_track_object_get_child_property (GESTrackObject * object,
1309 const gchar * first_property_name, ...)
1313 va_start (var_args, first_property_name);
1314 ges_track_object_get_child_property_valist (object, first_property_name,
1320 * ges_track_object_get_child_property_by_pspec:
1321 * @object: a #GESTrackObject
1322 * @pspec: The #GParamSpec that specifies the property you want to get
1323 * @value: return location for the value
1325 * Gets a property of a child of @object.
1330 ges_track_object_get_child_property_by_pspec (GESTrackObject * object,
1331 GParamSpec * pspec, GValue * value)
1333 GstElement *element;
1335 GESTrackObjectPrivate *priv = object->priv;
1337 if (!priv->properties_hashtable)
1338 goto prop_hash_not_set;
1340 element = g_hash_table_lookup (priv->properties_hashtable, pspec);
1344 g_object_get_property (G_OBJECT (element), pspec->name, value);
1350 GST_ERROR ("The %s property doesn't exist", pspec->name);
1355 GST_ERROR ("The child properties haven't been set on %p", object);
1360 static GParamSpec **
1361 default_list_children_properties (GESTrackObject * object, guint * n_properties)
1363 GParamSpec **pspec, *spec;
1364 GHashTableIter iter;
1365 gpointer key, value;
1369 if (!object->priv->properties_hashtable)
1370 goto prop_hash_not_set;
1372 *n_properties = g_hash_table_size (object->priv->properties_hashtable);
1373 pspec = g_new (GParamSpec *, *n_properties);
1375 g_hash_table_iter_init (&iter, object->priv->properties_hashtable);
1376 while (g_hash_table_iter_next (&iter, &key, &value)) {
1377 spec = G_PARAM_SPEC (key);
1378 pspec[i] = g_param_spec_ref (spec);
1387 GST_ERROR ("The child properties haven't been set on %p", object);