From 265049c5192cf0ce862c7db7b4745636afb6c17b Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 8 May 2024 16:03:03 +1000 Subject: 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 --- src/tangara/audio/audio_decoder.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/tangara/audio/audio_decoder.cpp') 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(); -- cgit v1.2.3