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;
92 G_DEFINE_TYPE_WITH_PRIVATE (GESProject, ges_project, GES_TYPE_ASSET);
94 static guint _signals[LAST_SIGNAL] = { 0 };
96 static guint nb_projects = 0;
105 static GParamSpec *_properties[LAST_SIGNAL] = { 0 };
108 _emit_loaded_in_idle (EmitLoadedInIdle * data)
110 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
112 gst_object_unref (data->project);
113 gst_object_unref (data->timeline);
114 g_slice_free (EmitLoadedInIdle, data);
120 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
122 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
124 ges_formatter_set_project (formatter, project);
125 priv->formatters = g_list_append (priv->formatters, formatter);
127 gst_object_ref_sink (formatter);
131 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
134 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
136 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
137 if (tmp->data == formatter) {
138 gst_object_unref (formatter);
139 priv->formatters = g_list_delete_link (priv->formatters, tmp);
147 ges_project_set_uri (GESProject * project, const gchar * uri)
149 GESProjectPrivate *priv;
151 g_return_if_fail (GES_IS_PROJECT (project));
153 priv = project->priv;
155 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
161 GST_LOG_OBJECT (project, "Uri should not be NULL");
165 priv->uri = g_strdup (uri);
167 /* We use that URI as ID */
168 ges_asset_set_id (GES_ASSET (project), uri);
174 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
177 GESProjectPrivate *priv;
178 GESFormatter *formatter;
180 priv = GES_PROJECT (project)->priv;
182 if (priv->uri == NULL) {
183 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
185 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
186 " as no URI set yet", GST_OBJECT_NAME (timeline),
187 ges_asset_get_id (GES_ASSET (project)));
189 data->timeline = gst_object_ref (timeline);
190 data->project = gst_object_ref (project);
192 /* Make sure the signal is emitted after the functions ends */
193 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
197 if (priv->formatter_asset == NULL)
198 priv->formatter_asset = _find_formatter_asset_for_id (priv->uri);
200 if (priv->formatter_asset == NULL) {
201 lerr = g_error_new (GES_ERROR, 0, "Could not find a suitable formatter");
205 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
207 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
213 ges_project_add_formatter (GES_PROJECT (project), formatter);
214 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
216 GST_WARNING_OBJECT (project, "Could not load the timeline,"
217 " returning: %s", lerr->message);
225 g_propagate_error (error, lerr);
230 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
231 const GValue * handler_return, gpointer data)
233 const gchar *ret = g_value_get_string (handler_return);
236 if (!gst_uri_is_valid (ret)) {
237 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
241 g_value_set_string (return_accu, ret);
248 /* GESAsset vmethod implementation */
249 static GESExtractable *
250 ges_project_extract (GESAsset * project, GError ** error)
252 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
254 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
255 if (_load_project (GES_PROJECT (project), timeline, error))
256 return GES_EXTRACTABLE (timeline);
258 gst_object_unref (timeline);
263 _add_media_new_paths_recursing (const gchar * value)
266 GFileEnumerator *fenum;
267 GFile *file = g_file_new_for_uri (value);
269 if (!(fenum = g_file_enumerate_children (file,
270 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
271 GST_INFO ("%s is not a folder", value);
276 GST_INFO ("Adding folder: %s", value);
277 g_ptr_array_add (new_paths, g_strdup (value));
278 info = g_file_enumerator_next_file (fenum, NULL, NULL);
279 while (info != NULL) {
280 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
281 GFile *f = g_file_enumerator_get_child (fenum, info);
282 gchar *uri = g_file_get_uri (f);
284 _add_media_new_paths_recursing (uri);
285 gst_object_unref (f);
288 g_object_unref (info);
289 info = g_file_enumerator_next_file (fenum, NULL, NULL);
293 gst_object_unref (file);
295 gst_object_unref (fenum);
299 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
301 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
303 if (new_paths == NULL)
304 new_paths = g_ptr_array_new_with_free_func (g_free);
307 _add_media_new_paths_recursing (uri);
309 g_ptr_array_add (new_paths, g_strdup (uri));
315 ges_missing_uri_default (GESProject * self, GError * error,
316 GESAsset * wrong_asset)
319 const gchar *old_uri = ges_asset_get_id (wrong_asset);
320 gchar *new_id = NULL;
322 if (ges_asset_request_id_update (wrong_asset, &new_id, error) && new_id) {
323 GST_INFO_OBJECT (self, "Returned guessed new ID: %s", new_id);
328 if (new_paths == NULL)
331 if (tried_uris == NULL)
332 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
334 for (i = 0; i < new_paths->len; i++) {
335 gchar *basename, *res;
337 basename = g_path_get_basename (old_uri);
338 res = g_build_filename (new_paths->pdata[i], basename, NULL);
341 if (g_strcmp0 (old_uri, res) == 0) {
342 g_hash_table_add (tried_uris, res);
343 } else if (g_hash_table_lookup (tried_uris, res)) {
344 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
347 g_hash_table_add (tried_uris, g_strdup (res));
348 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
357 ges_uri_asset_try_update_id (GError * error, GESAsset * wrong_asset)
359 return ges_missing_uri_default (NULL, error, wrong_asset);
363 ges_uri_assets_validate_uri (const gchar * nid)
366 g_hash_table_remove (tried_uris, nid);
369 /* GObject vmethod implementation */
371 _dispose (GObject * object)
374 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
377 g_hash_table_unref (priv->assets);
378 if (priv->loading_assets)
379 g_hash_table_unref (priv->loading_assets);
380 if (priv->loaded_with_error)
381 g_hash_table_unref (priv->loaded_with_error);
382 if (priv->formatter_asset)
383 gst_object_unref (priv->formatter_asset);
385 for (tmp = priv->formatters; tmp; tmp = tmp->next)
386 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
388 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
392 _finalize (GObject * object)
394 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
398 g_list_free_full (priv->encoding_profiles, g_object_unref);
400 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
404 _get_property (GESProject * project, guint property_id,
405 GValue * value, GParamSpec * pspec)
407 GESProjectPrivate *priv = project->priv;
409 switch (property_id) {
411 g_value_set_string (value, priv->uri);
414 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
419 _set_property (GESProject * project, guint property_id,
420 const GValue * value, GParamSpec * pspec)
422 switch (property_id) {
424 project->priv->uri = g_value_dup_string (value);
427 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
432 ges_project_class_init (GESProjectClass * klass)
434 GObjectClass *object_class = G_OBJECT_CLASS (klass);
436 klass->asset_added = NULL;
437 klass->missing_uri = ges_missing_uri_default;
438 klass->loading_error = NULL;
439 klass->asset_removed = NULL;
440 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
441 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
446 * The location of the project to use.
448 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
449 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
451 g_object_class_install_properties (object_class, PROP_LAST, _properties);
454 * GESProject::asset-added:
455 * @project: the #GESProject
456 * @asset: The #GESAsset that has been added to @project
458 _signals[ASSET_ADDED_SIGNAL] =
459 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
460 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
461 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
464 * GESProject::asset-loading:
465 * @project: the #GESProject
466 * @asset: The #GESAsset that started loading
470 _signals[ASSET_LOADING_SIGNAL] =
471 g_signal_new ("asset-loading", G_TYPE_FROM_CLASS (klass),
472 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_loading),
473 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
476 * GESProject::asset-removed:
477 * @project: the #GESProject
478 * @asset: The #GESAsset that has been removed from @project
480 _signals[ASSET_REMOVED_SIGNAL] =
481 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
482 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
483 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
486 * GESProject::loaded:
487 * @project: the #GESProject that is done loading a project.
488 * @timeline: The #GESTimeline that complete loading
490 _signals[LOADED_SIGNAL] =
491 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
492 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
493 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
494 1, GES_TYPE_TIMELINE);
497 * GESProject::missing-uri:
498 * @project: the #GESProject reporting that a file has moved
499 * @error: The error that happened
500 * @wrong_asset: The asset with the wrong ID, you should us it and its content
501 * only to find out what the new location is.
505 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
507 * return g_strdup ("file:///the/new/uri.ogg");
511 * main (int argc, gchar ** argv)
513 * GESTimeline *timeline;
514 * GESProject *project = ges_project_new ("file:///some/uri.xges");
516 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
517 * timeline = ges_asset_extract (GES_ASSET (project));
521 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
523 _signals[MISSING_URI_SIGNAL] =
524 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
525 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
526 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
527 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
530 * GESProject::error-loading-asset:
531 * @project: the #GESProject on which a problem happend when creted a #GESAsset
532 * @error: The #GError defining the error that occured, might be %NULL
533 * @id: The @id of the asset that failed loading
534 * @extractable_type: The @extractable_type of the asset that
537 * Informs you that a #GESAsset could not be created. In case of
538 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
539 * #GST_CORE_ERROR_MISSING_PLUGIN
541 _signals[ERROR_LOADING_ASSET] =
542 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
543 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
544 NULL, NULL, g_cclosure_marshal_generic,
545 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
547 object_class->dispose = _dispose;
548 object_class->finalize = _finalize;
550 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
554 ges_project_init (GESProject * project)
556 GESProjectPrivate *priv = project->priv =
557 ges_project_get_instance_private (project);
560 priv->formatters = NULL;
561 priv->formatter_asset = NULL;
562 priv->encoding_profiles = NULL;
563 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
564 g_free, gst_object_unref);
565 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
566 g_free, gst_object_unref);
567 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
572 _send_error_loading_asset (GESProject * project, GESAsset * asset,
575 const gchar *id = ges_asset_get_id (asset);
577 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
578 g_hash_table_remove (project->priv->loading_assets, id);
579 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
580 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
581 ges_asset_get_extractable_type (asset));
585 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
588 gchar *new_id = NULL;
591 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
592 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
593 g_return_val_if_fail (error, NULL);
595 id = ges_asset_get_id (asset);
596 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
597 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
598 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
599 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
601 _send_error_loading_asset (project, asset, error);
606 /* Always send the MISSING_URI signal if requesting new ID is possible
607 * so that subclasses of GESProject are aware of the missing-uri */
608 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
612 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
613 if (!ges_asset_try_proxy (asset, new_id)) {
618 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
621 g_hash_table_remove (project->priv->loading_assets, id);
624 _send_error_loading_asset (project, asset, error);
631 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
633 GError *error = NULL;
634 gchar *possible_id = NULL;
635 GESAsset *asset = ges_asset_request_finish (res, &error);
638 possible_id = ges_project_try_updating_id (project, source, error);
640 if (possible_id == NULL)
643 ges_project_create_asset (project, possible_id,
644 ges_asset_get_extractable_type (source));
646 g_free (possible_id);
647 g_error_free (error);
651 ges_asset_set_proxy (NULL, asset);
652 ges_project_add_asset (project, asset);
654 gst_object_unref (asset);
658 * ges_project_set_loaded:
659 * @project: The #GESProject from which to emit the "project-loaded" signal
661 * Emits the "loaded" signal. This method should be called by sublasses when
662 * the project is fully loaded.
664 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
667 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
669 GST_INFO_OBJECT (project, "Emit project loaded");
670 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
671 timeline_fill_gaps (formatter->timeline);
673 ges_timeline_commit (formatter->timeline);
676 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
678 /* We are now done with that formatter */
679 ges_project_remove_formatter (project, formatter);
684 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
689 if ((asset = ges_asset_cache_lookup (extractable_type, id))) {
690 if (g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
691 gst_object_ref (asset)))
692 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
696 /**************************************
698 * API Implementation *
700 **************************************/
703 * ges_project_create_asset:
704 * @project: A #GESProject
705 * @id: (allow-none): The id of the asset to create and add to @project
706 * @extractable_type: The #GType of the asset to create
708 * Create and add a #GESAsset to @project. You should connect to the
709 * "asset-added" signal to get the asset when it finally gets added to
712 * Returns: %TRUE if the asset started to be added %FALSE it was already
716 ges_project_create_asset (GESProject * project, const gchar * id,
717 GType extractable_type)
719 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
720 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
724 id = g_type_name (extractable_type);
726 if (g_hash_table_lookup (project->priv->assets, id) ||
727 g_hash_table_lookup (project->priv->loading_assets, id) ||
728 g_hash_table_lookup (project->priv->loaded_with_error, id))
731 /* TODO Add a GCancellable somewhere in our API */
732 ges_asset_request_async (extractable_type, id, NULL,
733 (GAsyncReadyCallback) new_asset_cb, project);
734 ges_project_add_loading_asset (project, extractable_type, id);
740 * ges_project_create_asset_sync:
741 * @project: A #GESProject
742 * @id: (allow-none): The id of the asset to create and add to @project
743 * @extractable_type: The #GType of the asset to create
744 * @error: A #GError to be set in case of error
746 * Create and add a #GESAsset to @project. You should connect to the
747 * "asset-added" signal to get the asset when it finally gets added to
750 * Returns: (transfer full) (nullable): The newly created #GESAsset or %NULL.
753 ges_project_create_asset_sync (GESProject * project, const gchar * id,
754 GType extractable_type, GError ** error)
757 gchar *possible_id = NULL;
758 gboolean retry = TRUE;
760 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
761 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
765 id = g_type_name (extractable_type);
767 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
769 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
770 g_hash_table_lookup (project->priv->loaded_with_error, id))
773 /* TODO Add a GCancellable somewhere in our API */
776 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
777 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
779 asset = ges_asset_request (extractable_type, id, error);
785 if ((!g_hash_table_lookup (project->priv->assets,
786 ges_asset_get_id (asset))))
787 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
790 g_free (possible_id);
791 ges_uri_assets_validate_uri (id);
798 tmpasset = ges_asset_cache_lookup (extractable_type, id);
799 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
801 if (possible_id == NULL) {
802 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, tmpasset);
803 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, *error, id,
809 g_clear_error (error);
815 if (!ges_asset_get_proxy_target (asset))
816 ges_asset_set_proxy (NULL, asset);
818 ges_project_add_asset (project, asset);
824 * ges_project_add_asset:
825 * @project: A #GESProject
826 * @asset: (transfer none): A #GESAsset to add to @project
828 * Adds a #Asset to @project, the project will keep a reference on
831 * Returns: %TRUE if the asset could be added %FALSE it was already
835 ges_project_add_asset (GESProject * project, GESAsset * asset)
837 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
839 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
842 g_hash_table_insert (project->priv->assets,
843 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
845 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
846 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
847 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
853 * ges_project_remove_asset:
854 * @project: A #GESProject
855 * @asset: (transfer none): A #GESAsset to remove from @project
857 * remove a @asset to from @project.
859 * Returns: %TRUE if the asset could be removed %FALSE otherwise
862 ges_project_remove_asset (GESProject * project, GESAsset * asset)
866 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
868 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
869 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
875 * ges_project_get_asset:
876 * @project: A #GESProject
877 * @id: The id of the asset to retrieve
878 * @extractable_type: The extractable_type of the asset
879 * to retrieve from @object
881 * Returns: (transfer full) (allow-none): The #GESAsset with
882 * @id or %NULL if no asset with @id as an ID
885 ges_project_get_asset (GESProject * project, const gchar * id,
886 GType extractable_type)
890 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
891 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
894 asset = g_hash_table_lookup (project->priv->assets, id);
897 return gst_object_ref (asset);
903 * ges_project_list_assets:
904 * @project: A #GESProject
905 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
908 * List all @asset contained in @project filtering per extractable_type
909 * as defined by @filter. It copies the asset and thus will not be updated
912 * Returns: (transfer full) (element-type GESAsset): The list of
913 * #GESAsset the object contains
916 ges_project_list_assets (GESProject * project, GType filter)
922 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
924 g_hash_table_iter_init (&iter, project->priv->assets);
925 while (g_hash_table_iter_next (&iter, &key, &value)) {
926 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
928 ret = g_list_append (ret, gst_object_ref (value));
936 * @project: A #GESProject to save
937 * @timeline: The #GESTimeline to save, it must have been extracted from @project
938 * @uri: The uri where to save @project and @timeline
939 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
940 * will try to save in the same format as the one from which the timeline as been loaded
941 * or default to the formatter with highest rank
942 * @overwrite: %TRUE to overwrite file if it exists
943 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
945 * Save the timeline of @project to @uri. You should make sure that @timeline
946 * is one of the timelines that have been extracted from @project
947 * (using ges_asset_extract (@project);)
949 * Returns: %TRUE if the project could be save, %FALSE otherwize
952 ges_project_save (GESProject * project, GESTimeline * timeline,
953 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
958 GESFormatter *formatter = NULL;
960 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
961 g_return_val_if_fail (formatter_asset == NULL ||
962 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
963 GES_TYPE_FORMATTER), FALSE);
964 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
966 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
967 if (tl_asset == NULL && project->priv->uri == NULL) {
968 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
971 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
972 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
976 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
977 " we have no uri set, so setting ourself as asset", timeline);
979 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
980 } else if (tl_asset != GES_ASSET (project)) {
981 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
982 " not created by this project can not save", timeline);
988 if (formatter_asset == NULL)
989 formatter_asset = gst_object_ref (ges_formatter_get_default ());
991 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
992 if (formatter == NULL) {
993 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
994 formatter_asset, ges_asset_get_id (formatter_asset),
995 (error && *error) ? (*error)->message : "Unknown Error");
1001 ges_project_add_formatter (project, formatter);
1002 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
1003 if (ret && project->priv->uri == NULL)
1004 ges_project_set_uri (project, uri);
1007 if (formatter_asset)
1008 gst_object_unref (formatter_asset);
1009 ges_project_remove_formatter (project, formatter);
1016 * @uri: (allow-none): The uri to be set after creating the project.
1018 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
1019 * if @uri is not valid or %NULL, the uri of the project will then be set
1020 * the first time you save the project. If you then save the project to
1021 * other locations, it will never be updated again and the first valid URI is
1022 * the URI it will keep refering to.
1024 * Returns: A newly created #GESProject
1027 ges_project_new (const gchar * uri)
1029 gchar *id = (gchar *) uri;
1030 GESProject *project;
1033 id = g_strdup_printf ("project-%i", nb_projects++);
1035 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
1038 ges_project_set_uri (project, uri);
1048 * @project: A #GESProject that has an @uri set already
1049 * @timeline: A blank timeline to load @project into
1050 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1052 * Loads @project into @timeline
1054 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1057 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1059 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1060 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1061 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1062 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1064 if (!_load_project (project, timeline, error))
1067 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1073 * ges_project_get_uri:
1074 * @project: A #GESProject
1076 * Retrieve the uri that is currently set on @project
1078 * Returns: (transfer full) (nullable): a newly allocated string representing uri.
1081 ges_project_get_uri (GESProject * project)
1083 GESProjectPrivate *priv;
1085 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1087 priv = project->priv;
1089 return g_strdup (priv->uri);
1094 * ges_project_add_encoding_profile:
1095 * @project: A #GESProject
1096 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1097 * the same name already exists, it will be replaced
1099 * Adds @profile to the project. It lets you save in what format
1100 * the project has been renders and keep a reference to those formats.
1101 * Also, those formats will be saves to the project file when possible.
1103 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1106 ges_project_add_encoding_profile (GESProject * project,
1107 GstEncodingProfile * profile)
1110 GESProjectPrivate *priv;
1112 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1113 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1115 priv = project->priv;
1116 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1117 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1119 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1120 gst_encoding_profile_get_name (profile)) == 0) {
1121 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1122 gst_encoding_profile_get_name (profile));
1124 gst_object_unref (tmp->data);
1125 tmp->data = gst_object_ref (profile);
1130 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1131 gst_object_ref (profile));
1137 * ges_project_list_encoding_profiles:
1138 * @project: A #GESProject
1140 * Lists the encoding profile that have been set to @project. The first one
1141 * is the latest added.
1143 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1144 * list of #GstEncodingProfile used in @project
1147 ges_project_list_encoding_profiles (GESProject * project)
1149 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1151 return project->priv->encoding_profiles;
1155 * ges_project_get_loading_assets:
1156 * @project: A #GESProject
1158 * Get the assets that are being loaded
1160 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1161 * that will be added to @project. Note that those Asset are *not* loaded yet,
1162 * and thus can not be used
1165 ges_project_get_loading_assets (GESProject * project)
1167 GHashTableIter iter;
1168 gpointer key, value;
1172 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1174 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1175 while (g_hash_table_iter_next (&iter, &key, &value))
1176 ret = g_list_prepend (ret, gst_object_ref (value));