Fix playback after restoring queue on boot

custom
jacqueline 12 months ago
parent 265049c519
commit 690c64c151
  1. 14
      src/tangara/audio/audio_fsm.cpp
  2. 8
      src/tangara/audio/stream_cues.cpp
  3. 3
      src/tangara/audio/stream_cues.hpp

@ -191,6 +191,11 @@ void AudioState::react(const internal::StreamStarted& ev) {
if (!sIsPaused && !is_in_state<states::Playback>()) {
transit<states::Playback>();
} else {
// Make sure everyone knows we've got a track ready to go, even if we're
// not playing it yet. This mostly matters when restoring the queue from
// disk after booting.
emitPlaybackUpdate(true);
}
}
@ -485,12 +490,13 @@ void Playback::react(const system_fsm::SdStateChanged& ev) {
void Playback::react(const internal::StreamHeartbeat& ev) {
sStreamCues.update(sOutput->samplesUsed());
auto current = sStreamCues.current();
if (!current.first) {
transit<Standby>();
} else {
if (sStreamCues.hasStream()) {
emitPlaybackUpdate(false);
} else {
// Finished the current stream, and there's nothing upcoming. We must be
// finished.
transit<Standby>();
}
}

@ -32,11 +32,15 @@ auto StreamCues::update(uint32_t sample) -> void {
auto StreamCues::addCue(std::shared_ptr<TrackInfo> track, uint32_t sample)
-> void {
if (sample == now_) {
current_ = {track, now_};
} else {
upcoming_.push_back(Cue{
.track = track,
.start_at = sample,
});
}
}
auto StreamCues::current() -> std::pair<std::shared_ptr<TrackInfo>, uint32_t> {
if (!current_) {
@ -54,4 +58,8 @@ auto StreamCues::current() -> std::pair<std::shared_ptr<TrackInfo>, uint32_t> {
return {current_->track, duration};
}
auto StreamCues::hasStream() -> bool {
return current_ || !upcoming_.empty();
}
} // namespace audio

@ -26,9 +26,12 @@ class StreamCues {
/* Updates the current track given the new most recently played sample. */
auto update(uint32_t sample) -> void;
/* Returns the current track, and how long it has been playing for. */
auto current() -> std::pair<std::shared_ptr<TrackInfo>, uint32_t>;
auto hasStream() -> bool;
auto addCue(std::shared_ptr<TrackInfo>, uint32_t start_at) -> void;
private:

Loading…
Cancel
Save