Commit 2ec94c04 authored by Max Kellermann's avatar Max Kellermann

player/Control: start thread on demand

Keep MPD's footprint small until playback is requested.
parent bf372e3e
...@@ -577,9 +577,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) ...@@ -577,9 +577,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
ZeroconfInit(raw_config, instance->event_loop); ZeroconfInit(raw_config, instance->event_loop);
for (auto &partition : instance->partitions)
partition.pc.StartThread();
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (create_db) { if (create_db) {
/* the database failed to load: recreate the /* the database failed to load: recreate the
......
...@@ -109,8 +109,6 @@ handle_newpartition(Client &client, Request request, Response &response) ...@@ -109,8 +109,6 @@ handle_newpartition(Client &client, Request request, Response &response)
ReplayGainConfig(), ReplayGainConfig(),
partition.pc); partition.pc);
partition.UpdateEffectiveReplayGainMode(); partition.UpdateEffectiveReplayGainMode();
partition.pc.StartThread();
partition.pc.LockUpdateAudio();
instance.EmitIdle(IDLE_PARTITION); instance.EmitIdle(IDLE_PARTITION);
......
...@@ -60,6 +60,9 @@ PlayerControl::WaitOutputConsumed(unsigned threshold) noexcept ...@@ -60,6 +60,9 @@ PlayerControl::WaitOutputConsumed(unsigned threshold) noexcept
void void
PlayerControl::Play(std::unique_ptr<DetachedSong> song) PlayerControl::Play(std::unique_ptr<DetachedSong> song)
{ {
if (!thread.IsDefined())
thread.Start();
assert(song != nullptr); assert(song != nullptr);
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
...@@ -74,6 +77,8 @@ PlayerControl::Play(std::unique_ptr<DetachedSong> song) ...@@ -74,6 +77,8 @@ PlayerControl::Play(std::unique_ptr<DetachedSong> song)
void void
PlayerControl::LockCancel() noexcept PlayerControl::LockCancel() noexcept
{ {
assert(thread.IsDefined());
LockSynchronousCommand(PlayerCommand::CANCEL); LockSynchronousCommand(PlayerCommand::CANCEL);
assert(next_song == nullptr); assert(next_song == nullptr);
} }
...@@ -81,6 +86,9 @@ PlayerControl::LockCancel() noexcept ...@@ -81,6 +86,9 @@ PlayerControl::LockCancel() noexcept
void void
PlayerControl::LockStop() noexcept PlayerControl::LockStop() noexcept
{ {
if (!thread.IsDefined())
return;
LockSynchronousCommand(PlayerCommand::CLOSE_AUDIO); LockSynchronousCommand(PlayerCommand::CLOSE_AUDIO);
assert(next_song == nullptr); assert(next_song == nullptr);
...@@ -90,13 +98,17 @@ PlayerControl::LockStop() noexcept ...@@ -90,13 +98,17 @@ PlayerControl::LockStop() noexcept
void void
PlayerControl::LockUpdateAudio() noexcept PlayerControl::LockUpdateAudio() noexcept
{ {
if (!thread.IsDefined())
return;
LockSynchronousCommand(PlayerCommand::UPDATE_AUDIO); LockSynchronousCommand(PlayerCommand::UPDATE_AUDIO);
} }
void void
PlayerControl::Kill() noexcept PlayerControl::Kill() noexcept
{ {
assert(thread.IsDefined()); if (!thread.IsDefined())
return;
LockSynchronousCommand(PlayerCommand::EXIT); LockSynchronousCommand(PlayerCommand::EXIT);
thread.Join(); thread.Join();
...@@ -123,6 +135,9 @@ PlayerControl::LockPause() noexcept ...@@ -123,6 +135,9 @@ PlayerControl::LockPause() noexcept
void void
PlayerControl::LockSetPause(bool pause_flag) noexcept PlayerControl::LockSetPause(bool pause_flag) noexcept
{ {
if (!thread.IsDefined())
return;
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
switch (state) { switch (state) {
...@@ -154,7 +169,7 @@ PlayerControl::LockGetStatus() noexcept ...@@ -154,7 +169,7 @@ PlayerControl::LockGetStatus() noexcept
PlayerStatus status; PlayerStatus status;
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (!occupied) if (!occupied && thread.IsDefined())
SynchronousCommand(PlayerCommand::REFRESH); SynchronousCommand(PlayerCommand::REFRESH);
status.state = state; status.state = state;
...@@ -216,6 +231,7 @@ PlayerControl::LockReadTaggedSong() noexcept ...@@ -216,6 +231,7 @@ PlayerControl::LockReadTaggedSong() noexcept
void void
PlayerControl::LockEnqueueSong(std::unique_ptr<DetachedSong> song) noexcept PlayerControl::LockEnqueueSong(std::unique_ptr<DetachedSong> song) noexcept
{ {
assert(thread.IsDefined());
assert(song != nullptr); assert(song != nullptr);
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
...@@ -270,6 +286,9 @@ PlayerControl::SeekLocked(std::unique_ptr<DetachedSong> song, SongTime t) ...@@ -270,6 +286,9 @@ PlayerControl::SeekLocked(std::unique_ptr<DetachedSong> song, SongTime t)
void void
PlayerControl::LockSeek(std::unique_ptr<DetachedSong> song, SongTime t) PlayerControl::LockSeek(std::unique_ptr<DetachedSong> song, SongTime t)
{ {
if (!thread.IsDefined())
thread.Start();
assert(song != nullptr); assert(song != nullptr);
{ {
......
...@@ -239,13 +239,6 @@ public: ...@@ -239,13 +239,6 @@ public:
const ReplayGainConfig &_replay_gain_config) noexcept; const ReplayGainConfig &_replay_gain_config) noexcept;
~PlayerControl() noexcept; ~PlayerControl() noexcept;
/**
* Throws on error.
*/
void StartThread() {
thread.Start();
}
void Kill() noexcept; void Kill() noexcept;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment