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:gesvideourisource
23 * @title: GESVideoUriSource
24 * @short_description: outputs a single video stream from a given file
30 #include <gst/pbutils/missing-plugins.h>
32 #include "ges-utils.h"
33 #include "ges-internal.h"
34 #include "ges-track-element.h"
35 #include "ges-video-uri-source.h"
36 #include "ges-uri-asset.h"
37 #include "ges-extractable.h"
39 struct _GESVideoUriSourcePrivate
41 GstElement *decodebin; /* Reference owned by parent class */
51 ges_video_uri_source_track_set_cb (GESVideoUriSource * self,
52 GParamSpec * arg G_GNUC_UNUSED, gpointer nothing)
55 const GstCaps *caps = NULL;
57 if (!self->priv->decodebin)
60 track = ges_track_element_get_track (GES_TRACK_ELEMENT (self));
64 caps = ges_track_get_caps (track);
66 GST_INFO_OBJECT (self, "Setting caps to: %" GST_PTR_FORMAT, caps);
67 g_object_set (self->priv->decodebin, "caps", caps, NULL);
70 /* GESSource VMethod */
72 ges_video_uri_source_create_source (GESTrackElement * trksrc)
74 GESVideoUriSource *self;
76 GstElement *decodebin;
77 const GstCaps *caps = NULL;
79 self = (GESVideoUriSource *) trksrc;
81 track = ges_track_element_get_track (trksrc);
83 caps = ges_track_get_caps (track);
85 decodebin = self->priv->decodebin = gst_element_factory_make ("uridecodebin",
88 g_object_set (decodebin, "caps", caps,
89 "expose-all-streams", FALSE, "uri", self->uri, NULL);
95 ges_video_uri_source_needs_converters (GESVideoSource * source)
97 GESTrack *track = ges_track_element_get_track (GES_TRACK_ELEMENT (source));
99 if (!track || ges_track_get_mixing (track)) {
100 GESAsset *asset = ges_asset_request (GES_TYPE_URI_CLIP,
101 GES_VIDEO_URI_SOURCE (source)->uri, NULL);
102 gboolean is_nested = FALSE;
106 g_object_get (asset, "is-nested-timeline", &is_nested, NULL);
107 gst_object_unref (asset);
116 /* Extractable interface implementation */
119 ges_extractable_check_id (GType type, const gchar * id, GError ** error)
121 return g_strdup (id);
125 extractable_set_asset (GESExtractable * extractable, GESAsset * asset)
127 /* FIXME That should go into #GESTrackElement, but
128 * some work is needed to make sure it works properly */
130 if (ges_track_element_get_track_type (GES_TRACK_ELEMENT (extractable)) ==
131 GES_TRACK_TYPE_UNKNOWN) {
132 ges_track_element_set_track_type (GES_TRACK_ELEMENT (extractable),
133 ges_track_element_asset_get_track_type (GES_TRACK_ELEMENT_ASSET
139 ges_extractable_interface_init (GESExtractableInterface * iface)
141 iface->asset_type = GES_TYPE_URI_SOURCE_ASSET;
142 iface->check_id = ges_extractable_check_id;
143 iface->set_asset = extractable_set_asset;
146 G_DEFINE_TYPE_WITH_CODE (GESVideoUriSource, ges_video_uri_source,
147 GES_TYPE_VIDEO_SOURCE, G_ADD_PRIVATE (GESVideoUriSource)
148 G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
149 ges_extractable_interface_init));
152 /* GObject VMethods */
155 ges_video_uri_source_get_property (GObject * object, guint property_id,
156 GValue * value, GParamSpec * pspec)
158 GESVideoUriSource *uriclip = GES_VIDEO_URI_SOURCE (object);
160 switch (property_id) {
162 g_value_set_string (value, uriclip->uri);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
170 ges_video_uri_source_set_property (GObject * object, guint property_id,
171 const GValue * value, GParamSpec * pspec)
173 GESVideoUriSource *uriclip = GES_VIDEO_URI_SOURCE (object);
175 switch (property_id) {
178 GST_WARNING_OBJECT (object, "Uri already set to %s", uriclip->uri);
181 uriclip->uri = g_value_dup_string (value);
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
189 ges_video_uri_source_dispose (GObject * object)
191 GESVideoUriSource *uriclip = GES_VIDEO_URI_SOURCE (object);
194 g_free (uriclip->uri);
196 G_OBJECT_CLASS (ges_video_uri_source_parent_class)->dispose (object);
200 ges_video_uri_source_class_init (GESVideoUriSourceClass * klass)
202 GObjectClass *object_class = G_OBJECT_CLASS (klass);
203 GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
205 object_class->get_property = ges_video_uri_source_get_property;
206 object_class->set_property = ges_video_uri_source_set_property;
207 object_class->dispose = ges_video_uri_source_dispose;
210 * GESVideoUriSource:uri:
212 * The location of the file/resource to use.
214 g_object_class_install_property (object_class, PROP_URI,
215 g_param_spec_string ("uri", "URI", "uri of the resource",
216 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
218 source_class->create_source = ges_video_uri_source_create_source;
219 source_class->ABI.abi.needs_converters =
220 ges_video_uri_source_needs_converters;
224 ges_video_uri_source_init (GESVideoUriSource * self)
226 self->priv = ges_video_uri_source_get_instance_private (self);
228 g_signal_connect (self, "notify::track",
229 G_CALLBACK (ges_video_uri_source_track_set_cb), NULL);
233 * ges_video_uri_source_new:
234 * @uri: the URI the source should control
236 * Creates a new #GESVideoUriSource for the provided @uri.
238 * Returns: (transfer floating) (nullable): The newly created #GESVideoUriSource,
239 * or %NULL if there was an error.
242 ges_video_uri_source_new (gchar * uri)
244 return g_object_new (GES_TYPE_VIDEO_URI_SOURCE, "uri", uri, NULL);