How can I use my own window?


I am using Gstreamer in a Flutter application, currently working on the MacOS build.

On desktop builds, I’d like to have control of the window that displays the video. I’ve read through the examples with GTK and QT, but Flutter doesn’t seem as friendly as these examples, and I am trying to use another windowing library. When I bring in SDL or GLFW and initialize either of those libraries, libdispatch causes a crash during the init.

EXC_BREAKPOINT (code=1, subcode=0x18d046d0c)

libdispatch.dylib!_dispatch_assert_queue_fail (Unknown Source:0)

I realize this is not really a Gstreamer problem, but I am wondering if I could use a GstGLWindow directly. I have tried creating such a window:

GstGLDisplay *d = gst_gl_display_new_with_type(GST_GL_DISPLAY_TYPE_COCOA);
GstGLWindow *w = gst_gl_window_new(d);
guintptr h = gst_gl_window_get_window_handle(w);

but no window appears. I am wondering if anyone has advice on doing this, if there is another way that you would recommend, or if I am totally off base with my approach. Apologies for my lack of experience with graphics libraries.

Turns out I had to initialize GLFW on the main thread, which was a little tricky. I am still curious about GstGLWindow usage.

GstGLWindow is not really intended to be used directly and is somewhat tied to an associated GstGLContext on some platforms. GstGLWindow is also not a general purpose windowing abstraction as it only contains enough implementation for very basic interactions. For anything else, it is very much recommended to write your sink element for integrating with your specific toolkit/drawing API. There are already some elements that do this.

  1. gtkglsink (Gtk3)
  2. qml(6)glsink
  3. gtk4paintablesink

On macOS, there are further complications in that the main thread must be running a CFRunLoop/NSRunLoop in order to successfully handle window system events from outside and posted internally from GStreamer-GL. This is because most UI operations are only valid to perform on the main thread (thread that calls main()). This is a macOS-only limitation. Missing this requirement is a common cause for no output window showing up at all.

1 Like