Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gstreamer zero copy #3754

Open
totaam opened this issue Feb 1, 2023 · 3 comments
Open

gstreamer zero copy #3754

totaam opened this issue Feb 1, 2023 · 3 comments
Labels
encoding enhancement New feature or request

Comments

@totaam
Copy link
Collaborator

totaam commented Feb 1, 2023

Add some form of zero copy to the gstreamer encoder and decoder (#3706).
We use Gst.Buffers wrapping one or more Gst.Memory areas.
The problem is that the pixel data (planar YUV or plain RGB) is consumed by the encoder and produced by the decoder - this data can be huge and copying it around is extremely inefficient.
Despite boasting of having zero-copy mechanisms, it's not obvious how one would use them via appsrc and appsink - or even using other, potentially custom, elements.
Most of the buffer methods end up copying the data:
https://github.com/GStreamer/gstreamer/blob/main/subprojects/gstreamer/gst/gstbuffer.c

Do we have to mess with allocators? ie: GstDmaBufAllocator

Interesting read: Inter-Process Texture Sharing with DMA-BUF
Ideally, we don't want to tie this to a specific rendering backend, but if the decoder is on a GPU appsink will probably end up downloading the data to system memory..

shmsrc is not a good fit as we would need to copy our data into a shared memory area.
Perhaps shmsink can give us a zero copy buffer - not clear yet.

@totaam totaam added enhancement New feature or request encoding labels Feb 1, 2023
@TijZwa
Copy link
Collaborator

TijZwa commented Feb 1, 2023

@totaam
Copy link
Collaborator Author

totaam commented Feb 1, 2023

@TijZwa glimagesink sounds good, but the video decoding code currently does not know where the picture is going to be used - this would only work for the OpenGL case.
Another problem is that gstreamer is asynchronous so managing the window events (create and destroy mainly) would be quite difficult.
It is mostly used in video players and such, where you create the window only once, whereas we may need to create and destroy multiple windows many times per second.

@totaam
Copy link
Collaborator Author

totaam commented Mar 12, 2024

Apparently, we are meant to use gst_buffer_new_wrapped_full
I'm pretty sure I've played with it before - I just can't remember what was wrong with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
encoding enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants