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 g_signal_emit (data->project, _signals[LOADED_SIGNAL], 0, data->timeline);
106 gst_object_unref (data->project);
107 gst_object_unref (data->timeline);
108 g_slice_free (EmitLoadedInIdle, data);
114 ges_project_add_formatter (GESProject * project, GESFormatter * formatter)
116 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
118 ges_formatter_set_project (formatter, project);
119 priv->formatters = g_list_append (priv->formatters, formatter);
121 gst_object_ref_sink (formatter);
125 ges_project_remove_formatter (GESProject * project, GESFormatter * formatter)
128 GESProjectPrivate *priv = GES_PROJECT (project)->priv;
130 for (tmp = priv->formatters; tmp; tmp = tmp->next) {
131 if (tmp->data == formatter) {
132 gst_object_unref (formatter);
133 priv->formatters = g_list_delete_link (priv->formatters, tmp);
141 ges_project_set_uri (GESProject * project, const gchar * uri)
143 GESProjectPrivate *priv;
145 g_return_if_fail (GES_IS_PROJECT (project));
147 priv = project->priv;
149 GST_WARNING_OBJECT (project, "Trying to rest URI, this is prohibited");
155 GST_LOG_OBJECT (project, "Uri should not be NULL");
159 priv->uri = g_strdup (uri);
161 /* We use that URI as ID */
162 ges_asset_set_id (GES_ASSET (project), uri);
168 _load_project (GESProject * project, GESTimeline * timeline, GError ** error)
171 GESProjectPrivate *priv;
172 GESFormatter *formatter;
174 priv = GES_PROJECT (project)->priv;
176 if (priv->uri == NULL) {
177 EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle);
179 GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s"
180 " as no URI set yet", GST_OBJECT_NAME (timeline),
181 ges_asset_get_id (GES_ASSET (project)));
183 data->timeline = gst_object_ref (timeline);
184 data->project = gst_object_ref (project);
186 /* Make sure the signal is emitted after the functions ends */
187 g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data);
191 if (priv->formatter_asset == NULL)
192 priv->formatter_asset = _find_formatter_asset_for_id (priv->uri);
194 if (priv->formatter_asset == NULL) {
195 lerr = g_error_new (GES_ERROR, 0, "Could not find a suitable formatter");
199 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
201 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
207 ges_project_add_formatter (GES_PROJECT (project), formatter);
208 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
210 GST_WARNING_OBJECT (project, "Could not load the timeline,"
211 " returning: %s", lerr->message);
219 g_propagate_error (error, lerr);
224 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
225 const GValue * handler_return, gpointer data)
227 const gchar *ret = g_value_get_string (handler_return);
230 if (!gst_uri_is_valid (ret)) {
231 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
235 g_value_set_string (return_accu, ret);
242 /* GESAsset vmethod implementation */
243 static GESExtractable *
244 ges_project_extract (GESAsset * project, GError ** error)
246 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
248 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
249 if (_load_project (GES_PROJECT (project), timeline, error))
250 return GES_EXTRACTABLE (timeline);
252 gst_object_unref (timeline);
257 _add_media_new_paths_recursing (const gchar * value)
260 GFileEnumerator *fenum;
261 GFile *file = g_file_new_for_uri (value);
263 if (!(fenum = g_file_enumerate_children (file,
264 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
265 GST_INFO ("%s is not a folder", value);
270 GST_INFO ("Adding folder: %s", value);
271 g_ptr_array_add (new_paths, g_strdup (value));
272 info = g_file_enumerator_next_file (fenum, NULL, NULL);
273 while (info != 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);
282 g_object_unref (info);
283 info = g_file_enumerator_next_file (fenum, NULL, NULL);
287 gst_object_unref (file);
289 gst_object_unref (fenum);
293 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
295 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
297 if (new_paths == NULL)
298 new_paths = g_ptr_array_new_with_free_func (g_free);
301 _add_media_new_paths_recursing (uri);
303 g_ptr_array_add (new_paths, g_strdup (uri));
309 ges_missing_uri_default (GESProject * self, GError * error,
310 GESAsset * wrong_asset)
313 const gchar *old_uri = ges_asset_get_id (wrong_asset);
315 if (new_paths == NULL)
318 if (tried_uris == NULL)
319 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
321 for (i = 0; i < new_paths->len; i++) {
322 gchar *basename, *res;
324 basename = g_path_get_basename (old_uri);
325 res = g_build_filename (new_paths->pdata[i], basename, NULL);
328 if (g_strcmp0 (old_uri, res) == 0) {
329 g_hash_table_add (tried_uris, res);
330 } else if (g_hash_table_lookup (tried_uris, res)) {
331 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
334 g_hash_table_add (tried_uris, g_strdup (res));
335 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
344 ges_uri_assets_validate_uri (const gchar * nid)
347 g_hash_table_remove (tried_uris, nid);
350 /* GObject vmethod implementation */
352 _dispose (GObject * object)
355 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
358 g_hash_table_unref (priv->assets);
359 if (priv->loading_assets)
360 g_hash_table_unref (priv->loading_assets);
361 if (priv->loaded_with_error)
362 g_hash_table_unref (priv->loaded_with_error);
363 if (priv->formatter_asset)
364 gst_object_unref (priv->formatter_asset);
366 for (tmp = priv->formatters; tmp; tmp = tmp->next)
367 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
369 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
373 _finalize (GObject * object)
375 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
380 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
384 _get_property (GESProject * project, guint property_id,
385 GValue * value, GParamSpec * pspec)
387 GESProjectPrivate *priv = project->priv;
389 switch (property_id) {
391 g_value_set_string (value, priv->uri);
394 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
399 _set_property (GESProject * project, guint property_id,
400 const GValue * value, GParamSpec * pspec)
402 switch (property_id) {
404 project->priv->uri = g_value_dup_string (value);
407 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
412 ges_project_class_init (GESProjectClass * klass)
414 GObjectClass *object_class = G_OBJECT_CLASS (klass);
416 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
418 klass->asset_added = NULL;
419 klass->missing_uri = ges_missing_uri_default;
420 klass->loading_error = NULL;
421 klass->asset_removed = NULL;
422 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
423 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
428 * The location of the project to use.
430 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
431 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
433 g_object_class_install_properties (object_class, PROP_LAST, _properties);
436 * GESProject::asset-added:
437 * @formatter: the #GESProject
438 * @asset: The #GESAsset that has been added to @project
440 _signals[ASSET_ADDED_SIGNAL] =
441 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
442 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
443 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
446 * GESProject::asset-removed:
447 * @formatter: the #GESProject
448 * @asset: The #GESAsset that has been removed from @project
450 _signals[ASSET_REMOVED_SIGNAL] =
451 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
452 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
453 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
456 * GESProject::loaded:
457 * @project: the #GESProject that is done loading a project.
458 * @timeline: The #GESTimeline that complete loading
460 _signals[LOADED_SIGNAL] =
461 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
462 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
463 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
464 1, GES_TYPE_TIMELINE);
467 * GESProject::missing-uri:
468 * @project: the #GESProject reporting that a file has moved
469 * @error: The error that happened
470 * @wrong_asset: The asset with the wrong ID, you should us it and its content
471 * only to find out what the new location is.
475 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
477 * return g_strdup ("file:///the/new/uri.ogg");
481 * main (int argc, gchar ** argv)
483 * GESTimeline *timeline;
484 * GESProject *project = ges_project_new ("file:///some/uri.xges");
486 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
487 * timeline = ges_asset_extract (GES_ASSET (project));
491 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
493 _signals[MISSING_URI_SIGNAL] =
494 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
495 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
496 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
497 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
500 * GESProject::error-loading-asset:
501 * @project: the #GESProject on which a problem happend when creted a #GESAsset
502 * @error: The #GError defining the error that accured, might be %NULL
503 * @id: The @id of the asset that failed loading
504 * @extractable_type: The @extractable_type of the asset that
507 * Informs you that a #GESAsset could not be created. In case of
508 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
509 * #GST_CORE_ERROR_MISSING_PLUGIN
511 _signals[ERROR_LOADING_ASSET] =
512 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
513 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
514 NULL, NULL, g_cclosure_marshal_generic,
515 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
517 object_class->dispose = _dispose;
518 object_class->finalize = _finalize;
520 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
524 ges_project_init (GESProject * project)
526 GESProjectPrivate *priv = project->priv =
527 G_TYPE_INSTANCE_GET_PRIVATE (project,
528 GES_TYPE_PROJECT, GESProjectPrivate);
531 priv->formatters = NULL;
532 priv->formatter_asset = NULL;
533 priv->encoding_profiles = NULL;
534 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
535 g_free, gst_object_unref);
536 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
537 g_free, gst_object_unref);
538 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
543 _send_error_loading_asset (GESProject * project, GESAsset * asset,
546 const gchar *id = ges_asset_get_id (asset);
548 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
549 g_hash_table_remove (project->priv->loading_assets, id);
550 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
551 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
552 ges_asset_get_extractable_type (asset));
556 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
559 gchar *new_id = NULL;
562 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
563 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
564 g_return_val_if_fail (error, NULL);
566 id = ges_asset_get_id (asset);
567 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
568 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
569 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
570 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
572 _send_error_loading_asset (project, asset, error);
577 if (new_id == NULL) {
578 GST_DEBUG_OBJECT (project, "Sending 'missing-uri' signal for %s", id);
579 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
584 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
585 if (!ges_asset_set_proxy (asset, new_id)) {
590 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
593 g_hash_table_remove (project->priv->loading_assets, id);
596 _send_error_loading_asset (project, asset, error);
603 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
605 GError *error = NULL;
606 gchar *possible_id = NULL;
607 GESAsset *asset = ges_asset_request_finish (res, &error);
610 possible_id = ges_project_try_updating_id (project, source, error);
612 if (possible_id == NULL)
615 ges_project_create_asset (project, possible_id,
616 ges_asset_get_extractable_type (source));
618 g_free (possible_id);
619 g_error_free (error);
623 ges_project_add_asset (project, asset);
625 gst_object_unref (asset);
629 * ges_project_set_loaded:
630 * @project: The #GESProject from which to emit the "project-loaded" signal
632 * Emits the "loaded" signal. This method should be called by sublasses when
633 * the project is fully loaded.
635 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
638 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
640 GST_INFO_OBJECT (project, "Emit project loaded");
641 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
642 timeline_fill_gaps (formatter->timeline);
644 ges_timeline_commit (formatter->timeline);
647 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
649 /* We are now done with that formatter */
650 ges_project_remove_formatter (project, formatter);
655 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
660 if ((asset = ges_asset_cache_lookup (extractable_type, id)))
661 g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
662 gst_object_ref (asset));
665 /**************************************
667 * API Implementation *
669 **************************************/
672 * ges_project_create_asset:
673 * @project: A #GESProject
674 * @id: (allow-none): The id of the asset to create and add to @project
675 * @extractable_type: The #GType of the asset to create
677 * Create and add a #GESAsset to @project. You should connect to the
678 * "asset-added" signal to get the asset when it finally gets added to
681 * Returns: %TRUE if the asset started to be added %FALSE it was already
685 ges_project_create_asset (GESProject * project, const gchar * id,
686 GType extractable_type)
688 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
689 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
693 id = g_type_name (extractable_type);
695 if (g_hash_table_lookup (project->priv->assets, id) ||
696 g_hash_table_lookup (project->priv->loading_assets, id) ||
697 g_hash_table_lookup (project->priv->loaded_with_error, id))
700 /* TODO Add a GCancellable somewhere in our API */
701 ges_asset_request_async (extractable_type, id, NULL,
702 (GAsyncReadyCallback) new_asset_cb, project);
703 ges_project_add_loading_asset (project, extractable_type, id);
709 * ges_project_create_asset_sync:
710 * @project: A #GESProject
711 * @id: (allow-none): The id of the asset to create and add to @project
712 * @extractable_type: The #GType of the asset to create
713 * @error: A #GError to be set in case of error
715 * Create and add a #GESAsset to @project. You should connect to the
716 * "asset-added" signal to get the asset when it finally gets added to
719 * Returns: The newly created #GESAsset
722 ges_project_create_asset_sync (GESProject * project, const gchar * id,
723 GType extractable_type, GError ** error)
726 gchar *possible_id = NULL;
727 gboolean retry = TRUE;
729 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
730 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
734 id = g_type_name (extractable_type);
736 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
738 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
739 g_hash_table_lookup (project->priv->loaded_with_error, id))
742 /* TODO Add a GCancellable somewhere in our API */
745 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
746 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
748 asset = ges_asset_request (extractable_type, id, error);
755 g_free (possible_id);
756 ges_uri_assets_validate_uri (id);
763 tmpasset = ges_asset_cache_lookup (extractable_type, id);
764 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
766 if (possible_id == NULL)
770 g_clear_error (error);
776 ges_project_add_asset (project, asset);
782 * ges_project_add_asset:
783 * @project: A #GESProject
784 * @asset: (transfer none): A #GESAsset to add to @project
786 * Adds a #Asset to @project, the project will keep a reference on
789 * Returns: %TRUE if the asset could be added %FALSE it was already
793 ges_project_add_asset (GESProject * project, GESAsset * asset)
795 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
797 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
800 g_hash_table_insert (project->priv->assets,
801 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
803 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
804 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
805 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
811 * ges_project_remove_asset:
812 * @project: A #GESProject
813 * @asset: (transfer none): A #GESAsset to remove from @project
815 * remove a @asset to from @project.
817 * Returns: %TRUE if the asset could be removed %FALSE otherwise
820 ges_project_remove_asset (GESProject * project, GESAsset * asset)
824 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
826 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
827 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
833 * ges_project_get_asset:
834 * @project: A #GESProject
835 * @id: The id of the asset to retrieve
836 * @extractable_type: The extractable_type of the asset
837 * to retrieve from @object
839 * Returns: (transfer full) (allow-none): The #GESAsset with
840 * @id or %NULL if no asset with @id as an ID
843 ges_project_get_asset (GESProject * project, const gchar * id,
844 GType extractable_type)
848 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
849 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
852 asset = g_hash_table_lookup (project->priv->assets, id);
855 return gst_object_ref (asset);
861 * ges_project_list_assets:
862 * @project: A #GESProject
863 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
866 * List all @asset contained in @project filtering per extractable_type
867 * as defined by @filter. It copies the asset and thus will not be updated
870 * Returns: (transfer full) (element-type GESAsset): The list of
871 * #GESAsset the object contains
874 ges_project_list_assets (GESProject * project, GType filter)
880 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
882 g_hash_table_iter_init (&iter, project->priv->assets);
883 while (g_hash_table_iter_next (&iter, &key, &value)) {
884 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
886 ret = g_list_append (ret, gst_object_ref (value));
894 * @project: A #GESProject to save
895 * @timeline: The #GESTimeline to save, it must have been extracted from @project
896 * @uri: The uri where to save @project and @timeline
897 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
898 * will try to save in the same format as the one from which the timeline as been loaded
899 * or default to the formatter with highest rank
900 * @overwrite: %TRUE to overwrite file if it exists
901 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
903 * Save the timeline of @project to @uri. You should make sure that @timeline
904 * is one of the timelines that have been extracted from @project
905 * (using ges_asset_extract (@project);)
907 * Returns: %TRUE if the project could be save, %FALSE otherwize
910 ges_project_save (GESProject * project, GESTimeline * timeline,
911 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
916 GESFormatter *formatter = NULL;
918 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
919 g_return_val_if_fail (formatter_asset == NULL ||
920 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
921 GES_TYPE_FORMATTER), FALSE);
922 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
924 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
925 if (tl_asset == NULL && project->priv->uri == NULL) {
926 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
929 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
930 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
934 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
935 " we have no uri set, so setting ourself as asset", timeline);
937 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
938 } else if (tl_asset != GES_ASSET (project)) {
939 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
940 " not created by this project can not save", timeline);
946 if (formatter_asset == NULL)
947 formatter_asset = gst_object_ref (ges_formatter_get_default ());
949 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
950 if (formatter == NULL) {
951 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
952 formatter_asset, ges_asset_get_id (formatter_asset),
953 (error && *error) ? (*error)->message : "Unknown Error");
959 ges_project_add_formatter (project, formatter);
960 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
961 if (ret && project->priv->uri == NULL)
962 ges_project_set_uri (project, uri);
966 gst_object_unref (formatter_asset);
967 ges_project_remove_formatter (project, formatter);
974 * @uri: (allow-none): The uri to be set after creating the project.
976 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
977 * if @uri is not valid or %NULL, the uri of the project will then be set
978 * the first time you save the project. If you then save the project to
979 * other locations, it will never be updated again and the first valid URI is
980 * the URI it will keep refering to.
982 * Returns: A newly created #GESProject
985 ges_project_new (const gchar * uri)
987 gchar *id = (gchar *) uri;
991 id = g_strdup_printf ("project-%i", nb_projects++);
993 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
996 ges_project_set_uri (project, uri);
1006 * @project: A #GESProject that has an @uri set already
1007 * @timeline: A blank timeline to load @project into
1008 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1010 * Loads @project into @timeline
1012 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1015 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1017 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1018 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1019 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1020 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1022 if (!_load_project (project, timeline, error))
1025 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1031 * ges_project_get_uri:
1032 * @project: A #GESProject
1034 * Retrieve the uri that is currently set on @project
1036 * Returns: The uri that is set on @project
1039 ges_project_get_uri (GESProject * project)
1041 GESProjectPrivate *priv;
1043 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1045 priv = project->priv;
1047 return g_strdup (priv->uri);
1052 * ges_project_add_encoding_profile:
1053 * @project: A #GESProject
1054 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1055 * the same name already exists, it will be replaced
1057 * Adds @profile to the project. It lets you save in what format
1058 * the project has been renders and keep a reference to those formats.
1059 * Also, those formats will be saves to the project file when possible.
1061 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1064 ges_project_add_encoding_profile (GESProject * project,
1065 GstEncodingProfile * profile)
1068 GESProjectPrivate *priv;
1070 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1071 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1073 priv = project->priv;
1074 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1075 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1077 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1078 gst_encoding_profile_get_name (profile)) == 0) {
1079 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1080 gst_encoding_profile_get_name (profile));
1082 gst_object_unref (tmp->data);
1083 tmp->data = gst_object_ref (profile);
1088 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1089 gst_object_ref (profile));
1095 * ges_project_list_encoding_profiles:
1096 * @project: A #GESProject
1098 * Lists the encoding profile that have been set to @project. The first one
1099 * is the latest added.
1101 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1102 * list of #GstEncodingProfile used in @project
1105 ges_project_list_encoding_profiles (GESProject * project)
1107 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1109 return project->priv->encoding_profiles;
1113 * ges_project_get_loading_assets:
1114 * @project: A #GESProject
1116 * Get the assets that are being loaded
1118 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1119 * that will be added to @project. Note that those Asset are *not* loaded yet,
1120 * and thus can not be used
1123 ges_project_get_loading_assets (GESProject * project)
1125 GHashTableIter iter;
1126 gpointer key, value;
1130 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1132 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1133 while (g_hash_table_iter_next (&iter, &key, &value))
1134 ret = g_list_prepend (ret, gst_object_ref (value));