From bfb0a2890ee4463b723c3221574007c5fa7e6c9e Mon Sep 17 00:00:00 2001 From: Anton Dehtiarov Date: Mon, 25 May 2020 21:16:46 +0300 Subject: [PATCH 1/2] audio: add get_micropones() function The Google VTS tests for Android VtsHalAudioV5_0Target(GetMicrophonesTest) needs to use pointer of function (*get_micropones)() which is not initialized and function adev_get_microphones() required for initialization witch is not implemented in tinyhal. The analysis of the implementation of the audio hal for Qualcomm (https://android.googlesource.com/platform/hardware/qcom/audio/+/refs/heads/ master/hal/audio_hw.c) and Goldfish (https://android.googlesource.com/device/generic/goldfish/+/dc18a59%5E%21/) have been made. The implementation similar to Goldfish(stub) has been chosen as basic. Function adev_get_microphones() was implemented as stub function that will expand in the future. This function fill array audio_microphone_characteristic_t with default microphone information. Signed-off-by: Anton Dehtiarov --- audio/audio_hw.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/audio/audio_hw.c b/audio/audio_hw.c index 6dd6beb..52dc1dd 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -2036,6 +2036,50 @@ static int do_init_in_pcm(struct stream_in_pcm *in, return 0; } +#ifdef AUDIO_DEVICE_API_VERSION_5_0 +static int adev_get_microphones(const struct audio_hw_device *dev, + struct audio_microphone_characteristic_t *mic_array, + size_t *mic_count) +{ + if (mic_count == NULL) { + return -ENOSYS; + } + + if (*mic_count == 0) { + *mic_count = 1; + return 0; + } + + if (mic_array == NULL) { + return -ENOSYS; + } + + strncpy(mic_array->device_id, "mic_generic", AUDIO_MICROPHONE_ID_MAX_LEN - 1); + mic_array->device = AUDIO_DEVICE_IN_BUILTIN_MIC; + strncpy(mic_array->address, AUDIO_BOTTOM_MICROPHONE_ADDRESS, + AUDIO_DEVICE_MAX_ADDRESS_LEN - 1); + memset(mic_array->channel_mapping, AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED, + sizeof(mic_array->channel_mapping)); + mic_array->location = AUDIO_MICROPHONE_LOCATION_UNKNOWN; + mic_array->group = 0; + mic_array->index_in_the_group = 0; + mic_array->sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN; + mic_array->max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN; + mic_array->min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN; + mic_array->directionality = AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN; + mic_array->num_frequency_responses = 0; + mic_array->geometric_location.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; + mic_array->geometric_location.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; + mic_array->geometric_location.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; + mic_array->orientation.x = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; + mic_array->orientation.y = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; + mic_array->orientation.z = AUDIO_MICROPHONE_COORDINATE_UNKNOWN; + + *mic_count = 1; + return 0; +} +#endif + /********************************************************************* * Stream open and close *********************************************************************/ @@ -2344,6 +2388,10 @@ static int adev_open(const hw_module_t *module, const char *name, adev->hw_device.close_input_stream = adev_close_input_stream; adev->hw_device.dump = adev_dump; +#ifdef AUDIO_DEVICE_API_VERSION_5_0 + adev->hw_device.get_microphones = adev_get_microphones; +#endif + property_get("ro.product.device", property, "generic"); snprintf(file_name, sizeof(file_name), "%s/audio.%s.xml", ETC_PATH, property); From b84e993c7fc966af6fd05a778dd3978657e2515e Mon Sep 17 00:00:00 2001 From: Anton Dehtiarov Date: Mon, 25 May 2020 23:14:47 +0300 Subject: [PATCH 2/2] audio: add get_active_micropones() function The Google VTS tests for Android VtsHalAudioV5_0Target(GetMicrophonesTest) needs to use pointer of function (*get_active_micropones)() which is not initialized and function in_get_active_microphones() required for initialization witch is not implemented in tinyhal. The analysis of the implementation of the audio hal for Qualcomm (https://android.googlesource.com/platform/hardware/qcom/audio/+/refs/heads/ master/hal/audio_hw.c) and Goldfish (https://android.googlesource.com/device/generic/goldfish/+/dc18a59%5E%21/) have been made. The implementation similar to Goldfish(stub) has been chosen as basic. Function in_get_active_microphones() was implemented as stub function that will expand in the future. This function fill array audio_microphone_characteristic_t with default microphone information. Signed-off-by: Anton Dehtiarov --- audio/audio_hw.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/audio/audio_hw.c b/audio/audio_hw.c index 52dc1dd..0dd01cb 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -2080,6 +2080,14 @@ static int adev_get_microphones(const struct audio_hw_device *dev, } #endif +#ifdef AUDIO_DEVICE_API_VERSION_5_0 +static int in_get_active_microphones(const struct audio_stream_in *stream, + struct audio_microphone_characteristic_t *mic_array, + size_t *mic_count) { + return adev_get_microphones(NULL, mic_array, mic_count); +} +#endif + /********************************************************************* * Stream open and close *********************************************************************/ @@ -2222,6 +2230,10 @@ static int adev_open_input_stream(struct audio_hw_device *dev, in->common.dev = adev; +#ifdef AUDIO_DEVICE_API_VERSION_5_0 + in->common.stream.get_active_microphones = in_get_active_microphones; +#endif + devices &= AUDIO_DEVICE_IN_ALL; ret = do_init_in_common(&in->common, config, devices); if (ret < 0) {