From 7aee718394cdd97f0b02310abd2556b8c7fc497b Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 13 May 2019 16:42:04 +0200 Subject: [PATCH] gstpad: Probes that return HANDLED can reset the data info field 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 | 3 ++- tests/check/gst/gstpad.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gst/gstpad.c b/gst/gstpad.c index 64d14d2..573556d 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -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; diff --git a/tests/check/gst/gstpad.c b/tests/check/gst/gstpad.c index 3948a4d..004ff1e 100644 --- a/tests/check/gst/gstpad.c +++ b/tests/check/gst/gstpad.c @@ -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); -- 2.7.4