From 51424c0da5c2dabf15c414905a5b396790d6ff52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 21 May 2007 21:34:49 +0000 Subject: [PATCH] libs/gst/controller/gstcontroller.*: Clarify the docs of gst_controller_get_value_array(): The array where the values... Original commit message from CVS: * libs/gst/controller/gstcontroller.c: (gst_controller_get_value_array): * libs/gst/controller/gstcontroller.h: Clarify the docs of gst_controller_get_value_array(): The array where the values should be written to must be allocated as there seems to be no way to get the size of a random GType. This doesn't change any behaviour. Also fix some typos all over the place and remove an unused, commented function that is not necessary as g_object_set() could be used instead. * tests/check/libs/controller.c: (GST_START_TEST), (gst_controller_suite): Add unit test for gst_controller_get_value_array(). --- ChangeLog | 15 ++++++++++ libs/gst/controller/gstcontroller.c | 55 +++++++++++-------------------------- libs/gst/controller/gstcontroller.h | 1 - tests/check/libs/controller.c | 50 +++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3b22c1..0d93afc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-05-21 Sebastian Dröge + + * libs/gst/controller/gstcontroller.c: + (gst_controller_get_value_array): + * libs/gst/controller/gstcontroller.h: + Clarify the docs of gst_controller_get_value_array(): The array where + the values should be written to must be allocated as there seems to be + no way to get the size of a random GType. This doesn't change any + behaviour. Also fix some typos all over the place and remove an unused, + commented function that is not necessary as g_object_set() could be + used instead. + * tests/check/libs/controller.c: (GST_START_TEST), + (gst_controller_suite): + Add unit test for gst_controller_get_value_array(). + 2007-05-21 Jan Schmidt * tests/check/gst/gstbuffer.c: (GST_START_TEST): diff --git a/libs/gst/controller/gstcontroller.c b/libs/gst/controller/gstcontroller.c index 47bf671..10de02b 100644 --- a/libs/gst/controller/gstcontroller.c +++ b/libs/gst/controller/gstcontroller.c @@ -1070,9 +1070,11 @@ gst_controller_sync_values (GstController * self, GstClockTime timestamp) * Function to be able to get an array of values for one or more given element * properties. * - * If the GstValueArray->values array in list nodes 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. + * All fields of the %GstValueArray in the list must be filled correctly. + * Especially the GstValueArray->values arrays must be big enough to keep + * the requested amount of values. + * + * The types of the values in the array are the same as the property's type. * * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise */ @@ -1100,12 +1102,15 @@ gst_controller_get_value_arrays (GstController * self, * @timestamp: the time that should be processed * @value_array: array to put control-values in * - * Function to be able to get an array of values for one element properties + * Function to be able to get an array of values for one element property. * - * 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. + * All fields of @value_array must be filled correctly. Especially the + * @value_array->values array must be big enough to keep the requested amount + * of values. * - * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise + * The type of the values in the array is the same as the property's type. + * + * Returns: %TRUE if the given array could be filled, %FALSE otherwise */ gboolean gst_controller_get_value_array (GstController * self, GstClockTime timestamp, @@ -1118,23 +1123,17 @@ gst_controller_get_value_array (GstController * self, GstClockTime timestamp, 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); - - /* TODO and if GstValueArray->values is not NULL, the caller is resposible that - is is big enough for nbsamples values, right? - */ + g_return_val_if_fail (value_array->values, FALSE); g_mutex_lock (self->lock); + if ((prop = gst_controller_find_controlled_property (self, value_array->property_name))) { - if (!value_array->values) { - /* TODO from where to get the base size - value_array->values=g_new(sizeof(???),nbsamples); - */ - } /* get current value_array via interpolator */ res = prop->get_value_array (prop, timestamp, value_array); } + g_mutex_unlock (self->lock); return (res); } @@ -1147,7 +1146,7 @@ gst_controller_get_value_array (GstController * self, GstClockTime timestamp, * * Sets the given interpolation mode on the given property. * - * Quadratic, qubic and user interpolation is not yet available. + * Quadratic, cubic and user interpolation is not yet available. * * * Returns: %TRUE if the property is handled by the controller, %FALSE otherwise @@ -1174,28 +1173,6 @@ gst_controller_set_interpolation_mode (GstController * self, return (res); } -/* -void -gst_controller_set_live_value(GstController * self, gchar *property_name, - GstClockTime timestamp, GValue *value) -{ - GstControlledProperty *prop; - - g_return_if_fail (GST_IS_CONTROLLER (self)); - g_return_if_fail (property_name); - - g_mutex_lock (self->lock); - if ((prop = gst_controller_find_controlled_property (self, property_name))) { - g_value_unset (&prop->live_value.value); - g_value_init (&prop->live_value.value, prop->type); - g_value_copy (value, &prop->live_value.value); - prop->live_value.timestamp = timestamp; - } - g_mutex_unlock (self->lock); -} - -*/ - /* gobject handling */ static void diff --git a/libs/gst/controller/gstcontroller.h b/libs/gst/controller/gstcontroller.h index 996be79..2f2bbcd 100644 --- a/libs/gst/controller/gstcontroller.h +++ b/libs/gst/controller/gstcontroller.h @@ -62,7 +62,6 @@ typedef struct _GstTimedValue * @values: pointer to the array * * Structure to receive multiple values at once. - * If the pointer to the values array is NULL, it will be allocated (CHECKME). */ typedef struct _GstValueArray { diff --git a/tests/check/libs/controller.c b/tests/check/libs/controller.c index 91d5f49..dd52ed2 100644 --- a/tests/check/libs/controller.c +++ b/tests/check/libs/controller.c @@ -970,6 +970,55 @@ GST_START_TEST (controller_refcount_new_list) GST_END_TEST; + +/* test retrieval of an array of values with get_value_array() */ +GST_START_TEST (controller_interpolate_linear_value_array) +{ + GstController *ctrl; + GstElement *elem; + gboolean res; + GValue val_ulong = { 0, }; + GstValueArray values = { 0, }; + + gst_controller_init (NULL, NULL); + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and should be controllable */ + ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL); + fail_unless (ctrl != NULL, NULL); + + /* set interpolation mode */ + gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_LINEAR); + + /* set control values */ + g_value_init (&val_ulong, G_TYPE_ULONG); + g_value_set_ulong (&val_ulong, 0); + res = gst_controller_set (ctrl, "ulong", 0 * GST_SECOND, &val_ulong); + fail_unless (res, NULL); + g_value_set_ulong (&val_ulong, 100); + res = gst_controller_set (ctrl, "ulong", 2 * GST_SECOND, &val_ulong); + fail_unless (res, NULL); + + /* now pull in values for some timestamps */ + values.property_name = "ulong"; + values.nbsamples = 3; + values.sample_interval = GST_SECOND; + values.values = (gpointer) g_new (gulong, 3); + + fail_unless (gst_controller_get_value_array (ctrl, 0, &values)); + fail_unless_equals_int (((gulong *) values.values)[0], 0); + fail_unless_equals_int (((gulong *) values.values)[1], 50); + fail_unless_equals_int (((gulong *) values.values)[2], 100); + + GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); + g_free (values.values); + g_object_unref (ctrl); + gst_object_unref (elem); +} + +GST_END_TEST; + static Suite * gst_controller_suite (void) { @@ -998,6 +1047,7 @@ gst_controller_suite (void) tcase_add_test (tc, controller_live); tcase_add_test (tc, controller_helper_any_gobject); tcase_add_test (tc, controller_misc); + tcase_add_test (tc, controller_interpolate_linear_value_array); return s; } -- 2.7.4