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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2010-09-13 23:21:15 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-04 17:59:21 +00:00
|
|
|
|
|
|
|
#include "gesmarshal.h"
|
2010-09-13 23:21:15 +00:00
|
|
|
#include "ges-formatter.h"
|
2010-11-26 17:39:26 +00:00
|
|
|
#include "ges-keyfile-formatter.h"
|
2010-09-13 23:21:15 +00:00
|
|
|
#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
|
|
|
|
{
|
|
|
|
gchar *data;
|
|
|
|
gsize length;
|
2012-01-04 17:59:21 +00:00
|
|
|
|
|
|
|
/* Make sure not to emit several times "moved-source" when the user already
|
|
|
|
* provided the new source URI. */
|
|
|
|
GHashTable *uri_newuri_table;
|
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 *
|
2011-02-16 15:21:48 +00:00
|
|
|
timeline, const gchar * uri);
|
2010-10-07 13:25:22 +00:00
|
|
|
static gboolean save_to_uri (GESFormatter * formatter, GESTimeline *
|
2011-02-16 15:21:48 +00:00
|
|
|
timeline, const gchar * uri);
|
|
|
|
static gboolean default_can_load_uri (const gchar * uri);
|
|
|
|
static gboolean default_can_save_uri (const gchar * uri);
|
2012-01-04 17:59:21 +00:00
|
|
|
static void discovery_error_cb (GESTimeline * timeline,
|
|
|
|
GESTimelineFileSource * tfs, GError * error, GESFormatter * formatter);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SOURCE_MOVED_SIGNAL,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint ges_formatter_signals[LAST_SIGNAL] = { 0 };
|
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));
|
|
|
|
|
2012-01-04 17:59:21 +00:00
|
|
|
/**
|
|
|
|
* GESFormatter::source-moved:
|
|
|
|
* @formatter: the #GESFormatter
|
|
|
|
* @source: The #GESTimelineFileSource that has an invalid URI. When this happens,
|
|
|
|
* you can call #ges_formatter_update_source_uri with the new URI of the source so
|
|
|
|
* the project can be loaded properly.
|
|
|
|
*/
|
|
|
|
ges_formatter_signals[SOURCE_MOVED_SIGNAL] =
|
|
|
|
g_signal_new ("source-moved", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE,
|
|
|
|
1, GES_TYPE_TIMELINE_FILE_SOURCE);
|
|
|
|
|
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;
|
2012-01-04 17:59:21 +00:00
|
|
|
klass->update_source_uri = NULL;
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_formatter_init (GESFormatter * object)
|
|
|
|
{
|
2011-01-08 15:01:31 +00:00
|
|
|
object->priv = G_TYPE_INSTANCE_GET_PRIVATE (object,
|
|
|
|
GES_TYPE_FORMATTER, GESFormatterPrivate);
|
2012-01-04 17:59:21 +00:00
|
|
|
|
|
|
|
object->priv->uri_newuri_table = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal, g_free, g_free);
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_formatter_dispose (GObject * object)
|
|
|
|
{
|
2011-01-08 15:01:31 +00:00
|
|
|
GESFormatterPrivate *priv = GES_FORMATTER (object)->priv;
|
2010-09-13 23:21:15 +00:00
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
if (priv->data) {
|
|
|
|
g_free (priv->data);
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
2012-01-04 17:59:21 +00:00
|
|
|
g_hash_table_destroy (priv->uri_newuri_table);
|
2010-09-13 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_formatter_new_for_uri:
|
|
|
|
* @uri: a #gchar * pointing to the uri
|
|
|
|
*
|
|
|
|
* Creates a #GESFormatter that can handle the given URI.
|
|
|
|
*
|
2010-11-26 17:39:26 +00:00
|
|
|
* Returns: A GESFormatter that can load the given uri, or NULL if
|
2010-09-13 23:21:15 +00:00
|
|
|
* the uri is not supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GESFormatter *
|
2011-02-16 15:21:48 +00:00
|
|
|
ges_formatter_new_for_uri (const gchar * uri)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
|
|
|
if (ges_formatter_can_load_uri (uri))
|
2010-10-07 12:49:15 +00:00
|
|
|
return GES_FORMATTER (ges_keyfile_formatter_new ());
|
2010-09-13 23:21:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-07 12:49:15 +00:00
|
|
|
/**
|
2010-11-26 17:39:26 +00:00
|
|
|
* ges_default_formatter_new:
|
2010-10-07 12:49:15 +00:00
|
|
|
*
|
|
|
|
* Creates a new instance of the default GESFormatter type on this system
|
2010-12-08 14:36:55 +00:00
|
|
|
* (currently #GESKeyfileFormatter).
|
2010-10-07 12:49:15 +00:00
|
|
|
*
|
2011-05-09 17:33:53 +00:00
|
|
|
* Returns: (transfer full): a #GESFormatter instance or %NULL
|
2010-10-07 12:49:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
GESFormatter *
|
|
|
|
ges_default_formatter_new (void)
|
|
|
|
{
|
|
|
|
return GES_FORMATTER (ges_keyfile_formatter_new ());
|
|
|
|
}
|
|
|
|
|
2010-11-26 17:39:26 +00:00
|
|
|
static gboolean
|
2011-02-16 15:21:48 +00:00
|
|
|
default_can_load_uri (const gchar * uri)
|
2010-11-26 17:39:26 +00:00
|
|
|
{
|
|
|
|
GST_ERROR ("No 'can_load_uri' vmethod implementation");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-02-16 15:21:48 +00:00
|
|
|
default_can_save_uri (const gchar * uri)
|
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-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
|
2011-02-16 15:21:48 +00:00
|
|
|
ges_formatter_can_load_uri (const gchar * uri)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: implement file format registry */
|
|
|
|
/* TODO: search through the registry and chose a GESFormatter class that can
|
|
|
|
* handle the URI.*/
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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-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
|
2011-02-16 15:21:48 +00:00
|
|
|
ges_formatter_can_save_uri (const gchar * uri)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: implement file format registry */
|
|
|
|
/* TODO: search through the registry and chose a GESFormatter class that can
|
|
|
|
* handle the URI.*/
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-07 13:25:22 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_set_data:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @data: the data to be set on the formatter
|
|
|
|
* @length: the length of the data in bytes
|
2010-10-07 13:25:22 +00:00
|
|
|
*
|
|
|
|
* Set the data that this formatter will use for loading. The formatter will
|
|
|
|
* takes ownership of the data and will free the data if
|
2010-11-26 17:39:26 +00:00
|
|
|
* @ges_formatter_set_data is called again or when the formatter itself is
|
|
|
|
* disposed. You should call @ges_formatter_clear_data () if you do not wish
|
2010-10-07 13:25:22 +00:00
|
|
|
* this to happen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ges_formatter_set_data (GESFormatter * formatter, void *data, gsize length)
|
|
|
|
{
|
2011-01-08 15:01:31 +00:00
|
|
|
GESFormatterPrivate *priv = GES_FORMATTER (formatter)->priv;
|
|
|
|
|
|
|
|
if (priv->data)
|
|
|
|
g_free (priv->data);
|
|
|
|
priv->data = data;
|
|
|
|
priv->length = length;
|
2010-10-07 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-20 17:01:37 +00:00
|
|
|
* ges_formatter_get_data:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @length: location into which to store the size of the data in bytes.
|
2010-10-07 13:25:22 +00:00
|
|
|
*
|
2011-01-10 13:28:35 +00:00
|
|
|
* Lets you get the data @formatter used for loading.
|
|
|
|
*
|
2011-12-07 02:11:25 +00:00
|
|
|
* Returns: (transfer none): a pointer to the data.
|
2010-10-07 13:25:22 +00:00
|
|
|
*/
|
|
|
|
void *
|
|
|
|
ges_formatter_get_data (GESFormatter * formatter, gsize * length)
|
|
|
|
{
|
2011-01-08 15:01:31 +00:00
|
|
|
GESFormatterPrivate *priv = GES_FORMATTER (formatter)->priv;
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
*length = priv->length;
|
|
|
|
|
|
|
|
return priv->data;
|
2010-10-07 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_formatter_clear_data:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
2010-10-07 13:25:22 +00:00
|
|
|
*
|
|
|
|
* clears the data from a #GESFormatter without freeing it. You should call
|
|
|
|
* this before disposing or setting data on a #GESFormatter if the current data
|
|
|
|
* pointer should not be freed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ges_formatter_clear_data (GESFormatter * formatter)
|
|
|
|
{
|
2011-01-08 15:01:31 +00:00
|
|
|
GESFormatterPrivate *priv = GES_FORMATTER (formatter)->priv;
|
|
|
|
|
|
|
|
priv->data = NULL;
|
|
|
|
priv->length = 0;
|
2010-10-07 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
/**
|
|
|
|
* ges_formatter_load:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @timeline: a #GESTimeline
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-10-07 13:25:22 +00:00
|
|
|
* Loads data from formatter to into timeline. You should first call
|
2010-11-26 17:39:26 +00:00
|
|
|
* ges_formatter_set_data() with the location and size of a block of data
|
|
|
|
* from which to read.
|
2010-10-07 13:25:22 +00:00
|
|
|
*
|
2010-09-13 23:21:15 +00:00
|
|
|
* Returns: TRUE if the data was successfully loaded into timeline
|
|
|
|
* or FALSE if an error occured during loading.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ges_formatter_load (GESFormatter * formatter, GESTimeline * timeline)
|
|
|
|
{
|
|
|
|
GESFormatterClass *klass;
|
|
|
|
|
|
|
|
klass = GES_FORMATTER_GET_CLASS (formatter);
|
|
|
|
|
|
|
|
if (klass->load)
|
|
|
|
return klass->load (formatter, timeline);
|
2010-10-07 12:49:15 +00:00
|
|
|
GST_ERROR ("not implemented!");
|
2010-09-13 23:21:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_formatter_save:
|
2010-11-26 17:39:26 +00:00
|
|
|
* @formatter: a #GESFormatter
|
|
|
|
* @timeline: a #GESTimeline
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
2010-10-07 13:25:22 +00:00
|
|
|
* Save data from timeline into a block of data. You can retrieve the location
|
2010-11-26 17:39:26 +00:00
|
|
|
* and size of this data with ges_formatter_get_data().
|
2010-09-13 23:21:15 +00:00
|
|
|
*
|
|
|
|
* Returns: TRUE if the timeline data was successfully saved for FALSE if
|
|
|
|
* an error occured during saving.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ges_formatter_save (GESFormatter * formatter, GESTimeline * timeline)
|
|
|
|
{
|
|
|
|
GESFormatterClass *klass;
|
2011-01-11 17:14:41 +00:00
|
|
|
GList *layers;
|
2010-09-13 23:21:15 +00:00
|
|
|
|
2010-11-27 17:11:56 +00:00
|
|
|
/* Saving an empty timeline is not allowed */
|
2011-05-26 16:15:29 +00:00
|
|
|
/* FIXME : Having a ges_timeline_is_empty() would be more efficient maybe */
|
2011-01-11 17:14:41 +00:00
|
|
|
layers = ges_timeline_get_layers (timeline);
|
|
|
|
|
|
|
|
g_return_val_if_fail (layers != NULL, FALSE);
|
|
|
|
g_list_foreach (layers, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (layers);
|
2010-11-27 17:11:56 +00:00
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
klass = GES_FORMATTER_GET_CLASS (formatter);
|
|
|
|
|
|
|
|
if (klass->save)
|
|
|
|
return klass->save (formatter, timeline);
|
2010-11-27 17:11:56 +00:00
|
|
|
|
2010-10-07 12:49:15 +00:00
|
|
|
GST_ERROR ("not implemented!");
|
2010-11-27 17:11:56 +00:00
|
|
|
|
2010-09-13 23:21:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-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,
|
2011-02-16 15:21:48 +00:00
|
|
|
const gchar * uri)
|
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);
|
|
|
|
|
|
|
|
g_signal_connect (timeline, "discovery-error",
|
|
|
|
G_CALLBACK (discovery_error_cb), formatter);
|
2010-10-07 13:25:22 +00:00
|
|
|
if (klass->load_from_uri)
|
|
|
|
return klass->load_from_uri (formatter, timeline, uri);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-02-16 15:21:48 +00:00
|
|
|
load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
|
|
|
|
const gchar * uri)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
|
|
|
gchar *location;
|
|
|
|
GError *e = NULL;
|
|
|
|
gboolean ret = TRUE;
|
2011-01-08 15:01:31 +00:00
|
|
|
GESFormatterPrivate *priv = GES_FORMATTER (formatter)->priv;
|
2010-09-13 23:21:15 +00:00
|
|
|
|
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
if (priv->data) {
|
2010-09-13 23:21:15 +00:00
|
|
|
GST_ERROR ("formatter already has data! please set data to NULL");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(location = gst_uri_get_location (uri))) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-08 15:01:31 +00:00
|
|
|
if (g_file_get_contents (location, &priv->data, &priv->length, &e)) {
|
2010-09-13 23:21:15 +00:00
|
|
|
if (!ges_formatter_load (formatter, timeline)) {
|
|
|
|
GST_ERROR ("couldn't deserialize formatter");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_ERROR ("couldn't read file '%s': %s", location, e->message);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
g_error_free (e);
|
|
|
|
g_free (location);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
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 *
|
2011-02-16 15:21:48 +00:00
|
|
|
timeline, const gchar * uri)
|
2010-10-07 13:25:22 +00:00
|
|
|
{
|
|
|
|
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
|
2011-05-26 16:15:29 +00:00
|
|
|
GList *layers;
|
2010-10-07 13:25:22 +00:00
|
|
|
|
2010-11-27 17:11:56 +00:00
|
|
|
/* Saving an empty timeline is not allowed */
|
2011-05-26 16:15:29 +00:00
|
|
|
/* FIXME : Having a ges_timeline_is_empty() would be more efficient maybe */
|
2011-01-08 10:22:36 +00:00
|
|
|
layers = ges_timeline_get_layers (timeline);
|
2011-05-26 16:15:29 +00:00
|
|
|
|
2011-01-08 10:22:36 +00:00
|
|
|
g_return_val_if_fail (layers != NULL, FALSE);
|
2011-05-26 16:15:29 +00:00
|
|
|
g_list_foreach (layers, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (layers);
|
2010-11-27 17:11:56 +00:00
|
|
|
|
2010-10-07 13:25:22 +00:00
|
|
|
if (klass->save_to_uri)
|
|
|
|
return klass->save_to_uri (formatter, timeline, uri);
|
|
|
|
|
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,
|
|
|
|
const gchar * uri)
|
2010-09-13 23:21:15 +00:00
|
|
|
{
|
|
|
|
gchar *location;
|
|
|
|
GError *e = NULL;
|
|
|
|
gboolean ret = TRUE;
|
2011-01-08 15:01:31 +00:00
|
|
|
GESFormatterPrivate *priv = GES_FORMATTER (formatter)->priv;
|
2010-09-13 23:21:15 +00:00
|
|
|
|
|
|
|
if (!(location = g_filename_from_uri (uri, NULL, NULL))) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ges_formatter_save (formatter, timeline)) {
|
|
|
|
GST_ERROR ("couldn't serialize formatter");
|
|
|
|
} else {
|
2011-01-08 15:01:31 +00:00
|
|
|
if (!g_file_set_contents (location, priv->data, priv->length, &e)) {
|
2010-09-13 23:21:15 +00:00
|
|
|
GST_ERROR ("couldn't write file '%s': %s", location, e->message);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
g_error_free (e);
|
|
|
|
g_free (location);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-04 17:59:21 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
ges_formatter_update_source_uri (GESFormatter * formatter,
|
|
|
|
GESTimelineFileSource * source, gchar * new_uri)
|
|
|
|
{
|
|
|
|
GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
|
|
|
|
|
|
|
|
if (klass->update_source_uri) {
|
|
|
|
const gchar *uri = ges_timeline_filesource_get_uri (source);
|
|
|
|
gchar *cached_uri =
|
|
|
|
g_hash_table_lookup (formatter->priv->uri_newuri_table, uri);
|
|
|
|
|
|
|
|
if (!cached_uri) {
|
|
|
|
g_hash_table_insert (formatter->priv->uri_newuri_table, g_strdup (uri),
|
|
|
|
g_strdup (new_uri));
|
|
|
|
|
|
|
|
GST_DEBUG ("Adding %s to the new uri cache", new_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return klass->update_source_uri (formatter, source, new_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_ERROR ("not implemented!");
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
discovery_error_cb (GESTimeline * timeline,
|
|
|
|
GESTimelineFileSource * tfs, GError * error, GESFormatter * formatter)
|
|
|
|
{
|
|
|
|
if (error->domain == GST_RESOURCE_ERROR &&
|
|
|
|
error->code == GST_RESOURCE_ERROR_NOT_FOUND) {
|
|
|
|
const gchar *uri = ges_timeline_filesource_get_uri (tfs);
|
|
|
|
gchar *new_uri =
|
|
|
|
g_hash_table_lookup (formatter->priv->uri_newuri_table, uri);
|
|
|
|
|
|
|
|
if (new_uri) {
|
|
|
|
ges_formatter_update_source_uri (formatter, tfs, new_uri);
|
|
|
|
GST_DEBUG ("%s found in the cache, new uri: %s", uri, new_uri);
|
|
|
|
} else
|
|
|
|
g_signal_emit (formatter, ges_formatter_signals[SOURCE_MOVED_SIGNAL], 0,
|
|
|
|
tfs);
|
|
|
|
}
|
|
|
|
}
|