The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* //device/servers/AudioFlinger/AudioDumpInterface.h |
| 2 | ** |
| 3 | ** Copyright 2008, 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_DUMP_INTERFACE_H |
| 19 | #define ANDROID_AUDIO_DUMP_INTERFACE_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> |
| 24 | #include <utils/SortedVector.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | #include <hardware_legacy/AudioHardwareBase.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 30 | #define AUDIO_DUMP_WAVE_HDR_SIZE 44 |
| 31 | |
| 32 | class AudioDumpInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | class AudioStreamOutDump : public AudioStreamOut { |
| 35 | public: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 36 | AudioStreamOutDump(AudioDumpInterface *interface, |
| 37 | int id, |
| 38 | AudioStreamOut* finalStream, |
| 39 | uint32_t devices, |
| 40 | int format, |
| 41 | uint32_t channels, |
| 42 | uint32_t sampleRate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | ~AudioStreamOutDump(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 45 | virtual ssize_t write(const void* buffer, size_t bytes); |
| 46 | virtual uint32_t sampleRate() const; |
| 47 | virtual size_t bufferSize() const; |
| 48 | virtual uint32_t channels() const; |
| 49 | virtual int format() const; |
| 50 | virtual uint32_t latency() const; |
| 51 | virtual status_t setVolume(float left, float right); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | virtual status_t standby(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 53 | virtual status_t setParameters(const String8& keyValuePairs); |
| 54 | virtual String8 getParameters(const String8& keys); |
| 55 | virtual status_t dump(int fd, const Vector<String16>& args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | void Close(void); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 57 | AudioStreamOut* finalStream() { return mFinalStream; } |
| 58 | uint32_t device() { return mDevice; } |
Eric Laurent | 69682b4 | 2009-08-04 07:29:18 -0700 | [diff] [blame] | 59 | int getId() { return mId; } |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 60 | virtual status_t getRenderPosition(uint32_t *dspFrames); |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | private: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 63 | AudioDumpInterface *mInterface; |
| 64 | int mId; |
| 65 | uint32_t mSampleRate; // |
| 66 | uint32_t mFormat; // |
| 67 | uint32_t mChannels; // output configuration |
| 68 | uint32_t mLatency; // |
| 69 | uint32_t mDevice; // current device this output is routed to |
| 70 | size_t mBufferSize; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | AudioStreamOut *mFinalStream; |
Eric Laurent | fc12466 | 2010-05-12 08:24:18 -0700 | [diff] [blame] | 72 | FILE *mFile; // output file |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 73 | int mFileCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 76 | class AudioStreamInDump : public AudioStreamIn { |
| 77 | public: |
| 78 | AudioStreamInDump(AudioDumpInterface *interface, |
| 79 | int id, |
| 80 | AudioStreamIn* finalStream, |
| 81 | uint32_t devices, |
| 82 | int format, |
| 83 | uint32_t channels, |
| 84 | uint32_t sampleRate); |
| 85 | ~AudioStreamInDump(); |
| 86 | |
| 87 | virtual uint32_t sampleRate() const; |
| 88 | virtual size_t bufferSize() const; |
| 89 | virtual uint32_t channels() const; |
| 90 | virtual int format() const; |
| 91 | |
| 92 | virtual status_t setGain(float gain); |
| 93 | virtual ssize_t read(void* buffer, ssize_t bytes); |
| 94 | virtual status_t standby(); |
| 95 | virtual status_t setParameters(const String8& keyValuePairs); |
| 96 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 97 | virtual unsigned int getInputFramesLost() const; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 98 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 99 | void Close(void); |
| 100 | AudioStreamIn* finalStream() { return mFinalStream; } |
| 101 | uint32_t device() { return mDevice; } |
| 102 | |
| 103 | private: |
| 104 | AudioDumpInterface *mInterface; |
| 105 | int mId; |
| 106 | uint32_t mSampleRate; // |
| 107 | uint32_t mFormat; // |
| 108 | uint32_t mChannels; // output configuration |
| 109 | uint32_t mDevice; // current device this output is routed to |
| 110 | size_t mBufferSize; |
| 111 | AudioStreamIn *mFinalStream; |
Eric Laurent | fc12466 | 2010-05-12 08:24:18 -0700 | [diff] [blame] | 112 | FILE *mFile; // output file |
| 113 | int mFileCount; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 114 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | |
| 116 | class AudioDumpInterface : public AudioHardwareBase |
| 117 | { |
| 118 | |
| 119 | public: |
| 120 | AudioDumpInterface(AudioHardwareInterface* hw); |
| 121 | virtual AudioStreamOut* openOutputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 122 | uint32_t devices, |
| 123 | int *format=0, |
| 124 | uint32_t *channels=0, |
| 125 | uint32_t *sampleRate=0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | status_t *status=0); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 127 | virtual void closeOutputStream(AudioStreamOut* out); |
| 128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | virtual ~AudioDumpInterface(); |
| 130 | |
| 131 | virtual status_t initCheck() |
| 132 | {return mFinalInterface->initCheck();} |
| 133 | virtual status_t setVoiceVolume(float volume) |
| 134 | {return mFinalInterface->setVoiceVolume(volume);} |
| 135 | virtual status_t setMasterVolume(float volume) |
| 136 | {return mFinalInterface->setMasterVolume(volume);} |
| 137 | |
Eric Laurent | fc12466 | 2010-05-12 08:24:18 -0700 | [diff] [blame] | 138 | virtual status_t setMode(int mode); |
| 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | // mic mute |
| 141 | virtual status_t setMicMute(bool state) |
| 142 | {return mFinalInterface->setMicMute(state);} |
| 143 | virtual status_t getMicMute(bool* state) |
| 144 | {return mFinalInterface->getMicMute(state);} |
| 145 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 146 | virtual status_t setParameters(const String8& keyValuePairs); |
| 147 | virtual String8 getParameters(const String8& keys); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
Eric Laurent | fc12466 | 2010-05-12 08:24:18 -0700 | [diff] [blame] | 149 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); |
| 150 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 151 | virtual AudioStreamIn* openInputStream(uint32_t devices, int *format, uint32_t *channels, |
| 152 | uint32_t *sampleRate, status_t *status, AudioSystem::audio_in_acoustics acoustics); |
| 153 | virtual void closeInputStream(AudioStreamIn* in); |
Dave Sparks | a5e2ef0 | 2009-05-19 18:28:20 -0700 | [diff] [blame] | 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | virtual status_t dump(int fd, const Vector<String16>& args) { return mFinalInterface->dumpState(fd, args); } |
| 156 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 157 | String8 fileName() const { return mFileName; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | protected: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 160 | AudioHardwareInterface *mFinalInterface; |
Eric Laurent | fc12466 | 2010-05-12 08:24:18 -0700 | [diff] [blame] | 161 | SortedVector<AudioStreamOutDump *> mOutputs; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 162 | SortedVector<AudioStreamInDump *> mInputs; |
| 163 | Mutex mLock; |
| 164 | String8 mPolicyCommands; |
| 165 | String8 mFileName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | }; // namespace android |
| 169 | |
| 170 | #endif // ANDROID_AUDIO_DUMP_INTERFACE_H |