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.
48 #include "ges-internal.h"
50 static GPtrArray *new_paths = NULL;
51 static GHashTable *tried_uris = NULL;
53 /* TODO We should rely on both extractable_type and @id to identify
54 * a Asset, not only @id
56 G_DEFINE_TYPE (GESProject, ges_project, GES_TYPE_ASSET);
58 struct _GESProjectPrivate
61 /* Set of asset ID being loaded */
62 GHashTable *loading_assets;
63 GHashTable *loaded_with_error;
64 GESAsset *formatter_asset;
70 GList *encoding_profiles;
73 typedef struct EmitLoadedInIdle
76 GESTimeline *timeline;
90 static guint _signals[LAST_SIGNAL] = { 0 };
92 static guint nb_projects = 0;
101 static GParamSpec *_properties[LAST_SIGNAL] = { 0 };
104 _emit_loaded_in_idle (EmitLoadedInIdle * data)
106 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
108 gst_object_unref (data->project);
109 gst_object_unref (data->timeline);
110 g_slice_free (EmitLoadedInIdle, data);
116 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
118 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
120 ges_formatter_set_project (formatter, project);
121 priv->formatters = g_list_append (priv->formatters, formatter);
123 gst_object_ref_sink (formatter);
127 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
130 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
132 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
133 if (tmp->data == formatter) {
134 gst_object_unref (formatter);
135 priv->formatters = g_list_delete_link (priv->formatters, tmp);
143 ges_project_set_uri (GESProject * project, const gchar * uri)
145 GESProjectPrivate *priv;
147 g_return_if_fail (GES_IS_PROJECT (project));
149 priv = project->priv;
151 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
157 GST_LOG_OBJECT (project, "Uri should not be NULL");
161 priv->uri = g_strdup (uri);
163 /* We use that URI as ID */
164 ges_asset_set_id (GES_ASSET (project), uri);
170 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
173 GESProjectPrivate *priv;
174 GESFormatter *formatter;
176 priv = GES_PROJECT (project)->priv;
178 if (priv->uri == NULL) {
179 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
181 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
182 " as no URI set yet", GST_OBJECT_NAME (timeline),
183 ges_asset_get_id (GES_ASSET (project)));
185 data->timeline = gst_object_ref (timeline);
186 data->project = gst_object_ref (project);
188 /* Make sure the signal is emitted after the functions ends */
189 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
193 if (priv->formatter_asset == NULL)
194 priv->formatter_asset = _find_formatter_asset_for_id (priv->uri);
196 if (priv->formatter_asset == NULL) {
197 lerr = g_error_new (GES_ERROR, 0, "Could not find a suitable formatter");
201 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
203 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
209 ges_project_add_formatter (GES_PROJECT (project), formatter);
210 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
212 GST_WARNING_OBJECT (project, "Could not load the timeline,"
213 " returning: %s", lerr->message);
221 g_propagate_error (error, lerr);
226 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
227 const GValue * handler_return, gpointer data)
229 const gchar *ret = g_value_get_string (handler_return);
232 if (!gst_uri_is_valid (ret)) {
233 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
237 g_value_set_string (return_accu, ret);
244 /* GESAsset vmethod implementation */
245 static GESExtractable *
246 ges_project_extract (GESAsset * project, GError ** error)
248 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
250 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
251 if (_load_project (GES_PROJECT (project), timeline, error))
252 return GES_EXTRACTABLE (timeline);
254 gst_object_unref (timeline);
259 _add_media_new_paths_recursing (const gchar * value)
262 GFileEnumerator *fenum;
263 GFile *file = g_file_new_for_uri (value);
265 if (!(fenum = g_file_enumerate_children (file,
266 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
267 GST_INFO ("%s is not a folder", value);
272 GST_INFO ("Adding folder: %s", value);
273 g_ptr_array_add (new_paths, g_strdup (value));
274 info = g_file_enumerator_next_file (fenum, NULL, NULL);
275 while (info != NULL) {
276 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
277 GFile *f = g_file_enumerator_get_child (fenum, info);
278 gchar *uri = g_file_get_uri (f);
280 _add_media_new_paths_recursing (uri);
281 gst_object_unref (f);
284 g_object_unref (info);
285 info = g_file_enumerator_next_file (fenum, NULL, NULL);
289 gst_object_unref (file);
291 gst_object_unref (fenum);
295 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
297 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
299 if (new_paths == NULL)
300 new_paths = g_ptr_array_new_with_free_func (g_free);
303 _add_media_new_paths_recursing (uri);
305 g_ptr_array_add (new_paths, g_strdup (uri));
311 ges_missing_uri_default (GESProject * self, GError * error,
312 GESAsset * wrong_asset)
315 const gchar *old_uri = ges_asset_get_id (wrong_asset);
317 if (new_paths == NULL)
320 if (tried_uris == NULL)
321 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
323 for (i = 0; i < new_paths->len; i++) {
324 gchar *basename, *res;
326 basename = g_path_get_basename (old_uri);
327 res = g_build_filename (new_paths->pdata[i], basename, NULL);
330 if (g_strcmp0 (old_uri, res) == 0) {
331 g_hash_table_add (tried_uris, res);
332 } else if (g_hash_table_lookup (tried_uris, res)) {
333 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
336 g_hash_table_add (tried_uris, g_strdup (res));
337 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
346 ges_uri_assets_validate_uri (const gchar * nid)
349 g_hash_table_remove (tried_uris, nid);
352 /* GObject vmethod implementation */
354 _dispose (GObject * object)
357 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
360 g_hash_table_unref (priv->assets);
361 if (priv->loading_assets)
362 g_hash_table_unref (priv->loading_assets);
363 if (priv->loaded_with_error)
364 g_hash_table_unref (priv->loaded_with_error);
365 if (priv->formatter_asset)
366 gst_object_unref (priv->formatter_asset);
368 for (tmp = priv->formatters; tmp; tmp = tmp->next)
369 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
371 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
375 _finalize (GObject * object)
377 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
382 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
386 _get_property (GESProject * project, guint property_id,
387 GValue * value, GParamSpec * pspec)
389 GESProjectPrivate *priv = project->priv;
391 switch (property_id) {
393 g_value_set_string (value, priv->uri);
396 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
401 _set_property (GESProject * project, guint property_id,
402 const GValue * value, GParamSpec * pspec)
404 switch (property_id) {
406 project->priv->uri = g_value_dup_string (value);
409 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
414 ges_project_class_init (GESProjectClass * klass)
416 GObjectClass *object_class = G_OBJECT_CLASS (klass);
418 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
420 klass->asset_added = NULL;
421 klass->missing_uri = ges_missing_uri_default;
422 klass->loading_error = NULL;
423 klass->asset_removed = NULL;
424 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
425 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
430 * The location of the project to use.
432 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
433 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
435 g_object_class_install_properties (object_class, PROP_LAST, _properties);
438 * GESProject::asset-added:
439 * @project: the #GESProject
440 * @asset: The #GESAsset that has been added to @project
442 _signals[ASSET_ADDED_SIGNAL] =
443 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
444 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
445 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
448 * GESProject::asset-loading:
449 * @project: the #GESProject
450 * @asset: The #GESAsset that started loading
454 _signals[ASSET_LOADING_SIGNAL] =
455 g_signal_new ("asset-loading", G_TYPE_FROM_CLASS (klass),
456 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_loading),
457 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
460 * GESProject::asset-removed:
461 * @project: the #GESProject
462 * @asset: The #GESAsset that has been removed from @project
464 _signals[ASSET_REMOVED_SIGNAL] =
465 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
466 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
467 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
470 * GESProject::loaded:
471 * @project: the #GESProject that is done loading a project.
472 * @timeline: The #GESTimeline that complete loading
474 _signals[LOADED_SIGNAL] =
475 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
476 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
477 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
478 1, GES_TYPE_TIMELINE);
481 * GESProject::missing-uri:
482 * @project: the #GESProject reporting that a file has moved
483 * @error: The error that happened
484 * @wrong_asset: The asset with the wrong ID, you should us it and its content
485 * only to find out what the new location is.
489 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
491 * return g_strdup ("file:///the/new/uri.ogg");
495 * main (int argc, gchar ** argv)
497 * GESTimeline *timeline;
498 * GESProject *project = ges_project_new ("file:///some/uri.xges");
500 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
501 * timeline = ges_asset_extract (GES_ASSET (project));
505 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
507 _signals[MISSING_URI_SIGNAL] =
508 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
509 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
510 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
511 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
514 * GESProject::error-loading-asset:
515 * @project: the #GESProject on which a problem happend when creted a #GESAsset
516 * @error: The #GError defining the error that accured, might be %NULL
517 * @id: The @id of the asset that failed loading
518 * @extractable_type: The @extractable_type of the asset that
521 * Informs you that a #GESAsset could not be created. In case of
522 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
523 * #GST_CORE_ERROR_MISSING_PLUGIN
525 _signals[ERROR_LOADING_ASSET] =
526 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
527 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
528 NULL, NULL, g_cclosure_marshal_generic,
529 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
531 object_class->dispose = _dispose;
532 object_class->finalize = _finalize;
534 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
538 ges_project_init (GESProject * project)
540 GESProjectPrivate *priv = project->priv =
541 G_TYPE_INSTANCE_GET_PRIVATE (project,
542 GES_TYPE_PROJECT, GESProjectPrivate);
545 priv->formatters = NULL;
546 priv->formatter_asset = NULL;
547 priv->encoding_profiles = NULL;
548 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
549 g_free, gst_object_unref);
550 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
551 g_free, gst_object_unref);
552 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
557 _send_error_loading_asset (GESProject * project, GESAsset * asset,
560 const gchar *id = ges_asset_get_id (asset);
562 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
563 g_hash_table_remove (project->priv->loading_assets, id);
564 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
565 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
566 ges_asset_get_extractable_type (asset));
570 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
573 gchar *new_id = NULL;
576 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
577 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
578 g_return_val_if_fail (error, NULL);
580 id = ges_asset_get_id (asset);
581 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
582 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
583 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
584 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
586 _send_error_loading_asset (project, asset, error);
591 if (new_id == NULL) {
592 GST_DEBUG_OBJECT (project, "Sending 'missing-uri' signal for %s", id);
593 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
598 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
599 if (!ges_asset_try_proxy (asset, new_id)) {
604 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
607 g_hash_table_remove (project->priv->loading_assets, id);
610 _send_error_loading_asset (project, asset, error);
617 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
619 GError *error = NULL;
620 gchar *possible_id = NULL;
621 GESAsset *asset = ges_asset_request_finish (res, &error);
624 possible_id = ges_project_try_updating_id (project, source, error);
626 if (possible_id == NULL)
629 ges_project_create_asset (project, possible_id,
630 ges_asset_get_extractable_type (source));
632 g_free (possible_id);
633 g_error_free (error);
637 ges_asset_set_proxy (NULL, asset);
638 ges_project_add_asset (project, asset);
640 gst_object_unref (asset);
644 * ges_project_set_loaded:
645 * @project: The #GESProject from which to emit the "project-loaded" signal
647 * Emits the "loaded" signal. This method should be called by sublasses when
648 * the project is fully loaded.
650 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
653 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
655 GST_INFO_OBJECT (project, "Emit project loaded");
656 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
657 timeline_fill_gaps (formatter->timeline);
659 ges_timeline_commit (formatter->timeline);
662 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
664 /* We are now done with that formatter */
665 ges_project_remove_formatter (project, formatter);
670 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
675 if ((asset = ges_asset_cache_lookup (extractable_type, id))) {
676 if (g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
677 gst_object_ref (asset)))
678 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
682 /**************************************
684 * API Implementation *
686 **************************************/
689 * ges_project_create_asset:
690 * @project: A #GESProject
691 * @id: (allow-none): The id of the asset to create and add to @project
692 * @extractable_type: The #GType of the asset to create
694 * Create and add a #GESAsset to @project. You should connect to the
695 * "asset-added" signal to get the asset when it finally gets added to
698 * Returns: %TRUE if the asset started to be added %FALSE it was already
702 ges_project_create_asset (GESProject * project, const gchar * id,
703 GType extractable_type)
705 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
706 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
710 id = g_type_name (extractable_type);
712 if (g_hash_table_lookup (project->priv->assets, id) ||
713 g_hash_table_lookup (project->priv->loading_assets, id) ||
714 g_hash_table_lookup (project->priv->loaded_with_error, id))
717 /* TODO Add a GCancellable somewhere in our API */
718 ges_asset_request_async (extractable_type, id, NULL,
719 (GAsyncReadyCallback) new_asset_cb, project);
720 ges_project_add_loading_asset (project, extractable_type, id);
726 * ges_project_create_asset_sync:
727 * @project: A #GESProject
728 * @id: (allow-none): The id of the asset to create and add to @project
729 * @extractable_type: The #GType of the asset to create
730 * @error: A #GError to be set in case of error
732 * Create and add a #GESAsset to @project. You should connect to the
733 * "asset-added" signal to get the asset when it finally gets added to
736 * Returns: (transfer full) (nullable): The newly created #GESAsset or %NULL.
739 ges_project_create_asset_sync (GESProject * project, const gchar * id,
740 GType extractable_type, GError ** error)
743 gchar *possible_id = NULL;
744 gboolean retry = TRUE;
746 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
747 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
751 id = g_type_name (extractable_type);
753 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
755 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
756 g_hash_table_lookup (project->priv->loaded_with_error, id))
759 /* TODO Add a GCancellable somewhere in our API */
762 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
763 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
765 asset = ges_asset_request (extractable_type, id, error);
771 if ((!g_hash_table_lookup (project->priv->assets,
772 ges_asset_get_id (asset))))
773 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
776 g_free (possible_id);
777 ges_uri_assets_validate_uri (id);
784 tmpasset = ges_asset_cache_lookup (extractable_type, id);
785 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, tmpasset);
786 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, *error, id,
788 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
790 if (possible_id == NULL)
793 g_clear_error (error);
799 if (!ges_asset_get_proxy_target (asset))
800 ges_asset_set_proxy (NULL, asset);
802 ges_project_add_asset (project, asset);
808 * ges_project_add_asset:
809 * @project: A #GESProject
810 * @asset: (transfer none): A #GESAsset to add to @project
812 * Adds a #Asset to @project, the project will keep a reference on
815 * Returns: %TRUE if the asset could be added %FALSE it was already
819 ges_project_add_asset (GESProject * project, GESAsset * asset)
821 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
823 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
826 g_hash_table_insert (project->priv->assets,
827 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
829 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
830 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
831 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
837 * ges_project_remove_asset:
838 * @project: A #GESProject
839 * @asset: (transfer none): A #GESAsset to remove from @project
841 * remove a @asset to from @project.
843 * Returns: %TRUE if the asset could be removed %FALSE otherwise
846 ges_project_remove_asset (GESProject * project, GESAsset * asset)
850 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
852 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
853 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
859 * ges_project_get_asset:
860 * @project: A #GESProject
861 * @id: The id of the asset to retrieve
862 * @extractable_type: The extractable_type of the asset
863 * to retrieve from @object
865 * Returns: (transfer full) (allow-none): The #GESAsset with
866 * @id or %NULL if no asset with @id as an ID
869 ges_project_get_asset (GESProject * project, const gchar * id,
870 GType extractable_type)
874 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
875 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
878 asset = g_hash_table_lookup (project->priv->assets, id);
881 return gst_object_ref (asset);
887 * ges_project_list_assets:
888 * @project: A #GESProject
889 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
892 * List all @asset contained in @project filtering per extractable_type
893 * as defined by @filter. It copies the asset and thus will not be updated
896 * Returns: (transfer full) (element-type GESAsset): The list of
897 * #GESAsset the object contains
900 ges_project_list_assets (GESProject * project, GType filter)
906 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
908 g_hash_table_iter_init (&iter, project->priv->assets);
909 while (g_hash_table_iter_next (&iter, &key, &value)) {
910 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
912 ret = g_list_append (ret, gst_object_ref (value));
920 * @project: A #GESProject to save
921 * @timeline: The #GESTimeline to save, it must have been extracted from @project
922 * @uri: The uri where to save @project and @timeline
923 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
924 * will try to save in the same format as the one from which the timeline as been loaded
925 * or default to the formatter with highest rank
926 * @overwrite: %TRUE to overwrite file if it exists
927 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
929 * Save the timeline of @project to @uri. You should make sure that @timeline
930 * is one of the timelines that have been extracted from @project
931 * (using ges_asset_extract (@project);)
933 * Returns: %TRUE if the project could be save, %FALSE otherwize
936 ges_project_save (GESProject * project, GESTimeline * timeline,
937 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
942 GESFormatter *formatter = NULL;
944 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
945 g_return_val_if_fail (formatter_asset == NULL ||
946 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
947 GES_TYPE_FORMATTER), FALSE);
948 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
950 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
951 if (tl_asset == NULL && project->priv->uri == NULL) {
952 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
955 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
956 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
960 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
961 " we have no uri set, so setting ourself as asset", timeline);
963 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
964 } else if (tl_asset != GES_ASSET (project)) {
965 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
966 " not created by this project can not save", timeline);
972 if (formatter_asset == NULL)
973 formatter_asset = gst_object_ref (ges_formatter_get_default ());
975 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
976 if (formatter == NULL) {
977 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
978 formatter_asset, ges_asset_get_id (formatter_asset),
979 (error && *error) ? (*error)->message : "Unknown Error");
985 ges_project_add_formatter (project, formatter);
986 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
987 if (ret && project->priv->uri == NULL)
988 ges_project_set_uri (project, uri);
992 gst_object_unref (formatter_asset);
993 ges_project_remove_formatter (project, formatter);
1000 * @uri: (allow-none): The uri to be set after creating the project.
1002 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
1003 * if @uri is not valid or %NULL, the uri of the project will then be set
1004 * the first time you save the project. If you then save the project to
1005 * other locations, it will never be updated again and the first valid URI is
1006 * the URI it will keep refering to.
1008 * Returns: A newly created #GESProject
1011 ges_project_new (const gchar * uri)
1013 gchar *id = (gchar *) uri;
1014 GESProject *project;
1017 id = g_strdup_printf ("project-%i", nb_projects++);
1019 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
1022 ges_project_set_uri (project, uri);
1032 * @project: A #GESProject that has an @uri set already
1033 * @timeline: A blank timeline to load @project into
1034 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1036 * Loads @project into @timeline
1038 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1041 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1043 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1044 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1045 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1046 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1048 if (!_load_project (project, timeline, error))
1051 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1057 * ges_project_get_uri:
1058 * @project: A #GESProject
1060 * Retrieve the uri that is currently set on @project
1062 * Returns: (transfer full) (nullable): a newly allocated string representing uri.
1065 ges_project_get_uri (GESProject * project)
1067 GESProjectPrivate *priv;
1069 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1071 priv = project->priv;
1073 return g_strdup (priv->uri);
1078 * ges_project_add_encoding_profile:
1079 * @project: A #GESProject
1080 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1081 * the same name already exists, it will be replaced
1083 * Adds @profile to the project. It lets you save in what format
1084 * the project has been renders and keep a reference to those formats.
1085 * Also, those formats will be saves to the project file when possible.
1087 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1090 ges_project_add_encoding_profile (GESProject * project,
1091 GstEncodingProfile * profile)
1094 GESProjectPrivate *priv;
1096 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1097 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1099 priv = project->priv;
1100 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1101 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1103 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1104 gst_encoding_profile_get_name (profile)) == 0) {
1105 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1106 gst_encoding_profile_get_name (profile));
1108 gst_object_unref (tmp->data);
1109 tmp->data = gst_object_ref (profile);
1114 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1115 gst_object_ref (profile));
1121 * ges_project_list_encoding_profiles:
1122 * @project: A #GESProject
1124 * Lists the encoding profile that have been set to @project. The first one
1125 * is the latest added.
1127 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1128 * list of #GstEncodingProfile used in @project
1131 ges_project_list_encoding_profiles (GESProject * project)
1133 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1135 return project->priv->encoding_profiles;
1139 * ges_project_get_loading_assets:
1140 * @project: A #GESProject
1142 * Get the assets that are being loaded
1144 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1145 * that will be added to @project. Note that those Asset are *not* loaded yet,
1146 * and thus can not be used
1149 ges_project_get_loading_assets (GESProject * project)
1151 GHashTableIter iter;
1152 gpointer key, value;
1156 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1158 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1159 while (g_hash_table_iter_next (&iter, &key, &value))
1160 ret = g_list_prepend (ret, gst_object_ref (value));