2013-10-01 22:49:05 +00:00
|
|
|
/*
|
2018-12-18 22:23:57 +00:00
|
|
|
* Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
|
2013-10-01 22:49:05 +00:00
|
|
|
* Not a contribution.
|
|
|
|
*
|
2014-01-10 23:56:19 +00:00
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
2013-10-01 22:49:05 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "voice"
|
|
|
|
/*#define LOG_NDEBUG 0*/
|
|
|
|
#define LOG_NDDEBUG 0
|
|
|
|
|
|
|
|
#include <errno.h>
|
2015-06-18 10:28:55 +00:00
|
|
|
#include <stdlib.h>
|
2013-10-01 22:49:05 +00:00
|
|
|
#include <math.h>
|
2018-12-18 22:23:57 +00:00
|
|
|
#include <log/log.h>
|
2013-10-01 22:49:05 +00:00
|
|
|
#include <cutils/str_parms.h>
|
|
|
|
|
|
|
|
#include "audio_hw.h"
|
|
|
|
#include "voice.h"
|
|
|
|
#include "voice_extn/voice_extn.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "platform_api.h"
|
2013-10-29 20:29:42 +00:00
|
|
|
#include "audio_extn.h"
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2017-05-18 11:43:33 +00:00
|
|
|
#ifdef DYNAMIC_LOG_ENABLED
|
|
|
|
#include <log_xml_parser.h>
|
|
|
|
#define LOG_MASK HAL_MOD_FILE_VOICE
|
|
|
|
#include <log_utils.h>
|
|
|
|
#endif
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
struct pcm_config pcm_config_voice_call = {
|
|
|
|
.channels = 1,
|
|
|
|
.rate = 8000,
|
|
|
|
.period_size = 160,
|
|
|
|
.period_count = 2,
|
|
|
|
.format = PCM_FORMAT_S16_LE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
|
|
|
|
audio_usecase_t usecase_id)
|
|
|
|
{
|
|
|
|
struct voice_session *session = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
|
|
|
|
if (ret == -ENOSYS) {
|
|
|
|
session = &adev->voice.session[VOICE_SESS_IDX];
|
|
|
|
}
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2015-06-10 05:23:45 +00:00
|
|
|
static bool voice_is_sidetone_device(snd_device_t out_device,
|
|
|
|
char *mixer_path)
|
|
|
|
{
|
|
|
|
bool is_sidetone_dev;
|
|
|
|
|
|
|
|
switch (out_device) {
|
|
|
|
case SND_DEVICE_OUT_VOICE_HANDSET:
|
|
|
|
is_sidetone_dev = true;
|
|
|
|
strlcpy(mixer_path, "sidetone-handset", MIXER_PATH_MAX_LENGTH);
|
|
|
|
break;
|
|
|
|
case SND_DEVICE_OUT_VOICE_HEADPHONES:
|
2019-04-30 06:28:43 +00:00
|
|
|
case SND_DEVICE_OUT_VOICE_HEADSET:
|
2015-06-10 05:23:45 +00:00
|
|
|
case SND_DEVICE_OUT_VOICE_ANC_HEADSET:
|
|
|
|
case SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET:
|
|
|
|
is_sidetone_dev = true;
|
|
|
|
strlcpy(mixer_path, "sidetone-headphones", MIXER_PATH_MAX_LENGTH);
|
|
|
|
break;
|
2018-12-18 22:23:57 +00:00
|
|
|
case SND_DEVICE_OUT_VOICE_USB_HEADSET:
|
2016-05-24 22:21:56 +00:00
|
|
|
case SND_DEVICE_OUT_USB_HEADSET:
|
2018-12-18 22:23:57 +00:00
|
|
|
// USB does not use a QC mixer.
|
|
|
|
mixer_path[0] = '\0';
|
2016-05-24 22:21:56 +00:00
|
|
|
is_sidetone_dev = true;
|
|
|
|
break;
|
2015-06-10 05:23:45 +00:00
|
|
|
default:
|
2018-12-18 22:23:57 +00:00
|
|
|
ALOGW("%s: %d is not a sidetone device", __func__, out_device);
|
2015-06-10 05:23:45 +00:00
|
|
|
is_sidetone_dev = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_sidetone_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void voice_set_sidetone(struct audio_device *adev,
|
|
|
|
snd_device_t out_snd_device, bool enable)
|
|
|
|
{
|
|
|
|
char mixer_path[MIXER_PATH_MAX_LENGTH];
|
|
|
|
ALOGD("%s: %s, out_snd_device: %d\n",
|
|
|
|
__func__, (enable ? "enable" : "disable"),
|
|
|
|
out_snd_device);
|
2016-05-24 22:21:56 +00:00
|
|
|
if (voice_is_sidetone_device(out_snd_device, mixer_path))
|
|
|
|
platform_set_sidetone(adev, out_snd_device, enable, mixer_path);
|
2015-06-10 05:23:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-31 16:05:59 +00:00
|
|
|
static bool voice_is_aanc_device(snd_device_t out_device,
|
|
|
|
char *mixer_path)
|
|
|
|
{
|
|
|
|
bool is_aanc_dev;
|
|
|
|
|
|
|
|
switch (out_device) {
|
|
|
|
case SND_DEVICE_OUT_ANC_HANDSET:
|
|
|
|
is_aanc_dev = true;
|
|
|
|
strlcpy(mixer_path, "aanc-path", MIXER_PATH_MAX_LENGTH);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
is_aanc_dev = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_aanc_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void voice_check_and_update_aanc_path(struct audio_device *adev,
|
|
|
|
snd_device_t out_snd_device,
|
|
|
|
bool enable)
|
|
|
|
{
|
|
|
|
char mixer_path[MIXER_PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
ALOGV("%s: %s, out_snd_device: %d\n",
|
|
|
|
__func__, (enable ? "enable" : "disable"), out_snd_device);
|
|
|
|
|
|
|
|
if (voice_is_aanc_device(out_snd_device, mixer_path))
|
|
|
|
platform_update_aanc_path(adev, out_snd_device, enable, mixer_path);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:24:38 +00:00
|
|
|
int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
|
2013-10-01 22:49:05 +00:00
|
|
|
{
|
2016-04-14 13:35:23 +00:00
|
|
|
int ret = 0;
|
2013-10-01 22:49:05 +00:00
|
|
|
struct audio_usecase *uc_info;
|
|
|
|
struct voice_session *session = NULL;
|
|
|
|
|
2013-11-05 20:49:15 +00:00
|
|
|
ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
|
|
|
session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
|
hal: miscellaneous fixes
Fixes for the following issues reported by KW
21725, 21726, 21727, 21737, 21738, 21739, 21740, 21750,
21751, 21752, 25317, 30602, 32620, 36778, 41817, 41819,
50942, 54468, 54470, 54479, 55569, 54481, 55570, 55571,
58485, 85112, 85122, 85123
Change-Id: I9abef07db7ccdc19789a201eb268a97e1b360cad
2014-06-30 20:56:18 +00:00
|
|
|
if (!session) {
|
|
|
|
ALOGE("stop_call: couldn't find voice session");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-06-10 05:23:45 +00:00
|
|
|
uc_info = get_usecase_from_list(adev, usecase_id);
|
|
|
|
if (uc_info == NULL) {
|
|
|
|
ALOGE("%s: Could not find the usecase (%d) in the list",
|
|
|
|
__func__, usecase_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
session->state.current = CALL_INACTIVE;
|
|
|
|
|
2015-06-10 05:23:45 +00:00
|
|
|
/* Disable sidetone only when no calls are active */
|
|
|
|
if (!voice_is_call_state_active(adev))
|
|
|
|
voice_set_sidetone(adev, uc_info->out_snd_device, false);
|
|
|
|
|
2016-10-31 16:05:59 +00:00
|
|
|
/* Disable aanc only when no calls are active */
|
|
|
|
if (!voice_is_call_state_active(adev))
|
|
|
|
voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, false);
|
|
|
|
|
2013-11-13 19:46:52 +00:00
|
|
|
ret = platform_stop_voice_call(adev->platform, session->vsid);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
|
|
|
/* 1. Close the PCM devices */
|
|
|
|
if (session->pcm_rx) {
|
|
|
|
pcm_close(session->pcm_rx);
|
|
|
|
session->pcm_rx = NULL;
|
|
|
|
}
|
|
|
|
if (session->pcm_tx) {
|
|
|
|
pcm_close(session->pcm_tx);
|
|
|
|
session->pcm_tx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2. Get and set stream specific mixer controls */
|
2014-04-24 18:55:48 +00:00
|
|
|
disable_audio_route(adev, uc_info);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
|
|
|
/* 3. Disable the rx and tx devices */
|
2014-04-24 18:55:48 +00:00
|
|
|
disable_snd_device(adev, uc_info->out_snd_device);
|
|
|
|
disable_snd_device(adev, uc_info->in_snd_device);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
|
|
|
list_remove(&uc_info->list);
|
|
|
|
free(uc_info);
|
|
|
|
|
|
|
|
ALOGD("%s: exit: status(%d)", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:24:38 +00:00
|
|
|
int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id)
|
2013-10-01 22:49:05 +00:00
|
|
|
{
|
2016-04-14 13:35:23 +00:00
|
|
|
int ret = 0;
|
2013-10-01 22:49:05 +00:00
|
|
|
struct audio_usecase *uc_info;
|
|
|
|
int pcm_dev_rx_id, pcm_dev_tx_id;
|
2014-02-24 06:04:44 +00:00
|
|
|
uint32_t sample_rate = 8000;
|
2013-10-01 22:49:05 +00:00
|
|
|
struct voice_session *session = NULL;
|
2013-10-17 18:16:13 +00:00
|
|
|
struct pcm_config voice_config = pcm_config_voice_call;
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2013-11-05 20:49:15 +00:00
|
|
|
ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2013-11-05 20:49:15 +00:00
|
|
|
session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
|
hal: miscellaneous fixes
Fixes for the following issues reported by KW
21725, 21726, 21727, 21737, 21738, 21739, 21740, 21750,
21751, 21752, 25317, 30602, 32620, 36778, 41817, 41819,
50942, 54468, 54470, 54479, 55569, 54481, 55570, 55571,
58485, 85112, 85122, 85123
Change-Id: I9abef07db7ccdc19789a201eb268a97e1b360cad
2014-06-30 20:56:18 +00:00
|
|
|
if (!session) {
|
|
|
|
ALOGE("start_call: couldn't find voice session");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
|
hal: miscellaneous fixes
Fixes for the following issues reported by KW
21725, 21726, 21727, 21737, 21738, 21739, 21740, 21750,
21751, 21752, 25317, 30602, 32620, 36778, 41817, 41819,
50942, 54468, 54470, 54479, 55569, 54481, 55570, 55571,
58485, 85112, 85122, 85123
Change-Id: I9abef07db7ccdc19789a201eb268a97e1b360cad
2014-06-30 20:56:18 +00:00
|
|
|
if (!uc_info) {
|
|
|
|
ALOGE("start_call: couldn't allocate mem for audio_usecase");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
uc_info->id = usecase_id;
|
|
|
|
uc_info->type = VOICE_CALL;
|
2017-11-15 08:28:55 +00:00
|
|
|
uc_info->stream.out = adev->current_call_output;
|
|
|
|
uc_info->devices = adev->current_call_output->devices;
|
|
|
|
|
|
|
|
if (popcount(uc_info->devices) == 2) {
|
|
|
|
ALOGE("%s: Invalid combo device(%#x) for voice call", __func__,
|
|
|
|
uc_info->devices);
|
|
|
|
ret = -EIO;
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
uc_info->in_snd_device = SND_DEVICE_NONE;
|
|
|
|
uc_info->out_snd_device = SND_DEVICE_NONE;
|
2018-09-12 01:00:09 +00:00
|
|
|
adev->voice.use_device_mute = false;
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2017-09-12 09:02:52 +00:00
|
|
|
if (audio_is_bluetooth_sco_device(uc_info->devices) && !adev->bt_sco_on) {
|
|
|
|
ALOGE("start_call: couldn't find BT SCO, SCO is not ready");
|
|
|
|
adev->voice.in_call = false;
|
|
|
|
ret = -EIO;
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
list_add_tail(&adev->usecase_list, &uc_info->list);
|
|
|
|
|
|
|
|
select_devices(adev, usecase_id);
|
|
|
|
|
|
|
|
pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
|
|
|
|
pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
|
|
|
|
|
|
|
|
if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
|
|
|
|
ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
|
|
|
|
__func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
|
|
|
|
ret = -EIO;
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
2014-02-24 06:04:44 +00:00
|
|
|
ret = platform_get_sample_rate(adev->platform, &sample_rate);
|
|
|
|
if (ret < 0) {
|
|
|
|
ALOGE("platform_get_sample_rate error %d\n", ret);
|
|
|
|
} else {
|
|
|
|
voice_config.rate = sample_rate;
|
|
|
|
}
|
|
|
|
ALOGD("voice_config.rate %d\n", voice_config.rate);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2015-04-10 00:45:20 +00:00
|
|
|
voice_set_mic_mute(adev, adev->voice.mic_mute);
|
|
|
|
|
2015-06-10 05:23:45 +00:00
|
|
|
ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
|
|
|
|
__func__, adev->snd_card, pcm_dev_tx_id);
|
|
|
|
session->pcm_tx = pcm_open(adev->snd_card,
|
|
|
|
pcm_dev_tx_id,
|
|
|
|
PCM_IN, &voice_config);
|
|
|
|
if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
|
|
|
|
ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
|
|
|
|
ret = -EIO;
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
|
2013-12-04 19:57:47 +00:00
|
|
|
__func__, adev->snd_card, pcm_dev_rx_id);
|
|
|
|
session->pcm_rx = pcm_open(adev->snd_card,
|
2013-10-01 22:49:05 +00:00
|
|
|
pcm_dev_rx_id,
|
2013-10-17 18:16:13 +00:00
|
|
|
PCM_OUT, &voice_config);
|
2013-10-01 22:49:05 +00:00
|
|
|
if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
|
|
|
|
ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
|
|
|
|
ret = -EIO;
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
|
|
|
|
2018-02-22 01:12:00 +00:00
|
|
|
if(adev->mic_break_enabled)
|
|
|
|
platform_set_mic_break_det(adev->platform, true);
|
|
|
|
|
2019-05-03 20:52:50 +00:00
|
|
|
ret = pcm_start(session->pcm_tx);
|
|
|
|
if (ret != 0) {
|
|
|
|
ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pcm_start(session->pcm_rx);
|
|
|
|
if (ret != 0) {
|
|
|
|
ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
2015-06-10 05:23:45 +00:00
|
|
|
|
2016-10-31 16:05:59 +00:00
|
|
|
/* Enable aanc only when no calls are active */
|
|
|
|
if (!voice_is_call_state_active(adev))
|
|
|
|
voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, true);
|
|
|
|
|
2015-06-10 05:23:45 +00:00
|
|
|
/* Enable sidetone only when no calls are already active */
|
|
|
|
if (!voice_is_call_state_active(adev))
|
|
|
|
voice_set_sidetone(adev, uc_info->out_snd_device, true);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2013-10-25 21:32:12 +00:00
|
|
|
voice_set_volume(adev, adev->voice.volume);
|
|
|
|
|
2013-11-13 19:46:52 +00:00
|
|
|
ret = platform_start_voice_call(adev->platform, session->vsid);
|
2013-10-01 22:49:05 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
|
|
|
|
goto error_start_voice;
|
|
|
|
}
|
|
|
|
|
|
|
|
session->state.current = CALL_ACTIVE;
|
2014-08-06 01:20:42 +00:00
|
|
|
goto done;
|
2013-10-01 22:49:05 +00:00
|
|
|
|
|
|
|
error_start_voice:
|
2014-08-20 23:24:38 +00:00
|
|
|
voice_stop_usecase(adev, usecase_id);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2014-08-06 01:20:42 +00:00
|
|
|
done:
|
2013-10-01 22:49:05 +00:00
|
|
|
ALOGD("%s: exit: status(%d)", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-08-06 01:20:42 +00:00
|
|
|
bool voice_is_call_state_active(struct audio_device *adev)
|
2013-10-01 22:49:05 +00:00
|
|
|
{
|
2014-08-06 01:20:42 +00:00
|
|
|
bool call_state = false;
|
2013-10-01 22:49:05 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2014-08-06 01:20:42 +00:00
|
|
|
ret = voice_extn_is_call_state_active(adev, &call_state);
|
2013-10-01 22:49:05 +00:00
|
|
|
if (ret == -ENOSYS) {
|
2014-08-06 01:20:42 +00:00
|
|
|
call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
|
2013-10-01 22:49:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 01:20:42 +00:00
|
|
|
return call_state;
|
2013-10-01 22:49:05 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 23:49:38 +00:00
|
|
|
bool voice_is_in_call(const struct audio_device *adev)
|
2014-09-05 20:51:35 +00:00
|
|
|
{
|
|
|
|
return adev->voice.in_call;
|
|
|
|
}
|
|
|
|
|
2016-01-29 23:49:38 +00:00
|
|
|
bool voice_is_in_call_rec_stream(const struct stream_in *in)
|
2014-04-24 10:46:22 +00:00
|
|
|
{
|
|
|
|
bool in_call_rec = false;
|
|
|
|
|
2014-12-08 22:31:39 +00:00
|
|
|
if (!in) {
|
|
|
|
ALOGE("%s: input stream is NULL", __func__);
|
|
|
|
return in_call_rec;
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:00:09 +00:00
|
|
|
if (in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
|
|
|
|
in->source == AUDIO_SOURCE_VOICE_UPLINK ||
|
|
|
|
in->source == AUDIO_SOURCE_VOICE_CALL) {
|
|
|
|
in_call_rec = true;
|
2014-04-24 10:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return in_call_rec;
|
|
|
|
}
|
|
|
|
|
2013-10-17 18:16:13 +00:00
|
|
|
uint32_t voice_get_active_session_id(struct audio_device *adev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
uint32_t session_id;
|
|
|
|
|
|
|
|
ret = voice_extn_get_active_session_id(adev, &session_id);
|
|
|
|
if (ret == -ENOSYS) {
|
|
|
|
session_id = VOICE_VSID;
|
|
|
|
}
|
|
|
|
return session_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int voice_check_and_set_incall_rec_usecase(struct audio_device *adev,
|
2013-11-20 00:02:12 +00:00
|
|
|
struct stream_in *in)
|
2013-10-17 18:16:13 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
uint32_t session_id;
|
2013-11-20 00:02:12 +00:00
|
|
|
int rec_mode = INCALL_REC_NONE;
|
2013-10-17 18:16:13 +00:00
|
|
|
|
2014-08-06 01:20:42 +00:00
|
|
|
if (voice_is_call_state_active(adev)) {
|
2013-10-17 18:16:13 +00:00
|
|
|
switch (in->source) {
|
|
|
|
case AUDIO_SOURCE_VOICE_UPLINK:
|
2013-12-04 00:54:40 +00:00
|
|
|
if (audio_extn_compr_cap_enabled() &&
|
|
|
|
audio_extn_compr_cap_format_supported(in->config.format)) {
|
|
|
|
in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS;
|
|
|
|
} else
|
|
|
|
in->usecase = USECASE_INCALL_REC_UPLINK;
|
2013-11-20 00:02:12 +00:00
|
|
|
rec_mode = INCALL_REC_UPLINK;
|
2013-10-17 18:16:13 +00:00
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_VOICE_DOWNLINK:
|
2013-12-04 00:54:40 +00:00
|
|
|
if (audio_extn_compr_cap_enabled() &&
|
|
|
|
audio_extn_compr_cap_format_supported(in->config.format)) {
|
|
|
|
in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS;
|
|
|
|
} else
|
|
|
|
in->usecase = USECASE_INCALL_REC_DOWNLINK;
|
2013-11-20 00:02:12 +00:00
|
|
|
rec_mode = INCALL_REC_DOWNLINK;
|
2013-10-17 18:16:13 +00:00
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_VOICE_CALL:
|
2013-12-04 00:54:40 +00:00
|
|
|
if (audio_extn_compr_cap_enabled() &&
|
|
|
|
audio_extn_compr_cap_format_supported(in->config.format)) {
|
|
|
|
in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS;
|
|
|
|
} else
|
|
|
|
in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK;
|
2013-11-20 00:02:12 +00:00
|
|
|
rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK;
|
2013-10-17 18:16:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOGV("%s: Source type %d doesnt match incall recording criteria",
|
|
|
|
__func__, in->source);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
session_id = voice_get_active_session_id(adev);
|
2013-11-20 00:02:12 +00:00
|
|
|
ret = platform_set_incall_recording_session_id(adev->platform,
|
|
|
|
session_id, rec_mode);
|
2019-04-11 01:04:28 +00:00
|
|
|
platform_set_incall_recording_session_channels(adev->platform,
|
|
|
|
in->config.channels);
|
2013-10-17 18:16:13 +00:00
|
|
|
ALOGV("%s: Update usecase to %d",__func__, in->usecase);
|
|
|
|
} else {
|
2015-03-30 13:46:14 +00:00
|
|
|
/*
|
|
|
|
* Reject the recording instances, where the recording is started
|
|
|
|
* with In-call voice recording source types but voice call is not
|
|
|
|
* active by the time input is started
|
|
|
|
*/
|
|
|
|
if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) ||
|
|
|
|
(in->source == AUDIO_SOURCE_VOICE_DOWNLINK) ||
|
|
|
|
(in->source == AUDIO_SOURCE_VOICE_CALL)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
ALOGE("%s: As voice call is not active, Incall rec usecase can't be \
|
|
|
|
selected for requested source:%d",__func__, in->source);
|
|
|
|
}
|
2013-10-17 18:16:13 +00:00
|
|
|
ALOGV("%s: voice call not active", __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-20 00:02:12 +00:00
|
|
|
int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev,
|
|
|
|
struct stream_in *in)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (in->source == AUDIO_SOURCE_VOICE_UPLINK ||
|
|
|
|
in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
|
|
|
|
in->source == AUDIO_SOURCE_VOICE_CALL) {
|
|
|
|
ret = platform_stop_incall_recording_usecase(adev->platform);
|
|
|
|
ALOGV("%s: Stop In-call recording", __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-06 08:55:16 +00:00
|
|
|
snd_device_t voice_get_incall_rec_backend_device(struct stream_in *in)
|
|
|
|
{
|
|
|
|
snd_device_t incall_record_device = {0};
|
|
|
|
|
2019-01-29 12:17:13 +00:00
|
|
|
if (!in) {
|
|
|
|
ALOGE("%s: input stream is NULL", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-06 08:55:16 +00:00
|
|
|
switch(in->source) {
|
|
|
|
case AUDIO_SOURCE_VOICE_UPLINK:
|
|
|
|
incall_record_device = SND_DEVICE_IN_INCALL_REC_TX;
|
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_VOICE_DOWNLINK:
|
|
|
|
incall_record_device = SND_DEVICE_IN_INCALL_REC_RX;
|
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_VOICE_CALL:
|
|
|
|
incall_record_device = SND_DEVICE_IN_INCALL_REC_RX_TX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOGI("Invalid source %d", in->source);
|
|
|
|
}
|
|
|
|
|
|
|
|
return incall_record_device;
|
|
|
|
}
|
|
|
|
|
2014-11-18 03:57:04 +00:00
|
|
|
snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device)
|
|
|
|
{
|
|
|
|
snd_device_t incall_record_device = in_snd_device;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For incall recording stream, AUDIO_COPP topology will be picked up
|
|
|
|
* from the calibration data of the input sound device which is nothing
|
|
|
|
* but the voice call's input device. But there are requirements to use
|
|
|
|
* AUDIO_COPP_MONO topology even if the voice call's input device is
|
|
|
|
* different. Hence override the input device with the one which uses
|
|
|
|
* the AUDIO_COPP_MONO topology.
|
|
|
|
*/
|
|
|
|
switch(in_snd_device) {
|
|
|
|
case SND_DEVICE_IN_HANDSET_MIC:
|
|
|
|
case SND_DEVICE_IN_VOICE_DMIC:
|
|
|
|
case SND_DEVICE_IN_AANC_HANDSET_MIC:
|
|
|
|
incall_record_device = SND_DEVICE_IN_HANDSET_MIC;
|
2015-02-19 22:29:01 +00:00
|
|
|
break;
|
2014-11-18 03:57:04 +00:00
|
|
|
case SND_DEVICE_IN_VOICE_SPEAKER_MIC:
|
|
|
|
case SND_DEVICE_IN_VOICE_SPEAKER_DMIC:
|
|
|
|
case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE:
|
|
|
|
case SND_DEVICE_IN_VOICE_SPEAKER_QMIC:
|
|
|
|
incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
|
2015-02-19 22:29:01 +00:00
|
|
|
break;
|
2014-11-18 03:57:04 +00:00
|
|
|
default:
|
|
|
|
incall_record_device = in_snd_device;
|
|
|
|
}
|
|
|
|
|
2015-02-19 22:29:01 +00:00
|
|
|
ALOGD("%s: in_snd_device(%d: %s) incall_record_device(%d: %s)", __func__,
|
|
|
|
in_snd_device, platform_get_snd_device_name(in_snd_device),
|
|
|
|
incall_record_device, platform_get_snd_device_name(incall_record_device));
|
|
|
|
|
2014-11-18 03:57:04 +00:00
|
|
|
return incall_record_device;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
int voice_set_mic_mute(struct audio_device *adev, bool state)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2013-11-15 23:21:40 +00:00
|
|
|
adev->voice.mic_mute = state;
|
2018-09-12 01:00:09 +00:00
|
|
|
|
2016-09-28 09:17:26 +00:00
|
|
|
if (audio_extn_hfp_is_active(adev)) {
|
2019-03-21 18:21:04 +00:00
|
|
|
err = audio_extn_hfp_set_mic_mute2(adev, state);
|
2016-09-28 09:17:26 +00:00
|
|
|
} else if (adev->mode == AUDIO_MODE_IN_CALL) {
|
2018-09-12 01:00:09 +00:00
|
|
|
/* Use device mute if incall music delivery usecase is in progress */
|
|
|
|
if (adev->voice.use_device_mute)
|
|
|
|
err = platform_set_device_mute(adev->platform, state, "tx");
|
|
|
|
else
|
|
|
|
err = platform_set_mic_mute(adev->platform, state);
|
|
|
|
ALOGV("%s: voice mute status=%d, use_device_mute flag=%d",
|
|
|
|
__func__, state, adev->voice.use_device_mute);
|
2016-09-28 09:17:26 +00:00
|
|
|
} else if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
|
2013-11-15 23:21:40 +00:00
|
|
|
err = voice_extn_compress_voip_set_mic_mute(adev, state);
|
2016-09-28 09:17:26 +00:00
|
|
|
}
|
2018-09-12 01:00:09 +00:00
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool voice_get_mic_mute(struct audio_device *adev)
|
|
|
|
{
|
|
|
|
return adev->voice.mic_mute;
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:00:09 +00:00
|
|
|
/*
|
|
|
|
* Following function is called when incall music uplink usecase is
|
|
|
|
* created or destroyed while mic is muted. If incall music uplink
|
|
|
|
* usecase is active, apply voice device mute to mute only voice Tx
|
|
|
|
* path and not the mixed voice Tx + inncall-music path. Revert to
|
|
|
|
* voice stream mute once incall music uplink usecase is inactive
|
|
|
|
*/
|
|
|
|
void voice_set_device_mute_flag(struct audio_device *adev, bool state)
|
|
|
|
{
|
|
|
|
if (adev->voice.mic_mute) {
|
|
|
|
if (state) {
|
|
|
|
platform_set_device_mute(adev->platform, true, "tx");
|
|
|
|
platform_set_mic_mute(adev->platform, false);
|
|
|
|
} else {
|
|
|
|
platform_set_mic_mute(adev->platform, true);
|
|
|
|
platform_set_device_mute(adev->platform, false, "tx");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
adev->voice.use_device_mute = state;
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
int voice_set_volume(struct audio_device *adev, float volume)
|
|
|
|
{
|
|
|
|
int vol, err = 0;
|
|
|
|
|
2013-10-25 21:32:12 +00:00
|
|
|
adev->voice.volume = volume;
|
2013-10-01 22:49:05 +00:00
|
|
|
if (adev->mode == AUDIO_MODE_IN_CALL) {
|
|
|
|
if (volume < 0.0) {
|
|
|
|
volume = 0.0;
|
|
|
|
} else if (volume > 1.0) {
|
|
|
|
volume = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vol = lrint(volume * 100.0);
|
|
|
|
|
|
|
|
// Voice volume levels from android are mapped to driver volume levels as follows.
|
|
|
|
// 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
|
|
|
|
// So adjust the volume to get the correct volume index in driver
|
|
|
|
vol = 100 - vol;
|
|
|
|
|
|
|
|
err = platform_set_voice_volume(adev->platform, vol);
|
|
|
|
}
|
2013-11-15 23:21:40 +00:00
|
|
|
if (adev->mode == AUDIO_MODE_IN_COMMUNICATION)
|
|
|
|
err = voice_extn_compress_voip_set_volume(adev, volume);
|
|
|
|
|
2013-10-25 21:32:12 +00:00
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int voice_start_call(struct audio_device *adev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2014-10-21 00:07:43 +00:00
|
|
|
adev->voice.in_call = true;
|
2018-12-18 22:23:57 +00:00
|
|
|
|
|
|
|
voice_set_mic_mute(adev, adev->voice.mic_mute);
|
|
|
|
|
2013-11-05 20:49:15 +00:00
|
|
|
ret = voice_extn_start_call(adev);
|
2013-10-01 22:49:05 +00:00
|
|
|
if (ret == -ENOSYS) {
|
2014-08-20 23:24:38 +00:00
|
|
|
ret = voice_start_usecase(adev, USECASE_VOICE_CALL);
|
2013-10-01 22:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int voice_stop_call(struct audio_device *adev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2014-08-06 01:20:42 +00:00
|
|
|
adev->voice.in_call = false;
|
2013-11-05 20:49:15 +00:00
|
|
|
ret = voice_extn_stop_call(adev);
|
2013-10-01 22:49:05 +00:00
|
|
|
if (ret == -ENOSYS) {
|
2014-08-20 23:24:38 +00:00
|
|
|
ret = voice_stop_usecase(adev, USECASE_VOICE_CALL);
|
2013-10-01 22:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-12 20:18:09 +00:00
|
|
|
void voice_get_parameters(struct audio_device *adev,
|
|
|
|
struct str_parms *query,
|
|
|
|
struct str_parms *reply)
|
|
|
|
{
|
|
|
|
voice_extn_get_parameters(adev, query, reply);
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
|
|
|
|
{
|
|
|
|
char value[32];
|
2013-12-16 23:54:40 +00:00
|
|
|
int ret = 0, err;
|
2014-02-01 02:12:13 +00:00
|
|
|
char *kv_pairs = str_parms_to_str(parms);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2014-02-01 02:12:13 +00:00
|
|
|
ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2013-12-16 23:54:40 +00:00
|
|
|
ret = voice_extn_set_parameters(adev, parms);
|
2014-07-21 21:51:44 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
if (ret == -ENOSYS)
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
goto done;
|
|
|
|
}
|
2013-12-16 23:54:40 +00:00
|
|
|
|
|
|
|
ret = voice_extn_compress_voip_set_parameters(adev, parms);
|
2014-07-21 21:51:44 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
if (ret == -ENOSYS)
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
goto done;
|
|
|
|
}
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2013-12-16 23:54:40 +00:00
|
|
|
err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
|
|
|
|
if (err >= 0) {
|
2013-10-01 22:49:05 +00:00
|
|
|
int tty_mode;
|
|
|
|
str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
|
|
|
|
if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
|
|
|
|
tty_mode = TTY_MODE_OFF;
|
|
|
|
else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
|
|
|
|
tty_mode = TTY_MODE_VCO;
|
|
|
|
else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
|
|
|
|
tty_mode = TTY_MODE_HCO;
|
|
|
|
else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
|
|
|
|
tty_mode = TTY_MODE_FULL;
|
|
|
|
else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tty_mode != adev->voice.tty_mode) {
|
|
|
|
adev->voice.tty_mode = tty_mode;
|
|
|
|
adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
|
2014-08-06 01:20:42 +00:00
|
|
|
if (voice_is_call_state_active(adev))
|
2014-02-06 22:05:14 +00:00
|
|
|
voice_update_devices_for_all_voice_usecases(adev);
|
2013-10-01 22:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 22:23:57 +00:00
|
|
|
err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HAC,
|
|
|
|
value, sizeof(value));
|
|
|
|
if (err >= 0) {
|
|
|
|
bool hac = false;
|
|
|
|
str_parms_del(parms, AUDIO_PARAMETER_KEY_HAC);
|
|
|
|
if (strcmp(value, AUDIO_PARAMETER_VALUE_HAC_ON) == 0)
|
|
|
|
hac = true;
|
|
|
|
|
|
|
|
if (hac != adev->voice.hac) {
|
|
|
|
adev->voice.hac = hac;
|
|
|
|
if (voice_is_in_call(adev))
|
|
|
|
voice_update_devices_for_all_voice_usecases(adev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 23:54:40 +00:00
|
|
|
err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC,
|
2013-11-20 00:02:12 +00:00
|
|
|
value, sizeof(value));
|
2013-12-16 23:54:40 +00:00
|
|
|
if (err >= 0) {
|
2013-11-20 00:02:12 +00:00
|
|
|
str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC);
|
|
|
|
if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0)
|
|
|
|
platform_start_incall_music_usecase(adev->platform);
|
|
|
|
else
|
|
|
|
platform_stop_incall_music_usecase(adev->platform);
|
2014-07-21 21:51:44 +00:00
|
|
|
}
|
2013-11-20 00:02:12 +00:00
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
done:
|
|
|
|
ALOGV("%s: exit with code(%d)", __func__, ret);
|
2014-02-01 02:12:13 +00:00
|
|
|
free(kv_pairs);
|
2013-10-01 22:49:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void voice_init(struct audio_device *adev)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
memset(&adev->voice, 0, sizeof(adev->voice));
|
|
|
|
adev->voice.tty_mode = TTY_MODE_OFF;
|
2018-12-18 22:23:57 +00:00
|
|
|
adev->voice.hac = false;
|
2013-10-01 22:49:05 +00:00
|
|
|
adev->voice.volume = 1.0f;
|
|
|
|
adev->voice.mic_mute = false;
|
2014-08-06 01:20:42 +00:00
|
|
|
adev->voice.in_call = false;
|
2013-10-01 22:49:05 +00:00
|
|
|
for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
|
|
|
|
adev->voice.session[i].pcm_rx = NULL;
|
|
|
|
adev->voice.session[i].pcm_tx = NULL;
|
|
|
|
adev->voice.session[i].state.current = CALL_INACTIVE;
|
|
|
|
adev->voice.session[i].state.new = CALL_INACTIVE;
|
2014-09-05 23:14:17 +00:00
|
|
|
adev->voice.session[i].vsid = VOICE_VSID;
|
2013-10-01 22:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
voice_extn_init(adev);
|
|
|
|
}
|
|
|
|
|
2014-02-06 22:05:14 +00:00
|
|
|
void voice_update_devices_for_all_voice_usecases(struct audio_device *adev)
|
|
|
|
{
|
|
|
|
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 == VOICE_CALL) {
|
|
|
|
ALOGV("%s: updating device for usecase:%s", __func__,
|
|
|
|
use_case_table[usecase->id]);
|
2014-09-05 20:51:35 +00:00
|
|
|
usecase->stream.out = adev->current_call_output;
|
2014-02-06 22:05:14 +00:00
|
|
|
select_devices(adev, usecase->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
|