From 3f45761b4f002249691a1a9a7a5bf8e8a01add78 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Tue, 18 Apr 2023 17:27:25 +0200 Subject: Add a way to know if the data callback is running --- src/cubeb_aaudio.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index 1c98ed3..80bd4ac 100644 --- a/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp @@ -135,6 +135,7 @@ struct cubeb_stream { std::atomic in_use{false}; std::atomic latency_metrics_available{false}; std::atomic state{stream_state::INIT}; + std::atomic in_data_callback{false}; triple_buffer timing_info; AAudioStream * ostream{}; @@ -180,6 +181,15 @@ struct cubeb { struct cubeb_stream streams[MAX_STREAMS]; }; +struct AutoInCallback { + AutoInCallback(cubeb_stream * stm) : stm(stm) + { + stm->in_data_callback.store(true); + } + ~AutoInCallback() { stm->in_data_callback.store(false); } + cubeb_stream * stm; +}; + // Only allowed from state thread, while mutex on stm is locked static void shutdown_with_error(cubeb_stream * stm) @@ -612,6 +622,7 @@ aaudio_duplex_data_cb(AAudioStream * astream, void * user_data, void * audio_data, int32_t num_frames) { cubeb_stream * stm = (cubeb_stream *)user_data; + AutoInCallback aic(stm); assert(stm->ostream == astream); assert(stm->istream); assert(num_frames >= 0); @@ -693,6 +704,7 @@ aaudio_output_data_cb(AAudioStream * astream, void * user_data, void * audio_data, int32_t num_frames) { cubeb_stream * stm = (cubeb_stream *)user_data; + AutoInCallback aic(stm); assert(stm->ostream == astream); assert(!stm->istream); assert(num_frames >= 0); @@ -741,6 +753,7 @@ aaudio_input_data_cb(AAudioStream * astream, void * user_data, void * audio_data, int32_t num_frames) { cubeb_stream * stm = (cubeb_stream *)user_data; + AutoInCallback aic(stm); assert(stm->istream == astream); assert(!stm->ostream); assert(num_frames >= 0); -- cgit v1.2.3