From 6be4f79ca0d075d607ac51b7536e28333f3de7b8 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Thu, 16 May 2013 08:10:35 +0200 Subject: [PATCH] uri-source: Expose the volume property. + Make the pspec_hash function an internal util. + Add a create_props_hashtable implementation + If TRACK_TYPE_AUDIO, put the volume properties in the hashtable. --- ges/ges-base-effect.c | 28 +--------------------------- ges/ges-uri-source.c | 46 +++++++++++++++++++++++++++++++++++++++++----- ges/ges-utils.c | 25 +++++++++++++++++++++++++ ges/ges-utils.h | 3 +++ 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/ges/ges-base-effect.c b/ges/ges-base-effect.c index 99b2b8b..4760b91 100644 --- a/ges/ges-base-effect.c +++ b/ges/ges-base-effect.c @@ -24,8 +24,8 @@ */ #include -#include +#include "ges-utils.h" #include "ges-internal.h" #include "ges-track-element.h" #include "ges-base-effect.h" @@ -33,9 +33,6 @@ G_DEFINE_ABSTRACT_TYPE (GESBaseEffect, ges_base_effect, GES_TYPE_OPERATION); static GHashTable *ges_base_effect_get_props_hashtable (GESTrackElement * self); -guint pspec_hash (gconstpointer key_spec); -static gboolean pspec_equal (gconstpointer key_spec_1, - gconstpointer key_spec_2); struct _GESBaseEffectPrivate { @@ -60,29 +57,6 @@ ges_base_effect_init (GESBaseEffect * self) GESBaseEffectPrivate); } -static gboolean -pspec_equal (gconstpointer key_spec_1, gconstpointer key_spec_2) -{ - const GParamSpec *key1 = key_spec_1; - const GParamSpec *key2 = key_spec_2; - - return (key1->owner_type == key2->owner_type && - strcmp (key1->name, key2->name) == 0); -} - -guint -pspec_hash (gconstpointer key_spec) -{ - const GParamSpec *key = key_spec; - const gchar *p; - guint h = key->owner_type; - - for (p = key->name; *p; p++) - h = (h << 5) - h + *p; - - return h; -} - /* Virtual methods */ static GHashTable * ges_base_effect_get_props_hashtable (GESTrackElement * self) diff --git a/ges/ges-uri-source.c b/ges/ges-uri-source.c index 94e0407..d286aab 100644 --- a/ges/ges-uri-source.c +++ b/ges/ges-uri-source.c @@ -26,12 +26,19 @@ * the type of the track which contains the object. */ +#include "ges-utils.h" #include "ges-internal.h" #include "ges-track-element.h" #include "ges-uri-source.h" #include "ges-uri-asset.h" #include "ges-extractable.h" +struct _GESUriSourcePrivate +{ + GHashTable *props_hashtable; + void *dummy; +}; + static gchar * ges_extractable_check_id (GType type, const gchar * id, GError ** error) { @@ -65,11 +72,6 @@ G_DEFINE_TYPE_WITH_CODE (GESUriSource, ges_track_filesource, G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE, ges_extractable_interface_init)); -struct _GESUriSourcePrivate -{ - void *dummy; -}; - enum { PROP_0, @@ -135,6 +137,9 @@ ges_uri_source_create_element (GESTrackElement * trksrc) GstPad *ghost; GESLayer *layer; gfloat layer_volume; + GObjectClass *class; + guint i, nb_specs; + GParamSpec **parray; self = (GESUriSource *) trksrc; track = ges_track_element_get_track (trksrc); @@ -171,6 +176,22 @@ ges_uri_source_create_element (GESTrackElement * trksrc) } else GST_DEBUG_OBJECT (trksrc, "NOT setting the volume"); + class = G_OBJECT_GET_CLASS (volume); + parray = g_object_class_list_properties (class, &nb_specs); + + if (self->priv->props_hashtable == NULL) + self->priv->props_hashtable = + g_hash_table_new_full ((GHashFunc) pspec_hash, pspec_equal, + (GDestroyNotify) g_param_spec_unref, gst_object_unref); + + for (i = 0; i < nb_specs; i++) { + if (parray[i]->flags & G_PARAM_WRITABLE) { + g_hash_table_insert (self->priv->props_hashtable, + g_param_spec_ref (parray[i]), gst_object_ref (volume)); + } + } + g_free (parray); + ret = topbin; break; default: @@ -185,6 +206,19 @@ ges_uri_source_create_element (GESTrackElement * trksrc) return ret; } +static GHashTable * +ges_uri_source_get_props_hashtable (GESTrackElement * element) +{ + GESUriSource *self = (GESUriSource *) element; + + if (self->priv->props_hashtable == NULL) + self->priv->props_hashtable = + g_hash_table_new_full ((GHashFunc) pspec_hash, pspec_equal, + (GDestroyNotify) g_param_spec_unref, gst_object_unref); + + return self->priv->props_hashtable; +} + static void ges_track_filesource_class_init (GESUriSourceClass * klass) { @@ -207,6 +241,7 @@ ges_track_filesource_class_init (GESUriSourceClass * klass) NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); track_class->create_element = ges_uri_source_create_element; + track_class->get_props_hastable = ges_uri_source_get_props_hashtable; } static void @@ -214,6 +249,7 @@ ges_track_filesource_init (GESUriSource * self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GES_TYPE_URI_SOURCE, GESUriSourcePrivate); + self->priv->props_hashtable = NULL; } /** diff --git a/ges/ges-utils.c b/ges/ges-utils.c index fc5f0eb..769952d 100644 --- a/ges/ges-utils.c +++ b/ges/ges-utils.c @@ -23,6 +23,8 @@ * */ +#include + #include "ges-internal.h" #include "ges-timeline.h" #include "ges-track.h" @@ -97,3 +99,26 @@ element_end_compare (GESTimelineElement * a, GESTimelineElement * b) return 1; } + +gboolean +pspec_equal (gconstpointer key_spec_1, gconstpointer key_spec_2) +{ + const GParamSpec *key1 = key_spec_1; + const GParamSpec *key2 = key_spec_2; + + return (key1->owner_type == key2->owner_type && + strcmp (key1->name, key2->name) == 0); +} + +guint +pspec_hash (gconstpointer key_spec) +{ + const GParamSpec *key = key_spec; + const gchar *p; + guint h = key->owner_type; + + for (p = key->name; *p; p++) + h = (h << 5) - h + *p; + + return h; +} diff --git a/ges/ges-utils.h b/ges/ges-utils.h index 87deb4e..ca09127 100644 --- a/ges/ges-utils.h +++ b/ges/ges-utils.h @@ -27,6 +27,9 @@ G_BEGIN_DECLS GESTimeline * ges_timeline_new_audio_video (void); +gboolean pspec_equal (gconstpointer key_spec_1, gconstpointer key_spec_2); +guint pspec_hash (gconstpointer key_spec); + G_END_DECLS -- 2.7.4