From 0232f5700318141d3604fe545ee009b53af79e73 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 18 Sep 2012 14:42:58 +0200 Subject: [PATCH] customtimelinesource: Override Extractable API: ges_material_custom_timeline_source_new (helper method) --- docs/libs/ges-sections.txt | 1 + ges/ges-custom-timeline-source.c | 157 ++++++++++++++++++++++++++++++++++++++- ges/ges-custom-timeline-source.h | 5 ++ 3 files changed, 160 insertions(+), 3 deletions(-) diff --git a/docs/libs/ges-sections.txt b/docs/libs/ges-sections.txt index 1d29135..56cc08f 100644 --- a/docs/libs/ges-sections.txt +++ b/docs/libs/ges-sections.txt @@ -956,6 +956,7 @@ ges_asset_request_async ges_asset_request_finish ges_asset_extract ges_list_assets +ges_asset_custom_timeline_source_new GESAssetPrivate GES_ASSET diff --git a/ges/ges-custom-timeline-source.c b/ges/ges-custom-timeline-source.c index 353adc4..e47ee11 100644 --- a/ges/ges-custom-timeline-source.c +++ b/ges/ges-custom-timeline-source.c @@ -24,14 +24,29 @@ * * #GESCustomTimelineSource allows creating #GESTimelineSource(s) without the * need to subclass. - * + * * Its usage should be limited to testing and prototyping purposes. + * + * To instanciate a asset to extract GESCustomTimelineSource-s the expected + * ID is: + * 'PointerToFuncAsInt!PointerToUDataAsInt' + * + * You should use the #ges_asset_custom_timeline_source_new helper to create + * a new GESAsset letting you extract GESCustomTimelineSource. */ #include "ges-internal.h" #include "ges-custom-timeline-source.h" #include "ges-timeline-source.h" #include "ges-track-source.h" +#include "ges-extractable.h" + +enum +{ + PROP_0, + PROP_FILL_FUNC, + PROP_USER_DATA +}; struct _GESCustomTimelineSourcePrivate { @@ -39,8 +54,77 @@ struct _GESCustomTimelineSourcePrivate gpointer user_data; }; -G_DEFINE_TYPE (GESCustomTimelineSource, ges_custom_timeline_source, - GES_TYPE_TIMELINE_SOURCE); +static void ges_extractable_interface_init (GESExtractableInterface * iface); + +G_DEFINE_TYPE_WITH_CODE (GESCustomTimelineSource, ges_custom_timeline_source, + GES_TYPE_TIMELINE_SOURCE, + G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE, + ges_extractable_interface_init)); + +static GParameter * +extractable_get_parameters_from_id (const gchar * id, guint * n_params) +{ + gchar **func_udata; + GParameter *params = g_new0 (GParameter, 2); + *n_params = 2; + + /* We already know that we have a valid ID here */ + func_udata = g_strsplit (id, "!", -1); + + params[0].name = g_strdup ("fill-func"); + g_value_init (¶ms[0].value, G_TYPE_POINTER); + g_value_set_pointer (¶ms[0].value, + GUINT_TO_POINTER (g_ascii_strtoll (func_udata[0], NULL, 10))); + + params[1].name = g_strdup ("user-data"); + g_value_init (¶ms[1].value, G_TYPE_POINTER); + g_value_set_pointer (¶ms[1].value, + GUINT_TO_POINTER (g_ascii_strtoll (func_udata[1], NULL, 10))); + + g_strfreev (func_udata); + + return params; +} + +static gchar * +extractable_check_id (GType type, const gchar * id) +{ + + gchar *ret, **strv = g_strsplit (id, "!", -1); + + if (g_strv_length (strv) != 2) { + g_strfreev (strv); + + return NULL; + } + + /* Remove any whitespace */ + strv[0] = g_strstrip (strv[0]); + strv[1] = g_strstrip (strv[1]); + ret = g_strjoinv ("!", strv); + + g_strfreev (strv); + + return ret; +} + +static gchar * +extractable_get_id (GESExtractable * self) +{ + GESCustomTimelineSourcePrivate *priv = + GES_CUSTOM_TIMELINE_SOURCE (self)->priv; + + return g_strdup_printf ("%i!%i", GPOINTER_TO_INT (priv->filltrackobjectfunc), + GPOINTER_TO_INT (priv->user_data)); +} + +static void +ges_extractable_interface_init (GESExtractableInterface * iface) +{ + iface->check_id = (GESExtractableCheckId) extractable_check_id; + iface->get_id = extractable_get_id; + iface->get_parameters_from_id = extractable_get_parameters_from_id; +} static gboolean ges_custom_timeline_source_fill_track_object (GESTimelineObject * object, @@ -54,8 +138,27 @@ ges_custom_timeline_source_create_track_object (GESTimelineObject * obj, } static void +_set_property (GObject * object, guint property_id, + const GValue * value, GParamSpec * pspec) +{ + GESCustomTimelineSourcePrivate *priv = + GES_CUSTOM_TIMELINE_SOURCE (object)->priv; + switch (property_id) { + case PROP_FILL_FUNC: + priv->filltrackobjectfunc = g_value_get_pointer (value); + break; + case PROP_USER_DATA: + priv->user_data = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void ges_custom_timeline_source_class_init (GESCustomTimelineSourceClass * klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); GESTimelineObjectClass *tlobj_class = GES_TIMELINE_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (GESCustomTimelineSourcePrivate)); @@ -63,6 +166,28 @@ ges_custom_timeline_source_class_init (GESCustomTimelineSourceClass * klass) tlobj_class->fill_track_object = ges_custom_timeline_source_fill_track_object; tlobj_class->create_track_object = ges_custom_timeline_source_create_track_object; + + object_class->set_property = _set_property; + + /** + * GESCustomTimelineSource:fill-func: + * + * The function pointer to create the TrackObject content + */ + g_object_class_install_property (object_class, PROP_FILL_FUNC, + g_param_spec_pointer ("fill-func", "Fill func", + "A pointer to a GESFillTrackObjectUserFunc", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + /** + * GESCustomTimelineSource:user-data: + * + * The user data that will be passed + */ + g_object_class_install_property (object_class, PROP_USER_DATA, + g_param_spec_pointer ("user-data", "User data", + "The user data pointer that will be passed when creating TrackObjects", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); } static void @@ -112,3 +237,29 @@ ges_custom_timeline_source_new (GESFillTrackObjectUserFunc func, return src; } + +/** + * ges_asset_custom_timeline_source_new: + * @func: (scope notified): The #GESFillTrackObjectUserFunc that will be used to fill the track + * objects. + * @user_data: (closure): a gpointer that will be used when @func is called. + * + * Helper constructor to instanciate a new #GESAsset from which you can + * extract #GESCustomTimelineSource-s + * + * Returns: The new #GESAsset. + */ +GESAsset * +ges_asset_custom_timeline_source_new (GESFillTrackObjectUserFunc func, + gpointer user_data) +{ + GESAsset *asset; + gchar *id = g_strdup_printf ("%i!%i", GPOINTER_TO_INT (func), + GPOINTER_TO_INT (user_data)); + + asset = ges_asset_request (GES_TYPE_CUSTOM_TIMELINE_SOURCE, id, NULL); + + g_free (id); + + return asset; +} diff --git a/ges/ges-custom-timeline-source.h b/ges/ges-custom-timeline-source.h index afa94b6..9e6a49d 100644 --- a/ges/ges-custom-timeline-source.h +++ b/ges/ges-custom-timeline-source.h @@ -100,6 +100,11 @@ GESCustomTimelineSource* ges_custom_timeline_source_new (GESFillTrackObjectUserFunc func, gpointer user_data); +GESAsset* +ges_asset_custom_timeline_source_new (GESFillTrackObjectUserFunc func, + gpointer user_data); + + G_END_DECLS #endif /* _GES_CUSTOM_TIMELINE_SOURCE */ -- 2.7.4