pad: Remove pad probes only once
authorOlivier Crête <olivier.crete@collabora.com>
Thu, 20 Sep 2012 18:48:17 +0000 (14:48 -0400)
committerOlivier Crête <olivier.crete@collabora.com>
Thu, 20 Sep 2012 19:24:33 +0000 (15:24 -0400)
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
tests/check/gst/gstpad.c

index 9153780..803d1c1 100644 (file)
@@ -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) {
index 5139d36..2b537e1 100644 (file)
@@ -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