diff --git a/src/Main.cxx b/src/Main.cxx index 12340bc7d..f9b474e6d 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -577,9 +577,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) ZeroconfInit(raw_config, instance->event_loop); - for (auto &partition : instance->partitions) - partition.pc.StartThread(); - #ifdef ENABLE_DATABASE if (create_db) { /* the database failed to load: recreate the diff --git a/src/command/PartitionCommands.cxx b/src/command/PartitionCommands.cxx index e3de9677f..379dcd51a 100644 --- a/src/command/PartitionCommands.cxx +++ b/src/command/PartitionCommands.cxx @@ -109,8 +109,6 @@ handle_newpartition(Client &client, Request request, Response &response) ReplayGainConfig(), partition.pc); partition.UpdateEffectiveReplayGainMode(); - partition.pc.StartThread(); - partition.pc.LockUpdateAudio(); instance.EmitIdle(IDLE_PARTITION); diff --git a/src/player/Control.cxx b/src/player/Control.cxx index b9a2cfc01..b53984c53 100644 --- a/src/player/Control.cxx +++ b/src/player/Control.cxx @@ -60,6 +60,9 @@ PlayerControl::WaitOutputConsumed(unsigned threshold) noexcept void PlayerControl::Play(std::unique_ptr song) { + if (!thread.IsDefined()) + thread.Start(); + assert(song != nullptr); const std::lock_guard protect(mutex); @@ -74,6 +77,8 @@ PlayerControl::Play(std::unique_ptr song) void PlayerControl::LockCancel() noexcept { + assert(thread.IsDefined()); + LockSynchronousCommand(PlayerCommand::CANCEL); assert(next_song == nullptr); } @@ -81,6 +86,9 @@ PlayerControl::LockCancel() noexcept void PlayerControl::LockStop() noexcept { + if (!thread.IsDefined()) + return; + LockSynchronousCommand(PlayerCommand::CLOSE_AUDIO); assert(next_song == nullptr); @@ -90,13 +98,17 @@ PlayerControl::LockStop() noexcept void PlayerControl::LockUpdateAudio() noexcept { + if (!thread.IsDefined()) + return; + LockSynchronousCommand(PlayerCommand::UPDATE_AUDIO); } void PlayerControl::Kill() noexcept { - assert(thread.IsDefined()); + if (!thread.IsDefined()) + return; LockSynchronousCommand(PlayerCommand::EXIT); thread.Join(); @@ -123,6 +135,9 @@ PlayerControl::LockPause() noexcept void PlayerControl::LockSetPause(bool pause_flag) noexcept { + if (!thread.IsDefined()) + return; + const std::lock_guard protect(mutex); switch (state) { @@ -154,7 +169,7 @@ PlayerControl::LockGetStatus() noexcept PlayerStatus status; const std::lock_guard protect(mutex); - if (!occupied) + if (!occupied && thread.IsDefined()) SynchronousCommand(PlayerCommand::REFRESH); status.state = state; @@ -216,6 +231,7 @@ PlayerControl::LockReadTaggedSong() noexcept void PlayerControl::LockEnqueueSong(std::unique_ptr song) noexcept { + assert(thread.IsDefined()); assert(song != nullptr); const std::lock_guard protect(mutex); @@ -270,6 +286,9 @@ PlayerControl::SeekLocked(std::unique_ptr song, SongTime t) void PlayerControl::LockSeek(std::unique_ptr song, SongTime t) { + if (!thread.IsDefined()) + thread.Start(); + assert(song != nullptr); { diff --git a/src/player/Control.hxx b/src/player/Control.hxx index 5e2fb4a89..0938c86f9 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -239,13 +239,6 @@ public: const ReplayGainConfig &_replay_gain_config) noexcept; ~PlayerControl() noexcept; - /** - * Throws on error. - */ - void StartThread() { - thread.Start(); - } - void Kill() noexcept; /**