diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index fe8a8db..4a57266 100644 --- a/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp @@ -48,6 +48,7 @@ using namespace std; X(AAudioStreamBuilder_delete) \ X(AAudioStreamBuilder_setDataCallback) \ X(AAudioStreamBuilder_setErrorCallback) \ + X(AAudioStreamBuilder_setSessionId) \ X(AAudioStream_close) \ X(AAudioStream_read) \ X(AAudioStream_requestStart) \ @@ -67,6 +68,7 @@ using namespace std; X(AAudioStream_getFramesWritten) \ X(AAudioStream_getFramesPerBurst) \ X(AAudioStream_getInputPreset) \ + X(AAudioStream_getSessionId) \ X(AAudioStreamBuilder_setInputPreset) \ X(AAudioStreamBuilder_setUsage) \ X(AAudioStreamBuilder_setFramesPerDataCallback) @@ -82,10 +84,8 @@ using namespace std; // X(AAudioStream_getXRunCount) \ // X(AAudioStream_isMMapUsed) \ // X(AAudioStreamBuilder_setContentType) \ - // X(AAudioStreamBuilder_setSessionId) \ // X(AAudioStream_getUsage) \ // X(AAudioStream_getContentType) \ - // X(AAudioStream_getSessionId) \ // END: not needed or added later on #define MAKE_TYPEDEF(x) static decltype(x) * cubeb_##x; @@ -179,6 +179,7 @@ struct cubeb_stream { bool voice_input{}; bool voice_output{}; cubeb_input_processing_params input_processing_params{}; + aaudio_session_id_t input_session_id{AAUDIO_SESSION_ID_NONE}; uint64_t previous_clock{}; }; @@ -1225,11 +1226,19 @@ aaudio_stream_init_impl(cubeb_stream * stm, lock_guard & lock) // input cubeb_stream_params in_params; if (stm->input_stream_params) { - aaudio_input_preset_t preset = - stm->voice_input ? *input_processing_params_to_input_preset( - stm->input_processing_params) - : AAUDIO_INPUT_PRESET_CAMCORDER; - WRAP(AAudioStreamBuilder_setInputPreset)(sb, preset); + if (stm->voice_input) { + const aaudio_session_id_t session_id = + stm->input_session_id == AAUDIO_SESSION_ID_NONE + ? AAUDIO_SESSION_ID_ALLOCATE + : stm->input_session_id; + WRAP(AAudioStreamBuilder_setSessionId)(sb, session_id); + const auto preset = *input_processing_params_to_input_preset( + stm->input_processing_params); + WRAP(AAudioStreamBuilder_setInputPreset)(sb, preset); + } else { + WRAP(AAudioStreamBuilder_setInputPreset) + (sb, AAUDIO_INPUT_PRESET_CAMCORDER); + } WRAP(AAudioStreamBuilder_setDirection)(sb, AAUDIO_DIRECTION_INPUT); WRAP(AAudioStreamBuilder_setDataCallback)(sb, in_data_callback, stm); assert(stm->latency_frames < std::numeric_limits::max()); @@ -1242,6 +1251,9 @@ aaudio_stream_init_impl(cubeb_stream * stm, lock_guard & lock) return res_err; } + if (stm->voice_input) { + stm->input_session_id = WRAP(AAudioStream_getSessionId)(stm->istream); + } int32_t input_burst_size = WRAP(AAudioStream_getFramesPerBurst)(stm->istream); LOG("AAudio input burst size: %d", input_burst_size);