gstreamer_gl (rust) on Windows

Matthew Waters ystreet00 at gmail.com
Tue Feb 8 02:56:27 UTC 2022


On 8/2/22 09:46, Steven Fontaine wrote:
> Thanks for all your help with this so far, Sebastian and Matt.
>
> > Which inconsistencies are making things difficult for you?
>
> In hindsight, it's more so my lack of knowledge of desktop gl bindings
> (coming from a weak background of webgl, where things tend to work
> "out of the box") and the gst/gst_gl libraries in general and their
> intricacies and common workflows. In any case, I don't think it's a
> shortcoming of the bindings themselves, I'm just not familiar enough
> with the libraries to fully understand errors I get, common pitfalls, etc.
>
> Regardless, following this:
>
> > I think you need to make the glutin context "uncurrent" before these
> > lines and make it current again afterwards:
>>https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/8b09a84bf197a8516858ea46db74c5132ea59406/examples/src/glupload.rs#L408-416
>
> fails at fill_info
> (https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/8b09a84bf197a8516858ea46db74c5132ea59406/examples/src/glupload.rs#L416),
> complaining that "glGetString not defined or returned invalid value".

This is incorrect.  The glutin GL context must still be current during
the call to fill_info() as some GL calls are performed to retrieve the
necessary info from the OpenGL context.  You only need to uncurrent when
GStreamer creates it's own OpenGL context, doing anything on glutin's
OpenGL (or GStreamer's wrapper) context will not work.  Windows is the
only platform where this uncurrenting is necessary (and only on some GL
drivers).

The thing is that by default, GStreamer will create it's own OpenGL
context at some unknown point in the future (generally on element set
up).  You need to override that in one of two ways:
1. Connect to the 'create-context' signal on the relevant GstGLDisplay
where you, move to the application thread (blocking), uncurrenting
glutin's context, then creating GStreamer's OpenGL context, then
recurrent glutin's OpenGL context (application thread), return to the
'create-context' thread and return the newly created GstGLContext.
2. Create the GstGLContext context yourself (shared with glutin's) and
pass it into GStreamer for it to use with some carefully placed pad
probes responding to GST_CONTEXT_QUERY's of the type
"gst.gl.local_context":
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.c#L577. 
As I mentioned before, the qmlglsink code is a good example for the
creation of the OpenGL context taking into account this Windows-specific
behaviour:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/subprojects/gst-plugins-good/ext/qt/gstqtglutility.cc#L263.

> I've been working on converting the glutin "sharing" example
> (https://github.com/rust-windowing/glutin/blob/b9081d2b27af0cdd15895775fe6688847a041229/glutin_examples/examples/sharing.rs)
> and have had quite a bit of success. Rather than sharing multiple
> windowed/headless glutin contexts, as the glutin example does, I've
> modified the code to share a single windowed (glutin) context and a
> single gst context. Every time the glutin context is used, the gst
> context is deactivated. Every time the gst context is needed, the
> glutin context is deactivated. This almost works. The application
> doesn't crash, events are handled properly, etc. The only problem is
> that nothing is rendered. The window displays a black screen, rather
> than any videotestsrc pattern I try. I'm creating the gst context
> exactly as described earlier in this thread, so assuming that's the
> correct way to set that up, I'm a bit stuck again.
>
> There are several differences between the gl setup in the glutin
> example and the gst example, so I might be configuring something
> improperly. That said, gl is pretty opaque, and hard to probe the
> state, so it's difficult for me to debug. Does anyone have any
> ideas/suggestions here, or perhaps know of some tools that could help
> me debug this?

I generally use apitrace on linux for recording/looking at GL state. 
There is a windows version but not sure exactly how well it works.

Cheers
-Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220208/eb753547/attachment.sig>


More information about the gstreamer-devel mailing list