1 /* GStreamer Editing Services
3 * Copyright (C) <2012> Thibault Saunier <thibault.saunier@collabora.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * @short_description: A GESAsset that is used to manage projects
24 * The #GESProject is used to control a set of #GESAsset and is a
25 * #GESAsset with #GES_TYPE_TIMELINE as @extractable_type itself. That
26 * means that you can extract #GESTimeline from a project as followed:
29 * GESProject *project;
30 * GESTimeline *timeline;
32 * project = ges_project_new ("file:///path/to/a/valid/project/uri");
34 * // Here you can connect to the various signal to get more infos about
35 * // what is happening and recover from errors if possible
38 * timeline = ges_asset_extract (GES_ASSET (project));
41 * The #GESProject class offers a higher level API to handle #GESAsset-s.
42 * It lets you request new asset, and it informs you about new assets through
43 * a set of signals. Also it handles problem such as missing files/missing
44 * #GstElement and lets you try to recover from those.
47 #include "ges-internal.h"
49 static GPtrArray *new_paths = NULL;
50 static GHashTable *tried_uris = NULL;
52 /* TODO We should rely on both extractable_type and @id to identify
53 * a Asset, not only @id
55 G_DEFINE_TYPE (GESProject, ges_project, GES_TYPE_ASSET);
57 struct _GESProjectPrivate
60 /* Set of asset ID being loaded */
61 GHashTable *loading_assets;
62 GHashTable *loaded_with_error;
63 GESAsset *formatter_asset;
69 GList *encoding_profiles;
72 typedef struct EmitLoadedInIdle
75 GESTimeline *timeline;
88 static guint _signals[LAST_SIGNAL] = { 0 };
90 static guint nb_projects = 0;
99 static GParamSpec *_properties[LAST_SIGNAL] = { 0 };
102 _emit_loaded_in_idle (EmitLoadedInIdle * data)
104 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
106 gst_object_unref (data->project);
107 gst_object_unref (data->timeline);
108 g_slice_free (EmitLoadedInIdle, data);
114 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
116 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
118 ges_formatter_set_project (formatter, project);
119 priv->formatters = g_list_append (priv->formatters, formatter);
121 gst_object_ref_sink (formatter);
125 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
128 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
130 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
131 if (tmp->data == formatter) {
132 gst_object_unref (formatter);
133 priv->formatters = g_list_delete_link (priv->formatters, tmp);
141 ges_project_set_uri (GESProject * project, const gchar * uri)
143 GESProjectPrivate *priv;
145 g_return_if_fail (GES_IS_PROJECT (project));
147 priv = project->priv;
149 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
155 GST_LOG_OBJECT (project, "Uri should not be NULL");
159 priv->uri = g_strdup (uri);
161 /* We use that URI as ID */
162 ges_asset_set_id (GES_ASSET (project), uri);
168 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
171 GESProjectPrivate *priv;
172 GESFormatter *formatter;
174 priv = GES_PROJECT (project)->priv;
176 if (priv->uri == NULL) {
177 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
179 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
180 " as no URI set yet", GST_OBJECT_NAME (timeline),
181 ges_asset_get_id (GES_ASSET (project)));
183 data->timeline = gst_object_ref (timeline);
184 data->project = gst_object_ref (project);
186 /* Make sure the signal is emitted after the functions ends */
187 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
191 if (priv->formatter_asset == NULL)
192 priv->formatter_asset = _find_formatter_asset_for_id (priv->uri);
194 if (priv->formatter_asset == NULL)
197 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
199 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
205 ges_project_add_formatter (GES_PROJECT (project), formatter);
206 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
208 GST_WARNING_OBJECT (project, "Could not load the timeline,"
209 " returning: %s", lerr->message);
217 g_propagate_error (error, lerr);
222 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
223 const GValue * handler_return, gpointer data)
225 const gchar *ret = g_value_get_string (handler_return);
228 if (!gst_uri_is_valid (ret)) {
229 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
233 g_value_set_string (return_accu, ret);
240 /* GESAsset vmethod implementation */
241 static GESExtractable *
242 ges_project_extract (GESAsset * project, GError ** error)
244 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
246 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
247 if (_load_project (GES_PROJECT (project), timeline, error))
248 return GES_EXTRACTABLE (timeline);
250 gst_object_unref (timeline);
255 _add_media_new_paths_recursing (const gchar * value)
258 GFileEnumerator *fenum;
259 GFile *file = g_file_new_for_uri (value);
261 if (!(fenum = g_file_enumerate_children (file,
262 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
263 GST_INFO ("%s is not a folder", value);
268 GST_INFO ("Adding folder: %s", value);
269 g_ptr_array_add (new_paths, g_strdup (value));
270 for (info = g_file_enumerator_next_file (fenum, NULL, NULL);
271 info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) {
273 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
274 GFile *f = g_file_enumerator_get_child (fenum, info);
275 gchar *uri = g_file_get_uri (f);
277 _add_media_new_paths_recursing (uri);
278 gst_object_unref (f);
284 gst_object_unref (file);
286 gst_object_unref (fenum);
290 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
292 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
294 if (new_paths == NULL)
295 new_paths = g_ptr_array_new_with_free_func (g_free);
298 _add_media_new_paths_recursing (uri);
300 g_ptr_array_add (new_paths, g_strdup (uri));
306 ges_missing_uri_default (GESProject * self, GError * error,
307 GESAsset * wrong_asset)
310 const gchar *old_uri = ges_asset_get_id (wrong_asset);
312 if (new_paths == NULL)
315 if (tried_uris == NULL)
316 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
318 for (i = 0; i < new_paths->len; i++) {
319 gchar *basename, *res;
321 basename = g_path_get_basename (old_uri);
322 res = g_build_filename (new_paths->pdata[i], basename, NULL);
325 if (g_strcmp0 (old_uri, res) == 0) {
326 g_hash_table_add (tried_uris, res);
327 } else if (g_hash_table_lookup (tried_uris, res)) {
328 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
331 g_hash_table_add (tried_uris, g_strdup (res));
332 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
341 ges_uri_assets_validate_uri (const gchar * nid)
344 g_hash_table_remove (tried_uris, nid);
347 /* GObject vmethod implementation */
349 _dispose (GObject * object)
352 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
355 g_hash_table_unref (priv->assets);
356 if (priv->loading_assets)
357 g_hash_table_unref (priv->loading_assets);
358 if (priv->loaded_with_error)
359 g_hash_table_unref (priv->loaded_with_error);
360 if (priv->formatter_asset)
361 gst_object_unref (priv->formatter_asset);
363 for (tmp = priv->formatters; tmp; tmp = tmp->next)
364 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
366 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
370 _finalize (GObject * object)
372 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
377 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
381 _get_property (GESProject * project, guint property_id,
382 GValue * value, GParamSpec * pspec)
384 GESProjectPrivate *priv = project->priv;
386 switch (property_id) {
388 g_value_set_string (value, priv->uri);
391 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
396 _set_property (GESProject * project, guint property_id,
397 const GValue * value, GParamSpec * pspec)
399 switch (property_id) {
401 project->priv->uri = g_value_dup_string (value);
404 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
409 ges_project_class_init (GESProjectClass * klass)
411 GObjectClass *object_class = G_OBJECT_CLASS (klass);
413 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
415 klass->asset_added = NULL;
416 klass->missing_uri = ges_missing_uri_default;
417 klass->loading_error = NULL;
418 klass->asset_removed = NULL;
419 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
420 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
425 * The location of the project to use.
427 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
428 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
430 g_object_class_install_properties (object_class, PROP_LAST, _properties);
433 * GESProject::asset-added:
434 * @formatter: the #GESProject
435 * @asset: The #GESAsset that has been added to @project
437 _signals[ASSET_ADDED_SIGNAL] =
438 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
439 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
440 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
443 * GESProject::asset-removed:
444 * @formatter: the #GESProject
445 * @asset: The #GESAsset that has been removed from @project
447 _signals[ASSET_REMOVED_SIGNAL] =
448 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
449 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
450 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
453 * GESProject::loaded:
454 * @project: the #GESProject that is done loading a project.
455 * @timeline: The #GESTimeline that complete loading
457 _signals[LOADED_SIGNAL] =
458 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
459 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
460 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
461 1, GES_TYPE_TIMELINE);
464 * GESProject::missing-uri:
465 * @project: the #GESProject reporting that a file has moved
466 * @error: The error that happened
467 * @wrong_asset: The asset with the wrong ID, you should us it and its content
468 * only to find out what the new location is.
472 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
474 * return g_strdup ("file:///the/new/uri.ogg");
478 * main (int argc, gchar ** argv)
480 * GESTimeline *timeline;
481 * GESProject *project = ges_project_new ("file:///some/uri.xges");
483 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
484 * timeline = ges_asset_extract (GES_ASSET (project));
488 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
490 _signals[MISSING_URI_SIGNAL] =
491 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
492 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
493 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
494 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
497 * GESProject::error-loading-asset:
498 * @project: the #GESProject on which a problem happend when creted a #GESAsset
499 * @error: The #GError defining the error that accured, might be %NULL
500 * @id: The @id of the asset that failed loading
501 * @extractable_type: The @extractable_type of the asset that
504 * Informs you that a #GESAsset could not be created. In case of
505 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
506 * #GST_CORE_ERROR_MISSING_PLUGIN
508 _signals[ERROR_LOADING_ASSET] =
509 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
510 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
511 NULL, NULL, g_cclosure_marshal_generic,
512 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
514 object_class->dispose = _dispose;
515 object_class->finalize = _finalize;
517 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
521 ges_project_init (GESProject * project)
523 GESProjectPrivate *priv = project->priv =
524 G_TYPE_INSTANCE_GET_PRIVATE (project,
525 GES_TYPE_PROJECT, GESProjectPrivate);
528 priv->formatters = NULL;
529 priv->formatter_asset = NULL;
530 priv->encoding_profiles = NULL;
531 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
532 g_free, gst_object_unref);
533 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
534 g_free, gst_object_unref);
535 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
540 _send_error_loading_asset (GESProject * project, GESAsset * asset,
543 const gchar *id = ges_asset_get_id (asset);
545 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
546 g_hash_table_remove (project->priv->loading_assets, id);
547 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
548 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
549 ges_asset_get_extractable_type (asset));
553 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
556 gchar *new_id = NULL;
559 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
560 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
561 g_return_val_if_fail (error, NULL);
563 id = ges_asset_get_id (asset);
564 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
565 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
566 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
567 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
569 _send_error_loading_asset (project, asset, error);
574 if (new_id == NULL) {
575 GST_DEBUG_OBJECT (project, "Sending 'missing-uri' signal for %s", id);
576 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
581 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
582 if (!ges_asset_set_proxy (asset, new_id)) {
587 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
590 g_hash_table_remove (project->priv->loading_assets, id);
593 _send_error_loading_asset (project, asset, error);
600 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
602 GError *error = NULL;
603 gchar *possible_id = NULL;
604 GESAsset *asset = ges_asset_request_finish (res, &error);
607 possible_id = ges_project_try_updating_id (project, source, error);
609 if (possible_id == NULL)
612 ges_project_create_asset (project, possible_id,
613 ges_asset_get_extractable_type (source));
615 g_free (possible_id);
616 g_error_free (error);
620 ges_project_add_asset (project, asset);
622 gst_object_unref (asset);
626 * ges_project_set_loaded:
627 * @project: The #GESProject from which to emit the "project-loaded" signal
629 * Emits the "loaded" signal. This method should be called by sublasses when
630 * the project is fully loaded.
632 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
635 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
637 GST_INFO_OBJECT (project, "Emit project loaded");
638 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
639 timeline_fill_gaps (formatter->timeline);
641 ges_timeline_commit (formatter->timeline);
644 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
646 /* We are now done with that formatter */
647 ges_project_remove_formatter (project, formatter);
652 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
657 if ((asset = ges_asset_cache_lookup (extractable_type, id)))
658 g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
659 gst_object_ref (asset));
662 /**************************************
664 * API Implementation *
666 **************************************/
669 * ges_project_create_asset:
670 * @project: A #GESProject
671 * @id: (allow-none): The id of the asset to create and add to @project
672 * @extractable_type: The #GType of the asset to create
674 * Create and add a #GESAsset to @project. You should connect to the
675 * "asset-added" signal to get the asset when it finally gets added to
678 * Returns: %TRUE if the asset started to be added %FALSE it was already
682 ges_project_create_asset (GESProject * project, const gchar * id,
683 GType extractable_type)
685 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
686 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
690 id = g_type_name (extractable_type);
692 if (g_hash_table_lookup (project->priv->assets, id) ||
693 g_hash_table_lookup (project->priv->loading_assets, id) ||
694 g_hash_table_lookup (project->priv->loaded_with_error, id))
697 /* TODO Add a GCancellable somewhere in our API */
698 ges_asset_request_async (extractable_type, id, NULL,
699 (GAsyncReadyCallback) new_asset_cb, project);
700 ges_project_add_loading_asset (project, extractable_type, id);
706 * ges_project_create_asset_sync:
707 * @project: A #GESProject
708 * @id: (allow-none): The id of the asset to create and add to @project
709 * @extractable_type: The #GType of the asset to create
710 * @error: A #GError to be set in case of error
712 * Create and add a #GESAsset to @project. You should connect to the
713 * "asset-added" signal to get the asset when it finally gets added to
716 * Returns: The newly created #GESAsset
719 ges_project_create_asset_sync (GESProject * project, const gchar * id,
720 GType extractable_type, GError ** error)
723 gchar *possible_id = NULL;
724 gboolean retry = TRUE;
726 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
727 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
731 id = g_type_name (extractable_type);
733 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
735 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
736 g_hash_table_lookup (project->priv->loaded_with_error, id))
739 /* TODO Add a GCancellable somewhere in our API */
742 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
743 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
745 asset = ges_asset_request (extractable_type, id, error);
752 g_free (possible_id);
753 ges_uri_assets_validate_uri (id);
760 tmpasset = ges_asset_cache_lookup (extractable_type, id);
761 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
763 if (possible_id == NULL)
767 g_clear_error (error);
773 ges_project_add_asset (project, asset);
779 * ges_project_add_asset:
780 * @project: A #GESProject
781 * @asset: (transfer none): A #GESAsset to add to @project
783 * Adds a #Asset to @project, the project will keep a reference on
786 * Returns: %TRUE if the asset could be added %FALSE it was already
790 ges_project_add_asset (GESProject * project, GESAsset * asset)
792 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
794 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
797 g_hash_table_insert (project->priv->assets,
798 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
800 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
801 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
802 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
808 * ges_project_remove_asset:
809 * @project: A #GESProject
810 * @asset: (transfer none): A #GESAsset to remove from @project
812 * remove a @asset to from @project.
814 * Returns: %TRUE if the asset could be removed %FALSE otherwise
817 ges_project_remove_asset (GESProject * project, GESAsset * asset)
821 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
823 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
824 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
830 * ges_project_get_asset:
831 * @project: A #GESProject
832 * @id: The id of the asset to retrieve
833 * @extractable_type: The extractable_type of the asset
834 * to retrieve from @object
836 * Returns: (transfer full) (allow-none): The #GESAsset with
837 * @id or %NULL if no asset with @id as an ID
840 ges_project_get_asset (GESProject * project, const gchar * id,
841 GType extractable_type)
845 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
846 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
849 asset = g_hash_table_lookup (project->priv->assets, id);
852 return gst_object_ref (asset);
858 * ges_project_list_assets:
859 * @project: A #GESProject
860 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
863 * List all @asset contained in @project filtering per extractable_type
864 * as defined by @filter. It copies the asset and thus will not be updated
867 * Returns: (transfer full) (element-type GESAsset): The list of
868 * #GESAsset the object contains
871 ges_project_list_assets (GESProject * project, GType filter)
877 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
879 g_hash_table_iter_init (&iter, project->priv->assets);
880 while (g_hash_table_iter_next (&iter, &key, &value)) {
881 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
883 ret = g_list_append (ret, gst_object_ref (value));
891 * @project: A #GESProject to save
892 * @timeline: The #GESTimeline to save, it must have been extracted from @project
893 * @uri: The uri where to save @project and @timeline
894 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
895 * will try to save in the same format as the one from which the timeline as been loaded
896 * or default to the formatter with highest rank
897 * @overwrite: %TRUE to overwrite file if it exists
898 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
900 * Save the timeline of @project to @uri. You should make sure that @timeline
901 * is one of the timelines that have been extracted from @project
902 * (using ges_asset_extract (@project);)
904 * Returns: %TRUE if the project could be save, %FALSE otherwize
907 ges_project_save (GESProject * project, GESTimeline * timeline,
908 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
913 GESFormatter *formatter = NULL;
915 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
916 g_return_val_if_fail (formatter_asset == NULL ||
917 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
918 GES_TYPE_FORMATTER), FALSE);
919 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
921 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
922 if (tl_asset == NULL && project->priv->uri == NULL) {
923 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
926 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
927 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
931 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
932 " we have no uri set, so setting ourself as asset", timeline);
934 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
935 } else if (tl_asset != GES_ASSET (project)) {
936 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
937 " not created by this project can not save", timeline);
943 if (formatter_asset == NULL)
944 formatter_asset = gst_object_ref (ges_formatter_get_default ());
946 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
947 if (formatter == NULL) {
948 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
949 formatter_asset, ges_asset_get_id (formatter_asset),
950 (error && *error) ? (*error)->message : "Unknown Error");
956 ges_project_add_formatter (project, formatter);
957 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
958 if (ret && project->priv->uri == NULL)
959 ges_project_set_uri (project, uri);
963 gst_object_unref (formatter_asset);
964 ges_project_remove_formatter (project, formatter);
971 * @uri: (allow-none): The uri to be set after creating the project.
973 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
974 * if @uri is not valid or %NULL, the uri of the project will then be set
975 * the first time you save the project. If you then save the project to
976 * other locations, it will never be updated again and the first valid URI is
977 * the URI it will keep refering to.
979 * Returns: A newly created #GESProject
982 ges_project_new (const gchar * uri)
984 gchar *id = (gchar *) uri;
988 id = g_strdup_printf ("project-%i", nb_projects++);
990 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
993 ges_project_set_uri (project, uri);
1003 * @project: A #GESProject that has an @uri set already
1004 * @timeline: A blank timeline to load @project into
1005 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1007 * Loads @project into @timeline
1009 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1012 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1014 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1015 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1016 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1017 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1019 if (!_load_project (project, timeline, error))
1022 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1028 * ges_project_get_uri:
1029 * @project: A #GESProject
1031 * Retrieve the uri that is currently set on @project
1033 * Returns: The uri that is set on @project
1036 ges_project_get_uri (GESProject * project)
1038 GESProjectPrivate *priv;
1040 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1042 priv = project->priv;
1044 return g_strdup (priv->uri);
1049 * ges_project_add_encoding_profile:
1050 * @project: A #GESProject
1051 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1052 * the same name already exists, it will be replaced
1054 * Adds @profile to the project. It lets you save in what format
1055 * the project has been renders and keep a reference to those formats.
1056 * Also, those formats will be saves to the project file when possible.
1058 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1061 ges_project_add_encoding_profile (GESProject * project,
1062 GstEncodingProfile * profile)
1065 GESProjectPrivate *priv;
1067 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1068 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1070 priv = project->priv;
1071 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1072 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1074 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1075 gst_encoding_profile_get_name (profile)) == 0) {
1076 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1077 gst_encoding_profile_get_name (profile));
1079 gst_object_unref (tmp->data);
1080 tmp->data = gst_object_ref (profile);
1085 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1086 gst_object_ref (profile));
1092 * ges_project_list_encoding_profiles:
1093 * @project: A #GESProject
1095 * Lists the encoding profile that have been set to @project. The first one
1096 * is the latest added.
1098 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1099 * list of #GstEncodingProfile used in @project
1102 ges_project_list_encoding_profiles (GESProject * project)
1104 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1106 return project->priv->encoding_profiles;
1110 * ges_project_get_loading_assets:
1111 * @project: A #GESProject
1113 * Get the assets that are being loaded
1115 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1116 * that will be added to @project. Note that those Asset are *not* loaded yet,
1117 * and thus can not be used
1120 ges_project_get_loading_assets (GESProject * project)
1122 GHashTableIter iter;
1123 gpointer key, value;
1127 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1129 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1130 while (g_hash_table_iter_next (&iter, &key, &value))
1131 ret = g_list_prepend (ret, gst_object_ref (value));