blob: 91a853466cbc0c0b1f7c85c79fa9aa0f7f1575da [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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,
leozwang@google.com522f42b2011-09-19 17:39:05 +000033 kPlatformMac = 4,
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000034 kPlatformAndroid = 5,
35 kPlatformIOS = 6
niklase@google.com470e71d2011-07-07 08:21:25 +000036 };
37
38 WebRtc_Word32 CheckPlatform();
39 WebRtc_Word32 CreatePlatformSpecificObjects();
40 WebRtc_Word32 AttachAudioBuffer();
41
42 AudioDeviceModuleImpl(const WebRtc_Word32 id, const AudioLayer audioLayer);
43 virtual ~AudioDeviceModuleImpl();
44
henrika@google.com73d65512011-09-07 15:11:18 +000045public: // RefCountedModule
niklase@google.com470e71d2011-07-07 08:21:25 +000046 virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
niklase@google.com470e71d2011-07-07 08:21:25 +000047 virtual WebRtc_Word32 TimeUntilNextProcess();
48 virtual WebRtc_Word32 Process();
49
50public:
51 // Factory methods (resource allocation/deallocation)
52 static AudioDeviceModule* Create(
53 const WebRtc_Word32 id,
54 const AudioLayer audioLayer = kPlatformDefaultAudio);
niklase@google.com470e71d2011-07-07 08:21:25 +000055
56 // Retrieve the currently utilized audio layer
57 virtual WebRtc_Word32 ActiveAudioLayer(AudioLayer* audioLayer) const;
58
59 // Error handling
60 virtual ErrorCode LastError() const;
61 virtual WebRtc_Word32 RegisterEventObserver(
62 AudioDeviceObserver* eventCallback);
63
64 // Full-duplex transportation of PCM audio
65 virtual WebRtc_Word32 RegisterAudioCallback(
66 AudioTransport* audioCallback);
67
68 // Main initializaton and termination
69 virtual WebRtc_Word32 Init();
70 virtual WebRtc_Word32 Terminate();
71 virtual bool Initialized() const;
72
73 // Device enumeration
74 virtual WebRtc_Word16 PlayoutDevices();
75 virtual WebRtc_Word16 RecordingDevices();
76 virtual WebRtc_Word32 PlayoutDeviceName(
77 WebRtc_UWord16 index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000078 char name[kAdmMaxDeviceNameSize],
79 char guid[kAdmMaxGuidSize]);
niklase@google.com470e71d2011-07-07 08:21:25 +000080 virtual WebRtc_Word32 RecordingDeviceName(
81 WebRtc_UWord16 index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000082 char name[kAdmMaxDeviceNameSize],
83 char guid[kAdmMaxGuidSize]);
niklase@google.com470e71d2011-07-07 08:21:25 +000084
85 // Device selection
86 virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index);
87 virtual WebRtc_Word32 SetPlayoutDevice(WindowsDeviceType device);
88 virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index);
89 virtual WebRtc_Word32 SetRecordingDevice(WindowsDeviceType device);
90
91 // Audio transport initialization
92 virtual WebRtc_Word32 PlayoutIsAvailable(bool* available);
93 virtual WebRtc_Word32 InitPlayout();
94 virtual bool PlayoutIsInitialized() const;
95 virtual WebRtc_Word32 RecordingIsAvailable(bool* available);
96 virtual WebRtc_Word32 InitRecording();
97 virtual bool RecordingIsInitialized() const;
98
99 // Audio transport control
100 virtual WebRtc_Word32 StartPlayout();
101 virtual WebRtc_Word32 StopPlayout();
102 virtual bool Playing() const;
103 virtual WebRtc_Word32 StartRecording();
104 virtual WebRtc_Word32 StopRecording();
105 virtual bool Recording() const;
106
107 // Microphone Automatic Gain Control (AGC)
108 virtual WebRtc_Word32 SetAGC(bool enable);
109 virtual bool AGC() const;
110
111 // Volume control based on the Windows Wave API (Windows only)
112 virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft,
113 WebRtc_UWord16 volumeRight);
114 virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16* volumeLeft,
115 WebRtc_UWord16* volumeRight) const;
116
117 // Audio mixer initialization
118 virtual WebRtc_Word32 SpeakerIsAvailable(bool* available);
119 virtual WebRtc_Word32 InitSpeaker();
120 virtual bool SpeakerIsInitialized() const;
121 virtual WebRtc_Word32 MicrophoneIsAvailable(bool* available);
122 virtual WebRtc_Word32 InitMicrophone();
123 virtual bool MicrophoneIsInitialized() const;
124
125 // Speaker volume controls
126 virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool* available);
127 virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume);
128 virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32* volume) const;
129 virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32* maxVolume) const;
130 virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32* minVolume) const;
131 virtual WebRtc_Word32 SpeakerVolumeStepSize(
132 WebRtc_UWord16* stepSize) const;
133
134 // Microphone volume controls
135 virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool* available);
136 virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume);
137 virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32* volume) const;
138 virtual WebRtc_Word32 MaxMicrophoneVolume(
139 WebRtc_UWord32* maxVolume) const;
140 virtual WebRtc_Word32 MinMicrophoneVolume(
141 WebRtc_UWord32* minVolume) const;
142 virtual WebRtc_Word32 MicrophoneVolumeStepSize(
143 WebRtc_UWord16* stepSize) const;
144
145 // Speaker mute control
146 virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool* available);
147 virtual WebRtc_Word32 SetSpeakerMute(bool enable);
148 virtual WebRtc_Word32 SpeakerMute(bool* enabled) const;
149
150 // Microphone mute control
151 virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool* available);
152 virtual WebRtc_Word32 SetMicrophoneMute(bool enable);
153 virtual WebRtc_Word32 MicrophoneMute(bool* enabled) const;
154
155 // Microphone boost control
156 virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool* available);
157 virtual WebRtc_Word32 SetMicrophoneBoost(bool enable);
158 virtual WebRtc_Word32 MicrophoneBoost(bool* enabled) const;
159
160 // Stereo support
161 virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool* available) const;
162 virtual WebRtc_Word32 SetStereoPlayout(bool enable);
163 virtual WebRtc_Word32 StereoPlayout(bool* enabled) const;
164 virtual WebRtc_Word32 StereoRecordingIsAvailable(bool* available) const;
165 virtual WebRtc_Word32 SetStereoRecording(bool enable);
166 virtual WebRtc_Word32 StereoRecording(bool* enabled) const;
167 virtual WebRtc_Word32 SetRecordingChannel(const ChannelType channel);
168 virtual WebRtc_Word32 RecordingChannel(ChannelType* channel) const;
169
170 // Delay information and control
171 virtual WebRtc_Word32 SetPlayoutBuffer(const BufferType type,
172 WebRtc_UWord16 sizeMS = 0);
173 virtual WebRtc_Word32 PlayoutBuffer(BufferType* type,
174 WebRtc_UWord16* sizeMS) const;
175 virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16* delayMS) const;
176 virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16* delayMS) const;
177
178 // CPU load
179 virtual WebRtc_Word32 CPULoad(WebRtc_UWord16* load) const;
180
181 // Recording of raw PCM data
182 virtual WebRtc_Word32 StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000183 const char pcmFileNameUTF8[kAdmMaxFileNameSize]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 virtual WebRtc_Word32 StopRawOutputFileRecording();
185 virtual WebRtc_Word32 StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000186 const char pcmFileNameUTF8[kAdmMaxFileNameSize]);
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 virtual WebRtc_Word32 StopRawInputFileRecording();
188
189 // Native sample rate controls (samples/sec)
190 virtual WebRtc_Word32 SetRecordingSampleRate(
191 const WebRtc_UWord32 samplesPerSec);
192 virtual WebRtc_Word32 RecordingSampleRate(
193 WebRtc_UWord32* samplesPerSec) const;
194 virtual WebRtc_Word32 SetPlayoutSampleRate(
195 const WebRtc_UWord32 samplesPerSec);
196 virtual WebRtc_Word32 PlayoutSampleRate(
197 WebRtc_UWord32* samplesPerSec) const;
198
199 // Mobile device specific functions
200 virtual WebRtc_Word32 ResetAudioDevice();
201 virtual WebRtc_Word32 SetLoudspeakerStatus(bool enable);
202 virtual WebRtc_Word32 GetLoudspeakerStatus(bool* enabled) const;
203
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000204 virtual int32_t EnableBuiltInAEC(bool enable);
205 virtual bool BuiltInAECIsEnabled() const;
206
niklase@google.com470e71d2011-07-07 08:21:25 +0000207public:
208 WebRtc_Word32 Id() {return _id;}
209
210private:
211 PlatformType Platform() const;
212 AudioLayer PlatformAudioLayer() const;
213
214private:
215 CriticalSectionWrapper& _critSect;
216 CriticalSectionWrapper& _critSectEventCb;
217 CriticalSectionWrapper& _critSectAudioCb;
218
219 AudioDeviceObserver* _ptrCbAudioDeviceObserver;
220
221 AudioDeviceUtility* _ptrAudioDeviceUtility;
222 AudioDeviceGeneric* _ptrAudioDevice;
223
224 AudioDeviceBuffer _audioDeviceBuffer;
225
226 WebRtc_Word32 _id;
227 AudioLayer _platformAudioLayer;
228 WebRtc_UWord32 _lastProcessTime;
229 PlatformType _platformType;
230 bool _initialized;
231 mutable ErrorCode _lastError;
232};
233
234} // namespace webrtc
235
236#endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_