GES: Add GESVideoSource and GESAudioSource base classes
[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:ges-video-source
23  * @short_description: Base Class for video sources
24  */
25
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"
32
33 G_DEFINE_TYPE (GESVideoSource, ges_video_source, GES_TYPE_SOURCE);
34
35 struct _GESVideoSourcePrivate
36 {
37   GstFramePositionner *positionner;
38 };
39
40 static void
41 update_z_order_cb (GESClip * clip, GParamSpec * arg G_GNUC_UNUSED,
42     GESVideoSource * self)
43 {
44   GESLayer *layer = ges_clip_get_layer (clip);
45
46   if (layer == NULL)
47     return;
48
49   /* 10000 is the max value of zorder on videomixerpad, hardcoded */
50
51   g_object_set (self->priv->positionner, "zorder",
52       10000 - ges_layer_get_priority (layer), NULL);
53
54   gst_object_unref (layer);
55 }
56
57 static GstElement *
58 ges_video_source_create_element (GESTrackElement * trksrc)
59 {
60   GstElement *topbin;
61   GstElement *sub_element;
62   GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
63   GESVideoSource *self;
64   GstElement *positionner;
65   const gchar *props[] = { "alpha", "posx", "posy", NULL };
66   GESTimelineElement *parent;
67
68   if (!source_class->create_source)
69     return NULL;
70
71   sub_element = source_class->create_source (trksrc);
72
73   self = (GESVideoSource *) trksrc;
74
75   /* That positionner will add metadata to buffers according to its
76      properties, acting like a proxy for our smart-mixer dynamic pads. */
77   positionner = gst_element_factory_make ("framepositionner", "frame_tagger");
78
79   ges_track_element_add_children_props (trksrc, positionner, NULL, NULL, props);
80   topbin =
81       ges_source_create_topbin ("videosrcbin", sub_element, positionner, NULL);
82   parent = ges_timeline_element_get_parent (GES_TIMELINE_ELEMENT (trksrc));
83   if (parent) {
84     self->priv->positionner = GST_FRAME_POSITIONNER (positionner);
85     g_signal_connect (parent, "notify::layer",
86         (GCallback) update_z_order_cb, trksrc);
87     update_z_order_cb (GES_CLIP (parent), NULL, self);
88     gst_object_unref (parent);
89   } else {
90     GST_ERROR ("No parent timeline element, SHOULD NOT HAPPEN");
91   }
92
93   return topbin;
94 }
95
96 static void
97 ges_video_source_class_init (GESVideoSourceClass * klass)
98 {
99   GESTrackElementClass *track_class = GES_TRACK_ELEMENT_CLASS (klass);
100   GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
101
102   g_type_class_add_private (klass, sizeof (GESVideoSourcePrivate));
103
104   track_class->gnlobject_factorytype = "gnlsource";
105   track_class->create_element = ges_video_source_create_element;
106   video_source_class->create_source = NULL;
107 }
108
109 static void
110 ges_video_source_init (GESVideoSource * self)
111 {
112   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
113       GES_TYPE_VIDEO_SOURCE, GESVideoSourcePrivate);
114   self->priv->positionner = NULL;
115 }