From 2d415996e076d531be92a04b15ff4dc41433fb63 Mon Sep 17 00:00:00 2001 From: juyuchen Date: Fri, 16 Nov 2018 14:15:16 +0800 Subject: [PATCH] audio: Enhance latency and tuning in voice call with hearing aid 1. Reduce microphone latency in voice call 2. Use specific acdb tuning Bug: 120869034 Test: manual audio test Change-Id: Ifabd1ce2cce5bb4285cc33cd792070c0c3b20f1a Signed-off-by: juyuchen (cherry picked from commit d194b43135d3799610a0272902b256c6bd95fa9e) --- hal/audio_hw.c | 15 +++++++++++++-- hal/msm8974/platform.c | 19 ++++++++++++++++++- hal/msm8974/platform.h | 2 ++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 9510ea19..0a0fc1c2 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -2258,7 +2258,8 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id) (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) || ((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) && (usecase->devices & AUDIO_DEVICE_IN_ALL_CODEC_BACKEND)) || - (usecase->devices == AUDIO_DEVICE_IN_VOICE_CALL))) { + (vc_usecase->devices == AUDIO_DEVICE_OUT_HEARING_AID) || + (usecase->devices == AUDIO_DEVICE_IN_VOICE_CALL))) { in_snd_device = vc_usecase->in_snd_device; out_snd_device = vc_usecase->out_snd_device; } @@ -2335,6 +2336,10 @@ int select_devices(struct audio_device *adev, audio_usecase_t uc_id) platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE); } else if (usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY) { out_device = AUDIO_DEVICE_OUT_TELEPHONY_TX; + } else { + /* forcing speaker o/p device to get matching i/p pair + in case o/p is not routed from same primary HAL */ + out_device = AUDIO_DEVICE_OUT_SPEAKER; } in_snd_device = platform_get_input_snd_device(adev->platform, out_device); } @@ -3186,13 +3191,19 @@ static int stop_output_stream(struct stream_out *out) ALOGE("%s: audio_extn_ip_hdlr_intf_close failed %d",__func__, ret); } + /* 1) media + voip output routing to handset must route media back to + speaker when voip stops. + 2) trigger voip input to reroute when voip output changes to + hearing aid. */ if (has_voip_usecase || out->devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) { struct listnode *node; struct audio_usecase *usecase; list_for_each(node, &adev->usecase_list) { usecase = node_to_item(node, struct audio_usecase, list); - if (usecase->type == PCM_CAPTURE || usecase == uc_info) + if ((usecase->type == PCM_CAPTURE && + usecase->id != USECASE_AUDIO_RECORD_VOIP) + || usecase == uc_info) continue; ALOGD("%s: select_devices at usecase(%d: %s) after removing the usecase(%d: %s)", diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c index 095028d5..7ba8ae7f 100644 --- a/hal/msm8974/platform.c +++ b/hal/msm8974/platform.c @@ -551,6 +551,7 @@ static const char * const device_table[SND_DEVICE_MAX] = { [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO] = "wsa-speaker-and-bt-sco", [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_WB] = "wsa-speaker-and-bt-sco-wb", [SND_DEVICE_OUT_SPEAKER_WSA_AND_BT_SCO_SWB] = "wsa-speaker-and-bt-sco-wb", + [SND_DEVICE_OUT_VOICE_HEARING_AID] = "hearing-aid", /* Capture sound devices */ [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", @@ -682,6 +683,7 @@ static const char * const device_table[SND_DEVICE_MAX] = { [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset", [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker", [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones", + [SND_DEVICE_IN_VOICE_HEARING_AID] = "hearing-aid-mic", }; // Platform specific backend bit width table @@ -802,6 +804,7 @@ static int acdb_device_table[SND_DEVICE_MAX] = { [SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_PROTECTED] = 124, [SND_DEVICE_OUT_SPEAKER_PROTECTED_RAS] = 134, [SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT_RAS] = 134, + [SND_DEVICE_OUT_VOICE_HEARING_AID] = 45, [SND_DEVICE_IN_HANDSET_MIC] = 4, [SND_DEVICE_IN_HANDSET_MIC_SB] = 163, [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4, @@ -928,6 +931,7 @@ static int acdb_device_table[SND_DEVICE_MAX] = { [SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = 4, [SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = 4, [SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = 4, + [SND_DEVICE_IN_VOICE_HEARING_AID] = 44, }; struct name_to_index { @@ -1022,6 +1026,7 @@ static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = { {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)}, {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)}, {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)}, + {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEARING_AID)}, {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)}, {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_SB)}, {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)}, @@ -1118,6 +1123,7 @@ static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = { {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)}, {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)}, {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)}, + {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEARING_AID)}, {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)}, {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)}, {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_QMIC_FLUENCE)}, @@ -1992,6 +1998,7 @@ static void set_platform_defaults(struct platform_data * my_data) backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES] = strdup("speaker-and-headphones"); backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET] = strdup("speaker-and-headphones"); backend_tag_table[SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET] = strdup("speaker-and-headphones"); + backend_tag_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("hearing-aid"); hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX"); hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX"); @@ -2077,6 +2084,10 @@ static void set_platform_defaults(struct platform_data * my_data) hw_interface_table[SND_DEVICE_OUT_SPEAKER_WSA] = strdup("SLIMBUS_0_RX"); hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = strdup("SLIMBUS_0_RX"); hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_2_WSA] = strdup("SLIMBUS_0_RX"); + /* So far, primary hal doesn't support hearing aid device. + Need snd_device to route voice call and use specific acdb tuning. + Also, BT_RX is a virtual port to indicate bluetooth hearing aid. */ + hw_interface_table[SND_DEVICE_OUT_VOICE_HEARING_AID] = strdup("BT_RX"), hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX"); hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_SB] = strdup("SLIMBUS_0_TX"); hw_interface_table[SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = strdup("SLIMBUS_0_TX"); @@ -2202,6 +2213,7 @@ static void set_platform_defaults(struct platform_data * my_data) hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE] = strdup("SLIMBUS_0_TX"); hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE] = strdup("SLIMBUS_0_TX"); hw_interface_table[SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT] = strdup("SLIMBUS_0_TX"); + hw_interface_table[SND_DEVICE_IN_VOICE_HEARING_AID] = strdup("SLIMBUS_0_TX"); my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT; /*remove ALAC & APE from DSP decoder list based on software decoder availability*/ @@ -5373,8 +5385,11 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o snd_device = SND_DEVICE_OUT_ANC_HANDSET; else snd_device = SND_DEVICE_OUT_VOICE_HANDSET; - } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) + } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX) { snd_device = SND_DEVICE_OUT_VOICE_TX; + } else if (devices & AUDIO_DEVICE_OUT_HEARING_AID) { + snd_device = SND_DEVICE_OUT_VOICE_HEARING_AID; + } if (snd_device != SND_DEVICE_NONE) { goto exit; @@ -5910,6 +5925,8 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d } else { snd_device = SND_DEVICE_IN_HANDSET_MIC; } + } else if (out_device & AUDIO_DEVICE_OUT_HEARING_AID) { + snd_device = SND_DEVICE_IN_VOICE_HEARING_AID; } } else if (my_data->use_generic_handset == true && // system prop is enabled (my_data->source_mic_type & SOURCE_QUAD_MIC) && // AND 4mic is available diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h index 41aa3465..7399d1bb 100644 --- a/hal/msm8974/platform.h +++ b/hal/msm8974/platform.h @@ -173,6 +173,7 @@ enum { SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_HEADPHONES, SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_HEADSET, SND_DEVICE_OUT_VOICE_SPEAKER_STEREO_AND_VOICE_ANC_FB_HEADSET, + SND_DEVICE_OUT_VOICE_HEARING_AID, SND_DEVICE_OUT_END, /* @@ -308,6 +309,7 @@ enum { SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE, SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE, SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT, + SND_DEVICE_IN_VOICE_HEARING_AID, SND_DEVICE_IN_END, SND_DEVICE_MAX = SND_DEVICE_IN_END,