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_assets_validate_uri (const gchar * nid)
360 g_hash_table_remove (tried_uris, nid);
363 /* GObject vmethod implementation */
365 _dispose (GObject * object)
368 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
371 g_hash_table_unref (priv->assets);
372 if (priv->loading_assets)
373 g_hash_table_unref (priv->loading_assets);
374 if (priv->loaded_with_error)
375 g_hash_table_unref (priv->loaded_with_error);
376 if (priv->formatter_asset)
377 gst_object_unref (priv->formatter_asset);
379 for (tmp = priv->formatters; tmp; tmp = tmp->next)
380 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
382 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
386 _finalize (GObject * object)
388 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
393 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
397 _get_property (GESProject * project, guint property_id,
398 GValue * value, GParamSpec * pspec)
400 GESProjectPrivate *priv = project->priv;
402 switch (property_id) {
404 g_value_set_string (value, priv->uri);
407 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
412 _set_property (GESProject * project, guint property_id,
413 const GValue * value, GParamSpec * pspec)
415 switch (property_id) {
417 project->priv->uri = g_value_dup_string (value);
420 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
425 ges_project_class_init (GESProjectClass * klass)
427 GObjectClass *object_class = G_OBJECT_CLASS (klass);
429 klass->asset_added = NULL;
430 klass->missing_uri = ges_missing_uri_default;
431 klass->loading_error = NULL;
432 klass->asset_removed = NULL;
433 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
434 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
439 * The location of the project to use.
441 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
442 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
444 g_object_class_install_properties (object_class, PROP_LAST, _properties);
447 * GESProject::asset-added:
448 * @project: the #GESProject
449 * @asset: The #GESAsset that has been added to @project
451 _signals[ASSET_ADDED_SIGNAL] =
452 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
453 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
454 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
457 * GESProject::asset-loading:
458 * @project: the #GESProject
459 * @asset: The #GESAsset that started loading
463 _signals[ASSET_LOADING_SIGNAL] =
464 g_signal_new ("asset-loading", G_TYPE_FROM_CLASS (klass),
465 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_loading),
466 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
469 * GESProject::asset-removed:
470 * @project: the #GESProject
471 * @asset: The #GESAsset that has been removed from @project
473 _signals[ASSET_REMOVED_SIGNAL] =
474 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
475 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
476 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
479 * GESProject::loaded:
480 * @project: the #GESProject that is done loading a project.
481 * @timeline: The #GESTimeline that complete loading
483 _signals[LOADED_SIGNAL] =
484 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
485 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
486 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
487 1, GES_TYPE_TIMELINE);
490 * GESProject::missing-uri:
491 * @project: the #GESProject reporting that a file has moved
492 * @error: The error that happened
493 * @wrong_asset: The asset with the wrong ID, you should us it and its content
494 * only to find out what the new location is.
498 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
500 * return g_strdup ("file:///the/new/uri.ogg");
504 * main (int argc, gchar ** argv)
506 * GESTimeline *timeline;
507 * GESProject *project = ges_project_new ("file:///some/uri.xges");
509 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
510 * timeline = ges_asset_extract (GES_ASSET (project));
514 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
516 _signals[MISSING_URI_SIGNAL] =
517 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
518 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
519 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
520 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
523 * GESProject::error-loading-asset:
524 * @project: the #GESProject on which a problem happend when creted a #GESAsset
525 * @error: The #GError defining the error that accured, might be %NULL
526 * @id: The @id of the asset that failed loading
527 * @extractable_type: The @extractable_type of the asset that
530 * Informs you that a #GESAsset could not be created. In case of
531 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
532 * #GST_CORE_ERROR_MISSING_PLUGIN
534 _signals[ERROR_LOADING_ASSET] =
535 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
536 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
537 NULL, NULL, g_cclosure_marshal_generic,
538 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
540 object_class->dispose = _dispose;
541 object_class->finalize = _finalize;
543 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
547 ges_project_init (GESProject * project)
549 GESProjectPrivate *priv = project->priv =
550 ges_project_get_instance_private (project);
553 priv->formatters = NULL;
554 priv->formatter_asset = NULL;
555 priv->encoding_profiles = NULL;
556 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
557 g_free, gst_object_unref);
558 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
559 g_free, gst_object_unref);
560 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
565 _send_error_loading_asset (GESProject * project, GESAsset * asset,
568 const gchar *id = ges_asset_get_id (asset);
570 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
571 g_hash_table_remove (project->priv->loading_assets, id);
572 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
573 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
574 ges_asset_get_extractable_type (asset));
578 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
581 gchar *new_id = NULL;
584 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
585 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
586 g_return_val_if_fail (error, NULL);
588 id = ges_asset_get_id (asset);
589 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
590 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
591 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
592 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
594 _send_error_loading_asset (project, asset, error);
599 /* Always send the MISSING_URI signal if requesting new ID is possible
600 * so that subclasses of GESProject are aware of the missing-uri */
601 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
605 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
606 if (!ges_asset_try_proxy (asset, new_id)) {
611 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
614 g_hash_table_remove (project->priv->loading_assets, id);
617 _send_error_loading_asset (project, asset, error);
624 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
626 GError *error = NULL;
627 gchar *possible_id = NULL;
628 GESAsset *asset = ges_asset_request_finish (res, &error);
631 possible_id = ges_project_try_updating_id (project, source, error);
633 if (possible_id == NULL)
636 ges_project_create_asset (project, possible_id,
637 ges_asset_get_extractable_type (source));
639 g_free (possible_id);
640 g_error_free (error);
644 ges_asset_set_proxy (NULL, asset);
645 ges_project_add_asset (project, asset);
647 gst_object_unref (asset);
651 * ges_project_set_loaded:
652 * @project: The #GESProject from which to emit the "project-loaded" signal
654 * Emits the "loaded" signal. This method should be called by sublasses when
655 * the project is fully loaded.
657 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
660 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
662 GST_INFO_OBJECT (project, "Emit project loaded");
663 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
664 timeline_fill_gaps (formatter->timeline);
666 ges_timeline_commit (formatter->timeline);
669 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
671 /* We are now done with that formatter */
672 ges_project_remove_formatter (project, formatter);
677 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
682 if ((asset = ges_asset_cache_lookup (extractable_type, id))) {
683 if (g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
684 gst_object_ref (asset)))
685 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
689 /**************************************
691 * API Implementation *
693 **************************************/
696 * ges_project_create_asset:
697 * @project: A #GESProject
698 * @id: (allow-none): The id of the asset to create and add to @project
699 * @extractable_type: The #GType of the asset to create
701 * Create and add a #GESAsset to @project. You should connect to the
702 * "asset-added" signal to get the asset when it finally gets added to
705 * Returns: %TRUE if the asset started to be added %FALSE it was already
709 ges_project_create_asset (GESProject * project, const gchar * id,
710 GType extractable_type)
712 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
713 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
717 id = g_type_name (extractable_type);
719 if (g_hash_table_lookup (project->priv->assets, id) ||
720 g_hash_table_lookup (project->priv->loading_assets, id) ||
721 g_hash_table_lookup (project->priv->loaded_with_error, id))
724 /* TODO Add a GCancellable somewhere in our API */
725 ges_asset_request_async (extractable_type, id, NULL,
726 (GAsyncReadyCallback) new_asset_cb, project);
727 ges_project_add_loading_asset (project, extractable_type, id);
733 * ges_project_create_asset_sync:
734 * @project: A #GESProject
735 * @id: (allow-none): The id of the asset to create and add to @project
736 * @extractable_type: The #GType of the asset to create
737 * @error: A #GError to be set in case of error
739 * Create and add a #GESAsset to @project. You should connect to the
740 * "asset-added" signal to get the asset when it finally gets added to
743 * Returns: (transfer full) (nullable): The newly created #GESAsset or %NULL.
746 ges_project_create_asset_sync (GESProject * project, const gchar * id,
747 GType extractable_type, GError ** error)
750 gchar *possible_id = NULL;
751 gboolean retry = TRUE;
753 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
754 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
758 id = g_type_name (extractable_type);
760 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
762 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
763 g_hash_table_lookup (project->priv->loaded_with_error, id))
766 /* TODO Add a GCancellable somewhere in our API */
769 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
770 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
772 asset = ges_asset_request (extractable_type, id, error);
778 if ((!g_hash_table_lookup (project->priv->assets,
779 ges_asset_get_id (asset))))
780 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
783 g_free (possible_id);
784 ges_uri_assets_validate_uri (id);
791 tmpasset = ges_asset_cache_lookup (extractable_type, id);
792 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
794 if (possible_id == NULL) {
795 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, tmpasset);
796 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, *error, id,
802 g_clear_error (error);
808 if (!ges_asset_get_proxy_target (asset))
809 ges_asset_set_proxy (NULL, asset);
811 ges_project_add_asset (project, asset);
817 * ges_project_add_asset:
818 * @project: A #GESProject
819 * @asset: (transfer none): A #GESAsset to add to @project
821 * Adds a #Asset to @project, the project will keep a reference on
824 * Returns: %TRUE if the asset could be added %FALSE it was already
828 ges_project_add_asset (GESProject * project, GESAsset * asset)
830 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
832 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
835 g_hash_table_insert (project->priv->assets,
836 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
838 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
839 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
840 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
846 * ges_project_remove_asset:
847 * @project: A #GESProject
848 * @asset: (transfer none): A #GESAsset to remove from @project
850 * remove a @asset to from @project.
852 * Returns: %TRUE if the asset could be removed %FALSE otherwise
855 ges_project_remove_asset (GESProject * project, GESAsset * asset)
859 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
861 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
862 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
868 * ges_project_get_asset:
869 * @project: A #GESProject
870 * @id: The id of the asset to retrieve
871 * @extractable_type: The extractable_type of the asset
872 * to retrieve from @object
874 * Returns: (transfer full) (allow-none): The #GESAsset with
875 * @id or %NULL if no asset with @id as an ID
878 ges_project_get_asset (GESProject * project, const gchar * id,
879 GType extractable_type)
883 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
884 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
887 asset = g_hash_table_lookup (project->priv->assets, id);
890 return gst_object_ref (asset);
896 * ges_project_list_assets:
897 * @project: A #GESProject
898 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
901 * List all @asset contained in @project filtering per extractable_type
902 * as defined by @filter. It copies the asset and thus will not be updated
905 * Returns: (transfer full) (element-type GESAsset): The list of
906 * #GESAsset the object contains
909 ges_project_list_assets (GESProject * project, GType filter)
915 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
917 g_hash_table_iter_init (&iter, project->priv->assets);
918 while (g_hash_table_iter_next (&iter, &key, &value)) {
919 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
921 ret = g_list_append (ret, gst_object_ref (value));
929 * @project: A #GESProject to save
930 * @timeline: The #GESTimeline to save, it must have been extracted from @project
931 * @uri: The uri where to save @project and @timeline
932 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
933 * will try to save in the same format as the one from which the timeline as been loaded
934 * or default to the formatter with highest rank
935 * @overwrite: %TRUE to overwrite file if it exists
936 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
938 * Save the timeline of @project to @uri. You should make sure that @timeline
939 * is one of the timelines that have been extracted from @project
940 * (using ges_asset_extract (@project);)
942 * Returns: %TRUE if the project could be save, %FALSE otherwize
945 ges_project_save (GESProject * project, GESTimeline * timeline,
946 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
951 GESFormatter *formatter = NULL;
953 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
954 g_return_val_if_fail (formatter_asset == NULL ||
955 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
956 GES_TYPE_FORMATTER), FALSE);
957 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
959 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
960 if (tl_asset == NULL && project->priv->uri == NULL) {
961 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
964 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
965 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
969 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
970 " we have no uri set, so setting ourself as asset", timeline);
972 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
973 } else if (tl_asset != GES_ASSET (project)) {
974 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
975 " not created by this project can not save", timeline);
981 if (formatter_asset == NULL)
982 formatter_asset = gst_object_ref (ges_formatter_get_default ());
984 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
985 if (formatter == NULL) {
986 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
987 formatter_asset, ges_asset_get_id (formatter_asset),
988 (error && *error) ? (*error)->message : "Unknown Error");
994 ges_project_add_formatter (project, formatter);
995 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
996 if (ret && project->priv->uri == NULL)
997 ges_project_set_uri (project, uri);
1000 if (formatter_asset)
1001 gst_object_unref (formatter_asset);
1002 ges_project_remove_formatter (project, formatter);
1009 * @uri: (allow-none): The uri to be set after creating the project.
1011 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
1012 * if @uri is not valid or %NULL, the uri of the project will then be set
1013 * the first time you save the project. If you then save the project to
1014 * other locations, it will never be updated again and the first valid URI is
1015 * the URI it will keep refering to.
1017 * Returns: A newly created #GESProject
1020 ges_project_new (const gchar * uri)
1022 gchar *id = (gchar *) uri;
1023 GESProject *project;
1026 id = g_strdup_printf ("project-%i", nb_projects++);
1028 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
1031 ges_project_set_uri (project, uri);
1041 * @project: A #GESProject that has an @uri set already
1042 * @timeline: A blank timeline to load @project into
1043 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1045 * Loads @project into @timeline
1047 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1050 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1052 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1053 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1054 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1055 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1057 if (!_load_project (project, timeline, error))
1060 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1066 * ges_project_get_uri:
1067 * @project: A #GESProject
1069 * Retrieve the uri that is currently set on @project
1071 * Returns: (transfer full) (nullable): a newly allocated string representing uri.
1074 ges_project_get_uri (GESProject * project)
1076 GESProjectPrivate *priv;
1078 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1080 priv = project->priv;
1082 return g_strdup (priv->uri);
1087 * ges_project_add_encoding_profile:
1088 * @project: A #GESProject
1089 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1090 * the same name already exists, it will be replaced
1092 * Adds @profile to the project. It lets you save in what format
1093 * the project has been renders and keep a reference to those formats.
1094 * Also, those formats will be saves to the project file when possible.
1096 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1099 ges_project_add_encoding_profile (GESProject * project,
1100 GstEncodingProfile * profile)
1103 GESProjectPrivate *priv;
1105 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1106 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1108 priv = project->priv;
1109 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1110 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1112 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1113 gst_encoding_profile_get_name (profile)) == 0) {
1114 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1115 gst_encoding_profile_get_name (profile));
1117 gst_object_unref (tmp->data);
1118 tmp->data = gst_object_ref (profile);
1123 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1124 gst_object_ref (profile));
1130 * ges_project_list_encoding_profiles:
1131 * @project: A #GESProject
1133 * Lists the encoding profile that have been set to @project. The first one
1134 * is the latest added.
1136 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1137 * list of #GstEncodingProfile used in @project
1140 ges_project_list_encoding_profiles (GESProject * project)
1142 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1144 return project->priv->encoding_profiles;
1148 * ges_project_get_loading_assets:
1149 * @project: A #GESProject
1151 * Get the assets that are being loaded
1153 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1154 * that will be added to @project. Note that those Asset are *not* loaded yet,
1155 * and thus can not be used
1158 ges_project_get_loading_assets (GESProject * project)
1160 GHashTableIter iter;
1161 gpointer key, value;
1165 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1167 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1168 while (g_hash_table_iter_next (&iter, &key, &value))
1169 ret = g_list_prepend (ret, gst_object_ref (value));