gstreamer_gl (rust) on Windows

Steven Fontaine sir.fon1103 at gmail.com
Mon Jan 31 22:05:16 UTC 2022


I'll be honest, thus far I've simply copied over examples/src/glupload.rs
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs>
and
have been hacking away at it, in an attempt to understand the logic and
understand the gstreamer_gl/glutin workflow, so I have nothing that would
really make sense even as a draft MR. But there's a couple main points of
glupload that are throwing me off.

So, as a brief summary, I'm trying to replicate examples/src/glwindow.rs
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/main/examples/src/glupload.rs>,
which simply creates a glupload::App(None) (L11
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/bin/glwindow.rs#L11>)
and runs glupload::main_loop in that App (L12
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/bin/glwindow.rs#L12>).
So my troubles come from trying to make examples/src/glupload.rs
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs>
support
Windows (WGL).

With that said, my troubles start in glupload::App::new
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L330>,
specifically at L350
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L350>.
Here glupload fails by design if the platform is not linux. This is easy to
fix, but within this if statement, glupload matches the raw gl context
handle, provided by glutin, checking only for EGL and GLX, then creates a
GLDisplay
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl/struct.GLDisplay.html>
 using gstreamer_gl_egl::GLDisplayEGL::
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl_egl/struct.GLDisplayEGL.html#method.from_gl_display>
with_egl_display
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl_egl/struct.GLDisplayEGL.html#method.from_gl_display>
, gstreamer_gl_wayland::GLDisplayWayland::
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl_wayland/struct.GLDisplayWayland.html#method.with_display>
with_display
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl_wayland/struct.GLDisplayWayland.html#method.with_display>,
or gstreamer_gl_x11::GLDisplayX11::
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl_x11/struct.GLDisplayX11.html#method.with_display>
with_display
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl_x11/struct.GLDisplayX11.html#method.with_display>,
depending on context. Lastly, it creates a wrapped GLContext (L408
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L408>
), using the GLDisplay created in the previous step. As far as I can tell,
this process handles linking the gl context provided by glutin to a
GLContext and linking that with the GLDisplay created in the
egl/wayland/x11 functions. It's this linking that I can't seem to replicate
on Windows. Since there's no equivalent functions for WGL, I'm somewhat
left in the dark here.

The most progress I've managed to make here is simply creating a new
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl/struct.GLDisplay.html#method.new>
GLDisplay
<https://gstreamer.pages.freedesktop.org/gstreamer-rs/stable/latest/docs/gstreamer_gl/struct.GLDisplay.html#method.new>
in
place of the GLDisplayXXX::with_display functions, creating the wrapped
GLContext in the same way as L408
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L408>
:

// L356
> <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L356>

let api = App::map_gl_api(windowed_context.get_api());
>


 // replace L358-406
> <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L358-406>
> with the following

let gl_context = if let RawHandle::Wgl(ctx) = unsafe {
> windowed_context.raw_handle() } {
>     ctx as usize
> } else {
>     panic!("Expected WGL!");
> };
>
// leak to ensure the display doesn't get dropped

let gl_display: &'static gstreamer_gl::GLDisplay =
> Box::leak(Box::new(gstreamer_gl::GLDisplay::new()));

let platform = gstreamer_gl::GLPlatform::WGL;



 // L408
> <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L408>

shared_context = unsafe { gst_gl::GLContext::new_wrapped(gl_display,
> gl_context, platform, api) } .unwrap();


which compiles and makes it past App::new, but then fails in main_loop with
the following error:

failed to share contexts through wglShareLists 0xaa', src\glupload.rs:697:44
<https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/74557132e17e24677b4f60fcffe32adec4de60c7/examples/src/glupload.rs#L697>

My intuition tells me that the GLDisplay and gl context aren't getting
properly linked, but I might be wrong. Anyway, hopefully this is helpful,
and thanks for all your help so far!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220131/eee8a234/attachment-0001.htm>


More information about the gstreamer-devel mailing list