mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-22 10:23:47 +00:00
f2cf753b17
Original commit message from CVS: 2005-06-27 Andy Wingo <wingo@pobox.com> * gst/base/gsttypefindhelper.c (gst_type_find_helper): Unref any remaining buffer. * gst/gsttrace.c (gst_alloc_trace_list_sorted): New helper, returns a sorted copy of the trace list. (gst_alloc_trace_print_live): New API, only prints traces with live objects. Sort the list. (gst_alloc_trace_print_all): Sort the list. (gst_alloc_trace_print): Align columns. * gst/elements/gstttypefindelement.c: * gst/elements/gsttee.c: * gst/base/gstbasesrc.c: * gst/base/gstbasesink.c: * gst/base/gstbasetransform.c: * gst/gstqueue.c: Adapt for pad activation changes. * gst/gstpipeline.c (gst_pipeline_init): Unref after parenting sched. (gst_pipeline_dispose): Drop ref on sched. * gst/gstpad.c (gst_pad_init): Set the default activate func. (gst_pad_activate_default): Push mode by default. (pre_activate_switch, post_activate_switch): New stubs, things to do before and after switching activation modes on pads. (gst_pad_set_active): Take a boolean and not a mode, dispatch to the pad's activate function to choose which mode to activate. Shortcut on deactivation and call the right function directly. (gst_pad_activate_pull): New API, (de)activates a pad in pull mode. (gst_pad_activate_push): New API, same for push mode. (gst_pad_set_activate_function) (gst_pad_set_activatepull_function) (gst_pad_set_activatepush_function): Setters for new API. * gst/gstminiobject.c (gst_mini_object_new, gst_mini_object_free): Trace all miniobjects. (gst_mini_object_make_writable): Unref the arg if we copy, like gst_caps_make_writable. * gst/gstmessage.c (_gst_message_initialize): No trace init. * gst/gstghostpad.c (gst_proxy_pad_do_activate) (gst_proxy_pad_do_activatepull, gst_proxy_pad_do_activatepush): Adapt for new pad API. * gst/gstevent.c (_gst_event_initialize): Don't initialize trace. * gst/gstelement.h: * gst/gstelement.c (gst_element_iterate_src_pads) (gst_element_iterate_sink_pads): New API functions. * gst/gstelement.c (iterator_fold_with_resync): New utility, should fold into gstiterator.c in some form. (gst_element_pads_activate): Simplified via use of fold and delegation of decisions to gstpad->activate. * gst/gstbus.c (gst_bus_source_finalize): Set the bus to NULL, help in debugging. * gst/gstbuffer.c (_gst_buffer_initialize): Ref the buffer type class once in init, like gstmessage. Didn't run into this issue but it seems correct. Don't initialize a trace, gstminiobject does that. * check/pipelines/simple_launch_lines.c (test_stop_from_app): New test, runs fakesrc ! fakesink, stopping on ::handoff via a message to the bus. (assert_live_count): New util function, uses alloc traces to check cleanup. * check/gst/gstghostpad.c (test_ghost_pads): More refcount checks. To be modified when unlink drops the internal pad.
153 lines
5.2 KiB
C
153 lines
5.2 KiB
C
/* GStreamer
|
|
* Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
|
|
*
|
|
* gstghostpad.c: Unit test for GstGhostPad
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "../gstcheck.h"
|
|
|
|
static void
|
|
assert_gstrefcount (gpointer p, gint i)
|
|
{
|
|
if (GST_OBJECT_REFCOUNT_VALUE (p) != i)
|
|
g_critical ("Expected refcount %d for %s, got %d", i, GST_OBJECT_NAME (p),
|
|
GST_OBJECT_REFCOUNT_VALUE (p));
|
|
}
|
|
|
|
START_TEST (test_ghost_pads)
|
|
{
|
|
GstElement *b1, *b2, *src, *i1, *sink;
|
|
GstPad *gsink, *gsrc, *gisrc, *gisink, *isink, *isrc, *fsrc, *fsink;
|
|
|
|
b1 = gst_element_factory_make ("pipeline", NULL);
|
|
b2 = gst_element_factory_make ("bin", NULL);
|
|
src = gst_element_factory_make ("fakesrc", NULL);
|
|
g_object_set (src, "num-buffers", (int) 10, NULL);
|
|
i1 = gst_element_factory_make ("identity", NULL);
|
|
sink = gst_element_factory_make ("fakesink", NULL);
|
|
|
|
fail_unless (gst_bin_add (GST_BIN (b2), i1));
|
|
fail_unless (gst_bin_add (GST_BIN (b1), src));
|
|
fail_unless (gst_bin_add (GST_BIN (b1), b2));
|
|
fail_unless (gst_bin_add (GST_BIN (b1), sink));
|
|
fail_unless (gst_element_link_pads (src, NULL, i1, NULL));
|
|
fail_unless (gst_element_link_pads (i1, NULL, sink, NULL));
|
|
GST_LOCK (b2);
|
|
fail_unless (b2->numsinkpads == 1);
|
|
fail_unless (GST_IS_GHOST_PAD (b2->sinkpads->data));
|
|
fail_unless (b2->numsrcpads == 1);
|
|
fail_unless (GST_IS_GHOST_PAD (b2->srcpads->data));
|
|
GST_UNLOCK (b2);
|
|
|
|
fsrc = gst_element_get_pad (src, "src");
|
|
fail_unless (fsrc != NULL);
|
|
gsink = GST_PAD (gst_object_ref (GST_OBJECT (b2->sinkpads->data)));
|
|
fail_unless (gsink != NULL);
|
|
gsrc = GST_PAD (gst_object_ref (GST_OBJECT (b2->srcpads->data)));
|
|
fail_unless (gsrc != NULL);
|
|
fsink = gst_element_get_pad (sink, "sink");
|
|
fail_unless (fsink != NULL);
|
|
|
|
isink = gst_element_get_pad (i1, "sink");
|
|
fail_unless (isink != NULL);
|
|
isrc = gst_element_get_pad (i1, "src");
|
|
fail_unless (isrc != NULL);
|
|
gisrc = gst_pad_get_peer (isink);
|
|
fail_unless (gisrc != NULL);
|
|
gisink = gst_pad_get_peer (isrc);
|
|
fail_unless (gisink != NULL);
|
|
|
|
/* all objects above have one refcount owned by us as well */
|
|
|
|
assert_gstrefcount (fsrc, 3); /* parent and gisrc */
|
|
assert_gstrefcount (gsink, 2); /* parent */
|
|
assert_gstrefcount (gsrc, 2); /* parent */
|
|
assert_gstrefcount (fsink, 3); /* parent and gisink */
|
|
|
|
assert_gstrefcount (gisrc, 2); /* parent */
|
|
assert_gstrefcount (isink, 3); /* parent and gsink */
|
|
assert_gstrefcount (gisink, 2); /* parent */
|
|
assert_gstrefcount (isrc, 3); /* parent and gsrc */
|
|
|
|
fail_unless (gst_element_set_state (b1,
|
|
GST_STATE_PLAYING) == GST_STATE_SUCCESS);
|
|
|
|
fail_unless (gst_element_set_state (b1, GST_STATE_NULL) == GST_STATE_SUCCESS);
|
|
|
|
gst_object_unref (GST_OBJECT (b1));
|
|
/* unreffing the bin will unref all elements, which will unlink and unparent
|
|
* all pads */
|
|
|
|
/* FIXME: ghost pads need to drop their internal pad in the unlink function,
|
|
* but can't right now. So internal pads have a ref from their parent, and the
|
|
* internal pads' targets have refs from the internals. When we do the last
|
|
* unref on the ghost pads, these refs should go away.
|
|
*/
|
|
|
|
assert_gstrefcount (fsrc, 2); /* gisrc */
|
|
assert_gstrefcount (gsink, 1);
|
|
assert_gstrefcount (gsrc, 1);
|
|
assert_gstrefcount (fsink, 2); /* gisink */
|
|
|
|
assert_gstrefcount (gisrc, 2); /* gsink -- fixme drop ref in unlink */
|
|
assert_gstrefcount (isink, 2); /* gsink */
|
|
assert_gstrefcount (gisink, 2); /* gsrc -- fixme drop ref in unlink */
|
|
assert_gstrefcount (isrc, 2); /* gsrc */
|
|
|
|
/* while the fixme isn't fixed, check cleanup */
|
|
gst_object_unref (GST_OBJECT (gsink));
|
|
assert_gstrefcount (isink, 1);
|
|
assert_gstrefcount (gisrc, 1);
|
|
assert_gstrefcount (fsrc, 2); /* gisrc */
|
|
gst_object_unref (GST_OBJECT (gisrc));
|
|
assert_gstrefcount (fsrc, 1);
|
|
|
|
gst_object_unref (GST_OBJECT (gsrc));
|
|
assert_gstrefcount (isrc, 1);
|
|
assert_gstrefcount (gisink, 1);
|
|
assert_gstrefcount (fsink, 2); /* gisrc */
|
|
gst_object_unref (GST_OBJECT (gisink));
|
|
assert_gstrefcount (fsink, 1);
|
|
}
|
|
END_TEST Suite * gst_ghost_pad_suite (void)
|
|
{
|
|
Suite *s = suite_create ("GstGhostPad");
|
|
TCase *tc_chain = tcase_create ("ghost pad tests");
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
tcase_add_test (tc_chain, test_ghost_pads);
|
|
|
|
return s;
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
int nf;
|
|
|
|
Suite *s = gst_ghost_pad_suite ();
|
|
SRunner *sr = srunner_create (s);
|
|
|
|
gst_check_init (&argc, &argv);
|
|
|
|
srunner_run_all (sr, CK_NORMAL);
|
|
nf = srunner_ntests_failed (sr);
|
|
srunner_free (sr);
|
|
|
|
return nf;
|
|
}
|