blob: 814ce5f717703572068baf4df4e1e26816a64962 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/* //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 Laurenta553c252009-07-17 12:17:14 -070023#include <utils/String8.h>
24#include <utils/SortedVector.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26#include <hardware_legacy/AudioHardwareBase.h>
27
28namespace android {
29
Eric Laurenta553c252009-07-17 12:17:14 -070030#define AUDIO_DUMP_WAVE_HDR_SIZE 44
31
32class AudioDumpInterface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
34class AudioStreamOutDump : public AudioStreamOut {
35public:
Eric Laurenta553c252009-07-17 12:17:14 -070036 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 Project9066cfe2009-03-03 19:31:44 -080043 ~AudioStreamOutDump();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Eric Laurenta553c252009-07-17 12:17:14 -070045 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 Project9066cfe2009-03-03 19:31:44 -080052 virtual status_t standby();
Eric Laurenta553c252009-07-17 12:17:14 -070053 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 Project9066cfe2009-03-03 19:31:44 -080056 void Close(void);
Eric Laurenta553c252009-07-17 12:17:14 -070057 AudioStreamOut* finalStream() { return mFinalStream; }
58 uint32_t device() { return mDevice; }
Eric Laurent69682b42009-08-04 07:29:18 -070059 int getId() { return mId; }
Eric Laurent0986e792010-01-19 17:37:09 -080060 virtual status_t getRenderPosition(uint32_t *dspFrames);
61
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062private:
Eric Laurenta553c252009-07-17 12:17:14 -070063 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 Project9066cfe2009-03-03 19:31:44 -080071 AudioStreamOut *mFinalStream;
Eric Laurentfc124662010-05-12 08:24:18 -070072 FILE *mFile; // output file
Eric Laurenta553c252009-07-17 12:17:14 -070073 int mFileCount;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074};
75
Eric Laurenta553c252009-07-17 12:17:14 -070076class 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);
Eric Laurent47d0a922010-02-26 02:47:27 -080097 virtual unsigned int getInputFramesLost() const;
Eric Laurenta553c252009-07-17 12:17:14 -070098 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;
Eric Laurentfc124662010-05-12 08:24:18 -0700112 FILE *mFile; // output file
113 int mFileCount;
Eric Laurenta553c252009-07-17 12:17:14 -0700114};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
116class AudioDumpInterface : public AudioHardwareBase
117{
118
119public:
120 AudioDumpInterface(AudioHardwareInterface* hw);
121 virtual AudioStreamOut* openOutputStream(
Eric Laurenta553c252009-07-17 12:17:14 -0700122 uint32_t devices,
123 int *format=0,
124 uint32_t *channels=0,
125 uint32_t *sampleRate=0,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 status_t *status=0);
Eric Laurenta553c252009-07-17 12:17:14 -0700127 virtual void closeOutputStream(AudioStreamOut* out);
128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 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 Laurentfc124662010-05-12 08:24:18 -0700138 virtual status_t setMode(int mode);
139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 // 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 Laurenta553c252009-07-17 12:17:14 -0700146 virtual status_t setParameters(const String8& keyValuePairs);
147 virtual String8 getParameters(const String8& keys);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
Eric Laurentfc124662010-05-12 08:24:18 -0700149 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount);
150
Eric Laurenta553c252009-07-17 12:17:14 -0700151 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 Sparksa5e2ef02009-05-19 18:28:20 -0700154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 virtual status_t dump(int fd, const Vector<String16>& args) { return mFinalInterface->dumpState(fd, args); }
156
Eric Laurenta553c252009-07-17 12:17:14 -0700157 String8 fileName() const { return mFileName; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158protected:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159
Eric Laurenta553c252009-07-17 12:17:14 -0700160 AudioHardwareInterface *mFinalInterface;
Eric Laurentfc124662010-05-12 08:24:18 -0700161 SortedVector<AudioStreamOutDump *> mOutputs;
Eric Laurenta553c252009-07-17 12:17:14 -0700162 SortedVector<AudioStreamInDump *> mInputs;
163 Mutex mLock;
164 String8 mPolicyCommands;
165 String8 mFileName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166};
167
168}; // namespace android
169
170#endif // ANDROID_AUDIO_DUMP_INTERFACE_H