diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2021-02-21 12:50:24 -0800 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2021-02-21 12:50:24 -0800 |
commit | 9551282c74eb05610cdf6f2dc0a65ea1689d4577 (patch) | |
tree | fada6e96199a23797ef848c57ef28f507ccc212f | |
parent | 863691131ceb8b87e2567f4acaae05a0e3b6f0b9 (diff) | |
parent | 88bb65c9b6f7a96d035985d6f435d9ae3e936cb4 (diff) |
Merge 88bb65c9b6f7a96d035985d6f435d9ae3e936cb4 on remote branch
Change-Id: I78dca18aaaeb6ac5791e1321324ac51a0dba8e4a
-rw-r--r-- | hal/audio_extn/utils.c | 12 | ||||
-rw-r--r-- | hal/audio_hw.c | 81 |
2 files changed, 63 insertions, 30 deletions
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c index 97742c76..0ba2f4f8 100644 --- a/hal/audio_extn/utils.c +++ b/hal/audio_extn/utils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2021, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright (C) 2014 The Android Open Source Project @@ -1159,9 +1159,6 @@ int audio_extn_utils_get_app_sample_rate_for_device( if (usecase->id == USECASE_AUDIO_PLAYBACK_VOIP) { usecase->stream.out->app_type_cfg.sample_rate = usecase->stream.out->sample_rate; - } else if (compare_device_type(&usecase->stream.out->device_list, - AUDIO_DEVICE_OUT_SPEAKER)) { - usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; } else if ((snd_device == SND_DEVICE_OUT_HDMI || snd_device == SND_DEVICE_OUT_USB_HEADSET || snd_device == SND_DEVICE_OUT_DISPLAY_PORT) && @@ -1180,9 +1177,7 @@ int audio_extn_utils_get_app_sample_rate_for_device( (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { /* Reset to default if no native stream is active*/ usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; - } else if (usecase->out_snd_device == SND_DEVICE_OUT_BT_A2DP || - usecase->out_snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP || - usecase->out_snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP) { + } else if (snd_device == SND_DEVICE_OUT_BT_A2DP) { /* * For a2dp playback get encoder sampling rate and set copp sampling rate, * for bit width use the stream param only. @@ -1190,6 +1185,9 @@ int audio_extn_utils_get_app_sample_rate_for_device( audio_extn_a2dp_get_enc_sample_rate(&usecase->stream.out->app_type_cfg.sample_rate); ALOGI("%s using %d sample rate rate for A2DP CoPP", __func__, usecase->stream.out->app_type_cfg.sample_rate); + } else if (compare_device_type(&usecase->stream.out->device_list, + AUDIO_DEVICE_OUT_SPEAKER)) { + usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; } audio_extn_btsco_get_sample_rate(snd_device, &usecase->stream.out->app_type_cfg.sample_rate); sample_rate = usecase->stream.out->app_type_cfg.sample_rate; diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 7c732456..9b29a219 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -3157,7 +3157,7 @@ int start_input_stream(struct stream_in *in) } if (is_sco_in_device_type(&in->device_list)) { - if (!adev->bt_sco_on) { + if (!adev->bt_sco_on || audio_extn_a2dp_source_is_ready()) { ALOGE("%s: SCO profile is not ready, return error", __func__); ret = -EIO; goto error_config; @@ -8747,7 +8747,30 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) /* When set to false, HAL should disable EC and NS */ if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0){ adev->bt_sco_on = true; - } else { + /* + * When ever BT_SCO=ON arrives, make sure to route + * all use cases to SCO device, otherwise due to delay in + * BT_SCO=ON and lack of synchronization with create audio patch + * request for SCO device, some times use case not routed properly to + * SCO device + */ + struct audio_usecase *usecase; + struct listnode *node; + list_for_each(node, &adev->usecase_list) { + usecase = node_to_item(node, struct audio_usecase, list); + if (usecase->stream.in && (usecase->type == PCM_CAPTURE) && + (!is_btsco_device(SND_DEVICE_NONE, usecase->in_snd_device))) { + ALOGD("BT_SCO ON, switch all in use case to it"); + select_devices(adev, usecase->id); + } + if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) && + (!is_btsco_device(usecase->out_snd_device, SND_DEVICE_NONE))) { + ALOGD("BT_SCO ON, switch all out use case to it"); + select_devices(adev, usecase->id); + } + } + } + else { adev->bt_sco_on = false; audio_extn_sco_reset_configuration(); } @@ -9560,6 +9583,10 @@ static int adev_open_input_stream(struct audio_hw_device *dev, in->config.period_count = VOIP_CAPTURE_PERIOD_COUNT; in->config.rate = config->sample_rate; in->af_period_multiplier = 1; + } else if (in->realtime) { + in->config = pcm_config_audio_capture_rt; + in->config.format = pcm_format_from_audio_format(config->format); + in->af_period_multiplier = af_period_multiplier; } else { int ret_val; pthread_mutex_lock(&adev->lock); @@ -10365,9 +10392,9 @@ static void adev_snd_mon_cb(void *cookie, struct str_parms *parms) int check_a2dp_restore_l(struct audio_device *adev, struct stream_out *out, bool restore) { struct audio_usecase *uc_info; - float left_p; - float right_p; + struct audio_usecase *usecase; struct listnode devices; + struct listnode *node; uc_info = get_usecase_from_list(adev, out->usecase); if (uc_info == NULL) { @@ -10403,34 +10430,42 @@ int check_a2dp_restore_l(struct audio_device *adev, struct stream_out *out, bool pthread_mutex_lock(&out->latch_lock); // mute stream and switch to speaker if suspended if (!out->a2dp_muted && !out->standby) { - ALOGD("%s: selecting speaker and muting stream", __func__); assign_devices(&devices, &out->device_list); reassign_device_list(&out->device_list, AUDIO_DEVICE_OUT_SPEAKER, ""); - left_p = out->volume_l; - right_p = out->volume_r; - out->a2dp_muted = true; - if (is_offload_usecase(out->usecase)) { - if (out->offload_state == OFFLOAD_STATE_PLAYING) - compress_pause(out->compr); - out_set_compr_volume(&out->stream, (float)0, (float)0); - } else if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP) { - out_set_voip_volume(&out->stream, (float)0, (float)0); - } else { - out_set_pcm_volume(&out->stream, (float)0, (float)0); - /* wait for stale pcm drained before switching to speaker */ - uint32_t latency = - (out->config.period_count * out->config.period_size * 1000) / - (out->config.rate); - usleep(latency * 1000); + list_for_each(node, &adev->usecase_list) { + usecase = node_to_item(node, struct audio_usecase, list); + if ((usecase != uc_info) && + platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, + usecase->out_snd_device)) { + assign_devices(&out->device_list, &usecase->stream.out->device_list); + break; + } + } + if (uc_info->out_snd_device == SND_DEVICE_OUT_BT_A2DP) { + out->a2dp_muted = true; + if (is_offload_usecase(out->usecase)) { + if (out->offload_state == OFFLOAD_STATE_PLAYING) + compress_pause(out->compr); + out_set_compr_volume(&out->stream, (float)0, (float)0); + } else if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP) { + out_set_voip_volume(&out->stream, (float)0, (float)0); + } else { + out_set_pcm_volume(&out->stream, (float)0, (float)0); + /* wait for stale pcm drained before switching to speaker */ + uint32_t latency = + (out->config.period_count * out->config.period_size * 1000) / + (out->config.rate); + usleep(latency * 1000); + } } select_devices(adev, out->usecase); + ALOGD("%s: switched to device:%s and stream muted:%d", __func__, + platform_get_snd_device_name(uc_info->out_snd_device), out->a2dp_muted); if (is_offload_usecase(out->usecase)) { if (out->offload_state == OFFLOAD_STATE_PLAYING) compress_resume(out->compr); } assign_devices(&out->device_list, &devices); - out->volume_l = left_p; - out->volume_r = right_p; } pthread_mutex_unlock(&out->latch_lock); } |