gstpad: Probes that return HANDLED can reset the data info field
authorEdward Hervey <bilboed@bilboed.com>
Mon, 13 May 2019 14:42:04 +0000 (16:42 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 8 Aug 2019 08:49:31 +0000 (09:49 +0100)
Before GST_PAD_PROBE_HANDLED was introduced, we had to handle the case
where some probes would reset the probe info data field to NULL. This would
be considered an invalid use-case.

But with GST_PAD_PROBE_HANDLED it is totally fine to reset that, since
the probe has "handled" it.

gst/gstpad.c
tests/check/gst/gstpad.c

index 12eb561..dcd52f2 100644 (file)
@@ -3569,7 +3569,8 @@ probe_hook_marshal (GHook * hook, ProbeMarshall * data)
   if ((flags & GST_PAD_PROBE_TYPE_IDLE))
     pad->priv->idle_running--;
 
-  if (original_data != NULL && info->data == NULL) {
+  if (ret != GST_PAD_PROBE_HANDLED && original_data != NULL
+      && info->data == NULL) {
     GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
     info->type = GST_PAD_PROBE_TYPE_INVALID;
     data->dropped = TRUE;
index 3948a4d..004ff1e 100644 (file)
@@ -622,6 +622,21 @@ _handled_probe_handler (GstPad * pad, GstPadProbeInfo * info, gpointer userdata)
   return GST_PAD_PROBE_HANDLED;
 }
 
+static GstPadProbeReturn
+_cleaning_handled_probe_handler (GstPad * pad, GstPadProbeInfo * info,
+    gpointer userdata)
+{
+  GstFlowReturn customflow = (GstFlowReturn) GPOINTER_TO_INT (userdata);
+
+  /* We are handling the data, we unref it and we reset the data field */
+  if (!(GST_PAD_PROBE_INFO_TYPE (info) & GST_PAD_PROBE_TYPE_QUERY_BOTH))
+    gst_mini_object_unref (info->data);
+  GST_PAD_PROBE_INFO_FLOW_RETURN (info) = customflow;
+  GST_PAD_PROBE_INFO_DATA (info) = NULL;
+
+  return GST_PAD_PROBE_HANDLED;
+}
+
 
 
 GST_START_TEST (test_events_query_unlinked)
@@ -786,6 +801,22 @@ GST_START_TEST (test_push_unlinked)
 
   }
 
+  /* Same thing, except that this time we also set the info data field
+   * to NULL in the probe. We can because we are returning _HANDLED */
+  GST_DEBUG ("push buffer handled and custom return (with info data NULL'ed)");
+  for (fl = GST_FLOW_NOT_SUPPORTED; fl <= GST_FLOW_OK; fl += 1) {
+    GST_DEBUG ("Testing with %s", gst_flow_get_name (fl));
+    id = gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_BUFFER,
+        _cleaning_handled_probe_handler, GINT_TO_POINTER (fl), NULL);
+    buffer = gst_buffer_new ();
+    gst_buffer_ref (buffer);
+    fail_unless (gst_pad_push (src, buffer) == fl);
+    ASSERT_MINI_OBJECT_REFCOUNT (buffer, "buffer", 1);
+    gst_buffer_unref (buffer);
+    gst_pad_remove_probe (src, id);
+
+  }
+
 
   /* cleanup */
   ASSERT_CAPS_REFCOUNT (caps, "caps", 2);