From 3d5fc7133faf9c629258e98a81e2055ec0ad97cb Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Thu, 13 Jun 2024 23:59:41 +0200 Subject: Implement aaudio_get_supported_input_processing_params --- src/cubeb_aaudio.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index 9e81ed3..a8f596f 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" @@ -175,10 +176,16 @@ struct cubeb_stream { uint64_t previous_clock{}; }; +struct cubeb_jni_delete { + void operator()(cubeb_jni * jni) { cubeb_jni_destroy(jni); } +}; + struct cubeb { struct cubeb_ops const * ops{}; void * libaaudio{}; + std::unique_ptr jni; + struct { // The state thread: it waits for state changes and stops // drained streams. @@ -1743,6 +1750,29 @@ 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) +{ + int ps = CUBEB_INPUT_PROCESSING_PARAM_NONE; + + if (cubeb_fx_is_available(ctx->jni.get(), CUBEB_FX_ACOUSTIC_ECHO_CANCELER)) { + LOG("%s: AEC is supported", __func__); + ps |= CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION; + } + if (cubeb_fx_is_available(ctx->jni.get(), CUBEB_FX_AUTOMATIC_GAIN_CONTROL)) { + LOG("%s: AGC is supported", __func__); + ps |= CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL; + } + if (cubeb_fx_is_available(ctx->jni.get(), CUBEB_FX_NOISE_SUPPRESSOR)) { + LOG("%s: NS is supported", __func__); + ps |= CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION; + } + + *params = static_cast(ps); + return CUBEB_OK; +} + extern "C" int aaudio_init(cubeb ** context, char const * context_name); @@ -1750,9 +1780,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 +1831,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); -- cgit v1.2.3