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,
62 ges_track_object_create_gnl_object_func (GESTrackObject * object);
65 ges_track_object_get_property (GObject * object, guint property_id,
66 GValue * value, GParamSpec * pspec)
68 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
70 switch (property_id) {
72 g_value_set_uint64 (value, tobj->start);
75 g_value_set_uint64 (value, tobj->inpoint);
78 g_value_set_uint64 (value, tobj->duration);
81 g_value_set_uint (value, tobj->priority);
84 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
89 ges_track_object_set_property (GObject * object, guint property_id,
90 const GValue * value, GParamSpec * pspec)
92 GESTrackObject *tobj = GES_TRACK_OBJECT (object);
94 switch (property_id) {
96 ges_track_object_set_start_internal (tobj, g_value_get_uint64 (value));
99 ges_track_object_set_inpoint_internal (tobj, g_value_get_uint64 (value));
102 ges_track_object_set_duration_internal (tobj, g_value_get_uint64 (value));
105 ges_track_object_set_priority_internal (tobj, g_value_get_uint (value));
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113 ges_track_object_dispose (GObject * object)
115 G_OBJECT_CLASS (ges_track_object_parent_class)->dispose (object);
119 ges_track_object_finalize (GObject * object)
121 G_OBJECT_CLASS (ges_track_object_parent_class)->finalize (object);
125 ges_track_object_class_init (GESTrackObjectClass * klass)
127 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 object_class->get_property = ges_track_object_get_property;
130 object_class->set_property = ges_track_object_set_property;
131 object_class->dispose = ges_track_object_dispose;
132 object_class->finalize = ges_track_object_finalize;
135 * GESTrackObject:start
137 * The position of the object in the container #GESTrack (in nanoseconds).
139 g_object_class_install_property (object_class, PROP_START,
140 g_param_spec_uint64 ("start", "Start",
141 "The position in the container", 0, G_MAXUINT64, 0,
145 * GESTrackObject:in-point
147 * The in-point at which this #GESTrackObject will start outputting data
148 * from its contents (in nanoseconds).
150 * Ex : an in-point of 5 seconds means that the first outputted buffer will
151 * be the one located 5 seconds in the controlled resource.
153 g_object_class_install_property (object_class, PROP_INPOINT,
154 g_param_spec_uint64 ("in-point", "In-point", "The in-point", 0,
155 G_MAXUINT64, 0, G_PARAM_READWRITE));
158 * GESTrackObject:duration
160 * The duration (in nanoseconds) which will be used in the container #GESTrack
161 * starting from 'in-point'.
164 g_object_class_install_property (object_class, PROP_DURATION,
165 g_param_spec_uint64 ("duration", "Duration", "The duration to use",
166 0, G_MAXUINT64, GST_SECOND, G_PARAM_READWRITE));
169 * GESTrackObject:priority
171 * The priority of the object within the containing #GESTrack.
172 * If two objects intersect over the same region of time, the @priority
173 * property is used to decide which one takes precedence.
175 * The highest priority (that supercedes everything) is 0, and then lowering
176 * priorities go in increasing numerical value (with #G_MAXUINT64 being the
179 g_object_class_install_property (object_class, PROP_PRIORITY,
180 g_param_spec_uint ("priority", "Priority",
181 "The priority of the object", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
183 klass->create_gnl_object = ges_track_object_create_gnl_object_func;
187 ges_track_object_init (GESTrackObject * self)
192 ges_track_object_set_start_internal (GESTrackObject * object, guint64 start)
194 g_return_val_if_fail (object->gnlobject, FALSE);
196 GST_DEBUG ("object:%p, start:%" GST_TIME_FORMAT,
197 object, GST_TIME_ARGS (start));
199 if (G_UNLIKELY (start == object->start))
202 g_object_set (object->gnlobject, "start", start, NULL);
207 ges_track_object_set_inpoint_internal (GESTrackObject * object, guint64 inpoint)
211 GST_DEBUG ("object:%p, inpoint:%" GST_TIME_FORMAT,
212 object, GST_TIME_ARGS (inpoint));
214 g_return_val_if_fail (object->gnlobject, FALSE);
216 if (G_UNLIKELY (inpoint == object->inpoint))
219 /* Calculate new media-start/duration/media-duration */
220 dur = object->inpoint - inpoint + object->duration;
222 g_object_set (object->gnlobject, "media-start", inpoint, "duration", dur,
223 "media-duration", dur, NULL);
228 ges_track_object_set_duration_internal (GESTrackObject * object,
231 GST_DEBUG ("object:%p, duration:%" GST_TIME_FORMAT,
232 object, GST_TIME_ARGS (duration));
234 g_return_val_if_fail (object->gnlobject, FALSE);
236 if (G_UNLIKELY (duration == object->duration))
239 g_object_set (object->gnlobject, "duration", duration, "media-duration",
245 ges_track_object_set_priority_internal (GESTrackObject * object,
248 GST_DEBUG ("object:%p, priority:%d", object, priority);
250 g_return_val_if_fail (object->gnlobject, FALSE);
252 if (G_UNLIKELY (priority == object->priority))
255 g_object_set (object->gnlobject, "priority", priority, NULL);
259 /* default 'create_gnl_object' virtual method implementation */
261 ges_track_object_create_gnl_object_func (GESTrackObject * object)
268 ensure_gnl_object (GESTrackObject * object)
270 GESTrackObjectClass *class;
273 if (object->gnlobject && object->valid)
276 /* 1. Create the GnlObject */
277 GST_DEBUG ("Creating GnlObject");
279 class = GES_TRACK_OBJECT_GET_CLASS (object);
281 if (G_UNLIKELY (class->create_gnl_object == NULL)) {
282 GST_ERROR ("No 'create_gnl_object' implementation !");
286 GST_DEBUG ("Calling virtual method");
288 /* call the create_gnl_object virtual method */
289 res = class->create_gnl_object (object);
291 if (G_UNLIKELY (res && (object->gnlobject == NULL))) {
293 ("'create_gnl_object' implementation returned TRUE but no GnlObject is available");
297 /* 2. Fill in the GnlObject */
299 GST_DEBUG ("Got a valid GnlObject, now filling it in");
302 ges_timeline_object_fill_track_object (object->timelineobj, object,
305 /* Set some properties on the GnlObject */
306 g_object_set (object->gnlobject, "caps", object->track->caps, NULL);
312 GST_DEBUG ("Returning res:%d", res);
318 ges_track_object_set_track (GESTrackObject * object, GESTrack * track)
320 GST_DEBUG ("object:%p, track:%p", object, track);
322 object->track = track;
325 return ensure_gnl_object (object);
331 ges_track_object_set_timeline_object (GESTrackObject * object,
332 GESTimelineObject * tlobj)
334 GST_DEBUG ("object:%p, timeline-object:%p", object, tlobj);
336 object->timelineobj = tlobj;