GstBuffer from NvBuffer dmabuf

Hi, I want to zero-copy pass dma buffer (NvBuffer) to GstBuffer for video streaming.
While scrolling this forum I found poorpong_nvmm sample application. After some tweaks it works on my side, but I’m struggling with gst_buffer_new_wrapped_full call in feed_function.

From sample it’s

buffer = gst_buffer_new_wrapped_full(flags,
                                             data,
                                             par.nv_buffer_size,
                                             0,
                                             par.nv_buffer_size,
                                             user_data,
                                             notify_to_destroy);

and then

gst_buffer_map (buffer, &map, GST_MAP_WRITE);
memcpy(map.data, par.nv_buffer, par.nv_buffer_size);
gst_buffer_unmap(buffer, &map);

What is nv_buffer_size? On my side it’s always equal to 1008 bytes. I assume, this is size of NvBuffer internal struct, or smth like that. Definitely not actual buffer size. Why does the above code works?

According to docs i rewrote the following call as

GstBuffer *buffer = gst_buffer_new_wrapped_full(
            (GstMemoryFlags)0,
            par.nv_buffer,
            par.psize[0],
            par.offset[0],
            par.psize[0],
            user_data,
            notify_to_destroy
        );

and skipped gst_buffer_map with memcpy calls.
Looks like everything is working as intended.

So, the question is: what is nv_buffer_size and why code from poorpong_nvmm actually works?

Hi,
This sample should be similar to your use-case:
Opencv gpu mat into GStreamer without downloading to cpu - #15 by DaneLLL

Please take a look.

@DaneLLL you’re pointing to the same topic as @Jakowlew mentionned where I provided that weird sample.

@Jakowlew, this was just a one evening trial that I posted for forum users, but not sure that it can be a good template unless this works fine with your case.

The main point would be the memory flags, where I was using NVMM memory instead of system memory (that you’re using with (GstMemoryFlags)0 ).
It is usual AFAIK that buffer size in NVMM reports a lower size than actual buffer.

Probably @DaneLLL or someone else more skilled than me would be able to give more details about the reported size and actual operation

Hi,

You are correct. It is internal structure of NvBuffer.

Thank Honey Patouceul for pointing out the query.

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