From f02b655fc07b6975999f774688d6d1ba41b90552 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Wed, 31 Aug 2005 10:00:08 +0000 Subject: [PATCH] check/gst-libs/controller.c: more tests (hehe I have the most) Original commit message from CVS: * check/gst-libs/controller.c: (gst_test_mono_source_get_property), (gst_test_mono_source_set_property), (gst_test_mono_source_class_init), (GST_START_TEST), (gst_controller_suite): more tests (hehe I have the most) * gst/gstbus.c: describe popping messages whenusing mulltiple sources * libs/gst/controller/gst-controller.c: (gst_controlled_property_set_interpolation_mode), (gst_controlled_property_new): * libs/gst/controller/gst-controller.h: * libs/gst/controller/gst-interpolation.c: implement boolean properties --- ChangeLog | 16 ++++++ check/gst-libs/controller.c | 94 ++++++++++++++++++++++++++++++++- gst/gstbus.c | 6 +++ libs/gst/controller/gst-controller.c | 29 +++++++--- libs/gst/controller/gst-controller.h | 2 + libs/gst/controller/gst-interpolation.c | 9 +++- libs/gst/controller/gstcontroller.c | 29 +++++++--- libs/gst/controller/gstcontroller.h | 2 + libs/gst/controller/gstinterpolation.c | 9 +++- tests/check/libs/controller.c | 94 ++++++++++++++++++++++++++++++++- 10 files changed, 274 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43a2fc6..922ecee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2005-08-31 Stefan Kost + + * check/gst-libs/controller.c: (gst_test_mono_source_get_property), + (gst_test_mono_source_set_property), + (gst_test_mono_source_class_init), (GST_START_TEST), + (gst_controller_suite): + more tests (hehe I have the most) + * gst/gstbus.c: + describe popping messages whenusing mulltiple sources + * libs/gst/controller/gst-controller.c: + (gst_controlled_property_set_interpolation_mode), + (gst_controlled_property_new): + * libs/gst/controller/gst-controller.h: + * libs/gst/controller/gst-interpolation.c: + implement boolean properties + 2005-08-31 Wim Taymans * gst/gstminiobject.c: (gst_mini_object_ref): diff --git a/check/gst-libs/controller.c b/check/gst-libs/controller.c index e7c334f..c20fce9 100644 --- a/check/gst-libs/controller.c +++ b/check/gst-libs/controller.c @@ -31,6 +31,9 @@ enum ARG_ULONG = 1, ARG_DOUBLE, ARG_BOOLEAN, + ARG_READONLY, + ARG_STATIC, + ARG_CONSTRUCTONLY, ARG_COUNT }; @@ -49,7 +52,7 @@ struct _GstTestMonoSource GstElement parent; gulong val_ulong; gdouble val_double; - gboolean val_bool; + gboolean val_boolean; }; struct _GstTestMonoSourceClass { @@ -71,6 +74,9 @@ gst_test_mono_source_get_property (GObject * object, case ARG_DOUBLE: g_value_set_double (value, self->val_double); break; + case ARG_BOOLEAN: + g_value_set_boolean (value, self->val_boolean); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -90,6 +96,11 @@ gst_test_mono_source_set_property (GObject * object, case ARG_DOUBLE: self->val_double = g_value_get_double (value); break; + case ARG_BOOLEAN: + self->val_boolean = g_value_get_boolean (value); + break; + case ARG_CONSTRUCTONLY: + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -115,6 +126,30 @@ gst_test_mono_source_class_init (GstTestMonoSourceClass * klass) "double prop", "double number parameter for the test_mono_source", 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, ARG_BOOLEAN, + g_param_spec_boolean ("boolean", + "boolean prop", + "boolean parameter for the test_mono_source", + FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, ARG_READONLY, + g_param_spec_ulong ("readonly", + "readonly prop", + "readonly parameter for the test_mono_source", + 0, G_MAXULONG, 0, G_PARAM_READABLE | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, ARG_STATIC, + g_param_spec_ulong ("static", + "static prop", + "static parameter for the test_mono_source", + 0, G_MAXULONG, 0, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, ARG_CONSTRUCTONLY, + g_param_spec_ulong ("construct-only", + "construct-only prop", + "construct-only parameter for the test_mono_source", + 0, G_MAXULONG, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static void @@ -214,6 +249,60 @@ GST_START_TEST (controller_new_fail2) GST_END_TEST; +/* tests for readonly params */ +GST_START_TEST (controller_new_fail3) +{ + GstController *ctrl; + GstElement *elem; + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and but is readonly */ + ASSERT_CRITICAL (ctrl = + gst_controller_new (G_OBJECT (elem), "readonly", NULL)); + fail_unless (ctrl == NULL, NULL); + + g_object_unref (elem); +} + +GST_END_TEST; + +/* tests for static params */ +GST_START_TEST (controller_new_fail4) +{ + GstController *ctrl; + GstElement *elem; + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and but is not controlable */ + ASSERT_CRITICAL (ctrl = gst_controller_new (G_OBJECT (elem), "static", NULL)); + fail_unless (ctrl == NULL, NULL); + + g_object_unref (elem); +} + +GST_END_TEST; + +/* tests for static params */ +GST_START_TEST (controller_new_fail5) +{ + GstController *ctrl; + GstElement *elem; + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and but is construct-only */ + ASSERT_CRITICAL (ctrl = + gst_controller_new (G_OBJECT (elem), "construct-only", NULL)); + fail_unless (ctrl == NULL, NULL); + + g_object_unref (elem); +} + +GST_END_TEST; + + /* tests for an element with controlled params */ GST_START_TEST (controller_new_okay1) { @@ -393,6 +482,9 @@ gst_controller_suite (void) tcase_add_test (tc, controller_init); tcase_add_test (tc, controller_new_fail1); tcase_add_test (tc, controller_new_fail2); + tcase_add_test (tc, controller_new_fail3); + tcase_add_test (tc, controller_new_fail4); + tcase_add_test (tc, controller_new_fail5); tcase_add_test (tc, controller_new_okay1); tcase_add_test (tc, controller_new_okay2); tcase_add_test (tc, controller_new_okay3); diff --git a/gst/gstbus.c b/gst/gstbus.c index b3e5337..68fee56 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -51,8 +51,14 @@ * possible to react to a message in the same thread that posted the * message on the bus. This should only be used if the application is able * to deal with messages from different threads. + * + * It is important to make sure that every message is popped from the bus at + * some point in time. Otherwise it will be presented to the watches (#GSource + * elements) again and again. One way to implement it is having one watch with a + * low priority (see gst_add_watch_full()) that pops all messages. * * Every #GstElement has its own bus. + * */ #include diff --git a/libs/gst/controller/gst-controller.c b/libs/gst/controller/gst-controller.c index 2c5374e..a7c295b 100644 --- a/libs/gst/controller/gst-controller.c +++ b/libs/gst/controller/gst-controller.c @@ -161,11 +161,15 @@ gst_timed_value_find (gconstpointer p1, gconstpointer p2) * * Sets the given Interpolation mode for the controlled property and activates * the respective interpolation hooks. + * + * Returns: %TRUE for success */ static gboolean gst_controlled_property_set_interpolation_mode (GstControlledProperty * self, GstInterpolateMode mode) { + gboolean res = TRUE; + self->interpolation = mode; if (mode != GST_INTERPOLATE_USER) { switch (self->type) { @@ -191,17 +195,27 @@ gst_controlled_property_set_interpolation_mode (GstControlledProperty * self, self->get_value_array = interpolation_methods[mode]->get_double_value_array; break; + case G_TYPE_BOOLEAN: + self->get = interpolation_methods[mode]->get_boolean; + self->get_value_array = + interpolation_methods[mode]->get_boolean_value_array; + break; + break; default: self->get = NULL; self->get_value_array = NULL; - GST_WARNING ("incomplete implementation for type '%d'", self->type); + } + if (!self->get || !self->get_value_array) { + GST_WARNING ("incomplete implementation for type '%d'", self->type); + res = FALSE; } } else { /* TODO shouldn't this also get a GstInterpolateMethod *user_method for the case mode==GST_INTERPOLATE_USER */ + res = FALSE; } - return (TRUE); + return (res); } /* @@ -227,10 +241,13 @@ gst_controlled_property_new (GObject * object, const gchar * name) g_object_class_find_property (G_OBJECT_GET_CLASS (object), name))) { GST_DEBUG (" psec->flags : 0x%08x", pspec->flags); - // check if this param is controlable - g_return_val_if_fail (!(pspec-> - flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)), NULL); - //g_return_val_if_fail((pspec->flags&GST_PARAM_CONTROLLABLE),NULL); + // check if this param is witable + g_return_val_if_fail ((pspec->flags & G_PARAM_WRITABLE), NULL); + // check if property is controlable + g_return_val_if_fail ((pspec->flags & GST_PARAM_CONTROLLABLE), NULL); + // check if this param is not construct-only + g_return_val_if_fail (!(pspec->flags & G_PARAM_CONSTRUCT_ONLY), NULL); + /* TODO do sanity checks we don't control some pspec->value_type: G_TYPE_PARAM_BOXED diff --git a/libs/gst/controller/gst-controller.h b/libs/gst/controller/gst-controller.h index 4234eea..95fa19d 100644 --- a/libs/gst/controller/gst-controller.h +++ b/libs/gst/controller/gst-controller.h @@ -123,6 +123,8 @@ typedef struct _GstInterpolateMethod InterpolateGetValueArray get_float_value_array; InterpolateGet get_double; InterpolateGetValueArray get_double_value_array; + InterpolateGet get_boolean; + InterpolateGetValueArray get_boolean_value_array; } GstInterpolateMethod; /** diff --git a/libs/gst/controller/gst-interpolation.c b/libs/gst/controller/gst-interpolation.c index 992fe6e..5fdd9d1 100644 --- a/libs/gst/controller/gst-interpolation.c +++ b/libs/gst/controller/gst-interpolation.c @@ -111,6 +111,7 @@ DEFINE_NONE_GET (int) DEFINE_NONE_GET (long) DEFINE_NONE_GET (float) DEFINE_NONE_GET (double) +DEFINE_NONE_GET (boolean) static GstInterpolateMethod interpolate_none = { interpolate_none_get, @@ -120,7 +121,9 @@ DEFINE_NONE_GET (double) interpolate_none_get, interpolate_none_get_float_value_array, interpolate_none_get, - interpolate_none_get_double_value_array + interpolate_none_get_double_value_array, + interpolate_none_get, + interpolate_none_get_boolean_value_array }; // returns the default value of the property, except for times with specific values @@ -158,6 +161,8 @@ static GstInterpolateMethod interpolate_trigger = { interpolate_trigger_get, NULL, interpolate_trigger_get, + NULL, + interpolate_trigger_get, NULL }; @@ -231,6 +236,8 @@ DEFINE_LINEAR_GET (double) interpolate_linear_get_float_value_array, interpolate_linear_get_double, interpolate_linear_get_double_value_array, + NULL, + NULL }; // square interpolation diff --git a/libs/gst/controller/gstcontroller.c b/libs/gst/controller/gstcontroller.c index 2c5374e..a7c295b 100644 --- a/libs/gst/controller/gstcontroller.c +++ b/libs/gst/controller/gstcontroller.c @@ -161,11 +161,15 @@ gst_timed_value_find (gconstpointer p1, gconstpointer p2) * * Sets the given Interpolation mode for the controlled property and activates * the respective interpolation hooks. + * + * Returns: %TRUE for success */ static gboolean gst_controlled_property_set_interpolation_mode (GstControlledProperty * self, GstInterpolateMode mode) { + gboolean res = TRUE; + self->interpolation = mode; if (mode != GST_INTERPOLATE_USER) { switch (self->type) { @@ -191,17 +195,27 @@ gst_controlled_property_set_interpolation_mode (GstControlledProperty * self, self->get_value_array = interpolation_methods[mode]->get_double_value_array; break; + case G_TYPE_BOOLEAN: + self->get = interpolation_methods[mode]->get_boolean; + self->get_value_array = + interpolation_methods[mode]->get_boolean_value_array; + break; + break; default: self->get = NULL; self->get_value_array = NULL; - GST_WARNING ("incomplete implementation for type '%d'", self->type); + } + if (!self->get || !self->get_value_array) { + GST_WARNING ("incomplete implementation for type '%d'", self->type); + res = FALSE; } } else { /* TODO shouldn't this also get a GstInterpolateMethod *user_method for the case mode==GST_INTERPOLATE_USER */ + res = FALSE; } - return (TRUE); + return (res); } /* @@ -227,10 +241,13 @@ gst_controlled_property_new (GObject * object, const gchar * name) g_object_class_find_property (G_OBJECT_GET_CLASS (object), name))) { GST_DEBUG (" psec->flags : 0x%08x", pspec->flags); - // check if this param is controlable - g_return_val_if_fail (!(pspec-> - flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)), NULL); - //g_return_val_if_fail((pspec->flags&GST_PARAM_CONTROLLABLE),NULL); + // check if this param is witable + g_return_val_if_fail ((pspec->flags & G_PARAM_WRITABLE), NULL); + // check if property is controlable + g_return_val_if_fail ((pspec->flags & GST_PARAM_CONTROLLABLE), NULL); + // check if this param is not construct-only + g_return_val_if_fail (!(pspec->flags & G_PARAM_CONSTRUCT_ONLY), NULL); + /* TODO do sanity checks we don't control some pspec->value_type: G_TYPE_PARAM_BOXED diff --git a/libs/gst/controller/gstcontroller.h b/libs/gst/controller/gstcontroller.h index 4234eea..95fa19d 100644 --- a/libs/gst/controller/gstcontroller.h +++ b/libs/gst/controller/gstcontroller.h @@ -123,6 +123,8 @@ typedef struct _GstInterpolateMethod InterpolateGetValueArray get_float_value_array; InterpolateGet get_double; InterpolateGetValueArray get_double_value_array; + InterpolateGet get_boolean; + InterpolateGetValueArray get_boolean_value_array; } GstInterpolateMethod; /** diff --git a/libs/gst/controller/gstinterpolation.c b/libs/gst/controller/gstinterpolation.c index 992fe6e..5fdd9d1 100644 --- a/libs/gst/controller/gstinterpolation.c +++ b/libs/gst/controller/gstinterpolation.c @@ -111,6 +111,7 @@ DEFINE_NONE_GET (int) DEFINE_NONE_GET (long) DEFINE_NONE_GET (float) DEFINE_NONE_GET (double) +DEFINE_NONE_GET (boolean) static GstInterpolateMethod interpolate_none = { interpolate_none_get, @@ -120,7 +121,9 @@ DEFINE_NONE_GET (double) interpolate_none_get, interpolate_none_get_float_value_array, interpolate_none_get, - interpolate_none_get_double_value_array + interpolate_none_get_double_value_array, + interpolate_none_get, + interpolate_none_get_boolean_value_array }; // returns the default value of the property, except for times with specific values @@ -158,6 +161,8 @@ static GstInterpolateMethod interpolate_trigger = { interpolate_trigger_get, NULL, interpolate_trigger_get, + NULL, + interpolate_trigger_get, NULL }; @@ -231,6 +236,8 @@ DEFINE_LINEAR_GET (double) interpolate_linear_get_float_value_array, interpolate_linear_get_double, interpolate_linear_get_double_value_array, + NULL, + NULL }; // square interpolation diff --git a/tests/check/libs/controller.c b/tests/check/libs/controller.c index e7c334f..c20fce9 100644 --- a/tests/check/libs/controller.c +++ b/tests/check/libs/controller.c @@ -31,6 +31,9 @@ enum ARG_ULONG = 1, ARG_DOUBLE, ARG_BOOLEAN, + ARG_READONLY, + ARG_STATIC, + ARG_CONSTRUCTONLY, ARG_COUNT }; @@ -49,7 +52,7 @@ struct _GstTestMonoSource GstElement parent; gulong val_ulong; gdouble val_double; - gboolean val_bool; + gboolean val_boolean; }; struct _GstTestMonoSourceClass { @@ -71,6 +74,9 @@ gst_test_mono_source_get_property (GObject * object, case ARG_DOUBLE: g_value_set_double (value, self->val_double); break; + case ARG_BOOLEAN: + g_value_set_boolean (value, self->val_boolean); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -90,6 +96,11 @@ gst_test_mono_source_set_property (GObject * object, case ARG_DOUBLE: self->val_double = g_value_get_double (value); break; + case ARG_BOOLEAN: + self->val_boolean = g_value_get_boolean (value); + break; + case ARG_CONSTRUCTONLY: + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -115,6 +126,30 @@ gst_test_mono_source_class_init (GstTestMonoSourceClass * klass) "double prop", "double number parameter for the test_mono_source", 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, ARG_BOOLEAN, + g_param_spec_boolean ("boolean", + "boolean prop", + "boolean parameter for the test_mono_source", + FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, ARG_READONLY, + g_param_spec_ulong ("readonly", + "readonly prop", + "readonly parameter for the test_mono_source", + 0, G_MAXULONG, 0, G_PARAM_READABLE | GST_PARAM_CONTROLLABLE)); + + g_object_class_install_property (gobject_class, ARG_STATIC, + g_param_spec_ulong ("static", + "static prop", + "static parameter for the test_mono_source", + 0, G_MAXULONG, 0, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, ARG_CONSTRUCTONLY, + g_param_spec_ulong ("construct-only", + "construct-only prop", + "construct-only parameter for the test_mono_source", + 0, G_MAXULONG, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static void @@ -214,6 +249,60 @@ GST_START_TEST (controller_new_fail2) GST_END_TEST; +/* tests for readonly params */ +GST_START_TEST (controller_new_fail3) +{ + GstController *ctrl; + GstElement *elem; + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and but is readonly */ + ASSERT_CRITICAL (ctrl = + gst_controller_new (G_OBJECT (elem), "readonly", NULL)); + fail_unless (ctrl == NULL, NULL); + + g_object_unref (elem); +} + +GST_END_TEST; + +/* tests for static params */ +GST_START_TEST (controller_new_fail4) +{ + GstController *ctrl; + GstElement *elem; + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and but is not controlable */ + ASSERT_CRITICAL (ctrl = gst_controller_new (G_OBJECT (elem), "static", NULL)); + fail_unless (ctrl == NULL, NULL); + + g_object_unref (elem); +} + +GST_END_TEST; + +/* tests for static params */ +GST_START_TEST (controller_new_fail5) +{ + GstController *ctrl; + GstElement *elem; + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and but is construct-only */ + ASSERT_CRITICAL (ctrl = + gst_controller_new (G_OBJECT (elem), "construct-only", NULL)); + fail_unless (ctrl == NULL, NULL); + + g_object_unref (elem); +} + +GST_END_TEST; + + /* tests for an element with controlled params */ GST_START_TEST (controller_new_okay1) { @@ -393,6 +482,9 @@ gst_controller_suite (void) tcase_add_test (tc, controller_init); tcase_add_test (tc, controller_new_fail1); tcase_add_test (tc, controller_new_fail2); + tcase_add_test (tc, controller_new_fail3); + tcase_add_test (tc, controller_new_fail4); + tcase_add_test (tc, controller_new_fail5); tcase_add_test (tc, controller_new_okay1); tcase_add_test (tc, controller_new_okay2); tcase_add_test (tc, controller_new_okay3); -- 2.7.4