2009-09-21 10:51:16 +00:00
|
|
|
/* GStreamer Editing Services
|
2009-11-30 14:14:25 +00:00
|
|
|
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
* 2009 Nokia Corporation
|
2009-09-21 10:51:16 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:25:20 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-09-21 10:51:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-07 19:02:48 +00:00
|
|
|
* SECTION:gesvideourisource
|
2017-03-08 21:13:48 +00:00
|
|
|
* @title: GESVideoUriSource
|
2013-07-09 13:31:15 +00:00
|
|
|
* @short_description: outputs a single video stream from a given file
|
2009-09-21 10:51:16 +00:00
|
|
|
*/
|
2018-09-24 14:41:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-09-21 10:51:16 +00:00
|
|
|
|
2020-02-19 21:06:26 +00:00
|
|
|
#include <stdio.h>
|
2013-11-18 16:41:07 +00:00
|
|
|
|
2020-02-19 21:06:26 +00:00
|
|
|
#include <gst/pbutils/missing-plugins.h>
|
2013-05-16 06:10:35 +00:00
|
|
|
#include "ges-utils.h"
|
2009-09-21 10:51:16 +00:00
|
|
|
#include "ges-internal.h"
|
2013-01-26 15:31:33 +00:00
|
|
|
#include "ges-track-element.h"
|
2020-07-03 20:34:21 +00:00
|
|
|
#include "ges-uri-source.h"
|
2013-07-09 13:31:15 +00:00
|
|
|
#include "ges-video-uri-source.h"
|
2013-01-20 15:44:57 +00:00
|
|
|
#include "ges-uri-asset.h"
|
2012-12-21 17:28:16 +00:00
|
|
|
#include "ges-extractable.h"
|
2009-09-21 10:51:16 +00:00
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
struct _GESVideoUriSourcePrivate
|
2013-05-16 06:10:35 +00:00
|
|
|
{
|
2020-07-03 20:34:21 +00:00
|
|
|
GESUriSource parent;
|
2013-05-16 06:10:35 +00:00
|
|
|
};
|
|
|
|
|
2013-05-16 07:40:22 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_URI
|
|
|
|
};
|
|
|
|
|
2013-06-27 12:20:00 +00:00
|
|
|
/* GESSource VMethod */
|
2013-05-16 07:40:22 +00:00
|
|
|
static GstElement *
|
2021-02-25 02:37:28 +00:00
|
|
|
ges_video_uri_source_create_source (GESSource * element)
|
2013-05-16 07:40:22 +00:00
|
|
|
{
|
2020-07-03 20:34:21 +00:00
|
|
|
return ges_uri_source_create_source (GES_VIDEO_URI_SOURCE (element)->priv);
|
2013-05-16 07:40:22 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 21:05:38 +00:00
|
|
|
static gboolean
|
|
|
|
ges_video_uri_source_needs_converters (GESVideoSource * source)
|
|
|
|
{
|
|
|
|
GESTrack *track = ges_track_element_get_track (GES_TRACK_ELEMENT (source));
|
|
|
|
|
|
|
|
if (!track || ges_track_get_mixing (track)) {
|
|
|
|
GESAsset *asset = ges_asset_request (GES_TYPE_URI_CLIP,
|
|
|
|
GES_VIDEO_URI_SOURCE (source)->uri, NULL);
|
|
|
|
gboolean is_nested = FALSE;
|
|
|
|
|
|
|
|
g_assert (asset);
|
|
|
|
|
|
|
|
g_object_get (asset, "is-nested-timeline", &is_nested, NULL);
|
|
|
|
gst_object_unref (asset);
|
|
|
|
|
|
|
|
return !is_nested;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-02-18 18:21:38 +00:00
|
|
|
static GstDiscovererVideoInfo *
|
|
|
|
_get_video_stream_info (GESVideoUriSource * self)
|
2020-02-19 21:06:26 +00:00
|
|
|
{
|
|
|
|
GstDiscovererStreamInfo *info;
|
2020-02-18 18:21:38 +00:00
|
|
|
GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
|
2020-02-19 21:06:26 +00:00
|
|
|
|
2020-02-19 21:09:19 +00:00
|
|
|
if (!asset) {
|
2020-02-18 18:21:38 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "No asset set yet");
|
|
|
|
return NULL;
|
2020-02-19 21:09:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 21:06:26 +00:00
|
|
|
info = ges_uri_source_asset_get_stream_info (GES_URI_SOURCE_ASSET (asset));
|
|
|
|
|
|
|
|
if (!GST_IS_DISCOVERER_VIDEO_INFO (info)) {
|
2020-02-18 18:21:38 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Doesn't have a video info (%" GST_PTR_FORMAT
|
2020-02-19 21:06:26 +00:00
|
|
|
")", info);
|
2020-02-18 18:21:38 +00:00
|
|
|
return NULL;
|
2020-02-19 21:06:26 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 18:21:38 +00:00
|
|
|
return GST_DISCOVERER_VIDEO_INFO (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ges_video_uri_source_get_natural_size (GESVideoSource * source, gint * width,
|
|
|
|
gint * height)
|
|
|
|
{
|
|
|
|
const GstTagList *tags = NULL;
|
|
|
|
gchar *rotation_info = NULL;
|
|
|
|
gint videoflip_method, rotate_angle;
|
|
|
|
GstDiscovererVideoInfo *info =
|
|
|
|
_get_video_stream_info (GES_VIDEO_URI_SOURCE (source));
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return FALSE;
|
2020-02-19 21:06:26 +00:00
|
|
|
|
2020-02-18 18:21:38 +00:00
|
|
|
*width = gst_discoverer_video_info_get_width (info);
|
|
|
|
*height = gst_discoverer_video_info_get_height (info);
|
2020-02-19 21:06:26 +00:00
|
|
|
if (!ges_timeline_element_lookup_child (GES_TIMELINE_ELEMENT (source),
|
|
|
|
"GstVideoFlip::video-direction", NULL, NULL))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ges_timeline_element_get_child_properties (GES_TIMELINE_ELEMENT (source),
|
|
|
|
"GstVideoFlip::video-direction", &videoflip_method, NULL);
|
|
|
|
|
|
|
|
/* Rotating 90 degrees, either way, rotate */
|
|
|
|
if (videoflip_method == 1 || videoflip_method == 3)
|
|
|
|
goto rotate;
|
|
|
|
|
|
|
|
if (videoflip_method != 8)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Rotation is automatic, we need to check if the media file is naturally
|
|
|
|
rotated */
|
|
|
|
tags =
|
|
|
|
gst_discoverer_stream_info_get_tags (GST_DISCOVERER_STREAM_INFO (info));
|
|
|
|
if (!tags)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!gst_tag_list_get_string (tags, GST_TAG_IMAGE_ORIENTATION,
|
|
|
|
&rotation_info))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (sscanf (rotation_info, "rotate-%d", &rotate_angle) == 1) {
|
|
|
|
if (rotate_angle == 90 || rotate_angle == 270)
|
|
|
|
goto rotate;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
g_free (rotation_info);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
rotate:
|
2020-02-19 21:09:19 +00:00
|
|
|
GST_INFO_OBJECT (source, "Stream is rotated, taking that into account");
|
2020-02-19 21:06:26 +00:00
|
|
|
*width =
|
|
|
|
gst_discoverer_video_info_get_height (GST_DISCOVERER_VIDEO_INFO (info));
|
|
|
|
*height =
|
|
|
|
gst_discoverer_video_info_get_width (GST_DISCOVERER_VIDEO_INFO (info));
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-05-16 07:40:22 +00:00
|
|
|
/* Extractable interface implementation */
|
|
|
|
|
2012-12-21 17:28:16 +00:00
|
|
|
static gchar *
|
|
|
|
ges_extractable_check_id (GType type, const gchar * id, GError ** error)
|
|
|
|
{
|
|
|
|
return g_strdup (id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_extractable_interface_init (GESExtractableInterface * iface)
|
|
|
|
{
|
2013-05-23 17:16:22 +00:00
|
|
|
iface->asset_type = GES_TYPE_URI_SOURCE_ASSET;
|
2012-12-21 17:28:16 +00:00
|
|
|
iface->check_id = ges_extractable_check_id;
|
|
|
|
}
|
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GESVideoUriSource, ges_video_uri_source,
|
2018-09-06 01:55:02 +00:00
|
|
|
GES_TYPE_VIDEO_SOURCE, G_ADD_PRIVATE (GESVideoUriSource)
|
2012-12-21 17:28:16 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
|
|
|
|
ges_extractable_interface_init));
|
2009-09-21 10:51:16 +00:00
|
|
|
|
2020-04-11 15:40:06 +00:00
|
|
|
static gboolean
|
|
|
|
_find_positioner (GstElement * a, GstElement * b)
|
|
|
|
{
|
|
|
|
return !g_strcmp0 (GST_OBJECT_NAME (gst_element_get_factory (a)),
|
|
|
|
"framepositioner");
|
|
|
|
}
|
|
|
|
|
2020-04-17 16:35:26 +00:00
|
|
|
static void
|
|
|
|
post_missing_element_message (GstElement * element, const gchar * name)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
msg = gst_missing_element_message_new (element, name);
|
|
|
|
gst_element_post_message (element, msg);
|
|
|
|
}
|
2013-05-16 07:40:22 +00:00
|
|
|
|
|
|
|
/* GObject VMethods */
|
2020-03-25 01:35:35 +00:00
|
|
|
static gboolean
|
|
|
|
ges_video_uri_source_create_filters (GESVideoSource * source,
|
|
|
|
GPtrArray * elements, gboolean needs_converters)
|
|
|
|
{
|
|
|
|
GESAsset *asset = ges_extractable_get_asset (GES_EXTRACTABLE (source));
|
2020-04-17 16:35:26 +00:00
|
|
|
GstDiscovererVideoInfo *info =
|
|
|
|
GST_DISCOVERER_VIDEO_INFO (ges_uri_source_asset_get_stream_info
|
|
|
|
(GES_URI_SOURCE_ASSET (asset)));
|
2020-03-25 01:35:35 +00:00
|
|
|
|
|
|
|
g_assert (GES_IS_URI_SOURCE_ASSET (asset));
|
|
|
|
if (!GES_VIDEO_SOURCE_CLASS (ges_video_uri_source_parent_class)
|
|
|
|
->ABI.abi.create_filters (source, elements, needs_converters))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-04-17 16:35:26 +00:00
|
|
|
if (gst_discoverer_video_info_is_interlaced (info)) {
|
|
|
|
const gchar *deinterlace_props[] = { "mode", "fields", "tff", NULL };
|
|
|
|
GstElement *deinterlace =
|
|
|
|
gst_element_factory_make ("deinterlace", "deinterlace");
|
|
|
|
|
|
|
|
if (deinterlace == NULL) {
|
|
|
|
post_missing_element_message (ges_track_element_get_nleobject
|
|
|
|
(GES_TRACK_ELEMENT (source)), "deinterlace");
|
|
|
|
|
|
|
|
GST_ELEMENT_WARNING (ges_track_element_get_nleobject (GES_TRACK_ELEMENT
|
|
|
|
(source)), CORE, MISSING_PLUGIN,
|
|
|
|
("Missing element '%s' - check your GStreamer installation.",
|
|
|
|
"deinterlace"), ("deinterlacing won't work"));
|
|
|
|
} else {
|
|
|
|
/* Right after the queue */
|
|
|
|
g_ptr_array_insert (elements, 1, gst_element_factory_make ("videoconvert",
|
|
|
|
NULL));
|
|
|
|
g_ptr_array_insert (elements, 2, deinterlace);
|
|
|
|
ges_track_element_add_children_props (GES_TRACK_ELEMENT (source),
|
|
|
|
deinterlace, NULL, NULL, deinterlace_props);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 15:40:06 +00:00
|
|
|
if (ges_uri_source_asset_is_image (GES_URI_SOURCE_ASSET (asset))) {
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_ptr_array_find_with_equal_func (elements, NULL,
|
|
|
|
(GEqualFunc) _find_positioner, &i);
|
|
|
|
/* Adding the imagefreeze right before the positionner so positioning can happen
|
|
|
|
* properly */
|
|
|
|
g_ptr_array_insert (elements, i,
|
|
|
|
gst_element_factory_make ("imagefreeze", NULL));
|
|
|
|
}
|
2020-03-25 01:35:35 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-09-21 10:51:16 +00:00
|
|
|
|
|
|
|
static void
|
2013-07-09 13:31:15 +00:00
|
|
|
ges_video_uri_source_get_property (GObject * object, guint property_id,
|
2009-09-21 10:51:16 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2020-03-25 01:35:35 +00:00
|
|
|
GESVideoUriSource *urisource = GES_VIDEO_URI_SOURCE (object);
|
2009-09-21 10:51:16 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_URI:
|
2020-03-25 01:35:35 +00:00
|
|
|
g_value_set_string (value, urisource->uri);
|
2009-09-21 10:51:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-09 13:31:15 +00:00
|
|
|
ges_video_uri_source_set_property (GObject * object, guint property_id,
|
2009-09-21 10:51:16 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2020-03-25 01:35:35 +00:00
|
|
|
GESVideoUriSource *urisource = GES_VIDEO_URI_SOURCE (object);
|
2009-09-21 10:51:16 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_URI:
|
2020-03-25 01:35:35 +00:00
|
|
|
if (urisource->uri) {
|
|
|
|
GST_WARNING_OBJECT (object, "Uri already set to %s", urisource->uri);
|
2013-06-23 22:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-03 20:34:21 +00:00
|
|
|
urisource->priv->uri = urisource->uri = g_value_dup_string (value);
|
2009-09-21 10:51:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-06-24 15:11:11 +00:00
|
|
|
ges_video_uri_source_finalize (GObject * object)
|
2009-09-21 10:51:16 +00:00
|
|
|
{
|
2020-03-25 01:35:35 +00:00
|
|
|
GESVideoUriSource *urisource = GES_VIDEO_URI_SOURCE (object);
|
2010-03-13 14:51:16 +00:00
|
|
|
|
2020-03-25 01:35:35 +00:00
|
|
|
g_free (urisource->uri);
|
2010-03-13 14:51:16 +00:00
|
|
|
|
2020-06-24 15:11:11 +00:00
|
|
|
G_OBJECT_CLASS (ges_video_uri_source_parent_class)->finalize (object);
|
2009-09-21 10:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-09 13:31:15 +00:00
|
|
|
ges_video_uri_source_class_init (GESVideoUriSourceClass * klass)
|
2009-09-21 10:51:16 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2020-12-14 01:54:37 +00:00
|
|
|
GESSourceClass *src_class = GES_SOURCE_CLASS (klass);
|
|
|
|
GESVideoSourceClass *video_src_class = GES_VIDEO_SOURCE_CLASS (klass);
|
2009-09-21 10:51:16 +00:00
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
object_class->get_property = ges_video_uri_source_get_property;
|
|
|
|
object_class->set_property = ges_video_uri_source_set_property;
|
2020-06-24 15:11:11 +00:00
|
|
|
object_class->finalize = ges_video_uri_source_finalize;
|
2009-09-21 10:51:16 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-09 13:31:15 +00:00
|
|
|
* GESVideoUriSource:uri:
|
2009-09-21 10:51:16 +00:00
|
|
|
*
|
|
|
|
* The location of the file/resource to use.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_URI,
|
|
|
|
g_param_spec_string ("uri", "URI", "uri of the resource",
|
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2013-05-16 01:27:20 +00:00
|
|
|
|
2020-12-14 01:54:37 +00:00
|
|
|
src_class->select_pad = ges_uri_source_select_pad;
|
|
|
|
|
2021-02-25 02:37:28 +00:00
|
|
|
src_class->create_source = ges_video_uri_source_create_source;
|
2020-12-14 01:54:37 +00:00
|
|
|
video_src_class->ABI.abi.needs_converters =
|
2020-02-10 21:05:38 +00:00
|
|
|
ges_video_uri_source_needs_converters;
|
2020-12-14 01:54:37 +00:00
|
|
|
video_src_class->ABI.abi.get_natural_size =
|
2020-02-19 21:06:26 +00:00
|
|
|
ges_video_uri_source_get_natural_size;
|
2020-12-14 01:54:37 +00:00
|
|
|
video_src_class->ABI.abi.create_filters = ges_video_uri_source_create_filters;
|
2009-09-21 10:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-07-09 13:31:15 +00:00
|
|
|
ges_video_uri_source_init (GESVideoUriSource * self)
|
2009-09-21 10:51:16 +00:00
|
|
|
{
|
2018-09-06 01:55:02 +00:00
|
|
|
self->priv = ges_video_uri_source_get_instance_private (self);
|
2020-07-03 20:34:21 +00:00
|
|
|
ges_uri_source_init (GES_TRACK_ELEMENT (self), self->priv);
|
2009-09-21 10:51:16 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 13:28:35 +00:00
|
|
|
/**
|
2013-07-09 13:31:15 +00:00
|
|
|
* ges_video_uri_source_new:
|
2011-01-10 13:28:35 +00:00
|
|
|
* @uri: the URI the source should control
|
|
|
|
*
|
2013-07-09 13:31:15 +00:00
|
|
|
* Creates a new #GESVideoUriSource for the provided @uri.
|
2011-01-10 13:28:35 +00:00
|
|
|
*
|
2016-05-14 23:04:17 +00:00
|
|
|
* Returns: (transfer floating) (nullable): The newly created #GESVideoUriSource,
|
|
|
|
* or %NULL if there was an error.
|
2011-01-10 13:28:35 +00:00
|
|
|
*/
|
2013-07-09 13:31:15 +00:00
|
|
|
GESVideoUriSource *
|
|
|
|
ges_video_uri_source_new (gchar * uri)
|
2009-09-21 10:51:16 +00:00
|
|
|
{
|
2013-07-09 13:31:15 +00:00
|
|
|
return g_object_new (GES_TYPE_VIDEO_URI_SOURCE, "uri", uri, NULL);
|
2009-09-21 10:51:16 +00:00
|
|
|
}
|