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);
316 gchar *new_id = NULL;
318 if (ges_asset_request_id_update (wrong_asset, &new_id, error) && new_id) {
319 GST_INFO_OBJECT (self, "Returned guessed new ID: %s", new_id);
324 if (new_paths == NULL)
327 if (tried_uris == NULL)
328 tried_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
330 for (i = 0; i < new_paths->len; i++) {
331 gchar *basename, *res;
333 basename = g_path_get_basename (old_uri);
334 res = g_build_filename (new_paths->pdata[i], basename, NULL);
337 if (g_strcmp0 (old_uri, res) == 0) {
338 g_hash_table_add (tried_uris, res);
339 } else if (g_hash_table_lookup (tried_uris, res)) {
340 GST_DEBUG_OBJECT (self, "File already tried: %s", res);
343 g_hash_table_add (tried_uris, g_strdup (res));
344 GST_DEBUG_OBJECT (self, "Trying: %s\n", res);
353 ges_uri_assets_validate_uri (const gchar * nid)
356 g_hash_table_remove (tried_uris, nid);
359 /* GObject vmethod implementation */
361 _dispose (GObject * object)
364 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
367 g_hash_table_unref (priv->assets);
368 if (priv->loading_assets)
369 g_hash_table_unref (priv->loading_assets);
370 if (priv->loaded_with_error)
371 g_hash_table_unref (priv->loaded_with_error);
372 if (priv->formatter_asset)
373 gst_object_unref (priv->formatter_asset);
375 for (tmp = priv->formatters; tmp; tmp = tmp->next)
376 ges_project_remove_formatter (GES_PROJECT (object), tmp->data);;
378 G_OBJECT_CLASS (ges_project_parent_class)->dispose (object);
382 _finalize (GObject * object)
384 GESProjectPrivate *priv = GES_PROJECT (object)->priv;
389 G_OBJECT_CLASS (ges_project_parent_class)->finalize (object);
393 _get_property (GESProject * project, guint property_id,
394 GValue * value, GParamSpec * pspec)
396 GESProjectPrivate *priv = project->priv;
398 switch (property_id) {
400 g_value_set_string (value, priv->uri);
403 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
408 _set_property (GESProject * project, guint property_id,
409 const GValue * value, GParamSpec * pspec)
411 switch (property_id) {
413 project->priv->uri = g_value_dup_string (value);
416 G_OBJECT_WARN_INVALID_PROPERTY_ID (project, property_id, pspec);
421 ges_project_class_init (GESProjectClass * klass)
423 GObjectClass *object_class = G_OBJECT_CLASS (klass);
425 g_type_class_add_private (klass, sizeof (GESProjectPrivate));
427 klass->asset_added = NULL;
428 klass->missing_uri = ges_missing_uri_default;
429 klass->loading_error = NULL;
430 klass->asset_removed = NULL;
431 object_class->get_property = (GObjectGetPropertyFunc) _get_property;
432 object_class->set_property = (GObjectSetPropertyFunc) _set_property;
437 * The location of the project to use.
439 _properties[PROP_URI] = g_param_spec_string ("uri", "URI",
440 "uri of the project", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
442 g_object_class_install_properties (object_class, PROP_LAST, _properties);
445 * GESProject::asset-added:
446 * @project: the #GESProject
447 * @asset: The #GESAsset that has been added to @project
449 _signals[ASSET_ADDED_SIGNAL] =
450 g_signal_new ("asset-added", G_TYPE_FROM_CLASS (klass),
451 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_added),
452 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
455 * GESProject::asset-loading:
456 * @project: the #GESProject
457 * @asset: The #GESAsset that started loading
461 _signals[ASSET_LOADING_SIGNAL] =
462 g_signal_new ("asset-loading", G_TYPE_FROM_CLASS (klass),
463 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_loading),
464 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
467 * GESProject::asset-removed:
468 * @project: the #GESProject
469 * @asset: The #GESAsset that has been removed from @project
471 _signals[ASSET_REMOVED_SIGNAL] =
472 g_signal_new ("asset-removed", G_TYPE_FROM_CLASS (klass),
473 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, asset_removed),
474 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_ASSET);
477 * GESProject::loaded:
478 * @project: the #GESProject that is done loading a project.
479 * @timeline: The #GESTimeline that complete loading
481 _signals[LOADED_SIGNAL] =
482 g_signal_new ("loaded", G_TYPE_FROM_CLASS (klass),
483 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESProjectClass, loaded),
484 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
485 1, GES_TYPE_TIMELINE);
488 * GESProject::missing-uri:
489 * @project: the #GESProject reporting that a file has moved
490 * @error: The error that happened
491 * @wrong_asset: The asset with the wrong ID, you should us it and its content
492 * only to find out what the new location is.
496 * source_moved_cb (GESProject *project, GError *error, GESAsset *asset_with_error)
498 * return g_strdup ("file:///the/new/uri.ogg");
502 * main (int argc, gchar ** argv)
504 * GESTimeline *timeline;
505 * GESProject *project = ges_project_new ("file:///some/uri.xges");
507 * g_signal_connect (project, "missing-uri", source_moved_cb, NULL);
508 * timeline = ges_asset_extract (GES_ASSET (project));
512 * Returns: (transfer full) (allow-none): The new URI of @wrong_asset
514 _signals[MISSING_URI_SIGNAL] =
515 g_signal_new ("missing-uri", G_TYPE_FROM_CLASS (klass),
516 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, missing_uri),
517 _uri_missing_accumulator, NULL, g_cclosure_marshal_generic,
518 G_TYPE_STRING, 2, G_TYPE_ERROR, GES_TYPE_ASSET);
521 * GESProject::error-loading-asset:
522 * @project: the #GESProject on which a problem happend when creted a #GESAsset
523 * @error: The #GError defining the error that accured, might be %NULL
524 * @id: The @id of the asset that failed loading
525 * @extractable_type: The @extractable_type of the asset that
528 * Informs you that a #GESAsset could not be created. In case of
529 * missing GStreamer plugins, the error will be set to #GST_CORE_ERROR
530 * #GST_CORE_ERROR_MISSING_PLUGIN
532 _signals[ERROR_LOADING_ASSET] =
533 g_signal_new ("error-loading-asset", G_TYPE_FROM_CLASS (klass),
534 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESProjectClass, loading_error),
535 NULL, NULL, g_cclosure_marshal_generic,
536 G_TYPE_NONE, 3, G_TYPE_ERROR, G_TYPE_STRING, G_TYPE_GTYPE);
538 object_class->dispose = _dispose;
539 object_class->finalize = _finalize;
541 GES_ASSET_CLASS (klass)->extract = ges_project_extract;
545 ges_project_init (GESProject * project)
547 GESProjectPrivate *priv = project->priv =
548 G_TYPE_INSTANCE_GET_PRIVATE (project,
549 GES_TYPE_PROJECT, GESProjectPrivate);
552 priv->formatters = NULL;
553 priv->formatter_asset = NULL;
554 priv->encoding_profiles = NULL;
555 priv->assets = g_hash_table_new_full (g_str_hash, g_str_equal,
556 g_free, gst_object_unref);
557 priv->loading_assets = g_hash_table_new_full (g_str_hash, g_str_equal,
558 g_free, gst_object_unref);
559 priv->loaded_with_error = g_hash_table_new_full (g_str_hash, g_str_equal,
564 _send_error_loading_asset (GESProject * project, GESAsset * asset,
567 const gchar *id = ges_asset_get_id (asset);
569 GST_DEBUG_OBJECT (project, "Sending error loading asset for %s", id);
570 g_hash_table_remove (project->priv->loading_assets, id);
571 g_hash_table_add (project->priv->loaded_with_error, g_strdup (id));
572 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, error, id,
573 ges_asset_get_extractable_type (asset));
577 ges_project_try_updating_id (GESProject * project, GESAsset * asset,
580 gchar *new_id = NULL;
583 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
584 g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
585 g_return_val_if_fail (error, NULL);
587 id = ges_asset_get_id (asset);
588 GST_DEBUG_OBJECT (project, "Try to proxy %s", id);
589 if (ges_asset_request_id_update (asset, &new_id, error) == FALSE) {
590 GST_DEBUG_OBJECT (project, "Type: %s can not be proxied for id: %s "
591 "and error: %s", g_type_name (G_OBJECT_TYPE (asset)), id,
593 _send_error_loading_asset (project, asset, error);
598 /* Always send the MISSING_URI signal if requesting new ID is possible
599 * so that subclasses of GESProject are aware of the missing-uri */
600 g_signal_emit (project, _signals[MISSING_URI_SIGNAL], 0, error, asset,
604 GST_DEBUG_OBJECT (project, "new id found: %s", new_id);
605 if (!ges_asset_try_proxy (asset, new_id)) {
610 GST_DEBUG_OBJECT (project, "No new id found for %s", id);
613 g_hash_table_remove (project->priv->loading_assets, id);
616 _send_error_loading_asset (project, asset, error);
623 new_asset_cb (GESAsset * source, GAsyncResult * res, GESProject * project)
625 GError *error = NULL;
626 gchar *possible_id = NULL;
627 GESAsset *asset = ges_asset_request_finish (res, &error);
630 possible_id = ges_project_try_updating_id (project, source, error);
632 if (possible_id == NULL)
635 ges_project_create_asset (project, possible_id,
636 ges_asset_get_extractable_type (source));
638 g_free (possible_id);
639 g_error_free (error);
643 ges_asset_set_proxy (NULL, asset);
644 ges_project_add_asset (project, asset);
646 gst_object_unref (asset);
650 * ges_project_set_loaded:
651 * @project: The #GESProject from which to emit the "project-loaded" signal
653 * Emits the "loaded" signal. This method should be called by sublasses when
654 * the project is fully loaded.
656 * Returns: %TRUE if the signale could be emitted %FALSE otherwize
659 ges_project_set_loaded (GESProject * project, GESFormatter * formatter)
661 GST_INFO_OBJECT (project, "Emit project loaded");
662 if (GST_STATE (formatter->timeline) < GST_STATE_PAUSED) {
663 timeline_fill_gaps (formatter->timeline);
665 ges_timeline_commit (formatter->timeline);
668 g_signal_emit (project, _signals[LOADED_SIGNAL], 0, formatter->timeline);
670 /* We are now done with that formatter */
671 ges_project_remove_formatter (project, formatter);
676 ges_project_add_loading_asset (GESProject * project, GType extractable_type,
681 if ((asset = ges_asset_cache_lookup (extractable_type, id))) {
682 if (g_hash_table_insert (project->priv->loading_assets, g_strdup (id),
683 gst_object_ref (asset)))
684 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
688 /**************************************
690 * API Implementation *
692 **************************************/
695 * ges_project_create_asset:
696 * @project: A #GESProject
697 * @id: (allow-none): The id of the asset to create and add to @project
698 * @extractable_type: The #GType of the asset to create
700 * Create and add a #GESAsset to @project. You should connect to the
701 * "asset-added" signal to get the asset when it finally gets added to
704 * Returns: %TRUE if the asset started to be added %FALSE it was already
708 ges_project_create_asset (GESProject * project, const gchar * id,
709 GType extractable_type)
711 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
712 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
716 id = g_type_name (extractable_type);
718 if (g_hash_table_lookup (project->priv->assets, id) ||
719 g_hash_table_lookup (project->priv->loading_assets, id) ||
720 g_hash_table_lookup (project->priv->loaded_with_error, id))
723 /* TODO Add a GCancellable somewhere in our API */
724 ges_asset_request_async (extractable_type, id, NULL,
725 (GAsyncReadyCallback) new_asset_cb, project);
726 ges_project_add_loading_asset (project, extractable_type, id);
732 * ges_project_create_asset_sync:
733 * @project: A #GESProject
734 * @id: (allow-none): The id of the asset to create and add to @project
735 * @extractable_type: The #GType of the asset to create
736 * @error: A #GError to be set in case of error
738 * Create and add a #GESAsset to @project. You should connect to the
739 * "asset-added" signal to get the asset when it finally gets added to
742 * Returns: (transfer full) (nullable): The newly created #GESAsset or %NULL.
745 ges_project_create_asset_sync (GESProject * project, const gchar * id,
746 GType extractable_type, GError ** error)
749 gchar *possible_id = NULL;
750 gboolean retry = TRUE;
752 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
753 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
757 id = g_type_name (extractable_type);
759 if ((asset = g_hash_table_lookup (project->priv->assets, id)))
761 else if (g_hash_table_lookup (project->priv->loading_assets, id) ||
762 g_hash_table_lookup (project->priv->loaded_with_error, id))
765 /* TODO Add a GCancellable somewhere in our API */
768 if (g_type_is_a (extractable_type, GES_TYPE_URI_CLIP)) {
769 asset = GES_ASSET (ges_uri_clip_asset_request_sync (id, error));
771 asset = ges_asset_request (extractable_type, id, error);
777 if ((!g_hash_table_lookup (project->priv->assets,
778 ges_asset_get_id (asset))))
779 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, asset);
782 g_free (possible_id);
783 ges_uri_assets_validate_uri (id);
790 tmpasset = ges_asset_cache_lookup (extractable_type, id);
791 possible_id = ges_project_try_updating_id (project, tmpasset, *error);
793 if (possible_id == NULL) {
794 g_signal_emit (project, _signals[ASSET_LOADING_SIGNAL], 0, tmpasset);
795 g_signal_emit (project, _signals[ERROR_LOADING_ASSET], 0, *error, id,
801 g_clear_error (error);
807 if (!ges_asset_get_proxy_target (asset))
808 ges_asset_set_proxy (NULL, asset);
810 ges_project_add_asset (project, asset);
816 * ges_project_add_asset:
817 * @project: A #GESProject
818 * @asset: (transfer none): A #GESAsset to add to @project
820 * Adds a #Asset to @project, the project will keep a reference on
823 * Returns: %TRUE if the asset could be added %FALSE it was already
827 ges_project_add_asset (GESProject * project, GESAsset * asset)
829 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
831 if (g_hash_table_lookup (project->priv->assets, ges_asset_get_id (asset)))
834 g_hash_table_insert (project->priv->assets,
835 g_strdup (ges_asset_get_id (asset)), gst_object_ref (asset));
837 g_hash_table_remove (project->priv->loading_assets, ges_asset_get_id (asset));
838 GST_DEBUG_OBJECT (project, "Asset added: %s", ges_asset_get_id (asset));
839 g_signal_emit (project, _signals[ASSET_ADDED_SIGNAL], 0, asset);
845 * ges_project_remove_asset:
846 * @project: A #GESProject
847 * @asset: (transfer none): A #GESAsset to remove from @project
849 * remove a @asset to from @project.
851 * Returns: %TRUE if the asset could be removed %FALSE otherwise
854 ges_project_remove_asset (GESProject * project, GESAsset * asset)
858 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
860 ret = g_hash_table_remove (project->priv->assets, ges_asset_get_id (asset));
861 g_signal_emit (project, _signals[ASSET_REMOVED_SIGNAL], 0, asset);
867 * ges_project_get_asset:
868 * @project: A #GESProject
869 * @id: The id of the asset to retrieve
870 * @extractable_type: The extractable_type of the asset
871 * to retrieve from @object
873 * Returns: (transfer full) (allow-none): The #GESAsset with
874 * @id or %NULL if no asset with @id as an ID
877 ges_project_get_asset (GESProject * project, const gchar * id,
878 GType extractable_type)
882 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
883 g_return_val_if_fail (g_type_is_a (extractable_type, GES_TYPE_EXTRACTABLE),
886 asset = g_hash_table_lookup (project->priv->assets, id);
889 return gst_object_ref (asset);
895 * ges_project_list_assets:
896 * @project: A #GESProject
897 * @filter: Type of assets to list, #GES_TYPE_EXTRACTABLE will list
900 * List all @asset contained in @project filtering per extractable_type
901 * as defined by @filter. It copies the asset and thus will not be updated
904 * Returns: (transfer full) (element-type GESAsset): The list of
905 * #GESAsset the object contains
908 ges_project_list_assets (GESProject * project, GType filter)
914 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
916 g_hash_table_iter_init (&iter, project->priv->assets);
917 while (g_hash_table_iter_next (&iter, &key, &value)) {
918 if (g_type_is_a (ges_asset_get_extractable_type (GES_ASSET (value)),
920 ret = g_list_append (ret, gst_object_ref (value));
928 * @project: A #GESProject to save
929 * @timeline: The #GESTimeline to save, it must have been extracted from @project
930 * @uri: The uri where to save @project and @timeline
931 * @formatter_asset: (allow-none): The formatter asset to use or %NULL. If %NULL,
932 * will try to save in the same format as the one from which the timeline as been loaded
933 * or default to the formatter with highest rank
934 * @overwrite: %TRUE to overwrite file if it exists
935 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
937 * Save the timeline of @project to @uri. You should make sure that @timeline
938 * is one of the timelines that have been extracted from @project
939 * (using ges_asset_extract (@project);)
941 * Returns: %TRUE if the project could be save, %FALSE otherwize
944 ges_project_save (GESProject * project, GESTimeline * timeline,
945 const gchar * uri, GESAsset * formatter_asset, gboolean overwrite,
950 GESFormatter *formatter = NULL;
952 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
953 g_return_val_if_fail (formatter_asset == NULL ||
954 g_type_is_a (ges_asset_get_extractable_type (formatter_asset),
955 GES_TYPE_FORMATTER), FALSE);
956 g_return_val_if_fail ((error == NULL || *error == NULL), FALSE);
958 tl_asset = ges_extractable_get_asset (GES_EXTRACTABLE (timeline));
959 if (tl_asset == NULL && project->priv->uri == NULL) {
960 GESAsset *asset = ges_asset_cache_lookup (GES_TYPE_PROJECT, uri);
963 GST_WARNING_OBJECT (project, "Trying to save project to %s but we already"
964 "have %" GST_PTR_FORMAT " for that uri, can not save", uri, asset);
968 GST_DEBUG_OBJECT (project, "Timeline %" GST_PTR_FORMAT " has no asset"
969 " we have no uri set, so setting ourself as asset", timeline);
971 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
972 } else if (tl_asset != GES_ASSET (project)) {
973 GST_WARNING_OBJECT (project, "Timeline %" GST_PTR_FORMAT
974 " not created by this project can not save", timeline);
980 if (formatter_asset == NULL)
981 formatter_asset = gst_object_ref (ges_formatter_get_default ());
983 formatter = GES_FORMATTER (ges_asset_extract (formatter_asset, error));
984 if (formatter == NULL) {
985 GST_WARNING_OBJECT (project, "Could not create the formatter %p %s: %s",
986 formatter_asset, ges_asset_get_id (formatter_asset),
987 (error && *error) ? (*error)->message : "Unknown Error");
993 ges_project_add_formatter (project, formatter);
994 ret = ges_formatter_save_to_uri (formatter, timeline, uri, overwrite, error);
995 if (ret && project->priv->uri == NULL)
996 ges_project_set_uri (project, uri);
1000 gst_object_unref (formatter_asset);
1001 ges_project_remove_formatter (project, formatter);
1008 * @uri: (allow-none): The uri to be set after creating the project.
1010 * Creates a new #GESProject and sets its uri to @uri if provided. Note that
1011 * if @uri is not valid or %NULL, the uri of the project will then be set
1012 * the first time you save the project. If you then save the project to
1013 * other locations, it will never be updated again and the first valid URI is
1014 * the URI it will keep refering to.
1016 * Returns: A newly created #GESProject
1019 ges_project_new (const gchar * uri)
1021 gchar *id = (gchar *) uri;
1022 GESProject *project;
1025 id = g_strdup_printf ("project-%i", nb_projects++);
1027 project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL));
1030 ges_project_set_uri (project, uri);
1040 * @project: A #GESProject that has an @uri set already
1041 * @timeline: A blank timeline to load @project into
1042 * @error: (out) (allow-none): An error to be set in case something wrong happens or %NULL
1044 * Loads @project into @timeline
1046 * Returns: %TRUE if the project could be loaded %FALSE otherwize.
1049 ges_project_load (GESProject * project, GESTimeline * timeline, GError ** error)
1051 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
1052 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1053 g_return_val_if_fail (ges_project_get_uri (project), FALSE);
1054 g_return_val_if_fail (timeline->tracks == NULL, FALSE);
1056 if (!_load_project (project, timeline, error))
1059 ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project));
1065 * ges_project_get_uri:
1066 * @project: A #GESProject
1068 * Retrieve the uri that is currently set on @project
1070 * Returns: (transfer full) (nullable): a newly allocated string representing uri.
1073 ges_project_get_uri (GESProject * project)
1075 GESProjectPrivate *priv;
1077 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1079 priv = project->priv;
1081 return g_strdup (priv->uri);
1086 * ges_project_add_encoding_profile:
1087 * @project: A #GESProject
1088 * @profile: A #GstEncodingProfile to add to the project. If a profile with
1089 * the same name already exists, it will be replaced
1091 * Adds @profile to the project. It lets you save in what format
1092 * the project has been renders and keep a reference to those formats.
1093 * Also, those formats will be saves to the project file when possible.
1095 * Returns: %TRUE if @profile could be added, %FALSE otherwize
1098 ges_project_add_encoding_profile (GESProject * project,
1099 GstEncodingProfile * profile)
1102 GESProjectPrivate *priv;
1104 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1105 g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), FALSE);
1107 priv = project->priv;
1108 for (tmp = priv->encoding_profiles; tmp; tmp = tmp->next) {
1109 GstEncodingProfile *tmpprofile = GST_ENCODING_PROFILE (tmp->data);
1111 if (g_strcmp0 (gst_encoding_profile_get_name (tmpprofile),
1112 gst_encoding_profile_get_name (profile)) == 0) {
1113 GST_INFO_OBJECT (project, "Already have profile: %s, replacing it",
1114 gst_encoding_profile_get_name (profile));
1116 gst_object_unref (tmp->data);
1117 tmp->data = gst_object_ref (profile);
1122 priv->encoding_profiles = g_list_prepend (priv->encoding_profiles,
1123 gst_object_ref (profile));
1129 * ges_project_list_encoding_profiles:
1130 * @project: A #GESProject
1132 * Lists the encoding profile that have been set to @project. The first one
1133 * is the latest added.
1135 * Returns: (transfer none) (element-type GstPbutils.EncodingProfile) (allow-none): The
1136 * list of #GstEncodingProfile used in @project
1139 ges_project_list_encoding_profiles (GESProject * project)
1141 g_return_val_if_fail (GES_IS_PROJECT (project), FALSE);
1143 return project->priv->encoding_profiles;
1147 * ges_project_get_loading_assets:
1148 * @project: A #GESProject
1150 * Get the assets that are being loaded
1152 * Returns: (transfer full) (element-type GES.Asset): A set of loading asset
1153 * that will be added to @project. Note that those Asset are *not* loaded yet,
1154 * and thus can not be used
1157 ges_project_get_loading_assets (GESProject * project)
1159 GHashTableIter iter;
1160 gpointer key, value;
1164 g_return_val_if_fail (GES_IS_PROJECT (project), NULL);
1166 g_hash_table_iter_init (&iter, project->priv->loading_assets);
1167 while (g_hash_table_iter_next (&iter, &key, &value))
1168 ret = g_list_prepend (ret, gst_object_ref (value));