Using a window with Gstreamer in a Flutter app

78 Views Asked by At

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 Gstreamer 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)
libdispatch.dylib!dispatch_assert_queue (Unknown Source:0)
HIToolbox!islGetInputSourceListWithAdditions (Unknown Source:0)
HIToolbox!isValidateInputSourceRef (Unknown Source:0)
HIToolbox!TSMGetInputSourceProperty (Unknown Source:0)
native_binding!_glfwPlatformInit (Unknown Source:0)
native_binding!glfwInit (Unknown Source:0)
native_binding!::SetupPipeline() (/Users/beng/experiments/upwork/rhub/flutter-app/fltgst-master/app/native_binding/src/native_binding.cpp:52)
[Unknown/Just-In-Time compiled code] (Unknown Source:0)
FlutterMacOS!dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&) (Unknown Source:0)
FlutterMacOS!dart::DartLibraryCalls::HandleMessage(long long, dart::Instance const&) (Unknown Source:0)
FlutterMacOS!dart::IsolateMessageHandler::HandleMessage(std::_LIBCPP_ABI_NAMESPACE::unique_ptr<dart::Message, std::_LIBCPP_ABI_NAMESPACE::default_delete<dart::Message>>) (Unknown Source:0)
FlutterMacOS!dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool) (Unknown Source:0)
FlutterMacOS!dart::MessageHandler::HandleNextMessage() (Unknown Source:0)
FlutterMacOS!Dart_HandleMessage (Unknown Source:0)
FlutterMacOS!tonic::DartMessageHandler::OnHandleMessage(tonic::DartState*) (Unknown Source:0)
FlutterMacOS!std::_LIBCPP_ABI_NAMESPACE::__function::__func<tonic::DartMessageHandler::OnMessage(tonic::DartState*)::$_0, std::_LIBCPP_ABI_NAMESPACE::allocator<tonic::DartMessageHandler::OnMessage(tonic::DartState*)::$_0>, void ()>::operator()() (Unknown Source:0)
FlutterMacOS!std::_LIBCPP_ABI_NAMESPACE::__function::__func<flutter::DartIsolate::SetMessageHandlingTaskRunner(fml::RefPtr<fml::TaskRunner> const&)::$_0::operator()(std::_LIBCPP_ABI_NAMESPACE::function<void ()>) const::'lambda'(), std::_LIBCPP_ABI_NAMESPACE::allocator<flutter::DartIsolate::SetMessageHandlingTaskRunner(fml::RefPtr<fml::TaskRunner> const&)::$_0::operator()(std::_LIBCPP_ABI_NAMESPACE::function<void ()>) const::'lambda'()>, void ()>::operator()() (Unknown Source:0)
FlutterMacOS!fml::MessageLoopImpl::FlushTasks(fml::FlushType) (Unknown Source:0)
FlutterMacOS!fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) (Unknown Source:0)

I also wonder 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);
gst_gl_window_show(w);
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.

1

There are 1 best solutions below

0
Benjamin Greenwood On

The problem was that I was calling glfwInit() about 5 threads deep into the app. This is because Flutter builds a MacOS app that embeds Flutter stuff inside of it (about 5 threads deep). Instead, I had to open up xcode and link GLFW to the MacOS app and call the init from Swift code.

This was illuminating: https://medium.com/@eibaan_54644/desktop-flutter-apps-8602dac54f68