diff options
author | Max Kellermann <max@musicpd.org> | 2021-07-30 13:32:58 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2021-07-30 13:42:59 +0200 |
commit | 6975d3ca4bcce3b61fbc87b15202e7d794baf169 (patch) | |
tree | 807f390fa2929406e7f7144dbbf6dba9fae9cee2 | |
parent | cdca27e6bb8fc00299a7337209c85956c74dde38 (diff) |
output/pipewire: switch from pw_main_loop to pw_thread_loop
We need this for pw_thread_loop_lock().
-rw-r--r-- | src/output/plugins/PipeWireOutputPlugin.cxx | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/src/output/plugins/PipeWireOutputPlugin.cxx b/src/output/plugins/PipeWireOutputPlugin.cxx index 57bce9f7c..d1ea6ffed 100644 --- a/src/output/plugins/PipeWireOutputPlugin.cxx +++ b/src/output/plugins/PipeWireOutputPlugin.cxx @@ -21,7 +21,6 @@ //#include "lib/pipewire/MainLoop.hxx" #include "../OutputAPI.hxx" #include "../Error.hxx" -#include "thread/Thread.hxx" #ifdef __GNUC__ #pragma GCC diagnostic push @@ -43,8 +42,9 @@ #include <stdexcept> class PipeWireOutput final : AudioOutput { - Thread thread{BIND_THIS_METHOD(RunThread)}; - struct pw_main_loop *loop; + const char *const name; + + struct pw_thread_loop *thread_loop; struct pw_stream *stream; std::byte buffer[1024]; @@ -83,10 +83,6 @@ private: o.Process(); } - void RunThread() noexcept { - pw_main_loop_run(loop); - } - /* virtual methods from class AudioOutput */ void Enable() override; void Disable() noexcept override; @@ -110,6 +106,7 @@ static constexpr auto stream_events = PipeWireOutput::MakeStreamEvents(); inline PipeWireOutput::PipeWireOutput(const ConfigBlock &block) :AudioOutput(FLAG_ENABLE_DISABLE), + name(block.GetBlockValue("name", "pipewire")), target_id(block.GetBlockValue("target", unsigned(PW_ID_ANY))) { } @@ -117,25 +114,17 @@ PipeWireOutput::PipeWireOutput(const ConfigBlock &block) void PipeWireOutput::Enable() { - loop = pw_main_loop_new(nullptr); - if (loop == nullptr) - throw std::runtime_error("pw_main_loop_new() failed"); - - try { - thread.Start(); - } catch (...) { - pw_main_loop_destroy(loop); - throw; - } + thread_loop = pw_thread_loop_new(name, nullptr); + if (thread_loop == nullptr) + throw std::runtime_error("pw_thread_loop_new() failed"); + + pw_thread_loop_start(thread_loop); } void PipeWireOutput::Disable() noexcept { - pw_main_loop_quit(loop); - thread.Join(); - - pw_main_loop_destroy(loop); + pw_thread_loop_destroy(thread_loop); } static constexpr enum spa_audio_format @@ -198,7 +187,7 @@ PipeWireOutput::Open(AudioFormat &audio_format) PW_KEY_NODE_NAME, "mpd", nullptr); - stream = pw_stream_new_simple(pw_main_loop_get_loop(loop), + stream = pw_stream_new_simple(pw_thread_loop_get_loop(thread_loop), "mpd", props, &stream_events, |