aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_aaudio.cpp
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2023-11-09 18:25:56 +0100
committerPaul Adenot <[email protected]>2023-11-10 11:31:35 +0100
commitb040f8968152d55d9475091cb83cd2f7692a43f4 (patch)
tree7ae220c5b2f8134656227371561e30e7b1128800 /src/cubeb_aaudio.cpp
parent4b4d18a70fcdb59c35a2affd3a99994ffd16ea8a (diff)
downloadcubeb-b040f8968152d55d9475091cb83cd2f7692a43f4.tar.gz
cubeb-b040f8968152d55d9475091cb83cd2f7692a43f4.zip
AAudio: when finding that an input device has been disconnected, reinitialize the duplex stream
Diffstat (limited to 'src/cubeb_aaudio.cpp')
-rw-r--r--src/cubeb_aaudio.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp
index 56d1ed7..e9286fb 100644
--- a/src/cubeb_aaudio.cpp
+++ b/src/cubeb_aaudio.cpp
@@ -110,6 +110,9 @@ aaudio_stream_destroy_locked(cubeb_stream * stm, lock_guard<mutex> & lock);
static int
aaudio_stream_start_locked(cubeb_stream * stm, lock_guard<mutex> & lock);
+static void
+reinitialize_stream(cubeb_stream * stm);
+
enum class stream_state {
INIT = 0,
STOPPED,
@@ -712,7 +715,13 @@ aaudio_duplex_data_cb(AAudioStream * astream, void * user_data,
long in_num_frames =
WRAP(AAudioStream_read)(stm->istream, stm->in_buf.data(), num_frames, 0);
if (in_num_frames < 0) { // error
- stm->state.store(stream_state::ERROR);
+ if (in_num_frames == AAUDIO_STREAM_STATE_DISCONNECTED) {
+ LOG("AAudioStream_read: %s (reinitializing)",
+ WRAP(AAudio_convertResultToText)(in_num_frames));
+ reinitialize_stream(stm);
+ } else {
+ stm->state.store(stream_state::ERROR);
+ }
LOG("AAudioStream_read: %s",
WRAP(AAudio_convertResultToText)(in_num_frames));
return AAUDIO_CALLBACK_RESULT_STOP;