1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
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.
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.
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.
22 * SECTION:gesvideosource
23 * @short_description: Base Class for video sources
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">
31 * <colspec colname="properties_type" colwidth="150px"/>
32 * <colspec colname="properties_name" colwidth="200px"/>
33 * <colspec colname="properties_flags" colwidth="400px"/>
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>
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>
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>
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>
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>
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>
78 #include <gst/pbutils/missing-plugins.h>
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"
87 G_DEFINE_ABSTRACT_TYPE (GESVideoSource, ges_video_source, GES_TYPE_SOURCE);
89 struct _GESVideoSourcePrivate
91 GstFramePositionner *positionner;
92 GstElement *capsfilter;
96 /* TrackElement VMethods */
98 layer_priority_changed_cb (GESLayer * layer, GParamSpec * arg G_GNUC_UNUSED,
99 GESVideoSource * self)
101 g_object_set (self->priv->positionner, "zorder",
102 10000 - ges_layer_get_priority (layer), NULL);
106 layer_changed_cb (GESClip * clip, GParamSpec * arg G_GNUC_UNUSED,
107 GESVideoSource * self)
109 GESVideoSourcePrivate *priv = self->priv;
112 g_signal_handlers_disconnect_by_func (priv->layer,
113 layer_priority_changed_cb, self);
116 priv->layer = ges_clip_get_layer (clip);
117 if (priv->layer == NULL)
120 /* We do not need any ref ourself as our parent owns one and we are connected
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);
127 g_object_set (self->priv->positionner, "zorder",
128 10000 - ges_layer_get_priority (self->priv->layer), NULL);
132 post_missing_element_message (GstElement * element, const gchar * name)
136 msg = gst_missing_element_message_new (element, name);
137 gst_element_post_message (element, msg);
141 ges_video_source_create_element (GESTrackElement * trksrc)
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,
150 const gchar *props[] = { "alpha", "posx", "posy", "width", "height", NULL };
151 GESTimelineElement *parent;
153 if (!source_class->create_source)
156 sub_element = source_class->create_source (trksrc);
158 self = (GESVideoSource *) trksrc;
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");
165 gst_element_factory_make ("videoscale", "track-element-videoscale");
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");
174 gst_element_factory_make ("capsfilter", "track-element-capsfilter");
176 ges_frame_positionner_set_source_and_filter (GST_FRAME_POSITIONNER
177 (positionner), trksrc, capsfilter);
179 ges_track_element_add_children_props (trksrc, positionner, NULL, NULL, props);
181 if (deinterlace == NULL) {
182 post_missing_element_message (sub_element, "deinterlace");
184 GST_ELEMENT_WARNING (sub_element, CORE, MISSING_PLUGIN,
185 ("Missing element '%s' - check your GStreamer installation.",
186 "deinterlace"), ("deinterlacing won't work"));
188 ges_source_create_topbin ("videosrcbin", sub_element, queue,
189 videoconvert, positionner, videoscale, videorate, capsfilter, NULL);
192 ges_source_create_topbin ("videosrcbin", sub_element, queue,
193 videoconvert, deinterlace, positionner, videoscale, videorate,
197 parent = ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (trksrc));
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);
205 GST_ERROR ("No parent timeline element, SHOULD NOT HAPPEN");
208 self->priv->capsfilter = capsfilter;
214 _set_parent (GESTimelineElement * self, GESTimelineElement * parent)
216 GESVideoSourcePrivate *priv = GES_VIDEO_SOURCE (self)->priv;
220 g_signal_handlers_disconnect_by_func (priv->layer,
221 layer_priority_changed_cb, self);
225 g_signal_handlers_disconnect_by_func (self->parent, layer_changed_cb, self);
228 if (parent && priv->positionner)
229 layer_changed_cb (GES_CLIP (parent), NULL, GES_VIDEO_SOURCE (self));
236 ges_video_source_class_init (GESVideoSourceClass * klass)
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);
242 g_type_class_add_private (klass, sizeof (GESVideoSourcePrivate));
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;
251 ges_video_source_init (GESVideoSource * self)
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;