+2007-05-21 Sebastian Dröge <slomo@circular-chaos.org>
+
+ * 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 <thaytan@mad.scientist.com>
* tests/check/gst/gstbuffer.c: (GST_START_TEST):
* 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
*/
* @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,
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);
}
*
* Sets the given interpolation mode on the given property.
*
- * <note><para>Quadratic, qubic and user interpolation is not yet available.
+ * <note><para>Quadratic, cubic and user interpolation is not yet available.
* </para></note>
*
* Returns: %TRUE if the property is handled by the controller, %FALSE otherwise
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
* @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
{
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)
{
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;
}