diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2023-02-22 11:02:45 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2023-02-22 15:24:51 +0300 |
commit | 2723fc47132b154e1722b86e7608156f4801b365 (patch) | |
tree | 2968915acec1b0ed75689d621707a09371edf446 /video | |
parent | e100506194ce33569877de2d95a407c2cf9924ad (diff) |
gtk4: Attach channel receiver to the default main context from the main thread
It requires acquiring the main context for thread-safety reasons and
that is only possible from the main thread itself.
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/319
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1101>
Diffstat (limited to 'video')
-rw-r--r-- | video/gtk4/src/sink/imp.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/video/gtk4/src/sink/imp.rs b/video/gtk4/src/sink/imp.rs index 3386a02c1..5149a0502 100644 --- a/video/gtk4/src/sink/imp.rs +++ b/video/gtk4/src/sink/imp.rs @@ -505,7 +505,21 @@ impl PaintableSink { ) { gst::debug!(CAT, imp: self, "Initializing paintable"); - let paintable = utils::invoke_on_main_thread(|| { + // The channel for the SinkEvents + let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); + let self_ = self.to_owned(); + + let paintable = utils::invoke_on_main_thread(move || { + // Attach the receiver from the main thread to make sure it is called + // from a place where it can acquire the default main context. + receiver.attach( + Some(&glib::MainContext::default()), + glib::clone!( + @weak self_ => @default-return glib::Continue(false), + move |action| self_.do_action(action) + ), + ); + #[cfg(any(target_os = "macos", feature = "gst_gl"))] { let gdk_context = if let GLContext::Initialized { gdk_context, .. } = @@ -523,17 +537,6 @@ impl PaintableSink { } }); - // The channel for the SinkEvents - let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); - let self_ = self.to_owned(); - receiver.attach( - None, - glib::clone!( - @weak self_ => @default-return glib::Continue(false), - move |action| self_.do_action(action) - ), - ); - **paintable_storage = Some(paintable); *self.sender.lock().unwrap() = Some(sender); |