From 1e344f25b155c519f6488ba2c745801cefe09790 Mon Sep 17 00:00:00 2001 From: Aniket Kumar Lata Date: Wed, 19 Jun 2019 17:09:01 -0700 Subject: [PATCH] hal: Update VoIP output calculations for stereo channels HAL assumes VoIP output supports mono configuration only. Buffer size, period calculations do not account for channels. At present, if VoIP is opened with stereo channels, buffer size returned to framework is incorrect. Update buffer size and period size calculations for VoIP output for stereo channel configuration. Change-Id: Ib30dde389c1a93fcfe8b0f68d50f2f2327f20489 --- hal/audio_hw.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hal/audio_hw.c b/hal/audio_hw.c index a8f3ad84..931f8e7c 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -4109,8 +4109,6 @@ static size_t out_get_buffer_size(const struct audio_stream *stream) return out->compr_config.fragment_size; } else if(out->usecase == USECASE_COMPRESS_VOIP_CALL) return voice_extn_compress_voip_out_get_buffer_size(out); - else if(out->usecase == USECASE_AUDIO_PLAYBACK_VOIP) - return VOIP_IO_BUF_SIZE(out->config.rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE); else if (is_offload_usecase(out->usecase) && out->flags == AUDIO_OUTPUT_FLAG_DIRECT) return out->hal_fragment_size; @@ -6169,8 +6167,6 @@ static size_t in_get_buffer_size(const struct audio_stream *stream) if(in->usecase == USECASE_COMPRESS_VOIP_CALL) return voice_extn_compress_voip_in_get_buffer_size(in); - else if(in->usecase == USECASE_AUDIO_RECORD_VOIP) - return VOIP_IO_BUF_SIZE(in->config.rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE); else if(audio_extn_compr_cap_usecase_supported(in->usecase)) return audio_extn_compr_cap_get_buffer_size(in->config.format); else if(audio_extn_cin_attached_usecase(in->usecase)) @@ -7282,8 +7278,17 @@ int adev_open_output_stream(struct audio_hw_device *dev, out->volume_r = INVALID_OUT_VOLUME; out->config = default_pcm_config_voip_copp; - out->config.period_size = VOIP_IO_BUF_SIZE(out->sample_rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE)/2; out->config.rate = out->sample_rate; + uint32_t channel_count = + audio_channel_count_from_out_mask(out->channel_mask); + uint32_t buffer_size = get_stream_buffer_size(DEFAULT_VOIP_BUF_DURATION_MS, + out->sample_rate, out->format, + channel_count, false); + uint32_t frame_size = audio_bytes_per_sample(out->format) * channel_count; + if (frame_size != 0) + out->config.period_size = buffer_size / frame_size; + else + ALOGW("%s: frame size is 0 for format %#x", __func__, out->format); } } else { if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION ||