📄 controller.c
字号:
gst_controller_sync_values (ctrl, 0 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL); gst_controller_sync_values (ctrl, 1 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL); gst_controller_sync_values (ctrl, 2 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL); /* unset second */ res = gst_controller_unset (ctrl, "ulong", 1 * GST_SECOND); fail_unless (res, NULL); /* verify value again */ gst_controller_sync_values (ctrl, 1 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL); gst_controller_sync_values (ctrl, 2 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); g_object_unref (ctrl); gst_object_unref (elem);}GST_END_TEST;/* test _unset_all() */GST_START_TEST (controller_unset_all){ GstController *ctrl; GstElement *elem; gboolean res; GValue val_ulong = { 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_NONE); /* 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", 1 * GST_SECOND, &val_ulong); fail_unless (res, NULL); /* verify values */ gst_controller_sync_values (ctrl, 0 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL); gst_controller_sync_values (ctrl, 1 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL); /* unset second */ res = gst_controller_unset_all (ctrl, "ulong"); fail_unless (res, NULL); /* verify value again */ gst_controller_sync_values (ctrl, 1 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 0, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); g_object_unref (ctrl); gst_object_unref (elem);}GST_END_TEST;/* test live value handling */GST_START_TEST (controller_live){ GstController *ctrl; GstElement *elem; gboolean res; GValue val_ulong = { 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", 4 * GST_SECOND, &val_ulong); fail_unless (res, NULL); g_value_set_ulong (&val_ulong, 200); res = gst_controller_set (ctrl, "ulong", 8 * GST_SECOND, &val_ulong); fail_unless (res, NULL); /* verify value */ gst_controller_sync_values (ctrl, 2 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 50, NULL); /* set live value */ g_object_set (elem, "ulong", 500, NULL); /* we should still get the live value */ gst_controller_sync_values (ctrl, 3 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 500, NULL); /* we should not get the live value anymore */ gst_controller_sync_values (ctrl, 4 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 100, NULL); gst_controller_sync_values (ctrl, 6 * GST_SECOND); fail_unless (GST_TEST_MONO_SOURCE (elem)->val_ulong == 150, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); g_object_unref (ctrl); gst_object_unref (elem);}GST_END_TEST;/* tests if we can run helper methods against any GObject */GST_START_TEST (controller_helper_any_gobject){ GstElement *elem; gboolean res; gst_controller_init (NULL, NULL); elem = gst_element_factory_make ("bin", "test_elem"); /* that element is not controllable */ res = gst_object_sync_values (G_OBJECT (elem), 0LL); fail_unless (res == FALSE, NULL); gst_object_unref (elem);}GST_END_TEST;GST_START_TEST (controller_misc){ GstController *ctrl; GstTimedValue *tval; GstElement *elem; GSList *list = NULL; gst_controller_init (NULL, NULL); /* test that an invalid timestamp throws a warning of some sort */ 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 value */ tval = g_new0 (GstTimedValue, 1); tval->timestamp = GST_CLOCK_TIME_NONE; g_value_init (&tval->value, G_TYPE_ULONG); g_value_set_ulong (&tval->value, 0); list = g_slist_append (list, tval); ASSERT_WARNING (fail_if (gst_controller_set_from_list (ctrl, "ulong", list))); /* try again with a valid stamp, should work now */ tval->timestamp = 0; fail_unless (gst_controller_set_from_list (ctrl, "ulong", list)); /* allocated GstTimedValue now belongs to the controller, but list not */ g_value_unset (&tval->value); g_free (tval); g_slist_free (list); g_object_unref (ctrl); gst_object_unref (elem);}GST_END_TEST;GST_START_TEST (controller_refcount_new_list){ GstController *ctrl, *ctrl2; GstElement *elem; GList *list = NULL; gst_controller_init (NULL, NULL); /* that property should exist and should be controllable */ elem = gst_element_factory_make ("testmonosource", "test_source"); list = g_list_append (NULL, "ulong"); ctrl = gst_controller_new_list (G_OBJECT (elem), list); fail_unless (ctrl != NULL, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); fail_unless (G_OBJECT (ctrl)->ref_count == 1); g_list_free (list); g_object_unref (ctrl); gst_object_unref (elem); /* try the same property twice, make sure the refcount is still 1 */ elem = gst_element_factory_make ("testmonosource", "test_source"); list = g_list_append (NULL, "ulong"); list = g_list_append (list, "ulong"); ctrl = gst_controller_new_list (G_OBJECT (elem), list); fail_unless (ctrl != NULL, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); fail_unless (G_OBJECT (ctrl)->ref_count == 1); g_list_free (list); g_object_unref (ctrl); gst_object_unref (elem); /* try two properties, make sure the refcount is still 1 */ elem = gst_element_factory_make ("testmonosource", "test_source"); list = g_list_append (NULL, "ulong"); list = g_list_append (list, "boolean"); ctrl = gst_controller_new_list (G_OBJECT (elem), list); fail_unless (ctrl != NULL, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); fail_unless (G_OBJECT (ctrl)->ref_count == 1); g_list_free (list); g_object_unref (ctrl); gst_object_unref (elem); /* try _new_list with existing controller */ elem = gst_element_factory_make ("testmonosource", "test_source"); ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL); fail_unless (ctrl != NULL, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); list = g_list_append (NULL, "ulong"); ctrl2 = gst_controller_new_list (G_OBJECT (elem), list); fail_unless (ctrl2 != NULL, NULL); fail_unless (ctrl == ctrl2, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); fail_unless (G_OBJECT (ctrl)->ref_count == 2); g_list_free (list); g_object_unref (ctrl); g_object_unref (ctrl2); gst_object_unref (elem); /* try _new_list first and then _new */ elem = gst_element_factory_make ("testmonosource", "test_source"); list = g_list_append (NULL, "ulong"); ctrl = gst_controller_new_list (G_OBJECT (elem), list); fail_unless (ctrl != NULL, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); ctrl2 = gst_controller_new (G_OBJECT (elem), "ulong", NULL); fail_unless (ctrl2 != NULL, NULL); fail_unless (ctrl == ctrl2, NULL); GST_INFO ("controller->ref_count=%d", G_OBJECT (ctrl)->ref_count); fail_unless (G_OBJECT (ctrl)->ref_count == 2); g_list_free (list); g_object_unref (ctrl); g_object_unref (ctrl2); gst_object_unref (elem);}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){ Suite *s = suite_create ("Controller"); TCase *tc = tcase_create ("general"); suite_add_tcase (s, tc); tcase_add_test (tc, controller_init); tcase_add_test (tc, controller_refcount_new_list); 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); tcase_add_test (tc, controller_param_twice); tcase_add_test (tc, controller_finalize); 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); 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;}GST_CHECK_MAIN (gst_controller);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -