diff options
author | Max Kellermann <max@musicpd.org> | 2018-09-21 18:00:23 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-09-21 18:12:28 +0200 |
commit | e3142312bb452606bcf008fff1c6cdb7a9478a22 (patch) | |
tree | 46ba940331d87526b9eb0bfca45dd159949b2cda | |
parent | e5d1ac0bd09760d9d568e92e94c1ae14c35e266f (diff) |
player/Control: convert to class
-rw-r--r-- | src/client/Client.hxx | 2 | ||||
-rw-r--r-- | src/player/Control.hxx | 31 | ||||
-rw-r--r-- | src/player/Thread.cxx | 6 | ||||
-rw-r--r-- | src/playlist/PlaylistQueue.hxx | 2 | ||||
-rw-r--r-- | src/queue/Playlist.cxx | 6 | ||||
-rw-r--r-- | src/queue/Playlist.hxx | 2 | ||||
-rw-r--r-- | src/queue/PlaylistState.hxx | 2 |
7 files changed, 37 insertions, 14 deletions
diff --git a/src/client/Client.hxx b/src/client/Client.hxx index 7edbc97c4..9b9e05a35 100644 --- a/src/client/Client.hxx +++ b/src/client/Client.hxx @@ -44,7 +44,7 @@ class EventLoop; class Path; struct Instance; struct Partition; -struct PlayerControl; +class PlayerControl; struct playlist; class Database; class Storage; diff --git a/src/player/Control.hxx b/src/player/Control.hxx index 4a65dce63..063d4b266 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -109,7 +109,9 @@ struct PlayerStatus { SongTime elapsed_time; }; -struct PlayerControl final : AudioOutputClient { +class PlayerControl final : public AudioOutputClient { + friend class Player; + PlayerListener &listener; PlayerOutputs &outputs; @@ -231,6 +233,7 @@ struct PlayerControl final : AudioOutputClient { double total_play_time = 0; +public: PlayerControl(PlayerListener &_listener, PlayerOutputs &_outputs, unsigned buffer_chunks, @@ -268,6 +271,7 @@ struct PlayerControl final : AudioOutputClient { cond.signal(); } +private: /** * Signals the object. The object is temporarily locked by * this function. @@ -347,7 +351,6 @@ struct PlayerControl final : AudioOutputClient { return WaitOutputConsumed(threshold); } -private: /** * Wait for the command to be finished by the player thread. * @@ -417,12 +420,14 @@ public: */ void LockSetBorderPause(bool border_pause) noexcept; +private: bool ApplyBorderPause() noexcept { if (border_pause) state = PlayerState::PAUSE; return border_pause; } +public: void Kill() noexcept; gcc_pure @@ -432,6 +437,7 @@ public: return state; } +private: /** * Set the error. Discards any previous error condition. * @@ -468,6 +474,7 @@ public: std::rethrow_exception(error); } +public: /** * Like CheckRethrowError(), but locks and unlocks the object. */ @@ -482,6 +489,7 @@ public: return error_type; } +private: /** * Set the #tagged_song attribute to a newly allocated copy of * the given #DetachedSong. Locks and unlocks the object. @@ -497,6 +505,7 @@ public: */ std::unique_ptr<DetachedSong> ReadTaggedSong() noexcept; +public: /** * Like ReadTaggedSong(), but locks and unlocks the object. */ @@ -521,6 +530,10 @@ public: */ void LockEnqueueSong(std::unique_ptr<DetachedSong> song) noexcept; + bool HasNextSong() const noexcept { + return next_song != nullptr; + } + /** * Makes the player thread seek the specified song to a position. * @@ -531,6 +544,19 @@ public: */ void LockSeek(std::unique_ptr<DetachedSong> song, SongTime t); +private: + /** + * Caller must lock the object. + */ + void CancelPendingSeek() noexcept { + if (!seeking) + return; + + seeking = false; + ClientSignal(); + } + +public: void SetCrossFade(float cross_fade_seconds) noexcept; float GetCrossFade() const noexcept { @@ -558,6 +584,7 @@ public: return total_play_time; } +private: void LockUpdateSongTag(DetachedSong &song, const Tag &new_tag) noexcept; diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 53b6a032b..73b90d2a3 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -261,12 +261,8 @@ private: bool SeekDecoder() noexcept; void CancelPendingSeek() noexcept { - if (!pc.seeking) - return; - pending_seek = SongTime::zero(); - pc.seeking = false; - pc.ClientSignal(); + pc.CancelPendingSeek(); } /** diff --git a/src/playlist/PlaylistQueue.hxx b/src/playlist/PlaylistQueue.hxx index 90404f734..4851a1c6d 100644 --- a/src/playlist/PlaylistQueue.hxx +++ b/src/playlist/PlaylistQueue.hxx @@ -27,7 +27,7 @@ class SongLoader; class SongEnumerator; struct playlist; -struct PlayerControl; +class PlayerControl; /** * Loads the contents of a playlist and append it to the specified diff --git a/src/queue/Playlist.cxx b/src/queue/Playlist.cxx index f2d6c9672..358cbee1a 100644 --- a/src/queue/Playlist.cxx +++ b/src/queue/Playlist.cxx @@ -91,7 +91,7 @@ playlist::SongStarted() inline void playlist::QueuedSongStarted(PlayerControl &pc) { - assert(pc.next_song == nullptr); + assert(!pc.HasNextSong()); assert(queued >= -1); assert(current >= 0); @@ -197,7 +197,7 @@ playlist::SyncWithPlayer(PlayerControl &pc) pc.Lock(); const PlayerState pc_state = pc.GetState(); - bool pc_has_next_song = pc.next_song != nullptr; + bool pc_has_next_song = pc.HasNextSong(); pc.Unlock(); if (pc_state == PlayerState::STOP) @@ -213,7 +213,7 @@ playlist::SyncWithPlayer(PlayerControl &pc) QueuedSongStarted(pc); pc.Lock(); - pc_has_next_song = pc.next_song != nullptr; + pc_has_next_song = pc.HasNextSong(); pc.Unlock(); /* make sure the queued song is always set (if diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx index f2ef4eac5..faee44031 100644 --- a/src/queue/Playlist.hxx +++ b/src/queue/Playlist.hxx @@ -25,7 +25,7 @@ enum TagType : uint8_t; struct Tag; -struct PlayerControl; +class PlayerControl; class DetachedSong; class Database; class SongLoader; diff --git a/src/queue/PlaylistState.hxx b/src/queue/PlaylistState.hxx index 8c08a607b..9274755a6 100644 --- a/src/queue/PlaylistState.hxx +++ b/src/queue/PlaylistState.hxx @@ -27,7 +27,7 @@ struct StateFileConfig; struct playlist; -struct PlayerControl; +class PlayerControl; class TextFile; class BufferedOutputStream; class SongLoader; |