From b040f8968152d55d9475091cb83cd2f7692a43f4 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Thu, 9 Nov 2023 18:25:56 +0100 Subject: AAudio: when finding that an input device has been disconnected, reinitialize the duplex stream --- src/cubeb_aaudio.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 & lock); static int aaudio_stream_start_locked(cubeb_stream * stm, lock_guard & 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; -- cgit v1.2.3