From 4b29d4f29ac856f1903fcaebda136164ca8323d9 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Tue, 6 Dec 2011 08:35:57 +0100 Subject: [PATCH] controller: remove GstValueArray Instead pass the values as arguments. This simplifies that code and helps bindings. --- docs/random/porting-to-0.11.txt | 4 +- gst/gstcontrolsource.c | 5 ++- gst/gstcontrolsource.h | 32 +++++---------- gst/gstobject.c | 33 ++++++++------- gst/gstobject.h | 5 ++- libs/gst/controller/gstinterpolation.c | 42 +++++++++---------- libs/gst/controller/gstlfocontrolsource.c | 50 +++++++++++------------ tests/benchmarks/controller.c | 10 +---- 8 files changed, 85 insertions(+), 96 deletions(-) diff --git a/docs/random/porting-to-0.11.txt b/docs/random/porting-to-0.11.txt index a83f4cf22e..33dddaf009 100644 --- a/docs/random/porting-to-0.11.txt +++ b/docs/random/porting-to-0.11.txt @@ -444,5 +444,7 @@ The 0.11 porting guide gst_controller_set_property_disabled -> gst_object_set_controlled_property_disabled gst_object_get_value_arrays has been removed. Loop over the controlled - properties fetch the value array. + properties fetch the value array. Also GstValueArray is gone. The fields of + GstValueArray are now passed directly to gst_object_get_value_array as + arguments. diff --git a/gst/gstcontrolsource.c b/gst/gstcontrolsource.c index 3d87670c8f..16e84a8b4a 100644 --- a/gst/gstcontrolsource.c +++ b/gst/gstcontrolsource.c @@ -120,12 +120,13 @@ gst_control_source_get_value (GstControlSource * self, GstClockTime timestamp, */ gboolean gst_control_source_get_value_array (GstControlSource * self, - GstClockTime timestamp, GstValueArray * value_array) + GstClockTime timestamp, GstClockTime interval, guint n_values, + gpointer * values) { g_return_val_if_fail (GST_IS_CONTROL_SOURCE (self), FALSE); if (G_LIKELY (self->get_value_array)) { - return self->get_value_array (self, timestamp, value_array); + return self->get_value_array (self, timestamp, interval, n_values, values); } else { GST_ERROR ("Not bound to a specific property yet!"); return FALSE; diff --git a/gst/gstcontrolsource.h b/gst/gstcontrolsource.h index e7be6cfabe..a46a7c9f49 100644 --- a/gst/gstcontrolsource.h +++ b/gst/gstcontrolsource.h @@ -62,23 +62,6 @@ struct _GstTimedValue GValue value; }; -/** - * GstValueArray: - * @property_name: the name of the property this array belongs to - * @nbsamples: number of samples requested - * @sample_interval: interval between each sample - * @values: pointer to the array - * - * Structure to receive multiple values at once. - */ -struct _GstValueArray -{ - const gchar *property_name; - gint nbsamples; - GstClockTime sample_interval; - gpointer *values; -}; - /** * GstControlSourceGetValue * @self: the #GstControlSource instance @@ -90,20 +73,24 @@ struct _GstValueArray * Returns: %TRUE if the value was successfully calculated. * */ -typedef gboolean (* GstControlSourceGetValue) (GstControlSource *self, GstClockTime timestamp, GValue *value); +typedef gboolean (* GstControlSourceGetValue) (GstControlSource *self, + GstClockTime timestamp, GValue *value); /** * GstControlSourceGetValueArray * @self: the #GstControlSource instance * @timestamp: timestamp for which a value should be calculated - * @value_array: array to put control-values in + * @interval: the time spacing between subsequent values + * @n_values: the number of values + * @values: array to put control-values in * - * Function for returning a #GstValueArray for a given timestamp. + * Function for returning an array of values for starting at a given timestamp. * * Returns: %TRUE if the values were successfully calculated. * */ -typedef gboolean (* GstControlSourceGetValueArray) (GstControlSource *self, GstClockTime timestamp, GstValueArray *value_array); +typedef gboolean (* GstControlSourceGetValueArray) (GstControlSource *self, + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *values); /** * GstControlSourceBind @@ -159,7 +146,8 @@ GType gst_control_source_get_type (void); gboolean gst_control_source_get_value (GstControlSource *self, GstClockTime timestamp, GValue *value); gboolean gst_control_source_get_value_array (GstControlSource *self, GstClockTime timestamp, - GstValueArray *value_array); + GstClockTime interval, guint n_values, + gpointer *values); gboolean gst_control_source_bind (GstControlSource *self, GParamSpec *pspec); diff --git a/gst/gstobject.c b/gst/gstobject.c index 44152286bf..bfecbd822a 100644 --- a/gst/gstobject.c +++ b/gst/gstobject.c @@ -1429,36 +1429,39 @@ gst_object_get_value (GstObject * object, const gchar * property_name, /** * gst_object_get_value_array: * @object: the object that has controlled properties + * @property_name: the name of the property to get * @timestamp: the time that should be processed - * @value_array: array to put control-values in + * @interval: the time spacing between subsequent values + * @n_values: the number of values + * @values: array to put control-values in * - * Function to be able to get an array of values for one element properties + * Gets a number of values for the given controllered property starting at the + * requested time. The array @values need to hold enough space for @n_values of + * the same type as the objects property's type. * - * If the GstValueArray->values array is NULL, it will be created by the function. - * The type of the values in the array are the same as the property's type. + * This function is useful if one wants to e.g. draw a graph of the control + * curve or apply a control curve sample by sample. * - * The g_object_* functions are just convenience functions for GObject - * - * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise + * Returns: %TRUE if the given array could be filled, %FALSE otherwise */ gboolean -gst_object_get_value_array (GstObject * object, GstClockTime timestamp, - GstValueArray * value_array) +gst_object_get_value_array (GstObject * object, const gchar * property_name, + GstClockTime timestamp, GstClockTime interval, guint n_values, + gpointer * values) { gboolean res = FALSE; GstControlledProperty *prop; g_return_val_if_fail (GST_IS_OBJECT (object), FALSE); + g_return_val_if_fail (property_name, FALSE); g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE); - g_return_val_if_fail (value_array, FALSE); - g_return_val_if_fail (value_array->property_name, FALSE); - g_return_val_if_fail (value_array->values, FALSE); + g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE); + g_return_val_if_fail (values, FALSE); GST_OBJECT_LOCK (object); - if ((prop = gst_object_find_controlled_property (object, - value_array->property_name))) { + if ((prop = gst_object_find_controlled_property (object, property_name))) { res = gst_control_source_get_value_array (prop->csource, timestamp, - value_array); + interval, n_values, values); } GST_OBJECT_UNLOCK (object); return res; diff --git a/gst/gstobject.h b/gst/gstobject.h index defa1065dc..d8ac54e8a8 100644 --- a/gst/gstobject.h +++ b/gst/gstobject.h @@ -250,8 +250,9 @@ GstControlSource * GValue * gst_object_get_value (GstObject * object, const gchar * property_name, GstClockTime timestamp); -gboolean gst_object_get_value_array (GstObject * object, GstClockTime timestamp, - GstValueArray * value_array); +gboolean gst_object_get_value_array (GstObject * object, const gchar * property_name, + GstClockTime timestamp, GstClockTime interval, + guint n_values, gpointer *values); GstClockTime gst_object_get_control_rate (GstObject * object); void gst_object_set_control_rate (GstObject * object, GstClockTime control_rate); diff --git a/libs/gst/controller/gstinterpolation.c b/libs/gst/controller/gstinterpolation.c index 54ff60e1a0..37351913e9 100644 --- a/libs/gst/controller/gstinterpolation.c +++ b/libs/gst/controller/gstinterpolation.c @@ -135,18 +135,18 @@ interpolate_none_get_##type (GstInterpolationControlSource *self, GstClockTime t \ static gboolean \ interpolate_none_get_##type##_value_array (GstInterpolationControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ GstClockTime next_ts = 0; \ - ctype *values = (ctype *) value_array->values; \ + ctype *values = (ctype *) _values; \ const GValue *ret_val = NULL; \ ctype ret = 0; \ GSequenceIter *iter1 = NULL, *iter2 = NULL; \ \ g_mutex_lock (self->lock); \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ if (!ret_val || ts >= next_ts) { \ iter1 = gst_interpolation_control_source_find_control_point_iter (self, ts); \ if (!iter1) { \ @@ -171,7 +171,7 @@ interpolate_none_get_##type##_value_array (GstInterpolationControlSource *self, ret = g_value_get_##type (ret_val); \ } \ *values = ret; \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -294,19 +294,19 @@ interpolate_trigger_get_##type (GstInterpolationControlSource *self, GstClockTim \ static gboolean \ interpolate_trigger_get_##type##_value_array (GstInterpolationControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ GstClockTime next_ts = 0; \ - ctype *values = (ctype *) value_array->values; \ + ctype *values = (ctype *) _values; \ const GValue *ret_val = NULL; \ ctype ret = 0; \ GSequenceIter *iter1 = NULL, *iter2 = NULL; \ gboolean triggered = FALSE; \ \ g_mutex_lock (self->lock); \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ if (!ret_val || ts >= next_ts) { \ iter1 = gst_interpolation_control_source_find_control_point_iter (self, ts); \ if (!iter1) { \ @@ -344,7 +344,7 @@ interpolate_trigger_get_##type##_value_array (GstInterpolationControlSource *sel triggered = FALSE; \ } \ *values = ret; \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -455,12 +455,12 @@ interpolate_linear_get_##vtype (GstInterpolationControlSource *self, GstClockTim \ static gboolean \ interpolate_linear_get_##vtype##_value_array (GstInterpolationControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ GstClockTime next_ts = 0; \ - g##vtype *values = (g##vtype *) value_array->values; \ + g##vtype *values = (g##vtype *) _values; \ GSequenceIter *iter1, *iter2 = NULL; \ GstControlPoint *cp1 = NULL, *cp2 = NULL, cp = {0, }; \ g##vtype val1 = 0, val2 = 0, min, max; \ @@ -474,7 +474,7 @@ interpolate_linear_get_##vtype##_value_array (GstInterpolationControlSource *sel min = g_value_get_##vtype (&self->priv->minimum_value); \ max = g_value_get_##vtype (&self->priv->maximum_value); \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ if (timestamp >= next_ts) { \ iter1 = gst_interpolation_control_source_find_control_point_iter (self, ts); \ if (!iter1) { \ @@ -499,7 +499,7 @@ interpolate_linear_get_##vtype##_value_array (GstInterpolationControlSource *sel val2 = g_value_get_##vtype (&cp2->value); \ } \ _interpolate_linear_internal_##vtype (cp1->timestamp, val1, (cp2 ? cp2->timestamp : GST_CLOCK_TIME_NONE), (cp2 ? val2 : 0), ts, min, max, values); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -709,18 +709,18 @@ interpolate_cubic_get_##vtype (GstInterpolationControlSource *self, GstClockTime \ static gboolean \ interpolate_cubic_get_##vtype##_value_array (GstInterpolationControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ GstClockTime next_ts = 0; \ - g##vtype *values = (g##vtype *) value_array->values; \ + g##vtype *values = (g##vtype *) _values; \ GSequenceIter *iter1, *iter2 = NULL; \ GstControlPoint *cp1 = NULL, *cp2 = NULL, cp = {0, }; \ g##vtype val1 = 0, val2 = 0, min, max; \ \ if (self->priv->nvalues <= 2) \ - return interpolate_linear_get_##vtype##_value_array (self, timestamp, value_array); \ + return interpolate_linear_get_##vtype##_value_array (self, timestamp, interval, n_values, values); \ \ g_mutex_lock (self->lock); \ \ @@ -731,7 +731,7 @@ interpolate_cubic_get_##vtype##_value_array (GstInterpolationControlSource *self min = g_value_get_##vtype (&self->priv->minimum_value); \ max = g_value_get_##vtype (&self->priv->maximum_value); \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ if (timestamp >= next_ts) { \ iter1 = gst_interpolation_control_source_find_control_point_iter (self, ts); \ if (!iter1) { \ @@ -756,7 +756,7 @@ interpolate_cubic_get_##vtype##_value_array (GstInterpolationControlSource *self val2 = g_value_get_##vtype (&cp2->value); \ } \ _interpolate_cubic_get_##vtype (self, cp1, val1, cp2, val2, timestamp, min, max, values); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ diff --git a/libs/gst/controller/gstlfocontrolsource.c b/libs/gst/controller/gstlfocontrolsource.c index 9aa22a9dca..eff9cc66de 100644 --- a/libs/gst/controller/gstlfocontrolsource.c +++ b/libs/gst/controller/gstlfocontrolsource.c @@ -109,11 +109,11 @@ waveform_sine_get_##type (GstLFOControlSource *self, GstClockTime timestamp, \ \ static gboolean \ waveform_sine_get_##type##_value_array (GstLFOControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ - g##type *values = (g##type *) value_array->values; \ + g##type *values = (g##type *) _values; \ g##type max, min; \ gdouble amp, off, frequency; \ GstClockTime timeshift, period; \ @@ -127,9 +127,9 @@ waveform_sine_get_##type##_value_array (GstLFOControlSource *self, \ period = self->priv->period; \ frequency = self->priv->frequency; \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ *values = _sine_get_##type (self, max, min, amp, off, timeshift, period, frequency, ts); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -210,11 +210,11 @@ waveform_square_get_##type (GstLFOControlSource *self, GstClockTime timestamp, \ \ static gboolean \ waveform_square_get_##type##_value_array (GstLFOControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ - g##type *values = (g##type *) value_array->values; \ + g##type *values = (g##type *) _values; \ g##type max, min; \ gdouble amp, off, frequency; \ GstClockTime timeshift, period; \ @@ -228,9 +228,9 @@ waveform_square_get_##type##_value_array (GstLFOControlSource *self, \ period = self->priv->period; \ frequency = self->priv->frequency; \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ *values = _square_get_##type (self, max, min, amp, off, timeshift, period, frequency, ts); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -308,11 +308,11 @@ waveform_saw_get_##type (GstLFOControlSource *self, GstClockTime timestamp, \ \ static gboolean \ waveform_saw_get_##type##_value_array (GstLFOControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ - g##type *values = (g##type *) value_array->values; \ + g##type *values = (g##type *) _values; \ g##type max, min; \ gdouble amp, off, frequency; \ GstClockTime timeshift, period; \ @@ -326,9 +326,9 @@ waveform_saw_get_##type##_value_array (GstLFOControlSource *self, \ period = self->priv->period; \ frequency = self->priv->frequency; \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ *values = _saw_get_##type (self, max, min, amp, off, timeshift, period, frequency, ts); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -406,11 +406,11 @@ waveform_rsaw_get_##type (GstLFOControlSource *self, GstClockTime timestamp, \ \ static gboolean \ waveform_rsaw_get_##type##_value_array (GstLFOControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ - g##type *values = (g##type *) value_array->values; \ + g##type *values = (g##type *) _values; \ g##type max, min; \ gdouble amp, off, frequency; \ GstClockTime timeshift, period; \ @@ -424,9 +424,9 @@ waveform_rsaw_get_##type##_value_array (GstLFOControlSource *self, \ period = self->priv->period; \ frequency = self->priv->frequency; \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ *values = _rsaw_get_##type (self, max, min, amp, off, timeshift, period, frequency, ts); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ @@ -509,11 +509,11 @@ waveform_triangle_get_##type (GstLFOControlSource *self, GstClockTime timestamp, \ static gboolean \ waveform_triangle_get_##type##_value_array (GstLFOControlSource *self, \ - GstClockTime timestamp, GstValueArray * value_array) \ + GstClockTime timestamp, GstClockTime interval, guint n_values, gpointer *_values) \ { \ - gint i; \ + guint i; \ GstClockTime ts = timestamp; \ - g##type *values = (g##type *) value_array->values; \ + g##type *values = (g##type *) _values; \ g##type max, min; \ gdouble amp, off, frequency; \ GstClockTime timeshift, period; \ @@ -527,9 +527,9 @@ waveform_triangle_get_##type##_value_array (GstLFOControlSource *self, \ period = self->priv->period; \ frequency = self->priv->frequency; \ \ - for(i = 0; i < value_array->nbsamples; i++) { \ + for(i = 0; i < n_values; i++) { \ *values = _triangle_get_##type (self, max, min, amp, off, timeshift, period, frequency, ts); \ - ts += value_array->sample_interval; \ + ts += interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ diff --git a/tests/benchmarks/controller.c b/tests/benchmarks/controller.c index 4975509f5f..ff95e44f19 100644 --- a/tests/benchmarks/controller.c +++ b/tests/benchmarks/controller.c @@ -154,17 +154,11 @@ main (gint argc, gchar * argv[]) { GstClockTime sample_duration = gst_util_uint64_scale_int (1, GST_SECOND, 44100); - GstValueArray va = { "freq", - BLOCK_SIZE * NUM_CP, - sample_duration, - NULL - }; - gdouble *values = g_new0 (gdouble, BLOCK_SIZE * NUM_CP); - va.values = (gpointer *) values; bt = gst_util_get_timestamp (); - gst_control_source_get_value_array (GST_CONTROL_SOURCE (csource), 0, &va); + gst_control_source_get_value_array (GST_CONTROL_SOURCE (csource), 0, + sample_duration, BLOCK_SIZE * NUM_CP, (gpointer) values); ct = gst_util_get_timestamp (); g_free (values); elapsed = GST_CLOCK_DIFF (bt, ct);