diff options
author | Andreas Pehrson <[email protected]> | 2024-06-24 09:36:37 +0200 |
---|---|---|
committer | Andreas Pehrson <[email protected]> | 2024-06-24 11:29:24 +0200 |
commit | d896f3af2a03d1df883c54fca0550edddf7ecbd6 (patch) | |
tree | 22b3b6fd5ad0b2ad9bdf7e7768de03ff49dffc2b | |
parent | 76ffc3e9e159c05c2513587e82e396a41eaf55f8 (diff) | |
download | cubeb-d896f3af2a03d1df883c54fca0550edddf7ecbd6.tar.gz cubeb-d896f3af2a03d1df883c54fca0550edddf7ecbd6.zip |
Allocate and share session ID for input voice streams
A session ID is required for audiofx, even through presets.
The latter is not clear in the documentation, but see
https://android.googlesource.com/platform/frameworks/av/+/master/services/audioflinger/AudioFlinger.cpp#1035
-rw-r--r-- | src/cubeb_aaudio.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
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<mutex> & 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<int32_t>::max()); @@ -1242,6 +1251,9 @@ aaudio_stream_init_impl(cubeb_stream * stm, lock_guard<mutex> & 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); |