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
32 #include <gst/pbutils/missing-plugins.h>
33 #include "ges-utils.h"
34 #include "ges-internal.h"
35 #include "ges-track-element.h"
36 #include "ges-video-uri-source.h"
37 #include "ges-uri-asset.h"
38 #include "ges-extractable.h"
40 struct _GESVideoUriSourcePrivate
42 GstElement *decodebin; /* Reference owned by parent class */
52 ges_video_uri_source_track_set_cb (GESVideoUriSource * self,
53 GParamSpec * arg G_GNUC_UNUSED, gpointer nothing)
56 const GstCaps *caps = NULL;
58 if (!self->priv->decodebin)
61 track = ges_track_element_get_track (GES_TRACK_ELEMENT (self));
65 caps = ges_track_get_caps (track);
67 GST_INFO_OBJECT (self, "Setting caps to: %" GST_PTR_FORMAT, caps);
68 g_object_set (self->priv->decodebin, "caps", caps, NULL);
71 /* GESSource VMethod */
73 ges_video_uri_source_create_source (GESTrackElement * trksrc)
75 GESVideoUriSource *self;
77 GstElement *decodebin;
78 const GstCaps *caps = NULL;
80 self = (GESVideoUriSource *) trksrc;
82 track = ges_track_element_get_track (trksrc);
84 caps = ges_track_get_caps (track);
86 decodebin = self->priv->decodebin = gst_element_factory_make ("uridecodebin",
89 g_object_set (decodebin, "caps", caps,
90 "expose-all-streams", FALSE, "uri", self->uri, NULL);
96 ges_video_uri_source_needs_converters (GESVideoSource * source)
98 GESTrack *track = ges_track_element_get_track (GES_TRACK_ELEMENT (source));
100 if (!track || ges_track_get_mixing (track)) {
101 GESAsset *asset = ges_asset_request (GES_TYPE_URI_CLIP,
102 GES_VIDEO_URI_SOURCE (source)->uri, NULL);
103 gboolean is_nested = FALSE;
107 g_object_get (asset, "is-nested-timeline", &is_nested, NULL);
108 gst_object_unref (asset);
118 ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
121 const GstTagList *tags = NULL;
122 gchar *rotation_info = NULL;
123 gint videoflip_method, rotate_angle;
124 GstDiscovererStreamInfo *info;
125 GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (source));
127 g_assert (GES_IS_URI_SOURCE_ASSET (asset));
128 info = ges_uri_source_asset_get_stream_info (GES_URI_SOURCE_ASSET (asset));
130 if (!GST_IS_DISCOVERER_VIDEO_INFO (info)) {
131 GST_ERROR_OBJECT (source, "Doesn't have a video info (%" GST_PTR_FORMAT
137 gst_discoverer_video_info_get_width (GST_DISCOVERER_VIDEO_INFO (info));
139 gst_discoverer_video_info_get_height (GST_DISCOVERER_VIDEO_INFO (info));
141 if (!ges_timeline_element_lookup_child (GES_TIMELINE_ELEMENT (source),
142 "GstVideoFlip::video-direction", NULL, NULL))
145 ges_timeline_element_get_child_properties (GES_TIMELINE_ELEMENT (source),
146 "GstVideoFlip::video-direction", &videoflip_method, NULL);
148 /* Rotating 90 degrees, either way, rotate */
149 if (videoflip_method == 1 || videoflip_method == 3)
152 if (videoflip_method != 8)
155 /* Rotation is automatic, we need to check if the media file is naturally
158 gst_discoverer_stream_info_get_tags (GST_DISCOVERER_STREAM_INFO (info));
162 if (!gst_tag_list_get_string (tags, GST_TAG_IMAGE_ORIENTATION,
166 if (sscanf (rotation_info, "rotate-%d", &rotate_angle) == 1) {
167 if (rotate_angle == 90 || rotate_angle == 270)
172 g_free (rotation_info);
176 GST_INFO_OBJECT (self, "Stream is rotated, taking that into account");
178 gst_discoverer_video_info_get_height (GST_DISCOVERER_VIDEO_INFO (info));
180 gst_discoverer_video_info_get_width (GST_DISCOVERER_VIDEO_INFO (info));
185 /* Extractable interface implementation */
188 ges_extractable_check_id (GType type, const gchar * id, GError ** error)
190 return g_strdup (id);
194 extractable_set_asset (GESExtractable * extractable, GESAsset * asset)
196 /* FIXME That should go into #GESTrackElement, but
197 * some work is needed to make sure it works properly */
199 if (ges_track_element_get_track_type (GES_TRACK_ELEMENT (extractable)) ==
200 GES_TRACK_TYPE_UNKNOWN) {
201 ges_track_element_set_track_type (GES_TRACK_ELEMENT (extractable),
202 ges_track_element_asset_get_track_type (GES_TRACK_ELEMENT_ASSET
208 ges_extractable_interface_init (GESExtractableInterface * iface)
210 iface->asset_type = GES_TYPE_URI_SOURCE_ASSET;
211 iface->check_id = ges_extractable_check_id;
212 iface->set_asset = extractable_set_asset;
215 G_DEFINE_TYPE_WITH_CODE (GESVideoUriSource, ges_video_uri_source,
216 GES_TYPE_VIDEO_SOURCE, G_ADD_PRIVATE (GESVideoUriSource)
217 G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
218 ges_extractable_interface_init));
221 /* GObject VMethods */
224 ges_video_uri_source_get_property (GObject * object, guint property_id,
225 GValue * value, GParamSpec * pspec)
227 GESVideoUriSource *uriclip = GES_VIDEO_URI_SOURCE (object);
229 switch (property_id) {
231 g_value_set_string (value, uriclip->uri);
234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
239 ges_video_uri_source_set_property (GObject * object, guint property_id,
240 const GValue * value, GParamSpec * pspec)
242 GESVideoUriSource *uriclip = GES_VIDEO_URI_SOURCE (object);
244 switch (property_id) {
247 GST_WARNING_OBJECT (object, "Uri already set to %s", uriclip->uri);
250 uriclip->uri = g_value_dup_string (value);
253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
258 ges_video_uri_source_dispose (GObject * object)
260 GESVideoUriSource *uriclip = GES_VIDEO_URI_SOURCE (object);
263 g_free (uriclip->uri);
265 G_OBJECT_CLASS (ges_video_uri_source_parent_class)->dispose (object);
269 ges_video_uri_source_class_init (GESVideoUriSourceClass * klass)
271 GObjectClass *object_class = G_OBJECT_CLASS (klass);
272 GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
274 object_class->get_property = ges_video_uri_source_get_property;
275 object_class->set_property = ges_video_uri_source_set_property;
276 object_class->dispose = ges_video_uri_source_dispose;
279 * GESVideoUriSource:uri:
281 * The location of the file/resource to use.
283 g_object_class_install_property (object_class, PROP_URI,
284 g_param_spec_string ("uri", "URI", "uri of the resource",
285 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
287 source_class->create_source = ges_video_uri_source_create_source;
288 source_class->ABI.abi.needs_converters =
289 ges_video_uri_source_needs_converters;
290 source_class->ABI.abi.get_natural_size =
291 ges_video_uri_source_get_natural_size;
295 ges_video_uri_source_init (GESVideoUriSource * self)
297 self->priv = ges_video_uri_source_get_instance_private (self);
299 g_signal_connect (self, "notify::track",
300 G_CALLBACK (ges_video_uri_source_track_set_cb), NULL);
304 * ges_video_uri_source_new:
305 * @uri: the URI the source should control
307 * Creates a new #GESVideoUriSource for the provided @uri.
309 * Returns: (transfer floating) (nullable): The newly created #GESVideoUriSource,
310 * or %NULL if there was an error.
313 ges_video_uri_source_new (gchar * uri)
315 return g_object_new (GES_TYPE_VIDEO_URI_SOURCE, "uri", uri, NULL);