Updating GstBuffer via a data probe

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Updating GstBuffer via a data probe

jagdspyder
Hello,

Consider the following pipeline (for depiction only):
udpsrc ! rtph264depay ! h264parse ! avdec_h264 ! queue ! autovideosink

I installed a data probe on avdec_h264's src pad and here's the callback that should attach some metadata to the GstBuffer:

```
static GstPadProbeReturn cb_attach_meta(GstPad *pad, GstPadProbeInfo *info, gpointer udata) {
  GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); // refcount here is 2

  buffer = gst_buffer_make_writable(buffer); // returns a new GstBuffer with refcount = 1
  if (buffer == NULL)
    return GST_PAD_PROBE_OK;

  /* attach metadata to buffer */

  return GST_PAD_PROBE_OK;
}

```

From the code comments, the buffer obtained from GST_PAD_PROBE_INFO_BUFFER(info) has a refcount of 2 so it is not writable and to make it so I must call gst_buffer_make_writable(buffer). The problem here is that upstream element udpsrc causes the following error

gst_mini_object_unref: assertion 'GST_MINI_OBJECT_REFCOUNT_VALUE (mini_object) > 0' failed
free_priv_data: object finalizing but still has parent (object:0x7fc9a012e480, parent:0x7fc9a0083640)

The queue produces the following error:
Unexpected item 0x7fc9a005fb40 dequeued from queue queue1 (refcounting problem?)

How to fix this? I improvised and added the following line before returning GST_PAD_PROBE_OK

```
info->data = buffer;
```
All errors disappeared, Is this the correct resolution here?
Reply | Threaded
Open this post in threaded view
|

Re: Updating GstBuffer via a data probe

jagdspyder
From here under the Data probes section https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html?gi-language=c

It seems that that line added is equivalent to GST_PAD_PROBE_INFO_DATA(info) = buffer;

So this is indeed the correct resolution here