docs: Port all docstring to gtk-doc markdown
[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  * @title: GESVideoSource
24  * @short_description: Base Class for video sources
25  *
26  * <refsect1 id="GESVideoSource.children_properties" role="properties">
27  * # Children Properties
28  * You can use the following children properties through the
29  * #ges_track_element_set_child_property and alike set of methods:
30  * <informaltable frame="none">
31  * <tgroup cols="3">
32  * <colspec colname="properties_type" colwidth="150px"/>
33  * <colspec colname="properties_name" colwidth="200px"/>
34  * <colspec colname="properties_flags" colwidth="400px"/>
35  * <tbody>
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  * <row>
42  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
43  *  <entry role="property_name"><link linkend="GESVideoSource--posx">posx</link></entry>
44  *  <entry>The desired x position for the stream.</entry>
45  * </row>
46  * <row>
47  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
48  *  <entry role="property_name"><link linkend="GESVideoSource--posy">posy</link></entry>
49  *  <entry>The desired y position for the stream</entry>
50  * </row>
51  * <row>
52  *  <entry role="property_type"><link linkend="guint"><type>guint</type></link></entry>
53  *  <entry role="property_name"><link linkend="GESVideoSource--zorder">zorder</link></entry>
54  *  <entry>The desired z order for the stream</entry>
55  * </row>
56  * <row>
57  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
58  *  <entry role="property_name"><link linkend="GESVideoSource--width">width</link></entry>
59  *  <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>
60  * </row>
61  * <row>
62  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
63  *  <entry role="property_name"><link linkend="GESVideoSource--height">height</link></entry>
64  *  <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>
65  * </row>
66  * <row>
67  *  <entry role="property_type"><link linkend="GstDeinterlaceModes"><type>GstDeinterlaceModes</type></link></entry>
68  *  <entry role="property_name"><link linkend="GESVideoSource--deinterlace-mode">deinterlace-mode</link></entry>
69  *  <entry>Deinterlace Mode</entry>
70  * </row>
71  * <row>
72  *  <entry role="property_type"><link linkend="GstDeinterlaceFields"><type>GstDeinterlaceFields</type></link></entry>
73  *  <entry role="property_name"><link linkend="GESVideoSource--deinterlace-fields">deinterlace-fields</link></entry>
74  *  <entry>Fields to use for deinterlacing</entry>
75  * </row>
76  * <row>
77  *  <entry role="property_type"><link linkend="GstDeinterlaceFieldLayout"><type>GstDeinterlaceFieldLayout</type></link></entry>
78  *  <entry role="property_name"><link linkend="GESVideoSource--deinterlace-tff">deinterlace-tff</link></entry>
79  *  <entry>Deinterlace top field first</entry>
80  * </row>
81  * </tbody>
82  * </tgroup>
83  * </informaltable>
84  * </refsect1>
85  */
86
87 #include <gst/pbutils/missing-plugins.h>
88
89 #include "ges-internal.h"
90 #include "ges/ges-meta-container.h"
91 #include "ges-track-element.h"
92 #include "ges-video-source.h"
93 #include "ges-layer.h"
94 #include "gstframepositioner.h"
95
96 #define parent_class ges_video_source_parent_class
97 G_DEFINE_ABSTRACT_TYPE (GESVideoSource, ges_video_source, GES_TYPE_SOURCE);
98
99 struct _GESVideoSourcePrivate
100 {
101   GstFramePositioner *positioner;
102   GstElement *capsfilter;
103 };
104
105 /* TrackElement VMethods */
106
107 static gboolean
108 _set_priority (GESTimelineElement * element, guint32 priority)
109 {
110   gboolean res;
111   GESVideoSource *self = GES_VIDEO_SOURCE (element);
112
113   res = GES_TIMELINE_ELEMENT_CLASS (parent_class)->set_priority (element,
114       priority);
115
116   if (res && self->priv->positioner)
117     g_object_set (self->priv->positioner, "zorder", G_MAXUINT - priority, NULL);
118
119   return res;
120 }
121
122 static void
123 post_missing_element_message (GstElement * element, const gchar * name)
124 {
125   GstMessage *msg;
126
127   msg = gst_missing_element_message_new (element, name);
128   gst_element_post_message (element, msg);
129 }
130
131 static GstElement *
132 ges_video_source_create_element (GESTrackElement * trksrc)
133 {
134   GstElement *topbin;
135   GstElement *sub_element;
136   GstElement *queue = gst_element_factory_make ("queue", NULL);
137   GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
138   GESVideoSource *self;
139   GstElement *positioner, *videoscale, *videorate, *capsfilter, *videoconvert,
140       *deinterlace;
141   const gchar *positioner_props[] =
142       { "alpha", "posx", "posy", "width", "height", NULL };
143   const gchar *deinterlace_props[] = { "mode", "fields", "tff", NULL };
144
145   if (!source_class->create_source)
146     return NULL;
147
148   sub_element = source_class->create_source (trksrc);
149
150   self = (GESVideoSource *) trksrc;
151
152   /* That positioner will add metadata to buffers according to its
153      properties, acting like a proxy for our smart-mixer dynamic pads. */
154   positioner = gst_element_factory_make ("framepositioner", "frame_tagger");
155   g_object_set (positioner, "zorder",
156       G_MAXUINT - GES_TIMELINE_ELEMENT_PRIORITY (self), NULL);
157
158   videoscale =
159       gst_element_factory_make ("videoscale", "track-element-videoscale");
160   videoconvert =
161       gst_element_factory_make ("videoconvert", "track-element-videoconvert");
162   videorate = gst_element_factory_make ("videorate", "track-element-videorate");
163   deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
164   capsfilter =
165       gst_element_factory_make ("capsfilter", "track-element-capsfilter");
166
167   ges_frame_positioner_set_source_and_filter (GST_FRAME_POSITIONNER
168       (positioner), trksrc, capsfilter);
169
170   ges_track_element_add_children_props (trksrc, positioner, NULL, NULL,
171       positioner_props);
172
173   if (deinterlace == NULL) {
174     post_missing_element_message (sub_element, "deinterlace");
175
176     GST_ELEMENT_WARNING (sub_element, CORE, MISSING_PLUGIN,
177         ("Missing element '%s' - check your GStreamer installation.",
178             "deinterlace"), ("deinterlacing won't work"));
179     topbin =
180         ges_source_create_topbin ("videosrcbin", sub_element, queue,
181         videoconvert, positioner, videoscale, videorate, capsfilter, NULL);
182   } else {
183     ges_track_element_add_children_props (trksrc, deinterlace, NULL, NULL,
184         deinterlace_props);
185     topbin =
186         ges_source_create_topbin ("videosrcbin", sub_element, queue,
187         videoconvert, deinterlace, positioner, videoscale, videorate,
188         capsfilter, NULL);
189   }
190
191   self->priv->positioner = GST_FRAME_POSITIONNER (positioner);
192   self->priv->positioner->scale_in_compositor =
193       !GES_VIDEO_SOURCE_GET_CLASS (self)->ABI.abi.disable_scale_in_compositor;
194   self->priv->capsfilter = capsfilter;
195
196   return topbin;
197 }
198
199 static gboolean
200 _lookup_child (GESTimelineElement * object,
201     const gchar * prop_name, GObject ** element, GParamSpec ** pspec)
202 {
203   gboolean res;
204
205   gchar *clean_name;
206
207   if (!g_strcmp0 (prop_name, "deinterlace-fields"))
208     clean_name = g_strdup ("GstDeinterlace::fields");
209   else if (!g_strcmp0 (prop_name, "deinterlace-mode"))
210     clean_name = g_strdup ("GstDeinterlace::mode");
211   else if (!g_strcmp0 (prop_name, "deinterlace-tff"))
212     clean_name = g_strdup ("GstDeinterlace::tff");
213   else if (!g_strcmp0 (prop_name, "tff") ||
214       !g_strcmp0 (prop_name, "fields") || !g_strcmp0 (prop_name, "mode")) {
215     GST_DEBUG_OBJECT (object, "Not allowed to use GstDeinterlace %s"
216         " property without prefixing its name", prop_name);
217     return FALSE;
218   } else
219     clean_name = g_strdup (prop_name);
220
221   res =
222       GES_TIMELINE_ELEMENT_CLASS (ges_video_source_parent_class)->lookup_child
223       (object, clean_name, element, pspec);
224
225   g_free (clean_name);
226
227   return res;
228 }
229
230 static void
231 ges_video_source_class_init (GESVideoSourceClass * klass)
232 {
233   GESTrackElementClass *track_element_class = GES_TRACK_ELEMENT_CLASS (klass);
234   GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
235   GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
236
237   g_type_class_add_private (klass, sizeof (GESVideoSourcePrivate));
238
239   element_class->set_priority = _set_priority;
240   element_class->lookup_child = _lookup_child;
241
242   track_element_class->nleobject_factorytype = "nlesource";
243   track_element_class->create_element = ges_video_source_create_element;
244   video_source_class->create_source = NULL;
245 }
246
247 static void
248 ges_video_source_init (GESVideoSource * self)
249 {
250   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
251       GES_TYPE_VIDEO_SOURCE, GESVideoSourcePrivate);
252   self->priv->positioner = NULL;
253   self->priv->capsfilter = NULL;
254 }