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