From 64f84d5468d97b6de7fed2c36b56b57d3a82b6cd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 13 Jul 2022 13:34:45 +0200 Subject: [PATCH] player/Listener: add virtual method OnPlayerState(), wrapping IDLE_PLAYER This eliminates most of the remaining global "player" idle events. --- NEWS | 1 + src/Partition.cxx | 6 ++++++ src/Partition.hxx | 1 + src/player/Listener.hxx | 6 ++++++ src/player/Thread.cxx | 10 ++++------ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index a3f7c6a05..313b4a01c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ ver 0.24 (not yet released) * protocol - "playlistfind"/"playlistsearch" have "sort" and "window" parameters - filter "prio" (for "playlistfind"/"playlistsearch") + - limit "player" idle events to the current partition * archive - add option to disable archive plugins in mpd.conf * decoder diff --git a/src/Partition.cxx b/src/Partition.cxx index 1c2f646dc..276a56a5c 100644 --- a/src/Partition.cxx +++ b/src/Partition.cxx @@ -189,6 +189,12 @@ Partition::OnPlayerError() noexcept EmitIdle(IDLE_PLAYER); } +void +Partition::OnPlayerStateChanged() noexcept +{ + EmitIdle(IDLE_PLAYER); +} + void Partition::OnPlayerSync() noexcept { diff --git a/src/Partition.hxx b/src/Partition.hxx index 9a841cdf9..a47855f98 100644 --- a/src/Partition.hxx +++ b/src/Partition.hxx @@ -278,6 +278,7 @@ private: /* virtual methods from class PlayerListener */ void OnPlayerError() noexcept override; + void OnPlayerStateChanged() noexcept override; void OnPlayerSync() noexcept override; void OnPlayerTagModified() noexcept override; void OnBorderPause() noexcept override; diff --git a/src/player/Listener.hxx b/src/player/Listener.hxx index 42254b85f..721478757 100644 --- a/src/player/Listener.hxx +++ b/src/player/Listener.hxx @@ -28,6 +28,12 @@ public: */ virtual void OnPlayerError() noexcept = 0; + /** + * Some state of the player has changed. This maps to + * #IDLE_PLAYER. + */ + virtual void OnPlayerStateChanged() noexcept = 0; + /** * Must call playlist_sync(). */ diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 9045b5d12..c2b84e93c 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -46,7 +46,6 @@ #include "CrossFade.hxx" #include "pcm/MixRampGlue.hxx" #include "tag/Tag.hxx" -#include "Idle.hxx" #include "util/Compiler.h" #include "util/Domain.hxx" #include "thread/Name.hxx" @@ -582,8 +581,7 @@ Player::OpenOutput() noexcept paused = false; pc.state = PlayerState::PLAY; - - idle_add(IDLE_PLAYER); + pc.listener.OnPlayerStateChanged(); return true; } @@ -617,7 +615,7 @@ Player::CheckDecoderStartup(std::unique_lock &lock) noexcept (buffer_before_play_size + sizeof(MusicChunk::data) - 1) / sizeof(MusicChunk::data); - idle_add(IDLE_PLAYER); + pc.listener.OnPlayerStateChanged(); if (pending_seek > SongTime::zero()) { assert(pc.seeking); @@ -707,7 +705,7 @@ Player::SeekDecoder(std::unique_lock &lock) noexcept pc.outputs.Cancel(); } - idle_add(IDLE_PLAYER); + pc.listener.OnPlayerStateChanged(); if (!dc.IsSeekableCurrentSong(*pc.next_song)) { /* the decoder is already decoding the "next" song - @@ -1108,7 +1106,7 @@ Player::SongBorder() noexcept pc.outputs.Drain(); pc.outputs.Pause(); - idle_add(IDLE_PLAYER); + pc.listener.OnPlayerStateChanged(); } }