blob: 9c8495211ba47843dab6066b4c886664330f40ce [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H
12#define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H
13
14#include "audio_device.h"
15#include "audio_device_buffer.h"
16
17namespace webrtc
18{
19
20class AudioDeviceGeneric;
21class AudioDeviceUtility;
22class CriticalSectionWrapper;
23
24class AudioDeviceModuleImpl : public AudioDeviceModule
25{
26public:
27 enum PlatformType
28 {
29 kPlatformNotSupported = 0,
30 kPlatformWin32 = 1,
31 kPlatformWinCe = 2,
32 kPlatformLinux = 3,
33 kPlatformMac = 4
34 };
35
36 WebRtc_Word32 CheckPlatform();
37 WebRtc_Word32 CreatePlatformSpecificObjects();
38 WebRtc_Word32 AttachAudioBuffer();
39
40 AudioDeviceModuleImpl(const WebRtc_Word32 id, const AudioLayer audioLayer);
41 virtual ~AudioDeviceModuleImpl();
42
43public: // Module
44 virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
45 virtual WebRtc_Word32 Version(
46 WebRtc_Word8 *version, WebRtc_UWord32& remainingBufferInBytes,
47 WebRtc_UWord32& position) const;
48 virtual WebRtc_Word32 TimeUntilNextProcess();
49 virtual WebRtc_Word32 Process();
50
51public:
52 // Factory methods (resource allocation/deallocation)
53 static AudioDeviceModule* Create(
54 const WebRtc_Word32 id,
55 const AudioLayer audioLayer = kPlatformDefaultAudio);
56 static void Destroy(AudioDeviceModule* module);
57
58 // Retrieve the currently utilized audio layer
59 virtual WebRtc_Word32 ActiveAudioLayer(AudioLayer* audioLayer) const;
60
61 // Error handling
62 virtual ErrorCode LastError() const;
63 virtual WebRtc_Word32 RegisterEventObserver(
64 AudioDeviceObserver* eventCallback);
65
66 // Full-duplex transportation of PCM audio
67 virtual WebRtc_Word32 RegisterAudioCallback(
68 AudioTransport* audioCallback);
69
70 // Main initializaton and termination
71 virtual WebRtc_Word32 Init();
72 virtual WebRtc_Word32 Terminate();
73 virtual bool Initialized() const;
74
75 // Device enumeration
76 virtual WebRtc_Word16 PlayoutDevices();
77 virtual WebRtc_Word16 RecordingDevices();
78 virtual WebRtc_Word32 PlayoutDeviceName(
79 WebRtc_UWord16 index,
80 WebRtc_Word8 name[kAdmMaxDeviceNameSize],
81 WebRtc_Word8 guid[kAdmMaxGuidSize]);
82 virtual WebRtc_Word32 RecordingDeviceName(
83 WebRtc_UWord16 index,
84 WebRtc_Word8 name[kAdmMaxDeviceNameSize],
85 WebRtc_Word8 guid[kAdmMaxGuidSize]);
86
87 // Device selection
88 virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index);
89 virtual WebRtc_Word32 SetPlayoutDevice(WindowsDeviceType device);
90 virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index);
91 virtual WebRtc_Word32 SetRecordingDevice(WindowsDeviceType device);
92
93 // Audio transport initialization
94 virtual WebRtc_Word32 PlayoutIsAvailable(bool* available);
95 virtual WebRtc_Word32 InitPlayout();
96 virtual bool PlayoutIsInitialized() const;
97 virtual WebRtc_Word32 RecordingIsAvailable(bool* available);
98 virtual WebRtc_Word32 InitRecording();
99 virtual bool RecordingIsInitialized() const;
100
101 // Audio transport control
102 virtual WebRtc_Word32 StartPlayout();
103 virtual WebRtc_Word32 StopPlayout();
104 virtual bool Playing() const;
105 virtual WebRtc_Word32 StartRecording();
106 virtual WebRtc_Word32 StopRecording();
107 virtual bool Recording() const;
108
109 // Microphone Automatic Gain Control (AGC)
110 virtual WebRtc_Word32 SetAGC(bool enable);
111 virtual bool AGC() const;
112
113 // Volume control based on the Windows Wave API (Windows only)
114 virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft,
115 WebRtc_UWord16 volumeRight);
116 virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16* volumeLeft,
117 WebRtc_UWord16* volumeRight) const;
118
119 // Audio mixer initialization
120 virtual WebRtc_Word32 SpeakerIsAvailable(bool* available);
121 virtual WebRtc_Word32 InitSpeaker();
122 virtual bool SpeakerIsInitialized() const;
123 virtual WebRtc_Word32 MicrophoneIsAvailable(bool* available);
124 virtual WebRtc_Word32 InitMicrophone();
125 virtual bool MicrophoneIsInitialized() const;
126
127 // Speaker volume controls
128 virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool* available);
129 virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
130 virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32* volume) const;
131 virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32* maxVolume) const;
132 virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32* minVolume) const;
133 virtual WebRtc_Word32 SpeakerVolumeStepSize(
134 WebRtc_UWord16* stepSize) const;
135
136 // Microphone volume controls
137 virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool* available);
138 virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
139 virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32* volume) const;
140 virtual WebRtc_Word32 MaxMicrophoneVolume(
141 WebRtc_UWord32* maxVolume) const;
142 virtual WebRtc_Word32 MinMicrophoneVolume(
143 WebRtc_UWord32* minVolume) const;
144 virtual WebRtc_Word32 MicrophoneVolumeStepSize(
145 WebRtc_UWord16* stepSize) const;
146
147 // Speaker mute control
148 virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool* available);
149 virtual WebRtc_Word32 SetSpeakerMute(bool enable);
150 virtual WebRtc_Word32 SpeakerMute(bool* enabled) const;
151
152 // Microphone mute control
153 virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool* available);
154 virtual WebRtc_Word32 SetMicrophoneMute(bool enable);
155 virtual WebRtc_Word32 MicrophoneMute(bool* enabled) const;
156
157 // Microphone boost control
158 virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool* available);
159 virtual WebRtc_Word32 SetMicrophoneBoost(bool enable);
160 virtual WebRtc_Word32 MicrophoneBoost(bool* enabled) const;
161
162 // Stereo support
163 virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool* available) const;
164 virtual WebRtc_Word32 SetStereoPlayout(bool enable);
165 virtual WebRtc_Word32 StereoPlayout(bool* enabled) const;
166 virtual WebRtc_Word32 StereoRecordingIsAvailable(bool* available) const;
167 virtual WebRtc_Word32 SetStereoRecording(bool enable);
168 virtual WebRtc_Word32 StereoRecording(bool* enabled) const;
169 virtual WebRtc_Word32 SetRecordingChannel(const ChannelType channel);
170 virtual WebRtc_Word32 RecordingChannel(ChannelType* channel) const;
171
172 // Delay information and control
173 virtual WebRtc_Word32 SetPlayoutBuffer(const BufferType type,
174 WebRtc_UWord16 sizeMS = 0);
175 virtual WebRtc_Word32 PlayoutBuffer(BufferType* type,
176 WebRtc_UWord16* sizeMS) const;
177 virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16* delayMS) const;
178 virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16* delayMS) const;
179
180 // CPU load
181 virtual WebRtc_Word32 CPULoad(WebRtc_UWord16* load) const;
182
183 // Recording of raw PCM data
184 virtual WebRtc_Word32 StartRawOutputFileRecording(
185 const WebRtc_Word8 pcmFileNameUTF8[kAdmMaxFileNameSize]);
186 virtual WebRtc_Word32 StopRawOutputFileRecording();
187 virtual WebRtc_Word32 StartRawInputFileRecording(
188 const WebRtc_Word8 pcmFileNameUTF8[kAdmMaxFileNameSize]);
189 virtual WebRtc_Word32 StopRawInputFileRecording();
190
191 // Native sample rate controls (samples/sec)
192 virtual WebRtc_Word32 SetRecordingSampleRate(
193 const WebRtc_UWord32 samplesPerSec);
194 virtual WebRtc_Word32 RecordingSampleRate(
195 WebRtc_UWord32* samplesPerSec) const;
196 virtual WebRtc_Word32 SetPlayoutSampleRate(
197 const WebRtc_UWord32 samplesPerSec);
198 virtual WebRtc_Word32 PlayoutSampleRate(
199 WebRtc_UWord32* samplesPerSec) const;
200
201 // Mobile device specific functions
202 virtual WebRtc_Word32 ResetAudioDevice();
203 virtual WebRtc_Word32 SetLoudspeakerStatus(bool enable);
204 virtual WebRtc_Word32 GetLoudspeakerStatus(bool* enabled) const;
205
206public:
207 WebRtc_Word32 Id() {return _id;}
208
209private:
210 PlatformType Platform() const;
211 AudioLayer PlatformAudioLayer() const;
212
213private:
214 CriticalSectionWrapper& _critSect;
215 CriticalSectionWrapper& _critSectEventCb;
216 CriticalSectionWrapper& _critSectAudioCb;
217
218 AudioDeviceObserver* _ptrCbAudioDeviceObserver;
219
220 AudioDeviceUtility* _ptrAudioDeviceUtility;
221 AudioDeviceGeneric* _ptrAudioDevice;
222
223 AudioDeviceBuffer _audioDeviceBuffer;
224
225 WebRtc_Word32 _id;
226 AudioLayer _platformAudioLayer;
227 WebRtc_UWord32 _lastProcessTime;
228 PlatformType _platformType;
229 bool _initialized;
230 mutable ErrorCode _lastError;
231};
232
233} // namespace webrtc
234
235#endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_