Track: Implement remove_object()
[platform/upstream/gstreamer.git] / ges / ges-track.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "ges-internal.h"
21 #include "ges-track.h"
22 #include "ges-track-object.h"
23
24 /**
25  * GESTrack
26  *
27  * Corresponds to one output format (i.e. audio OR video)
28  *
29  * Contains the compatible TrackObject(s)
30  */
31
32 G_DEFINE_TYPE (GESTrack, ges_track, GST_TYPE_BIN);
33
34 static void
35 ges_track_get_property (GObject * object, guint property_id,
36     GValue * value, GParamSpec * pspec)
37 {
38   switch (property_id) {
39     default:
40       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
41   }
42 }
43
44 static void
45 ges_track_set_property (GObject * object, guint property_id,
46     const GValue * value, GParamSpec * pspec)
47 {
48   switch (property_id) {
49     default:
50       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
51   }
52 }
53
54 static void
55 ges_track_dispose (GObject * object)
56 {
57   GESTrack *track = (GESTrack *) object;
58
59   /* FIXME : Remove all TrackObjects ! */
60
61   if (track->composition) {
62     g_object_unref (track->composition);
63     track->composition = NULL;
64   }
65
66   G_OBJECT_CLASS (ges_track_parent_class)->dispose (object);
67 }
68
69 static void
70 ges_track_finalize (GObject * object)
71 {
72   G_OBJECT_CLASS (ges_track_parent_class)->finalize (object);
73 }
74
75 static void
76 ges_track_class_init (GESTrackClass * klass)
77 {
78   GObjectClass *object_class = G_OBJECT_CLASS (klass);
79
80   object_class->get_property = ges_track_get_property;
81   object_class->set_property = ges_track_set_property;
82   object_class->dispose = ges_track_dispose;
83   object_class->finalize = ges_track_finalize;
84 }
85
86 static void
87 ges_track_init (GESTrack * self)
88 {
89   self->composition = gst_element_factory_make ("gnlcomposition", NULL);
90 }
91
92 GESTrack *
93 ges_track_new (void)
94 {
95   return g_object_new (GES_TYPE_TRACK, NULL);
96 }
97
98 void
99 ges_track_set_timeline (GESTrack * track, GESTimeline * timeline)
100 {
101   GST_DEBUG ("track:%p, timeline:%p", track, timeline);
102
103   track->timeline = timeline;
104 }
105
106 gboolean
107 ges_track_add_object (GESTrack * track, GESTrackObject * object)
108 {
109   GST_DEBUG ("track:%p, object:%p", track, object);
110
111   if (G_UNLIKELY (object->track != NULL)) {
112     GST_WARNING ("Object already belongs to another track");
113     return FALSE;
114   }
115
116   if (G_UNLIKELY (object->gnlobject != NULL)) {
117     GST_ERROR ("TrackObject doesn't have a gnlobject !");
118     return FALSE;
119   }
120
121   if (G_UNLIKELY (!ges_track_object_set_track (object, track))) {
122     GST_ERROR ("Couldn't properly add the object to the Track");
123     return FALSE;
124   }
125
126   GST_DEBUG ("Adding object to ourself");
127
128   /* make sure the object has a valid gnlobject ! */
129   if (G_UNLIKELY (!gst_bin_add (GST_BIN (track->composition),
130               object->gnlobject))) {
131     GST_WARNING ("Couldn't add object to the GnlComposition");
132     return FALSE;
133   }
134
135   return TRUE;
136 }
137
138 gboolean
139 ges_track_remove_object (GESTrack * track, GESTrackObject * object)
140 {
141   GST_DEBUG ("track:%p, object:%p", track, object);
142
143   if (G_UNLIKELY (object->track != track)) {
144     GST_WARNING ("Object belongs to another track");
145     return FALSE;
146   }
147
148   if (G_LIKELY (object->gnlobject != NULL)) {
149     GST_DEBUG ("Removing GnlObject from composition");
150     if (!gst_bin_remove (GST_BIN (track->composition), object->gnlobject)) {
151       GST_WARNING ("Failed to remove gnlobject from composition");
152       return FALSE;
153     }
154   }
155
156   ges_track_object_set_track (object, NULL);
157
158   return TRUE;
159 }