1 /* 2 ** 3 ** Copyright 2007, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef ANDROID_AUDIO_HARDWARE_GENERIC_H 19 #define ANDROID_AUDIO_HARDWARE_GENERIC_H 20 21 #include <stdint.h> 22 #include <sys/types.h> 23 24 #include <utils/threads.h> 25 26 #include <hardware_legacy/AudioSystemLegacy.h> 27 #include <hardware_legacy/AudioHardwareBase.h> 28 29 namespace android_audio_legacy { 30 using android::Mutex; 31 using android::AutoMutex; 32 33 // ---------------------------------------------------------------------------- 34 35 class AudioHardwareGeneric; 36 37 class AudioStreamOutGeneric : public AudioStreamOut { 38 public: AudioStreamOutGeneric()39 AudioStreamOutGeneric() : mAudioHardware(0), mFd(-1) {} 40 virtual ~AudioStreamOutGeneric(); 41 42 virtual status_t set( 43 AudioHardwareGeneric *hw, 44 int mFd, 45 uint32_t devices, 46 int *pFormat, 47 uint32_t *pChannels, 48 uint32_t *pRate); 49 sampleRate()50 virtual uint32_t sampleRate() const { return 44100; } bufferSize()51 virtual size_t bufferSize() const { return 4096; } channels()52 virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } format()53 virtual int format() const { return AudioSystem::PCM_16_BIT; } latency()54 virtual uint32_t latency() const { return 20; } setVolume(float left,float right)55 virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 56 virtual ssize_t write(const void* buffer, size_t bytes); 57 virtual status_t standby(); 58 virtual status_t dump(int fd, const Vector<String16>& args); 59 virtual status_t setParameters(const String8& keyValuePairs); 60 virtual String8 getParameters(const String8& keys); 61 virtual status_t getRenderPosition(uint32_t *dspFrames); 62 63 private: 64 AudioHardwareGeneric *mAudioHardware; 65 Mutex mLock; 66 int mFd; 67 uint32_t mDevice; 68 }; 69 70 class AudioStreamInGeneric : public AudioStreamIn { 71 public: AudioStreamInGeneric()72 AudioStreamInGeneric() : mAudioHardware(0), mFd(-1) {} 73 virtual ~AudioStreamInGeneric(); 74 75 virtual status_t set( 76 AudioHardwareGeneric *hw, 77 int mFd, 78 uint32_t devices, 79 int *pFormat, 80 uint32_t *pChannels, 81 uint32_t *pRate, 82 AudioSystem::audio_in_acoustics acoustics); 83 sampleRate()84 virtual uint32_t sampleRate() const { return 8000; } bufferSize()85 virtual size_t bufferSize() const { return 320; } channels()86 virtual uint32_t channels() const { return AudioSystem::CHANNEL_IN_MONO; } format()87 virtual int format() const { return AudioSystem::PCM_16_BIT; } setGain(float gain)88 virtual status_t setGain(float gain) { return INVALID_OPERATION; } 89 virtual ssize_t read(void* buffer, ssize_t bytes); 90 virtual status_t dump(int fd, const Vector<String16>& args); standby()91 virtual status_t standby() { return NO_ERROR; } 92 virtual status_t setParameters(const String8& keyValuePairs); 93 virtual String8 getParameters(const String8& keys); getInputFramesLost()94 virtual unsigned int getInputFramesLost() const { return 0; } 95 96 private: 97 AudioHardwareGeneric *mAudioHardware; 98 Mutex mLock; 99 int mFd; 100 uint32_t mDevice; 101 }; 102 103 104 class AudioHardwareGeneric : public AudioHardwareBase 105 { 106 public: 107 AudioHardwareGeneric(); 108 virtual ~AudioHardwareGeneric(); 109 virtual status_t initCheck(); 110 virtual status_t setVoiceVolume(float volume); 111 virtual status_t setMasterVolume(float volume); 112 113 // mic mute 114 virtual status_t setMicMute(bool state); 115 virtual status_t getMicMute(bool* state); 116 117 // create I/O streams 118 virtual AudioStreamOut* openOutputStream( 119 uint32_t devices, 120 int *format=0, 121 uint32_t *channels=0, 122 uint32_t *sampleRate=0, 123 status_t *status=0); 124 virtual void closeOutputStream(AudioStreamOut* out); 125 126 virtual AudioStreamIn* openInputStream( 127 uint32_t devices, 128 int *format, 129 uint32_t *channels, 130 uint32_t *sampleRate, 131 status_t *status, 132 AudioSystem::audio_in_acoustics acoustics); 133 virtual void closeInputStream(AudioStreamIn* in); 134 135 void closeOutputStream(AudioStreamOutGeneric* out); 136 void closeInputStream(AudioStreamInGeneric* in); 137 protected: 138 virtual status_t dump(int fd, const Vector<String16>& args); 139 140 private: 141 status_t dumpInternals(int fd, const Vector<String16>& args); 142 143 Mutex mLock; 144 AudioStreamOutGeneric *mOutput; 145 AudioStreamInGeneric *mInput; 146 int mFd; 147 bool mMicMute; 148 }; 149 150 // ---------------------------------------------------------------------------- 151 152 }; // namespace android 153 154 #endif // ANDROID_AUDIO_HARDWARE_GENERIC_H 155