From 945e0d2be95f2b591b341631b01f7e348e60bd7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 20 Sep 2012 14:48:17 -0400 Subject: [PATCH] pad: Remove pad probes only once Also add test to make sure that if a pad probe is removed while it's callback is running, the cleanup_hook isn't called again if it returns GST_PAD_PROBE_REMOVE --- gst/gstpad.c | 3 +++ tests/check/gst/gstpad.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/gst/gstpad.c b/gst/gstpad.c index 9153780..803d1c1 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -1257,6 +1257,9 @@ cleanup_hook (GstPad * pad, GHook * hook) { GstPadProbeType type; + if (!G_HOOK_IS_VALID (hook)) + return; + type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT; if (type & GST_PAD_PROBE_TYPE_BLOCKING) { diff --git a/tests/check/gst/gstpad.c b/tests/check/gst/gstpad.c index 5139d36..2b537e1 100644 --- a/tests/check/gst/gstpad.c +++ b/tests/check/gst/gstpad.c @@ -1073,6 +1073,53 @@ GST_START_TEST (test_pad_blocking_with_probe_type_blocking) GST_END_TEST; +static gboolean pad_probe_remove_notifiy_called = FALSE; + +static GstPadProbeReturn +probe_remove_self_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) +{ + gst_pad_remove_probe (pad, info->id); + + fail_unless (pad->num_probes == 0); + fail_unless (pad->num_blocked == 0); + + return GST_PAD_PROBE_REMOVE; +} + +static void +probe_remove_notify_cb (gpointer data) +{ + fail_unless (pad_probe_remove_notifiy_called == FALSE); + pad_probe_remove_notifiy_called = TRUE; +} + +GST_START_TEST (test_pad_probe_remove) +{ + GstPad *pad; + + pad = gst_pad_new ("src", GST_PAD_SRC); + fail_unless (pad != NULL); + + gst_pad_set_active (pad, TRUE); + fail_unless (pad->num_probes == 0); + fail_unless (pad->num_blocked == 0); + gst_pad_add_probe (pad, + GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, + probe_remove_self_cb, NULL, probe_remove_notify_cb); + fail_unless (pad->num_probes == 1); + fail_unless (pad->num_blocked == 1); + + pad_probe_remove_notifiy_called = FALSE; + gst_pad_push_event (pad, gst_event_new_stream_start ("asda")); + + fail_unless (pad->num_probes == 0); + fail_unless (pad->num_blocked == 0); + + gst_object_unref (pad); +} + +GST_END_TEST; + static gboolean got_notify; static void @@ -1507,6 +1554,7 @@ gst_pad_suite (void) tcase_add_test (tc_chain, test_block_async); tcase_add_test (tc_chain, test_pad_blocking_with_probe_type_block); tcase_add_test (tc_chain, test_pad_blocking_with_probe_type_blocking); + tcase_add_test (tc_chain, test_pad_probe_remove); tcase_add_test (tc_chain, test_queue_src_caps_notify_linked); tcase_add_test (tc_chain, test_queue_src_caps_notify_not_linked); #if 0 -- 2.7.4