2010-09-13 23:21:15 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
|
|
|
|
* 2010 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-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:ges-formatter
|
2010-11-26 17:39:26 +00:00
|
|
|
* @short_description: Timeline saving and loading.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* The #GESFormatter is the object responsible for loading and/or saving the contents
|
|
|
|
* of a #GESTimeline to/from various formats.
|
|
|
|
*
|
|
|
|
* In order to save a #GESTimeline, you can either let GES pick a default formatter by
|
|
|
|
* using ges_timeline_save_to_uri(), or pick your own formatter and use
|
|
|
|
* ges_formatter_save_to_uri().
|
|
|
|
*
|
|
|
|
* To load a #GESTimeline, you might want to be able to track the progress of the loading,
|
|
|
|
* in which case you should create an empty #GESTimeline, connect to the relevant signals
|
|
|
|
* and call ges_formatter_load_from_uri().
|
|
|
|
*
|
|
|
|
* If you do not care about tracking the loading progress, you can use the convenience
|
|
|
|
* ges_timeline_new_from_uri() method.
|
|
|
|
*
|
|
|
|
* Support for saving or loading new formats can be added by creating a subclass of
|
|
|
|
* #GESFormatter and implement the various vmethods of #GESFormatterClass.
|
2012-01-07 16:28:15 +00:00
|
|
|
*
|
2012-07-01 23:57:30 +00:00
|
|
|
* Note that subclasses should call ges_formatter_project_loaded when they are done
|
|
|
|
* loading a project.
|
2010-09-13 23:21:15 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2012-04-03 23:25:18 +00:00
|
|
|
#include <gio/gio.h>
|
2010-09-13 23:21:15 +00:00
|
|
|
#include <stdlib.h>
|
2012-01-04 17:59:21 +00:00
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
#include "ges-formatter.h"
|
|
|
|
#include "ges-internal.h"
|
2012-01-04 17:59:21 +00:00
|
|
|
#include "ges.h"
|
2010-09-13 23:21:15 +00:00
|
|
|
|
2010-12-09 14:21:10 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GESFormatter, ges_formatter, G_TYPE_OBJECT);
|
2010-09-13 23:21:15 +00:00
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
struct _GESFormatterPrivate
|
|
|
|
{
|
2012-11-24 02:52:32 +00:00
|
|
|
gpointer nothing;
|
2011-01-08 15:01:31 +00:00
|
|
|
};
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
static void ges_formatter_dispose (GObject * object);
|
2010-10-07 13:25:22 +00:00
|
|
|
static gboolean load_from_uri (GESFormatter * formatter, GESTimeline *
|
2012-09-23 00:05:42 +00:00
|
|
|
timeline, const gchar * uri, GError ** error);
|
2010-10-07 13:25:22 +00:00
|
|
|
static gboolean save_to_uri (GESFormatter * formatter, GESTimeline *
|
2012-09-23 00:05:42 +00:00
|
|
|
timeline, const gchar * uri, GError ** error);
|
|
|
|
static gboolean default_can_load_uri (const gchar * uri, GError ** error);
|
|
|
|
static gboolean default_can_save_uri (const gchar * uri, GError ** error);
|
2012-01-04 17:59:21 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
static void
|
|
|
|
ges_formatter_class_init (GESFormatterClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GESFormatterPrivate));
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
object_class->dispose = ges_formatter_dispose;
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2010-11-26 17:39:26 +00:00
|
|
|
klass->can_load_uri = default_can_load_uri;
|
|
|
|
klass->can_save_uri = default_can_save_uri;
|
2010-10-07 13:25:22 +00:00
|
|
|
klass->load_from_uri = load_from_uri;
|
|
|
|
klass->save_to_uri = save_to_uri;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_formatter_init (GESFormatter * object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_formatter_dispose (GObject * object)
|
|
|
|
{
|
2012-09-23 00:06:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-26 17:39:26 +00:00
|
|
|
static gboolean
|
2012-09-23 00:05:42 +00:00
|
|
|
default_can_load_uri (const gchar * uri, GError ** error)
|
2010-11-26 17:39:26 +00:00
|
|
|
{
|
|
|
|
GST_ERROR ("No 'can_load_uri' vmethod implementation");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-23 00:05:42 +00:00
|
|
|
default_can_save_uri (const gchar * uri, GError ** error)
|
2010-11-26 17:39:26 +00:00
|
|
|
{
|
|
|
|
GST_ERROR ("No 'can_save_uri' vmethod implementation");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_can_load_uri:
|
|
|
|
* @uri: a #gchar * pointing to the URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2012-01-04 17:59:21 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Checks if there is a #GESFormatter available which can load a #GESTimeline
|
|
|
|
* from the given URI.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if there is a #GESFormatter that can support the given uri
|
|
|
|
* or FALSE if not.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2012-09-23 00:05:42 +00:00
|
|
|
ges_formatter_can_load_uri (const gchar * uri, GError ** error)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
|
|
|
if (!(gst_uri_is_valid (uri))) {
|
|
|
|
GST_ERROR ("Invalid uri!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(gst_uri_has_protocol (uri, "file"))) {
|
|
|
|
gchar *proto = gst_uri_get_protocol (uri);
|
|
|
|
GST_ERROR ("Unspported protocol '%s'", proto);
|
|
|
|
g_free (proto);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-24 02:52:32 +00:00
|
|
|
/* FIXME Reimplement */
|
|
|
|
GST_FIXME ("This should be reimplemented");
|
2012-09-23 00:06:44 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-26 17:39:26 +00:00
|
|
|
* ges_formatter_can_save_uri:
|
2010-09-13 23:21:15 +00:00
|
|
|
* @uri: a #gchar * pointing to a URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2012-01-04 17:59:21 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns TRUE if there is a #GESFormatter available which can save a
|
|
|
|
* #GESTimeline to the given URI.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if the given @uri is supported, else FALSE.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2012-09-23 00:05:42 +00:00
|
|
|
ges_formatter_can_save_uri (const gchar * uri, GError ** error)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
|
|
|
if (!(gst_uri_is_valid (uri))) {
|
2012-01-05 16:21:40 +00:00
|
|
|
GST_ERROR ("%s invalid uri!", uri);
|
2010-09-13 23:21:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(gst_uri_has_protocol (uri, "file"))) {
|
|
|
|
gchar *proto = gst_uri_get_protocol (uri);
|
|
|
|
GST_ERROR ("Unspported protocol '%s'", proto);
|
|
|
|
g_free (proto);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: implement file format registry */
|
|
|
|
/* TODO: search through the registry and chose a GESFormatter class that can
|
|
|
|
* handle the URI.*/
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_formatter_load_from_uri:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @timeline: a #GESTimeline
|
2010-09-13 23:21:15 +00:00
|
|
|
* @uri: a #gchar * pointing to a URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2012-01-04 17:59:21 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Load data from the given URI into timeline.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if the timeline data was successfully loaded from the URI,
|
|
|
|
* else FALSE.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
|
2012-09-23 00:05:42 +00:00
|
|
|
const gchar * uri, GError ** error)
|
2010-10-07 13:25:22 +00:00
|
|
|
{
|
2012-05-21 22:10:29 +00:00
|
|
|
gboolean ret = FALSE;
|
2010-10-07 13:25:22 +00:00
|
|
|
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
|
|
|
|
|
2012-01-04 17:59:21 +00:00
|
|
|
g_return_val_if_fail (GES_IS_FORMATTER (formatter), FALSE);
|
|
|
|
g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
|
|
|
|
|
2012-05-21 22:10:29 +00:00
|
|
|
if (klass->load_from_uri) {
|
|
|
|
ges_timeline_enable_update (timeline, FALSE);
|
2012-07-01 23:34:53 +00:00
|
|
|
formatter->timeline = timeline;
|
2012-09-23 00:05:42 +00:00
|
|
|
ret = klass->load_from_uri (formatter, timeline, uri, error);
|
2012-05-21 22:10:29 +00:00
|
|
|
ges_timeline_enable_update (timeline, TRUE);
|
|
|
|
}
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2012-05-21 22:10:29 +00:00
|
|
|
return ret;
|
2010-10-07 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-02-16 15:21:48 +00:00
|
|
|
load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
|
2012-09-23 00:05:42 +00:00
|
|
|
const gchar * uri, GError ** error)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
2012-11-24 02:52:32 +00:00
|
|
|
GST_FIXME ("This should be reimplemented");
|
|
|
|
return FALSE;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_formatter_save_to_uri:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @timeline: a #GESTimeline
|
2010-09-13 23:21:15 +00:00
|
|
|
* @uri: a #gchar * pointing to a URI
|
2012-09-23 00:05:42 +00:00
|
|
|
* @error: A #GError that will be set in case of error
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Save data from timeline to the given URI.
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: TRUE if the timeline data was successfully saved to the URI
|
|
|
|
* else FALSE.
|
2010-09-13 23:21:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2010-10-07 13:25:22 +00:00
|
|
|
ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline *
|
2012-09-23 00:05:42 +00:00
|
|
|
timeline, const gchar * uri, GError ** error)
|
2010-10-07 13:25:22 +00:00
|
|
|
{
|
|
|
|
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
|
2010-11-27 17:11:56 +00:00
|
|
|
|
2010-10-07 13:25:22 +00:00
|
|
|
if (klass->save_to_uri)
|
2012-09-23 00:05:42 +00:00
|
|
|
return klass->save_to_uri (formatter, timeline, uri, error);
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2011-05-26 16:15:29 +00:00
|
|
|
GST_ERROR ("not implemented!");
|
|
|
|
|
2010-10-07 13:25:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-02-16 15:21:48 +00:00
|
|
|
save_to_uri (GESFormatter * formatter, GESTimeline * timeline,
|
2012-09-23 00:05:42 +00:00
|
|
|
const gchar * uri, GError ** error)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
2012-11-24 02:52:32 +00:00
|
|
|
GST_FIXME ("This should be reimplemented");
|
2012-01-04 17:59:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|