1*79330504STreehugger Robot /* //device/servers/AudioFlinger/AudioDumpInterface.h 2*79330504STreehugger Robot ** 3*79330504STreehugger Robot ** Copyright 2008, The Android Open Source Project 4*79330504STreehugger Robot ** 5*79330504STreehugger Robot ** Licensed under the Apache License, Version 2.0 (the "License"); 6*79330504STreehugger Robot ** you may not use this file except in compliance with the License. 7*79330504STreehugger Robot ** You may obtain a copy of the License at 8*79330504STreehugger Robot ** 9*79330504STreehugger Robot ** http://www.apache.org/licenses/LICENSE-2.0 10*79330504STreehugger Robot ** 11*79330504STreehugger Robot ** Unless required by applicable law or agreed to in writing, software 12*79330504STreehugger Robot ** distributed under the License is distributed on an "AS IS" BASIS, 13*79330504STreehugger Robot ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*79330504STreehugger Robot ** See the License for the specific language governing permissions and 15*79330504STreehugger Robot ** limitations under the License. 16*79330504STreehugger Robot */ 17*79330504STreehugger Robot 18*79330504STreehugger Robot #ifndef ANDROID_AUDIO_DUMP_INTERFACE_H 19*79330504STreehugger Robot #define ANDROID_AUDIO_DUMP_INTERFACE_H 20*79330504STreehugger Robot 21*79330504STreehugger Robot #include <stdint.h> 22*79330504STreehugger Robot #include <sys/types.h> 23*79330504STreehugger Robot #include <utils/String8.h> 24*79330504STreehugger Robot #include <utils/SortedVector.h> 25*79330504STreehugger Robot 26*79330504STreehugger Robot #include <hardware_legacy/AudioHardwareBase.h> 27*79330504STreehugger Robot 28*79330504STreehugger Robot namespace android { 29*79330504STreehugger Robot 30*79330504STreehugger Robot #define AUDIO_DUMP_WAVE_HDR_SIZE 44 31*79330504STreehugger Robot 32*79330504STreehugger Robot class AudioDumpInterface; 33*79330504STreehugger Robot 34*79330504STreehugger Robot class AudioStreamOutDump : public AudioStreamOut { 35*79330504STreehugger Robot public: 36*79330504STreehugger Robot AudioStreamOutDump(AudioDumpInterface *interface, 37*79330504STreehugger Robot int id, 38*79330504STreehugger Robot AudioStreamOut* finalStream, 39*79330504STreehugger Robot uint32_t devices, 40*79330504STreehugger Robot int format, 41*79330504STreehugger Robot uint32_t channels, 42*79330504STreehugger Robot uint32_t sampleRate); 43*79330504STreehugger Robot ~AudioStreamOutDump(); 44*79330504STreehugger Robot 45*79330504STreehugger Robot virtual ssize_t write(const void* buffer, size_t bytes); 46*79330504STreehugger Robot virtual uint32_t sampleRate() const; 47*79330504STreehugger Robot virtual size_t bufferSize() const; 48*79330504STreehugger Robot virtual uint32_t channels() const; 49*79330504STreehugger Robot virtual int format() const; 50*79330504STreehugger Robot virtual uint32_t latency() const; 51*79330504STreehugger Robot virtual status_t setVolume(float left, float right); 52*79330504STreehugger Robot virtual status_t standby(); 53*79330504STreehugger Robot virtual status_t setParameters(const String8& keyValuePairs); 54*79330504STreehugger Robot virtual String8 getParameters(const String8& keys); 55*79330504STreehugger Robot virtual status_t dump(int fd, const Vector<String16>& args); 56*79330504STreehugger Robot void Close(void); finalStream()57*79330504STreehugger Robot AudioStreamOut* finalStream() { return mFinalStream; } device()58*79330504STreehugger Robot uint32_t device() { return mDevice; } getId()59*79330504STreehugger Robot int getId() { return mId; } 60*79330504STreehugger Robot virtual status_t getRenderPosition(uint32_t *dspFrames); 61*79330504STreehugger Robot 62*79330504STreehugger Robot private: 63*79330504STreehugger Robot AudioDumpInterface *mInterface; 64*79330504STreehugger Robot int mId; 65*79330504STreehugger Robot uint32_t mSampleRate; // 66*79330504STreehugger Robot uint32_t mFormat; // 67*79330504STreehugger Robot uint32_t mChannels; // output configuration 68*79330504STreehugger Robot uint32_t mLatency; // 69*79330504STreehugger Robot uint32_t mDevice; // current device this output is routed to 70*79330504STreehugger Robot size_t mBufferSize; 71*79330504STreehugger Robot AudioStreamOut *mFinalStream; 72*79330504STreehugger Robot FILE *mFile; // output file 73*79330504STreehugger Robot int mFileCount; 74*79330504STreehugger Robot }; 75*79330504STreehugger Robot 76*79330504STreehugger Robot class AudioStreamInDump : public AudioStreamIn { 77*79330504STreehugger Robot public: 78*79330504STreehugger Robot AudioStreamInDump(AudioDumpInterface *interface, 79*79330504STreehugger Robot int id, 80*79330504STreehugger Robot AudioStreamIn* finalStream, 81*79330504STreehugger Robot uint32_t devices, 82*79330504STreehugger Robot int format, 83*79330504STreehugger Robot uint32_t channels, 84*79330504STreehugger Robot uint32_t sampleRate); 85*79330504STreehugger Robot ~AudioStreamInDump(); 86*79330504STreehugger Robot 87*79330504STreehugger Robot virtual uint32_t sampleRate() const; 88*79330504STreehugger Robot virtual size_t bufferSize() const; 89*79330504STreehugger Robot virtual uint32_t channels() const; 90*79330504STreehugger Robot virtual int format() const; 91*79330504STreehugger Robot 92*79330504STreehugger Robot virtual status_t setGain(float gain); 93*79330504STreehugger Robot virtual ssize_t read(void* buffer, ssize_t bytes); 94*79330504STreehugger Robot virtual status_t standby(); 95*79330504STreehugger Robot virtual status_t setParameters(const String8& keyValuePairs); 96*79330504STreehugger Robot virtual String8 getParameters(const String8& keys); 97*79330504STreehugger Robot virtual unsigned int getInputFramesLost() const; 98*79330504STreehugger Robot virtual status_t dump(int fd, const Vector<String16>& args); 99*79330504STreehugger Robot void Close(void); finalStream()100*79330504STreehugger Robot AudioStreamIn* finalStream() { return mFinalStream; } device()101*79330504STreehugger Robot uint32_t device() { return mDevice; } 102*79330504STreehugger Robot 103*79330504STreehugger Robot private: 104*79330504STreehugger Robot AudioDumpInterface *mInterface; 105*79330504STreehugger Robot int mId; 106*79330504STreehugger Robot uint32_t mSampleRate; // 107*79330504STreehugger Robot uint32_t mFormat; // 108*79330504STreehugger Robot uint32_t mChannels; // output configuration 109*79330504STreehugger Robot uint32_t mDevice; // current device this output is routed to 110*79330504STreehugger Robot size_t mBufferSize; 111*79330504STreehugger Robot AudioStreamIn *mFinalStream; 112*79330504STreehugger Robot FILE *mFile; // output file 113*79330504STreehugger Robot int mFileCount; 114*79330504STreehugger Robot }; 115*79330504STreehugger Robot 116*79330504STreehugger Robot class AudioDumpInterface : public AudioHardwareBase 117*79330504STreehugger Robot { 118*79330504STreehugger Robot 119*79330504STreehugger Robot public: 120*79330504STreehugger Robot AudioDumpInterface(AudioHardwareInterface* hw); 121*79330504STreehugger Robot virtual AudioStreamOut* openOutputStream( 122*79330504STreehugger Robot uint32_t devices, 123*79330504STreehugger Robot int *format=0, 124*79330504STreehugger Robot uint32_t *channels=0, 125*79330504STreehugger Robot uint32_t *sampleRate=0, 126*79330504STreehugger Robot status_t *status=0); 127*79330504STreehugger Robot virtual void closeOutputStream(AudioStreamOut* out); 128*79330504STreehugger Robot 129*79330504STreehugger Robot virtual ~AudioDumpInterface(); 130*79330504STreehugger Robot initCheck()131*79330504STreehugger Robot virtual status_t initCheck() 132*79330504STreehugger Robot {return mFinalInterface->initCheck();} setVoiceVolume(float volume)133*79330504STreehugger Robot virtual status_t setVoiceVolume(float volume) 134*79330504STreehugger Robot {return mFinalInterface->setVoiceVolume(volume);} setMasterVolume(float volume)135*79330504STreehugger Robot virtual status_t setMasterVolume(float volume) 136*79330504STreehugger Robot {return mFinalInterface->setMasterVolume(volume);} 137*79330504STreehugger Robot 138*79330504STreehugger Robot virtual status_t setMode(int mode); 139*79330504STreehugger Robot 140*79330504STreehugger Robot // mic mute setMicMute(bool state)141*79330504STreehugger Robot virtual status_t setMicMute(bool state) 142*79330504STreehugger Robot {return mFinalInterface->setMicMute(state);} getMicMute(bool * state)143*79330504STreehugger Robot virtual status_t getMicMute(bool* state) 144*79330504STreehugger Robot {return mFinalInterface->getMicMute(state);} 145*79330504STreehugger Robot 146*79330504STreehugger Robot virtual status_t setParameters(const String8& keyValuePairs); 147*79330504STreehugger Robot virtual String8 getParameters(const String8& keys); 148*79330504STreehugger Robot 149*79330504STreehugger Robot virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 150*79330504STreehugger Robot 151*79330504STreehugger Robot virtual AudioStreamIn* openInputStream(uint32_t devices, int *format, uint32_t *channels, 152*79330504STreehugger Robot uint32_t *sampleRate, status_t *status, AudioSystem::audio_in_acoustics acoustics); 153*79330504STreehugger Robot virtual void closeInputStream(AudioStreamIn* in); 154*79330504STreehugger Robot dump(int fd,const Vector<String16> & args)155*79330504STreehugger Robot virtual status_t dump(int fd, const Vector<String16>& args) { return mFinalInterface->dumpState(fd, args); } 156*79330504STreehugger Robot fileName()157*79330504STreehugger Robot String8 fileName() const { return mFileName; } 158*79330504STreehugger Robot protected: 159*79330504STreehugger Robot 160*79330504STreehugger Robot AudioHardwareInterface *mFinalInterface; 161*79330504STreehugger Robot SortedVector<AudioStreamOutDump *> mOutputs; 162*79330504STreehugger Robot SortedVector<AudioStreamInDump *> mInputs; 163*79330504STreehugger Robot Mutex mLock; 164*79330504STreehugger Robot String8 mPolicyCommands; 165*79330504STreehugger Robot String8 mFileName; 166*79330504STreehugger Robot }; 167*79330504STreehugger Robot 168*79330504STreehugger Robot }; // namespace android 169*79330504STreehugger Robot 170*79330504STreehugger Robot #endif // ANDROID_AUDIO_DUMP_INTERFACE_H 171