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 ges_timeline_commit (data->timeline);
105 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
107 gst_object_unref (data->project);
108 gst_object_unref (data->timeline);
109 g_slice_free (EmitLoadedInIdle, data);
115 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
117 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
119 ges_formatter_set_project (formatter, project);
120 priv->formatters = g_list_append (priv->formatters, formatter);
122 gst_object_ref_sink (formatter);
126 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
129 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
131 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
132 if (tmp->data == formatter) {
133 gst_object_unref (formatter);
134 priv->formatters = g_list_delete_link (priv->formatters, tmp);
142 ges_project_set_uri (GESProject * project, const gchar * uri)
144 GESProjectPrivate *priv;
146 g_return_if_fail (GES_IS_PROJECT (project));
148 priv = project->priv;
150 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
155 if (uri == NULL || !gst_uri_is_valid (uri)) {
156 GST_LOG_OBJECT (project, "Invalid URI: %s", uri);
160 priv->uri = g_strdup (uri);
162 /* We use that URI as ID */
163 ges_asset_set_id (GES_ASSET (project), uri);
169 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
172 GESProjectPrivate *priv;
173 GESFormatter *formatter;
175 priv = GES_PROJECT (project)->priv;
177 if (priv->uri == NULL) {
178 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
180 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
181 " as no URI set yet", GST_OBJECT_NAME (timeline),
182 ges_asset_get_id (GES_ASSET (project)));
184 data->timeline = gst_object_ref (timeline);
185 data->project = gst_object_ref (project);
187 /* Make sure the signal is emitted after the functions ends */
188 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
192 if (priv->formatter_asset == NULL)
193 priv->formatter_asset = _find_formatter_asset_for_uri (priv->uri);
195 if (priv->formatter_asset == NULL)
198 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
200 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
206 ges_project_add_formatter (GES_PROJECT (project), formatter);
207 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
209 GST_WARNING_OBJECT (project, "Could not load the timeline,"
210 " returning: %s", lerr->message);
218 g_propagate_error (error, lerr);
223 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
224 const GValue * handler_return, gpointer data)
226 const gchar *ret = g_value_get_string (handler_return);
229 if (!gst_uri_is_valid (ret)) {
230 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
234 g_value_set_string (return_accu, ret);
241 /* GESAsset vmethod implementation */
242 static GESExtractable *
243 ges_project_extract (GESAsset * project, GError ** error)
245 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
247 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
248 if (_load_project (GES_PROJECT (project), timeline, error))
249 return GES_EXTRACTABLE (timeline);
251 gst_object_unref (timeline);
256 _add_media_new_paths_recursing (const gchar * value)
259 GFileEnumerator *fenum;
260 GFile *file = g_file_new_for_uri (value);
262 if (!(fenum = g_file_enumerate_children (file,
263 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
264 GST_INFO ("%s is not a folder", value);
269 GST_INFO ("Adding folder: %s", value);
270 g_ptr_array_add (new_paths, g_strdup (value));
271 for (info = g_file_enumerator_next_file (fenum, NULL, NULL);
272 info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) {
274 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
275 GFile *f = g_file_enumerator_get_child (fenum, info);
276 gchar *uri = g_file_get_uri (f);
278 _add_media_new_paths_recursing (uri);
279 gst_object_unref (f);
285 gst_object_unref (file);
287 gst_object_unref (fenum);
292 ges_add_missing_uri_relocation_path (const gchar * option_name,
293 const gchar * value, gpointer udata, GError ** error)
295 g_return_val_if_fail (gst_uri_is_valid (value), FALSE);
297 if (new_paths == NULL)
298 new_paths = g_ptr_array_new_with_free_func (g_free);
300 g_print ("\n\nOption name %s\n\n", option_name);
301 if (g_strcmp0 (option_name, "--sample-path-recurse") == 0 ||
302 g_strcmp0 (option_name, "-R") == 0) {
303 _add_media_new_paths_recursing (value);
305 GST_INFO ("Adding folder: %s", value);
306 g_ptr_array_add (new_paths, g_strdup (value));
313 ges_missing_uri_default (GESProject * self, GError * error,
314 GESAsset * wrong_asset)
317 const gchar *old_uri = ges_asset_get_id (wrong_asset);
319 if (new_paths == NULL)
322 if (tried_uris == NULL)
323 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
325 for (i = 0; i < new_paths->len; i++) {
326 gchar *basename, *res;
328 basename = g_path_get_basename (old_uri);
329 res = g_build_filename (new_paths->pdata[i], basename, NULL);
332 if (g_strcmp0 (old_uri, res) == 0) {
333 g_hash_table_add (tried_uris, res);
334 } else if (g_hash_table_lookup (tried_uris, res)) {
335 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
338 g_hash_table_add (tried_uris, g_strdup (res));
339 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
348 ges_uri_assets_validate_uri (const gchar * nid)
351 g_hash_table_remove (tried_uris, nid);
354 /* GObject vmethod implementation */
356 _dispose (GObject * object)
359 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
362 g_hash_table_unref (priv->assets);
363 if (priv->loading_assets)
364 g_hash_table_unref (priv->loading_assets);
365 if (priv->loaded_with_error)
366 g_hash_table_unref (priv->loaded_with_error);
367 if (priv->formatter_asset)
368 gst_object_unref (priv->formatter_asset);
370 for (tmp = priv->formatters; tmp; tmp = tmp->next)
371 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
373 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
377 _finalize (GObject * object)
379 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
384 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
388 _get_property (GESProject * project, guint property_id,
389 GValue * value, GParamSpec * pspec)
391 GESProjectPrivate *priv = project->priv;
393 switch (property_id) {
395 g_value_set_string (value, priv->uri);
398 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
403 _set_property (GESProject * project, guint property_id,
404 const GValue * value, GParamSpec * pspec)
406 switch (property_id) {
408 project->priv->uri = g_value_dup_string (value);
411 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
416 ges_project_class_init (GESProjectClass * klass)
418 GObjectClass *object_class = G_OBJECT_CLASS (klass);
420 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
422 klass->asset_added = NULL;
423 klass->missing_uri = ges_missing_uri_default;
424 klass->loading_error = NULL;
425 klass->asset_removed = NULL;
426 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
427 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
432 * The location of the project to use.
434 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
435 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
437 g_object_class_install_properties (object_class, PROP_LAST, _properties);
440 * GESProject::asset-added:
441 * @formatter: the #GESProject
442 * @asset: The #GESAsset that has been added to @project
444 _signals[ASSET_ADDED_SIGNAL] =
445 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
446 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
447 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
450 * GESProject::asset-removed:
451 * @formatter: the #GESProject
452 * @asset: The #GESAsset that has been removed from @project
454 _signals[ASSET_REMOVED_SIGNAL] =
455 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
456 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
457 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
460 * GESProject::loaded:
461 * @project: the #GESProject that is done loading a project.
462 * @timeline: The #GESTimeline that complete loading
464 _signals[LOADED_SIGNAL] =
465 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
466 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
467 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
468 1, GES_TYPE_TIMELINE);
471 * GESProject::missing-uri:
472 * @project: the #GESProject reporting that a file has moved
473 * @error: The error that happened
474 * @wrong_asset: The asset with the wrong ID, you should us it and its content
475 * only to find out what the new location is.
479 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
481 * return g_strdup ("file:///the/new/uri.ogg");
485 * main (int argc, gchar ** argv)
487 * GESTimeline *timeline;
488 * GESProject *project = ges_project_new ("file:///some/uri.xges");
490 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
491 * timeline = ges_asset_extract (GES_ASSET (project));
495 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
497 _signals[MISSING_URI_SIGNAL] =
498 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
499 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
500 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
501 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
504 * GESProject::error-loading-asset:
505 * @project: the #GESProject on which a problem happend when creted a #GESAsset
506 * @error: The #GError defining the error that accured, might be %NULL
507 * @id: The @id of the asset that failed loading
508 * @extractable_type: The @extractable_type of the asset that
511 * Informs you that a #GESAsset could not be created. In case of
512 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
513 * #GST_CORE_ERROR_MISSING_PLUGIN
515 _signals[ERROR_LOADING_ASSET] =
516 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
517 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
518 NULL, NULL, g_cclosure_marshal_generic,
519 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
521 object_class->dispose = _dispose;
522 object_class->finalize = _finalize;
524 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
528 ges_project_init (GESProject * project)
530 GESProjectPrivate *priv = project->priv =
531 G_TYPE_INSTANCE_GET_PRIVATE (project,
532 GES_TYPE_PROJECT, GESProjectPrivate);
535 priv->formatters = NULL;
536 priv->formatter_asset = NULL;
537 priv->encoding_profiles = NULL;
538 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
539 g_free, gst_object_unref);
540 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
541 g_free, gst_object_unref);
542 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
547 _send_error_loading_asset (GESProject * project, GESAsset * asset,
550 const gchar *id = ges_asset_get_id (asset);
552 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
553 g_hash_table_remove (project->priv->loading_assets, id);
554 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
555 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
556 ges_asset_get_extractable_type (asset));
560 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
563 gchar *new_id = NULL;
566 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
567 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
568 g_return_val_if_fail (error, NULL);
570 id = ges_asset_get_id (asset);
571 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
572 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
573 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
574 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
576 _send_error_loading_asset (project, asset, error);
581 if (new_id == NULL) {
582 GST_DEBUG_OBJECT (project, "Sending 'missing-uri' signal for %s", id);
583 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
588 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
589 if (!ges_asset_set_proxy (asset, new_id)) {
594 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
597 g_hash_table_remove (project->priv->loading_assets, id);
600 _send_error_loading_asset (project, asset, error);
607 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
609 GError *error = NULL;
610 gchar *possible_id = NULL;
611 GESAsset *asset = ges_asset_request_finish (res, &error);
614 possible_id = ges_project_try_updating_id (project, source, error);
616 if (possible_id == NULL)
619 ges_project_create_asset (project, possible_id,
620 ges_asset_get_extractable_type (source));
622 g_free (possible_id);
623 g_error_free (error);
627 ges_project_add_asset (project, asset);
629 gst_object_unref (asset);
633 * ges_project_set_loaded:
634 * @project: The #GESProject from which to emit the "project-loaded" signal
636 * Emits the "loaded" signal. This method should be called by sublasses when
637 * the project is fully loaded.
639 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
642 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
644 GST_INFO_OBJECT (project, "Emit project loaded");
645 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
646 timeline_fill_gaps (formatter->timeline);
648 ges_timeline_commit (formatter->timeline);
651 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
653 /* We are now done with that formatter */
654 ges_project_remove_formatter (project, formatter);
659 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
664 if ((asset = ges_asset_cache_lookup (extractable_type, id)))
665 g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
666 gst_object_ref (asset));
669 /**************************************
671 * API Implementation *
673 **************************************/
676 * ges_project_create_asset:
677 * @project: A #GESProject
678 * @id: (allow-none): The id of the asset to create and add to @project
679 * @extractable_type: The #GType of the asset to create
681 * Create and add a #GESAsset to @project. You should connect to the
682 * "asset-added" signal to get the asset when it finally gets added to
685 * Returns: %TRUE if the asset started to be added %FALSE it was already
689 ges_project_create_asset (GESProject * project, const gchar * id,
690 GType extractable_type)
692 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
693 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
697 id = g_type_name (extractable_type);
699 if (g_hash_table_lookup (project->priv->assets, id) ||
700 g_hash_table_lookup (project->priv->loading_assets, id) ||
701 g_hash_table_lookup (project->priv->loaded_with_error, id))
704 /* TODO Add a GCancellable somewhere in our API */
705 ges_asset_request_async (extractable_type, id, NULL,
706 (GAsyncReadyCallback) new_asset_cb, project);
707 ges_project_add_loading_asset (project, extractable_type, id);
713 * ges_project_create_asset_sync:
714 * @project: A #GESProject
715 * @id: (allow-none): The id of the asset to create and add to @project
716 * @extractable_type: The #GType of the asset to create
717 * @error: A #GError to be set in case of error
719 * Create and add a #GESAsset to @project. You should connect to the
720 * "asset-added" signal to get the asset when it finally gets added to
723 * Returns: The newly created #GESAsset
726 ges_project_create_asset_sync (GESProject * project, const gchar * id,
727 GType extractable_type, GError ** error)
730 gchar *possible_id = NULL;
731 gboolean retry = TRUE;
733 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
734 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
738 id = g_type_name (extractable_type);
740 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
742 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
743 g_hash_table_lookup (project->priv->loaded_with_error, id))
746 /* TODO Add a GCancellable somewhere in our API */
749 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
750 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
752 asset = ges_asset_request (extractable_type, id, error);
759 g_free (possible_id);
760 ges_uri_assets_validate_uri (id);
767 tmpasset = ges_asset_cache_lookup (extractable_type, id);
768 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
770 if (possible_id == NULL)
773 g_clear_error (error);
781 ges_project_add_asset (project, asset);
787 * ges_project_add_asset:
788 * @project: A #GESProject
789 * @asset: (transfer none): A #GESAsset to add to @project
791 * Adds a #Asset to @project, the project will keep a reference on
794 * Returns: %TRUE if the asset could be added %FALSE it was already
798 ges_project_add_asset (GESProject * project, GESAsset * asset)
800 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
802 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
805 g_hash_table_insert (project->priv->assets,
806 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
808 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
809 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
810 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
816 * ges_project_remove_asset:
817 * @project: A #GESProject
818 * @asset: (transfer none): A #GESAsset to remove from @project
820 * remove a @asset to from @project.
822 * Returns: %TRUE if the asset could be removed %FALSE otherwise
825 ges_project_remove_asset (GESProject * project, GESAsset * asset)
829 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
831 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
832 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
838 * ges_project_get_asset:
839 * @project: A #GESProject
840 * @id: The id of the asset to retrieve
841 * @extractable_type: The extractable_type of the asset
842 * to retrieve from @object
844 * Returns: (transfer full) (allow-none): The #GESAsset with
845 * @id or %NULL if no asset with @id as an ID
848 ges_project_get_asset (GESProject * project, const gchar * id,
849 GType extractable_type)
853 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
854 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
857 asset = g_hash_table_lookup (project->priv->assets, id);
860 return gst_object_ref (asset);
866 * ges_project_list_assets:
867 * @project: A #GESProject
868 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
871 * List all @asset contained in @project filtering per extractable_type
872 * as defined by @filter. It copies the asset and thus will not be updated
875 * Returns: (transfer full) (element-type GESAsset): The list of
876 * #GESAsset the object contains
879 ges_project_list_assets (GESProject * project, GType filter)
885 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
887 g_hash_table_iter_init (&iter, project->priv->assets);
888 while (g_hash_table_iter_next (&iter, &key, &value)) {
889 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
891 ret = g_list_append (ret, gst_object_ref (value));
899 * @project: A #GESProject to save
900 * @timeline: The #GESTimeline to save, it must have been extracted from @project
901 * @uri: The uri where to save @project and @timeline
902 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
903 * will try to save in the same format as the one from which the timeline as been loaded
904 * or default to the formatter with highest rank
905 * @overwrite: %TRUE to overwrite file if it exists
906 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
908 * Save the timeline of @project to @uri. You should make sure that @timeline
909 * is one of the timelines that have been extracted from @project
910 * (using ges_asset_extract (@project);)
912 * Returns: %TRUE if the project could be save, %FALSE otherwize
915 ges_project_save (GESProject * project, GESTimeline * timeline,
916 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
921 GESFormatter *formatter = NULL;
923 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
924 g_return_val_if_fail (formatter_asset == NULL ||
925 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
926 GES_TYPE_FORMATTER), FALSE);
927 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
929 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
930 if (tl_asset == NULL && project->priv->uri == NULL) {
931 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
934 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
935 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
939 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
940 " we have no uri set, so setting ourself as asset", timeline);
942 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
943 } else if (tl_asset != GES_ASSET (project)) {
944 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
945 " not created by this project can not save", timeline);
951 if (formatter_asset == NULL)
952 formatter_asset = gst_object_ref (ges_formatter_get_default ());
954 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
955 if (formatter == NULL) {
956 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
957 formatter_asset, ges_asset_get_id (formatter_asset),
958 (error && *error) ? (*error)->message : "Unknown Error");
964 ges_project_add_formatter (project, formatter);
965 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
966 if (ret && project->priv->uri == NULL)
967 ges_project_set_uri (project, uri);
971 gst_object_unref (formatter_asset);
972 ges_project_remove_formatter (project, formatter);
979 * @uri: (allow-none): The uri to be set after creating the project.
981 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
982 * if @uri is not valid or %NULL, the uri of the project will then be set
983 * the first time you save the project. If you then save the project to
984 * other locations, it will never be updated again and the first valid URI is
985 * the URI it will keep refering to.
987 * Returns: A newly created #GESProject
990 ges_project_new (const gchar * uri)
992 gchar *id = (gchar *) uri;
996 id = g_strdup_printf ("project-%i", nb_projects++);
998 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
1001 ges_project_set_uri (project, uri);
1011 * @project: A #GESProject that has an @uri set already
1012 * @timeline: A blank timeline to load @project into
1013 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1015 * Loads @project into @timeline
1017 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1020 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1022 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1023 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1024 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1025 g_return_val_if_fail (
1026 (ges_extractable_get_asset (GES_EXTRACTABLE (timeline)) == NULL), FALSE);
1028 if (!_load_project (project, timeline, error))
1031 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1037 * ges_project_get_uri:
1038 * @project: A #GESProject
1040 * Retrieve the uri that is currently set on @project
1042 * Returns: The uri that is set on @project
1045 ges_project_get_uri (GESProject * project)
1047 GESProjectPrivate *priv;
1049 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1051 priv = project->priv;
1053 return g_strdup (priv->uri);
1058 * ges_project_add_encoding_profile:
1059 * @project: A #GESProject
1060 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1061 * the same name already exists, it will be replaced
1063 * Adds @profile to the project. It lets you save in what format
1064 * the project has been renders and keep a reference to those formats.
1065 * Also, those formats will be saves to the project file when possible.
1067 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1070 ges_project_add_encoding_profile (GESProject * project,
1071 GstEncodingProfile * profile)
1074 GESProjectPrivate *priv;
1076 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1077 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1079 priv = project->priv;
1080 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1081 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1083 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1084 gst_encoding_profile_get_name (profile)) == 0) {
1085 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1086 gst_encoding_profile_get_name (profile));
1088 gst_object_unref (tmp->data);
1089 tmp->data = gst_object_ref (profile);
1094 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1095 gst_object_ref (profile));
1101 * ges_project_list_encoding_profiles:
1102 * @project: A #GESProject
1104 * Lists the encoding profile that have been set to @project. The first one
1105 * is the latest added.
1107 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1108 * list of #GstEncodingProfile used in @project
1111 ges_project_list_encoding_profiles (GESProject * project)
1113 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1115 return project->priv->encoding_profiles;
1119 * ges_project_get_loading_assets:
1120 * @project: A #GESProject
1122 * Get the assets that are being loaded
1124 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1125 * that will be added to @project. Note that those Asset are *not* loaded yet,
1126 * and thus can not be used
1129 ges_project_get_loading_assets (GESProject * project)
1131 GHashTableIter iter;
1132 gpointer key, value;
1136 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1138 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1139 while (g_hash_table_iter_next (&iter, &key, &value))
1140 ret = g_list_prepend (ret, gst_object_ref (value));