From 2f43e4bc668f04a222500ab34536ef00149e209f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 21 Oct 2013 23:22:16 +0200 Subject: Playlist: copy stream tags from the PlayerThread Finally restores an important feature that has been broken for several months when the PlayerThread started working with Song copies instead of pointers to the Queue's Song instances (commit e96779d). --- src/PlayerControl.hxx | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'src/PlayerControl.hxx') diff --git a/src/PlayerControl.hxx b/src/PlayerControl.hxx index b2b2087e2..bdfc10fec 100644 --- a/src/PlayerControl.hxx +++ b/src/PlayerControl.hxx @@ -100,7 +100,7 @@ struct player_control { Thread thread; /** - * This lock protects #command, #state, #error. + * This lock protects #command, #state, #error, #tagged_song. */ mutable Mutex mutex; @@ -129,6 +129,18 @@ struct player_control { */ Error error; + /** + * A copy of the current #Song after its tags have been + * updated by the decoder (for example, a radio stream that + * has sent a new tag after switching to the next song). This + * shall be used by the GlobalEvents::TAG handler to update + * the current #Song in the queue. + * + * Protected by #mutex. Set by the PlayerThread and consumed + * by the main thread. + */ + Song *tagged_song; + uint16_t bit_rate; AudioFormat audio_format; float total_time; @@ -356,6 +368,35 @@ public: return error_type; } + /** + * Set the #tagged_song attribute to a newly allocated copy of + * the given #Song. Locks and unlocks the object. + */ + void LockSetTaggedSong(const Song &song); + + void ClearTaggedSong(); + + /** + * Read and clear the #tagged_song attribute. + * + * Caller must lock the object. + */ + Song *ReadTaggedSong() { + Song *result = tagged_song; + tagged_song = nullptr; + return result; + } + + /** + * Like ReadTaggedSong(), but locks and unlocks the object. + */ + Song *LockReadTaggedSong() { + Lock(); + Song *result = ReadTaggedSong(); + Unlock(); + return result; + } + void Stop(); void UpdateAudio(); -- cgit v1.2.3