Skip to content

Commit 7a3b57e

Browse files
committed
fix(linux/xdgportal): fix pipewire teardown logic, GNOME XDG stop icon
* Destroying the core and context during a reinit can cause a deadlock which can be reproduced when PW_STREAM_FLAG_RT_PROCESS is set. Fix by ensuring that full teardown is only done in pipewire destructor. * Add a delay before sending the interrupt signal, as the GNOME XDG portal needs time to detect changes, otherwise Sunshine will crash when the users manually stops the stream on mutter.
1 parent 86fcc42 commit 7a3b57e

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/platform/linux/portalgrab.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,24 @@ namespace portal {
723723

724724
~pipewire_t() {
725725
cleanup_stream();
726+
727+
pw_thread_loop_lock(loop);
728+
729+
if (core) {
730+
pw_core_disconnect(core);
731+
core = nullptr;
732+
}
733+
if (context) {
734+
pw_context_destroy(context);
735+
context = nullptr;
736+
}
737+
738+
pw_thread_loop_unlock(loop);
739+
740+
pw_thread_loop_stop(loop);
741+
if (fd >= 0) {
742+
close(fd);
743+
}
726744
pw_thread_loop_destroy(loop);
727745
}
728746

@@ -775,21 +793,8 @@ namespace portal {
775793
pw_stream_destroy(stream_data.stream);
776794
stream_data.stream = nullptr;
777795
}
778-
if (core) {
779-
pw_core_disconnect(core);
780-
core = nullptr;
781-
}
782-
if (context) {
783-
pw_context_destroy(context);
784-
context = nullptr;
785-
}
786796

787797
pw_thread_loop_unlock(loop);
788-
789-
pw_thread_loop_stop(loop);
790-
if (fd >= 0) {
791-
close(fd);
792-
}
793798
}
794799
session_cache_t::instance().invalidate();
795800
}
@@ -1322,6 +1327,8 @@ namespace portal {
13221327
stream_stopped.store(false);
13231328
previous_height.store(0);
13241329
previous_width.store(0);
1330+
// Delay interrupt signal to give Portal time to detect change
1331+
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
13251332
return platf::capture_e::interrupted;
13261333
} else {
13271334
BOOST_LOG(warning) << "PipeWire stream disconnected. Forcing session reset."sv;

0 commit comments

Comments
 (0)