From 6db6d3c50cfbff35139dad1adfe0f3f143bef1c9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Sep 2018 17:14:19 +0200 Subject: [PATCH] player/Thread: move StartPlayerThread() into PlayerControl --- Makefile.am | 2 +- src/Main.cxx | 3 +-- src/command/PartitionCommands.cxx | 3 +-- src/player/Control.hxx | 7 +++++ src/player/Thread.cxx | 28 ++++++++++++------- src/player/Thread.hxx | 45 ------------------------------- 6 files changed, 28 insertions(+), 60 deletions(-) delete mode 100644 src/player/Thread.hxx diff --git a/Makefile.am b/Makefile.am index c05d101b0..1b2735027 100644 --- a/Makefile.am +++ b/Makefile.am @@ -142,7 +142,7 @@ libmpd_a_SOURCES = \ src/Partition.cxx src/Partition.hxx \ src/Permission.cxx src/Permission.hxx \ src/player/CrossFade.cxx src/player/CrossFade.hxx \ - src/player/Thread.cxx src/player/Thread.hxx \ + src/player/Thread.cxx \ src/player/Control.cxx src/player/Control.hxx \ src/player/Listener.hxx \ src/player/Outputs.hxx \ diff --git a/src/Main.cxx b/src/Main.cxx index 4e1a65b85..93b87a1ce 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -24,7 +24,6 @@ #include "PlaylistFile.hxx" #include "MusicChunk.hxx" #include "StateFile.hxx" -#include "player/Thread.hxx" #include "Mapper.hxx" #include "Permission.hxx" #include "Listen.hxx" @@ -613,7 +612,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) ZeroconfInit(raw_config, instance->event_loop); for (auto &partition : instance->partitions) - StartPlayerThread(partition.pc); + partition.pc.StartThread(); #ifdef ENABLE_DATABASE if (create_db) { diff --git a/src/command/PartitionCommands.cxx b/src/command/PartitionCommands.cxx index 4bf3c641f..e7e8a0608 100644 --- a/src/command/PartitionCommands.cxx +++ b/src/command/PartitionCommands.cxx @@ -25,7 +25,6 @@ #include "IdleFlags.hxx" #include "client/Client.hxx" #include "client/Response.hxx" -#include "player/Thread.hxx" #include "util/CharUtil.hxx" CommandResult @@ -111,7 +110,7 @@ handle_newpartition(Client &client, Request request, Response &response) ReplayGainConfig(), partition.pc); partition.UpdateEffectiveReplayGainMode(); - StartPlayerThread(partition.pc); + partition.pc.StartThread(); partition.pc.LockUpdateAudio(); instance.EmitIdle(IDLE_PARTITION); diff --git a/src/player/Control.hxx b/src/player/Control.hxx index ebd063098..11bf43cc0 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -237,6 +237,13 @@ struct PlayerControl final : AudioOutputClient { const ReplayGainConfig &_replay_gain_config) noexcept; ~PlayerControl() noexcept; + /** + * Throws on error. + */ + void StartThread() { + thread.Start(); + } + /** * Locks the object. */ diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 11c360fdf..8ef278fd8 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -17,8 +17,25 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* \file + * + * The player thread controls the playback. It acts as a bridge + * between the decoder thread and the output thread(s): it receives + * #MusicChunk objects from the decoder, optionally mixes them + * (cross-fading), applies software volume, and sends them to the + * audio outputs via audio_output_all_play(). + * + * It is controlled by the main thread (the playlist code), see + * Control.hxx. The playlist enqueues new songs into the player + * thread and sends it commands. + * + * The player thread itself does not do any I/O. It synchronizes with + * other threads via #GMutex and #GCond objects, and passes + * #MusicChunk instances around in #MusicPipe objects. + */ + #include "config.h" -#include "Thread.hxx" +#include "Control.hxx" #include "Outputs.hxx" #include "Listener.hxx" #include "decoder/Control.hxx" @@ -27,7 +44,6 @@ #include "MusicChunk.hxx" #include "song/DetachedSong.hxx" #include "CrossFade.hxx" -#include "Control.hxx" #include "tag/Tag.hxx" #include "Idle.hxx" #include "util/Domain.hxx" @@ -1170,11 +1186,3 @@ PlayerControl::RunThread() noexcept } } } - -void -StartPlayerThread(PlayerControl &pc) -{ - assert(!pc.thread.IsDefined()); - - pc.thread.Start(); -} diff --git a/src/player/Thread.hxx b/src/player/Thread.hxx deleted file mode 100644 index c5cf5cba2..000000000 --- a/src/player/Thread.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2003-2017 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/* \file - * - * The player thread controls the playback. It acts as a bridge - * between the decoder thread and the output thread(s): it receives - * #MusicChunk objects from the decoder, optionally mixes them - * (cross-fading), applies software volume, and sends them to the - * audio outputs via audio_output_all_play(). - * - * It is controlled by the main thread (the playlist code), see - * Control.hxx. The playlist enqueues new songs into the player - * thread and sends it commands. - * - * The player thread itself does not do any I/O. It synchronizes with - * other threads via #GMutex and #GCond objects, and passes - * #MusicChunk instances around in #MusicPipe objects. - */ - -#ifndef MPD_PLAYER_THREAD_HXX -#define MPD_PLAYER_THREAD_HXX - -struct PlayerControl; - -void -StartPlayerThread(PlayerControl &pc); - -#endif