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.
* gst/gstregistry.c: Handle the case where a feature/plugin is
not found.
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)
{
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;
}
-Subproject commit 019a3be6a5b7cde92c5daae35fe189c8aebeb5b6
+Subproject commit 62cd70d46eb00c3eb6b973b8a3b5fe6c202dbb29
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 */
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)
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
return typefind_type;
}
+
static void
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)
{
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:
*
* 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);
* 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);
* 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);
+ }
}
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
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 */
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)
{
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;
}