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