The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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/AudioHardwareBase.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
| 32 | class AudioHardwareGeneric; |
| 33 | |
| 34 | class AudioStreamOutGeneric : public AudioStreamOut { |
| 35 | public: |
| 36 | AudioStreamOutGeneric() : mAudioHardware(0), mFd(-1) {} |
| 37 | virtual ~AudioStreamOutGeneric(); |
| 38 | |
| 39 | virtual status_t set( |
| 40 | AudioHardwareGeneric *hw, |
| 41 | int mFd, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 42 | uint32_t devices, |
| 43 | int *pFormat, |
| 44 | uint32_t *pChannels, |
| 45 | uint32_t *pRate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
| 47 | virtual uint32_t sampleRate() const { return 44100; } |
| 48 | virtual size_t bufferSize() const { return 4096; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 49 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | virtual int format() const { return AudioSystem::PCM_16_BIT; } |
| 51 | virtual uint32_t latency() const { return 20; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 52 | virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | virtual ssize_t write(const void* buffer, size_t bytes); |
| 54 | virtual status_t standby(); |
| 55 | virtual status_t dump(int fd, const Vector<String16>& args); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 56 | virtual status_t setParameters(const String8& keyValuePairs); |
| 57 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 58 | virtual status_t getRenderPosition(uint32_t *dspFrames); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | AudioHardwareGeneric *mAudioHardware; |
| 62 | Mutex mLock; |
| 63 | int mFd; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 64 | uint32_t mDevice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | class AudioStreamInGeneric : public AudioStreamIn { |
| 68 | public: |
| 69 | AudioStreamInGeneric() : mAudioHardware(0), mFd(-1) {} |
| 70 | virtual ~AudioStreamInGeneric(); |
| 71 | |
| 72 | virtual status_t set( |
| 73 | AudioHardwareGeneric *hw, |
| 74 | int mFd, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 75 | uint32_t devices, |
| 76 | int *pFormat, |
| 77 | uint32_t *pChannels, |
| 78 | uint32_t *pRate, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | AudioSystem::audio_in_acoustics acoustics); |
| 80 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 81 | virtual uint32_t sampleRate() const { return 8000; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | virtual size_t bufferSize() const { return 320; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 83 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_IN_MONO; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | virtual int format() const { return AudioSystem::PCM_16_BIT; } |
| 85 | virtual status_t setGain(float gain) { return INVALID_OPERATION; } |
| 86 | virtual ssize_t read(void* buffer, ssize_t bytes); |
| 87 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 88 | virtual status_t standby() { return NO_ERROR; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 89 | virtual status_t setParameters(const String8& keyValuePairs); |
| 90 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 91 | virtual unsigned int getInputFramesLost() const { return 0; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
| 93 | private: |
| 94 | AudioHardwareGeneric *mAudioHardware; |
| 95 | Mutex mLock; |
| 96 | int mFd; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 97 | uint32_t mDevice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | |
| 101 | class AudioHardwareGeneric : public AudioHardwareBase |
| 102 | { |
| 103 | public: |
| 104 | AudioHardwareGeneric(); |
| 105 | virtual ~AudioHardwareGeneric(); |
| 106 | virtual status_t initCheck(); |
| 107 | virtual status_t setVoiceVolume(float volume); |
| 108 | virtual status_t setMasterVolume(float volume); |
| 109 | |
| 110 | // mic mute |
| 111 | virtual status_t setMicMute(bool state); |
| 112 | virtual status_t getMicMute(bool* state); |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | // create I/O streams |
| 115 | virtual AudioStreamOut* openOutputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 116 | uint32_t devices, |
| 117 | int *format=0, |
| 118 | uint32_t *channels=0, |
| 119 | uint32_t *sampleRate=0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | status_t *status=0); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 121 | virtual void closeOutputStream(AudioStreamOut* out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
| 123 | virtual AudioStreamIn* openInputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 124 | uint32_t devices, |
| 125 | int *format, |
| 126 | uint32_t *channels, |
| 127 | uint32_t *sampleRate, |
Dave Sparks | ad216e5 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 128 | status_t *status, |
| 129 | AudioSystem::audio_in_acoustics acoustics); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 130 | virtual void closeInputStream(AudioStreamIn* in); |
Dave Sparks | ad216e5 | 2009-05-19 14:38:46 -0700 | [diff] [blame] | 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | void closeOutputStream(AudioStreamOutGeneric* out); |
| 133 | void closeInputStream(AudioStreamInGeneric* in); |
| 134 | protected: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 136 | |
| 137 | private: |
| 138 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 139 | |
| 140 | Mutex mLock; |
| 141 | AudioStreamOutGeneric *mOutput; |
| 142 | AudioStreamInGeneric *mInput; |
| 143 | int mFd; |
| 144 | bool mMicMute; |
| 145 | }; |
| 146 | |
| 147 | // ---------------------------------------------------------------------------- |
| 148 | |
| 149 | }; // namespace android |
| 150 | |
| 151 | #endif // ANDROID_AUDIO_HARDWARE_GENERIC_H |