static gboolean _load_project (GESProject * project, GESTimeline * timeline, GError ** error) { GError *lerr = NULL; GESProjectPrivate *priv; GESFormatter *formatter; priv = GES_PROJECT (project)->priv; if (priv->uri == NULL) { EmitLoadedInIdle *data = g_slice_new (EmitLoadedInIdle); GST_LOG_OBJECT (project, "%s, Loading an empty timeline %s" " as no URI set yet", GST_OBJECT_NAME (timeline), ges_asset_get_id (GES_ASSET (project))); data->timeline = gst_object_ref (timeline); data->project = gst_object_ref (project); /* Make sure the signal is emitted after the functions ends */ g_idle_add ((GSourceFunc) _emit_loaded_in_idle, data); return TRUE; } if (priv->formatter_asset == NULL) priv->formatter_asset = _find_formatter_asset_for_uri (priv->uri); if (priv->formatter_asset == NULL) goto failed; formatter = GES_FORMATTER (ges_asset_extract (priv->formatter_asset, &lerr)); if (lerr) { GST_WARNING_OBJECT (project, "Could not create the formatter: %s", (*error)->message); goto failed; } ges_project_add_formatter (GES_PROJECT (project), formatter); ges_formatter_load_from_uri (formatter, timeline, priv->uri, &lerr); if (lerr) { GST_WARNING_OBJECT (project, "Could not load the timeline," " returning: %s", lerr->message); goto failed; } return TRUE; failed: if (lerr) g_propagate_error (error, lerr); return FALSE; }
static void _finalize (GObject * object) { GESProjectPrivate *priv = GES_PROJECT (object)->priv; if (priv->uri) g_free (priv->uri); }
static void _finalize (GObject * object) { GESProjectPrivate *priv = GES_PROJECT (object)->priv; if (priv->uri) g_free (priv->uri); G_OBJECT_CLASS (ges_project_parent_class)->finalize (object); }
static void ges_project_add_formatter (GESProject * project, GESFormatter * formatter) { GESProjectPrivate *priv = GES_PROJECT (project)->priv; ges_formatter_set_project (formatter, project); priv->formatters = g_list_append (priv->formatters, formatter); gst_object_ref_sink (formatter); }
static void new_asset_cb (GESAsset * source, GAsyncResult * res, NewAssetUData * udata) { GError *error = NULL; GESAsset *asset = ges_asset_request_finish (res, &error); GST_DEBUG_OBJECT (udata->layer, "%" GST_PTR_FORMAT " Asset loaded, " "setting its asset", udata->clip); if (error) { GESProject *project = udata->layer->timeline ? GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE (udata->layer->timeline))) : NULL; if (project) { gchar *possible_id; possible_id = ges_project_try_updating_id (project, source, error); if (possible_id) { ges_asset_request_async (ges_asset_get_extractable_type (source), possible_id, NULL, (GAsyncReadyCallback) new_asset_cb, udata); g_free (possible_id); return; } } GST_ERROR ("Asset could not be created for uri %s, error: %s", ges_asset_get_id (asset), error->message); } else { GESProject *project = udata->layer->timeline ? GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE (udata->layer->timeline))) : NULL; ges_extractable_set_asset (GES_EXTRACTABLE (udata->clip), asset); ges_project_add_asset (project, asset); ges_layer_add_clip (udata->layer, udata->clip); } gst_object_unref (asset); g_slice_free (NewAssetUData, udata); }
/* GObject vmethod implementation */ static void _dispose (GObject * object) { GList *tmp; GESProjectPrivate *priv = GES_PROJECT (object)->priv; if (priv->assets) g_hash_table_unref (priv->assets); if (priv->loading_assets) g_hash_table_unref (priv->loading_assets); if (priv->loaded_with_error) g_hash_table_unref (priv->loaded_with_error); if (priv->formatter_asset) gst_object_unref (priv->formatter_asset); for (tmp = priv->formatters; tmp; tmp = tmp->next) ges_project_remove_formatter (GES_PROJECT (object), tmp->data);; G_OBJECT_CLASS (ges_project_parent_class)->dispose (object); }
/* GESAsset vmethod implementation */ static GESExtractable * ges_project_extract (GESAsset * project, GError ** error) { GESTimeline *timeline = ges_timeline_new (); if (_load_project (GES_PROJECT (project), timeline, error)) return GES_EXTRACTABLE (timeline); gst_object_unref (timeline); return NULL; }
/* GESAsset vmethod implementation */ static GESExtractable * ges_project_extract (GESAsset * project, GError ** error) { GESTimeline *timeline = g_object_new (GES_TYPE_TIMELINE, NULL); ges_extractable_set_asset (GES_EXTRACTABLE (timeline), GES_ASSET (project)); if (_load_project (GES_PROJECT (project), timeline, error)) return GES_EXTRACTABLE (timeline); gst_object_unref (timeline); return NULL; }
static void ges_project_remove_formatter (GESProject * project, GESFormatter * formatter) { GList *tmp; GESProjectPrivate *priv = GES_PROJECT (project)->priv; for (tmp = priv->formatters; tmp; tmp = tmp->next) { if (tmp->data == formatter) { gst_object_unref (formatter); priv->formatters = g_list_delete_link (priv->formatters, tmp); return; } } }
/** * ges_project_new: * @uri: (allow-none): The uri to be set after creating the project. * * Creates a new #GESProject and sets its uri to @uri if provided. Note that * if @uri is not valid or %NULL, the uri of the project will then be set * the first time you save the project. If you then save the project to * other locations, it will never be updated again and the first valid URI is * the URI it will keep refering to. * * Returns: A newly created #GESProject */ GESProject * ges_project_new (const gchar * uri) { gchar *id = (gchar *) uri; GESProject *project; if (uri == NULL) id = g_strdup_printf ("project-%i", nb_projects++); project = GES_PROJECT (ges_asset_request (GES_TYPE_TIMELINE, id, NULL)); if (project && uri) ges_project_set_uri (project, uri); return project; }
/** * ges_layer_add_clip: * @layer: a #GESLayer * @clip: (transfer full): the #GESClip to add. * * Adds the given clip to the layer. Sets the clip's parent, and thus * takes ownership of the clip. * * An clip can only be added to one layer. * * Calling this method will construct and properly set all the media related * elements on @clip. If you need to know when those objects (actually #GESTrackElement) * are constructed, you should connect to the container::child-added signal which * is emited right after those elements are ready to be used. * * Returns: TRUE if the clip was properly added to the layer, or FALSE * if the @layer refuses to add the clip. */ gboolean ges_layer_add_clip (GESLayer * layer, GESClip * clip) { GESAsset *asset; GESLayerPrivate *priv; GESLayer *current_layer; g_return_val_if_fail (GES_IS_LAYER (layer), FALSE); g_return_val_if_fail (GES_IS_CLIP (clip), FALSE); GST_DEBUG_OBJECT (layer, "adding clip:%p", clip); priv = layer->priv; current_layer = ges_clip_get_layer (clip); if (G_UNLIKELY (current_layer)) { GST_WARNING ("Clip %p already belongs to another layer", clip); gst_object_unref (current_layer); return FALSE; } asset = ges_extractable_get_asset (GES_EXTRACTABLE (clip)); if (asset == NULL) { gchar *id; NewAssetUData *mudata = g_slice_new (NewAssetUData); mudata->clip = clip; mudata->layer = layer; GST_DEBUG_OBJECT (layer, "%" GST_PTR_FORMAT " as no reference to any " "assets creating a asset... trying sync", clip); id = ges_extractable_get_id (GES_EXTRACTABLE (clip)); asset = ges_asset_request (G_OBJECT_TYPE (clip), id, NULL); if (asset == NULL) { GESProject *project = layer->timeline ? GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE (layer->timeline))) : NULL; ges_asset_request_async (G_OBJECT_TYPE (clip), id, NULL, (GAsyncReadyCallback) new_asset_cb, mudata); if (project) ges_project_add_loading_asset (project, G_OBJECT_TYPE (clip), id); g_free (id); GST_LOG_OBJECT (layer, "Object added async"); return TRUE; } g_free (id); ges_extractable_set_asset (GES_EXTRACTABLE (clip), asset); g_slice_free (NewAssetUData, mudata); } gst_object_ref_sink (clip); /* Take a reference to the clip and store it stored by start/priority */ priv->clips_start = g_list_insert_sorted (priv->clips_start, clip, (GCompareFunc) element_start_compare); /* Inform the clip it's now in this layer */ ges_clip_set_layer (clip, layer); GST_DEBUG ("current clip priority : %d, Height: %d", _PRIORITY (clip), LAYER_HEIGHT); /* Set the priority. */ if (_PRIORITY (clip) > LAYER_HEIGHT) { GST_WARNING_OBJECT (layer, "%p is out of the layer space, setting its priority to " "%d, setting it to the maximum priority of the layer: %d", clip, _PRIORITY (clip), LAYER_HEIGHT - 1); _set_priority0 (GES_TIMELINE_ELEMENT (clip), LAYER_HEIGHT - 1); } /* If the clip has an acceptable priority, we just let it with its current * priority */ ges_layer_resync_priorities (layer); ges_timeline_element_set_timeline (GES_TIMELINE_ELEMENT (clip), layer->timeline); /* emit 'clip-added' */ g_signal_emit (layer, ges_layer_signals[OBJECT_ADDED], 0, clip); return TRUE; }