check/gst/gstplugin.c: More testing

Original commit message from CVS:
* check/gst/gstplugin.c: (register_check_elements),
(GST_START_TEST), (peek), (suggest), (gst_plugin_suite):
More testing
* gst/elements/gsttypefindelement.c: Fix refcounting.
* gst/gsttypefind.c:
* gst/gsttypefindfactory.c:
* gst/gsttypefindfactory.h:
This commit is contained in:
David Schleef 2005-09-16 03:46:14 +00:00
parent 41cd7b46c6
commit 02bde78085
9 changed files with 149 additions and 50 deletions

View file

@ -1,3 +1,13 @@
2005-09-15 David Schleef <ds@schleef.org>
* check/gst/gstplugin.c: (register_check_elements),
(GST_START_TEST), (peek), (suggest), (gst_plugin_suite):
More testing
* gst/elements/gsttypefindelement.c: Fix refcounting.
* gst/gsttypefind.c:
* gst/gsttypefindfactory.c:
* gst/gsttypefindfactory.h:
2005-09-15 David Schleef <ds@schleef.org>
* gst/gstindex.c: get refcounting correct.

View file

@ -136,6 +136,58 @@ GST_START_TEST (test_find_feature)
GST_END_TEST;
guint8 *
peek (gpointer data, gint64 offset, guint size)
{
return NULL;
}
void
suggest (gpointer data, guint probability, const GstCaps * caps)
{
}
GST_START_TEST (test_typefind)
{
GstPlugin *plugin;
GstPluginFeature *feature;
GstTypeFind typefind = {
peek,
suggest,
NULL,
NULL,
GST_PADDING_INIT
};
plugin = gst_default_registry_find_plugin ("typefindfunctions");
fail_if (plugin == NULL, "Failed to find typefind functions");
fail_if (plugin->object.refcount != 2,
"Refcount of plugin in registry should be 2");
fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
feature = gst_registry_find_feature (gst_registry_get_default (),
"audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
fail_if (feature->plugin != plugin,
"Expected indentity to be from gstelements plugin");
fail_if (plugin->object.refcount != 3,
"Refcount of plugin in registry+feature should be 3");
gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
&typefind);
gst_object_unref (feature->plugin);
fail_if (plugin->object.refcount != 1,
"Refcount of plugin in after list free should be 1");
gst_object_unref (plugin);
}
GST_END_TEST;
Suite *
gst_plugin_suite (void)
{
@ -150,6 +202,7 @@ gst_plugin_suite (void)
tcase_add_test (tc_chain, test_load_gstelements);
tcase_add_test (tc_chain, test_registry_get_plugin_list);
tcase_add_test (tc_chain, test_find_feature);
tcase_add_test (tc_chain, test_typefind);
return s;
}

2
common

@ -1 +1 @@
Subproject commit 019a3be6a5b7cde92c5daae35fe189c8aebeb5b6
Subproject commit 62cd70d46eb00c3eb6b973b8a3b5fe6c202dbb29

View file

@ -632,7 +632,7 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer)
g_list_prepend (typefind->possibilities, entry);
all_factories = g_list_next (all_factories);
}
g_list_free (all_factories);
gst_plugin_feature_list_free (all_factories);
}
/* call every typefind function once */

View file

@ -62,18 +62,12 @@ gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
g_return_val_if_fail (func != NULL, FALSE);
GST_INFO ("registering typefind function for %s", name);
factory =
GST_TYPE_FIND_FACTORY (gst_registry_find_feature (gst_registry_get_default
(), name, GST_TYPE_TYPE_FIND_FACTORY));
if (!factory) {
factory = g_object_new (GST_TYPE_TYPE_FIND_FACTORY, NULL);
GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name);
g_assert (GST_IS_TYPE_FIND_FACTORY (factory));
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE (factory), name);
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
} else {
GST_DEBUG_OBJECT (factory, "using old typefind factory for %s", name);
}
factory = g_object_new (GST_TYPE_TYPE_FIND_FACTORY, NULL);
GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name);
g_assert (GST_IS_TYPE_FIND_FACTORY (factory));
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE (factory), name);
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory), rank);
if (factory->extensions)

View file

@ -92,8 +92,6 @@ static void gst_type_find_factory_init (GTypeInstance * instance,
gpointer g_class);
static void gst_type_find_factory_dispose (GObject * object);
static void gst_type_find_load_plugin (GstTypeFind * find, gpointer data);
static GstPluginFeatureClass *parent_class = NULL;
GType
@ -123,6 +121,7 @@ gst_type_find_factory_get_type (void)
return typefind_type;
}
static void
gst_type_find_factory_class_init (gpointer g_class, gpointer class_data)
{
@ -132,14 +131,15 @@ gst_type_find_factory_class_init (gpointer g_class, gpointer class_data)
object_class->dispose = gst_type_find_factory_dispose;
}
static void
gst_type_find_factory_init (GTypeInstance * instance, gpointer g_class)
{
GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (instance);
factory->user_data = factory;
factory->function = gst_type_find_load_plugin;
}
static void
gst_type_find_factory_dispose (GObject * object)
{
@ -154,28 +154,6 @@ gst_type_find_factory_dispose (GObject * object)
factory->extensions = NULL;
}
}
static void
gst_type_find_load_plugin (GstTypeFind * find, gpointer data)
{
GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (data);
GST_DEBUG_OBJECT (factory, "need to load typefind function %s",
GST_PLUGIN_FEATURE_NAME (factory));
factory =
GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
(factory)));
if (factory) {
if (factory->function == gst_type_find_load_plugin) {
/* looks like we didn't get a real typefind function */
g_warning ("could not load valid typefind function for feature '%s'\n",
GST_PLUGIN_FEATURE_NAME (factory));
} else {
g_assert (factory->function);
gst_type_find_factory_call_function (factory, find);
}
}
}
/**
* gst_type_find_factory_get_list:
@ -200,8 +178,8 @@ gst_type_find_factory_get_list (void)
*
* Returns: the #GstCaps associated with this factory
*/
const GstCaps *
gst_type_find_factory_get_caps (const GstTypeFindFactory * factory)
GstCaps *
gst_type_find_factory_get_caps (GstTypeFindFactory * factory)
{
g_return_val_if_fail (GST_IS_TYPE_FIND_FACTORY (factory), NULL);
@ -220,7 +198,7 @@ gst_type_find_factory_get_caps (const GstTypeFindFactory * factory)
* Returns: a NULL-terminated array of extensions associated with this factory
*/
gchar **
gst_type_find_factory_get_extensions (const GstTypeFindFactory * factory)
gst_type_find_factory_get_extensions (GstTypeFindFactory * factory)
{
g_return_val_if_fail (GST_IS_TYPE_FIND_FACTORY (factory), NULL);
@ -236,16 +214,27 @@ gst_type_find_factory_get_extensions (const GstTypeFindFactory * factory)
* Calls the typefinding function associated with this factory.
*/
void
gst_type_find_factory_call_function (const GstTypeFindFactory * factory,
gst_type_find_factory_call_function (GstTypeFindFactory * factory,
GstTypeFind * find)
{
GstTypeFindFactory *new_factory;
g_return_if_fail (GST_IS_TYPE_FIND_FACTORY (factory));
g_return_if_fail (find != NULL);
g_return_if_fail (find->peek != NULL);
g_return_if_fail (find->suggest != NULL);
/* should never happen */
g_assert (factory->function != NULL);
/* gst_plugin_feature_load will steal our ref */
gst_object_ref (factory->feature.plugin);
new_factory =
GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
(factory)));
if (new_factory) {
g_assert (new_factory->function != NULL);
factory->function (find, factory->user_data);
new_factory->function (find, new_factory->user_data);
/* FIXME hack. somehow, this refcount gets destroyed */
gst_object_ref (new_factory->feature.plugin);
//gst_object_unref (new_factory->feature.plugin);
}
}

View file

@ -70,9 +70,9 @@ GType gst_type_find_factory_get_type (void);
GList * gst_type_find_factory_get_list (void);
gchar ** gst_type_find_factory_get_extensions (const GstTypeFindFactory *factory);
const GstCaps * gst_type_find_factory_get_caps (const GstTypeFindFactory *factory);
void gst_type_find_factory_call_function (const GstTypeFindFactory *factory,
gchar ** gst_type_find_factory_get_extensions (GstTypeFindFactory *factory);
GstCaps * gst_type_find_factory_get_caps (GstTypeFindFactory *factory);
void gst_type_find_factory_call_function (GstTypeFindFactory *factory,
GstTypeFind *find);
G_END_DECLS

View file

@ -632,7 +632,7 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer)
g_list_prepend (typefind->possibilities, entry);
all_factories = g_list_next (all_factories);
}
g_list_free (all_factories);
gst_plugin_feature_list_free (all_factories);
}
/* call every typefind function once */

View file

@ -136,6 +136,58 @@ GST_START_TEST (test_find_feature)
GST_END_TEST;
guint8 *
peek (gpointer data, gint64 offset, guint size)
{
return NULL;
}
void
suggest (gpointer data, guint probability, const GstCaps * caps)
{
}
GST_START_TEST (test_typefind)
{
GstPlugin *plugin;
GstPluginFeature *feature;
GstTypeFind typefind = {
peek,
suggest,
NULL,
NULL,
GST_PADDING_INIT
};
plugin = gst_default_registry_find_plugin ("typefindfunctions");
fail_if (plugin == NULL, "Failed to find typefind functions");
fail_if (plugin->object.refcount != 2,
"Refcount of plugin in registry should be 2");
fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
feature = gst_registry_find_feature (gst_registry_get_default (),
"audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
fail_if (feature->plugin != plugin,
"Expected indentity to be from gstelements plugin");
fail_if (plugin->object.refcount != 3,
"Refcount of plugin in registry+feature should be 3");
gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
&typefind);
gst_object_unref (feature->plugin);
fail_if (plugin->object.refcount != 1,
"Refcount of plugin in after list free should be 1");
gst_object_unref (plugin);
}
GST_END_TEST;
Suite *
gst_plugin_suite (void)
{
@ -150,6 +202,7 @@ gst_plugin_suite (void)
tcase_add_test (tc_chain, test_load_gstelements);
tcase_add_test (tc_chain, test_registry_get_plugin_list);
tcase_add_test (tc_chain, test_find_feature);
tcase_add_test (tc_chain, test_typefind);
return s;
}