2010-08-06 10:58:08 +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
|
2012-11-04 00:25:20 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-08-06 10:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-07 19:02:48 +00:00
|
|
|
* SECTION:gesimagesource
|
2017-03-08 21:13:48 +00:00
|
|
|
* @title: GESImageSource
|
2010-08-06 10:58:08 +00:00
|
|
|
* @short_description: outputs the video stream from a media file as a still
|
|
|
|
* image.
|
2016-07-22 11:32:51 +00:00
|
|
|
*
|
2010-08-06 10:58:08 +00:00
|
|
|
* Outputs the video stream from a given file as a still frame. The frame
|
2013-02-08 19:39:18 +00:00
|
|
|
* chosen will be determined by the in-point property on the track element. For
|
2010-08-06 10:58:08 +00:00
|
|
|
* image files, do not set the in-point property.
|
|
|
|
*/
|
2018-09-24 14:41:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2010-08-06 10:58:08 +00:00
|
|
|
|
|
|
|
#include "ges-internal.h"
|
2013-01-26 15:31:33 +00:00
|
|
|
#include "ges-track-element.h"
|
2013-01-26 17:21:56 +00:00
|
|
|
#include "ges-image-source.h"
|
2010-08-06 10:58:08 +00:00
|
|
|
|
|
|
|
|
2013-01-26 17:21:56 +00:00
|
|
|
struct _GESImageSourcePrivate
|
2010-12-04 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Dummy variable */
|
|
|
|
void *nothing;
|
|
|
|
};
|
|
|
|
|
2010-08-06 10:58:08 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_URI
|
|
|
|
};
|
|
|
|
|
2018-09-06 01:55:02 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GESImageSource, ges_image_source,
|
|
|
|
GES_TYPE_VIDEO_SOURCE);
|
2010-08-06 10:58:08 +00:00
|
|
|
static void
|
2013-01-26 17:21:56 +00:00
|
|
|
ges_image_source_get_property (GObject * object, guint property_id,
|
2010-08-06 10:58:08 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-01-26 17:21:56 +00:00
|
|
|
GESImageSource *uriclip = GES_IMAGE_SOURCE (object);
|
2010-08-06 10:58:08 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_URI:
|
2013-01-20 15:42:29 +00:00
|
|
|
g_value_set_string (value, uriclip->uri);
|
2010-08-06 10:58:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 17:21:56 +00:00
|
|
|
ges_image_source_set_property (GObject * object, guint property_id,
|
2010-08-06 10:58:08 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-01-26 17:21:56 +00:00
|
|
|
GESImageSource *uriclip = GES_IMAGE_SOURCE (object);
|
2010-08-06 10:58:08 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_URI:
|
2013-01-20 15:42:29 +00:00
|
|
|
uriclip->uri = g_value_dup_string (value);
|
2010-08-06 10:58:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 17:21:56 +00:00
|
|
|
ges_image_source_dispose (GObject * object)
|
2010-08-06 10:58:08 +00:00
|
|
|
{
|
2013-01-26 17:21:56 +00:00
|
|
|
GESImageSource *uriclip = GES_IMAGE_SOURCE (object);
|
2010-08-06 10:58:08 +00:00
|
|
|
|
2013-01-20 15:42:29 +00:00
|
|
|
if (uriclip->uri)
|
|
|
|
g_free (uriclip->uri);
|
2010-08-06 10:58:08 +00:00
|
|
|
|
2013-01-26 17:21:56 +00:00
|
|
|
G_OBJECT_CLASS (ges_image_source_parent_class)->dispose (object);
|
2010-08-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-09 16:36:00 +00:00
|
|
|
static void
|
|
|
|
pad_added_cb (GstElement * timeline, GstPad * pad, GstElement * scale)
|
2010-08-06 10:58:08 +00:00
|
|
|
{
|
2010-08-09 16:36:00 +00:00
|
|
|
GstPad *sinkpad;
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
|
|
|
|
sinkpad = gst_element_get_static_pad (scale, "sink");
|
|
|
|
if (sinkpad) {
|
|
|
|
GST_DEBUG ("got sink pad, trying to link");
|
|
|
|
|
|
|
|
ret = gst_pad_link (pad, sinkpad);
|
2013-10-17 13:16:00 +00:00
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
if (GST_PAD_LINK_SUCCESSFUL (ret)) {
|
2010-08-09 16:36:00 +00:00
|
|
|
GST_DEBUG ("linked ok, returning");
|
|
|
|
return;
|
2013-10-17 13:16:00 +00:00
|
|
|
}
|
2010-08-09 16:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("pad failed to link properly");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
2013-06-27 12:20:00 +00:00
|
|
|
ges_image_source_create_source (GESTrackElement * track_element)
|
2010-08-09 16:36:00 +00:00
|
|
|
{
|
2010-08-11 16:23:17 +00:00
|
|
|
GstElement *bin, *source, *scale, *freeze, *iconv;
|
2010-08-09 16:36:00 +00:00
|
|
|
GstPad *src, *target;
|
|
|
|
|
|
|
|
bin = GST_ELEMENT (gst_bin_new ("still-image-bin"));
|
|
|
|
source = gst_element_factory_make ("uridecodebin", NULL);
|
|
|
|
scale = gst_element_factory_make ("videoscale", NULL);
|
|
|
|
freeze = gst_element_factory_make ("imagefreeze", NULL);
|
2011-10-11 07:51:43 +00:00
|
|
|
iconv = gst_element_factory_make ("videoconvert", NULL);
|
2010-08-09 16:36:00 +00:00
|
|
|
|
2010-08-12 13:45:15 +00:00
|
|
|
g_object_set (scale, "add-borders", TRUE, NULL);
|
|
|
|
|
2010-08-11 16:23:17 +00:00
|
|
|
gst_bin_add_many (GST_BIN (bin), source, scale, freeze, iconv, NULL);
|
2010-08-09 16:36:00 +00:00
|
|
|
|
2010-08-10 08:54:04 +00:00
|
|
|
gst_element_link_pads_full (scale, "src", iconv, "sink",
|
2010-08-09 16:36:00 +00:00
|
|
|
GST_PAD_LINK_CHECK_NOTHING);
|
2010-08-10 08:54:04 +00:00
|
|
|
gst_element_link_pads_full (iconv, "src", freeze, "sink",
|
|
|
|
GST_PAD_LINK_CHECK_NOTHING);
|
2010-08-09 16:36:00 +00:00
|
|
|
|
2010-08-11 16:23:17 +00:00
|
|
|
/* FIXME: add capsfilter here with sink caps (see 626518) */
|
|
|
|
|
|
|
|
target = gst_element_get_static_pad (freeze, "src");
|
2010-08-09 16:36:00 +00:00
|
|
|
|
|
|
|
src = gst_ghost_pad_new ("src", target);
|
|
|
|
gst_element_add_pad (bin, src);
|
|
|
|
gst_object_unref (target);
|
|
|
|
|
2013-02-15 02:34:48 +00:00
|
|
|
g_object_set (source, "uri", ((GESImageSource *) track_element)->uri, NULL);
|
2010-08-09 16:36:00 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (source), "pad-added",
|
|
|
|
G_CALLBACK (pad_added_cb), scale);
|
2010-08-06 10:58:08 +00:00
|
|
|
|
2010-08-09 16:36:00 +00:00
|
|
|
return bin;
|
2010-08-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 17:21:56 +00:00
|
|
|
ges_image_source_class_init (GESImageSourceClass * klass)
|
2010-08-06 10:58:08 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2013-07-09 13:31:15 +00:00
|
|
|
GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
|
2010-08-06 10:58:08 +00:00
|
|
|
|
2013-01-26 17:21:56 +00:00
|
|
|
object_class->get_property = ges_image_source_get_property;
|
|
|
|
object_class->set_property = ges_image_source_set_property;
|
|
|
|
object_class->dispose = ges_image_source_dispose;
|
2010-08-06 10:58:08 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-26 17:21:56 +00:00
|
|
|
* GESImageSource:uri:
|
2010-08-06 10:58:08 +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));
|
2016-07-22 11:32:51 +00:00
|
|
|
|
|
|
|
GES_TIMELINE_ELEMENT_CLASS (klass)->set_inpoint = NULL;
|
2013-06-27 12:20:00 +00:00
|
|
|
source_class->create_source = ges_image_source_create_source;
|
2020-02-19 21:06:26 +00:00
|
|
|
source_class->ABI.abi.get_natural_size =
|
|
|
|
ges_video_uri_source_get_natural_size;
|
2010-08-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-26 17:21:56 +00:00
|
|
|
ges_image_source_init (GESImageSource * self)
|
2010-08-06 10:58:08 +00:00
|
|
|
{
|
2018-09-06 01:55:02 +00:00
|
|
|
self->priv = ges_image_source_get_instance_private (self);
|
2010-08-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 13:28:35 +00:00
|
|
|
/**
|
2013-01-26 17:21:56 +00:00
|
|
|
* ges_image_source_new:
|
2011-01-10 13:28:35 +00:00
|
|
|
* @uri: the URI the source should control
|
|
|
|
*
|
2013-01-26 17:21:56 +00:00
|
|
|
* Creates a new #GESImageSource for the provided @uri.
|
2011-01-10 13:28:35 +00:00
|
|
|
*
|
2016-05-14 23:04:17 +00:00
|
|
|
* Returns: (transfer floating): A new #GESImageSource.
|
2011-01-10 13:28:35 +00:00
|
|
|
*/
|
2013-01-26 17:21:56 +00:00
|
|
|
GESImageSource *
|
|
|
|
ges_image_source_new (gchar * uri)
|
2010-08-06 10:58:08 +00:00
|
|
|
{
|
2013-01-26 17:21:56 +00:00
|
|
|
return g_object_new (GES_TYPE_IMAGE_SOURCE, "uri", uri, "track-type",
|
2012-12-20 23:23:54 +00:00
|
|
|
GES_TRACK_TYPE_VIDEO, NULL);
|
2010-08-06 10:58:08 +00:00
|
|
|
}
|