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:gesimagesource
23 * @title: GESImageSource
24 * @short_description: outputs the video stream from a media file as a still
27 * Outputs the video stream from a given file as a still frame. The frame
28 * chosen will be determined by the in-point property on the track element. For
29 * image files, do not set the in-point property.
35 #include "ges-internal.h"
36 #include "ges-track-element.h"
37 #include "ges-image-source.h"
40 struct _GESImageSourcePrivate
52 G_DEFINE_TYPE_WITH_PRIVATE (GESImageSource, ges_image_source,
53 GES_TYPE_VIDEO_SOURCE);
55 ges_image_source_get_property (GObject * object, guint property_id,
56 GValue * value, GParamSpec * pspec)
58 GESImageSource *uriclip = GES_IMAGE_SOURCE (object);
60 switch (property_id) {
62 g_value_set_string (value, uriclip->uri);
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
70 ges_image_source_set_property (GObject * object, guint property_id,
71 const GValue * value, GParamSpec * pspec)
73 GESImageSource *uriclip = GES_IMAGE_SOURCE (object);
75 switch (property_id) {
77 uriclip->uri = g_value_dup_string (value);
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
85 ges_image_source_dispose (GObject * object)
87 GESImageSource *uriclip = GES_IMAGE_SOURCE (object);
90 g_free (uriclip->uri);
92 G_OBJECT_CLASS (ges_image_source_parent_class)->dispose (object);
96 pad_added_cb (GstElement * timeline, GstPad * pad, GstElement * scale)
101 sinkpad = gst_element_get_static_pad (scale, "sink");
103 GST_DEBUG ("got sink pad, trying to link");
105 ret = gst_pad_link (pad, sinkpad);
106 gst_object_unref (sinkpad);
107 if (GST_PAD_LINK_SUCCESSFUL (ret)) {
108 GST_DEBUG ("linked ok, returning");
113 GST_DEBUG ("pad failed to link properly");
117 ges_image_source_create_source (GESTrackElement * track_element)
119 GstElement *bin, *source, *scale, *freeze, *iconv;
120 GstPad *src, *target;
122 bin = GST_ELEMENT (gst_bin_new ("still-image-bin"));
123 source = gst_element_factory_make ("uridecodebin", NULL);
124 scale = gst_element_factory_make ("videoscale", NULL);
125 freeze = gst_element_factory_make ("imagefreeze", NULL);
126 iconv = gst_element_factory_make ("videoconvert", NULL);
128 g_object_set (scale, "add-borders", TRUE, NULL);
130 gst_bin_add_many (GST_BIN (bin), source, scale, freeze, iconv, NULL);
132 gst_element_link_pads_full (scale, "src", iconv, "sink",
133 GST_PAD_LINK_CHECK_NOTHING);
134 gst_element_link_pads_full (iconv, "src", freeze, "sink",
135 GST_PAD_LINK_CHECK_NOTHING);
137 /* FIXME: add capsfilter here with sink caps (see 626518) */
139 target = gst_element_get_static_pad (freeze, "src");
141 src = gst_ghost_pad_new ("src", target);
142 gst_element_add_pad (bin, src);
143 gst_object_unref (target);
145 g_object_set (source, "uri", ((GESImageSource *) track_element)->uri, NULL);
147 g_signal_connect (G_OBJECT (source), "pad-added",
148 G_CALLBACK (pad_added_cb), scale);
154 ges_image_source_class_init (GESImageSourceClass * klass)
156 GObjectClass *object_class = G_OBJECT_CLASS (klass);
157 GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
159 object_class->get_property = ges_image_source_get_property;
160 object_class->set_property = ges_image_source_set_property;
161 object_class->dispose = ges_image_source_dispose;
164 * GESImageSource:uri:
166 * The location of the file/resource to use.
168 g_object_class_install_property (object_class, PROP_URI,
169 g_param_spec_string ("uri", "URI", "uri of the resource",
170 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
172 GES_TIMELINE_ELEMENT_CLASS (klass)->set_inpoint = NULL;
173 source_class->create_source = ges_image_source_create_source;
177 ges_image_source_init (GESImageSource * self)
179 self->priv = ges_image_source_get_instance_private (self);
183 * ges_image_source_new:
184 * @uri: the URI the source should control
186 * Creates a new #GESImageSource for the provided @uri.
188 * Returns: (transfer floating): A new #GESImageSource.
191 ges_image_source_new (gchar * uri)
193 return g_object_new (GES_TYPE_IMAGE_SOURCE, "uri", uri, "track-type",
194 GES_TRACK_TYPE_VIDEO, NULL);