Commit e5d1ac0b authored by Max Kellermann's avatar Max Kellermann

player/Thread: move functions into PlayerControl

parent c0411fa4
...@@ -29,12 +29,14 @@ ...@@ -29,12 +29,14 @@
#include "Chrono.hxx" #include "Chrono.hxx"
#include "ReplayGainConfig.hxx" #include "ReplayGainConfig.hxx"
#include "ReplayGainMode.hxx" #include "ReplayGainMode.hxx"
#include "MusicChunkPtr.hxx"
#include <exception> #include <exception>
#include <memory> #include <memory>
#include <stdint.h> #include <stdint.h>
struct Tag;
class PlayerListener; class PlayerListener;
class PlayerOutputs; class PlayerOutputs;
class DetachedSong; class DetachedSong;
...@@ -556,6 +558,22 @@ public: ...@@ -556,6 +558,22 @@ public:
return total_play_time; return total_play_time;
} }
void LockUpdateSongTag(DetachedSong &song,
const Tag &new_tag) noexcept;
/**
* Plays a #MusicChunk object (after applying software
* volume). If it contains a (stream) tag, copy it to the
* current song, so MPD's playlist reflects the new stream
* tag.
*
* Player lock is not held.
*
* Throws on error.
*/
void PlayChunk(DetachedSong &song, MusicChunkPtr chunk,
const AudioFormat &format);
/* virtual methods from AudioOutputClient */ /* virtual methods from AudioOutputClient */
void ChunksConsumed() override { void ChunksConsumed() override {
LockSignal(); LockSignal();
......
...@@ -726,9 +726,9 @@ Player::ProcessCommand() noexcept ...@@ -726,9 +726,9 @@ Player::ProcessCommand() noexcept
return true; return true;
} }
static void inline void
update_song_tag(PlayerControl &pc, DetachedSong &song, PlayerControl::LockUpdateSongTag(DetachedSong &song,
const Tag &new_tag) noexcept const Tag &new_tag) noexcept
{ {
if (song.IsFile()) if (song.IsFile())
/* don't update tags of local files, only remote /* don't update tags of local files, only remote
...@@ -737,48 +737,40 @@ update_song_tag(PlayerControl &pc, DetachedSong &song, ...@@ -737,48 +737,40 @@ update_song_tag(PlayerControl &pc, DetachedSong &song,
song.SetTag(new_tag); song.SetTag(new_tag);
pc.LockSetTaggedSong(song); LockSetTaggedSong(song);
/* the main thread will update the playlist version when he /* the main thread will update the playlist version when he
receives this event */ receives this event */
pc.listener.OnPlayerTagModified(); listener.OnPlayerTagModified();
/* notify all clients that the tag of the current song has /* notify all clients that the tag of the current song has
changed */ changed */
idle_add(IDLE_PLAYER); idle_add(IDLE_PLAYER);
} }
/** inline void
* Plays a #MusicChunk object (after applying software volume). If PlayerControl::PlayChunk(DetachedSong &song, MusicChunkPtr chunk,
* it contains a (stream) tag, copy it to the current song, so MPD's const AudioFormat &format)
* playlist reflects the new stream tag.
*
* Player lock is not held.
*/
static void
play_chunk(PlayerControl &pc,
DetachedSong &song, MusicChunkPtr chunk,
const AudioFormat format)
{ {
assert(chunk->CheckFormat(format)); assert(chunk->CheckFormat(format));
if (chunk->tag != nullptr) if (chunk->tag != nullptr)
update_song_tag(pc, song, *chunk->tag); LockUpdateSongTag(song, *chunk->tag);
if (chunk->IsEmpty()) if (chunk->IsEmpty())
return; return;
{ {
const std::lock_guard<Mutex> lock(pc.mutex); const std::lock_guard<Mutex> lock(mutex);
pc.bit_rate = chunk->bit_rate; bit_rate = chunk->bit_rate;
} }
/* send the chunk to the audio outputs */ /* send the chunk to the audio outputs */
const double chunk_length(chunk->length); const double chunk_length(chunk->length);
pc.outputs.Play(std::move(chunk)); outputs.Play(std::move(chunk));
pc.total_play_time += chunk_length / format.GetTimeToSize(); total_play_time += chunk_length / format.GetTimeToSize();
} }
inline bool inline bool
...@@ -875,8 +867,8 @@ Player::PlayNextChunk() noexcept ...@@ -875,8 +867,8 @@ Player::PlayNextChunk() noexcept
/* play the current chunk */ /* play the current chunk */
try { try {
play_chunk(pc, *song, std::move(chunk), pc.PlayChunk(*song, std::move(chunk),
play_audio_format); play_audio_format);
} catch (...) { } catch (...) {
LogError(std::current_exception()); LogError(std::current_exception());
......
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