1 /* GStreamer Editing Services
3 * Copyright (C) <2012> Thibault Saunier <thibault.saunier@collabora.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * @short_description: A GESAsset that is used to manage projects
24 * The #GESProject is used to control a set of #GESAsset and is a
25 * #GESAsset with #GES_TYPE_TIMELINE as @extractable_type itself. That
26 * means that you can extract #GESTimeline from a project as followed:
29 * GESProject *project;
30 * GESTimeline *timeline;
32 * project = ges_project_new ("file:///path/to/a/valid/project/uri");
34 * // Here you can connect to the various signal to get more infos about
35 * // what is happening and recover from errors if possible
38 * timeline = ges_asset_extract (GES_ASSET (project));
41 * The #GESProject class offers a higher level API to handle #GESAsset-s.
42 * It lets you request new asset, and it informs you about new assets through
43 * a set of signals. Also it handles problem such as missing files/missing
44 * #GstElement and lets you try to recover from those.
47 #include "ges-internal.h"
49 static GPtrArray *new_paths = NULL;
50 static GHashTable *tried_uris = NULL;
52 /* TODO We should rely on both extractable_type and @id to identify
53 * a Asset, not only @id
55 G_DEFINE_TYPE (GESProject, ges_project, GES_TYPE_ASSET);
57 struct _GESProjectPrivate
60 /* Set of asset ID being loaded */
61 GHashTable *loading_assets;
62 GHashTable *loaded_with_error;
63 GESAsset *formatter_asset;
69 GList *encoding_profiles;
72 typedef struct EmitLoadedInIdle
75 GESTimeline *timeline;
88 static guint _signals[LAST_SIGNAL] = { 0 };
90 static guint nb_projects = 0;
99 static GParamSpec *_properties[LAST_SIGNAL] = { 0 };
102 _emit_loaded_in_idle (EmitLoadedInIdle * data)
104 ges_timeline_commit (data->timeline);
105 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
107 gst_object_unref (data->project);
108 gst_object_unref (data->timeline);
109 g_slice_free (EmitLoadedInIdle, data);
115 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
117 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
119 ges_formatter_set_project (formatter, project);
120 priv->formatters = g_list_append (priv->formatters, formatter);
122 gst_object_ref_sink (formatter);
126 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
129 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
131 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
132 if (tmp->data == formatter) {
133 gst_object_unref (formatter);
134 priv->formatters = g_list_delete_link (priv->formatters, tmp);
142 ges_project_set_uri (GESProject * project, const gchar * uri)
144 GESProjectPrivate *priv;
146 g_return_if_fail (GES_IS_PROJECT (project));
148 priv = project->priv;
150 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
155 if (uri == NULL || !gst_uri_is_valid (uri)) {
156 GST_LOG_OBJECT (project, "Invalid URI: %s", uri);
160 priv->uri = g_strdup (uri);
162 /* We use that URI as ID */
163 ges_asset_set_id (GES_ASSET (project), uri);
169 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
172 GESProjectPrivate *priv;
173 GESFormatter *formatter;
175 priv = GES_PROJECT (project)->priv;
177 if (priv->uri == NULL) {
178 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
180 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
181 " as no URI set yet", GST_OBJECT_NAME (timeline),
182 ges_asset_get_id (GES_ASSET (project)));
184 data->timeline = gst_object_ref (timeline);
185 data->project = gst_object_ref (project);
187 /* Make sure the signal is emitted after the functions ends */
188 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
192 if (priv->formatter_asset == NULL)
193 priv->formatter_asset = _find_formatter_asset_for_uri (priv->uri);
195 if (priv->formatter_asset == NULL)
198 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
200 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
206 ges_project_add_formatter (GES_PROJECT (project), formatter);
207 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
209 GST_WARNING_OBJECT (project, "Could not load the timeline,"
210 " returning: %s", lerr->message);
218 g_propagate_error (error, lerr);
223 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
224 const GValue * handler_return, gpointer data)
226 const gchar *ret = g_value_get_string (handler_return);
229 if (!gst_uri_is_valid (ret)) {
230 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
234 g_value_set_string (return_accu, ret);
241 /* GESAsset vmethod implementation */
242 static GESExtractable *
243 ges_project_extract (GESAsset * project, GError ** error)
245 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
247 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
248 if (_load_project (GES_PROJECT (project), timeline, error))
249 return GES_EXTRACTABLE (timeline);
251 gst_object_unref (timeline);
256 _add_media_new_paths_recursing (const gchar * value)
259 GFileEnumerator *fenum;
260 GFile *file = g_file_new_for_uri (value);
262 if (!(fenum = g_file_enumerate_children (file,
263 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
264 GST_INFO ("%s is not a folder", value);
269 GST_INFO ("Adding folder: %s", value);
270 g_ptr_array_add (new_paths, g_strdup (value));
271 for (info = g_file_enumerator_next_file (fenum, NULL, NULL);
272 info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) {
274 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
275 GFile *f = g_file_enumerator_get_child (fenum, info);
276 gchar *uri = g_file_get_uri (f);
278 _add_media_new_paths_recursing (uri);
279 gst_object_unref (f);
285 gst_object_unref (file);
287 gst_object_unref (fenum);
291 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
293 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
295 if (new_paths == NULL)
296 new_paths = g_ptr_array_new_with_free_func (g_free);
299 _add_media_new_paths_recursing (uri);
301 g_ptr_array_add (new_paths, g_strdup (uri));
307 ges_missing_uri_default (GESProject * self, GError * error,
308 GESAsset * wrong_asset)
311 const gchar *old_uri = ges_asset_get_id (wrong_asset);
313 if (new_paths == NULL)
316 if (tried_uris == NULL)
317 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
319 for (i = 0; i < new_paths->len; i++) {
320 gchar *basename, *res;
322 basename = g_path_get_basename (old_uri);
323 res = g_build_filename (new_paths->pdata[i], basename, NULL);
326 if (g_strcmp0 (old_uri, res) == 0) {
327 g_hash_table_add (tried_uris, res);
328 } else if (g_hash_table_lookup (tried_uris, res)) {
329 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
332 g_hash_table_add (tried_uris, g_strdup (res));
333 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
342 ges_uri_assets_validate_uri (const gchar * nid)
345 g_hash_table_remove (tried_uris, nid);
348 /* GObject vmethod implementation */
350 _dispose (GObject * object)
353 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
356 g_hash_table_unref (priv->assets);
357 if (priv->loading_assets)
358 g_hash_table_unref (priv->loading_assets);
359 if (priv->loaded_with_error)
360 g_hash_table_unref (priv->loaded_with_error);
361 if (priv->formatter_asset)
362 gst_object_unref (priv->formatter_asset);
364 for (tmp = priv->formatters; tmp; tmp = tmp->next)
365 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
367 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
371 _finalize (GObject * object)
373 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
378 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
382 _get_property (GESProject * project, guint property_id,
383 GValue * value, GParamSpec * pspec)
385 GESProjectPrivate *priv = project->priv;
387 switch (property_id) {
389 g_value_set_string (value, priv->uri);
392 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
397 _set_property (GESProject * project, guint property_id,
398 const GValue * value, GParamSpec * pspec)
400 switch (property_id) {
402 project->priv->uri = g_value_dup_string (value);
405 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
410 ges_project_class_init (GESProjectClass * klass)
412 GObjectClass *object_class = G_OBJECT_CLASS (klass);
414 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
416 klass->asset_added = NULL;
417 klass->missing_uri = ges_missing_uri_default;
418 klass->loading_error = NULL;
419 klass->asset_removed = NULL;
420 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
421 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
426 * The location of the project to use.
428 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
429 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
431 g_object_class_install_properties (object_class, PROP_LAST, _properties);
434 * GESProject::asset-added:
435 * @formatter: the #GESProject
436 * @asset: The #GESAsset that has been added to @project
438 _signals[ASSET_ADDED_SIGNAL] =
439 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
440 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
441 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
444 * GESProject::asset-removed:
445 * @formatter: the #GESProject
446 * @asset: The #GESAsset that has been removed from @project
448 _signals[ASSET_REMOVED_SIGNAL] =
449 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
450 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
451 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
454 * GESProject::loaded:
455 * @project: the #GESProject that is done loading a project.
456 * @timeline: The #GESTimeline that complete loading
458 _signals[LOADED_SIGNAL] =
459 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
460 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
461 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
462 1, GES_TYPE_TIMELINE);
465 * GESProject::missing-uri:
466 * @project: the #GESProject reporting that a file has moved
467 * @error: The error that happened
468 * @wrong_asset: The asset with the wrong ID, you should us it and its content
469 * only to find out what the new location is.
473 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
475 * return g_strdup ("file:///the/new/uri.ogg");
479 * main (int argc, gchar ** argv)
481 * GESTimeline *timeline;
482 * GESProject *project = ges_project_new ("file:///some/uri.xges");
484 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
485 * timeline = ges_asset_extract (GES_ASSET (project));
489 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
491 _signals[MISSING_URI_SIGNAL] =
492 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
493 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
494 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
495 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
498 * GESProject::error-loading-asset:
499 * @project: the #GESProject on which a problem happend when creted a #GESAsset
500 * @error: The #GError defining the error that accured, might be %NULL
501 * @id: The @id of the asset that failed loading
502 * @extractable_type: The @extractable_type of the asset that
505 * Informs you that a #GESAsset could not be created. In case of
506 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
507 * #GST_CORE_ERROR_MISSING_PLUGIN
509 _signals[ERROR_LOADING_ASSET] =
510 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
511 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
512 NULL, NULL, g_cclosure_marshal_generic,
513 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
515 object_class->dispose = _dispose;
516 object_class->finalize = _finalize;
518 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
522 ges_project_init (GESProject * project)
524 GESProjectPrivate *priv = project->priv =
525 G_TYPE_INSTANCE_GET_PRIVATE (project,
526 GES_TYPE_PROJECT, GESProjectPrivate);
529 priv->formatters = NULL;
530 priv->formatter_asset = NULL;
531 priv->encoding_profiles = NULL;
532 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
533 g_free, gst_object_unref);
534 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
535 g_free, gst_object_unref);
536 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
541 _send_error_loading_asset (GESProject * project, GESAsset * asset,
544 const gchar *id = ges_asset_get_id (asset);
546 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
547 g_hash_table_remove (project->priv->loading_assets, id);
548 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
549 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
550 ges_asset_get_extractable_type (asset));
554 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
557 gchar *new_id = NULL;
560 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
561 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
562 g_return_val_if_fail (error, NULL);
564 id = ges_asset_get_id (asset);
565 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
566 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
567 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
568 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
570 _send_error_loading_asset (project, asset, error);
575 if (new_id == NULL) {
576 GST_DEBUG_OBJECT (project, "Sending 'missing-uri' signal for %s", id);
577 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
582 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
583 if (!ges_asset_set_proxy (asset, new_id)) {
588 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
591 g_hash_table_remove (project->priv->loading_assets, id);
594 _send_error_loading_asset (project, asset, error);
601 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
603 GError *error = NULL;
604 gchar *possible_id = NULL;
605 GESAsset *asset = ges_asset_request_finish (res, &error);
608 possible_id = ges_project_try_updating_id (project, source, error);
610 if (possible_id == NULL)
613 ges_project_create_asset (project, possible_id,
614 ges_asset_get_extractable_type (source));
616 g_free (possible_id);
617 g_error_free (error);
621 ges_project_add_asset (project, asset);
623 gst_object_unref (asset);
627 * ges_project_set_loaded:
628 * @project: The #GESProject from which to emit the "project-loaded" signal
630 * Emits the "loaded" signal. This method should be called by sublasses when
631 * the project is fully loaded.
633 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
636 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
638 GST_INFO_OBJECT (project, "Emit project loaded");
639 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
640 timeline_fill_gaps (formatter->timeline);
642 ges_timeline_commit (formatter->timeline);
645 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
647 /* We are now done with that formatter */
648 ges_project_remove_formatter (project, formatter);
653 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
658 if ((asset = ges_asset_cache_lookup (extractable_type, id)))
659 g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
660 gst_object_ref (asset));
663 /**************************************
665 * API Implementation *
667 **************************************/
670 * ges_project_create_asset:
671 * @project: A #GESProject
672 * @id: (allow-none): The id of the asset to create and add to @project
673 * @extractable_type: The #GType of the asset to create
675 * Create and add a #GESAsset to @project. You should connect to the
676 * "asset-added" signal to get the asset when it finally gets added to
679 * Returns: %TRUE if the asset started to be added %FALSE it was already
683 ges_project_create_asset (GESProject * project, const gchar * id,
684 GType extractable_type)
686 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
687 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
691 id = g_type_name (extractable_type);
693 if (g_hash_table_lookup (project->priv->assets, id) ||
694 g_hash_table_lookup (project->priv->loading_assets, id) ||
695 g_hash_table_lookup (project->priv->loaded_with_error, id))
698 /* TODO Add a GCancellable somewhere in our API */
699 ges_asset_request_async (extractable_type, id, NULL,
700 (GAsyncReadyCallback) new_asset_cb, project);
701 ges_project_add_loading_asset (project, extractable_type, id);
707 * ges_project_create_asset_sync:
708 * @project: A #GESProject
709 * @id: (allow-none): The id of the asset to create and add to @project
710 * @extractable_type: The #GType of the asset to create
711 * @error: A #GError to be set in case of error
713 * Create and add a #GESAsset to @project. You should connect to the
714 * "asset-added" signal to get the asset when it finally gets added to
717 * Returns: The newly created #GESAsset
720 ges_project_create_asset_sync (GESProject * project, const gchar * id,
721 GType extractable_type, GError ** error)
724 gchar *possible_id = NULL;
725 gboolean retry = TRUE;
727 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
728 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
732 id = g_type_name (extractable_type);
734 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
736 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
737 g_hash_table_lookup (project->priv->loaded_with_error, id))
740 /* TODO Add a GCancellable somewhere in our API */
743 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
744 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
746 asset = ges_asset_request (extractable_type, id, error);
753 g_free (possible_id);
754 ges_uri_assets_validate_uri (id);
761 tmpasset = ges_asset_cache_lookup (extractable_type, id);
762 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
764 if (possible_id == NULL)
767 g_clear_error (error);
775 ges_project_add_asset (project, asset);
781 * ges_project_add_asset:
782 * @project: A #GESProject
783 * @asset: (transfer none): A #GESAsset to add to @project
785 * Adds a #Asset to @project, the project will keep a reference on
788 * Returns: %TRUE if the asset could be added %FALSE it was already
792 ges_project_add_asset (GESProject * project, GESAsset * asset)
794 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
796 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
799 g_hash_table_insert (project->priv->assets,
800 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
802 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
803 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
804 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
810 * ges_project_remove_asset:
811 * @project: A #GESProject
812 * @asset: (transfer none): A #GESAsset to remove from @project
814 * remove a @asset to from @project.
816 * Returns: %TRUE if the asset could be removed %FALSE otherwise
819 ges_project_remove_asset (GESProject * project, GESAsset * asset)
823 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
825 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
826 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
832 * ges_project_get_asset:
833 * @project: A #GESProject
834 * @id: The id of the asset to retrieve
835 * @extractable_type: The extractable_type of the asset
836 * to retrieve from @object
838 * Returns: (transfer full) (allow-none): The #GESAsset with
839 * @id or %NULL if no asset with @id as an ID
842 ges_project_get_asset (GESProject * project, const gchar * id,
843 GType extractable_type)
847 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
848 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
851 asset = g_hash_table_lookup (project->priv->assets, id);
854 return gst_object_ref (asset);
860 * ges_project_list_assets:
861 * @project: A #GESProject
862 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
865 * List all @asset contained in @project filtering per extractable_type
866 * as defined by @filter. It copies the asset and thus will not be updated
869 * Returns: (transfer full) (element-type GESAsset): The list of
870 * #GESAsset the object contains
873 ges_project_list_assets (GESProject * project, GType filter)
879 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
881 g_hash_table_iter_init (&iter, project->priv->assets);
882 while (g_hash_table_iter_next (&iter, &key, &value)) {
883 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
885 ret = g_list_append (ret, gst_object_ref (value));
893 * @project: A #GESProject to save
894 * @timeline: The #GESTimeline to save, it must have been extracted from @project
895 * @uri: The uri where to save @project and @timeline
896 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
897 * will try to save in the same format as the one from which the timeline as been loaded
898 * or default to the formatter with highest rank
899 * @overwrite: %TRUE to overwrite file if it exists
900 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
902 * Save the timeline of @project to @uri. You should make sure that @timeline
903 * is one of the timelines that have been extracted from @project
904 * (using ges_asset_extract (@project);)
906 * Returns: %TRUE if the project could be save, %FALSE otherwize
909 ges_project_save (GESProject * project, GESTimeline * timeline,
910 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
915 GESFormatter *formatter = NULL;
917 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
918 g_return_val_if_fail (formatter_asset == NULL ||
919 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
920 GES_TYPE_FORMATTER), FALSE);
921 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
923 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
924 if (tl_asset == NULL && project->priv->uri == NULL) {
925 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
928 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
929 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
933 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
934 " we have no uri set, so setting ourself as asset", timeline);
936 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
937 } else if (tl_asset != GES_ASSET (project)) {
938 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
939 " not created by this project can not save", timeline);
945 if (formatter_asset == NULL)
946 formatter_asset = gst_object_ref (ges_formatter_get_default ());
948 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
949 if (formatter == NULL) {
950 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
951 formatter_asset, ges_asset_get_id (formatter_asset),
952 (error && *error) ? (*error)->message : "Unknown Error");
958 ges_project_add_formatter (project, formatter);
959 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
960 if (ret && project->priv->uri == NULL)
961 ges_project_set_uri (project, uri);
965 gst_object_unref (formatter_asset);
966 ges_project_remove_formatter (project, formatter);
973 * @uri: (allow-none): The uri to be set after creating the project.
975 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
976 * if @uri is not valid or %NULL, the uri of the project will then be set
977 * the first time you save the project. If you then save the project to
978 * other locations, it will never be updated again and the first valid URI is
979 * the URI it will keep refering to.
981 * Returns: A newly created #GESProject
984 ges_project_new (const gchar * uri)
986 gchar *id = (gchar *) uri;
990 id = g_strdup_printf ("project-%i", nb_projects++);
992 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
995 ges_project_set_uri (project, uri);
1005 * @project: A #GESProject that has an @uri set already
1006 * @timeline: A blank timeline to load @project into
1007 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1009 * Loads @project into @timeline
1011 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1014 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1016 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1017 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1018 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1019 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1021 if (!_load_project (project, timeline, error))
1024 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1030 * ges_project_get_uri:
1031 * @project: A #GESProject
1033 * Retrieve the uri that is currently set on @project
1035 * Returns: The uri that is set on @project
1038 ges_project_get_uri (GESProject * project)
1040 GESProjectPrivate *priv;
1042 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1044 priv = project->priv;
1046 return g_strdup (priv->uri);
1051 * ges_project_add_encoding_profile:
1052 * @project: A #GESProject
1053 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1054 * the same name already exists, it will be replaced
1056 * Adds @profile to the project. It lets you save in what format
1057 * the project has been renders and keep a reference to those formats.
1058 * Also, those formats will be saves to the project file when possible.
1060 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1063 ges_project_add_encoding_profile (GESProject * project,
1064 GstEncodingProfile * profile)
1067 GESProjectPrivate *priv;
1069 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1070 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1072 priv = project->priv;
1073 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1074 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1076 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1077 gst_encoding_profile_get_name (profile)) == 0) {
1078 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1079 gst_encoding_profile_get_name (profile));
1081 gst_object_unref (tmp->data);
1082 tmp->data = gst_object_ref (profile);
1087 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1088 gst_object_ref (profile));
1094 * ges_project_list_encoding_profiles:
1095 * @project: A #GESProject
1097 * Lists the encoding profile that have been set to @project. The first one
1098 * is the latest added.
1100 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1101 * list of #GstEncodingProfile used in @project
1104 ges_project_list_encoding_profiles (GESProject * project)
1106 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1108 return project->priv->encoding_profiles;
1112 * ges_project_get_loading_assets:
1113 * @project: A #GESProject
1115 * Get the assets that are being loaded
1117 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1118 * that will be added to @project. Note that those Asset are *not* loaded yet,
1119 * and thus can not be used
1122 ges_project_get_loading_assets (GESProject * project)
1124 GHashTableIter iter;
1125 gpointer key, value;
1129 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1131 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1132 while (g_hash_table_iter_next (&iter, &key, &value))
1133 ret = g_list_prepend (ret, gst_object_ref (value));