hal: fix trailing sound heard during a2dp codec switch
When a2dp reconfig comes for pcm offload usecase, path
can be disabled without switching to speaker, which
leads cached PCM data rendered out after switching to
new codec, so trailing sound can be heard first and then
followed with mute, and finally when unmute is issued,
the mute period can sound like a glitch.
Change-Id: I8dc4349d0cb334252f1f9bbb27713e71a0bc7fb3
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index f4b39fb..9321477 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3827,7 +3827,7 @@
if (is_speaker_active || is_speaker_safe_active) {
a2dp_combo = true;
} else {
- if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
+ if (!is_offload_usecase(out->usecase)) {
ALOGE("%s: A2DP profile is not ready, return error", __func__);
ret = -EAGAIN;
goto error_config;
@@ -4979,7 +4979,7 @@
platform_set_swap_channels(adev, true);
audio_extn_perf_lock_release(&adev->perf_lock_handle);
}
- if ((out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
+ if (is_offload_usecase(out->usecase) &&
(!is_a2dp_out_device_type(&out->device_list) || audio_extn_a2dp_source_is_ready())) {
pthread_mutex_lock(&out->latch_lock);
if (out->a2dp_compress_mute) {
@@ -5852,7 +5852,7 @@
(audio_extn_a2dp_source_is_suspended())) {
if (!(compare_device_type(&out->device_list, AUDIO_DEVICE_OUT_SPEAKER) ||
compare_device_type(&out->device_list, AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
- if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
+ if (!is_offload_usecase(out->usecase)) {
ret = -EIO;
goto exit;
}
@@ -8905,7 +8905,7 @@
pthread_mutex_unlock(&usecase->stream.out->latch_lock);
audio_extn_a2dp_set_handoff_mode(false);
break;
- } else if (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
+ } else if (is_offload_usecase(usecase->stream.out->usecase)) {
pthread_mutex_lock(&usecase->stream.out->latch_lock);
if (usecase->stream.out->a2dp_compress_mute) {
pthread_mutex_unlock(&usecase->stream.out->latch_lock);
@@ -10367,7 +10367,7 @@
ALOGD("%s: restoring A2dp and unmuting stream", __func__);
if (uc_info->out_snd_device != SND_DEVICE_OUT_BT_A2DP)
select_devices(adev, uc_info->id);
- if ((out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
+ if (is_offload_usecase(out->usecase) &&
(uc_info->out_snd_device == SND_DEVICE_OUT_BT_A2DP)) {
if (out->a2dp_compress_mute) {
out->a2dp_compress_mute = false;
@@ -10379,7 +10379,7 @@
pthread_mutex_unlock(&out->latch_lock);
} else {
pthread_mutex_lock(&out->latch_lock);
- if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
+ if (is_offload_usecase(out->usecase)) {
// mute compress stream if suspended
if (!out->a2dp_compress_mute && !out->standby) {
ALOGD("%s: selecting speaker and muting stream", __func__);