Merge pull request #3136 from hrdl-github/fix-pipewire-locking

Pipewire backend: use pipewire thread lock
master
Alexis Rouillard 2024-04-14 10:33:22 +02:00 committed by GitHub
commit ddacb111a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 0 deletions

View File

@ -48,12 +48,17 @@ PipewireBackend::PipewireBackend(PrivateConstructorTag tag)
if (mainloop_ == nullptr) { if (mainloop_ == nullptr) {
throw std::runtime_error("pw_thread_loop_new() failed."); throw std::runtime_error("pw_thread_loop_new() failed.");
} }
pw_thread_loop_lock(mainloop_);
context_ = pw_context_new(pw_thread_loop_get_loop(mainloop_), nullptr, 0); context_ = pw_context_new(pw_thread_loop_get_loop(mainloop_), nullptr, 0);
if (context_ == nullptr) { if (context_ == nullptr) {
pw_thread_loop_unlock(mainloop_);
throw std::runtime_error("pa_context_new() failed."); throw std::runtime_error("pa_context_new() failed.");
} }
core_ = pw_context_connect(context_, nullptr, 0); core_ = pw_context_connect(context_, nullptr, 0);
if (core_ == nullptr) { if (core_ == nullptr) {
pw_thread_loop_unlock(mainloop_);
throw std::runtime_error("pw_context_connect() failed"); throw std::runtime_error("pw_context_connect() failed");
} }
registry_ = pw_core_get_registry(core_, PW_VERSION_REGISTRY, 0); registry_ = pw_core_get_registry(core_, PW_VERSION_REGISTRY, 0);
@ -61,11 +66,17 @@ PipewireBackend::PipewireBackend(PrivateConstructorTag tag)
spa_zero(registryListener_); spa_zero(registryListener_);
pw_registry_add_listener(registry_, &registryListener_, &REGISTRY_EVENTS, this); pw_registry_add_listener(registry_, &registryListener_, &REGISTRY_EVENTS, this);
if (pw_thread_loop_start(mainloop_) < 0) { if (pw_thread_loop_start(mainloop_) < 0) {
pw_thread_loop_unlock(mainloop_);
throw std::runtime_error("pw_thread_loop_start() failed."); throw std::runtime_error("pw_thread_loop_start() failed.");
} }
pw_thread_loop_unlock(mainloop_);
} }
PipewireBackend::~PipewireBackend() { PipewireBackend::~PipewireBackend() {
if (mainloop_ != nullptr) {
pw_thread_loop_lock(mainloop_);
}
if (registry_ != nullptr) { if (registry_ != nullptr) {
pw_proxy_destroy((struct pw_proxy *)registry_); pw_proxy_destroy((struct pw_proxy *)registry_);
} }
@ -81,6 +92,7 @@ PipewireBackend::~PipewireBackend() {
} }
if (mainloop_ != nullptr) { if (mainloop_ != nullptr) {
pw_thread_loop_unlock(mainloop_);
pw_thread_loop_stop(mainloop_); pw_thread_loop_stop(mainloop_);
pw_thread_loop_destroy(mainloop_); pw_thread_loop_destroy(mainloop_);
} }