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