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 GstElement *queue = gst_element_factory_make ("queue", NULL);
100 GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
101 GESVideoSource *self;
102 GstElement *positioner, *videoflip, *videoscale, *videorate, *capsfilter,
103 *videoconvert, *deinterlace;
104 const gchar *positioner_props[] =
105 { "alpha", "posx", "posy", "width", "height", NULL };
106 const gchar *deinterlace_props[] = { "mode", "fields", "tff", NULL };
107 const gchar *videoflip_props[] = { "video-direction", NULL };
109 if (!source_class->create_source)
112 sub_element = source_class->create_source (trksrc);
114 self = (GESVideoSource *) trksrc;
116 /* That positioner will add metadata to buffers according to its
117 properties, acting like a proxy for our smart-mixer dynamic pads. */
118 positioner = gst_element_factory_make ("framepositioner", "frame_tagger");
119 g_object_set (positioner, "zorder",
120 G_MAXUINT - GES_TIMELINE_ELEMENT_PRIORITY (self), NULL);
122 /* If there's image-orientation tag, make sure the image is correctly oriented
123 * before we scale it. */
124 videoflip = gst_element_factory_make ("videoflip", "track-element-videoflip");
125 g_object_set (videoflip, "video-direction", GST_VIDEO_ORIENTATION_AUTO, NULL);
128 gst_element_factory_make ("videoscale", "track-element-videoscale");
130 gst_element_factory_make ("videoconvert", "track-element-videoconvert");
131 videorate = gst_element_factory_make ("videorate", "track-element-videorate");
132 deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
134 gst_element_factory_make ("capsfilter", "track-element-capsfilter");
136 ges_frame_positioner_set_source_and_filter (GST_FRAME_POSITIONNER
137 (positioner), trksrc, capsfilter);
139 ges_track_element_add_children_props (trksrc, positioner, NULL, NULL,
141 ges_track_element_add_children_props (trksrc, videoflip, NULL, NULL,
144 if (deinterlace == NULL) {
145 post_missing_element_message (sub_element, "deinterlace");
147 GST_ELEMENT_WARNING (sub_element, CORE, MISSING_PLUGIN,
148 ("Missing element '%s' - check your GStreamer installation.",
149 "deinterlace"), ("deinterlacing won't work"));
151 ges_source_create_topbin ("videosrcbin", sub_element, queue,
152 videoconvert, positioner, videoflip, videoscale, videorate, capsfilter,
155 ges_track_element_add_children_props (trksrc, deinterlace, NULL, NULL,
158 ges_source_create_topbin ("videosrcbin", sub_element, queue,
159 videoconvert, deinterlace, positioner, videoflip, videoscale, videorate,
163 self->priv->positioner = GST_FRAME_POSITIONNER (positioner);
164 self->priv->positioner->scale_in_compositor =
165 !GES_VIDEO_SOURCE_GET_CLASS (self)->ABI.abi.disable_scale_in_compositor;
166 self->priv->capsfilter = capsfilter;
172 _lookup_child (GESTimelineElement * object,
173 const gchar * prop_name, GObject ** element, GParamSpec ** pspec)
179 if (!g_strcmp0 (prop_name, "deinterlace-fields"))
180 clean_name = g_strdup ("GstDeinterlace::fields");
181 else if (!g_strcmp0 (prop_name, "deinterlace-mode"))
182 clean_name = g_strdup ("GstDeinterlace::mode");
183 else if (!g_strcmp0 (prop_name, "deinterlace-tff"))
184 clean_name = g_strdup ("GstDeinterlace::tff");
185 else if (!g_strcmp0 (prop_name, "tff") ||
186 !g_strcmp0 (prop_name, "fields") || !g_strcmp0 (prop_name, "mode")) {
187 GST_DEBUG_OBJECT (object, "Not allowed to use GstDeinterlace %s"
188 " property without prefixing its name", prop_name);
191 clean_name = g_strdup (prop_name);
194 GES_TIMELINE_ELEMENT_CLASS (ges_video_source_parent_class)->lookup_child
195 (object, clean_name, element, pspec);
203 ges_video_source_class_init (GESVideoSourceClass * klass)
205 GESTrackElementClass *track_element_class = GES_TRACK_ELEMENT_CLASS (klass);
206 GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
207 GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
209 element_class->set_priority = _set_priority;
210 element_class->lookup_child = _lookup_child;
212 track_element_class->nleobject_factorytype = "nlesource";
213 track_element_class->create_element = ges_video_source_create_element;
214 video_source_class->create_source = NULL;
218 ges_video_source_init (GESVideoSource * self)
220 self->priv = ges_video_source_get_instance_private (self);
221 self->priv->positioner = NULL;
222 self->priv->capsfilter = NULL;