diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-05-08 16:03:03 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-05-08 16:03:03 +1000 |
| commit | 265049c5192cf0ce862c7db7b4745636afb6c17b (patch) | |
| tree | 6729bc947c6c2d2d196c9e7baa994a35aeea76ee /src/tangara/audio/audio_decoder.cpp | |
| parent | b242ba998699208c87dc066158964de0866b61e2 (diff) | |
| download | tangara-fw-265049c5192cf0ce862c7db7b4745636afb6c17b.tar.gz | |
Count samples going in and out of the drain buffer
This is a more accurate way of knowing which track is playing when, and
also simplifies a lot of fragile logic in audio_fsm
Diffstat (limited to 'src/tangara/audio/audio_decoder.cpp')
| -rw-r--r-- | src/tangara/audio/audio_decoder.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/tangara/audio/audio_decoder.cpp b/src/tangara/audio/audio_decoder.cpp index 0e38bca8..ee06d984 100644 --- a/src/tangara/audio/audio_decoder.cpp +++ b/src/tangara/audio/audio_decoder.cpp @@ -92,7 +92,7 @@ void Decoder::Main() { // If we were already decoding, then make sure we finish up the current // file gracefully. if (stream_) { - finishDecode(); + finishDecode(true); } // Ensure there's actually stream data; we might have been given nullptr @@ -106,7 +106,7 @@ void Decoder::Main() { } if (!continueDecode()) { - finishDecode(); + finishDecode(false); } } } @@ -179,12 +179,16 @@ auto Decoder::continueDecode() -> bool { return !res->is_stream_finished; } -auto Decoder::finishDecode() -> void { +auto Decoder::finishDecode(bool cancel) -> void { assert(track_); // Tell everyone we're finished. - events::Audio().Dispatch(internal::DecodingFinished{.track = track_}); - processor_->endStream(); + if (cancel) { + events::Audio().Dispatch(internal::DecodingCancelled{.track = track_}); + } else { + events::Audio().Dispatch(internal::DecodingFinished{.track = track_}); + } + processor_->endStream(cancel); // Clean up after ourselves. stream_.reset(); |
