1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:ges-track-object
22 * @short_description: Base Class for objects contained in a #GESTrack
24 * #GESTrackObject is the Base Class for any object that can be contained in a
27 * It contains the basic information as to the location of the object within
28 * its container, like the start position, the in-point, the duration and the
32 #include "ges-internal.h"
33 #include "ges-track-object.h"
34 #include "ges-timeline-object.h"
36 static GQuark _start_quark;
37 static GQuark _inpoint_quark;
38 static GQuark _duration_quark;
39 static GQuark _priority_quark;
43 _start_quark = g_quark_from_static_string ("start"); \
44 _inpoint_quark = g_quark_from_static_string ("inpoint"); \
45 _duration_quark = g_quark_from_static_string ("duration"); \
46 _priority_quark = g_quark_from_static_string ("priority"); \
49 G_DEFINE_TYPE_WITH_CODE (GESTrackObject, ges_track_object, G_TYPE_OBJECT,
63 ges_track_object_create_gnl_object_func (GESTrackObject * object);
66 ges_track_object_get_property (GObject * object, guint property_id,
67 GValue * value, GParamSpec * pspec)
69 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
71 switch (property_id) {
73 g_value_set_uint64 (value, tobj->start);
76 g_value_set_uint64 (value, tobj->inpoint);
79 g_value_set_uint64 (value, tobj->duration);
82 g_value_set_uint (value, tobj->priority);
85 g_value_set_boolean (value, tobj->active);
88 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
93 ges_track_object_set_property (GObject * object, guint property_id,
94 const GValue * value, GParamSpec * pspec)
96 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
98 switch (property_id) {
100 ges_track_object_set_start_internal (tobj, g_value_get_uint64 (value));
103 ges_track_object_set_inpoint_internal (tobj, g_value_get_uint64 (value));
106 ges_track_object_set_duration_internal (tobj, g_value_get_uint64 (value));
109 ges_track_object_set_priority_internal (tobj, g_value_get_uint (value));
112 ges_track_object_set_active (tobj, g_value_get_boolean (value));
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
120 ges_track_object_dispose (GObject * object)
122 G_OBJECT_CLASS (ges_track_object_parent_class)->dispose (object);
126 ges_track_object_finalize (GObject * object)
128 G_OBJECT_CLASS (ges_track_object_parent_class)->finalize (object);
132 ges_track_object_class_init (GESTrackObjectClass * klass)
134 GObjectClass *object_class = G_OBJECT_CLASS (klass);
136 object_class->get_property = ges_track_object_get_property;
137 object_class->set_property = ges_track_object_set_property;
138 object_class->dispose = ges_track_object_dispose;
139 object_class->finalize = ges_track_object_finalize;
142 * GESTrackObject:start
144 * The position of the object in the container #GESTrack (in nanoseconds).
146 g_object_class_install_property (object_class, PROP_START,
147 g_param_spec_uint64 ("start", "Start",
148 "The position in the container", 0, G_MAXUINT64, 0,
152 * GESTrackObject:in-point
154 * The in-point at which this #GESTrackObject will start outputting data
155 * from its contents (in nanoseconds).
157 * Ex : an in-point of 5 seconds means that the first outputted buffer will
158 * be the one located 5 seconds in the controlled resource.
160 g_object_class_install_property (object_class, PROP_INPOINT,
161 g_param_spec_uint64 ("in-point", "In-point", "The in-point", 0,
162 G_MAXUINT64, 0, G_PARAM_READWRITE));
165 * GESTrackObject:duration
167 * The duration (in nanoseconds) which will be used in the container #GESTrack
168 * starting from 'in-point'.
171 g_object_class_install_property (object_class, PROP_DURATION,
172 g_param_spec_uint64 ("duration", "Duration", "The duration to use",
173 0, G_MAXUINT64, GST_SECOND, G_PARAM_READWRITE));
176 * GESTrackObject:priority
178 * The priority of the object within the containing #GESTrack.
179 * If two objects intersect over the same region of time, the @priority
180 * property is used to decide which one takes precedence.
182 * The highest priority (that supercedes everything) is 0, and then lowering
183 * priorities go in increasing numerical value (with #G_MAXUINT64 being the
186 g_object_class_install_property (object_class, PROP_PRIORITY,
187 g_param_spec_uint ("priority", "Priority",
188 "The priority of the object", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
191 * GESTrackObject:active
193 * Whether the object should be taken into account in the #GEStrack output.
194 * If #FALSE, then its contents will not be used in the resulting track.
196 g_object_class_install_property (object_class, PROP_ACTIVE,
197 g_param_spec_boolean ("active", "Active", "Use object in output",
198 TRUE, G_PARAM_READWRITE));
200 klass->create_gnl_object = ges_track_object_create_gnl_object_func;
204 ges_track_object_init (GESTrackObject * self)
206 /* Sane default values */
209 self->duration = GST_SECOND;
214 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start)
216 g_return_val_if_fail (object->gnlobject, FALSE);
218 GST_DEBUG ("object:%p, start:%" GST_TIME_FORMAT,
219 object, GST_TIME_ARGS (start));
221 if (G_UNLIKELY (start == object->start))
224 g_object_set (object->gnlobject, "start", start, NULL);
229 ges_track_object_set_inpoint_internal (GESTrackObject * object, guint64 inpoint)
233 GST_DEBUG ("object:%p, inpoint:%" GST_TIME_FORMAT,
234 object, GST_TIME_ARGS (inpoint));
236 g_return_val_if_fail (object->gnlobject, FALSE);
238 if (G_UNLIKELY (inpoint == object->inpoint))
241 /* Calculate new media-start/duration/media-duration */
242 dur = object->inpoint - inpoint + object->duration;
244 g_object_set (object->gnlobject, "media-start", inpoint, "duration", dur,
245 "media-duration", dur, NULL);
250 ges_track_object_set_duration_internal (GESTrackObject * object,
253 GST_DEBUG ("object:%p, duration:%" GST_TIME_FORMAT,
254 object, GST_TIME_ARGS (duration));
256 g_return_val_if_fail (object->gnlobject, FALSE);
258 if (G_UNLIKELY (duration == object->duration))
261 g_object_set (object->gnlobject, "duration", duration, "media-duration",
267 ges_track_object_set_priority_internal (GESTrackObject * object,
270 GST_DEBUG ("object:%p, priority:%d", object, priority);
272 g_return_val_if_fail (object->gnlobject, FALSE);
274 if (G_UNLIKELY (priority == object->priority))
277 g_object_set (object->gnlobject, "priority", priority, NULL);
282 ges_track_object_set_active (GESTrackObject * object, gboolean active)
284 GST_DEBUG ("object:%p, active:%d", object, active);
286 g_return_val_if_fail (object->gnlobject, FALSE);
288 if (G_UNLIKELY (active == object->active))
291 g_object_set (object->gnlobject, "active", active, NULL);
295 /* default 'create_gnl_object' virtual method implementation */
297 ges_track_object_create_gnl_object_func (GESTrackObject * object)
304 ensure_gnl_object (GESTrackObject * object)
306 GESTrackObjectClass *class;
309 if (object->gnlobject && object->valid)
312 /* 1. Create the GnlObject */
313 GST_DEBUG ("Creating GnlObject");
315 class = GES_TRACK_OBJECT_GET_CLASS (object);
317 if (G_UNLIKELY (class->create_gnl_object == NULL)) {
318 GST_ERROR ("No 'create_gnl_object' implementation !");
322 GST_DEBUG ("Calling virtual method");
324 /* call the create_gnl_object virtual method */
325 res = class->create_gnl_object (object);
327 if (G_UNLIKELY (res && (object->gnlobject == NULL))) {
329 ("'create_gnl_object' implementation returned TRUE but no GnlObject is available");
333 /* 2. Fill in the GnlObject */
335 GST_DEBUG ("Got a valid GnlObject, now filling it in");
338 ges_timeline_object_fill_track_object (object->timelineobj, object,
341 /* Set some properties on the GnlObject */
342 g_object_set (object->gnlobject, "caps", object->track->caps, NULL);
348 GST_DEBUG ("Returning res:%d", res);
354 ges_track_object_set_track (GESTrackObject * object, GESTrack * track)
356 GST_DEBUG ("object:%p, track:%p", object, track);
358 object->track = track;
361 return ensure_gnl_object (object);
367 ges_track_object_set_timeline_object (GESTrackObject * object,
368 GESTimelineObject * tlobj)
370 GST_DEBUG ("object:%p, timeline-object:%p", object, tlobj);
372 object->timelineobj = tlobj;