Zero copy buffer to GUI

What is the right way to do ?

I have a video pipeline and I use an appsink to copy the buffer to create a new texture , this new texture is being render in the GUI context.
The question is there a better way to do it ?
How to prevent the copy of the frame ?

(I’m running on Nvidia and I add a nvvidconv to move the buffer from NVMM to CPU), that is a lot of copies.

processing → pipeline → appsink
!
!
!
gui_app <-------------- create texture
(create window, (with copy of frame data)
create GL context) !
swap buffers

void gui_update_video_texture(GstCapture* capture) {
if (!capture || !capture->video_out_appsink) return;
nvtxRangePush("Video Texture Update");

GstSample *videosample = gst_app_sink_try_pull_sample(
    GST_APP_SINK(capture->video_out_appsink), 1 * GST_MSECOND);
                             
if (videosample) {
    nvtxRangePush("Video Buffer Processing");
    GstBuffer *videobuf = gst_sample_get_buffer(videosample);
    GstMapInfo map;                   

    if (gst_buffer_map(videobuf, &map, GST_MAP_READ)) {
        glBindTexture(GL_TEXTURE_2D, g_gui_state.videotex);  
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1280, 720, 0, GL_RGBA,
                     GL_UNSIGNED_BYTE, map.data);
        gst_buffer_unmap(videobuf, &map);
    }
    gst_sample_unref(videosample);
    nvtxRangePop();
}
        
nvtxRangePop();
}

Hello @michelc33,

I think you should look for a way to wrap your NVMM buffer into a GL texture.
That way you can manipulate the GPU memory buffer without making any copies.

Just out of curiosity.
What are you doing with the buffer on the application once you get the buffers out of the appsink?
Maybe we can come together with another idea of how to achieve what you are ultimately trying.

best regards,
Andres Campos

Thank you for the feedback, I have tried with mixed result (SEG FAULT).
The end goal is to render the video that is blended with a GUI. the GUI by itself will create opengl context and share it, so that we can render the video and the GUI in the same window.

Thanks,

Michel

Hello @michelc33,

Got it.
Thanks for the extra detail.

Maybe you can try using glupload to get NVMM buffers in GL memory space.
Then you can use glimagesink for displaying GL image.

Finally, you can find a way to assign the window handle on the image sink.

Please keep us posted.
This is very interesting.

best regards,

Andres Campos