mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-10-31 22:58:51 +00:00
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/1099>
This commit is contained in:
parent
f08b65ece1
commit
ce1faa6020
1 changed files with 15 additions and 12 deletions
|
@ -508,7 +508,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, .. } =
|
||||
|
@ -526,17 +540,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);
|
||||
|
|
Loading…
Reference in a new issue