2013-07-09 13:31:15 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
* 2009 Nokia Corporation
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-07 19:02:48 +00:00
|
|
|
* SECTION:gesvideosource
|
2017-03-08 21:13:48 +00:00
|
|
|
* @title: GESVideoSource
|
2013-07-09 13:31:15 +00:00
|
|
|
* @short_description: Base Class for video sources
|
|
|
|
*/
|
2018-09-24 14:41:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2014-01-15 18:12:08 +00:00
|
|
|
#include <gst/pbutils/missing-plugins.h>
|
2019-03-15 15:24:16 +00:00
|
|
|
#include <gst/video/video.h>
|
2014-01-15 18:12:08 +00:00
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
#include "ges-internal.h"
|
|
|
|
#include "ges/ges-meta-container.h"
|
|
|
|
#include "ges-track-element.h"
|
|
|
|
#include "ges-video-source.h"
|
|
|
|
#include "ges-layer.h"
|
2016-04-13 09:31:05 +00:00
|
|
|
#include "gstframepositioner.h"
|
2020-02-19 21:09:19 +00:00
|
|
|
#include "ges-extractable.h"
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2015-08-27 14:28:42 +00:00
|
|
|
#define parent_class ges_video_source_parent_class
|
2020-04-06 17:36:29 +00:00
|
|
|
static GESExtractableInterface *parent_extractable_iface = NULL;
|
2013-07-09 13:31:15 +00:00
|
|
|
|
|
|
|
struct _GESVideoSourcePrivate
|
|
|
|
{
|
2016-04-13 09:31:05 +00:00
|
|
|
GstFramePositioner *positioner;
|
2013-08-21 09:32:45 +00:00
|
|
|
GstElement *capsfilter;
|
2013-07-09 13:31:15 +00:00
|
|
|
};
|
|
|
|
|
2020-02-19 21:09:19 +00:00
|
|
|
static void
|
|
|
|
ges_video_source_set_asset (GESExtractable * extractable, GESAsset * asset)
|
|
|
|
{
|
|
|
|
GESVideoSource *self = GES_VIDEO_SOURCE (extractable);
|
|
|
|
|
2020-03-25 01:30:38 +00:00
|
|
|
parent_extractable_iface->set_asset (extractable, asset);
|
|
|
|
|
2020-02-19 21:09:19 +00:00
|
|
|
ges_video_source_get_natural_size (self,
|
|
|
|
&self->priv->positioner->natural_width,
|
|
|
|
&self->priv->positioner->natural_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_extractable_interface_init (GESExtractableInterface * iface)
|
|
|
|
{
|
|
|
|
iface->set_asset = ges_video_source_set_asset;
|
2020-04-22 17:39:21 +00:00
|
|
|
|
|
|
|
parent_extractable_iface = g_type_interface_peek_parent (iface);
|
2020-02-19 21:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GESVideoSource, ges_video_source,
|
|
|
|
GES_TYPE_SOURCE, G_ADD_PRIVATE (GESVideoSource)
|
|
|
|
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
|
|
|
|
ges_extractable_interface_init));
|
2018-09-06 01:55:02 +00:00
|
|
|
|
2013-09-01 16:19:32 +00:00
|
|
|
/* TrackElement VMethods */
|
|
|
|
|
2015-08-27 14:28:42 +00:00
|
|
|
static gboolean
|
|
|
|
_set_priority (GESTimelineElement * element, guint32 priority)
|
2013-09-01 16:19:32 +00:00
|
|
|
{
|
2015-08-27 14:28:42 +00:00
|
|
|
gboolean res;
|
|
|
|
GESVideoSource *self = GES_VIDEO_SOURCE (element);
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2015-08-27 14:28:42 +00:00
|
|
|
res = GES_TIMELINE_ELEMENT_CLASS (parent_class)->set_priority (element,
|
|
|
|
priority);
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
if (res && self->priv->positioner)
|
|
|
|
g_object_set (self->priv->positioner, "zorder", G_MAXUINT - priority, NULL);
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2015-08-27 14:28:42 +00:00
|
|
|
return res;
|
2013-07-09 13:31:15 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 01:35:35 +00:00
|
|
|
static gboolean
|
|
|
|
ges_video_source_create_filters (GESVideoSource * self, GPtrArray * elements,
|
|
|
|
gboolean needs_converters)
|
2013-07-09 13:31:15 +00:00
|
|
|
{
|
2020-03-25 01:35:35 +00:00
|
|
|
GESTrackElement *trksrc = GES_TRACK_ELEMENT (self);
|
2020-04-17 16:35:26 +00:00
|
|
|
GstElement *positioner, *videoflip, *capsfilter;
|
|
|
|
const gchar *positioner_props[]
|
|
|
|
= { "alpha", "posx", "posy", "width", "height", NULL };
|
2019-03-19 15:39:20 +00:00
|
|
|
const gchar *videoflip_props[] = { "video-direction", NULL };
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2020-02-10 21:05:38 +00:00
|
|
|
g_ptr_array_add (elements, gst_element_factory_make ("queue", NULL));
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
/* That positioner will add metadata to buffers according to its
|
2013-07-09 13:31:15 +00:00
|
|
|
properties, acting like a proxy for our smart-mixer dynamic pads. */
|
2016-04-13 09:31:05 +00:00
|
|
|
positioner = gst_element_factory_make ("framepositioner", "frame_tagger");
|
|
|
|
g_object_set (positioner, "zorder",
|
2015-09-02 15:58:33 +00:00
|
|
|
G_MAXUINT - GES_TIMELINE_ELEMENT_PRIORITY (self), NULL);
|
2020-02-10 21:05:38 +00:00
|
|
|
g_ptr_array_add (elements, positioner);
|
2013-07-09 13:31:15 +00:00
|
|
|
|
2020-04-17 16:35:26 +00:00
|
|
|
if (needs_converters)
|
|
|
|
g_ptr_array_add (elements, gst_element_factory_make ("videoconvert", NULL));
|
|
|
|
|
2019-03-15 15:24:16 +00:00
|
|
|
/* If there's image-orientation tag, make sure the image is correctly oriented
|
|
|
|
* before we scale it. */
|
|
|
|
videoflip = gst_element_factory_make ("videoflip", "track-element-videoflip");
|
|
|
|
g_object_set (videoflip, "video-direction", GST_VIDEO_ORIENTATION_AUTO, NULL);
|
2020-02-10 21:05:38 +00:00
|
|
|
g_ptr_array_add (elements, videoflip);
|
2019-03-15 15:24:16 +00:00
|
|
|
|
2020-02-10 21:05:38 +00:00
|
|
|
if (needs_converters) {
|
|
|
|
g_ptr_array_add (elements, gst_element_factory_make ("videoscale",
|
|
|
|
"track-element-videoscale"));
|
|
|
|
g_ptr_array_add (elements, gst_element_factory_make ("videoconvert",
|
|
|
|
"track-element-videoconvert"));
|
|
|
|
}
|
|
|
|
g_ptr_array_add (elements, gst_element_factory_make ("videorate",
|
|
|
|
"track-element-videorate"));
|
2020-04-17 16:35:26 +00:00
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
capsfilter =
|
|
|
|
gst_element_factory_make ("capsfilter", "track-element-capsfilter");
|
2020-02-10 21:05:38 +00:00
|
|
|
g_ptr_array_add (elements, capsfilter);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
ges_frame_positioner_set_source_and_filter (GST_FRAME_POSITIONNER
|
|
|
|
(positioner), trksrc, capsfilter);
|
2013-08-21 09:32:45 +00:00
|
|
|
|
2016-04-29 13:29:00 +00:00
|
|
|
ges_track_element_add_children_props (trksrc, positioner, NULL, NULL,
|
|
|
|
positioner_props);
|
2019-03-19 15:39:20 +00:00
|
|
|
ges_track_element_add_children_props (trksrc, videoflip, NULL, NULL,
|
|
|
|
videoflip_props);
|
2014-01-15 18:12:08 +00:00
|
|
|
|
2016-04-13 09:31:05 +00:00
|
|
|
self->priv->positioner = GST_FRAME_POSITIONNER (positioner);
|
2016-08-02 20:42:20 +00:00
|
|
|
self->priv->positioner->scale_in_compositor =
|
|
|
|
!GES_VIDEO_SOURCE_GET_CLASS (self)->ABI.abi.disable_scale_in_compositor;
|
2020-02-19 21:09:19 +00:00
|
|
|
ges_video_source_get_natural_size (self,
|
|
|
|
&self->priv->positioner->natural_width,
|
|
|
|
&self->priv->positioner->natural_height);
|
|
|
|
|
2013-08-21 09:32:45 +00:00
|
|
|
self->priv->capsfilter = capsfilter;
|
|
|
|
|
2020-03-25 01:35:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
|
|
|
ges_video_source_create_element (GESTrackElement * trksrc)
|
|
|
|
{
|
|
|
|
GstElement *topbin;
|
|
|
|
GstElement *sub_element;
|
|
|
|
GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_GET_CLASS (trksrc);
|
|
|
|
GESVideoSource *self;
|
|
|
|
gboolean needs_converters = TRUE;
|
|
|
|
GPtrArray *elements;
|
|
|
|
|
|
|
|
if (!source_class->create_source)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sub_element = source_class->create_source (trksrc);
|
|
|
|
|
|
|
|
self = (GESVideoSource *) trksrc;
|
|
|
|
if (source_class->ABI.abi.needs_converters)
|
|
|
|
needs_converters = source_class->ABI.abi.needs_converters (self);
|
|
|
|
|
|
|
|
elements = g_ptr_array_new ();
|
|
|
|
g_assert (source_class->ABI.abi.create_filters);
|
|
|
|
if (!source_class->ABI.abi.create_filters (self, elements, needs_converters)) {
|
|
|
|
g_ptr_array_free (elements, TRUE);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
topbin = ges_source_create_topbin ("videosrcbin", sub_element, elements);
|
|
|
|
g_ptr_array_free (elements, TRUE);
|
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
return topbin;
|
|
|
|
}
|
|
|
|
|
2016-04-29 13:29:00 +00:00
|
|
|
static gboolean
|
|
|
|
_lookup_child (GESTimelineElement * object,
|
|
|
|
const gchar * prop_name, GObject ** element, GParamSpec ** pspec)
|
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
gchar *clean_name;
|
|
|
|
|
|
|
|
if (!g_strcmp0 (prop_name, "deinterlace-fields"))
|
|
|
|
clean_name = g_strdup ("GstDeinterlace::fields");
|
|
|
|
else if (!g_strcmp0 (prop_name, "deinterlace-mode"))
|
|
|
|
clean_name = g_strdup ("GstDeinterlace::mode");
|
|
|
|
else if (!g_strcmp0 (prop_name, "deinterlace-tff"))
|
|
|
|
clean_name = g_strdup ("GstDeinterlace::tff");
|
|
|
|
else if (!g_strcmp0 (prop_name, "tff") ||
|
|
|
|
!g_strcmp0 (prop_name, "fields") || !g_strcmp0 (prop_name, "mode")) {
|
|
|
|
GST_DEBUG_OBJECT (object, "Not allowed to use GstDeinterlace %s"
|
|
|
|
" property without prefixing its name", prop_name);
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
clean_name = g_strdup (prop_name);
|
|
|
|
|
|
|
|
res =
|
|
|
|
GES_TIMELINE_ELEMENT_CLASS (ges_video_source_parent_class)->lookup_child
|
|
|
|
(object, clean_name, element, pspec);
|
|
|
|
|
|
|
|
g_free (clean_name);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
static void
|
|
|
|
ges_video_source_class_init (GESVideoSourceClass * klass)
|
|
|
|
{
|
2016-04-29 13:29:00 +00:00
|
|
|
GESTrackElementClass *track_element_class = GES_TRACK_ELEMENT_CLASS (klass);
|
2013-09-01 16:19:32 +00:00
|
|
|
GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
|
2013-07-09 13:31:15 +00:00
|
|
|
GESVideoSourceClass *video_source_class = GES_VIDEO_SOURCE_CLASS (klass);
|
|
|
|
|
2015-08-27 14:28:42 +00:00
|
|
|
element_class->set_priority = _set_priority;
|
2016-04-29 13:29:00 +00:00
|
|
|
element_class->lookup_child = _lookup_child;
|
2015-08-27 14:28:42 +00:00
|
|
|
|
2016-04-29 13:29:00 +00:00
|
|
|
track_element_class->nleobject_factorytype = "nlesource";
|
|
|
|
track_element_class->create_element = ges_video_source_create_element;
|
2020-03-25 01:23:16 +00:00
|
|
|
track_element_class->ABI.abi.default_track_type = GES_TRACK_TYPE_VIDEO;
|
|
|
|
|
2013-07-09 13:31:15 +00:00
|
|
|
video_source_class->create_source = NULL;
|
2020-03-25 01:35:35 +00:00
|
|
|
video_source_class->ABI.abi.create_filters = ges_video_source_create_filters;
|
2013-07-09 13:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_video_source_init (GESVideoSource * self)
|
|
|
|
{
|
2018-09-06 01:55:02 +00:00
|
|
|
self->priv = ges_video_source_get_instance_private (self);
|
2016-04-13 09:31:05 +00:00
|
|
|
self->priv->positioner = NULL;
|
2013-08-21 09:32:45 +00:00
|
|
|
self->priv->capsfilter = NULL;
|
2020-02-19 21:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_video_source_get_natural_size:
|
|
|
|
* @self: A #GESVideoSource
|
|
|
|
* @width: (out): The natural width of the underlying source
|
|
|
|
* @height: (out): The natural height of the underlying source
|
|
|
|
*
|
|
|
|
* Retrieves the natural size of the video stream. The natural size, is
|
|
|
|
* the size at which it will be displayed if no scaling is being applied.
|
|
|
|
*
|
|
|
|
* NOTE: The sources take into account the potential video rotation applied
|
|
|
|
* by the #videoflip element that is inside the source, effects applied on
|
|
|
|
* the clip which potentially also rotate the element are not taken into
|
|
|
|
* account.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the object has a natural size, %FALSE otherwise.
|
2020-06-19 15:13:24 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2020-02-19 21:06:26 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ges_video_source_get_natural_size (GESVideoSource * self, gint * width,
|
|
|
|
gint * height)
|
|
|
|
{
|
|
|
|
GESVideoSourceClass *klass = GES_VIDEO_SOURCE_GET_CLASS (self);
|
|
|
|
|
|
|
|
if (!klass->ABI.abi.get_natural_size)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return klass->ABI.abi.get_natural_size (self, width, height);
|
2013-07-09 13:31:15 +00:00
|
|
|
}
|