From 130da9f065ce68a5ec34542bfa6998ae6d14706c Mon Sep 17 00:00:00 2001 From: "Christopher N. Hesse" Date: Wed, 15 Feb 2017 12:18:41 +0100 Subject: [PATCH] audio: Cleanup and fix voicecall preparation * if (usecase == NULL) should actually be if (vc_usecase == NULL) * Avoid unnecessary if-block indentation by updating the control flow Change-Id: If00ac405a1eac429862b953580e8614227015134 --- audio/audio_hw.c | 72 ++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/audio/audio_hw.c b/audio/audio_hw.c index d0aa3dc8..f0bfff07 100644 --- a/audio/audio_hw.c +++ b/audio/audio_hw.c @@ -905,48 +905,48 @@ static int select_devices(struct audio_device *adev, } active_out = (struct stream_out *)usecase->stream; + + /* + * If the voice call is active, use the sound devices of voice call usecase + * so that it would not result any device switch. All the usecases will + * be switched to new device when select_devices() is called for voice call + * usecase. + */ + if (usecase->type != VOICE_CALL && adev->voice.in_call) { + vc_usecase = get_usecase_from_id(adev, USECASE_VOICE_CALL); + if (vc_usecase == NULL) { + ALOGE("%s: Could not find the voice call usecase", __func__); + } else { + in_snd_device = vc_usecase->in_snd_device; + out_snd_device = vc_usecase->out_snd_device; + } + } + if (usecase->type == VOICE_CALL) { - out_snd_device = get_output_snd_device(adev, active_out->devices); + usecase->devices = active_out->devices; prepare_voice_session(adev->voice.session, active_out->devices); + out_snd_device = get_output_snd_device(adev, active_out->devices); in_snd_device = get_input_snd_device(adev, active_out->devices); + } else if (usecase->type == PCM_PLAYBACK) { usecase->devices = active_out->devices; - } else { - /* - * If the voice call is active, use the sound devices of voice call usecase - * so that it would not result any device switch. All the usecases will - * be switched to new device when select_devices() is called for voice call - * usecase. - */ - if (adev->voice.in_call) { - vc_usecase = get_usecase_from_id(adev, USECASE_VOICE_CALL); - if (usecase == NULL) { - ALOGE("%s: Could not find the voice call usecase", __func__); - } else { - in_snd_device = vc_usecase->in_snd_device; - out_snd_device = vc_usecase->out_snd_device; + in_snd_device = SND_DEVICE_NONE; + if (out_snd_device == SND_DEVICE_NONE) { + out_snd_device = get_output_snd_device(adev, active_out->devices); + if (active_out == adev->primary_output && + active_input && + active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) { + select_devices(adev, active_input->usecase); } } - if (usecase->type == PCM_PLAYBACK) { - usecase->devices = active_out->devices; - in_snd_device = SND_DEVICE_NONE; - if (out_snd_device == SND_DEVICE_NONE) { - out_snd_device = get_output_snd_device(adev, active_out->devices); - if (active_out == adev->primary_output && - active_input && - active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) { - select_devices(adev, active_input->usecase); - } - } - } else if (usecase->type == PCM_CAPTURE) { - usecase->devices = ((struct stream_in *)usecase->stream)->devices; - out_snd_device = SND_DEVICE_NONE; - if (in_snd_device == SND_DEVICE_NONE) { - if (active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION && - adev->primary_output && !adev->primary_output->standby) { - in_snd_device = get_input_snd_device(adev, adev->primary_output->devices); - } else { - in_snd_device = get_input_snd_device(adev, AUDIO_DEVICE_NONE); - } + } else if (usecase->type == PCM_CAPTURE) { + usecase->devices = ((struct stream_in *)usecase->stream)->devices; + out_snd_device = SND_DEVICE_NONE; + if (in_snd_device == SND_DEVICE_NONE) { + if (active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION && + adev->primary_output && !adev->primary_output->standby) { + in_snd_device = get_input_snd_device(adev, adev->primary_output->devices); + } else { + in_snd_device = get_input_snd_device(adev, AUDIO_DEVICE_NONE); } } }