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>
23#include <utils/String8.h>
24#include <utils/SortedVector.h>
25
26#include <hardware_legacy/AudioHardwareBase.h>
27
28namespace android {
29
30#define AUDIO_DUMP_WAVE_HDR_SIZE 44
31
32class AudioDumpInterface;
33
34class AudioStreamOutDump : public AudioStreamOut {
35public:
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);
43                        ~AudioStreamOutDump();
44
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);
52    virtual status_t    standby();
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);
56    void                Close(void);
57    AudioStreamOut*     finalStream() { return mFinalStream; }
58    uint32_t            device() { return mDevice; }
59    int                 getId()  { return mId; }
60    virtual status_t    getRenderPosition(uint32_t *dspFrames);
61
62private:
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;
71    AudioStreamOut      *mFinalStream;
72    FILE                *mFile;      // output file
73    int                 mFileCount;
74};
75
76class AudioStreamInDump : public AudioStreamIn {
77public:
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);
97    virtual unsigned int  getInputFramesLost() const;
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
103private:
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;
112    FILE                *mFile;      // output file
113    int                 mFileCount;
114};
115
116class AudioDumpInterface : public AudioHardwareBase
117{
118
119public:
120                        AudioDumpInterface(AudioHardwareInterface* hw);
121    virtual AudioStreamOut* openOutputStream(
122                                uint32_t devices,
123                                int *format=0,
124                                uint32_t *channels=0,
125                                uint32_t *sampleRate=0,
126                                status_t *status=0);
127    virtual    void        closeOutputStream(AudioStreamOut* out);
128
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
138    virtual status_t    setMode(int mode);
139
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
146    virtual status_t    setParameters(const String8& keyValuePairs);
147    virtual String8     getParameters(const String8& keys);
148
149    virtual size_t      getInputBufferSize(uint32_t sampleRate, int format, int channelCount);
150
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);
154
155    virtual status_t    dump(int fd, const Vector<String16>& args) { return mFinalInterface->dumpState(fd, args); }
156
157            String8     fileName() const { return mFileName; }
158protected:
159
160    AudioHardwareInterface          *mFinalInterface;
161    SortedVector<AudioStreamOutDump *>   mOutputs;
162    SortedVector<AudioStreamInDump *>    mInputs;
163    Mutex                           mLock;
164    String8                         mPolicyCommands;
165    String8                         mFileName;
166};
167
168}; // namespace android
169
170#endif // ANDROID_AUDIO_DUMP_INTERFACE_H
171