video-source: Simply set framepositionner->zorder = self->priority
[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  * <row>
36  *  <entry role="property_type"><link linkend="gdouble"><type>double</type></link></entry>
37  *  <entry role="property_name"><link linkend="GESVideoSource--alpha">alpha</link></entry>
38  *  <entry>The desired alpha for the stream.</entry>
39  * </row>
40  * <row>
41  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
42  *  <entry role="property_name"><link linkend="GESVideoSource--posx">posx</link></entry>
43  *  <entry>The desired x position for the stream.</entry>
44  * </row>
45  * <row>
46  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
47  *  <entry role="property_name"><link linkend="GESVideoSource--posy">posy</link></entry>
48  *  <entry>The desired y position for the stream</entry>
49  * </row>
50  * <row>
51  *  <entry role="property_type"><link linkend="guint"><type>guint</type></link></entry>
52  *  <entry role="property_name"><link linkend="GESVideoSource--zorder">zorder</link></entry>
53  *  <entry>The desired z order for the stream</entry>
54  * </row>
55  * <row>
56  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
57  *  <entry role="property_name"><link linkend="GESVideoSource--width">width</link></entry>
58  *  <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>
59  * </row>
60  * <row>
61  *  <entry role="property_type"><link linkend="gint"><type>gint</type></link></entry>
62  *  <entry role="property_name"><link linkend="GESVideoSource--height">height</link></entry>
63  *  <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>
64  * </row>
65  * </tbody>
66  * </tgroup>
67  * </informaltable>
68  * </refsect1>
69  */
70
71 #include <gst/pbutils/missing-plugins.h>
72
73 #include "ges-internal.h"
74 #include "ges/ges-meta-container.h"
75 #include "ges-track-element.h"
76 #include "ges-video-source.h"
77 #include "ges-layer.h"
78 #include "gstframepositionner.h"
79
80 #define parent_class ges_video_source_parent_class
81 G_DEFINE_ABSTRACT_TYPE (GESVideoSource, ges_video_source, GES_TYPE_SOURCE);
82
83 struct _GESVideoSourcePrivate
84 {
85   GstFramePositionner *positionner;
86   GstElement *capsfilter;
87 };
88
89 /* TrackElement VMethods */
90
91 static gboolean
92 _set_priority (GESTimelineElement * element, guint32 priority)
93 {
94   gboolean res;
95   GESVideoSource *self = GES_VIDEO_SOURCE (element);
96
97   res = GES_TIMELINE_ELEMENT_CLASS (parent_class)->set_priority (element,
98       priority);
99
100   if (res && self->priv->positionner)
101     g_object_set (self->priv->positionner, "zorder",
102         GES_TIMELINE_ELEMENT_PRIORITY (self), NULL);
103
104   return res;
105 }
106
107 static void
108 post_missing_element_message (GstElement * element, const gchar * name)
109 {
110   GstMessage *msg;
111
112   msg = gst_missing_element_message_new (element, name);
113   gst_element_post_message (element, msg);
114 }
115
116 static GstElement *
117 ges_video_source_create_element (GESTrackElement * trksrc)
118 {
119   GstElement *topbin;
120   GstElement *sub_element;
121   GstElement *queue = gst_element_factory_make ("queue", NULL);
122   GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
123   GESVideoSource *self;
124   GstElement *positionner, *videoscale, *videorate, *capsfilter, *videoconvert,
125       *deinterlace;
126   const gchar *props[] = { "alpha", "posx", "posy", "width", "height", NULL };
127   GESTimelineElement *parent;
128
129   if (!source_class->create_source)
130     return NULL;
131
132   sub_element = source_class->create_source (trksrc);
133
134   self = (GESVideoSource *) trksrc;
135
136   /* That positionner will add metadata to buffers according to its
137      properties, acting like a proxy for our smart-mixer dynamic pads. */
138   positionner = gst_element_factory_make ("framepositionner", "frame_tagger");
139
140   videoscale =
141       gst_element_factory_make ("videoscale", "track-element-videoscale");
142   videoconvert =
143       gst_element_factory_make ("videoconvert", "track-element-videoconvert");
144   videorate = gst_element_factory_make ("videorate", "track-element-videorate");
145   deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
146   if (deinterlace == NULL) {
147     deinterlace = gst_element_factory_make ("avdeinterlace", "deinterlace");
148   }
149   capsfilter =
150       gst_element_factory_make ("capsfilter", "track-element-capsfilter");
151
152   ges_frame_positionner_set_source_and_filter (GST_FRAME_POSITIONNER
153       (positionner), trksrc, capsfilter);
154
155   ges_track_element_add_children_props (trksrc, positionner, NULL, NULL, props);
156
157   if (deinterlace == NULL) {
158     post_missing_element_message (sub_element, "deinterlace");
159
160     GST_ELEMENT_WARNING (sub_element, CORE, MISSING_PLUGIN,
161         ("Missing element '%s' - check your GStreamer installation.",
162             "deinterlace"), ("deinterlacing won't work"));
163     topbin =
164         ges_source_create_topbin ("videosrcbin", sub_element, queue,
165         videoconvert, positionner, videoscale, videorate, capsfilter, NULL);
166   } else {
167     topbin =
168         ges_source_create_topbin ("videosrcbin", sub_element, queue,
169         videoconvert, deinterlace, positionner, videoscale, videorate,
170         capsfilter, NULL);
171   }
172
173   parent = ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (trksrc));
174   if (parent) {
175     self->priv->positionner = GST_FRAME_POSITIONNER (positionner);
176     gst_object_unref (parent);
177   } else {
178     GST_ERROR ("No parent timeline element, SHOULD NOT HAPPEN");
179   }
180
181   self->priv->capsfilter = capsfilter;
182
183   return topbin;
184 }
185
186 static void
187 ges_video_source_class_init (GESVideoSourceClass * klass)
188 {
189   GESTrackElementClass *track_class = GES_TRACK_ELEMENT_CLASS (klass);
190   GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
191   GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
192
193   g_type_class_add_private (klass, sizeof (GESVideoSourcePrivate));
194
195   element_class->set_priority = _set_priority;
196
197   track_class->nleobject_factorytype = "nlesource";
198   track_class->create_element = ges_video_source_create_element;
199   video_source_class->create_source = NULL;
200 }
201
202 static void
203 ges_video_source_init (GESVideoSource * self)
204 {
205   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
206       GES_TYPE_VIDEO_SOURCE, GESVideoSourcePrivate);
207   self->priv->positionner = NULL;
208   self->priv->capsfilter = NULL;
209 }