diff options
author | Andreas Pehrson <[email protected]> | 2024-06-24 11:17:37 +0200 |
---|---|---|
committer | Andreas Pehrson <[email protected]> | 2024-06-24 11:28:05 +0200 |
commit | 220eb1978f8008127b00e58baef119e46e855913 (patch) | |
tree | 4c568f6802a82e93622634c72d0873cab2780476 /src/cubeb_aaudio.cpp | |
parent | 667fb710d31ab624e7e9893eceb1b7738372c964 (diff) | |
download | cubeb-220eb1978f8008127b00e58baef119e46e855913.tar.gz cubeb-220eb1978f8008127b00e58baef119e46e855913.zip |
Implement aaudio_get_supported_input_processing_params
This also sets up the AAudio backend with JNI if available from the
client. Input processing params are only supported if JNI is available
and it reports that AEC is available on the system.
Diffstat (limited to 'src/cubeb_aaudio.cpp')
-rw-r--r-- | src/cubeb_aaudio.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index 9e81ed3..26f28f8 100644 --- a/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp @@ -5,6 +5,7 @@ * accompanying file LICENSE for details. */ #include "cubeb-internal.h" +#include "cubeb-jni.h" #include "cubeb/cubeb.h" #include "cubeb_android.h" #include "cubeb_log.h" @@ -135,6 +136,10 @@ struct AAudioTimingInfo { uint32_t input_latency; }; +struct cubeb_jni_delete { + void operator()(cubeb_jni * jni) { cubeb_jni_destroy(jni); } +}; + struct cubeb_stream { /* Note: Must match cubeb_stream layout in cubeb.c. */ cubeb * context{}; @@ -179,6 +184,8 @@ struct cubeb { struct cubeb_ops const * ops{}; void * libaaudio{}; + std::unique_ptr<cubeb_jni, cubeb_jni_delete> jni; + struct { // The state thread: it waits for state changes and stops // drained streams. @@ -1743,6 +1750,28 @@ aaudio_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate) return CUBEB_OK; } +int +aaudio_get_supported_input_processing_params( + cubeb * ctx, cubeb_input_processing_params * params) +{ + if (!ctx->jni) { + return CUBEB_ERROR_NOT_SUPPORTED; + } + + if (cubeb_fx_is_available(ctx->jni.get(), CUBEB_FX_ACOUSTIC_ECHO_CANCELER)) { + *params = static_cast<cubeb_input_processing_params>( + CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION | + CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL | + CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION); + } else { + *params = CUBEB_INPUT_PROCESSING_PARAM_NONE; + } + + LOG("%s: Supported params are %s (%d)", __func__, + input_processing_params_to_str(*params), *params); + return CUBEB_OK; +} + extern "C" int aaudio_init(cubeb ** context, char const * context_name); @@ -1750,9 +1779,10 @@ const static struct cubeb_ops aaudio_ops = { /*.init =*/aaudio_init, /*.get_backend_id =*/aaudio_get_backend_id, /*.get_max_channel_count =*/aaudio_get_max_channel_count, - /* .get_min_latency =*/aaudio_get_min_latency, + /*.get_min_latency =*/aaudio_get_min_latency, /*.get_preferred_sample_rate =*/aaudio_get_preferred_sample_rate, - /*.get_supported_input_processing_params =*/nullptr, + /*.get_supported_input_processing_params =*/ + aaudio_get_supported_input_processing_params, /*.enumerate_devices =*/nullptr, /*.device_collection_destroy =*/nullptr, /*.destroy =*/aaudio_destroy, @@ -1800,6 +1830,7 @@ aaudio_init(cubeb ** context, char const * /* context_name */) cubeb * ctx = new cubeb; ctx->ops = &aaudio_ops; ctx->libaaudio = libaaudio; + ctx->jni.reset(cubeb_jni_init()); ctx->state.thread = std::thread(state_thread, ctx); |