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:ges-video-source
23 * @short_description: Base Class for video sources
26 #include "ges-internal.h"
27 #include "ges/ges-meta-container.h"
28 #include "ges-track-element.h"
29 #include "ges-video-source.h"
30 #include "ges-layer.h"
31 #include "gstframepositionner.h"
33 G_DEFINE_TYPE (GESVideoSource, ges_video_source, GES_TYPE_SOURCE);
35 struct _GESVideoSourcePrivate
37 GstFramePositionner *positionner;
38 GstElement *capsfilter;
42 /* TrackElement VMethods */
44 layer_priority_changed_cb (GESLayer * layer, GParamSpec * arg G_GNUC_UNUSED,
45 GESVideoSource * self)
47 g_object_set (self->priv->positionner, "zorder",
48 10000 - ges_layer_get_priority (layer), NULL);
52 layer_changed_cb (GESClip * clip, GParamSpec * arg G_GNUC_UNUSED,
53 GESVideoSource * self)
55 GESVideoSourcePrivate *priv = self->priv;
58 g_signal_handlers_disconnect_by_func (priv->layer,
59 layer_priority_changed_cb, self);
62 priv->layer = ges_clip_get_layer (clip);
63 if (priv->layer == NULL)
66 /* We do not need any ref ourself as our parent owns one and we are connected
68 g_object_unref (priv->layer);
69 /* 10000 is the max value of zorder on videomixerpad, hardcoded */
70 g_signal_connect (self->priv->layer, "notify::priority",
71 G_CALLBACK (layer_priority_changed_cb), self);
73 g_object_set (self->priv->positionner, "zorder",
74 10000 - ges_layer_get_priority (self->priv->layer), NULL);
78 ges_video_source_create_element (GESTrackElement * trksrc)
81 GstElement *sub_element;
82 GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
84 GstElement *positionner, *videoscale, *capsfilter;
85 const gchar *props[] = { "alpha", "posx", "posy", "width", "height", NULL };
86 GESTimelineElement *parent;
88 if (!source_class->create_source)
91 sub_element = source_class->create_source (trksrc);
93 self = (GESVideoSource *) trksrc;
95 /* That positionner will add metadata to buffers according to its
96 properties, acting like a proxy for our smart-mixer dynamic pads. */
97 positionner = gst_element_factory_make ("framepositionner", "frame_tagger");
100 gst_element_factory_make ("videoscale", "track-element-videoscale");
102 gst_element_factory_make ("capsfilter", "track-element-capsfilter");
104 ges_frame_positionner_set_source_and_filter (GST_FRAME_POSITIONNER
105 (positionner), trksrc, capsfilter);
107 ges_track_element_add_children_props (trksrc, positionner, NULL, NULL, props);
109 ges_source_create_topbin ("videosrcbin", sub_element, positionner,
110 videoscale, capsfilter, NULL);
111 parent = ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (trksrc));
113 self->priv->positionner = GST_FRAME_POSITIONNER (positionner);
114 g_signal_connect (parent, "notify::layer",
115 (GCallback) layer_changed_cb, trksrc);
116 layer_changed_cb (GES_CLIP (parent), NULL, self);
117 gst_object_unref (parent);
119 GST_ERROR ("No parent timeline element, SHOULD NOT HAPPEN");
122 self->priv->capsfilter = capsfilter;
128 _set_parent (GESTimelineElement * self, GESTimelineElement * parent)
130 GESVideoSourcePrivate *priv = GES_VIDEO_SOURCE (self)->priv;
134 g_signal_handlers_disconnect_by_func (priv->layer,
135 layer_priority_changed_cb, self);
139 g_signal_handlers_disconnect_by_func (self->parent, layer_changed_cb, self);
142 if (parent && priv->positionner)
143 layer_changed_cb (GES_CLIP (parent), NULL, GES_VIDEO_SOURCE (self));
150 ges_video_source_class_init (GESVideoSourceClass * klass)
152 GESTrackElementClass *track_class = GES_TRACK_ELEMENT_CLASS (klass);
153 GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
154 GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
156 g_type_class_add_private (klass, sizeof (GESVideoSourcePrivate));
158 element_class->set_parent = _set_parent;
159 track_class->gnlobject_factorytype = "gnlsource";
160 track_class->create_element = ges_video_source_create_element;
161 video_source_class->create_source = NULL;
165 ges_video_source_init (GESVideoSource * self)
167 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
168 GES_TYPE_VIDEO_SOURCE, GESVideoSourcePrivate);
169 self->priv->positionner = NULL;
170 self->priv->capsfilter = NULL;