diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-09-13 15:23:03 +1000 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-09-13 15:23:03 +1000 |
| commit | f58679983e0854e2f976f2c5bbea1a8755c70bc3 (patch) | |
| tree | 51f87f5441ff79dd6e489dd09dd7cfa183861440 | |
| parent | 79dccc2685fad2763c5df31255095946cece2248 (diff) | |
| download | tangara-fw-f58679983e0854e2f976f2c5bbea1a8755c70bc3.tar.gz | |
Save positions over 5 minutes, every minute
| -rw-r--r-- | src/tangara/audio/audio_fsm.cpp | 12 | ||||
| -rw-r--r-- | src/tangara/audio/audio_fsm.hpp | 1 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp index 131e0a06..210f9afd 100644 --- a/src/tangara/audio/audio_fsm.cpp +++ b/src/tangara/audio/audio_fsm.cpp @@ -70,6 +70,8 @@ StreamCues AudioState::sStreamCues; bool AudioState::sIsPaused = true; +uint8_t AudioState::sUpdateCounter = 0; + auto AudioState::emitPlaybackUpdate(bool paused) -> void { std::optional<uint32_t> position; auto current = sStreamCues.current(); @@ -80,8 +82,14 @@ auto AudioState::emitPlaybackUpdate(bool paused) -> void { current.first->start_offset.value_or(0); } - if (position) { - // Update position if the duration has been long enough + // If we've got an elapsed duration and it's more than 5 minutes + // increment a counter. Every 60 counts (ie, every minute) save the current elapsed position + if (position && *position > (5 * 60)) { + sUpdateCounter++; + if (sUpdateCounter > 60) { + sUpdateCounter = 0; + updateSavedPosition(current.first->uri, *position); + } } PlaybackUpdate event{ diff --git a/src/tangara/audio/audio_fsm.hpp b/src/tangara/audio/audio_fsm.hpp index 0c8f4d26..99824b4c 100644 --- a/src/tangara/audio/audio_fsm.hpp +++ b/src/tangara/audio/audio_fsm.hpp @@ -90,6 +90,7 @@ class AudioState : public tinyfsm::Fsm<AudioState> { static std::optional<IAudioOutput::Format> sDrainFormat; static bool sIsPaused; + static uint8_t sUpdateCounter; }; namespace states { |
