player/Control: add LockGetSyncInfo()
This commit is contained in:
parent
8c638c50a3
commit
0e0bc7976f
@ -434,6 +434,17 @@ public:
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SyncInfo {
|
||||||
|
PlayerState state;
|
||||||
|
bool has_next_song;
|
||||||
|
};
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
SyncInfo LockGetSyncInfo() const noexcept {
|
||||||
|
const std::lock_guard<Mutex> protect(mutex);
|
||||||
|
return {state, next_song != nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Set the error. Discards any previous error condition.
|
* Set the error. Discards any previous error condition.
|
||||||
@ -527,10 +538,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void LockEnqueueSong(std::unique_ptr<DetachedSong> song) noexcept;
|
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.
|
* Makes the player thread seek the specified song to a position.
|
||||||
*
|
*
|
||||||
|
@ -91,7 +91,7 @@ playlist::SongStarted()
|
|||||||
inline void
|
inline void
|
||||||
playlist::QueuedSongStarted(PlayerControl &pc)
|
playlist::QueuedSongStarted(PlayerControl &pc)
|
||||||
{
|
{
|
||||||
assert(!pc.HasNextSong());
|
assert(!pc.LockGetSyncInfo().has_next_song);
|
||||||
assert(queued >= -1);
|
assert(queued >= -1);
|
||||||
assert(current >= 0);
|
assert(current >= 0);
|
||||||
|
|
||||||
@ -195,12 +195,9 @@ playlist::SyncWithPlayer(PlayerControl &pc)
|
|||||||
playing anymore; ignore the event */
|
playing anymore; ignore the event */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pc.Lock();
|
const auto i = pc.LockGetSyncInfo();
|
||||||
const PlayerState pc_state = pc.GetState();
|
|
||||||
bool pc_has_next_song = pc.HasNextSong();
|
|
||||||
pc.Unlock();
|
|
||||||
|
|
||||||
if (pc_state == PlayerState::STOP)
|
if (i.state == PlayerState::STOP)
|
||||||
/* the player thread has stopped: check if playback
|
/* the player thread has stopped: check if playback
|
||||||
should be restarted with the next song. That can
|
should be restarted with the next song. That can
|
||||||
happen if the playlist isn't filling the queue fast
|
happen if the playlist isn't filling the queue fast
|
||||||
@ -209,16 +206,12 @@ playlist::SyncWithPlayer(PlayerControl &pc)
|
|||||||
else {
|
else {
|
||||||
/* check if the player thread has already started
|
/* check if the player thread has already started
|
||||||
playing the queued song */
|
playing the queued song */
|
||||||
if (!pc_has_next_song && queued != -1)
|
if (!i.has_next_song && queued != -1)
|
||||||
QueuedSongStarted(pc);
|
QueuedSongStarted(pc);
|
||||||
|
|
||||||
pc.Lock();
|
|
||||||
pc_has_next_song = pc.HasNextSong();
|
|
||||||
pc.Unlock();
|
|
||||||
|
|
||||||
/* make sure the queued song is always set (if
|
/* make sure the queued song is always set (if
|
||||||
possible) */
|
possible) */
|
||||||
if (!pc_has_next_song && queued < 0)
|
if (!pc.LockGetSyncInfo().has_next_song && queued < 0)
|
||||||
UpdateQueuedSong(pc, nullptr);
|
UpdateQueuedSong(pc, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user