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;
89 static guint _signals[LAST_SIGNAL] = { 0 };
91 static guint nb_projects = 0;
100 static GParamSpec *_properties[LAST_SIGNAL] = { 0 };
103 _emit_loaded_in_idle (EmitLoadedInIdle * data)
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");
156 GST_LOG_OBJECT (project, "Uri should not be NULL");
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_id (priv->uri);
195 if (priv->formatter_asset == NULL) {
196 lerr = g_error_new (GES_ERROR, 0, "Could not find a suitable formatter");
200 formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr));
202 GST_WARNING_OBJECT (project, "Could not create the formatter: %s",
208 ges_project_add_formatter (GES_PROJECT (project), formatter);
209 ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr);
211 GST_WARNING_OBJECT (project, "Could not load the timeline,"
212 " returning: %s", lerr->message);
220 g_propagate_error (error, lerr);
225 _uri_missing_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
226 const GValue * handler_return, gpointer data)
228 const gchar *ret = g_value_get_string (handler_return);
231 if (!gst_uri_is_valid (ret)) {
232 GST_INFO ("The uri %s was not valid, can not work with it!", ret);
236 g_value_set_string (return_accu, ret);
243 /* GESAsset vmethod implementation */
244 static GESExtractable *
245 ges_project_extract (GESAsset * project, GError ** error)
247 GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL);
249 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
250 if (_load_project (GES_PROJECT (project), timeline, error))
251 return GES_EXTRACTABLE (timeline);
253 gst_object_unref (timeline);
258 _add_media_new_paths_recursing (const gchar * value)
261 GFileEnumerator *fenum;
262 GFile *file = g_file_new_for_uri (value);
264 if (!(fenum = g_file_enumerate_children (file,
265 "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
266 GST_INFO ("%s is not a folder", value);
271 GST_INFO ("Adding folder: %s", value);
272 g_ptr_array_add (new_paths, g_strdup (value));
273 info = g_file_enumerator_next_file (fenum, NULL, NULL);
274 while (info != NULL) {
275 if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
276 GFile *f = g_file_enumerator_get_child (fenum, info);
277 gchar *uri = g_file_get_uri (f);
279 _add_media_new_paths_recursing (uri);
280 gst_object_unref (f);
283 g_object_unref (info);
284 info = g_file_enumerator_next_file (fenum, NULL, NULL);
288 gst_object_unref (file);
290 gst_object_unref (fenum);
294 ges_add_missing_uri_relocation_uri (const gchar * uri, gboolean recurse)
296 g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
298 if (new_paths == NULL)
299 new_paths = g_ptr_array_new_with_free_func (g_free);
302 _add_media_new_paths_recursing (uri);
304 g_ptr_array_add (new_paths, g_strdup (uri));
310 ges_missing_uri_default (GESProject * self, GError * error,
311 GESAsset * wrong_asset)
314 const gchar *old_uri = ges_asset_get_id (wrong_asset);
316 if (new_paths == NULL)
319 if (tried_uris == NULL)
320 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
322 for (i = 0; i < new_paths->len; i++) {
323 gchar *basename, *res;
325 basename = g_path_get_basename (old_uri);
326 res = g_build_filename (new_paths->pdata[i], basename, NULL);
329 if (g_strcmp0 (old_uri, res) == 0) {
330 g_hash_table_add (tried_uris, res);
331 } else if (g_hash_table_lookup (tried_uris, res)) {
332 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
335 g_hash_table_add (tried_uris, g_strdup (res));
336 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
345 ges_uri_assets_validate_uri (const gchar * nid)
348 g_hash_table_remove (tried_uris, nid);
351 /* GObject vmethod implementation */
353 _dispose (GObject * object)
356 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
359 g_hash_table_unref (priv->assets);
360 if (priv->loading_assets)
361 g_hash_table_unref (priv->loading_assets);
362 if (priv->loaded_with_error)
363 g_hash_table_unref (priv->loaded_with_error);
364 if (priv->formatter_asset)
365 gst_object_unref (priv->formatter_asset);
367 for (tmp = priv->formatters; tmp; tmp = tmp->next)
368 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
370 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
374 _finalize (GObject * object)
376 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
381 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
385 _get_property (GESProject * project, guint property_id,
386 GValue * value, GParamSpec * pspec)
388 GESProjectPrivate *priv = project->priv;
390 switch (property_id) {
392 g_value_set_string (value, priv->uri);
395 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
400 _set_property (GESProject * project, guint property_id,
401 const GValue * value, GParamSpec * pspec)
403 switch (property_id) {
405 project->priv->uri = g_value_dup_string (value);
408 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
413 ges_project_class_init (GESProjectClass * klass)
415 GObjectClass *object_class = G_OBJECT_CLASS (klass);
417 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
419 klass->asset_added = NULL;
420 klass->missing_uri = ges_missing_uri_default;
421 klass->loading_error = NULL;
422 klass->asset_removed = NULL;
423 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
424 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
429 * The location of the project to use.
431 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
432 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
434 g_object_class_install_properties (object_class, PROP_LAST, _properties);
437 * GESProject::asset-added:
438 * @project: the #GESProject
439 * @asset: The #GESAsset that has been added to @project
441 _signals[ASSET_ADDED_SIGNAL] =
442 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
443 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
444 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
447 * GESProject::asset-loading:
448 * @project: the #GESProject
449 * @asset: The #GESAsset that started loading
453 _signals[ASSET_LOADING_SIGNAL] =
454 g_signal_new ("asset-loading", G_TYPE_FROM_CLASS (klass),
455 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_loading),
456 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
459 * GESProject::asset-removed:
460 * @project: the #GESProject
461 * @asset: The #GESAsset that has been removed from @project
463 _signals[ASSET_REMOVED_SIGNAL] =
464 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
465 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
466 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
469 * GESProject::loaded:
470 * @project: the #GESProject that is done loading a project.
471 * @timeline: The #GESTimeline that complete loading
473 _signals[LOADED_SIGNAL] =
474 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
475 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
476 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
477 1, GES_TYPE_TIMELINE);
480 * GESProject::missing-uri:
481 * @project: the #GESProject reporting that a file has moved
482 * @error: The error that happened
483 * @wrong_asset: The asset with the wrong ID, you should us it and its content
484 * only to find out what the new location is.
488 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
490 * return g_strdup ("file:///the/new/uri.ogg");
494 * main (int argc, gchar ** argv)
496 * GESTimeline *timeline;
497 * GESProject *project = ges_project_new ("file:///some/uri.xges");
499 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
500 * timeline = ges_asset_extract (GES_ASSET (project));
504 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
506 _signals[MISSING_URI_SIGNAL] =
507 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
508 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
509 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
510 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
513 * GESProject::error-loading-asset:
514 * @project: the #GESProject on which a problem happend when creted a #GESAsset
515 * @error: The #GError defining the error that accured, might be %NULL
516 * @id: The @id of the asset that failed loading
517 * @extractable_type: The @extractable_type of the asset that
520 * Informs you that a #GESAsset could not be created. In case of
521 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
522 * #GST_CORE_ERROR_MISSING_PLUGIN
524 _signals[ERROR_LOADING_ASSET] =
525 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
526 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
527 NULL, NULL, g_cclosure_marshal_generic,
528 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
530 object_class->dispose = _dispose;
531 object_class->finalize = _finalize;
533 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
537 ges_project_init (GESProject * project)
539 GESProjectPrivate *priv = project->priv =
540 G_TYPE_INSTANCE_GET_PRIVATE (project,
541 GES_TYPE_PROJECT, GESProjectPrivate);
544 priv->formatters = NULL;
545 priv->formatter_asset = NULL;
546 priv->encoding_profiles = NULL;
547 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
548 g_free, gst_object_unref);
549 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
550 g_free, gst_object_unref);
551 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
556 _send_error_loading_asset (GESProject * project, GESAsset * asset,
559 const gchar *id = ges_asset_get_id (asset);
561 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
562 g_hash_table_remove (project->priv->loading_assets, id);
563 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
564 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
565 ges_asset_get_extractable_type (asset));
569 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
572 gchar *new_id = NULL;
575 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
576 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
577 g_return_val_if_fail (error, NULL);
579 id = ges_asset_get_id (asset);
580 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
581 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
582 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
583 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
585 _send_error_loading_asset (project, asset, error);
590 if (new_id == NULL) {
591 GST_DEBUG_OBJECT (project, "Sending 'missing-uri' signal for %s", id);
592 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
597 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
598 if (!ges_asset_try_proxy (asset, new_id)) {
603 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
606 g_hash_table_remove (project->priv->loading_assets, id);
609 _send_error_loading_asset (project, asset, error);
616 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
618 GError *error = NULL;
619 gchar *possible_id = NULL;
620 GESAsset *asset = ges_asset_request_finish (res, &error);
623 possible_id = ges_project_try_updating_id (project, source, error);
625 if (possible_id == NULL)
628 ges_project_create_asset (project, possible_id,
629 ges_asset_get_extractable_type (source));
631 g_free (possible_id);
632 g_error_free (error);
636 ges_asset_set_proxy (NULL, asset);
637 ges_project_add_asset (project, asset);
639 gst_object_unref (asset);
643 * ges_project_set_loaded:
644 * @project: The #GESProject from which to emit the "project-loaded" signal
646 * Emits the "loaded" signal. This method should be called by sublasses when
647 * the project is fully loaded.
649 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
652 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
654 GST_INFO_OBJECT (project, "Emit project loaded");
655 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
656 timeline_fill_gaps (formatter->timeline);
658 ges_timeline_commit (formatter->timeline);
661 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
663 /* We are now done with that formatter */
664 ges_project_remove_formatter (project, formatter);
669 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
674 if ((asset = ges_asset_cache_lookup (extractable_type, id))) {
675 if (g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
676 gst_object_ref (asset)))
677 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
681 /**************************************
683 * API Implementation *
685 **************************************/
688 * ges_project_create_asset:
689 * @project: A #GESProject
690 * @id: (allow-none): The id of the asset to create and add to @project
691 * @extractable_type: The #GType of the asset to create
693 * Create and add a #GESAsset to @project. You should connect to the
694 * "asset-added" signal to get the asset when it finally gets added to
697 * Returns: %TRUE if the asset started to be added %FALSE it was already
701 ges_project_create_asset (GESProject * project, const gchar * id,
702 GType extractable_type)
704 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
705 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
709 id = g_type_name (extractable_type);
711 if (g_hash_table_lookup (project->priv->assets, id) ||
712 g_hash_table_lookup (project->priv->loading_assets, id) ||
713 g_hash_table_lookup (project->priv->loaded_with_error, id))
716 /* TODO Add a GCancellable somewhere in our API */
717 ges_asset_request_async (extractable_type, id, NULL,
718 (GAsyncReadyCallback) new_asset_cb, project);
719 ges_project_add_loading_asset (project, extractable_type, id);
725 * ges_project_create_asset_sync:
726 * @project: A #GESProject
727 * @id: (allow-none): The id of the asset to create and add to @project
728 * @extractable_type: The #GType of the asset to create
729 * @error: A #GError to be set in case of error
731 * Create and add a #GESAsset to @project. You should connect to the
732 * "asset-added" signal to get the asset when it finally gets added to
735 * Returns: The newly created #GESAsset
738 ges_project_create_asset_sync (GESProject * project, const gchar * id,
739 GType extractable_type, GError ** error)
742 gchar *possible_id = NULL;
743 gboolean retry = TRUE;
745 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
746 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
750 id = g_type_name (extractable_type);
752 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
754 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
755 g_hash_table_lookup (project->priv->loaded_with_error, id))
758 /* TODO Add a GCancellable somewhere in our API */
761 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
762 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
764 asset = ges_asset_request (extractable_type, id, error);
770 if ((!g_hash_table_lookup (project->priv->assets,
771 ges_asset_get_id (asset))))
772 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
775 g_free (possible_id);
776 ges_uri_assets_validate_uri (id);
783 tmpasset = ges_asset_cache_lookup (extractable_type, id);
784 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, tmpasset);
785 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, *error, id,
787 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
789 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: The uri that is set on @project
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));