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 * @title: GESVideoSource
24 * @short_description: Base Class for video sources
26 * ## Children Properties:
28 * You can use the following children properties through the
29 * #ges_track_element_set_child_property and alike set of methods:
31 * - #gdouble `alpha`: The desired alpha for the stream.
32 * - #gint `posx`: The desired x position for the stream.
33 * - #gint `posy`: The desired y position for the stream
34 * - #gint `width`: The desired width for that source.
35 * Set to 0 if size is not mandatory, will be set to width of the current track.
36 * - #gint `height`: The desired height for that source.
37 * Set to 0 if size is not mandatory, will be set to height of the current track.
38 * - #GstDeinterlaceModes `deinterlace-mode`: Deinterlace Mode
39 * - #GstDeinterlaceFields `deinterlace-fields`: Fields to use for deinterlacing
40 * - #GstDeinterlaceFieldLayout `deinterlace-tff`: Deinterlace top field first
41 * - #GstVideoOrientationMethod `video-direction`: The desired video rotation and flipping.
47 #include <gst/pbutils/missing-plugins.h>
48 #include <gst/video/video.h>
50 #include "ges-internal.h"
51 #include "ges/ges-meta-container.h"
52 #include "ges-track-element.h"
53 #include "ges-video-source.h"
54 #include "ges-layer.h"
55 #include "gstframepositioner.h"
57 #define parent_class ges_video_source_parent_class
59 struct _GESVideoSourcePrivate
61 GstFramePositioner *positioner;
62 GstElement *capsfilter;
65 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GESVideoSource, ges_video_source,
68 /* TrackElement VMethods */
71 _set_priority (GESTimelineElement * element, guint32 priority)
74 GESVideoSource *self = GES_VIDEO_SOURCE (element);
76 res = GES_TIMELINE_ELEMENT_CLASS (parent_class)->set_priority (element,
79 if (res && self->priv->positioner)
80 g_object_set (self->priv->positioner, "zorder", G_MAXUINT - priority, NULL);
86 post_missing_element_message (GstElement * element, const gchar * name)
90 msg = gst_missing_element_message_new (element, name);
91 gst_element_post_message (element, msg);
95 ges_video_source_create_element (GESTrackElement * trksrc)
98 GstElement *sub_element;
99 GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
100 GESVideoSource *self;
101 GstElement *positioner, *videoflip, *capsfilter, *deinterlace;
102 const gchar *positioner_props[] =
103 { "alpha", "posx", "posy", "width", "height", NULL };
104 const gchar *deinterlace_props[] = { "mode", "fields", "tff", NULL };
105 const gchar *videoflip_props[] = { "video-direction", NULL };
106 gboolean needs_converters = TRUE;
109 if (!source_class->create_source)
112 sub_element = source_class->create_source (trksrc);
114 self = (GESVideoSource *) trksrc;
115 if (source_class->ABI.abi.needs_converters)
116 needs_converters = source_class->ABI.abi.needs_converters (self);
118 elements = g_ptr_array_new ();
119 g_ptr_array_add (elements, gst_element_factory_make ("queue", NULL));
121 /* That positioner will add metadata to buffers according to its
122 properties, acting like a proxy for our smart-mixer dynamic pads. */
123 positioner = gst_element_factory_make ("framepositioner", "frame_tagger");
124 g_object_set (positioner, "zorder",
125 G_MAXUINT - GES_TIMELINE_ELEMENT_PRIORITY (self), NULL);
126 g_ptr_array_add (elements, positioner);
128 /* If there's image-orientation tag, make sure the image is correctly oriented
129 * before we scale it. */
130 videoflip = gst_element_factory_make ("videoflip", "track-element-videoflip");
131 g_object_set (videoflip, "video-direction", GST_VIDEO_ORIENTATION_AUTO, NULL);
132 g_ptr_array_add (elements, videoflip);
134 if (needs_converters) {
135 g_ptr_array_add (elements, gst_element_factory_make ("videoscale",
136 "track-element-videoscale"));
137 g_ptr_array_add (elements, gst_element_factory_make ("videoconvert",
138 "track-element-videoconvert"));
140 g_ptr_array_add (elements, gst_element_factory_make ("videorate",
141 "track-element-videorate"));
143 gst_element_factory_make ("capsfilter", "track-element-capsfilter");
144 g_ptr_array_add (elements, capsfilter);
146 ges_frame_positioner_set_source_and_filter (GST_FRAME_POSITIONNER
147 (positioner), trksrc, capsfilter);
149 ges_track_element_add_children_props (trksrc, positioner, NULL, NULL,
151 ges_track_element_add_children_props (trksrc, videoflip, NULL, NULL,
154 deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
155 if (deinterlace == NULL) {
156 post_missing_element_message (sub_element, "deinterlace");
158 GST_ELEMENT_WARNING (sub_element, CORE, MISSING_PLUGIN,
159 ("Missing element '%s' - check your GStreamer installation.",
160 "deinterlace"), ("deinterlacing won't work"));
162 g_ptr_array_add (elements, deinterlace);
163 ges_track_element_add_children_props (trksrc, deinterlace, NULL, NULL,
166 topbin = ges_source_create_topbin ("videosrcbin", sub_element, elements);
167 g_ptr_array_free (elements, TRUE);
169 self->priv->positioner = GST_FRAME_POSITIONNER (positioner);
170 self->priv->positioner->scale_in_compositor =
171 !GES_VIDEO_SOURCE_GET_CLASS (self)->ABI.abi.disable_scale_in_compositor;
172 self->priv->capsfilter = capsfilter;
178 _lookup_child (GESTimelineElement * object,
179 const gchar * prop_name, GObject ** element, GParamSpec ** pspec)
185 if (!g_strcmp0 (prop_name, "deinterlace-fields"))
186 clean_name = g_strdup ("GstDeinterlace::fields");
187 else if (!g_strcmp0 (prop_name, "deinterlace-mode"))
188 clean_name = g_strdup ("GstDeinterlace::mode");
189 else if (!g_strcmp0 (prop_name, "deinterlace-tff"))
190 clean_name = g_strdup ("GstDeinterlace::tff");
191 else if (!g_strcmp0 (prop_name, "tff") ||
192 !g_strcmp0 (prop_name, "fields") || !g_strcmp0 (prop_name, "mode")) {
193 GST_DEBUG_OBJECT (object, "Not allowed to use GstDeinterlace %s"
194 " property without prefixing its name", prop_name);
197 clean_name = g_strdup (prop_name);
200 GES_TIMELINE_ELEMENT_CLASS (ges_video_source_parent_class)->lookup_child
201 (object, clean_name, element, pspec);
209 ges_video_source_class_init (GESVideoSourceClass * klass)
211 GESTrackElementClass *track_element_class = GES_TRACK_ELEMENT_CLASS (klass);
212 GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
213 GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
215 element_class->set_priority = _set_priority;
216 element_class->lookup_child = _lookup_child;
218 track_element_class->nleobject_factorytype = "nlesource";
219 track_element_class->create_element = ges_video_source_create_element;
220 video_source_class->create_source = NULL;
224 ges_video_source_init (GESVideoSource * self)
226 self->priv = ges_video_source_get_instance_private (self);
227 self->priv->positioner = NULL;
228 self->priv->capsfilter = NULL;