ges: multifilesrc support

* GESMultiFileSource class
* multifilesrc example
* Support multifile:// urls in uri asset
* start/stop index modification
* Doc

https://bugzilla.gnome.org/show_bug.cgi?id=719373
This commit is contained in:
Lubosz Sarnecki 2013-11-12 12:13:31 +01:00 committed by Thibault Saunier
parent e2827bf0b7
commit 46c65aaaaf
15 changed files with 508 additions and 7 deletions

View file

@ -290,7 +290,7 @@ AG_GST_SET_PLUGINDIR
dnl define an ERROR_CFLAGS Makefile variable
AG_GST_SET_ERROR_CFLAGS($GST_GIT, [-Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wundef \
-Wwrite-strings -Wformat-nonliteral -Wformat-security -Wold-style-definition \
-Wwrite-strings -Wformat-security -Wold-style-definition \
-Winit-self -Wmissing-include-dirs -Waddress -Waggregate-return -Wno-multichar \
-Wnested-externs])

View file

@ -78,6 +78,7 @@ platform as well as Windows. It is released under the GNU Library General Public
<xi:include href="xml/ges-video-transition.xml"/>
<xi:include href="xml/ges-audio-transition.xml"/>
<xi:include href="xml/ges-image-source.xml"/>
<xi:include href="xml/ges-multi-file-source.xml"/>
<xi:include href="xml/ges-effect.xml"/>
</chapter>

View file

@ -270,6 +270,23 @@ GESImageSourceClass
ges_image_source_get_type
</SECTION>
<SECTION>
<FILE>ges-multi-file-source</FILE>
<TITLE>GESMultiFileSource</TITLE>
GESMultiFileSource
ges_multi_file_source_new
<SUBSECTION Standard>
GESMultiFileSourcePrivate
GES_IS_MULTI_FILE_SOURCE
GES_IS_MULTI_FILE_SOURCE_CLASS
GES_MULTI_FILE_SOURCE
GES_MULTI_FILE_SOURCE_CLASS
GES_MULTI_FILE_SOURCE_GET_CLASS
GES_TYPE_MULTI_FILE_SOURCE
GESMultiFileSourceClass
ges_multi_file_source_get_type
</SECTION>
<SECTION>
<FILE>ges-transition</FILE>
<TITLE>GESTransition</TITLE>

View file

@ -25,6 +25,7 @@ ges_video_uri_source_get_type
ges_audio_uri_source_get_type
ges_track_get_type
ges_image_source_get_type
ges_multi_file_source_get_type
ges_track_element_get_type
ges_base_effect_get_type
ges_effect_get_type

View file

@ -38,6 +38,7 @@ libges_@GST_API_VERSION@_la_SOURCES = \
ges-video-uri-source.c \
ges-audio-uri-source.c \
ges-image-source.c \
ges-multi-file-source.c \
ges-transition.c \
ges-audio-transition.c \
ges-video-transition.c \
@ -104,6 +105,7 @@ libges_@GST_API_VERSION@include_HEADERS = \
ges-video-uri-source.h \
ges-audio-uri-source.h \
ges-image-source.h \
ges-multi-file-source.h \
ges-transition.h \
ges-audio-transition.h \
ges-video-transition.h \

View file

@ -304,4 +304,16 @@ G_GNUC_INTERNAL GESImageSource * ges_image_source_new (gchar *uri);
G_GNUC_INTERNAL GESTitleSource * ges_title_source_new (void);
G_GNUC_INTERNAL GESVideoTestSource * ges_video_test_source_new (void);
/******************************
* GESMultiFile internal API *
******************************/
typedef struct GESMultiFileURI
{
gchar *location;
gint start;
gint end;
} GESMultiFileURI;
G_GNUC_INTERNAL GESMultiFileURI * ges_multi_file_uri_new (const gchar * uri);
#endif /* __GES_INTERNAL_H__ */

271
ges/ges-multi-file-source.c Normal file
View file

@ -0,0 +1,271 @@
/* GStreamer Editing Services
* Copyright (C) 2013 Lubosz Sarnecki <lubosz@gmail.com>
*
* 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.
*/
/**
* SECTION:ges-multi-file-source
* @short_description: outputs the video stream from a sequence of images.
*
* Outputs the video stream from a given image sequence. The start frame
* chosen will be determined by the in-point property on the track element.
*/
#include <stdlib.h>
#include <string.h>
#include "ges-internal.h"
#include "ges-track-element.h"
#include "ges-multi-file-source.h"
#include "ges-extractable.h"
#include "ges-uri-asset.h"
#include "ges-internal.h"
/* Extractable interface implementation */
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)
{
iface->check_id = ges_extractable_check_id;
}
G_DEFINE_TYPE_WITH_CODE (GESMultiFileSource, ges_multi_file_source,
GES_TYPE_VIDEO_SOURCE,
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE,
ges_extractable_interface_init));
struct _GESMultiFileSourcePrivate
{
/* Dummy variable */
void *nothing;
};
enum
{
PROP_0,
PROP_URI
};
static void
ges_multi_file_source_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
GESMultiFileSource *uriclip = GES_MULTI_FILE_SOURCE (object);
switch (property_id) {
case PROP_URI:
g_value_set_string (value, uriclip->uri);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
ges_multi_file_source_set_property (GObject * object, guint property_id,
const GValue * value, GParamSpec * pspec)
{
GESMultiFileSource *uriclip = GES_MULTI_FILE_SOURCE (object);
switch (property_id) {
case PROP_URI:
uriclip->uri = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
ges_multi_file_source_dispose (GObject * object)
{
GESMultiFileSource *uriclip = GES_MULTI_FILE_SOURCE (object);
if (uriclip->uri)
g_free (uriclip->uri);
G_OBJECT_CLASS (ges_multi_file_source_parent_class)->dispose (object);
}
static void
pad_added_cb (GstElement * decodebin, GstPad * pad, GstElement * bin)
{
GstPad *srcpad;
srcpad = gst_ghost_pad_new ("src", pad);
gst_pad_set_active (srcpad, TRUE);
gst_element_add_pad (bin, srcpad);
}
/**
* ges_multi_file_uri_new: (skip)
*
* Reads start/stop index and location from a multifile uri.
*
*/
GESMultiFileURI *
ges_multi_file_uri_new (const gchar * uri)
{
gchar *colon = NULL;
gchar *at = NULL;
gchar *indices;
int charpos;
GESMultiFileURI *uri_data;
const int prefix_size = strlen (GES_MULTI_FILE_URI_PREFIX);
uri_data = malloc (sizeof (GESMultiFileURI));
uri_data->start = 0;
uri_data->end = -1;
at = strchr (uri, '@');
if (at != NULL) {
charpos = (int) (at - uri);
indices = g_strdup_printf ("%.*s", charpos, uri);
indices = &indices[prefix_size];
colon = strchr (indices, ':');
if (colon != NULL) {
charpos = (int) (colon - indices);
uri_data->end = atoi (colon + 1);
uri_data->start = atoi (g_strdup_printf ("%.*s", charpos, indices));
GST_DEBUG ("indices start: %d end %d\n", uri_data->start, uri_data->end);
} else {
GST_ERROR
("Malformated multifile uri. You are using '@' and are missing ':'");
}
uri_data->location = at + 1;
} else {
uri_data->location = g_strdup (&uri[prefix_size]);
}
GST_DEBUG ("location: %s\n", uri_data->location);
return uri_data;
}
static GstElement *
ges_multi_file_source_create_source (GESTrackElement * track_element)
{
GESMultiFileSource *self;
GstElement *bin, *src, *decodebin;
GstCaps *disc_caps;
GstDiscovererStreamInfo *stream_info;
GValue fps = G_VALUE_INIT;
GstCaps *caps;
GESUriSourceAsset *asset;
GESMultiFileURI *uri_data;
self = (GESMultiFileSource *) track_element;
asset =
GES_URI_SOURCE_ASSET (ges_extractable_get_asset (GES_EXTRACTABLE (self)));
if (asset != NULL) {
stream_info = ges_uri_source_asset_get_stream_info (asset);
g_assert (stream_info);
disc_caps = gst_discoverer_stream_info_get_caps (stream_info);
caps = gst_caps_copy (disc_caps);
GST_DEBUG ("Got some nice caps %s", gst_caps_to_string (disc_caps));
gst_object_unref (stream_info);
gst_caps_unref (disc_caps);
} else {
caps = gst_caps_new_empty ();
GST_WARNING ("Could not extract asset.");
}
g_value_init (&fps, GST_TYPE_FRACTION);
gst_value_set_fraction (&fps, 25, 1);
gst_caps_set_value (caps, "framerate", &fps);
bin = GST_ELEMENT (gst_bin_new ("multi-image-bin"));
src = gst_element_factory_make ("multifilesrc", NULL);
uri_data = ges_multi_file_uri_new (self->uri);
g_object_set (src, "start-index", uri_data->start, "stop-index",
uri_data->end, "caps", caps, "location", uri_data->location, NULL);
g_free (uri_data);
decodebin = gst_element_factory_make ("decodebin", NULL);
gst_bin_add_many (GST_BIN (bin), src, decodebin, NULL);
gst_element_link_pads_full (src, "src", decodebin, "sink",
GST_PAD_LINK_CHECK_NOTHING);
g_signal_connect (G_OBJECT (decodebin), "pad-added",
G_CALLBACK (pad_added_cb), bin);
return bin;
}
static void
ges_multi_file_source_class_init (GESMultiFileSourceClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
g_type_class_add_private (klass, sizeof (GESMultiFileSourcePrivate));
object_class->get_property = ges_multi_file_source_get_property;
object_class->set_property = ges_multi_file_source_set_property;
object_class->dispose = ges_multi_file_source_dispose;
/**
* GESMultiFileSource:uri:
*
* The uri of the file/resource to use. You can set a start index,
* a stop index and a sequence pattern.
* The format is &lt;multifile://start:stop\@location-pattern&gt;.
* The pattern uses printf string formating.
*
* Example uris:
*
* multifile:///home/you/image\%03d.jpg
*
* multifile://20:50@/home/you/sequence/\%04d.png
*
*/
g_object_class_install_property (object_class, PROP_URI,
g_param_spec_string ("uri", "URI", "multifile uri",
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
source_class->create_source = ges_multi_file_source_create_source;
}
static void
ges_multi_file_source_init (GESMultiFileSource * self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
GES_TYPE_MULTI_FILE_SOURCE, GESMultiFileSourcePrivate);
}
/**
* ges_multi_file_source_new:
* @uri: the URI the source should control
*
* Creates a new #GESMultiFileSource for the provided @uri.
*
* Returns: A new #GESMultiFileSource.
*/
GESMultiFileSource *
ges_multi_file_source_new (gchar * uri)
{
return g_object_new (GES_TYPE_MULTI_FILE_SOURCE, "uri", uri,
"track-type", GES_TRACK_TYPE_VIDEO, NULL);
}

View file

@ -0,0 +1,72 @@
/* GStreamer Editing Services
* Copyright (C) 2013 Lubosz Sarnecki <lubosz@gmail.com>
*
* 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.
*/
#ifndef _GES_MULTI_FILE_SOURCE
#define _GES_MULTI_FILE_SOURCE
#include <glib-object.h>
#include <ges/ges-types.h>
#include <ges/ges-video-source.h>
G_BEGIN_DECLS
#define GES_TYPE_MULTI_FILE_SOURCE ges_multi_file_source_get_type()
#define GES_MULTI_FILE_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GES_TYPE_MULTI_FILE_SOURCE, GESMultiFileSource))
#define ges_multi_file_source_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GES_TYPE_MULTI_FILE_SOURCE, GESMultiFileSourceClass))
#define GES_IS_MULTI_FILE_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GES_TYPE_MULTI_FILE_SOURCE))
#define GES_IS_MULTI_FILE_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GES_TYPE_MULTI_FILE_SOURCE))
#define ges_multi_file_source_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GES_TYPE_MULTI_FILE_SOURCE, GESMultiFileSourceClass))
typedef struct _GESMultiFileSourcePrivate GESMultiFileSourcePrivate;
/**
* GESMultiFileSource:
*/
struct _GESMultiFileSource
{
/*< private > */
GESVideoSource parent;
gchar *uri;
GESMultiFileSourcePrivate *priv;
/* Padding for API extension */
gpointer _ges_reserved[GES_PADDING];
};
struct _GESMultiFileSourceClass
{
GESVideoSourceClass parent_class;
/* Padding for API extension */
gpointer _ges_reserved[GES_PADDING];
};
GType ges_multi_file_source_get_type (void);
GESMultiFileSource *ges_multi_file_source_new (gchar * uri);
#define GES_MULTI_FILE_URI_PREFIX "multifile://"
G_END_DECLS
#endif /* _GES_MULTI_FILE_SOURCE */

View file

@ -119,6 +119,12 @@ typedef struct _GESAudioUriSourceClass GESAudioUriSourceClass;
typedef struct _GESImageSource GESImageSource;
typedef struct _GESImageSourceClass GESImageSourceClass;
typedef struct _GESMultiFileSource GESMultiFileSource;
typedef struct _GESMultiFileSourceClass GESMultiFileSourceClass;
typedef struct _GESMultiFileClip GESMultiFileClip;
typedef struct _GESMultiFileClipClass GESMultiFileClipClass;
typedef struct _GESTransition GESTransition;
typedef struct _GESTransitionClass GESTransitionClass;

View file

@ -438,7 +438,8 @@ ges_uri_clip_asset_new (const gchar * uri, GCancellable * cancellable,
/**
* ges_uri_clip_asset_request_sync:
* @uri: The URI of the file for which to create a #GESUriClipAsset
* @uri: The URI of the file for which to create a #GESUriClipAsset.
* You can also use multi file uris for #GESMultiFileSource.
* @error: (allow-none): An error to be set in case something wrong happens or %NULL
*
* Creates a #GESUriClipAsset for @uri syncronously. You should avoid
@ -453,6 +454,7 @@ ges_uri_clip_asset_request_sync (const gchar * uri, GError ** error)
GstDiscovererInfo *info;
GstDiscoverer *discoverer;
GESUriClipAsset *asset;
gchar *first_file, *first_file_uri;
asset = GES_URI_CLIP_ASSET (ges_asset_request (GES_TYPE_URI_CLIP, uri,
&lerror));
@ -470,7 +472,22 @@ ges_uri_clip_asset_request_sync (const gchar * uri, GError ** error)
asset = g_object_new (GES_TYPE_URI_CLIP_ASSET, "id", uri,
"extractable-type", GES_TYPE_URI_CLIP, NULL);
discoverer = GES_URI_CLIP_ASSET_GET_CLASS (asset)->sync_discoverer;
info = gst_discoverer_discover_uri (discoverer, uri, &lerror);
if (g_str_has_prefix (uri, GES_MULTI_FILE_URI_PREFIX)) {
GESMultiFileURI *uri_data;
uri_data = ges_multi_file_uri_new (uri);
first_file = g_strdup_printf (uri_data->location, uri_data->start);
first_file_uri = gst_filename_to_uri (first_file, &lerror);
info = gst_discoverer_discover_uri (discoverer, first_file_uri, &lerror);
GST_DEBUG ("Got multifile uri. Discovering first file %s", first_file_uri);
g_free (uri_data);
g_free (first_file_uri);
g_free (first_file);
} else {
info = gst_discoverer_discover_uri (discoverer, uri, &lerror);
}
if (info == NULL || lerror != NULL) {
gst_object_unref (asset);
if (lerror)
@ -552,8 +569,11 @@ _extract (GESAsset * asset, GError ** error)
return NULL;
}
if (GST_IS_DISCOVERER_VIDEO_INFO (priv->sinfo) &&
gst_discoverer_video_info_is_image ((GstDiscovererVideoInfo *)
if (g_str_has_prefix (priv->uri, GES_MULTI_FILE_URI_PREFIX)) {
trackelement =
GES_TRACK_ELEMENT (ges_multi_file_source_new (g_strdup (priv->uri)));
} else if (GST_IS_DISCOVERER_VIDEO_INFO (priv->sinfo)
&& gst_discoverer_video_info_is_image ((GstDiscovererVideoInfo *)
priv->sinfo))
trackelement =
GES_TRACK_ELEMENT (ges_image_source_new (g_strdup (priv->uri)));

View file

@ -36,6 +36,7 @@
#include "ges-extractable.h"
#include "ges-image-source.h"
#include "ges-audio-test-source.h"
#include "ges-multi-file-source.h"
static void ges_extractable_interface_init (GESExtractableInterface * iface);
@ -427,7 +428,10 @@ ges_uri_clip_create_track_element (GESClip * clip, GESTrackType type)
GESUriClipPrivate *priv = GES_URI_CLIP (clip)->priv;
GESTrackElement *res = NULL;
if (priv->is_image) {
if (g_str_has_prefix (priv->uri, GES_MULTI_FILE_URI_PREFIX)) {
GST_DEBUG ("Creating a GESMultiFileSource for %s", priv->uri);
res = (GESTrackElement *) ges_multi_file_source_new (priv->uri);
} else if (priv->is_image) {
if (type != GES_TRACK_TYPE_VIDEO) {
GST_DEBUG ("Object is still image, not adding any audio source");
return NULL;

View file

@ -62,6 +62,7 @@
#include <ges/ges-video-uri-source.h>
#include <ges/ges-audio-uri-source.h>
#include <ges/ges-image-source.h>
#include <ges/ges-multi-file-source.h>
#include <ges/ges-video-test-source.h>
#include <ges/ges-audio-test-source.h>
#include <ges/ges-title-source.h>

View file

@ -8,4 +8,5 @@ simple1
text_properties
transition
thumbnails
overlays
overlays
multifilesrc

View file

@ -16,6 +16,7 @@ noinst_PROGRAMS = \
overlays \
text_properties \
assets \
multifilesrc \
$(graphical)
AM_CFLAGS = -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_CFLAGS) $(GTK_CFLAGS)

View file

@ -0,0 +1,92 @@
/* GStreamer Editing Services
* Copyright (C) 2013 Lubosz Sarnecki <lubosz@gmail.com>
*
* 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.
*/
#include <stdlib.h>
#include <ges/ges.h>
/* A image sequence test */
int
main (int argc, gchar ** argv)
{
GError *err = NULL;
GOptionContext *ctx;
GESPipeline *pipeline;
GESTimeline *timeline;
GESAsset *asset;
GESLayer *layer;
GMainLoop *mainloop;
GESTrack *track;
gint duration = 10;
gchar *filepattern = NULL;
GOptionEntry options[] = {
{"duration", 'd', 0, G_OPTION_ARG_INT, &duration,
"duration to use from the file (in seconds, default:10s)", "seconds"},
{"pattern-url", 'u', 0, G_OPTION_ARG_FILENAME, &filepattern,
"Pattern of the files. i.e. multifile:///foo/%04d.jpg",
"pattern-url"},
{NULL}
};
ctx = g_option_context_new ("- Plays an image sequence");
g_option_context_add_main_entries (ctx, options, NULL);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
g_print ("Error initializing %s\n", err->message);
exit (1);
}
if (filepattern == NULL) {
g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
exit (0);
}
g_option_context_free (ctx);
gst_init (&argc, &argv);
ges_init ();
timeline = ges_timeline_new ();
track = GES_TRACK (ges_video_track_new ());
ges_timeline_add_track (timeline, track);
layer = ges_layer_new ();
if (!ges_timeline_add_layer (timeline, layer))
return -1;
asset = GES_ASSET (ges_uri_clip_asset_request_sync (filepattern, &err));
ges_layer_add_asset (layer, asset, 0, 0, 5 * GST_SECOND,
GES_TRACK_TYPE_VIDEO);
pipeline = ges_pipeline_new ();
if (!ges_pipeline_set_timeline (pipeline, timeline))
return -1;
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
mainloop = g_main_loop_new (NULL, FALSE);
g_timeout_add_seconds (4, (GSourceFunc) g_main_loop_quit, mainloop);
g_main_loop_run (mainloop);
return 0;
}