2001-05-25 21:00:07 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
#define ITERS 100
|
2001-05-25 21:00:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstElement *
|
2001-05-25 21:00:07 +00:00
|
|
|
create_bin (void)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
bin = gst_bin_new ("testbin");
|
2004-04-13 10:44:29 +00:00
|
|
|
g_assert (GST_IS_BIN (bin));
|
2002-05-11 20:30:05 +00:00
|
|
|
element = gst_element_factory_make ("fakesrc", NULL);
|
2004-04-13 10:44:29 +00:00
|
|
|
g_assert (GST_IS_ELEMENT (element));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (element, "test1");
|
|
|
|
gst_bin_add (GST_BIN (bin), element);
|
2002-05-11 20:30:05 +00:00
|
|
|
element = gst_element_factory_make ("fakesrc", NULL);
|
2004-04-13 10:44:29 +00:00
|
|
|
g_assert (GST_IS_ELEMENT (element));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (element, "test2");
|
|
|
|
gst_bin_add (GST_BIN (bin), element);
|
|
|
|
|
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstElement *
|
2001-05-25 21:00:07 +00:00
|
|
|
create_bin_ghostpads (void)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstElement *element1, *element2;
|
|
|
|
|
|
|
|
bin = gst_bin_new ("testbin");
|
2002-05-11 20:30:05 +00:00
|
|
|
element1 = gst_element_factory_make ("identity", NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN (bin), element1);
|
2002-05-11 20:30:05 +00:00
|
|
|
element2 = gst_element_factory_make ("fakesink", NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN (bin), element2);
|
2003-01-10 04:54:20 +00:00
|
|
|
gst_element_link_pads (element1, "src", element2, "sink");
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"),
|
|
|
|
"ghost_sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_remove_test1 (void)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
bin = gst_bin_new ("testbin");
|
2002-05-11 20:30:05 +00:00
|
|
|
element = gst_element_factory_make ("fakesrc", NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (element, "test1");
|
|
|
|
g_assert (GST_OBJECT_FLOATING (element));
|
|
|
|
gst_bin_add (GST_BIN (bin), element);
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (element));
|
|
|
|
gst_bin_remove (GST_BIN (bin), element);
|
|
|
|
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_remove_test2 (void)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
bin = gst_bin_new ("testbin");
|
2002-05-11 20:30:05 +00:00
|
|
|
element = gst_element_factory_make ("fakesrc", NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (element, "test1");
|
|
|
|
gst_object_ref (GST_OBJECT (element));
|
|
|
|
g_assert (GST_OBJECT_FLOATING (element));
|
|
|
|
gst_bin_add (GST_BIN (bin), element);
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (element));
|
|
|
|
gst_bin_remove (GST_BIN (bin), element);
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (element));
|
|
|
|
g_assert (!GST_OBJECT_DESTROYED (element));
|
|
|
|
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (element));
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2001-05-25 21:00:07 +00:00
|
|
|
g_assert (GST_OBJECT_DESTROYED (element));
|
|
|
|
gst_object_unref (GST_OBJECT (element));
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
|
|
|
/* This code is bogus */
|
2001-05-25 21:00:07 +00:00
|
|
|
static void
|
|
|
|
add_remove_test3 (void)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
bin = gst_bin_new ("testbin");
|
2002-05-11 20:30:05 +00:00
|
|
|
element = gst_element_factory_make ("fakesrc", NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (element, "test1");
|
|
|
|
g_assert (GST_OBJECT_FLOATING (element));
|
|
|
|
gst_bin_add (GST_BIN (bin), element);
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (element));
|
|
|
|
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (element));
|
2001-05-25 21:00:07 +00:00
|
|
|
g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
|
|
|
|
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
|
|
|
/* This code is bogus */
|
2001-05-25 21:00:07 +00:00
|
|
|
static void
|
|
|
|
add_remove_test4 (void)
|
|
|
|
{
|
|
|
|
GstElement *bin, *bin2;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
bin = gst_bin_new ("testbin");
|
2002-05-11 20:30:05 +00:00
|
|
|
element = gst_element_factory_make ("fakesrc", NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (element, "test1");
|
|
|
|
g_assert (GST_OBJECT_FLOATING (element));
|
|
|
|
gst_bin_add (GST_BIN (bin), element);
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (element));
|
|
|
|
|
|
|
|
bin2 = create_bin ();
|
|
|
|
g_assert (GST_OBJECT_FLOATING (bin2));
|
|
|
|
gst_bin_add (GST_BIN (bin), bin2);
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (bin2));
|
|
|
|
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin2));
|
2001-05-25 21:00:07 +00:00
|
|
|
g_assert (gst_bin_get_by_name (GST_BIN (bin), "testbin") == NULL);
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (element));
|
2001-05-25 21:00:07 +00:00
|
|
|
g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL);
|
|
|
|
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
int
|
2004-03-13 15:27:01 +00:00
|
|
|
main (int argc, gchar * argv[])
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
|
|
|
GstElement *bin;
|
2003-10-15 01:25:41 +00:00
|
|
|
int usage1;
|
2001-05-25 21:00:07 +00:00
|
|
|
gint i, iters;
|
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE);
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
iters = atoi (argv[1]);
|
|
|
|
else
|
|
|
|
iters = ITERS;
|
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
g_print ("starting test\n");
|
2003-10-15 01:25:41 +00:00
|
|
|
|
|
|
|
usage1 = gst_alloc_trace_live_all ();
|
|
|
|
//gst_alloc_trace_print_all ();
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/unref new bin %d\n", gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/unref %d bins %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
g_assert (GST_OBJECT_FLOATING (bin));
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
|
|
|
gst_object_sink (GST_OBJECT (bin));
|
|
|
|
g_assert (!GST_OBJECT_FLOATING (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/ref/sink/unref new bin %d\n",
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
|
|
|
gst_object_sink (GST_OBJECT (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/ref/sink/unref %d bins %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
g_assert (!GST_OBJECT_DESTROYED (bin));
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2001-05-25 21:00:07 +00:00
|
|
|
g_assert (GST_OBJECT_DESTROYED (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/destroy/unref new bin %d\n",
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
|
|
|
|
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
bin = gst_bin_new ("somebin");
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/destroy/unref %d bin %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/ref/unref/unref new bin %d\n",
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
|
|
|
|
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/ref/unref/unref %d bin %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("craete/ref/destroy/unref/unref new bin %d\n",
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
|
|
|
|
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("craete/ref/destroy/unref/unref %d bins %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
bin = gst_bin_new ("somebin");
|
|
|
|
gst_object_ref (GST_OBJECT (bin));
|
|
|
|
gst_element_set_name (bin, "testing123");
|
2003-04-15 18:17:24 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (bin, "testing123");
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("craete/ref/destroy/unref/unref %d bins with name %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
bin = gst_bin_new ("somebin");
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (bin, "testing");
|
|
|
|
}
|
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("set name %d times %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
|
|
|
bin = create_bin ();
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/unref %d bin with children %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters / 2; i++) {
|
|
|
|
bin = create_bin_ghostpads ();
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (bin));
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("create/unref %d bin with children and ghostpads %d\n", iters / 2,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
|
|
|
add_remove_test1 ();
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("add/remove test1 %d in bin %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
|
|
|
add_remove_test2 ();
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("add/remove test2 %d in bin %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
|
|
|
add_remove_test3 ();
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("add/destroy/remove test3 %d in bin %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
#if 0
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < iters; i++) {
|
|
|
|
add_remove_test4 ();
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("add/destroy/remove test4 %d in bin %d\n", iters,
|
|
|
|
gst_alloc_trace_live_all () - usage1);
|
2003-10-15 01:25:41 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("leaked: %d\n", gst_alloc_trace_live_all () - usage1);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-10-15 01:25:41 +00:00
|
|
|
//gst_alloc_trace_print_all ();
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return (gst_alloc_trace_live_all () - usage1 ? -1 : 0);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|