libs/gst/controller/: Don't crash if someone tries to set an interpolation mode that is invalid or that isn't support...

Original commit message from CVS:
* libs/gst/controller/gstcontroller.c:
(gst_controlled_property_set_interpolation_mode):
* libs/gst/controller/gstinterpolation.c:
Don't crash if someone tries to set an interpolation mode that
is invalid or that isn't supported yet. Fixes #422295.
* tests/check/libs/controller.c: (GST_START_TEST),
(gst_controller_suite):
Add a test case for the above.
This commit is contained in:
Tim-Philipp Müller 2007-05-04 12:37:01 +00:00
parent c086db87a3
commit 42651f72ff
4 changed files with 53 additions and 0 deletions

View file

@ -1,3 +1,15 @@
2007-05-04 Tim-Philipp Müller <tim at centricular dot net>
* libs/gst/controller/gstcontroller.c:
(gst_controlled_property_set_interpolation_mode):
* libs/gst/controller/gstinterpolation.c:
Don't crash if someone tries to set an interpolation mode that
is invalid or that isn't supported yet. Fixes #422295.
* tests/check/libs/controller.c: (GST_START_TEST),
(gst_controller_suite):
Add a test case for the above.
2007-05-03 Edward Hervey <edward@fluendo.com>
* libs/gst/base/gstbasetransform.c: (gst_base_transform_chain):

View file

@ -95,6 +95,7 @@ extern GList
* gst_controlled_property_find_timed_value_node (GstControlledProperty *
prop, GstClockTime timestamp);
extern GstInterpolateMethod *interpolation_methods[];
extern guint num_interpolation_methods;
/* callbacks */
@ -181,6 +182,11 @@ gst_controlled_property_set_interpolation_mode (GstControlledProperty * self,
{
gboolean res = TRUE;
if (mode >= num_interpolation_methods || interpolation_methods[mode] == NULL) {
GST_WARNING ("interpolation mode %d invalid or not implemented yet", mode);
return FALSE;
}
self->interpolation = mode;
if (mode != GST_INTERPOLATE_USER) {
switch (self->base) {

View file

@ -319,3 +319,5 @@ GstInterpolateMethod *interpolation_methods[] = {
NULL,
NULL
};
guint num_interpolation_methods = G_N_ELEMENTS (interpolation_methods);

View file

@ -638,6 +638,38 @@ GST_START_TEST (controller_interpolate_linear)
GST_END_TEST;
/* make sure we don't crash when someone sets an unsupported interpolation
* mode */
GST_START_TEST (controller_interpolate_unimplemented)
{
GstController *ctrl;
GstElement *elem;
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 unsupported interpolation mode */
gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_CUBIC);
/* set another unsupported interpolation mode */
gst_controller_set_interpolation_mode (ctrl, "ulong",
GST_INTERPOLATE_QUADRATIC);
/* set completely bogus interpolation mode */
gst_controller_set_interpolation_mode (ctrl, "ulong",
(GstInterpolateMode) 93871);
g_object_unref (ctrl);
gst_object_unref (elem);
}
GST_END_TEST;
/* test _unset() */
GST_START_TEST (controller_unset)
{
@ -958,6 +990,7 @@ gst_controller_suite (void)
tcase_add_test (tc, controller_interpolate_none);
tcase_add_test (tc, controller_interpolate_trigger);
tcase_add_test (tc, controller_interpolate_linear);
tcase_add_test (tc, controller_interpolate_unimplemented);
tcase_add_test (tc, controller_unset);
tcase_add_test (tc, controller_unset_all);
tcase_add_test (tc, controller_live);