1 /* 2 ** Copyright 2008, 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 #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 #define CODEC_TYPE_PCM 0 31 #define PCM_FILL_BUFFER_COUNT 1 32 #define AUDIO_HW_NUM_OUT_BUF 2 // Number of buffers in audio driver for output 33 34 // TODO: determine actual audio DSP and hardware latency 35 #define AUDIO_HW_OUT_LATENCY_MS 0 // Additionnal latency introduced by audio DSP and hardware in ms 36 #define AUDIO_HW_OUT_SAMPLERATE 44100 // Default audio output sample rate 37 #define AUDIO_HW_OUT_CHANNELS (AudioSystem::CHANNEL_OUT_STEREO) // Default audio output channel mask 38 #define AUDIO_HW_OUT_FORMAT (AudioSystem::PCM_16_BIT) // Default audio output sample format 39 #define AUDIO_HW_OUT_BUFSZ 4096 // Default audio output buffer size 40 41 #if 0 42 #define AUDIO_HW_IN_SAMPLERATE 8000 // Default audio input sample rate 43 #define AUDIO_HW_IN_CHANNELS (AudioSystem::CHANNEL_IN_MONO) // Default audio input channel mask 44 #define AUDIO_HW_IN_FORMAT (AudioSystem::PCM_16_BIT) // Default audio input sample format 45 #define AUDIO_HW_IN_BUFSZ 256 // Default audio input buffer size 46 47 #define VOICE_VOLUME_MAX 5 // Maximum voice volume 48 #endif 49 50 class AudioHardware : public AudioHardwareBase 51 { 52 class AudioStreamOutQ5V2; 53 54 public: 55 AudioHardware(); 56 virtual ~AudioHardware(); 57 virtual status_t initCheck(); 58 59 virtual status_t setVoiceVolume(float volume); 60 virtual status_t setMasterVolume(float volume); 61 62 virtual status_t setMode(int mode); 63 64 virtual status_t setMicMute(bool state); 65 virtual status_t getMicMute(bool* state); 66 67 virtual status_t setParameters(const String8& keyValuePairs); 68 virtual String8 getParameters(const String8& keys); 69 70 virtual AudioStreamOut* openOutputStream( 71 uint32_t devices, 72 int *format=0, 73 uint32_t *channels=0, 74 uint32_t *sampleRate=0, 75 status_t *status=0); 76 77 virtual AudioStreamIn* openInputStream( 78 uint32_t devices, 79 int *format, 80 uint32_t *channels, 81 uint32_t *sampleRate, 82 status_t *status, 83 AudioSystem::audio_in_acoustics acoustics); 84 85 virtual void closeOutputStream(AudioStreamOut* out); 86 virtual void closeInputStream(AudioStreamIn* in); 87 88 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 89 clearCurDevice()90 void clearCurDevice() { } 91 92 protected: 93 virtual status_t dump(int fd, const Vector<String16>& args); 94 95 private: 96 97 class AudioStreamOutQ5V2 : public AudioStreamOut { 98 public: 99 AudioStreamOutQ5V2(); 100 virtual ~AudioStreamOutQ5V2(); 101 status_t set(AudioHardware* mHardware, 102 uint32_t devices, 103 int *pFormat, 104 uint32_t *pChannels, 105 uint32_t *pRate); sampleRate()106 virtual uint32_t sampleRate() const { return mSampleRate; } 107 // must be 32-bit aligned bufferSize()108 virtual size_t bufferSize() const { return mBufferSize; } channels()109 virtual uint32_t channels() const { return mChannels; } format()110 virtual int format() const { return AUDIO_HW_OUT_FORMAT; } latency()111 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)112 virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 113 virtual ssize_t write(const void* buffer, size_t bytes); 114 virtual status_t standby(); 115 virtual status_t dump(int fd, const Vector<String16>& args); 116 bool checkStandby(); 117 virtual status_t setParameters(const String8& keyValuePairs); 118 virtual String8 getParameters(const String8& keys); devices()119 uint32_t devices() { return mDevices; } 120 virtual status_t getRenderPosition(uint32_t *dspFrames); 121 122 private: 123 AudioHardware* mHardware; 124 int mFd; 125 int mStartCount; 126 int mRetryCount; 127 bool mStandby; 128 uint32_t mDevices; 129 uint32_t mChannels; 130 uint32_t mSampleRate; 131 size_t mBufferSize; 132 }; 133 134 bool mInit; 135 bool mMicMute; 136 137 AudioStreamOutQ5V2* mOutput; 138 Mutex mLock; 139 }; 140 141 142 }; // namespace android 143 144 #endif // ANDROID_AUDIO_HARDWARE_MSM72XX_H 145