From 45c7f609da95fc576d68e836348e67d0bc0abbf3 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Sat, 24 Nov 2012 00:09:28 -0300 Subject: [PATCH] timeline: Make use of the Project API for timeline saving API: * Add a formatter_type paramatter to ges_timeline_save_to_uri --- ges/ges-timeline.c | 61 +++++++++++++++++++++++++++-------------- ges/ges-timeline.h | 11 ++++++-- tests/examples/ges-ui.c | 14 ++-------- tools/ges-launch.c | 2 +- 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/ges/ges-timeline.c b/ges/ges-timeline.c index ea1dcf3cb6..94f257f6f1 100644 --- a/ges/ges-timeline.c +++ b/ges/ges-timeline.c @@ -32,8 +32,6 @@ * * To save/load a timeline, you can use the ges_timeline_load_from_uri() and * ges_timeline_save_to_uri() methods to use the default format. If you wish - * to specify the format to save/load the timeline from, please consult the - * documentation about #GESFormatter. */ #include "ges-internal.h" @@ -1653,27 +1651,18 @@ ges_timeline_new (void) * Returns: A new timeline if the uri was loaded successfully, or NULL if the * uri could not be loaded */ - GESTimeline * ges_timeline_new_from_uri (const gchar * uri, GError ** error) { GESTimeline *ret; + GESProject *project = ges_project_new (uri); - /* FIXME : we should have a GError** argument so the user can know why - * it wasn't able to load the uri - */ - - ret = ges_timeline_new (); - - if (!ges_timeline_load_from_uri (ret, uri, error)) { - g_object_unref (ret); - return NULL; - } + ret = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), error)); + gst_object_unref (ret); return ret; } - /** * ges_timeline_load_from_uri: * @timeline: an empty #GESTimeline into which to load the formatter @@ -1684,32 +1673,62 @@ ges_timeline_new_from_uri (const gchar * uri, GError ** error) * Returns: TRUE if the timeline was loaded successfully, or FALSE if the uri * could not be loaded. */ - gboolean ges_timeline_load_from_uri (GESTimeline * timeline, const gchar * uri, GError ** error) { - GST_FIXME ("This should be reimplemented"); - return FALSE; + GESProject *project; + gboolean ret = FALSE; + + g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE); + g_return_val_if_fail ((ges_extractable_get_asset (GES_EXTRACTABLE + (timeline)) == NULL), FALSE); + + project = ges_project_new (uri); + ret = ges_project_load (project, timeline, error); + gst_object_unref (project); + + return ret; } /** * ges_timeline_save_to_uri: * @timeline: a #GESTimeline * @uri: The location to save to + * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL, + * will try to save in the same format as the one from which the timeline as been loaded + * or default to the formatter with highest rank + * @overwrite: %TRUE to overwrite file if it exists + * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL * * Saves the timeline to the given location * * Returns: TRUE if the timeline was successfully saved to the given location, * else FALSE. */ - gboolean ges_timeline_save_to_uri (GESTimeline * timeline, const gchar * uri, - GError ** error) + GESAsset * formatter_asset, gboolean overwrite, GError ** error) { - GST_FIXME ("This should be reimplemented"); - return FALSE; + gboolean ret, created_proj; + GESProject *project; + + g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE); + project = + GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE (timeline))); + + if (project == NULL) { + project = ges_project_new (NULL); + created_proj = TRUE; + } + + ret = ges_project_save (project, timeline, uri, formatter_asset, overwrite, + error); + + if (created_proj) + gst_object_unref (project); + + return ret; } /** diff --git a/ges/ges-timeline.h b/ges/ges-timeline.h index cca178bdc0..854425d05c 100644 --- a/ges/ges-timeline.h +++ b/ges/ges-timeline.h @@ -48,6 +48,13 @@ G_BEGIN_DECLS #define GES_TIMELINE_GET_TRACKS(obj) (GES_TIMELINE (obj)->tracks) #define GES_TIMELINE_GET_LAYERS(obj) (GES_TIMELINE (obj)->layers) +/** + * ges_timeline_get_project: + * + * Helper macro to retrieve the project from which a #GESTimeline as been extracted + */ +#define ges_timeline_get_project(obj) (GES_TIMELINE (ges_extractable_get_asset (obj)) + typedef struct _GESTimelinePrivate GESTimelinePrivate; /** @@ -95,8 +102,8 @@ GESTimeline* ges_timeline_new (void); GESTimeline* ges_timeline_new_from_uri (const gchar *uri, GError **error); gboolean ges_timeline_load_from_uri (GESTimeline *timeline, const gchar *uri, GError **error); -gboolean ges_timeline_save_to_uri (GESTimeline *timeline, const gchar *uri, GError **error); - +gboolean ges_timeline_save_to_uri (GESTimeline * timeline, const gchar * uri, + GESAsset *formatter_asset, gboolean overwrite, GError ** error); gboolean ges_timeline_add_layer (GESTimeline *timeline, GESTimelineLayer *layer); GESTimelineLayer * ges_timeline_append_layer (GESTimeline * timeline); gboolean ges_timeline_remove_layer (GESTimeline *timeline, GESTimelineLayer *layer); diff --git a/tests/examples/ges-ui.c b/tests/examples/ges-ui.c index e3422b4376..8e3ff7a2e2 100644 --- a/tests/examples/ges-ui.c +++ b/tests/examples/ges-ui.c @@ -1239,7 +1239,7 @@ app_add_transition (App * app) static void app_save_to_uri (App * app, gchar * uri) { - ges_timeline_save_to_uri (app->timeline, uri, NULL); + ges_timeline_save_to_uri (app->timeline, uri, NULL, FALSE, NULL); } static void @@ -1377,20 +1377,10 @@ fail: static gboolean load_file_async (App * app) { - -#if 0 - GESFormatter *formatter; - g_printf ("%s\n", app->pending_uri); - - formatter = ges_formatter_new_for_uri (app->pending_uri); - ges_formatter_load_from_uri (formatter, app->timeline, app->pending_uri, - NULL); + ges_timeline_load_from_uri (app->timeline, app->pending_uri, NULL); g_free (app->pending_uri); app->pending_uri = NULL; -#endif - - GST_FIXME ("This should be reimplemented"); return FALSE; } diff --git a/tools/ges-launch.c b/tools/ges-launch.c index b179a4be70..685b0932b3 100644 --- a/tools/ges-launch.c +++ b/tools/ges-launch.c @@ -275,7 +275,7 @@ create_pipeline (gchar * load_path, gchar * save_path, int argc, char **argv, g_error ("couldn't create uri for '%s", save_path); goto failure; } - ges_timeline_save_to_uri (timeline, uri, NULL); + ges_timeline_save_to_uri (timeline, uri, NULL, TRUE, NULL); g_free (uri); }