NvBufSurface lifetime after gstbuffer is recieved from appsink

Hi,

I have our application instantiating a gsreamer pipeline running on Jetson Orin NX.
It basically captures frames directly into NVMM memory for later processing with CUDA.

nvv4l2camerasrc device=/dev/video0 ! video/x-raw(memory:NVMM),width=1920,height=1080,framerate=25/1 ! appsink name=i_appsink sync=false drop=true max-buffers=5

events for appsink frame ready are enabled using:

g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, "sync", FALSE, NULL);
g_signal_connect (appsink, "new-sample", G_CALLBACK (on_buffer), NULL);

callback function is a straightforward one:

void on_buffer(GstAppSink * sink, Callback_Data* callback_data) {
    GstSample *sample = gst_app_sink_pull_sample (GST_APP_SINK (appsink));

    if (sample) {
        GstBuffer *buffer = gst_sample_get_buffer(sample);
        GstMapInfo info;
        gst_buffer_map(buffer, &info, GST_MAP_READ);
        NvBufSurface *nvBuf_surface = (NvBufSurface*) info.data;

       // map nvBuf_surface and use data here ........

        gst_buffer_unmap (buffer, &info);
    }
    gst_sample_unref(sample);
}

The code works as it should.

My question is, will the call to gst_buffer_unmap() cause NvBufSurfaceDestroy() to be called to free up the dma buffer in NvBufSurface.
What if I want to unref/unmap the gst buffer and keep the underlying NvBufSurface for longer, how can I proceed?

Thanks,
Malek

gst_buffer_unmap is just the corresponding operation of gst_buffer_map, what gst_buffer_unmap will do depends on what is done in gst_buffer_map. It has nothing to do with NvBufSurfaceDestroy() in the on_buffer() callback.

What do you mean by “keep the underlying NvBufSurface for longer”?

Hi, thanks for your reply.

I meant, after the on_buffer() gong out of scope, NvBufSurface will still be in memory and can be accessed or it will be cleaned up by gst_sample_unref()?

Thanks,
Malek

There are only two elements(plugins) in your pipeline. When the on_buffer() callback finished, the buffer will be returned to the nvv4l2camerasrc plugin. It is open source, you can see where and how the memory in the gstbuffer been released. As what I known about the nvv4l2camerasrc plugin, it uses a bufferpool to manage the buffers, the buffers in the pool may be reused in loop. For the downstream element(plugin), it is not available after the gstbuffer is returned to upstream element.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.