Document known and usable child properties for GESTrackElements subclasses
[platform/upstream/gst-editing-services.git] / ges / ges-video-source.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3  *               2009 Nokia Corporation
4  *
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.
9  *
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.
14  *
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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * SECTION:gesvideosource
23  * @short_description: Base Class for video sources
24  *
25  * <refsect1 id="GESVideoSource.children_properties" role="properties">
26  * <title role="children_properties.title">Children Properties</title>
27  * <para>You can use the following children properties through the
28  * #ges_track_element_set_child_property and alike set of methods:</para>
29  * <informaltable frame="none">
30  * <tgroup cols="3">
31  * <colspec colname="properties_type" colwidth="150px"/>
32  * <colspec colname="properties_name" colwidth="200px"/>
33  * <colspec colname="properties_flags" colwidth="400px"/>
34  * <tbody>
35  *
36  * <row>
37  *  <entry role="property_type"><link linkend="gdouble"><type>double</type></link></entry>
38  *  <entry role="property_name"><link linkend="GESVideoSource--alpha">alpha</link></entry>
39  *  <entry>The desired alpha for the stream.</entry>
40  * </row>
41  *
42  * <row>
43  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
44  *  <entry role="property_name"><link linkend="GESVideoSource--posx">posx</link></entry>
45  *  <entry>The desired x position for the stream.</entry>
46  * </row>
47  *
48  * <row>
49  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
50  *  <entry role="property_name"><link linkend="GESVideoSource--posy">posy</link></entry>
51  *  <entry>The desired y position for the stream</entry>
52  * </row>
53  *
54  * <row>
55  *  <entry role="property_type"><link linkend="guint"><type>guint</type></link></entry>
56  *  <entry role="property_name"><link linkend="GESVideoSource--zorder">zorder</link></entry>
57  *  <entry>The desired z order for the stream</entry>
58  * </row>
59  *
60  * <row>
61  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
62  *  <entry role="property_name"><link linkend="GESVideoSource--width">width</link></entry>
63  *  <entry>The desired width for that source. Set to 0 if size is not mandatory, will be set to width of the current track.</entry>
64  * </row>
65  *
66  * <row>
67  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
68  *  <entry role="property_name"><link linkend="GESVideoSource--height">height</link></entry>
69  *  <entry>The desired height for that source. Set to 0 if size is not mandatory, will be set to height of the current track.</entry>
70  * </row>
71  *
72  * </tbody>
73  * </tgroup>
74  * </informaltable>
75  * </refsect1>
76  */
77
78 #include <gst/pbutils/missing-plugins.h>
79
80 #include "ges-internal.h"
81 #include "ges/ges-meta-container.h"
82 #include "ges-track-element.h"
83 #include "ges-video-source.h"
84 #include "ges-layer.h"
85 #include "gstframepositionner.h"
86
87 G_DEFINE_ABSTRACT_TYPE (GESVideoSource, ges_video_source, GES_TYPE_SOURCE);
88
89 struct _GESVideoSourcePrivate
90 {
91   GstFramePositionner *positionner;
92   GstElement *capsfilter;
93   GESLayer *layer;
94 };
95
96 /* TrackElement VMethods */
97 static void
98 layer_priority_changed_cb (GESLayer * layer, GParamSpec * arg G_GNUC_UNUSED,
99     GESVideoSource * self)
100 {
101   g_object_set (self->priv->positionner, "zorder",
102       10000 - ges_layer_get_priority (layer), NULL);
103 }
104
105 static void
106 layer_changed_cb (GESClip * clip, GParamSpec * arg G_GNUC_UNUSED,
107     GESVideoSource * self)
108 {
109   GESVideoSourcePrivate *priv = self->priv;
110
111   if (priv->layer) {
112     g_signal_handlers_disconnect_by_func (priv->layer,
113         layer_priority_changed_cb, self);
114   }
115
116   priv->layer = ges_clip_get_layer (clip);
117   if (priv->layer == NULL)
118     return;
119
120   /* We do not need any ref ourself as our parent owns one and we are connected
121    * to it */
122   g_object_unref (priv->layer);
123   /* 10000 is the max value of zorder on videomixerpad, hardcoded */
124   g_signal_connect (self->priv->layer, "notify::priority",
125       G_CALLBACK (layer_priority_changed_cb), self);
126
127   g_object_set (self->priv->positionner, "zorder",
128       10000 - ges_layer_get_priority (self->priv->layer), NULL);
129 }
130
131 static void
132 post_missing_element_message (GstElement * element, const gchar * name)
133 {
134   GstMessage *msg;
135
136   msg = gst_missing_element_message_new (element, name);
137   gst_element_post_message (element, msg);
138 }
139
140 static GstElement *
141 ges_video_source_create_element (GESTrackElement * trksrc)
142 {
143   GstElement *topbin;
144   GstElement *sub_element;
145   GstElement *queue = gst_element_factory_make ("queue", NULL);
146   GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
147   GESVideoSource *self;
148   GstElement *positionner, *videoscale, *videorate, *capsfilter, *videoconvert,
149       *deinterlace;
150   const gchar *props[] = { "alpha", "posx", "posy", "width", "height", NULL };
151   GESTimelineElement *parent;
152
153   if (!source_class->create_source)
154     return NULL;
155
156   sub_element = source_class->create_source (trksrc);
157
158   self = (GESVideoSource *) trksrc;
159
160   /* That positionner will add metadata to buffers according to its
161      properties, acting like a proxy for our smart-mixer dynamic pads. */
162   positionner = gst_element_factory_make ("framepositionner", "frame_tagger");
163
164   videoscale =
165       gst_element_factory_make ("videoscale", "track-element-videoscale");
166   videoconvert =
167       gst_element_factory_make ("videoconvert", "track-element-videoconvert");
168   videorate = gst_element_factory_make ("videorate", "track-element-videorate");
169   deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
170   if (deinterlace == NULL) {
171     deinterlace = gst_element_factory_make ("avdeinterlace", "deinterlace");
172   }
173   capsfilter =
174       gst_element_factory_make ("capsfilter", "track-element-capsfilter");
175
176   ges_frame_positionner_set_source_and_filter (GST_FRAME_POSITIONNER
177       (positionner), trksrc, capsfilter);
178
179   ges_track_element_add_children_props (trksrc, positionner, NULL, NULL, props);
180
181   if (deinterlace == NULL) {
182     post_missing_element_message (sub_element, "deinterlace");
183
184     GST_ELEMENT_WARNING (sub_element, CORE, MISSING_PLUGIN,
185         ("Missing element '%s' - check your GStreamer installation.",
186             "deinterlace"), ("deinterlacing won't work"));
187     topbin =
188         ges_source_create_topbin ("videosrcbin", sub_element, queue,
189         videoconvert, positionner, videoscale, videorate, capsfilter, NULL);
190   } else {
191     topbin =
192         ges_source_create_topbin ("videosrcbin", sub_element, queue,
193         videoconvert, deinterlace, positionner, videoscale, videorate,
194         capsfilter, NULL);
195   }
196
197   parent = ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (trksrc));
198   if (parent) {
199     self->priv->positionner = GST_FRAME_POSITIONNER (positionner);
200     g_signal_connect (parent, "notify::layer",
201         (GCallback) layer_changed_cb, trksrc);
202     layer_changed_cb (GES_CLIP (parent), NULL, self);
203     gst_object_unref (parent);
204   } else {
205     GST_ERROR ("No parent timeline element, SHOULD NOT HAPPEN");
206   }
207
208   self->priv->capsfilter = capsfilter;
209
210   return topbin;
211 }
212
213 static gboolean
214 _set_parent (GESTimelineElement * self, GESTimelineElement * parent)
215 {
216   GESVideoSourcePrivate *priv = GES_VIDEO_SOURCE (self)->priv;
217
218   if (self->parent) {
219     if (priv->layer) {
220       g_signal_handlers_disconnect_by_func (priv->layer,
221           layer_priority_changed_cb, self);
222       priv->layer = NULL;
223     }
224
225     g_signal_handlers_disconnect_by_func (self->parent, layer_changed_cb, self);
226   }
227
228   if (parent && priv->positionner)
229     layer_changed_cb (GES_CLIP (parent), NULL, GES_VIDEO_SOURCE (self));
230
231
232   return TRUE;
233 }
234
235 static void
236 ges_video_source_class_init (GESVideoSourceClass * klass)
237 {
238   GESTrackElementClass *track_class = GES_TRACK_ELEMENT_CLASS (klass);
239   GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
240   GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
241
242   g_type_class_add_private (klass, sizeof (GESVideoSourcePrivate));
243
244   element_class->set_parent = _set_parent;
245   track_class->nleobject_factorytype = "nlesource";
246   track_class->create_element = ges_video_source_create_element;
247   video_source_class->create_source = NULL;
248 }
249
250 static void
251 ges_video_source_init (GESVideoSource * self)
252 {
253   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
254       GES_TYPE_VIDEO_SOURCE, GESVideoSourcePrivate);
255   self->priv->positionner = NULL;
256   self->priv->capsfilter = NULL;
257 }