Skip to content

Commit

Permalink
Invalidate timing info buffers when destorying AAudio stream.
Browse files Browse the repository at this point in the history
aaudio_stream_get_position() returns incorrect result because
aaudio_stream_init() recycled destroyed stream where the
timing_info buffers contain stale data.
  • Loading branch information
jhlin authored and kinetiknz committed Apr 29, 2024
1 parent b82e270 commit 19fcbef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cubeb_aaudio.cpp
Expand Up @@ -1049,6 +1049,8 @@ aaudio_stream_destroy_locked(cubeb_stream * stm, lock_guard<mutex> & lock)
stm->istream = nullptr;
}

stm->timing_info.invalidate();

if (stm->resampler) {
cubeb_resampler_destroy(stm->resampler);
stm->resampler = nullptr;
Expand Down
7 changes: 7 additions & 0 deletions src/cubeb_triple_buffer.h
Expand Up @@ -42,6 +42,13 @@ template <typename T> class triple_buffer {
{
return (shared_state.load(std::memory_order_relaxed) & BACK_DIRTY_BIT) != 0;
}
// Reset state and indices to initial values.
void invalidate()
{
shared_state.store(0, std::memory_order_release);
input_idx = 1;
output_idx = 2;
}

private:
// Publish a value to the consumer. Returns true if the data was overwritten
Expand Down
3 changes: 3 additions & 0 deletions test/test_triple_buffer.cpp
Expand Up @@ -64,4 +64,7 @@ TEST(cubeb, triple_buffer)
}

t.join();

buffer.invalidate();
ASSERT_FALSE(buffer.updated());
}

0 comments on commit 19fcbef

Please sign in to comment.