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.
This commit is contained in:
Edward Hervey 2019-05-13 16:42:04 +02:00 committed by Tim-Philipp Müller
parent 3a8910f53b
commit 53e879c750
2 changed files with 33 additions and 1 deletions

View 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;

View 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);