1 /* 2 ** Copyright 2008, Google Inc. 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 #ifndef ANDROID_AUDIO_HARDWARE_H 18 #define ANDROID_AUDIO_HARDWARE_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <utils/threads.h> 24 #include <utils/SortedVector.h> 25 26 #include <hardware_legacy/AudioHardwareBase.h> 27 28 namespace android { 29 30 // ---------------------------------------------------------------------------- 31 // Kernel driver interface 32 // 33 /* Source (TX) devices */ 34 #define ADSP_AUDIO_DEVICE_ID_HANDSET_MIC 0x107ac8d 35 #define ADSP_AUDIO_DEVICE_ID_HEADSET_MIC 0x1081510 36 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC 0x1081512 37 #define ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC 0x1081518 38 #define ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC 0x108151b 39 #define ADSP_AUDIO_DEVICE_ID_I2S_MIC 0x1089bf3 40 41 /* Special loopback pseudo device to be paired with an RX device */ 42 /* with usage ADSP_AUDIO_DEVICE_USAGE_MIXED_PCM_LOOPBACK */ 43 #define ADSP_AUDIO_DEVICE_ID_MIXED_PCM_LOOPBACK_TX 0x1089bf2 44 45 /* Sink (RX) devices */ 46 #define ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR 0x107ac88 47 #define ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO 0x1081511 48 #define ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO 0x107ac8a 49 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO 0x1081513 50 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET 0x108c508 51 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_STEREO_HEADSET 0x108c894 52 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO 0x1081514 53 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_MONO_HEADSET 0x108c895 54 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_STEREO_HEADSET 0x108c509 55 #define ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR 0x1081519 56 #define ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR 0x108151c 57 #define ADSP_AUDIO_DEVICE_ID_I2S_SPKR 0x1089bf4 58 59 #define HANDSET_MIC ADSP_AUDIO_DEVICE_ID_HANDSET_MIC 60 #define HANDSET_SPKR ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR 61 #define HEADSET_MIC ADSP_AUDIO_DEVICE_ID_HEADSET_MIC 62 #define HEADSET_SPKR_MONO ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO 63 #define HEADSET_SPKR_STEREO ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO 64 #define SPKR_PHONE_MIC ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC 65 #define SPKR_PHONE_MONO ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO 66 #define SPKR_PHONE_STEREO ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO 67 #define BT_A2DP_SPKR ADSP_AUDIO_DEVICE_ID_BT_A2DP_SPKR 68 #define BT_SCO_MIC ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC 69 #define BT_SCO_SPKR ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR 70 #define TTY_HEADSET_MIC ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC 71 #define TTY_HEADSET_SPKR ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR 72 #define FM_HEADSET ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO 73 #define FM_SPKR ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO 74 #define SPKR_PHONE_HEADSET_STEREO ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET 75 76 #define ACDB_ID_EXT_MIC_REC 307 77 #define ACDB_ID_HEADSET_PLAYBACK 407 78 #define ACDB_ID_HEADSET_RINGTONE_PLAYBACK 408 79 #define ACDB_ID_INT_MIC_REC 507 80 #define ACDB_ID_CAMCORDER 508 81 #define ACDB_ID_INT_MIC_VR 509 82 #define ACDB_ID_SPKR_PLAYBACK 607 83 84 #define SAMP_RATE_INDX_8000 0 85 #define SAMP_RATE_INDX_11025 1 86 #define SAMP_RATE_INDX_12000 2 87 #define SAMP_RATE_INDX_16000 3 88 #define SAMP_RATE_INDX_22050 4 89 #define SAMP_RATE_INDX_24000 5 90 #define SAMP_RATE_INDX_32000 6 91 #define SAMP_RATE_INDX_44100 7 92 #define SAMP_RATE_INDX_48000 8 93 94 #define EQ_MAX_BAND_NUM 12 95 96 #define ADRC_ENABLE 0x0001 97 #define ADRC_DISABLE 0x0000 98 #define EQ_ENABLE 0x0002 99 #define EQ_DISABLE 0x0000 100 #define RX_IIR_ENABLE 0x0004 101 #define RX_IIR_DISABLE 0x0000 102 103 #define KEY_A1026_VR_MODE "vr_mode" 104 105 struct msm_bt_endpoint { 106 int tx; 107 int rx; 108 char name[64]; 109 }; 110 111 struct eq_filter_type { 112 int16_t gain; 113 uint16_t freq; 114 uint16_t type; 115 uint16_t qf; 116 }; 117 118 struct eqalizer { 119 uint16_t bands; 120 uint16_t params[132]; 121 }; 122 123 struct rx_iir_filter { 124 uint16_t num_bands; 125 uint16_t iir_params[48]; 126 }; 127 128 struct msm_audio_config { 129 uint32_t buffer_size; 130 uint32_t buffer_count; 131 uint32_t channel_count; 132 uint32_t sample_rate; 133 uint32_t codec_type; 134 uint32_t unused[3]; 135 }; 136 137 struct msm_mute_info { 138 uint32_t mute; 139 uint32_t path; 140 }; 141 142 #define CODEC_TYPE_PCM 0 143 #define PCM_FILL_BUFFER_COUNT 1 144 #define AUDIO_HW_NUM_OUT_BUF 2 // Number of buffers in audio driver for output 145 // TODO: determine actual audio DSP and hardware latency 146 #define AUDIO_HW_OUT_LATENCY_MS 0 // Additionnal latency introduced by audio DSP and hardware in ms 147 148 #define AUDIO_HW_IN_SAMPLERATE 8000 // Default audio input sample rate 149 #define AUDIO_HW_IN_CHANNELS (AudioSystem::CHANNEL_IN_MONO) // Default audio input channel mask 150 #define AUDIO_HW_IN_BUFFERSIZE 2048 // Default audio input buffer size 151 #define AUDIO_KERNEL_PCM_IN_BUFFERSIZE 2048 152 #define AUDIO_HW_IN_FORMAT (AudioSystem::PCM_16_BIT) // Default audio input sample format 153 // ---------------------------------------------------------------------------- 154 155 156 class AudioHardware : public AudioHardwareBase 157 { 158 class AudioStreamOutMSM72xx; 159 class AudioStreamInMSM72xx; 160 161 public: 162 AudioHardware(); 163 virtual ~AudioHardware(); 164 virtual status_t initCheck(); 165 166 virtual status_t setVoiceVolume(float volume); 167 virtual status_t setMasterVolume(float volume); 168 169 virtual status_t setMode(int mode); 170 171 // mic mute 172 virtual status_t setMicMute(bool state); 173 virtual status_t getMicMute(bool* state); 174 175 virtual status_t setParameters(const String8& keyValuePairs); 176 virtual String8 getParameters(const String8& keys); 177 178 // create I/O streams 179 virtual AudioStreamOut* openOutputStream( 180 uint32_t devices, 181 int *format=0, 182 uint32_t *channels=0, 183 uint32_t *sampleRate=0, 184 status_t *status=0); 185 186 virtual AudioStreamIn* openInputStream( 187 188 uint32_t devices, 189 int *format, 190 uint32_t *channels, 191 uint32_t *sampleRate, 192 status_t *status, 193 AudioSystem::audio_in_acoustics acoustics); 194 195 virtual void closeOutputStream(AudioStreamOut* out); 196 virtual void closeInputStream(AudioStreamIn* in); 197 198 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 199 200 protected: 201 virtual status_t dump(int fd, const Vector<String16>& args); 202 203 private: 204 205 status_t doAudioRouteOrMute(uint32_t device); 206 status_t setMicMute_nosync(bool state); 207 status_t checkMicMute(); 208 status_t dumpInternals(int fd, const Vector<String16>& args); 209 uint32_t getInputSampleRate(uint32_t sampleRate); 210 bool checkOutputStandby(); 211 status_t get_mMode(); 212 status_t get_mRoutes(); 213 status_t set_mRecordState(bool onoff); 214 status_t doA1026_init(); 215 status_t get_snd_dev(); 216 status_t doAudience_A1026_Control(int Mode, bool Record, uint32_t Routes); 217 status_t doRouting(AudioStreamInMSM72xx *input); 218 status_t updateACDB(); 219 status_t updateBT(); 220 221 class AudioStreamOutMSM72xx : public AudioStreamOut { 222 public: 223 AudioStreamOutMSM72xx(); 224 virtual ~AudioStreamOutMSM72xx(); 225 status_t set(AudioHardware* mHardware, 226 uint32_t devices, 227 int *pFormat, 228 uint32_t *pChannels, 229 uint32_t *pRate); sampleRate()230 virtual uint32_t sampleRate() const { return 44100; } 231 // must be 32-bit aligned - driver only seems to like 4800 bufferSize()232 virtual size_t bufferSize() const { return 4800; } channels()233 virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } format()234 virtual int format() const { return AudioSystem::PCM_16_BIT; } latency()235 virtual uint32_t latency() const { return (1000*AUDIO_HW_NUM_OUT_BUF*(bufferSize()/frameSize()))/sampleRate()+AUDIO_HW_OUT_LATENCY_MS; } setVolume(float left,float right)236 virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 237 virtual ssize_t write(const void* buffer, size_t bytes); 238 virtual status_t standby(); 239 virtual status_t dump(int fd, const Vector<String16>& args); 240 bool checkStandby(); 241 virtual status_t setParameters(const String8& keyValuePairs); 242 virtual String8 getParameters(const String8& keys); devices()243 uint32_t devices() { return mDevices; } 244 245 private: 246 AudioHardware* mHardware; 247 int mFd; 248 int mStartCount; 249 int mRetryCount; 250 bool mStandby; 251 uint32_t mDevices; 252 }; 253 254 class AudioStreamInMSM72xx : public AudioStreamIn { 255 public: 256 enum input_state { 257 AUDIO_INPUT_CLOSED, 258 AUDIO_INPUT_OPENED, 259 AUDIO_INPUT_STARTED 260 }; 261 262 AudioStreamInMSM72xx(); 263 virtual ~AudioStreamInMSM72xx(); 264 status_t set(AudioHardware* mHardware, 265 uint32_t devices, 266 int *pFormat, 267 uint32_t *pChannels, 268 uint32_t *pRate, 269 AudioSystem::audio_in_acoustics acoustics); bufferSize()270 virtual size_t bufferSize() const { return mBufferSize; } channels()271 virtual uint32_t channels() const { return mChannels; } format()272 virtual int format() const { return mFormat; } sampleRate()273 virtual uint32_t sampleRate() const { return mSampleRate; } setGain(float gain)274 virtual status_t setGain(float gain) { return INVALID_OPERATION; } 275 virtual ssize_t read(void* buffer, ssize_t bytes); 276 virtual status_t dump(int fd, const Vector<String16>& args); 277 virtual status_t standby(); 278 virtual status_t setParameters(const String8& keyValuePairs); 279 virtual String8 getParameters(const String8& keys); devices()280 uint32_t devices() { return mDevices; } 281 282 private: 283 AudioHardware* mHardware; 284 int mFd; 285 int mState; 286 int mRetryCount; 287 int mFormat; 288 uint32_t mChannels; 289 uint32_t mSampleRate; 290 size_t mBufferSize; 291 AudioSystem::audio_in_acoustics mAcoustics; 292 uint32_t mDevices; 293 }; 294 295 static const uint32_t inputSamplingRates[]; 296 Mutex mA1026Lock; 297 bool mA1026Init; 298 bool mRecordState; 299 bool mInit; 300 bool mMicMute; 301 bool mBluetoothNrec; 302 uint32_t mBluetoothIdTx; 303 uint32_t mBluetoothIdRx; 304 AudioStreamOutMSM72xx* mOutput; 305 SortedVector <AudioStreamInMSM72xx*> mInputs; 306 307 msm_bt_endpoint *mBTEndpoints; 308 int mNumBTEndpoints; 309 int mCurSndDevice; 310 int mNoiseSuppressionState; 311 312 friend class AudioStreamInMSM72xx; 313 Mutex mLock; 314 uint32_t mRoutes[AudioSystem::NUM_MODES]; 315 }; 316 317 // ---------------------------------------------------------------------------- 318 319 }; // namespace android 320 321 #endif // ANDROID_AUDIO_HARDWARE_MSM72XX_H 322