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.
23 * @short_description: A GESAsset that is used to manage projects
25 * The #GESProject is used to control a set of #GESAsset and is a
26 * #GESAsset with `GES_TYPE_TIMELINE` as @extractable_type itself. That
27 * means that you can extract #GESTimeline from a project as followed:
30 * GESProject *project;
31 * GESTimeline *timeline;
33 * project = ges_project_new ("file:///path/to/a/valid/project/uri");
35 * // Here you can connect to the various signal to get more infos about
36 * // what is happening and recover from errors if possible
39 * timeline = ges_asset_extract (GES_ASSET (project));
42 * The #GESProject class offers a higher level API to handle #GESAsset-s.
43 * It lets you request new asset, and it informs you about new assets through
44 * a set of signals. Also it handles problem such as missing files/missing
45 * #GstElement and lets you try to recover from those.
52 #include "ges-internal.h"
54 static GPtrArray *new_paths = NULL;
55 static GHashTable *tried_uris = NULL;
57 /* TODO We should rely on both extractable_type and @id to identify
58 * a Asset, not only @id
60 struct _GESProjectPrivate
63 /* Set of asset ID being loaded */
64 GHashTable *loading_assets;
65 GHashTable *loaded_with_error;
66 GESAsset *formatter_asset;
72 GList *encoding_profiles;
75 typedef struct EmitLoadedInIdle
78 GESTimeline *timeline;
93 G_DEFINE_TYPE_WITH_PRIVATE (GESProject, ges_project, GES_TYPE_ASSET);
95 static guint _signals[LAST_SIGNAL] = { 0 };
97 static guint nb_projects = 0;
106 static GParamSpec *_properties[LAST_SIGNAL] = { 0 };
109 _emit_loaded_in_idle (EmitLoadedInIdle * data)
111 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
113 gst_object_unref (data->project);
114 gst_object_unref (data->timeline);
115 g_slice_free (EmitLoadedInIdle, data);
121 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
123 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
125 ges_formatter_set_project (formatter, project);
126 priv->formatters = g_list_append (priv->formatters, formatter);
128 gst_object_ref_sink (formatter);
132 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
135 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
137 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
138 if (tmp->data == formatter) {
139 gst_object_unref (formatter);
140 priv->formatters = g_list_delete_link (priv->formatters, tmp);
148 ges_project_set_uri (GESProject * project, const gchar * uri)
150 GESProjectPrivate *priv;
152 g_return_if_fail (GES_IS_PROJECT (project));
154 priv = project->priv;
156 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
162 GST_LOG_OBJECT (project, "Uri should not be NULL");
166 priv->uri = g_strdup (uri);
168 /* We use that URI as ID */
169 ges_asset_set_id (GES_ASSET (project), uri);
175 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
178 GESProjectPrivate *priv;
179 GESFormatter *formatter;
181 priv = GES_PROJECT (project)->priv;
183 g_signal_emit (project, _signals[LOADING_SIGNAL], 0, timeline);
184 if (priv->uri == NULL) {
185 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
187 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
188 " as no URI set yet", GST_OBJECT_NAME (timeline),
189 ges_asset_get_id (GES_ASSET (project)));
191 data->timeline = gst_object_ref (timeline);
192 data->project = gst_object_ref (project);
194 /* Make sure the signal is emitted after the functions ends */
195 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
199 if (priv->formatter_asset == NULL)
200 priv->formatter_asset = _find_formatter_asset_for_id (priv->uri);
202 if (priv->formatter_asset == NULL) {
203 lerr = g_error_new (GES_ERROR, 0, "Could not find a suitable formatter");
207 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
209 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
215 ges_project_add_formatter (GES_PROJECT (project), formatter);
216 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
218 GST_WARNING_OBJECT (project, "Could not load the timeline,"
219 " returning: %s", lerr->message);
227 g_propagate_error (error, lerr);
232 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
233 const GValue * handler_return, gpointer data)
235 const gchar *ret = g_value_get_string (handler_return);
238 if (!gst_uri_is_valid (ret)) {
239 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
243 g_value_set_string (return_accu, ret);
250 /* GESAsset vmethod implementation */
251 static GESExtractable *
252 ges_project_extract (GESAsset * project, GError ** error)
254 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
256 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
257 if (_load_project (GES_PROJECT (project), timeline, error))
258 return GES_EXTRACTABLE (timeline);
260 gst_object_unref (timeline);
265 _add_media_new_paths_recursing (const gchar * value)
268 GFileEnumerator *fenum;
269 GFile *file = g_file_new_for_uri (value);
271 if (!(fenum = g_file_enumerate_children (file,
272 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
273 GST_INFO ("%s is not a folder", value);
278 GST_INFO ("Adding folder: %s", value);
279 g_ptr_array_add (new_paths, g_strdup (value));
280 info = g_file_enumerator_next_file (fenum, NULL, NULL);
281 while (info != NULL) {
282 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
283 GFile *f = g_file_enumerator_get_child (fenum, info);
284 gchar *uri = g_file_get_uri (f);
286 _add_media_new_paths_recursing (uri);
287 gst_object_unref (f);
290 g_object_unref (info);
291 info = g_file_enumerator_next_file (fenum, NULL, NULL);
295 gst_object_unref (file);
297 gst_object_unref (fenum);
301 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
303 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
305 if (new_paths == NULL)
306 new_paths = g_ptr_array_new_with_free_func (g_free);
309 _add_media_new_paths_recursing (uri);
311 g_ptr_array_add (new_paths, g_strdup (uri));
317 ges_missing_uri_default (GESProject * self, GError * error,
318 GESAsset * wrong_asset)
321 const gchar *old_uri = ges_asset_get_id (wrong_asset);
322 gchar *new_id = NULL;
324 if (ges_asset_request_id_update (wrong_asset, &new_id, error) && new_id) {
325 GST_INFO_OBJECT (self, "Returned guessed new ID: %s", new_id);
330 if (new_paths == NULL)
333 if (tried_uris == NULL)
334 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
336 for (i = 0; i < new_paths->len; i++) {
337 gchar *basename, *res;
339 basename = g_path_get_basename (old_uri);
340 res = g_build_filename (new_paths->pdata[i], basename, NULL);
343 if (g_strcmp0 (old_uri, res) == 0) {
344 g_hash_table_add (tried_uris, res);
345 } else if (g_hash_table_lookup (tried_uris, res)) {
346 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
349 g_hash_table_add (tried_uris, g_strdup (res));
350 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
359 ges_uri_asset_try_update_id (GError * error, GESAsset * wrong_asset)
361 return ges_missing_uri_default (NULL, error, wrong_asset);
365 ges_uri_assets_validate_uri (const gchar * nid)
368 g_hash_table_remove (tried_uris, nid);
371 /* GObject vmethod implementation */
373 _dispose (GObject * object)
375 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
378 g_hash_table_unref (priv->assets);
379 if (priv->loading_assets)
380 g_hash_table_unref (priv->loading_assets);
381 if (priv->loaded_with_error)
382 g_hash_table_unref (priv->loaded_with_error);
383 if (priv->formatter_asset)
384 gst_object_unref (priv->formatter_asset);
386 while (priv->formatters)
387 ges_project_remove_formatter (GES_PROJECT (object), priv->formatters->data);
389 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
393 _finalize (GObject * object)
395 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
399 g_list_free_full (priv->encoding_profiles, g_object_unref);
401 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
405 _get_property (GESProject * project, guint property_id,
406 GValue * value, GParamSpec * pspec)
408 GESProjectPrivate *priv = project->priv;
410 switch (property_id) {
412 g_value_set_string (value, priv->uri);
415 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
420 _set_property (GESProject * project, guint property_id,
421 const GValue * value, GParamSpec * pspec)
423 switch (property_id) {
425 project->priv->uri = g_value_dup_string (value);
428 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
433 ges_project_class_init (GESProjectClass * klass)
435 GObjectClass *object_class = G_OBJECT_CLASS (klass);
437 klass->asset_added = NULL;
438 klass->missing_uri = ges_missing_uri_default;
439 klass->loading_error = NULL;
440 klass->asset_removed = NULL;
441 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
442 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
447 * The location of the project to use.
449 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
450 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
452 g_object_class_install_properties (object_class, PROP_LAST, _properties);
455 * GESProject::asset-added:
456 * @project: the #GESProject
457 * @asset: The #GESAsset that has been added to @project
459 _signals[ASSET_ADDED_SIGNAL] =
460 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
461 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
462 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
465 * GESProject::asset-loading:
466 * @project: the #GESProject
467 * @asset: The #GESAsset that started loading
471 _signals[ASSET_LOADING_SIGNAL] =
472 g_signal_new ("asset-loading", G_TYPE_FROM_CLASS (klass),
473 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_loading),
474 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
477 * GESProject::asset-removed:
478 * @project: the #GESProject
479 * @asset: The #GESAsset that has been removed from @project
481 _signals[ASSET_REMOVED_SIGNAL] =
482 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
483 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
484 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
487 * GESProject::loading:
488 * @project: the #GESProject that is starting to load a timeline
489 * @timeline: The #GESTimeline that started loading
493 _signals[LOADING_SIGNAL] =
494 g_signal_new ("loading", G_TYPE_FROM_CLASS (klass),
495 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loading),
496 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
497 1, GES_TYPE_TIMELINE);
500 * GESProject::loaded:
501 * @project: the #GESProject that is done loading a timeline.
502 * @timeline: The #GESTimeline that completed loading
504 _signals[LOADED_SIGNAL] =
505 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
506 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
507 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
508 1, GES_TYPE_TIMELINE);
511 * GESProject::missing-uri:
512 * @project: the #GESProject reporting that a file has moved
513 * @error: The error that happened
514 * @wrong_asset: The asset with the wrong ID, you should us it and its content
515 * only to find out what the new location is.
519 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
521 * return g_strdup ("file:///the/new/uri.ogg");
525 * main (int argc, gchar ** argv)
527 * GESTimeline *timeline;
528 * GESProject *project = ges_project_new ("file:///some/uri.xges");
530 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
531 * timeline = ges_asset_extract (GES_ASSET (project));
535 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
537 _signals[MISSING_URI_SIGNAL] =
538 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
539 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
540 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
541 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
544 * GESProject::error-loading-asset:
545 * @project: the #GESProject on which a problem happend when creted a #GESAsset
546 * @error: The #GError defining the error that occured, might be %NULL
547 * @id: The @id of the asset that failed loading
548 * @extractable_type: The @extractable_type of the asset that
551 * Informs you that a #GESAsset could not be created. In case of
552 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
553 * #GST_CORE_ERROR_MISSING_PLUGIN
555 _signals[ERROR_LOADING_ASSET] =
556 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
557 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
558 NULL, NULL, g_cclosure_marshal_generic,
559 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
561 object_class->dispose = _dispose;
562 object_class->finalize = _finalize;
564 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
568 ges_project_init (GESProject * project)
570 GESProjectPrivate *priv = project->priv =
571 ges_project_get_instance_private (project);
574 priv->formatters = NULL;
575 priv->formatter_asset = NULL;
576 priv->encoding_profiles = NULL;
577 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
578 g_free, gst_object_unref);
579 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
580 g_free, gst_object_unref);
581 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
586 _send_error_loading_asset (GESProject * project, GESAsset * asset,
589 const gchar *id = ges_asset_get_id (asset);
591 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
592 g_hash_table_remove (project->priv->loading_assets, id);
593 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
594 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
595 ges_asset_get_extractable_type (asset));
599 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
602 gchar *new_id = NULL;
605 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
606 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
607 g_return_val_if_fail (error, NULL);
609 id = ges_asset_get_id (asset);
610 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
611 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
612 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
613 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
615 _send_error_loading_asset (project, asset, error);
620 /* Always send the MISSING_URI signal if requesting new ID is possible
621 * so that subclasses of GESProject are aware of the missing-uri */
622 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
626 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
627 if (!ges_asset_try_proxy (asset, new_id)) {
632 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
635 g_hash_table_remove (project->priv->loading_assets, id);
638 _send_error_loading_asset (project, asset, error);
645 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
647 GError *error = NULL;
648 gchar *possible_id = NULL;
649 GESAsset *asset = ges_asset_request_finish (res, &error);
652 possible_id = ges_project_try_updating_id (project, source, error);
653 g_clear_error (&error);
655 if (possible_id == NULL)
658 ges_project_create_asset (project, possible_id,
659 ges_asset_get_extractable_type (source));
661 g_free (possible_id);
665 ges_asset_set_proxy (NULL, asset);
666 ges_project_add_asset (project, asset);
668 gst_object_unref (asset);
672 * ges_project_set_loaded:
673 * @project: The #GESProject from which to emit the "project-loaded" signal
675 * Emits the "loaded" signal. This method should be called by sublasses when
676 * the project is fully loaded.
678 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
681 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
683 GST_INFO_OBJECT (project, "Emit project loaded");
684 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
685 timeline_fill_gaps (formatter->timeline);
687 ges_timeline_commit (formatter->timeline);
690 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
692 /* We are now done with that formatter */
693 ges_project_remove_formatter (project, formatter);
698 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
703 if ((asset = ges_asset_cache_lookup (extractable_type, id))) {
704 if (g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
705 gst_object_ref (asset)))
706 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
710 /**************************************
712 * API Implementation *
714 **************************************/
717 * ges_project_create_asset:
718 * @project: A #GESProject
719 * @id: (allow-none): The id of the asset to create and add to @project
720 * @extractable_type: The #GType of the asset to create
722 * Create and add a #GESAsset to @project. You should connect to the
723 * "asset-added" signal to get the asset when it finally gets added to
726 * Returns: %TRUE if the asset started to be added %FALSE it was already
730 ges_project_create_asset (GESProject * project, const gchar * id,
731 GType extractable_type)
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 (g_hash_table_lookup (project->priv->assets, id) ||
741 g_hash_table_lookup (project->priv->loading_assets, id) ||
742 g_hash_table_lookup (project->priv->loaded_with_error, id))
745 /* TODO Add a GCancellable somewhere in our API */
746 ges_asset_request_async (extractable_type, id, NULL,
747 (GAsyncReadyCallback) new_asset_cb, project);
748 ges_project_add_loading_asset (project, extractable_type, id);
754 * ges_project_create_asset_sync:
755 * @project: A #GESProject
756 * @id: (allow-none): The id of the asset to create and add to @project
757 * @extractable_type: The #GType of the asset to create
758 * @error: A #GError to be set in case of error
760 * Create and add a #GESAsset to @project. You should connect to the
761 * "asset-added" signal to get the asset when it finally gets added to
764 * Returns: (transfer full) (nullable): The newly created #GESAsset or %NULL.
767 ges_project_create_asset_sync (GESProject * project, const gchar * id,
768 GType extractable_type, GError ** error)
771 gchar *possible_id = NULL;
772 gboolean retry = TRUE;
774 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
775 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
779 id = g_type_name (extractable_type);
781 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
783 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
784 g_hash_table_lookup (project->priv->loaded_with_error, id))
787 /* TODO Add a GCancellable somewhere in our API */
790 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
791 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
793 asset = ges_asset_request (extractable_type, id, error);
799 if ((!g_hash_table_lookup (project->priv->assets,
800 ges_asset_get_id (asset))))
801 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
804 g_free (possible_id);
805 ges_uri_assets_validate_uri (id);
812 tmpasset = ges_asset_cache_lookup (extractable_type, id);
813 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
815 if (possible_id == NULL) {
816 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, tmpasset);
817 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, *error, id,
823 g_clear_error (error);
829 if (!ges_asset_get_proxy_target (asset))
830 ges_asset_set_proxy (NULL, asset);
832 ges_project_add_asset (project, asset);
838 * ges_project_add_asset:
839 * @project: A #GESProject
840 * @asset: (transfer none): A #GESAsset to add to @project
842 * Adds a #GESAsset to @project, the project will keep a reference on
845 * Returns: %TRUE if the asset could be added %FALSE it was already
849 ges_project_add_asset (GESProject * project, GESAsset * asset)
851 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
853 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
856 g_hash_table_insert (project->priv->assets,
857 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
859 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
860 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
861 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
867 * ges_project_remove_asset:
868 * @project: A #GESProject
869 * @asset: (transfer none): A #GESAsset to remove from @project
871 * remove a @asset to from @project.
873 * Returns: %TRUE if the asset could be removed %FALSE otherwise
876 ges_project_remove_asset (GESProject * project, GESAsset * asset)
880 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
882 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
883 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
889 * ges_project_get_asset:
890 * @project: A #GESProject
891 * @id: The id of the asset to retrieve
892 * @extractable_type: The extractable_type of the asset
893 * to retrieve from @object
895 * Returns: (transfer full) (allow-none): The #GESAsset with
896 * @id or %NULL if no asset with @id as an ID
899 ges_project_get_asset (GESProject * project, const gchar * id,
900 GType extractable_type)
904 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
905 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
908 asset = g_hash_table_lookup (project->priv->assets, id);
911 return gst_object_ref (asset);
917 * ges_project_list_assets:
918 * @project: A #GESProject
919 * @filter: Type of assets to list, `GES_TYPE_EXTRACTABLE` will list
922 * List all @asset contained in @project filtering per extractable_type
923 * as defined by @filter. It copies the asset and thus will not be updated
926 * Returns: (transfer full) (element-type GESAsset): The list of
927 * #GESAsset the object contains
930 ges_project_list_assets (GESProject * project, GType filter)
936 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
938 g_hash_table_iter_init (&iter, project->priv->assets);
939 while (g_hash_table_iter_next (&iter, &key, &value)) {
940 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
942 ret = g_list_append (ret, gst_object_ref (value));
950 * @project: A #GESProject to save
951 * @timeline: The #GESTimeline to save, it must have been extracted from @project
952 * @uri: The uri where to save @project and @timeline
953 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
954 * will try to save in the same format as the one from which the timeline as been loaded
955 * or default to the formatter with highest rank
956 * @overwrite: %TRUE to overwrite file if it exists
957 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
959 * Save the timeline of @project to @uri. You should make sure that @timeline
960 * is one of the timelines that have been extracted from @project
961 * (using ges_asset_extract (@project);)
963 * Returns: %TRUE if the project could be save, %FALSE otherwize
966 ges_project_save (GESProject * project, GESTimeline * timeline,
967 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
972 GESFormatter *formatter = NULL;
974 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
975 g_return_val_if_fail (formatter_asset == NULL ||
976 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
977 GES_TYPE_FORMATTER), FALSE);
978 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
980 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
981 if (tl_asset == NULL && project->priv->uri == NULL) {
982 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
985 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
986 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
990 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
991 " we have no uri set, so setting ourself as asset", timeline);
993 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
994 } else if (tl_asset != GES_ASSET (project)) {
995 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
996 " not created by this project can not save", timeline);
1002 if (formatter_asset == NULL)
1003 formatter_asset = gst_object_ref (ges_formatter_get_default ());
1005 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
1006 if (formatter == NULL) {
1007 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
1008 formatter_asset, ges_asset_get_id (formatter_asset),
1009 (error && *error) ? (*error)->message : "Unknown Error");
1015 ges_project_add_formatter (project, formatter);
1016 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
1017 if (ret && project->priv->uri == NULL)
1018 ges_project_set_uri (project, uri);
1021 if (formatter_asset)
1022 gst_object_unref (formatter_asset);
1023 ges_project_remove_formatter (project, formatter);
1030 * @uri: (allow-none): The uri to be set after creating the project.
1032 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
1033 * if @uri is not valid or %NULL, the uri of the project will then be set
1034 * the first time you save the project. If you then save the project to
1035 * other locations, it will never be updated again and the first valid URI is
1036 * the URI it will keep refering to.
1038 * Returns: A newly created #GESProject
1041 ges_project_new (const gchar * uri)
1043 gchar *id = (gchar *) uri;
1044 GESProject *project;
1047 id = g_strdup_printf ("project-%i", nb_projects++);
1049 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
1052 ges_project_set_uri (project, uri);
1062 * @project: A #GESProject that has an @uri set already
1063 * @timeline: A blank timeline to load @project into
1064 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1066 * Loads @project into @timeline
1068 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1071 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1073 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1074 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1075 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1076 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1078 if (!_load_project (project, timeline, error))
1081 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1087 * ges_project_get_uri:
1088 * @project: A #GESProject
1090 * Retrieve the uri that is currently set on @project
1092 * Returns: (transfer full) (nullable): a newly allocated string representing uri.
1095 ges_project_get_uri (GESProject * project)
1097 GESProjectPrivate *priv;
1099 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1101 priv = project->priv;
1103 return g_strdup (priv->uri);
1108 * ges_project_add_encoding_profile:
1109 * @project: A #GESProject
1110 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1111 * the same name already exists, it will be replaced
1113 * Adds @profile to the project. It lets you save in what format
1114 * the project has been renders and keep a reference to those formats.
1115 * Also, those formats will be saves to the project file when possible.
1117 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1120 ges_project_add_encoding_profile (GESProject * project,
1121 GstEncodingProfile * profile)
1124 GESProjectPrivate *priv;
1126 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1127 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1129 priv = project->priv;
1130 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1131 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1133 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1134 gst_encoding_profile_get_name (profile)) == 0) {
1135 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1136 gst_encoding_profile_get_name (profile));
1138 gst_object_unref (tmp->data);
1139 tmp->data = gst_object_ref (profile);
1144 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1145 gst_object_ref (profile));
1151 * ges_project_list_encoding_profiles:
1152 * @project: A #GESProject
1154 * Lists the encoding profile that have been set to @project. The first one
1155 * is the latest added.
1157 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1158 * list of #GstEncodingProfile used in @project
1161 ges_project_list_encoding_profiles (GESProject * project)
1163 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1165 return project->priv->encoding_profiles;
1169 * ges_project_get_loading_assets:
1170 * @project: A #GESProject
1172 * Get the assets that are being loaded
1174 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1175 * that will be added to @project. Note that those Asset are *not* loaded yet,
1176 * and thus can not be used
1179 ges_project_get_loading_assets (GESProject * project)
1181 GHashTableIter iter;
1182 gpointer key, value;
1186 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1188 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1189 while (g_hash_table_iter_next (&iter, &key, &value))
1190 ret = g_list_prepend (ret, gst_object_ref (value));