Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "audio_hw_primary" |
| 18 | /*#define LOG_NDEBUG 0*/ |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 19 | #define LOG_NDDEBUG 0 |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 20 | |
| 21 | #include <errno.h> |
| 22 | #include <pthread.h> |
| 23 | #include <stdint.h> |
| 24 | #include <sys/time.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <dlfcn.h> |
| 27 | #include <math.h> |
| 28 | |
| 29 | #include <cutils/log.h> |
| 30 | #include <cutils/str_parms.h> |
| 31 | #include <cutils/properties.h> |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 32 | #include <cutils/list.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 33 | |
| 34 | #include "audio_hw.h" |
| 35 | |
| 36 | #define LIB_ACDB_LOADER "/system/lib/libacdbloader.so" |
| 37 | #define LIB_CSD_CLIENT "/system/lib/libcsd-client.so" |
| 38 | #define MIXER_XML_PATH "/system/etc/mixer_paths.xml" |
| 39 | #define MIXER_CARD 0 |
| 40 | |
| 41 | #define STRING_TO_ENUM(string) { #string, string } |
| 42 | |
| 43 | /* Flags used to initialize acdb_settings variable that goes to ACDB library */ |
| 44 | #define DMIC_FLAG 0x00000002 |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 45 | #define TTY_MODE_OFF 0x00000010 |
| 46 | #define TTY_MODE_FULL 0x00000020 |
| 47 | #define TTY_MODE_VCO 0x00000040 |
| 48 | #define TTY_MODE_HCO 0x00000080 |
| 49 | #define TTY_MODE_CLEAR 0xFFFFFF0F |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 50 | |
| 51 | struct string_to_enum { |
| 52 | const char *name; |
| 53 | uint32_t value; |
| 54 | }; |
| 55 | |
| 56 | static const struct string_to_enum out_channels_name_to_enum_table[] = { |
| 57 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO), |
| 58 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1), |
| 59 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1), |
| 60 | }; |
| 61 | |
| 62 | static const char * const use_case_table[AUDIO_USECASE_MAX] = { |
| 63 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback", |
| 64 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback", |
| 65 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback", |
| 66 | [USECASE_AUDIO_RECORD] = "audio-record", |
| 67 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record", |
| 68 | [USECASE_VOICE_CALL] = "voice-call", |
| 69 | }; |
| 70 | |
| 71 | static const int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
| 72 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0}, |
| 73 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14}, |
| 74 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1}, |
| 75 | [USECASE_AUDIO_RECORD] = {0, 0}, |
| 76 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14}, |
| 77 | [USECASE_VOICE_CALL] = {12, 12}, |
| 78 | }; |
| 79 | |
| 80 | /* Array to store sound devices */ |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 81 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 82 | [SND_DEVICE_NONE] = "none", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 83 | /* Playback sound devices */ |
| 84 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 85 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 86 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
| 87 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
| 88 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 89 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 90 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 91 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 92 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 93 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus", |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 94 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 95 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 96 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 97 | |
| 98 | /* Capture sound devices */ |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 99 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 100 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 101 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
| 102 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 103 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
| 104 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 105 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 106 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 107 | [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef", |
| 108 | [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs", |
| 109 | [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus", |
| 110 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef", |
| 111 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs", |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 112 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 113 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 114 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 115 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 116 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef", |
| 117 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs", |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 118 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence", |
| 119 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 122 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 123 | static const int acdb_device_table[SND_DEVICE_MAX] = { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 124 | [SND_DEVICE_NONE] = -1, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 125 | [SND_DEVICE_OUT_HANDSET] = 7, |
| 126 | [SND_DEVICE_OUT_SPEAKER] = 14, |
| 127 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
| 128 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
| 129 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 14, |
| 130 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 131 | [SND_DEVICE_OUT_HDMI] = 18, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 132 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14, |
| 133 | [SND_DEVICE_OUT_BT_SCO] = 22, |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 134 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81, |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 135 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 136 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 137 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 138 | |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 139 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 140 | [SND_DEVICE_IN_SPEAKER_MIC] = 4, |
| 141 | [SND_DEVICE_IN_HEADSET_MIC] = 8, |
| 142 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
| 143 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8, |
| 144 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 145 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 146 | [SND_DEVICE_IN_CAMCORDER_MIC] = 61, |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 147 | [SND_DEVICE_IN_VOICE_DMIC_EF] = 6, |
| 148 | [SND_DEVICE_IN_VOICE_DMIC_BS] = 5, |
| 149 | [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91, |
| 150 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13, |
| 151 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12, |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 152 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 153 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 154 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 155 | [SND_DEVICE_IN_VOICE_REC_MIC] = 62, |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 156 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62, |
| 157 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62, |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 158 | /* TODO: Update with proper acdb ids */ |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 159 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 62, |
| 160 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 62, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 163 | int edid_get_max_channels(void); |
| 164 | |
Ravi Kumar Alamanda | 3771884 | 2013-02-22 18:44:45 -0800 | [diff] [blame] | 165 | static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT; |
| 166 | static bool is_tmus = false; |
| 167 | |
| 168 | static void check_operator() |
| 169 | { |
| 170 | char value[PROPERTY_VALUE_MAX]; |
| 171 | int mccmnc; |
| 172 | property_get("gsm.sim.operator.numeric",value,"0"); |
| 173 | mccmnc = atoi(value); |
| 174 | ALOGD("%s: tmus mccmnc %d", __func__, mccmnc); |
| 175 | switch(mccmnc) { |
| 176 | /* TMUS MCC(310), MNC(490, 260, 026) */ |
| 177 | case 310490: |
| 178 | case 310260: |
| 179 | case 310026: |
| 180 | is_tmus = true; |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | static bool is_operator_tmus() |
| 186 | { |
| 187 | pthread_once(&check_op_once_ctl, check_operator); |
| 188 | return is_tmus; |
| 189 | } |
| 190 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 191 | static int get_pcm_device_id(struct audio_route *ar, |
| 192 | audio_usecase_t usecase, |
| 193 | int device_type) |
| 194 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 195 | int device_id; |
| 196 | if (device_type == PCM_PLAYBACK) |
| 197 | device_id = pcm_device_table[usecase][0]; |
| 198 | else |
| 199 | device_id = pcm_device_table[usecase][1]; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 200 | return device_id; |
| 201 | } |
| 202 | |
| 203 | static int get_acdb_device_id(snd_device_t snd_device) |
| 204 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 205 | return acdb_device_table[snd_device]; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 208 | static void add_backend_name(char *mixer_path, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 209 | snd_device_t snd_device) |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 210 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 211 | if (snd_device == SND_DEVICE_IN_BT_SCO_MIC) |
| 212 | strcat(mixer_path, " bt-sco"); |
| 213 | else if(snd_device == SND_DEVICE_OUT_BT_SCO) |
| 214 | strcat(mixer_path, " bt-sco"); |
| 215 | else if (snd_device == SND_DEVICE_OUT_HDMI) |
| 216 | strcat(mixer_path, " hdmi"); |
| 217 | else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI) |
| 218 | strcat(mixer_path, " speaker-and-hdmi"); |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 221 | static int enable_audio_route(struct audio_device *adev, |
| 222 | struct audio_usecase *usecase, |
| 223 | bool update_mixer) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 224 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 225 | snd_device_t snd_device; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 226 | char mixer_path[50]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 227 | |
| 228 | if (usecase == NULL) |
| 229 | return -EINVAL; |
| 230 | |
| 231 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
| 232 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 233 | if (usecase->type == PCM_CAPTURE) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 234 | snd_device = usecase->in_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 235 | else |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 236 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 237 | |
| 238 | strcpy(mixer_path, use_case_table[usecase->id]); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 239 | add_backend_name(mixer_path, snd_device); |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 240 | ALOGD("%s: apply mixer path: %s", __func__, mixer_path); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 241 | audio_route_apply_path(adev->audio_route, mixer_path); |
| 242 | if (update_mixer) |
| 243 | audio_route_update_mixer(adev->audio_route); |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 244 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 245 | ALOGV("%s: exit", __func__); |
| 246 | return 0; |
| 247 | } |
| 248 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 249 | static int disable_audio_route(struct audio_device *adev, |
| 250 | struct audio_usecase *usecase, |
| 251 | bool update_mixer) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 252 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 253 | snd_device_t snd_device; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 254 | char mixer_path[50]; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 255 | |
| 256 | if (usecase == NULL) |
| 257 | return -EINVAL; |
| 258 | |
| 259 | ALOGV("%s: enter: usecase(%d)", __func__, usecase->id); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 260 | if (usecase->type == PCM_CAPTURE) |
| 261 | snd_device = usecase->in_snd_device; |
| 262 | else |
| 263 | snd_device = usecase->out_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 264 | strcpy(mixer_path, use_case_table[usecase->id]); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 265 | add_backend_name(mixer_path, snd_device); |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 266 | ALOGD("%s: reset mixer path: %s", __func__, mixer_path); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 267 | audio_route_reset_path(adev->audio_route, mixer_path); |
| 268 | if (update_mixer) |
| 269 | audio_route_update_mixer(adev->audio_route); |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 270 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 271 | ALOGV("%s: exit", __func__); |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static int enable_snd_device(struct audio_device *adev, |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 276 | snd_device_t snd_device, |
| 277 | bool update_mixer) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 278 | { |
| 279 | int acdb_dev_id, acdb_dev_type; |
| 280 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 281 | if (snd_device < SND_DEVICE_MIN || |
| 282 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 283 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 284 | return -EINVAL; |
| 285 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 286 | |
| 287 | adev->snd_dev_ref_cnt[snd_device]++; |
| 288 | if (adev->snd_dev_ref_cnt[snd_device] > 1) { |
| 289 | ALOGD("%s: snd_device(%d: %s) is already active", |
| 290 | __func__, snd_device, device_table[snd_device]); |
| 291 | return 0; |
| 292 | } |
| 293 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 294 | acdb_dev_id = get_acdb_device_id(snd_device); |
| 295 | if (acdb_dev_id < 0) { |
| 296 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 297 | __func__, snd_device); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 298 | adev->snd_dev_ref_cnt[snd_device]--; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 299 | return -EINVAL; |
| 300 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 301 | if (adev->acdb_send_audio_cal) { |
| 302 | ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
| 303 | __func__, snd_device, acdb_dev_id); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 304 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 305 | snd_device < SND_DEVICE_OUT_END) |
| 306 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 307 | else |
| 308 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 309 | adev->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 310 | } else { |
| 311 | ALOGW("%s: Could find the symbol acdb_send_audio_cal from %s", |
| 312 | __func__, LIB_ACDB_LOADER); |
| 313 | } |
| 314 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 315 | ALOGD("%s: snd_device(%d: %s)", __func__, |
| 316 | snd_device, device_table[snd_device]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 317 | audio_route_apply_path(adev->audio_route, device_table[snd_device]); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 318 | if (update_mixer) |
| 319 | audio_route_update_mixer(adev->audio_route); |
| 320 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 321 | return 0; |
| 322 | } |
| 323 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 324 | static int disable_snd_device(struct audio_device *adev, |
| 325 | snd_device_t snd_device, |
| 326 | bool update_mixer) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 327 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 328 | if (snd_device < SND_DEVICE_MIN || |
| 329 | snd_device >= SND_DEVICE_MAX) { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 330 | ALOGE("%s: Invalid sound device %d", __func__, snd_device); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 331 | return -EINVAL; |
| 332 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 333 | if (adev->snd_dev_ref_cnt[snd_device] <= 0) { |
| 334 | ALOGE("%s: device ref cnt is already 0", __func__); |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | adev->snd_dev_ref_cnt[snd_device]--; |
| 338 | if (adev->snd_dev_ref_cnt[snd_device] == 0) { |
| 339 | ALOGD("%s: snd_device(%d: %s)", __func__, |
| 340 | snd_device, device_table[snd_device]); |
| 341 | audio_route_reset_path(adev->audio_route, device_table[snd_device]); |
| 342 | if (update_mixer) |
| 343 | audio_route_update_mixer(adev->audio_route); |
| 344 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 348 | static void check_usecases_codec_backend(struct audio_device *adev, |
| 349 | struct audio_usecase *uc_info, |
| 350 | snd_device_t snd_device) |
| 351 | { |
| 352 | struct listnode *node; |
| 353 | struct audio_usecase *usecase; |
| 354 | bool switch_device[AUDIO_USECASE_MAX]; |
| 355 | int i, num_uc_to_switch = 0; |
| 356 | |
| 357 | /* |
| 358 | * This function is to make sure that all the usecases that are active on |
| 359 | * the hardware codec backend are always routed to any one device that is |
| 360 | * handled by the hardware codec. |
| 361 | * For example, if low-latency and deep-buffer usecases are currently active |
| 362 | * on speaker and out_set_parameters(headset) is received on low-latency |
| 363 | * output, then we have to make sure deep-buffer is also switched to headset, |
| 364 | * because of the limitation that both the devices cannot be enabled |
| 365 | * at the same time as they share the same backend. |
| 366 | */ |
| 367 | /* Disable all the usecases on the shared backend other than the |
| 368 | specified usecase */ |
| 369 | for (i = 0; i < AUDIO_USECASE_MAX; i++) |
| 370 | switch_device[i] = false; |
| 371 | |
| 372 | list_for_each(node, &adev->usecase_list) { |
| 373 | usecase = node_to_item(node, struct audio_usecase, list); |
| 374 | if (usecase->type != PCM_CAPTURE && |
| 375 | usecase != uc_info && |
| 376 | usecase->out_snd_device != snd_device && |
| 377 | usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) { |
| 378 | ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..", |
| 379 | __func__, use_case_table[usecase->id], |
| 380 | device_table[usecase->out_snd_device]); |
| 381 | disable_audio_route(adev, usecase, false); |
| 382 | switch_device[usecase->id] = true; |
| 383 | num_uc_to_switch++; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | if (num_uc_to_switch) { |
| 388 | /* Make sure all the streams are de-routed before disabling the device */ |
| 389 | audio_route_update_mixer(adev->audio_route); |
| 390 | |
| 391 | list_for_each(node, &adev->usecase_list) { |
| 392 | usecase = node_to_item(node, struct audio_usecase, list); |
| 393 | if (switch_device[usecase->id]) { |
| 394 | disable_snd_device(adev, usecase->out_snd_device, false); |
| 395 | enable_snd_device(adev, snd_device, false); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /* Make sure new snd device is enabled before re-routing the streams */ |
| 400 | audio_route_update_mixer(adev->audio_route); |
| 401 | |
| 402 | /* Re-route all the usecases on the shared backend other than the |
| 403 | specified usecase to new snd devices */ |
| 404 | list_for_each(node, &adev->usecase_list) { |
| 405 | usecase = node_to_item(node, struct audio_usecase, list); |
| 406 | /* Update the out_snd_device only before enabling the audio route */ |
| 407 | if (switch_device[usecase->id] ) { |
| 408 | usecase->out_snd_device = snd_device; |
| 409 | enable_audio_route(adev, usecase, false); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | audio_route_update_mixer(adev->audio_route); |
| 414 | } |
| 415 | } |
| 416 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 417 | static int set_hdmi_channels(struct mixer *mixer, |
| 418 | int channel_count) |
| 419 | { |
| 420 | struct mixer_ctl *ctl; |
| 421 | const char *channel_cnt_str = NULL; |
| 422 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 423 | switch (channel_count) { |
| 424 | case 8: |
| 425 | channel_cnt_str = "Eight"; break; |
| 426 | case 7: |
| 427 | channel_cnt_str = "Seven"; break; |
| 428 | case 6: |
| 429 | channel_cnt_str = "Six"; break; |
| 430 | case 5: |
| 431 | channel_cnt_str = "Five"; break; |
| 432 | case 4: |
| 433 | channel_cnt_str = "Four"; break; |
| 434 | case 3: |
| 435 | channel_cnt_str = "Three"; break; |
| 436 | default: |
| 437 | channel_cnt_str = "Two"; break; |
| 438 | } |
| 439 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 440 | if (!ctl) { |
| 441 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 442 | __func__, mixer_ctl_name); |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 446 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | /* must be called with hw device mutex locked */ |
| 451 | static void read_hdmi_channel_masks(struct stream_out *out) |
| 452 | { |
| 453 | int channels = edid_get_max_channels(); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 454 | ALOGV("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 455 | |
| 456 | switch (channels) { |
| 457 | /* |
| 458 | * Do not handle stereo output in Multi-channel cases |
| 459 | * Stereo case is handled in normal playback path |
| 460 | */ |
| 461 | case 6: |
| 462 | ALOGV("%s: HDMI supports 5.1", __func__); |
| 463 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 464 | break; |
| 465 | case 8: |
| 466 | ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__); |
| 467 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1; |
| 468 | out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1; |
| 469 | break; |
| 470 | default: |
| 471 | ALOGE("Unsupported number of channels (%d)", channels); |
| 472 | break; |
| 473 | } |
| 474 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 475 | ALOGV("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 478 | static snd_device_t get_output_snd_device(struct audio_device *adev, |
| 479 | audio_devices_t devices) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 480 | { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 481 | audio_mode_t mode = adev->mode; |
| 482 | snd_device_t snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 483 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 484 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 485 | if (devices == AUDIO_DEVICE_NONE || |
| 486 | devices & AUDIO_DEVICE_BIT_IN) { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 487 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 488 | goto exit; |
| 489 | } |
| 490 | |
| 491 | if (mode == AUDIO_MODE_IN_CALL) { |
| 492 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 493 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 494 | if (adev->tty_mode == TTY_MODE_FULL) |
| 495 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
| 496 | else if (adev->tty_mode == TTY_MODE_VCO) |
| 497 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
| 498 | else if (adev->tty_mode == TTY_MODE_HCO) |
| 499 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
| 500 | else |
| 501 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 502 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 503 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 504 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 505 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
| 506 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
Ravi Kumar Alamanda | 3771884 | 2013-02-22 18:44:45 -0800 | [diff] [blame] | 507 | if (is_operator_tmus()) |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 508 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS; |
| 509 | else |
| 510 | snd_device = SND_DEVICE_OUT_HANDSET; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 511 | } |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 512 | if (snd_device != SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 513 | goto exit; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | if (popcount(devices) == 2) { |
| 518 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 519 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 520 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 521 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 522 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 523 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 524 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 525 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 526 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
| 527 | } else { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 528 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 529 | goto exit; |
| 530 | } |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 531 | if (snd_device != SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 532 | goto exit; |
| 533 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 534 | } |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 535 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 536 | if (popcount(devices) != 1) { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 537 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 538 | goto exit; |
| 539 | } |
| 540 | |
| 541 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 542 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 543 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
| 544 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 545 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 546 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 547 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 548 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 549 | snd_device = SND_DEVICE_OUT_HDMI ; |
| 550 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 551 | snd_device = SND_DEVICE_OUT_HANDSET; |
| 552 | } else { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 553 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 554 | } |
| 555 | exit: |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 556 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 557 | return snd_device; |
| 558 | } |
| 559 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 560 | static snd_device_t get_input_snd_device(struct audio_device *adev, |
| 561 | audio_devices_t out_device) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 562 | { |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 563 | audio_source_t source = (adev->active_input == NULL) ? |
| 564 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 565 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 566 | audio_mode_t mode = adev->mode; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 567 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 568 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 569 | & ~AUDIO_DEVICE_BIT_IN; |
| 570 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 571 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 572 | snd_device_t snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 573 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 574 | ALOGV("%s: enter: out_device(%#x) in_device(%#x)", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 575 | __func__, out_device, in_device); |
| 576 | if (mode == AUDIO_MODE_IN_CALL) { |
| 577 | if (out_device == AUDIO_DEVICE_NONE) { |
| 578 | ALOGE("%s: No output device set for voice call", __func__); |
| 579 | goto exit; |
| 580 | } |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 581 | if (adev->tty_mode != TTY_MODE_OFF) { |
| 582 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 583 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 584 | switch (adev->tty_mode) { |
| 585 | case TTY_MODE_FULL: |
| 586 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 587 | break; |
| 588 | case TTY_MODE_VCO: |
| 589 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 590 | break; |
| 591 | case TTY_MODE_HCO: |
| 592 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 593 | break; |
| 594 | default: |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 595 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode); |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 596 | } |
| 597 | goto exit; |
| 598 | } |
| 599 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 600 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE || |
| 601 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 602 | if (adev->mic_type_analog || adev->fluence_in_voice_call == false) { |
| 603 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 604 | } else { |
| 605 | if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
Ravi Kumar Alamanda | 3771884 | 2013-02-22 18:44:45 -0800 | [diff] [blame] | 606 | if (is_operator_tmus()) |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 607 | snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS; |
| 608 | else |
| 609 | snd_device = SND_DEVICE_IN_VOICE_DMIC_EF; |
| 610 | } else if(adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) |
| 611 | snd_device = SND_DEVICE_IN_VOICE_DMIC_BS; |
| 612 | else |
| 613 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 614 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 615 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 616 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
| 617 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 618 | snd_device = SND_DEVICE_IN_BT_SCO_MIC ; |
| 619 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
Ravi Kumar Alamanda | 0231779 | 2013-03-04 20:56:50 -0800 | [diff] [blame] | 620 | if (adev->fluence_in_voice_call && adev->fluence_in_spkr_mode && |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 621 | adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 622 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF; |
Ravi Kumar Alamanda | 0231779 | 2013-03-04 20:56:50 -0800 | [diff] [blame] | 623 | } else if (adev->fluence_in_voice_call && adev->fluence_in_spkr_mode && |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 624 | adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) { |
| 625 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS; |
| 626 | } else { |
| 627 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 628 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 629 | } |
| 630 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 631 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 632 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 633 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 634 | } |
| 635 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 636 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 637 | if (adev->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 638 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 639 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF; |
| 640 | else if (adev->fluence_in_voice_rec) |
| 641 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE; |
| 642 | else |
| 643 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
| 644 | } else if (adev->dualmic_config == DUALMIC_CONFIG_BROADSIDE) { |
| 645 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 646 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS; |
| 647 | else if (adev->fluence_in_voice_rec) |
| 648 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE; |
| 649 | else |
| 650 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
| 651 | } else |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 652 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 653 | } |
Ravi Kumar Alamanda | 8455fa7 | 2013-02-19 14:53:19 -0800 | [diff] [blame] | 654 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 655 | if (out_device & AUDIO_DEVICE_OUT_SPEAKER) |
| 656 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 657 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 658 | goto exit; |
| 659 | } |
| 660 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 661 | if (snd_device != SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 662 | goto exit; |
| 663 | } |
| 664 | |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 665 | if (in_device != AUDIO_DEVICE_NONE && |
Ravi Kumar Alamanda | 8455fa7 | 2013-02-19 14:53:19 -0800 | [diff] [blame] | 666 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 667 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 668 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 669 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 670 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 671 | if (adev->mic_type_analog) |
| 672 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 673 | else |
| 674 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 675 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 676 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 677 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 678 | snd_device = SND_DEVICE_IN_BT_SCO_MIC ; |
| 679 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 680 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 681 | } else { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 682 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 683 | ALOGW("%s: Using default handset-mic", __func__); |
| 684 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 685 | } |
| 686 | } else { |
| 687 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 688 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 689 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 690 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 691 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 692 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 693 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 694 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 695 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 696 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 697 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 698 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 699 | } else { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 700 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 701 | ALOGW("%s: Using default handset-mic", __func__); |
| 702 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | exit: |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 706 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 707 | return snd_device; |
| 708 | } |
| 709 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 710 | static struct audio_usecase *get_usecase_from_list(struct audio_device *adev, |
| 711 | audio_usecase_t uc_id) |
| 712 | { |
| 713 | struct audio_usecase *usecase; |
| 714 | struct listnode *node; |
| 715 | |
| 716 | list_for_each(node, &adev->usecase_list) { |
| 717 | usecase = node_to_item(node, struct audio_usecase, list); |
| 718 | if (usecase->id == uc_id) |
| 719 | return usecase; |
| 720 | } |
| 721 | return NULL; |
| 722 | } |
| 723 | |
| 724 | static int select_devices(struct audio_device *adev, |
| 725 | audio_usecase_t uc_id) |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 726 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 727 | snd_device_t out_snd_device = SND_DEVICE_NONE; |
| 728 | snd_device_t in_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 729 | struct audio_usecase *usecase = NULL; |
| 730 | struct audio_usecase *vc_usecase = NULL; |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 731 | struct listnode *node; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 732 | int acdb_rx_id, acdb_tx_id; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 733 | int status = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 734 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 735 | usecase = get_usecase_from_list(adev, uc_id); |
| 736 | if (usecase == NULL) { |
| 737 | ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id); |
| 738 | return -EINVAL; |
| 739 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 740 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 741 | if (usecase->type == VOICE_CALL) { |
| 742 | out_snd_device = get_output_snd_device(adev, usecase->stream.out->devices); |
| 743 | in_snd_device = get_input_snd_device(adev, usecase->stream.out->devices); |
| 744 | usecase->devices = usecase->stream.out->devices; |
| 745 | } else { |
| 746 | /* |
| 747 | * If the voice call is active, use the sound devices of voice call usecase |
| 748 | * so that it would not result any device switch. All the usecases will |
| 749 | * be switched to new device when select_devices() is called for voice call |
| 750 | * usecase. This is to avoid switching devices for voice call when |
| 751 | * check_usecases_codec_backend() is called below. |
| 752 | */ |
| 753 | if (adev->in_call) { |
| 754 | vc_usecase = get_usecase_from_list(adev, USECASE_VOICE_CALL); |
| 755 | if (vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) { |
| 756 | in_snd_device = vc_usecase->in_snd_device; |
| 757 | out_snd_device = vc_usecase->out_snd_device; |
| 758 | } |
| 759 | } |
| 760 | if (usecase->type == PCM_PLAYBACK) { |
| 761 | usecase->devices = usecase->stream.out->devices; |
| 762 | in_snd_device = SND_DEVICE_NONE; |
| 763 | if (out_snd_device == SND_DEVICE_NONE) |
| 764 | out_snd_device = get_output_snd_device(adev, |
| 765 | usecase->stream.out->devices); |
| 766 | } else if (usecase->type == PCM_CAPTURE) { |
| 767 | usecase->devices = usecase->stream.in->device; |
| 768 | out_snd_device = SND_DEVICE_NONE; |
| 769 | if (in_snd_device == SND_DEVICE_NONE) |
| 770 | in_snd_device = get_input_snd_device(adev, SND_DEVICE_NONE); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | if (out_snd_device == usecase->out_snd_device && |
| 775 | in_snd_device == usecase->in_snd_device) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 779 | ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__, |
| 780 | out_snd_device, device_table[out_snd_device], |
| 781 | in_snd_device, device_table[in_snd_device]); |
| 782 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 783 | /* |
| 784 | * Limitation: While in call, to do a device switch we need to disable |
| 785 | * and enable both RX and TX devices though one of them is same as current |
| 786 | * device. |
| 787 | */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 788 | if (usecase->type == VOICE_CALL && adev->csd_client != NULL && |
| 789 | usecase->in_snd_device != SND_DEVICE_NONE && |
| 790 | usecase->out_snd_device != SND_DEVICE_NONE) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 791 | /* This must be called before disabling the mixer controls on APQ side */ |
| 792 | if (adev->csd_disable_device == NULL) { |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 793 | ALOGE("%s: dlsym error for csd_client_disable_device", __func__); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 794 | } else { |
| 795 | status = adev->csd_disable_device(); |
| 796 | if (status < 0) { |
| 797 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 798 | __func__, status); |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 803 | /* Disable current sound devices */ |
| 804 | if (usecase->out_snd_device != SND_DEVICE_NONE) { |
| 805 | disable_audio_route(adev, usecase, true); |
| 806 | disable_snd_device(adev, usecase->out_snd_device, false); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 809 | if (usecase->in_snd_device != SND_DEVICE_NONE) { |
| 810 | disable_audio_route(adev, usecase, true); |
| 811 | disable_snd_device(adev, usecase->in_snd_device, false); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 814 | /* Enable new sound devices */ |
| 815 | if (out_snd_device != SND_DEVICE_NONE) { |
| 816 | if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) |
| 817 | check_usecases_codec_backend(adev, usecase, out_snd_device); |
| 818 | enable_snd_device(adev, out_snd_device, false); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 819 | } |
| 820 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 821 | if (in_snd_device != SND_DEVICE_NONE) |
| 822 | enable_snd_device(adev, in_snd_device, false); |
| 823 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 824 | audio_route_update_mixer(adev->audio_route); |
| 825 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 826 | usecase->in_snd_device = in_snd_device; |
| 827 | usecase->out_snd_device = out_snd_device; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 828 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 829 | enable_audio_route(adev, usecase, true); |
| 830 | |
| 831 | if (usecase->type == VOICE_CALL && adev->csd_client) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 832 | if (adev->csd_enable_device == NULL) { |
| 833 | ALOGE("%s: dlsym error for csd_client_enable_device", |
| 834 | __func__); |
| 835 | } else { |
| 836 | acdb_rx_id = get_acdb_device_id(out_snd_device); |
| 837 | acdb_tx_id = get_acdb_device_id(in_snd_device); |
| 838 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 839 | if (acdb_rx_id > 0 || acdb_tx_id > 0) { |
| 840 | status = adev->csd_enable_device(acdb_rx_id, acdb_tx_id, |
| 841 | adev->acdb_settings); |
| 842 | if (status < 0) { |
| 843 | ALOGE("%s: csd_client_enable_device, failed, error %d", |
| 844 | __func__, status); |
| 845 | } |
| 846 | } else { |
| 847 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 848 | acdb_rx_id, acdb_tx_id); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | } |
| 852 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 853 | return status; |
| 854 | } |
| 855 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 856 | static int stop_input_stream(struct stream_in *in) |
| 857 | { |
| 858 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 859 | struct audio_usecase *uc_info; |
| 860 | struct audio_device *adev = in->dev; |
| 861 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 862 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 863 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 864 | ALOGD("%s: enter: usecase(%d: %s)", __func__, |
| 865 | in->usecase, use_case_table[in->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 866 | uc_info = get_usecase_from_list(adev, in->usecase); |
| 867 | if (uc_info == NULL) { |
| 868 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 869 | __func__, in->usecase); |
| 870 | return -EINVAL; |
| 871 | } |
| 872 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 873 | /* 1. Disable stream specific mixer controls */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 874 | disable_audio_route(adev, uc_info, true); |
| 875 | |
| 876 | /* 2. Disable the tx device */ |
| 877 | disable_snd_device(adev, uc_info->in_snd_device, true); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 878 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 879 | list_remove(&uc_info->list); |
| 880 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 881 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 882 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 883 | return ret; |
| 884 | } |
| 885 | |
| 886 | int start_input_stream(struct stream_in *in) |
| 887 | { |
| 888 | /* 1. Enable output device and stream routing controls */ |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 889 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 890 | struct audio_usecase *uc_info; |
| 891 | struct audio_device *adev = in->dev; |
| 892 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 893 | ALOGD("%s: enter: usecase(%d)", __func__, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 894 | in->pcm_device_id = get_pcm_device_id(adev->audio_route, |
| 895 | in->usecase, |
| 896 | PCM_CAPTURE); |
| 897 | if (in->pcm_device_id < 0) { |
| 898 | ALOGE("%s: Could not find PCM device id for the usecase(%d)", |
| 899 | __func__, in->usecase); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 900 | ret = -EINVAL; |
| 901 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 902 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 903 | |
| 904 | adev->active_input = in; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 905 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
| 906 | uc_info->id = in->usecase; |
| 907 | uc_info->type = PCM_CAPTURE; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 908 | uc_info->stream.in = in; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 909 | uc_info->devices = in->device; |
| 910 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 911 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 912 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 913 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 914 | select_devices(adev, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 915 | |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 916 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d", |
| 917 | __func__, SOUND_CARD, in->pcm_device_id, in->config.channels); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 918 | in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id, |
| 919 | PCM_IN, &in->config); |
| 920 | if (in->pcm && !pcm_is_ready(in->pcm)) { |
| 921 | ALOGE("%s: %s", __func__, pcm_get_error(in->pcm)); |
| 922 | pcm_close(in->pcm); |
| 923 | in->pcm = NULL; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 924 | ret = -EIO; |
| 925 | goto error_open; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 926 | } |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 927 | ALOGD("%s: exit", __func__); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 928 | return ret; |
| 929 | |
| 930 | error_open: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 931 | stop_input_stream(in); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 932 | |
| 933 | error_config: |
| 934 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 935 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 936 | |
| 937 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | static int stop_output_stream(struct stream_out *out) |
| 941 | { |
| 942 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 943 | struct audio_usecase *uc_info; |
| 944 | struct audio_device *adev = out->dev; |
| 945 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 946 | ALOGD("%s: enter: usecase(%d: %s)", __func__, |
| 947 | out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 948 | uc_info = get_usecase_from_list(adev, out->usecase); |
| 949 | if (uc_info == NULL) { |
| 950 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 951 | __func__, out->usecase); |
| 952 | return -EINVAL; |
| 953 | } |
| 954 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 955 | /* 1. Get and set stream specific mixer controls */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 956 | disable_audio_route(adev, uc_info, true); |
| 957 | |
| 958 | /* 2. Disable the rx device */ |
| 959 | disable_snd_device(adev, uc_info->out_snd_device, true); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 960 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 961 | list_remove(&uc_info->list); |
| 962 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 963 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 964 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 965 | return ret; |
| 966 | } |
| 967 | |
| 968 | int start_output_stream(struct stream_out *out) |
| 969 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 970 | int ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 971 | struct audio_usecase *uc_info; |
| 972 | struct audio_device *adev = out->dev; |
| 973 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 974 | ALOGD("%s: enter: usecase(%d: %s) devices(%#x)", |
| 975 | __func__, out->usecase, use_case_table[out->usecase], out->devices); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 976 | out->pcm_device_id = get_pcm_device_id(adev->audio_route, |
| 977 | out->usecase, |
| 978 | PCM_PLAYBACK); |
| 979 | if (out->pcm_device_id < 0) { |
| 980 | ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)", |
| 981 | __func__, out->pcm_device_id, out->usecase); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 982 | ret = -EINVAL; |
| 983 | goto error_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
| 987 | uc_info->id = out->usecase; |
| 988 | uc_info->type = PCM_PLAYBACK; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 989 | uc_info->stream.out = out; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 990 | uc_info->devices = out->devices; |
| 991 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 992 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 993 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 994 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 995 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 996 | select_devices(adev, out->usecase); |
| 997 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 998 | ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)", |
| 999 | __func__, 0, out->pcm_device_id); |
| 1000 | out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id, |
| 1001 | PCM_OUT, &out->config); |
| 1002 | if (out->pcm && !pcm_is_ready(out->pcm)) { |
| 1003 | ALOGE("%s: %s", __func__, pcm_get_error(out->pcm)); |
| 1004 | pcm_close(out->pcm); |
| 1005 | out->pcm = NULL; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1006 | ret = -EIO; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1007 | goto error_pcm_open; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1008 | } |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1009 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1010 | return 0; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1011 | error_pcm_open: |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1012 | stop_output_stream(out); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1013 | error_config: |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1014 | return ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static int stop_voice_call(struct audio_device *adev) |
| 1018 | { |
| 1019 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1020 | struct audio_usecase *uc_info; |
| 1021 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1022 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1023 | adev->in_call = false; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1024 | if (adev->csd_client) { |
| 1025 | if (adev->csd_stop_voice == NULL) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1026 | ALOGE("dlsym error for csd_client_disable_device"); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1027 | } else { |
| 1028 | ret = adev->csd_stop_voice(); |
| 1029 | if (ret < 0) { |
| 1030 | ALOGE("%s: csd_client error %d\n", __func__, ret); |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | /* 1. Close the PCM devices */ |
| 1036 | if (adev->voice_call_rx) { |
| 1037 | pcm_close(adev->voice_call_rx); |
| 1038 | adev->voice_call_rx = NULL; |
| 1039 | } |
| 1040 | if (adev->voice_call_tx) { |
| 1041 | pcm_close(adev->voice_call_tx); |
| 1042 | adev->voice_call_tx = NULL; |
| 1043 | } |
| 1044 | |
| 1045 | uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL); |
| 1046 | if (uc_info == NULL) { |
| 1047 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 1048 | __func__, USECASE_VOICE_CALL); |
| 1049 | return -EINVAL; |
| 1050 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1051 | |
| 1052 | /* 2. Get and set stream specific mixer controls */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1053 | disable_audio_route(adev, uc_info, true); |
| 1054 | |
| 1055 | /* 3. Disable the rx and tx devices */ |
| 1056 | disable_snd_device(adev, uc_info->out_snd_device, false); |
| 1057 | disable_snd_device(adev, uc_info->in_snd_device, true); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1058 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1059 | list_remove(&uc_info->list); |
| 1060 | free(uc_info); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1061 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1062 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1063 | return ret; |
| 1064 | } |
| 1065 | |
| 1066 | static int start_voice_call(struct audio_device *adev) |
| 1067 | { |
| 1068 | int i, ret = 0; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1069 | struct audio_usecase *uc_info; |
| 1070 | int pcm_dev_rx_id, pcm_dev_tx_id; |
| 1071 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1072 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1073 | |
| 1074 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
| 1075 | uc_info->id = USECASE_VOICE_CALL; |
| 1076 | uc_info->type = VOICE_CALL; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1077 | uc_info->stream.out = adev->primary_output; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1078 | uc_info->devices = adev->primary_output->devices; |
| 1079 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 1080 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1081 | |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 1082 | list_add_tail(&adev->usecase_list, &uc_info->list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1083 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1084 | select_devices(adev, USECASE_VOICE_CALL); |
| 1085 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1086 | pcm_dev_rx_id = get_pcm_device_id(adev->audio_route, uc_info->id, |
| 1087 | PCM_PLAYBACK); |
| 1088 | pcm_dev_tx_id = get_pcm_device_id(adev->audio_route, uc_info->id, |
| 1089 | PCM_CAPTURE); |
| 1090 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1091 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) { |
| 1092 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)", |
| 1093 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id); |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1094 | ret = -EIO; |
| 1095 | goto error_start_voice; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1096 | } |
| 1097 | |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1098 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1099 | __func__, SOUND_CARD, pcm_dev_rx_id); |
| 1100 | adev->voice_call_rx = pcm_open(SOUND_CARD, |
| 1101 | pcm_dev_rx_id, |
| 1102 | PCM_OUT, &pcm_config_voice_call); |
| 1103 | if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) { |
| 1104 | ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx)); |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1105 | ret = -EIO; |
| 1106 | goto error_start_voice; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1109 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1110 | __func__, SOUND_CARD, pcm_dev_tx_id); |
| 1111 | adev->voice_call_tx = pcm_open(SOUND_CARD, |
| 1112 | pcm_dev_tx_id, |
| 1113 | PCM_IN, &pcm_config_voice_call); |
| 1114 | if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) { |
| 1115 | ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx)); |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1116 | ret = -EIO; |
| 1117 | goto error_start_voice; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1118 | } |
| 1119 | pcm_start(adev->voice_call_rx); |
| 1120 | pcm_start(adev->voice_call_tx); |
| 1121 | |
| 1122 | if (adev->csd_client) { |
| 1123 | if (adev->csd_start_voice == NULL) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1124 | ALOGE("dlsym error for csd_client_start_voice"); |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1125 | goto error_start_voice; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1126 | } else { |
| 1127 | ret = adev->csd_start_voice(); |
| 1128 | if (ret < 0) { |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1129 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 1130 | goto error_start_voice; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | adev->in_call = true; |
Ravi Kumar Alamanda | 8b9c5c8 | 2013-02-20 16:59:34 -0800 | [diff] [blame] | 1136 | return 0; |
| 1137 | |
| 1138 | error_start_voice: |
| 1139 | stop_voice_call(adev); |
| 1140 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1141 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1142 | return ret; |
| 1143 | } |
| 1144 | |
| 1145 | static int check_input_parameters(uint32_t sample_rate, |
| 1146 | audio_format_t format, |
| 1147 | int channel_count) |
| 1148 | { |
| 1149 | if (format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL; |
| 1150 | |
| 1151 | if ((channel_count < 1) || (channel_count > 2)) return -EINVAL; |
| 1152 | |
| 1153 | switch (sample_rate) { |
| 1154 | case 8000: |
| 1155 | case 11025: |
| 1156 | case 12000: |
| 1157 | case 16000: |
| 1158 | case 22050: |
| 1159 | case 24000: |
| 1160 | case 32000: |
| 1161 | case 44100: |
| 1162 | case 48000: |
| 1163 | break; |
| 1164 | default: |
| 1165 | return -EINVAL; |
| 1166 | } |
| 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static size_t get_input_buffer_size(uint32_t sample_rate, |
| 1172 | audio_format_t format, |
| 1173 | int channel_count) |
| 1174 | { |
| 1175 | size_t size = 0; |
| 1176 | |
| 1177 | if (check_input_parameters(sample_rate, format, channel_count) != 0) return 0; |
| 1178 | |
| 1179 | if (sample_rate == 8000 || sample_rate == 16000 || sample_rate == 32000) { |
| 1180 | size = (sample_rate * 20) / 1000; |
| 1181 | } else if (sample_rate == 11025 || sample_rate == 12000) { |
| 1182 | size = 256; |
| 1183 | } else if (sample_rate == 22050 || sample_rate == 24000) { |
| 1184 | size = 512; |
| 1185 | } else if (sample_rate == 44100 || sample_rate == 48000) { |
| 1186 | size = 1024; |
| 1187 | } |
| 1188 | |
| 1189 | return size * sizeof(short) * channel_count; |
| 1190 | } |
| 1191 | |
| 1192 | static uint32_t out_get_sample_rate(const struct audio_stream *stream) |
| 1193 | { |
| 1194 | struct stream_out *out = (struct stream_out *)stream; |
| 1195 | |
| 1196 | return out->config.rate; |
| 1197 | } |
| 1198 | |
| 1199 | static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 1200 | { |
| 1201 | return -ENOSYS; |
| 1202 | } |
| 1203 | |
| 1204 | static size_t out_get_buffer_size(const struct audio_stream *stream) |
| 1205 | { |
| 1206 | struct stream_out *out = (struct stream_out *)stream; |
| 1207 | |
| 1208 | return out->config.period_size * audio_stream_frame_size(stream); |
| 1209 | } |
| 1210 | |
| 1211 | static uint32_t out_get_channels(const struct audio_stream *stream) |
| 1212 | { |
| 1213 | struct stream_out *out = (struct stream_out *)stream; |
| 1214 | |
| 1215 | return out->channel_mask; |
| 1216 | } |
| 1217 | |
| 1218 | static audio_format_t out_get_format(const struct audio_stream *stream) |
| 1219 | { |
| 1220 | return AUDIO_FORMAT_PCM_16_BIT; |
| 1221 | } |
| 1222 | |
| 1223 | static int out_set_format(struct audio_stream *stream, audio_format_t format) |
| 1224 | { |
| 1225 | return -ENOSYS; |
| 1226 | } |
| 1227 | |
| 1228 | static int out_standby(struct audio_stream *stream) |
| 1229 | { |
| 1230 | struct stream_out *out = (struct stream_out *)stream; |
| 1231 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1232 | ALOGD("%s: enter: usecase(%d: %s)", __func__, |
| 1233 | out->usecase, use_case_table[out->usecase]); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1234 | pthread_mutex_lock(&out->lock); |
| 1235 | |
| 1236 | if (!out->standby) { |
| 1237 | out->standby = true; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1238 | if (out->pcm) { |
| 1239 | pcm_close(out->pcm); |
| 1240 | out->pcm = NULL; |
| 1241 | } |
| 1242 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1243 | stop_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1244 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1245 | } |
| 1246 | pthread_mutex_unlock(&out->lock); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1247 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | static int out_dump(const struct audio_stream *stream, int fd) |
| 1252 | { |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
| 1256 | static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 1257 | { |
| 1258 | struct stream_out *out = (struct stream_out *)stream; |
| 1259 | struct audio_device *adev = out->dev; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1260 | struct audio_usecase *usecase; |
| 1261 | struct listnode *node; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1262 | struct str_parms *parms; |
| 1263 | char value[32]; |
| 1264 | int ret, val = 0; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1265 | bool select_new_device = false; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1266 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1267 | ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s", |
| 1268 | __func__, out->usecase, use_case_table[out->usecase], kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1269 | parms = str_parms_create_str(kvpairs); |
| 1270 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 1271 | if (ret >= 0) { |
| 1272 | val = atoi(value); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1273 | pthread_mutex_lock(&out->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1274 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1275 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1276 | /* |
| 1277 | * When HDMI cable is unplugged the music playback is paused and |
| 1278 | * the policy manager sends routing=0. But the audioflinger |
| 1279 | * continues to write data until standby time (3sec). |
| 1280 | * As the HDMI core is turned off, the write gets blocked. |
| 1281 | * Avoid this by routing audio to speaker until standby. |
| 1282 | */ |
| 1283 | if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL && |
| 1284 | val == AUDIO_DEVICE_NONE) { |
| 1285 | val = AUDIO_DEVICE_OUT_SPEAKER; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * select_devices() call below switches all the usecases on the same |
| 1290 | * backend to the new device. Refer to check_usecases_codec_backend() in |
| 1291 | * the select_devices(). But how do we undo this? |
| 1292 | * |
| 1293 | * For example, music playback is active on headset (deep-buffer usecase) |
| 1294 | * and if we go to ringtones and select a ringtone, low-latency usecase |
| 1295 | * will be started on headset+speaker. As we can't enable headset+speaker |
| 1296 | * and headset devices at the same time, select_devices() switches the music |
| 1297 | * playback to headset+speaker while starting low-lateny usecase for ringtone. |
| 1298 | * So when the ringtone playback is completed, how do we undo the same? |
| 1299 | * |
| 1300 | * We are relying on the out_set_parameters() call on deep-buffer output, |
| 1301 | * once the ringtone playback is ended. |
| 1302 | * NOTE: We should not check if the current devices are same as new devices. |
| 1303 | * Because select_devices() must be called to switch back the music |
| 1304 | * playback to headset. |
| 1305 | */ |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1306 | if (val != 0) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1307 | out->devices = val; |
| 1308 | |
| 1309 | if (!out->standby) |
| 1310 | select_devices(adev, out->usecase); |
| 1311 | |
| 1312 | if ((adev->mode == AUDIO_MODE_IN_CALL) && !adev->in_call && |
| 1313 | (out == adev->primary_output)) { |
| 1314 | start_voice_call(adev); |
| 1315 | } else if ((adev->mode == AUDIO_MODE_IN_CALL) && adev->in_call && |
| 1316 | (out == adev->primary_output)) { |
| 1317 | select_devices(adev, USECASE_VOICE_CALL); |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1321 | if ((adev->mode != AUDIO_MODE_IN_CALL) && adev->in_call && |
| 1322 | (out == adev->primary_output)) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1323 | stop_voice_call(adev); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1324 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1325 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1326 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1327 | pthread_mutex_unlock(&out->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1328 | } |
| 1329 | str_parms_destroy(parms); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1330 | ALOGD("%s: exit: code(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1331 | return ret; |
| 1332 | } |
| 1333 | |
| 1334 | static char* out_get_parameters(const struct audio_stream *stream, const char *keys) |
| 1335 | { |
| 1336 | struct stream_out *out = (struct stream_out *)stream; |
| 1337 | struct str_parms *query = str_parms_create_str(keys); |
| 1338 | char *str; |
| 1339 | char value[256]; |
| 1340 | struct str_parms *reply = str_parms_create(); |
| 1341 | size_t i, j; |
| 1342 | int ret; |
| 1343 | bool first = true; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1344 | ALOGD("%s: enter: keys - %s", __func__, keys); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1345 | ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value)); |
| 1346 | if (ret >= 0) { |
| 1347 | value[0] = '\0'; |
| 1348 | i = 0; |
| 1349 | while (out->supported_channel_masks[i] != 0) { |
| 1350 | for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) { |
| 1351 | if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) { |
| 1352 | if (!first) { |
| 1353 | strcat(value, "|"); |
| 1354 | } |
| 1355 | strcat(value, out_channels_name_to_enum_table[j].name); |
| 1356 | first = false; |
| 1357 | break; |
| 1358 | } |
| 1359 | } |
| 1360 | i++; |
| 1361 | } |
| 1362 | str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value); |
| 1363 | str = str_parms_to_str(reply); |
| 1364 | } else { |
| 1365 | str = strdup(keys); |
| 1366 | } |
| 1367 | str_parms_destroy(query); |
| 1368 | str_parms_destroy(reply); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1369 | ALOGD("%s: exit: returns - %s", __func__, str); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1370 | return str; |
| 1371 | } |
| 1372 | |
| 1373 | static uint32_t out_get_latency(const struct audio_stream_out *stream) |
| 1374 | { |
| 1375 | struct stream_out *out = (struct stream_out *)stream; |
| 1376 | |
| 1377 | return (out->config.period_count * out->config.period_size * 1000) / (out->config.rate); |
| 1378 | } |
| 1379 | |
| 1380 | static int out_set_volume(struct audio_stream_out *stream, float left, |
| 1381 | float right) |
| 1382 | { |
| 1383 | return -ENOSYS; |
| 1384 | } |
| 1385 | |
| 1386 | static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, |
| 1387 | size_t bytes) |
| 1388 | { |
| 1389 | struct stream_out *out = (struct stream_out *)stream; |
| 1390 | struct audio_device *adev = out->dev; |
| 1391 | int i, ret = -1; |
| 1392 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1393 | pthread_mutex_lock(&out->lock); |
| 1394 | if (out->standby) { |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1395 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1396 | ret = start_output_stream(out); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1397 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1398 | if (ret != 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1399 | goto exit; |
| 1400 | } |
| 1401 | out->standby = false; |
| 1402 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1403 | |
| 1404 | if (out->pcm) { |
| 1405 | //ALOGV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes); |
| 1406 | ret = pcm_write(out->pcm, (void *)buffer, bytes); |
| 1407 | } |
| 1408 | |
| 1409 | exit: |
| 1410 | pthread_mutex_unlock(&out->lock); |
| 1411 | |
| 1412 | if (ret != 0) { |
| 1413 | out_standby(&out->stream.common); |
| 1414 | usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) / |
| 1415 | out_get_sample_rate(&out->stream.common)); |
| 1416 | } |
| 1417 | return bytes; |
| 1418 | } |
| 1419 | |
| 1420 | static int out_get_render_position(const struct audio_stream_out *stream, |
| 1421 | uint32_t *dsp_frames) |
| 1422 | { |
| 1423 | return -EINVAL; |
| 1424 | } |
| 1425 | |
| 1426 | static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 1427 | { |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
| 1431 | static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 1432 | { |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
| 1436 | static int out_get_next_write_timestamp(const struct audio_stream_out *stream, |
| 1437 | int64_t *timestamp) |
| 1438 | { |
| 1439 | return -EINVAL; |
| 1440 | } |
| 1441 | |
| 1442 | /** audio_stream_in implementation **/ |
| 1443 | static uint32_t in_get_sample_rate(const struct audio_stream *stream) |
| 1444 | { |
| 1445 | struct stream_in *in = (struct stream_in *)stream; |
| 1446 | |
| 1447 | return in->config.rate; |
| 1448 | } |
| 1449 | |
| 1450 | static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) |
| 1451 | { |
| 1452 | return -ENOSYS; |
| 1453 | } |
| 1454 | |
| 1455 | static size_t in_get_buffer_size(const struct audio_stream *stream) |
| 1456 | { |
| 1457 | struct stream_in *in = (struct stream_in *)stream; |
| 1458 | |
| 1459 | return in->config.period_size * audio_stream_frame_size(stream); |
| 1460 | } |
| 1461 | |
| 1462 | static uint32_t in_get_channels(const struct audio_stream *stream) |
| 1463 | { |
| 1464 | struct stream_in *in = (struct stream_in *)stream; |
| 1465 | |
| 1466 | return in->channel_mask; |
| 1467 | } |
| 1468 | |
| 1469 | static audio_format_t in_get_format(const struct audio_stream *stream) |
| 1470 | { |
| 1471 | return AUDIO_FORMAT_PCM_16_BIT; |
| 1472 | } |
| 1473 | |
| 1474 | static int in_set_format(struct audio_stream *stream, audio_format_t format) |
| 1475 | { |
| 1476 | return -ENOSYS; |
| 1477 | } |
| 1478 | |
| 1479 | static int in_standby(struct audio_stream *stream) |
| 1480 | { |
| 1481 | struct stream_in *in = (struct stream_in *)stream; |
| 1482 | struct audio_device *adev = in->dev; |
| 1483 | int status = 0; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1484 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1485 | pthread_mutex_lock(&in->lock); |
| 1486 | if (!in->standby) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1487 | in->standby = true; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1488 | if (in->pcm) { |
| 1489 | pcm_close(in->pcm); |
| 1490 | in->pcm = NULL; |
| 1491 | } |
| 1492 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1493 | status = stop_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1494 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1495 | } |
| 1496 | pthread_mutex_unlock(&in->lock); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1497 | ALOGD("%s: exit: status(%d)", __func__, status); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1498 | return status; |
| 1499 | } |
| 1500 | |
| 1501 | static int in_dump(const struct audio_stream *stream, int fd) |
| 1502 | { |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) |
| 1507 | { |
| 1508 | struct stream_in *in = (struct stream_in *)stream; |
| 1509 | struct audio_device *adev = in->dev; |
| 1510 | struct str_parms *parms; |
| 1511 | char *str; |
| 1512 | char value[32]; |
| 1513 | int ret, val = 0; |
| 1514 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1515 | ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1516 | parms = str_parms_create_str(kvpairs); |
| 1517 | |
| 1518 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value)); |
| 1519 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1520 | pthread_mutex_lock(&in->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1521 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1522 | if (ret >= 0) { |
| 1523 | val = atoi(value); |
| 1524 | /* no audio source uses val == 0 */ |
| 1525 | if ((in->source != val) && (val != 0)) { |
| 1526 | in->source = val; |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value)); |
| 1531 | if (ret >= 0) { |
| 1532 | val = atoi(value); |
| 1533 | if ((in->device != val) && (val != 0)) { |
| 1534 | in->device = val; |
| 1535 | /* If recording is in progress, change the tx device to new device */ |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1536 | if (!in->standby) |
| 1537 | ret = select_devices(adev, in->usecase); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1541 | pthread_mutex_unlock(&adev->lock); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1542 | pthread_mutex_unlock(&in->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1543 | |
| 1544 | str_parms_destroy(parms); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1545 | ALOGD("%s: exit: status(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1546 | return ret; |
| 1547 | } |
| 1548 | |
| 1549 | static char* in_get_parameters(const struct audio_stream *stream, |
| 1550 | const char *keys) |
| 1551 | { |
| 1552 | return strdup(""); |
| 1553 | } |
| 1554 | |
| 1555 | static int in_set_gain(struct audio_stream_in *stream, float gain) |
| 1556 | { |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
| 1560 | static ssize_t in_read(struct audio_stream_in *stream, void *buffer, |
| 1561 | size_t bytes) |
| 1562 | { |
| 1563 | struct stream_in *in = (struct stream_in *)stream; |
| 1564 | struct audio_device *adev = in->dev; |
| 1565 | int i, ret = -1; |
| 1566 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1567 | pthread_mutex_lock(&in->lock); |
| 1568 | if (in->standby) { |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1569 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1570 | ret = start_input_stream(in); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 1571 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1572 | if (ret != 0) { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1573 | goto exit; |
| 1574 | } |
| 1575 | in->standby = 0; |
| 1576 | } |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1577 | |
| 1578 | if (in->pcm) { |
| 1579 | ret = pcm_read(in->pcm, buffer, bytes); |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | * Instead of writing zeroes here, we could trust the hardware |
| 1584 | * to always provide zeroes when muted. |
| 1585 | */ |
| 1586 | if (ret == 0 && adev->mic_mute) |
| 1587 | memset(buffer, 0, bytes); |
| 1588 | |
| 1589 | exit: |
| 1590 | pthread_mutex_unlock(&in->lock); |
| 1591 | |
| 1592 | if (ret != 0) { |
| 1593 | in_standby(&in->stream.common); |
| 1594 | ALOGV("%s: read failed - sleeping for buffer duration", __func__); |
| 1595 | usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) / |
| 1596 | in_get_sample_rate(&in->stream.common)); |
| 1597 | } |
| 1598 | return bytes; |
| 1599 | } |
| 1600 | |
| 1601 | static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) |
| 1602 | { |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
| 1606 | static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 1607 | { |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
| 1611 | static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) |
| 1612 | { |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | static int adev_open_output_stream(struct audio_hw_device *dev, |
| 1617 | audio_io_handle_t handle, |
| 1618 | audio_devices_t devices, |
| 1619 | audio_output_flags_t flags, |
| 1620 | struct audio_config *config, |
| 1621 | struct audio_stream_out **stream_out) |
| 1622 | { |
| 1623 | struct audio_device *adev = (struct audio_device *)dev; |
| 1624 | struct stream_out *out; |
| 1625 | int i, ret; |
| 1626 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1627 | ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)", |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1628 | __func__, config->sample_rate, config->channel_mask, devices, flags); |
| 1629 | *stream_out = NULL; |
| 1630 | out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); |
| 1631 | |
| 1632 | if (devices == AUDIO_DEVICE_NONE) |
| 1633 | devices = AUDIO_DEVICE_OUT_SPEAKER; |
| 1634 | |
| 1635 | out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO; |
| 1636 | out->channel_mask = AUDIO_CHANNEL_OUT_STEREO; |
| 1637 | out->flags = flags; |
| 1638 | out->devices = devices; |
| 1639 | |
| 1640 | /* Init use case and pcm_config */ |
| 1641 | if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT && |
| 1642 | out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 1643 | out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH; |
| 1644 | out->config = pcm_config_hdmi_multi; |
| 1645 | |
| 1646 | pthread_mutex_lock(&adev->lock); |
| 1647 | read_hdmi_channel_masks(out); |
| 1648 | pthread_mutex_unlock(&adev->lock); |
| 1649 | |
| 1650 | if (config->sample_rate == 0) config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1651 | if (config->channel_mask == 0) config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1; |
| 1652 | out->channel_mask = config->channel_mask; |
| 1653 | out->config.rate = config->sample_rate; |
| 1654 | out->config.channels = popcount(out->channel_mask); |
| 1655 | out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2); |
| 1656 | set_hdmi_channels(adev->mixer, out->config.channels); |
| 1657 | } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) { |
| 1658 | out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER; |
| 1659 | out->config = pcm_config_deep_buffer; |
| 1660 | } else { |
| 1661 | out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY; |
| 1662 | out->config = pcm_config_low_latency; |
| 1663 | } |
| 1664 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 1665 | if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) { |
| 1666 | if(adev->primary_output == NULL) |
| 1667 | adev->primary_output = out; |
| 1668 | else { |
| 1669 | ALOGE("%s: Primary output is already opened", __func__); |
| 1670 | return -EEXIST; |
| 1671 | } |
| 1672 | } |
| 1673 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1674 | /* Check if this usecase is already existing */ |
| 1675 | pthread_mutex_lock(&adev->lock); |
| 1676 | if (get_usecase_from_list(adev, out->usecase) != NULL) { |
| 1677 | ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase); |
| 1678 | free(out); |
| 1679 | *stream_out = NULL; |
| 1680 | pthread_mutex_unlock(&adev->lock); |
| 1681 | return -EEXIST; |
| 1682 | } |
| 1683 | pthread_mutex_unlock(&adev->lock); |
| 1684 | |
| 1685 | out->stream.common.get_sample_rate = out_get_sample_rate; |
| 1686 | out->stream.common.set_sample_rate = out_set_sample_rate; |
| 1687 | out->stream.common.get_buffer_size = out_get_buffer_size; |
| 1688 | out->stream.common.get_channels = out_get_channels; |
| 1689 | out->stream.common.get_format = out_get_format; |
| 1690 | out->stream.common.set_format = out_set_format; |
| 1691 | out->stream.common.standby = out_standby; |
| 1692 | out->stream.common.dump = out_dump; |
| 1693 | out->stream.common.set_parameters = out_set_parameters; |
| 1694 | out->stream.common.get_parameters = out_get_parameters; |
| 1695 | out->stream.common.add_audio_effect = out_add_audio_effect; |
| 1696 | out->stream.common.remove_audio_effect = out_remove_audio_effect; |
| 1697 | out->stream.get_latency = out_get_latency; |
| 1698 | out->stream.set_volume = out_set_volume; |
| 1699 | out->stream.write = out_write; |
| 1700 | out->stream.get_render_position = out_get_render_position; |
| 1701 | out->stream.get_next_write_timestamp = out_get_next_write_timestamp; |
| 1702 | |
| 1703 | out->dev = adev; |
| 1704 | out->standby = 1; |
| 1705 | |
| 1706 | config->format = out->stream.common.get_format(&out->stream.common); |
| 1707 | config->channel_mask = out->stream.common.get_channels(&out->stream.common); |
| 1708 | config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common); |
| 1709 | |
| 1710 | *stream_out = &out->stream; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1711 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1712 | return 0; |
| 1713 | } |
| 1714 | |
| 1715 | static void adev_close_output_stream(struct audio_hw_device *dev, |
| 1716 | struct audio_stream_out *stream) |
| 1717 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1718 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1719 | out_standby(&stream->common); |
| 1720 | free(stream); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1721 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) |
| 1725 | { |
| 1726 | struct audio_device *adev = (struct audio_device *)dev; |
| 1727 | struct str_parms *parms; |
| 1728 | char *str; |
| 1729 | char value[32]; |
| 1730 | int ret; |
| 1731 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1732 | ALOGD("%s: enter: %s", __func__, kvpairs); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1733 | |
| 1734 | parms = str_parms_create_str(kvpairs); |
| 1735 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value)); |
| 1736 | if (ret >= 0) { |
| 1737 | int tty_mode; |
| 1738 | |
| 1739 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0) |
| 1740 | tty_mode = TTY_MODE_OFF; |
| 1741 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0) |
| 1742 | tty_mode = TTY_MODE_VCO; |
| 1743 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0) |
| 1744 | tty_mode = TTY_MODE_HCO; |
| 1745 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0) |
| 1746 | tty_mode = TTY_MODE_FULL; |
| 1747 | else |
| 1748 | return -EINVAL; |
| 1749 | |
| 1750 | pthread_mutex_lock(&adev->lock); |
| 1751 | if (tty_mode != adev->tty_mode) { |
| 1752 | adev->tty_mode = tty_mode; |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 1753 | adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode; |
| 1754 | if (adev->in_call) |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1755 | select_devices(adev, USECASE_VOICE_CALL); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1756 | } |
| 1757 | pthread_mutex_unlock(&adev->lock); |
| 1758 | } |
| 1759 | |
| 1760 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); |
| 1761 | if (ret >= 0) { |
| 1762 | /* When set to false, HAL should disable EC and NS |
| 1763 | * But it is currently not supported. |
| 1764 | */ |
| 1765 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 1766 | adev->bluetooth_nrec = true; |
| 1767 | else |
| 1768 | adev->bluetooth_nrec = false; |
| 1769 | } |
| 1770 | |
| 1771 | ret = str_parms_get_str(parms, "screen_state", value, sizeof(value)); |
| 1772 | if (ret >= 0) { |
| 1773 | if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) |
| 1774 | adev->screen_off = false; |
| 1775 | else |
| 1776 | adev->screen_off = true; |
| 1777 | } |
| 1778 | |
| 1779 | str_parms_destroy(parms); |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1780 | ALOGD("%s: exit with code(%d)", __func__, ret); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1781 | return ret; |
| 1782 | } |
| 1783 | |
| 1784 | static char* adev_get_parameters(const struct audio_hw_device *dev, |
| 1785 | const char *keys) |
| 1786 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1787 | return strdup(""); |
| 1788 | } |
| 1789 | |
| 1790 | static int adev_init_check(const struct audio_hw_device *dev) |
| 1791 | { |
| 1792 | return 0; |
| 1793 | } |
| 1794 | |
| 1795 | static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) |
| 1796 | { |
| 1797 | struct audio_device *adev = (struct audio_device *)dev; |
| 1798 | int vol, err = 0; |
| 1799 | |
| 1800 | pthread_mutex_lock(&adev->lock); |
| 1801 | adev->voice_volume = volume; |
| 1802 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 1803 | if (volume < 0.0) { |
| 1804 | volume = 0.0; |
| 1805 | } else if (volume > 1.0) { |
| 1806 | volume = 1.0; |
| 1807 | } |
| 1808 | |
| 1809 | vol = lrint(volume * 100.0); |
| 1810 | |
| 1811 | // Voice volume levels from android are mapped to driver volume levels as follows. |
| 1812 | // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0 |
| 1813 | // So adjust the volume to get the correct volume index in driver |
| 1814 | vol = 100 - vol; |
| 1815 | |
| 1816 | if (adev->csd_client) { |
| 1817 | if (adev->csd_volume == NULL) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1818 | ALOGE("%s: dlsym error for csd_client_volume", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1819 | } else { |
| 1820 | err = adev->csd_volume(vol); |
| 1821 | if (err < 0) { |
| 1822 | ALOGE("%s: csd_client error %d", __func__, err); |
| 1823 | } |
| 1824 | } |
| 1825 | } else { |
| 1826 | ALOGE("%s: No CSD Client present", __func__); |
| 1827 | } |
| 1828 | } |
| 1829 | pthread_mutex_unlock(&adev->lock); |
| 1830 | return err; |
| 1831 | } |
| 1832 | |
| 1833 | static int adev_set_master_volume(struct audio_hw_device *dev, float volume) |
| 1834 | { |
| 1835 | return -ENOSYS; |
| 1836 | } |
| 1837 | |
| 1838 | static int adev_get_master_volume(struct audio_hw_device *dev, |
| 1839 | float *volume) |
| 1840 | { |
| 1841 | return -ENOSYS; |
| 1842 | } |
| 1843 | |
| 1844 | static int adev_set_master_mute(struct audio_hw_device *dev, bool muted) |
| 1845 | { |
| 1846 | return -ENOSYS; |
| 1847 | } |
| 1848 | |
| 1849 | static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted) |
| 1850 | { |
| 1851 | return -ENOSYS; |
| 1852 | } |
| 1853 | |
| 1854 | static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) |
| 1855 | { |
| 1856 | struct audio_device *adev = (struct audio_device *)dev; |
| 1857 | |
| 1858 | pthread_mutex_lock(&adev->lock); |
| 1859 | if (adev->mode != mode) { |
| 1860 | adev->mode = mode; |
| 1861 | } |
| 1862 | pthread_mutex_unlock(&adev->lock); |
| 1863 | return 0; |
| 1864 | } |
| 1865 | |
| 1866 | static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) |
| 1867 | { |
| 1868 | struct audio_device *adev = (struct audio_device *)dev; |
| 1869 | int err = 0; |
| 1870 | |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1871 | pthread_mutex_lock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1872 | adev->mic_mute = state; |
| 1873 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 1874 | if (adev->csd_client) { |
| 1875 | if (adev->csd_mic_mute == NULL) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 1876 | ALOGE("%s: dlsym error for csd_mic_mute", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1877 | } else { |
| 1878 | err = adev->csd_mic_mute(state); |
| 1879 | if (err < 0) { |
| 1880 | ALOGE("%s: csd_client error %d", __func__, err); |
| 1881 | } |
| 1882 | } |
| 1883 | } else { |
| 1884 | ALOGE("%s: No CSD Client present", __func__); |
| 1885 | } |
| 1886 | } |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 1887 | pthread_mutex_unlock(&adev->lock); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1888 | return err; |
| 1889 | } |
| 1890 | |
| 1891 | static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) |
| 1892 | { |
| 1893 | struct audio_device *adev = (struct audio_device *)dev; |
| 1894 | |
| 1895 | *state = adev->mic_mute; |
| 1896 | |
| 1897 | return 0; |
| 1898 | } |
| 1899 | |
| 1900 | static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, |
| 1901 | const struct audio_config *config) |
| 1902 | { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1903 | int channel_count = popcount(config->channel_mask); |
| 1904 | |
| 1905 | return get_input_buffer_size(config->sample_rate, config->format, channel_count); |
| 1906 | } |
| 1907 | |
| 1908 | static int adev_open_input_stream(struct audio_hw_device *dev, |
| 1909 | audio_io_handle_t handle, |
| 1910 | audio_devices_t devices, |
| 1911 | struct audio_config *config, |
| 1912 | struct audio_stream_in **stream_in) |
| 1913 | { |
| 1914 | struct audio_device *adev = (struct audio_device *)dev; |
| 1915 | struct stream_in *in; |
| 1916 | int ret, buffer_size, frame_size; |
| 1917 | int channel_count = popcount(config->channel_mask); |
| 1918 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1919 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1920 | *stream_in = NULL; |
| 1921 | if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0) |
| 1922 | return -EINVAL; |
| 1923 | |
| 1924 | in = (struct stream_in *)calloc(1, sizeof(struct stream_in)); |
| 1925 | |
| 1926 | in->stream.common.get_sample_rate = in_get_sample_rate; |
| 1927 | in->stream.common.set_sample_rate = in_set_sample_rate; |
| 1928 | in->stream.common.get_buffer_size = in_get_buffer_size; |
| 1929 | in->stream.common.get_channels = in_get_channels; |
| 1930 | in->stream.common.get_format = in_get_format; |
| 1931 | in->stream.common.set_format = in_set_format; |
| 1932 | in->stream.common.standby = in_standby; |
| 1933 | in->stream.common.dump = in_dump; |
| 1934 | in->stream.common.set_parameters = in_set_parameters; |
| 1935 | in->stream.common.get_parameters = in_get_parameters; |
| 1936 | in->stream.common.add_audio_effect = in_add_audio_effect; |
| 1937 | in->stream.common.remove_audio_effect = in_remove_audio_effect; |
| 1938 | in->stream.set_gain = in_set_gain; |
| 1939 | in->stream.read = in_read; |
| 1940 | in->stream.get_input_frames_lost = in_get_input_frames_lost; |
| 1941 | |
| 1942 | in->device = devices; |
| 1943 | in->source = AUDIO_SOURCE_DEFAULT; |
| 1944 | in->dev = adev; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1945 | in->standby = 1; |
| 1946 | in->channel_mask = config->channel_mask; |
| 1947 | |
| 1948 | /* Update config params with the requested sample rate and channels */ |
| 1949 | in->usecase = USECASE_AUDIO_RECORD; |
| 1950 | in->config = pcm_config_audio_capture; |
| 1951 | in->config.channels = channel_count; |
| 1952 | in->config.rate = config->sample_rate; |
| 1953 | |
| 1954 | frame_size = audio_stream_frame_size((struct audio_stream *)in); |
| 1955 | buffer_size = get_input_buffer_size(config->sample_rate, |
| 1956 | config->format, |
| 1957 | channel_count); |
| 1958 | in->config.period_size = buffer_size / frame_size; |
| 1959 | |
| 1960 | *stream_in = &in->stream; |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1961 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1962 | return 0; |
| 1963 | |
| 1964 | err_open: |
| 1965 | free(in); |
| 1966 | *stream_in = NULL; |
| 1967 | return ret; |
| 1968 | } |
| 1969 | |
| 1970 | static void adev_close_input_stream(struct audio_hw_device *dev, |
| 1971 | struct audio_stream_in *stream) |
| 1972 | { |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 1973 | ALOGD("%s", __func__); |
| 1974 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1975 | in_standby(&stream->common); |
| 1976 | free(stream); |
| 1977 | |
| 1978 | return; |
| 1979 | } |
| 1980 | |
| 1981 | static int adev_dump(const audio_hw_device_t *device, int fd) |
| 1982 | { |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | static int adev_close(hw_device_t *device) |
| 1987 | { |
| 1988 | struct audio_device *adev = (struct audio_device *)device; |
| 1989 | audio_route_free(adev->audio_route); |
| 1990 | free(device); |
| 1991 | return 0; |
| 1992 | } |
| 1993 | |
| 1994 | static void init_platform_data(struct audio_device *adev) |
| 1995 | { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 1996 | char platform[PROPERTY_VALUE_MAX]; |
| 1997 | char baseband[PROPERTY_VALUE_MAX]; |
| 1998 | char value[PROPERTY_VALUE_MAX]; |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 1999 | |
| 2000 | adev->dualmic_config = DUALMIC_CONFIG_NONE; |
Ravi Kumar Alamanda | 0231779 | 2013-03-04 20:56:50 -0800 | [diff] [blame] | 2001 | adev->fluence_in_spkr_mode = false; |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2002 | adev->fluence_in_voice_call = false; |
| 2003 | adev->fluence_in_voice_rec = false; |
| 2004 | adev->mic_type_analog = false; |
| 2005 | |
| 2006 | property_get("persist.audio.handset.mic.type",value,""); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2007 | if (!strcmp("analog", value)) |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2008 | adev->mic_type_analog = true; |
| 2009 | |
| 2010 | property_get("persist.audio.dualmic.config",value,""); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2011 | if (!strcmp("broadside", value)) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2012 | adev->dualmic_config = DUALMIC_CONFIG_BROADSIDE; |
| 2013 | adev->acdb_settings |= DMIC_FLAG; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2014 | } else if (!strcmp("endfire", value)) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2015 | adev->dualmic_config = DUALMIC_CONFIG_ENDFIRE; |
| 2016 | adev->acdb_settings |= DMIC_FLAG; |
| 2017 | } |
| 2018 | |
| 2019 | if (adev->dualmic_config != DUALMIC_CONFIG_NONE) { |
| 2020 | property_get("persist.audio.fluence.voicecall",value,""); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2021 | if (!strcmp("true", value)) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2022 | adev->fluence_in_voice_call = true; |
| 2023 | } |
| 2024 | |
| 2025 | property_get("persist.audio.fluence.voicerec",value,""); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2026 | if (!strcmp("true", value)) { |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2027 | adev->fluence_in_voice_rec = true; |
| 2028 | } |
Ravi Kumar Alamanda | 0231779 | 2013-03-04 20:56:50 -0800 | [diff] [blame] | 2029 | |
| 2030 | property_get("persist.audio.fluence.speaker",value,""); |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2031 | if (!strcmp("true", value)) { |
Ravi Kumar Alamanda | 0231779 | 2013-03-04 20:56:50 -0800 | [diff] [blame] | 2032 | adev->fluence_in_spkr_mode = true; |
| 2033 | } |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 2034 | } |
| 2035 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2036 | adev->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 2037 | if (adev->acdb_handle == NULL) { |
| 2038 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 2039 | } else { |
| 2040 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2041 | adev->acdb_deallocate = (acdb_deallocate_t)dlsym(adev->acdb_handle, |
| 2042 | "acdb_loader_deallocate_ACDB"); |
| 2043 | adev->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(adev->acdb_handle, |
| 2044 | "acdb_loader_send_audio_cal"); |
| 2045 | adev->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(adev->acdb_handle, |
| 2046 | "acdb_loader_send_voice_cal"); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 2047 | adev->acdb_init = (acdb_init_t)dlsym(adev->acdb_handle, |
| 2048 | "acdb_loader_init_ACDB"); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2049 | if (adev->acdb_init == NULL) |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 2050 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror()); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2051 | else |
| 2052 | adev->acdb_init(); |
| 2053 | } |
| 2054 | |
| 2055 | /* If platform is Fusion3, load CSD Client specific symbols |
| 2056 | * Voice call is handled by MDM and apps processor talks to |
| 2057 | * MDM through CSD Client |
| 2058 | */ |
| 2059 | property_get("ro.board.platform", platform, ""); |
| 2060 | property_get("ro.baseband", baseband, ""); |
| 2061 | if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) { |
| 2062 | adev->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 2063 | if (adev->csd_client == NULL) |
| 2064 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 2065 | } |
| 2066 | |
| 2067 | if (adev->csd_client) { |
| 2068 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2069 | adev->csd_client_deinit = (csd_client_deinit_t)dlsym(adev->csd_client, |
| 2070 | "csd_client_deinit"); |
| 2071 | adev->csd_disable_device = (csd_disable_device_t)dlsym(adev->csd_client, |
| 2072 | "csd_client_disable_device"); |
| 2073 | adev->csd_enable_device = (csd_enable_device_t)dlsym(adev->csd_client, |
| 2074 | "csd_client_enable_device"); |
| 2075 | adev->csd_start_voice = (csd_start_voice_t)dlsym(adev->csd_client, |
| 2076 | "csd_client_start_voice"); |
| 2077 | adev->csd_stop_voice = (csd_stop_voice_t)dlsym(adev->csd_client, |
| 2078 | "csd_client_stop_voice"); |
| 2079 | adev->csd_volume = (csd_volume_t)dlsym(adev->csd_client, |
| 2080 | "csd_client_volume"); |
| 2081 | adev->csd_mic_mute = (csd_mic_mute_t)dlsym(adev->csd_client, |
| 2082 | "csd_client_mic_mute"); |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 2083 | adev->csd_client_init = (csd_client_init_t)dlsym(adev->csd_client, |
| 2084 | "csd_client_init"); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2085 | |
| 2086 | if (adev->csd_client_init == NULL) { |
Ravi Kumar Alamanda | 610e8cc | 2013-02-12 01:42:38 -0800 | [diff] [blame] | 2087 | ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror()); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2088 | } else { |
| 2089 | adev->csd_client_init(); |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | static int adev_open(const hw_module_t *module, const char *name, |
| 2095 | hw_device_t **device) |
| 2096 | { |
| 2097 | struct audio_device *adev; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2098 | int i, ret; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2099 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 2100 | ALOGD("%s: enter", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2101 | if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; |
| 2102 | |
| 2103 | adev = calloc(1, sizeof(struct audio_device)); |
| 2104 | |
| 2105 | adev->mixer = mixer_open(MIXER_CARD); |
| 2106 | if (!adev->mixer) { |
| 2107 | ALOGE("Unable to open the mixer, aborting."); |
| 2108 | return -ENOSYS; |
| 2109 | } |
| 2110 | |
| 2111 | adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH); |
| 2112 | if (!adev->audio_route) { |
| 2113 | free(adev); |
| 2114 | ALOGE("%s: Failed to init audio route controls, aborting.", __func__); |
| 2115 | *device = NULL; |
| 2116 | return -EINVAL; |
| 2117 | } |
| 2118 | |
| 2119 | adev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 2120 | adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0; |
| 2121 | adev->device.common.module = (struct hw_module_t *)module; |
| 2122 | adev->device.common.close = adev_close; |
| 2123 | |
| 2124 | adev->device.init_check = adev_init_check; |
| 2125 | adev->device.set_voice_volume = adev_set_voice_volume; |
| 2126 | adev->device.set_master_volume = adev_set_master_volume; |
| 2127 | adev->device.get_master_volume = adev_get_master_volume; |
| 2128 | adev->device.set_master_mute = adev_set_master_mute; |
| 2129 | adev->device.get_master_mute = adev_get_master_mute; |
| 2130 | adev->device.set_mode = adev_set_mode; |
| 2131 | adev->device.set_mic_mute = adev_set_mic_mute; |
| 2132 | adev->device.get_mic_mute = adev_get_mic_mute; |
| 2133 | adev->device.set_parameters = adev_set_parameters; |
| 2134 | adev->device.get_parameters = adev_get_parameters; |
| 2135 | adev->device.get_input_buffer_size = adev_get_input_buffer_size; |
| 2136 | adev->device.open_output_stream = adev_open_output_stream; |
| 2137 | adev->device.close_output_stream = adev_close_output_stream; |
| 2138 | adev->device.open_input_stream = adev_open_input_stream; |
| 2139 | adev->device.close_input_stream = adev_close_input_stream; |
| 2140 | adev->device.dump = adev_dump; |
| 2141 | |
| 2142 | /* Set the default route before the PCM stream is opened */ |
| 2143 | pthread_mutex_lock(&adev->lock); |
| 2144 | adev->mode = AUDIO_MODE_NORMAL; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 2145 | adev->active_input = NULL; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 2146 | adev->primary_output = NULL; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2147 | adev->out_device = AUDIO_DEVICE_NONE; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2148 | adev->voice_call_rx = NULL; |
| 2149 | adev->voice_call_tx = NULL; |
| 2150 | adev->voice_volume = 1.0f; |
| 2151 | adev->tty_mode = TTY_MODE_OFF; |
| 2152 | adev->bluetooth_nrec = true; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2153 | adev->in_call = false; |
Ravi Kumar Alamanda | f996704 | 2013-02-14 19:35:14 -0800 | [diff] [blame] | 2154 | adev->acdb_settings = TTY_MODE_OFF; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame^] | 2155 | for (i = 0; i < SND_DEVICE_MAX; i++) { |
| 2156 | adev->snd_dev_ref_cnt[i] = 0; |
| 2157 | } |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 2158 | list_init(&adev->usecase_list); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2159 | pthread_mutex_unlock(&adev->lock); |
| 2160 | |
| 2161 | /* Loads platform specific libraries dynamically */ |
| 2162 | init_platform_data(adev); |
| 2163 | |
| 2164 | *device = &adev->device.common; |
| 2165 | |
Ravi Kumar Alamanda | 75d924d | 2013-02-20 21:30:08 -0800 | [diff] [blame] | 2166 | ALOGD("%s: exit", __func__); |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 2167 | return 0; |
| 2168 | } |
| 2169 | |
| 2170 | static struct hw_module_methods_t hal_module_methods = { |
| 2171 | .open = adev_open, |
| 2172 | }; |
| 2173 | |
| 2174 | struct audio_module HAL_MODULE_INFO_SYM = { |
| 2175 | .common = { |
| 2176 | .tag = HARDWARE_MODULE_TAG, |
| 2177 | .module_api_version = AUDIO_MODULE_API_VERSION_0_1, |
| 2178 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 2179 | .id = AUDIO_HARDWARE_MODULE_ID, |
| 2180 | .name = "QCOM Audio HAL", |
| 2181 | .author = "Code Aurora Forum", |
| 2182 | .methods = &hal_module_methods, |
| 2183 | }, |
| 2184 | }; |