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