Commit 1f037478 authored by Andy Wingo Wingo's avatar Andy Wingo Wingo
Browse files

fix refcounting tests so that they compile and run, but they fail currently:...

fix refcounting tests so that they compile and run, but they fail currently: gst leaks obscene amounts of memory ;) f...

Original commit message from CVS:
* fix refcounting tests so that they compile and run, but they fail currently:
gst leaks obscene amounts of memory ;)
* fix plugin loading test so that it only refers to plugins within the gstreamer/
tree
* store gst plugin paths in the registry
* is GST_REGISTRY is set, only use the user registry with the PLUGIN_PATH explictly
specified by the user
* all tests should pass now except refcounting
parent 4b8c43a3
......@@ -40,6 +40,7 @@ gchar *_gst_progname;
gboolean _gst_registry_auto_load = TRUE;
static GstRegistry *_global_registry;
static GstRegistry *_user_registry;
static gboolean _gst_registry_fixed = FALSE;
extern gint _gst_trace_on;
......@@ -287,12 +288,9 @@ init_pre (void)
gst_registry_add_path (_global_registry, PLUGINS_DIR);
#endif /* PLUGINS_USE_BUILDDIR */
gst_registry_pool_add (_global_registry, 100);
homedir = g_get_home_dir ();
user_reg = g_strjoin ("/", homedir, LOCAL_REGISTRY_FILE, NULL);
_user_registry = gst_xml_registry_new ("user_registry", user_reg);
gst_registry_pool_add (_user_registry, 50);
g_free (user_reg);
}
......@@ -369,6 +367,21 @@ init_post (void)
_gst_buffer_initialize ();
_gst_buffer_pool_initialize ();
if (!_gst_registry_fixed) {
/* don't override command-line options */
if (g_getenv ("GST_REGISTRY")) {
g_object_set (_user_registry, "location", g_getenv ("GST_REGISTRY"), NULL);
_gst_registry_fixed = TRUE;
}
}
if (!_gst_registry_fixed) {
gst_registry_pool_add (_global_registry, 100);
gst_registry_pool_add (_user_registry, 50);
} else {
gst_registry_pool_add (_user_registry, 50);
}
if (_gst_registry_auto_load) {
gst_registry_pool_load_all ();
}
......@@ -465,7 +478,8 @@ init_popt_callback (poptContext context, enum poptCallbackReason reason,
gst_scheduler_factory_set_default_name (arg);
break;
case ARG_REGISTRY:
GST_XML_REGISTRY (_global_registry)->location = g_strdup (arg);
g_object_set (G_OBJECT (_user_registry), "location", arg, NULL);
_gst_registry_fixed = TRUE;
break;
default:
g_warning ("option %d not recognized", option->val);
......
......@@ -195,15 +195,26 @@ gst_registry_unload (GstRegistry *registry)
* gst_registry_add_path:
* @registry: the registry to add the path to
*
* Add the given pathstring to the registry. The syntax of the
* pathstring is specific to the registry.
* Add the given path to the registry. The syntax of the
* path is specific to the registry. If the path has already been
* added, do nothing.
*/
void
gst_registry_add_path (GstRegistry *registry, const gchar *path)
{
GList *l;
g_return_if_fail (GST_IS_REGISTRY (registry));
g_return_if_fail (path != NULL);
l = registry->paths;
while (l) {
if (strcmp (l->data, path) == 0)
return;
l = g_list_next (l);
}
registry->paths = g_list_append (registry->paths, g_strdup (path));
}
......
......@@ -62,12 +62,12 @@ static gboolean gst_xml_registry_save (GstRegistry *registry);
static gboolean gst_xml_registry_rebuild (GstRegistry *registry);
static void gst_xml_registry_get_perms_func (GstXMLRegistry *registry);
static void gst_xml_registry_add_path_list_func (GstXMLRegistry *registry);
static gboolean gst_xml_registry_open_func (GstXMLRegistry *registry, GstXMLRegistryMode mode);
static gboolean gst_xml_registry_load_func (GstXMLRegistry *registry, gchar *data, gssize *size);
static gboolean gst_xml_registry_save_func (GstXMLRegistry *registry, gchar *format, ...);
static gboolean gst_xml_registry_close_func (GstXMLRegistry *registry);
static GstRegistryReturn gst_xml_registry_load_plugin (GstRegistry *registry, GstPlugin *plugin);
static void gst_xml_registry_start_element (GMarkupParseContext *context,
......@@ -94,6 +94,23 @@ static void gst_xml_registry_error (GMarkupParseContext *context,
GError *error,
gpointer user_data);
static void gst_xml_registry_paths_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error);
static void gst_xml_registry_paths_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error);
static void gst_xml_registry_paths_text (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error);
static GstRegistryClass *parent_class = NULL;
/* static guint gst_xml_registry_signals[LAST_SIGNAL] = { 0 }; */
......@@ -107,6 +124,16 @@ gst_xml_registry_parser =
gst_xml_registry_error,
};
static const GMarkupParser
gst_xml_registry_paths_parser =
{
gst_xml_registry_paths_start_element,
gst_xml_registry_paths_end_element,
gst_xml_registry_paths_text,
NULL,
NULL
};
GType
gst_xml_registry_get_type (void)
......@@ -159,6 +186,7 @@ gst_xml_registry_class_init (GstXMLRegistryClass *klass)
gstregistry_class->load_plugin = GST_DEBUG_FUNCPTR (gst_xml_registry_load_plugin);
gstxmlregistry_class->get_perms_func = GST_DEBUG_FUNCPTR (gst_xml_registry_get_perms_func);
gstxmlregistry_class->add_path_list_func = GST_DEBUG_FUNCPTR (gst_xml_registry_add_path_list_func);
gstxmlregistry_class->open_func = GST_DEBUG_FUNCPTR (gst_xml_registry_open_func);
gstxmlregistry_class->load_func = GST_DEBUG_FUNCPTR (gst_xml_registry_load_func);
gstxmlregistry_class->save_func = GST_DEBUG_FUNCPTR (gst_xml_registry_save_func);
......@@ -222,6 +250,9 @@ gst_xml_registry_set_property (GObject* object, guint prop_id,
if (CLASS (object)->get_perms_func)
CLASS (object)->get_perms_func (registry);
if (CLASS (object)->add_path_list_func)
CLASS (object)->add_path_list_func (registry);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -307,6 +338,46 @@ static void gst_xml_registry_get_perms_func (GstXMLRegistry *registry)
}
}
static void
gst_xml_registry_add_path_list_func (GstXMLRegistry *registry)
{
FILE *reg;
GMarkupParseContext *context;
gchar *text;
gssize size;
GError *error = NULL;
context = g_markup_parse_context_new (&gst_xml_registry_paths_parser, 0, registry, NULL);
if (! (reg = fopen (registry->location, "r"))) {
return;
}
text = g_malloc (BLOCK_SIZE);
size = fread (text, 1, BLOCK_SIZE, reg);
while (size) {
g_markup_parse_context_parse (context, text, size, &error);
if (error) {
fprintf(stderr, "ERROR: parsing registry: %s\n", error->message);
g_free (text);
fclose (reg);
return;
}
if (registry->state == GST_XML_REGISTRY_PATHS_DONE)
break;
size = fread (text, 1, BLOCK_SIZE, reg);
}
fclose (reg);
g_free (text);
}
static gboolean
plugin_times_older_than_recurse(gchar *path, time_t regtime)
{
......@@ -360,16 +431,9 @@ plugin_times_older_than(GList *paths, time_t regtime)
return TRUE;
}
static void
plugin_added_func (GstRegistry *registry, GstPlugin *plugin, gpointer user_data)
{
GST_INFO (GST_CAT_PLUGIN_LOADING, "added plugin %s with %d features\n", plugin->name, plugin->numfeatures);
}
static gboolean
gst_xml_registry_open_func (GstXMLRegistry *registry, GstXMLRegistryMode mode)
{
gulong handler_id;
GstRegistry *gst_registry;
GList *paths;
......@@ -384,13 +448,8 @@ gst_xml_registry_open_func (GstXMLRegistry *registry, GstXMLRegistryMode mode)
if (!plugin_times_older_than (paths, get_time (registry->location))) {
GST_INFO (GST_CAT_GST_INIT, "Registry out of date, rebuilding...");
handler_id = g_signal_connect (registry, "plugin_added",
G_CALLBACK (plugin_added_func), NULL);
gst_registry_rebuild (gst_registry);
g_signal_handler_disconnect (registry, handler_id);
if (gst_registry->flags & GST_REGISTRY_WRITABLE) {
gst_registry_save (gst_registry);
if (!plugin_times_older_than (paths, get_time (registry->location))) {
......@@ -452,13 +511,15 @@ gst_xml_registry_close_func (GstXMLRegistry *registry)
static gboolean
gst_xml_registry_load (GstRegistry *registry)
{
GstXMLRegistry *xmlregistry = GST_XML_REGISTRY (registry);
GstXMLRegistry *xmlregistry;
gchar *text;
gssize size;
GError *error = NULL;
GTimer *timer;
gdouble seconds;
xmlregistry = GST_XML_REGISTRY (registry);
timer = g_timer_new();
xmlregistry->context = g_markup_parse_context_new (&gst_xml_registry_parser, 0, registry, NULL);
......@@ -475,17 +536,19 @@ gst_xml_registry_load (GstRegistry *registry)
while (size) {
g_markup_parse_context_parse (xmlregistry->context, text, size, &error);
if (error) {
fprintf(stderr, "ERROR: parsing registry: %s\n", error->message);
g_free (text);
CLASS (xmlregistry)->close_func (xmlregistry);
return FALSE;
}
size = BLOCK_SIZE;
CLASS (xmlregistry)->load_func (xmlregistry, text, &size);
}
g_free (text);
if (error) {
fprintf(stderr, "ERROR: parsing registry: %s\n", error->message);
return FALSE;
}
g_timer_stop (timer);
seconds = g_timer_elapsed (timer, NULL);
......@@ -974,6 +1037,67 @@ gst_xml_registry_error (GMarkupParseContext *context, GError *error,
{
g_print ("error %s\n", error->message);
}
static void
gst_xml_registry_paths_start_element (GMarkupParseContext *context, const gchar *element_name,
const gchar **attribute_names, const gchar **attribute_values,
gpointer user_data, GError **error)
{
GstXMLRegistry *xmlregistry = GST_XML_REGISTRY (user_data);
switch (xmlregistry->state) {
case GST_XML_REGISTRY_NONE:
if (!strcmp (element_name, "GST-PluginRegistry")) {
xmlregistry->state = GST_XML_REGISTRY_TOP;
}
break;
case GST_XML_REGISTRY_TOP:
if (!strcmp (element_name, "gst-registry-paths")) {
xmlregistry->state = GST_XML_REGISTRY_PATHS;
}
break;
case GST_XML_REGISTRY_PATHS:
if (!strcmp (element_name, "path")) {
xmlregistry->state = GST_XML_REGISTRY_PATH;
}
break;
default:
break;
}
}
static void
gst_xml_registry_paths_end_element (GMarkupParseContext *context, const gchar *element_name,
gpointer user_data, GError **error)
{
GstXMLRegistry *xmlregistry = GST_XML_REGISTRY (user_data);
switch (xmlregistry->state) {
case GST_XML_REGISTRY_PATH:
if (!strcmp (element_name, "path")) {
xmlregistry->state = GST_XML_REGISTRY_PATHS;
}
break;
case GST_XML_REGISTRY_PATHS:
if (!strcmp (element_name, "gst-plugin-paths")) {
xmlregistry->state = GST_XML_REGISTRY_PATHS_DONE;
}
break;
default:
break;
}
}
static void
gst_xml_registry_paths_text (GMarkupParseContext *context, const gchar *text,
gsize text_len, gpointer user_data, GError **error)
{
GstXMLRegistry *xmlregistry = GST_XML_REGISTRY (user_data);
if (xmlregistry->state == GST_XML_REGISTRY_PATH)
gst_registry_add_path (GST_REGISTRY (xmlregistry), g_strndup (text, text_len));
}
/*
* Save
*/
......@@ -1220,11 +1344,22 @@ gst_xml_registry_save (GstRegistry *registry)
return FALSE;
}
walk = g_list_last (registry->plugins);
CLASS (xmlregistry)->save_func (xmlregistry, "<?xml version=\"1.0\"?>\n");
CLASS (xmlregistry)->save_func (xmlregistry, "<GST-PluginRegistry>\n");
walk = g_list_last (gst_registry_get_path_list (GST_REGISTRY (registry)));
CLASS (xmlregistry)->save_func (xmlregistry, "<gst-plugin-paths>\n");
while (walk) {
CLASS (xmlregistry)->save_func (xmlregistry, "<path>");
CLASS (xmlregistry)->save_func (xmlregistry, (gchar*)walk->data);
CLASS (xmlregistry)->save_func (xmlregistry, "</path>\n");
walk = g_list_previous (walk);
}
CLASS (xmlregistry)->save_func (xmlregistry, "</gst-plugin-paths>\n");
walk = g_list_last (registry->plugins);
while (walk) {
GstPlugin *plugin = GST_PLUGIN (walk->data);
......
......@@ -47,6 +47,9 @@ typedef struct _GstXMLRegistryClass GstXMLRegistryClass;
typedef enum {
GST_XML_REGISTRY_NONE,
GST_XML_REGISTRY_TOP,
GST_XML_REGISTRY_PATHS,
GST_XML_REGISTRY_PATH,
GST_XML_REGISTRY_PATHS_DONE,
GST_XML_REGISTRY_PLUGIN,
GST_XML_REGISTRY_FEATURE,
GST_XML_REGISTRY_PADTEMPLATE,
......@@ -60,11 +63,8 @@ typedef enum {
GST_XML_REGISTRY_WRITE,
} GstXMLRegistryMode;
enum {
GST_XML_REGISTRY_OPEN = (1 << 1)
};
typedef void (*GstXMLRegistryGetPerms) (GstXMLRegistry *registry);
typedef void (*GstXMLRegistryAddPathList) (GstXMLRegistry *registry);
typedef gboolean (*GstXMLRegistryParser) (GMarkupParseContext *context,
const gchar *tag,
const gchar *text,
......@@ -113,6 +113,7 @@ struct _GstXMLRegistryClass {
GstRegistryClass parent_class;
GstXMLRegistryGetPerms get_perms_func;
GstXMLRegistryAddPathList add_path_list_func;
GstXMLRegistryOpen open_func;
GstXMLRegistryLoad load_func;
GstXMLRegistrySave save_func;
......
......@@ -14,13 +14,13 @@ main (int argc, char *argv[])
g_print ("%d plugins loaded\n", numplugins);
g_mem_chunk_info ();
plugin = gst_registry_pool_find_plugin ("ossaudio");
plugin = gst_registry_pool_find_plugin ("testplugin");
g_assert (plugin != NULL);
g_print ("%d features in plugin\n", g_list_length (gst_plugin_get_feature_list (plugin)));
g_print ("ossaudio: %p loaded: %s\n", plugin, (gst_plugin_is_loaded (plugin) ? "true": "false"));
g_print ("testplugin: %p loaded: %s\n", plugin, (gst_plugin_is_loaded (plugin) ? "true": "false"));
loaded = gst_plugin_load_plugin (plugin);
g_assert (loaded == TRUE);
......@@ -30,9 +30,9 @@ main (int argc, char *argv[])
g_mem_chunk_info ();
plugin = gst_registry_pool_find_plugin ("ossaudio");
plugin = gst_registry_pool_find_plugin ("testplugin");
g_assert (plugin != NULL);
g_print ("ossaudio: %p loaded: %s\n", plugin, (gst_plugin_is_loaded (plugin) ? "true": "false"));
g_print ("testplugin: %p loaded: %s\n", plugin, (gst_plugin_is_loaded (plugin) ? "true": "false"));
g_print ("%d features in plugin\n", g_list_length (gst_plugin_get_feature_list (plugin)));
......@@ -46,9 +46,9 @@ main (int argc, char *argv[])
g_mem_chunk_info ();
plugin = gst_registry_pool_find_plugin ("ossaudio");
plugin = gst_registry_pool_find_plugin ("testplugin");
g_assert (plugin != NULL);
g_print ("ossaudio: %p loaded: %s\n", plugin, (gst_plugin_is_loaded (plugin) ? "true": "false"));
g_print ("testplugin: %p loaded: %s\n", plugin, (gst_plugin_is_loaded (plugin) ? "true": "false"));
return 0;
}
# GstObject is no longer instantiatable in glib2
# neither is GstElement
if BUILD_FAILING_TESTS
tests_failing = element
tests_failing = element bin element_pad pad
else
tests_failing =
endif
tests_working = bin element_pad pad
tests_working =
element_SOURCES = element.c mem.c
pad_SOURCES = pad.c mem.c
......
......@@ -11,10 +11,10 @@ create_bin (void)
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_element_set_name (element, "test1");
gst_bin_add (GST_BIN (bin), element);
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_element_set_name (element, "test2");
gst_bin_add (GST_BIN (bin), element);
......@@ -28,16 +28,12 @@ create_bin_ghostpads (void)
GstElement *element1, *element2;
bin = gst_bin_new ("testbin");
element1 = gst_element_new ();
gst_element_set_name (element1, "test1");
gst_element_add_pad (element1, gst_pad_new ("src1", GST_PAD_SRC));
element1 = gst_element_factory_make ("identity", NULL);
gst_bin_add (GST_BIN (bin), element1);
element2 = gst_element_new ();
gst_element_set_name (element2, "test2");
gst_element_add_pad (element2, gst_pad_new ("sink1", GST_PAD_SINK));
element2 = gst_element_factory_make ("fakesink", NULL);
gst_bin_add (GST_BIN (bin), element2);
gst_element_connect (element1, "src1", element2, "sink1");
gst_element_add_ghost_pad (bin, gst_element_get_pad (element2, "sink1"), "ghost_sink");
gst_element_connect_pads (element1, "src", element2, "sink");
gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"), "ghost_sink");
return bin;
}
......@@ -49,7 +45,7 @@ add_remove_test1 (void)
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_element_set_name (element, "test1");
g_assert (GST_OBJECT_FLOATING (element));
gst_bin_add (GST_BIN (bin), element);
......@@ -66,7 +62,7 @@ add_remove_test2 (void)
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_element_set_name (element, "test1");
gst_object_ref (GST_OBJECT (element));
g_assert (GST_OBJECT_FLOATING (element));
......@@ -90,7 +86,7 @@ add_remove_test3 (void)
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_element_set_name (element, "test1");
g_assert (GST_OBJECT_FLOATING (element));
gst_bin_add (GST_BIN (bin), element);
......@@ -109,7 +105,7 @@ add_remove_test4 (void)
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_element_set_name (element, "test1");
g_assert (GST_OBJECT_FLOATING (element));
gst_bin_add (GST_BIN (bin), element);
......
......@@ -21,17 +21,17 @@ main (int argc, gchar *argv[])
g_print ("starting test\n");
usage1 = vmsize();
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_unref (GST_OBJECT (element));
g_print ("create/unref new element %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_unref (GST_OBJECT (element));
}
g_print ("create/unref %d elements %ld\n", iters, vmsize()-usage1);
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
g_assert (GST_OBJECT_FLOATING (element));
gst_object_ref (GST_OBJECT (element));
gst_object_sink (GST_OBJECT (element));
......@@ -41,14 +41,14 @@ main (int argc, gchar *argv[])
for (i=0; i<iters;i++) {
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_ref (GST_OBJECT (element));
gst_object_sink (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
}
g_print ("create/ref/sink/unref %d elements %ld\n", iters, vmsize()-usage1);
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
g_assert (!GST_OBJECT_DESTROYED (element));
gst_object_destroy (GST_OBJECT (element));
g_assert (GST_OBJECT_DESTROYED (element));
......@@ -56,27 +56,27 @@ main (int argc, gchar *argv[])
g_print ("create/destroy/unref new element %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_destroy (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
}
g_print ("create/destroy/unref %d element %ld\n", iters, vmsize()-usage1);
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_ref (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
g_print ("create/ref/unref/unref new element %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_ref (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
}
g_print ("create/ref/unref/unref %d element %ld\n", iters, vmsize()-usage1);
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_ref (GST_OBJECT (element));
gst_object_destroy (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
......@@ -84,7 +84,7 @@ main (int argc, gchar *argv[])
g_print ("craete/ref/destroy/unref/unref new element %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_ref (GST_OBJECT (element));
gst_object_destroy (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
......@@ -93,7 +93,7 @@ main (int argc, gchar *argv[])
g_print ("craete/ref/destroy/unref/unref %d elements %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters;i++) {
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
gst_object_ref (GST_OBJECT (element));
gst_element_set_name (element, "testing123");
gst_object_destroy (GST_OBJECT (element));
......@@ -103,7 +103,7 @@ main (int argc, gchar *argv[])
}
g_print ("craete/ref/destroy/unref/unref %d elements with name %ld\n", iters, vmsize()-usage1);
element = gst_element_new ();
element = gst_element_factory_make ("fakesrc", NULL);
for (i=0; i<iters;i++) {
gst_element_set_name (element, "testing");
}
......