From 38257fb81cdb81620872daf9d9edf32e03f89fcb Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 8 Jan 2025 09:07:58 +0100 Subject: [PATCH] On reinit, only call AAudioStream_getFramesWritten on a real stream This is a fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1936675. --- src/cubeb_aaudio.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index a8636224..e767d6fd 100644 --- a/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp @@ -1039,16 +1039,24 @@ reinitialize_stream(cubeb_stream * stm) state == stream_state::STARTING || state == stream_state::DRAINING; int err = aaudio_stream_stop_locked(stm, lock); - // get total number of written frames before destroying the stream. - uint64_t total_frames = stm->pos_estimate.initial_position() + - WRAP(AAudioStream_getFramesWritten)(stm->ostream); - // error ignored. + // Error ignored. + + // Get total number of written frames before destroying the stream. + uint64_t total_frames = stm->pos_estimate.initial_position(); + if (stm->ostream) { + // For output-only and duplex, use the output stream. + total_frames += WRAP(AAudioStream_getFramesWritten)(stm->ostream); + } else if (stm->istream) { + // Input-only, we can only use the input stream. + total_frames += WRAP(AAudioStream_getFramesWritten)(stm->istream); + } + aaudio_stream_destroy_locked(stm, lock); err = aaudio_stream_init_impl(stm, lock); assert(stm->in_use.load()); - // set the new initial position. + // Set the new initial position. stm->pos_estimate.reinit(total_frames); if (err != CUBEB_OK) {