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