Skip to content

Commit

Permalink
On reinit, only call AAudioStream_getFramesWritten on a real stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Pehrsons committed Jan 8, 2025
1 parent 9a9d034 commit 292f756
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/cubeb_aaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 292f756

Please sign in to comment.