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-uri-source.h"
37 #include "ges-video-uri-source.h"
38 #include "ges-uri-asset.h"
39 #include "ges-extractable.h"
41 struct _GESVideoUriSourcePrivate
52 /* GESSource VMethod */
54 ges_video_uri_source_create_source (GESSource * element)
56 return ges_uri_source_create_source (GES_VIDEO_URI_SOURCE (element)->priv);
60 ges_video_uri_source_needs_converters (GESVideoSource * source)
62 GESTrack *track = ges_track_element_get_track (GES_TRACK_ELEMENT (source));
64 if (!track || ges_track_get_mixing (track)) {
65 GESAsset *asset = ges_asset_request (GES_TYPE_URI_CLIP,
66 GES_VIDEO_URI_SOURCE (source)->uri, NULL);
67 gboolean is_nested = FALSE;
71 g_object_get (asset, "is-nested-timeline", &is_nested, NULL);
72 gst_object_unref (asset);
81 static GstDiscovererVideoInfo *
82 _get_video_stream_info (GESVideoUriSource * self)
84 GstDiscovererStreamInfo *info;
85 GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
88 GST_DEBUG_OBJECT (self, "No asset set yet");
92 info = ges_uri_source_asset_get_stream_info (GES_URI_SOURCE_ASSET (asset));
94 if (!GST_IS_DISCOVERER_VIDEO_INFO (info)) {
95 GST_ERROR_OBJECT (self, "Doesn't have a video info (%" GST_PTR_FORMAT
100 return GST_DISCOVERER_VIDEO_INFO (info);
105 ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
108 const GstTagList *tags = NULL;
109 gchar *rotation_info = NULL;
110 gint videoflip_method, rotate_angle;
111 GstDiscovererVideoInfo *info =
112 _get_video_stream_info (GES_VIDEO_URI_SOURCE (source));
117 *width = gst_discoverer_video_info_get_width (info);
118 *height = gst_discoverer_video_info_get_height (info);
119 if (!ges_timeline_element_lookup_child (GES_TIMELINE_ELEMENT (source),
120 "GstVideoFlip::video-direction", NULL, NULL))
123 ges_timeline_element_get_child_properties (GES_TIMELINE_ELEMENT (source),
124 "GstVideoFlip::video-direction", &videoflip_method, NULL);
126 /* Rotating 90 degrees, either way, rotate */
127 if (videoflip_method == 1 || videoflip_method == 3)
130 if (videoflip_method != 8)
133 /* Rotation is automatic, we need to check if the media file is naturally
136 gst_discoverer_stream_info_get_tags (GST_DISCOVERER_STREAM_INFO (info));
140 if (!gst_tag_list_get_string (tags, GST_TAG_IMAGE_ORIENTATION,
144 if (sscanf (rotation_info, "rotate-%d", &rotate_angle) == 1) {
145 if (rotate_angle == 90 || rotate_angle == 270)
150 g_free (rotation_info);
154 GST_INFO_OBJECT (source, "Stream is rotated, taking that into account");
156 gst_discoverer_video_info_get_height (GST_DISCOVERER_VIDEO_INFO (info));
158 gst_discoverer_video_info_get_width (GST_DISCOVERER_VIDEO_INFO (info));
163 /* Extractable interface implementation */
166 ges_extractable_check_id (GType type, const gchar * id, GError ** error)
168 return g_strdup (id);
172 ges_extractable_interface_init (GESExtractableInterface * iface)
174 iface->asset_type = GES_TYPE_URI_SOURCE_ASSET;
175 iface->check_id = ges_extractable_check_id;
178 G_DEFINE_TYPE_WITH_CODE (GESVideoUriSource, ges_video_uri_source,
179 GES_TYPE_VIDEO_SOURCE, G_ADD_PRIVATE (GESVideoUriSource)
180 G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
181 ges_extractable_interface_init));
184 _find_positioner (GstElement * a, GstElement * b)
186 return !g_strcmp0 (GST_OBJECT_NAME (gst_element_get_factory (a)),
191 post_missing_element_message (GstElement * element, const gchar * name)
195 msg = gst_missing_element_message_new (element, name);
196 gst_element_post_message (element, msg);
199 /* GObject VMethods */
201 ges_video_uri_source_create_filters (GESVideoSource * source,
202 GPtrArray * elements, gboolean needs_converters)
204 GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (source));
205 GstDiscovererVideoInfo *info =
206 GST_DISCOVERER_VIDEO_INFO (ges_uri_source_asset_get_stream_info
207 (GES_URI_SOURCE_ASSET (asset)));
209 g_assert (GES_IS_URI_SOURCE_ASSET (asset));
210 if (!GES_VIDEO_SOURCE_CLASS (ges_video_uri_source_parent_class)
211 ->ABI.abi.create_filters (source, elements, needs_converters))
214 if (gst_discoverer_video_info_is_interlaced (info)) {
215 const gchar *deinterlace_props[] = { "mode", "fields", "tff", NULL };
216 GstElement *deinterlace =
217 gst_element_factory_make ("deinterlace", "deinterlace");
219 if (deinterlace == NULL) {
220 post_missing_element_message (ges_track_element_get_nleobject
221 (GES_TRACK_ELEMENT (source)), "deinterlace");
223 GST_ELEMENT_WARNING (ges_track_element_get_nleobject (GES_TRACK_ELEMENT
224 (source)), CORE, MISSING_PLUGIN,
225 ("Missing element '%s' - check your GStreamer installation.",
226 "deinterlace"), ("deinterlacing won't work"));
228 /* Right after the queue */
229 g_ptr_array_insert (elements, 1, gst_element_factory_make ("videoconvert",
231 g_ptr_array_insert (elements, 2, deinterlace);
232 ges_track_element_add_children_props (GES_TRACK_ELEMENT (source),
233 deinterlace, NULL, NULL, deinterlace_props);
238 if (ges_uri_source_asset_is_image (GES_URI_SOURCE_ASSET (asset))) {
241 g_ptr_array_find_with_equal_func (elements, NULL,
242 (GEqualFunc) _find_positioner, &i);
243 /* Adding the imagefreeze right before the positionner so positioning can happen
245 g_ptr_array_insert (elements, i,
246 gst_element_factory_make ("imagefreeze", NULL));
253 ges_video_uri_source_get_property (GObject * object, guint property_id,
254 GValue * value, GParamSpec * pspec)
256 GESVideoUriSource *urisource = GES_VIDEO_URI_SOURCE (object);
258 switch (property_id) {
260 g_value_set_string (value, urisource->uri);
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
268 ges_video_uri_source_set_property (GObject * object, guint property_id,
269 const GValue * value, GParamSpec * pspec)
271 GESVideoUriSource *urisource = GES_VIDEO_URI_SOURCE (object);
273 switch (property_id) {
275 if (urisource->uri) {
276 GST_WARNING_OBJECT (object, "Uri already set to %s", urisource->uri);
279 urisource->priv->uri = urisource->uri = g_value_dup_string (value);
282 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
287 ges_video_uri_source_finalize (GObject * object)
289 GESVideoUriSource *urisource = GES_VIDEO_URI_SOURCE (object);
291 g_free (urisource->uri);
293 G_OBJECT_CLASS (ges_video_uri_source_parent_class)->finalize (object);
297 ges_video_uri_source_class_init (GESVideoUriSourceClass * klass)
299 GObjectClass *object_class = G_OBJECT_CLASS (klass);
300 GESSourceClass *src_class = GES_SOURCE_CLASS (klass);
301 GESVideoSourceClass *video_src_class = GES_VIDEO_SOURCE_CLASS (klass);
303 object_class->get_property = ges_video_uri_source_get_property;
304 object_class->set_property = ges_video_uri_source_set_property;
305 object_class->finalize = ges_video_uri_source_finalize;
308 * GESVideoUriSource:uri:
310 * The location of the file/resource to use.
312 g_object_class_install_property (object_class, PROP_URI,
313 g_param_spec_string ("uri", "URI", "uri of the resource",
314 NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
316 src_class->select_pad = ges_uri_source_select_pad;
318 src_class->create_source = ges_video_uri_source_create_source;
319 video_src_class->ABI.abi.needs_converters =
320 ges_video_uri_source_needs_converters;
321 video_src_class->ABI.abi.get_natural_size =
322 ges_video_uri_source_get_natural_size;
323 video_src_class->ABI.abi.create_filters = ges_video_uri_source_create_filters;
327 ges_video_uri_source_init (GESVideoUriSource * self)
329 self->priv = ges_video_uri_source_get_instance_private (self);
330 ges_uri_source_init (GES_TRACK_ELEMENT (self), self->priv);
334 * ges_video_uri_source_new:
335 * @uri: the URI the source should control
337 * Creates a new #GESVideoUriSource for the provided @uri.
339 * Returns: (transfer floating) (nullable): The newly created #GESVideoUriSource,
340 * or %NULL if there was an error.
343 ges_video_uri_source_new (gchar * uri)
345 return g_object_new (GES_TYPE_VIDEO_URI_SOURCE, "uri", uri, NULL);