From 2aaf499e2e05bbec4f2848039805f7f96235eb4e Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sat, 21 Oct 2023 17:49:30 -0700 Subject: [PATCH] linux-pipewire: Add locks to unsafe pipewire functions These functions log that they should be used with the thread lock held, so lets hold the lock before calling them. (cherry picked from commit f0697980c353fa92f9811f0c6c5b8da3517300ac) --- plugins/linux-pipewire/pipewire.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/linux-pipewire/pipewire.c b/plugins/linux-pipewire/pipewire.c index 163bb36ad..8b01357f3 100644 --- a/plugins/linux-pipewire/pipewire.c +++ b/plugins/linux-pipewire/pipewire.c @@ -1286,14 +1286,20 @@ obs_pipewire_connect_stream(obs_pipewire *obs_pw, obs_source_t *source, void obs_pipewire_stream_show(obs_pipewire_stream *obs_pw_stream) { - if (obs_pw_stream->stream) + if (obs_pw_stream->stream) { + pw_thread_loop_lock(obs_pw_stream->obs_pw->thread_loop); pw_stream_set_active(obs_pw_stream->stream, true); + pw_thread_loop_unlock(obs_pw_stream->obs_pw->thread_loop); + } } void obs_pipewire_stream_hide(obs_pipewire_stream *obs_pw_stream) { - if (obs_pw_stream->stream) + if (obs_pw_stream->stream) { + pw_thread_loop_lock(obs_pw_stream->obs_pw->thread_loop); pw_stream_set_active(obs_pw_stream->stream, false); + pw_thread_loop_unlock(obs_pw_stream->obs_pw->thread_loop); + } } uint32_t obs_pipewire_stream_get_width(obs_pipewire_stream *obs_pw_stream) @@ -1433,9 +1439,11 @@ void obs_pipewire_stream_destroy(obs_pipewire_stream *obs_pw_stream) g_clear_pointer(&obs_pw_stream->texture, gs_texture_destroy); obs_leave_graphics(); + pw_thread_loop_lock(obs_pw_stream->obs_pw->thread_loop); if (obs_pw_stream->stream) pw_stream_disconnect(obs_pw_stream->stream); g_clear_pointer(&obs_pw_stream->stream, pw_stream_destroy); + pw_thread_loop_unlock(obs_pw_stream->obs_pw->thread_loop); clear_format_info(obs_pw_stream); bfree(obs_pw_stream);