blob: 8cbfbf53ea1d8f04f66e7570937fbcd85c70943d [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
pbos@webrtc.org25509882013-04-09 10:30:35 +000038 int32_t CheckPlatform();
39 int32_t CreatePlatformSpecificObjects();
40 int32_t AttachAudioBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +000041
pbos@webrtc.org25509882013-04-09 10:30:35 +000042 AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer);
niklase@google.com470e71d2011-07-07 08:21:25 +000043 virtual ~AudioDeviceModuleImpl();
44
henrika@google.com73d65512011-09-07 15:11:18 +000045public: // RefCountedModule
pbos@webrtc.org25509882013-04-09 10:30:35 +000046 virtual int32_t ChangeUniqueId(const int32_t id);
47 virtual int32_t TimeUntilNextProcess();
48 virtual int32_t Process();
niklase@google.com470e71d2011-07-07 08:21:25 +000049
50public:
51 // Factory methods (resource allocation/deallocation)
52 static AudioDeviceModule* Create(
pbos@webrtc.org25509882013-04-09 10:30:35 +000053 const int32_t id,
niklase@google.com470e71d2011-07-07 08:21:25 +000054 const AudioLayer audioLayer = kPlatformDefaultAudio);
niklase@google.com470e71d2011-07-07 08:21:25 +000055
56 // Retrieve the currently utilized audio layer
pbos@webrtc.org25509882013-04-09 10:30:35 +000057 virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59 // Error handling
60 virtual ErrorCode LastError() const;
pbos@webrtc.org25509882013-04-09 10:30:35 +000061 virtual int32_t RegisterEventObserver(
niklase@google.com470e71d2011-07-07 08:21:25 +000062 AudioDeviceObserver* eventCallback);
63
64 // Full-duplex transportation of PCM audio
pbos@webrtc.org25509882013-04-09 10:30:35 +000065 virtual int32_t RegisterAudioCallback(
niklase@google.com470e71d2011-07-07 08:21:25 +000066 AudioTransport* audioCallback);
67
68 // Main initializaton and termination
pbos@webrtc.org25509882013-04-09 10:30:35 +000069 virtual int32_t Init();
70 virtual int32_t Terminate();
niklase@google.com470e71d2011-07-07 08:21:25 +000071 virtual bool Initialized() const;
72
73 // Device enumeration
pbos@webrtc.org25509882013-04-09 10:30:35 +000074 virtual int16_t PlayoutDevices();
75 virtual int16_t RecordingDevices();
76 virtual int32_t PlayoutDeviceName(
77 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000078 char name[kAdmMaxDeviceNameSize],
79 char guid[kAdmMaxGuidSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +000080 virtual int32_t RecordingDeviceName(
81 uint16_t 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
pbos@webrtc.org25509882013-04-09 10:30:35 +000086 virtual int32_t SetPlayoutDevice(uint16_t index);
87 virtual int32_t SetPlayoutDevice(WindowsDeviceType device);
88 virtual int32_t SetRecordingDevice(uint16_t index);
89 virtual int32_t SetRecordingDevice(WindowsDeviceType device);
niklase@google.com470e71d2011-07-07 08:21:25 +000090
91 // Audio transport initialization
pbos@webrtc.org25509882013-04-09 10:30:35 +000092 virtual int32_t PlayoutIsAvailable(bool* available);
93 virtual int32_t InitPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +000094 virtual bool PlayoutIsInitialized() const;
pbos@webrtc.org25509882013-04-09 10:30:35 +000095 virtual int32_t RecordingIsAvailable(bool* available);
96 virtual int32_t InitRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +000097 virtual bool RecordingIsInitialized() const;
98
99 // Audio transport control
pbos@webrtc.org25509882013-04-09 10:30:35 +0000100 virtual int32_t StartPlayout();
101 virtual int32_t StopPlayout();
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 virtual bool Playing() const;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000103 virtual int32_t StartRecording();
104 virtual int32_t StopRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 virtual bool Recording() const;
106
107 // Microphone Automatic Gain Control (AGC)
pbos@webrtc.org25509882013-04-09 10:30:35 +0000108 virtual int32_t SetAGC(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000109 virtual bool AGC() const;
110
111 // Volume control based on the Windows Wave API (Windows only)
pbos@webrtc.org25509882013-04-09 10:30:35 +0000112 virtual int32_t SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight);
113 virtual int32_t WaveOutVolume(uint16_t* volumeLeft,
114 uint16_t* volumeRight) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
116 // Audio mixer initialization
pbos@webrtc.org25509882013-04-09 10:30:35 +0000117 virtual int32_t SpeakerIsAvailable(bool* available);
118 virtual int32_t InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000119 virtual bool SpeakerIsInitialized() const;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000120 virtual int32_t MicrophoneIsAvailable(bool* available);
121 virtual int32_t InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000122 virtual bool MicrophoneIsInitialized() const;
123
124 // Speaker volume controls
pbos@webrtc.org25509882013-04-09 10:30:35 +0000125 virtual int32_t SpeakerVolumeIsAvailable(bool* available);
126 virtual int32_t SetSpeakerVolume(uint32_t volume);
127 virtual int32_t SpeakerVolume(uint32_t* volume) const;
128 virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const;
129 virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const;
130 virtual int32_t SpeakerVolumeStepSize(
131 uint16_t* stepSize) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
133 // Microphone volume controls
pbos@webrtc.org25509882013-04-09 10:30:35 +0000134 virtual int32_t MicrophoneVolumeIsAvailable(bool* available);
135 virtual int32_t SetMicrophoneVolume(uint32_t volume);
136 virtual int32_t MicrophoneVolume(uint32_t* volume) const;
137 virtual int32_t MaxMicrophoneVolume(
138 uint32_t* maxVolume) const;
139 virtual int32_t MinMicrophoneVolume(
140 uint32_t* minVolume) const;
141 virtual int32_t MicrophoneVolumeStepSize(
142 uint16_t* stepSize) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
144 // Speaker mute control
pbos@webrtc.org25509882013-04-09 10:30:35 +0000145 virtual int32_t SpeakerMuteIsAvailable(bool* available);
146 virtual int32_t SetSpeakerMute(bool enable);
147 virtual int32_t SpeakerMute(bool* enabled) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
149 // Microphone mute control
pbos@webrtc.org25509882013-04-09 10:30:35 +0000150 virtual int32_t MicrophoneMuteIsAvailable(bool* available);
151 virtual int32_t SetMicrophoneMute(bool enable);
152 virtual int32_t MicrophoneMute(bool* enabled) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
154 // Microphone boost control
pbos@webrtc.org25509882013-04-09 10:30:35 +0000155 virtual int32_t MicrophoneBoostIsAvailable(bool* available);
156 virtual int32_t SetMicrophoneBoost(bool enable);
157 virtual int32_t MicrophoneBoost(bool* enabled) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
159 // Stereo support
pbos@webrtc.org25509882013-04-09 10:30:35 +0000160 virtual int32_t StereoPlayoutIsAvailable(bool* available) const;
161 virtual int32_t SetStereoPlayout(bool enable);
162 virtual int32_t StereoPlayout(bool* enabled) const;
163 virtual int32_t StereoRecordingIsAvailable(bool* available) const;
164 virtual int32_t SetStereoRecording(bool enable);
165 virtual int32_t StereoRecording(bool* enabled) const;
166 virtual int32_t SetRecordingChannel(const ChannelType channel);
167 virtual int32_t RecordingChannel(ChannelType* channel) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
169 // Delay information and control
pbos@webrtc.org25509882013-04-09 10:30:35 +0000170 virtual int32_t SetPlayoutBuffer(const BufferType type,
171 uint16_t sizeMS = 0);
172 virtual int32_t PlayoutBuffer(BufferType* type,
173 uint16_t* sizeMS) const;
174 virtual int32_t PlayoutDelay(uint16_t* delayMS) const;
175 virtual int32_t RecordingDelay(uint16_t* delayMS) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
177 // CPU load
pbos@webrtc.org25509882013-04-09 10:30:35 +0000178 virtual int32_t CPULoad(uint16_t* load) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
180 // Recording of raw PCM data
pbos@webrtc.org25509882013-04-09 10:30:35 +0000181 virtual int32_t StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000182 const char pcmFileNameUTF8[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +0000183 virtual int32_t StopRawOutputFileRecording();
184 virtual int32_t StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000185 const char pcmFileNameUTF8[kAdmMaxFileNameSize]);
pbos@webrtc.org25509882013-04-09 10:30:35 +0000186 virtual int32_t StopRawInputFileRecording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
188 // Native sample rate controls (samples/sec)
pbos@webrtc.org25509882013-04-09 10:30:35 +0000189 virtual int32_t SetRecordingSampleRate(
190 const uint32_t samplesPerSec);
191 virtual int32_t RecordingSampleRate(
192 uint32_t* samplesPerSec) const;
193 virtual int32_t SetPlayoutSampleRate(
194 const uint32_t samplesPerSec);
195 virtual int32_t PlayoutSampleRate(
196 uint32_t* samplesPerSec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
198 // Mobile device specific functions
pbos@webrtc.org25509882013-04-09 10:30:35 +0000199 virtual int32_t ResetAudioDevice();
200 virtual int32_t SetLoudspeakerStatus(bool enable);
201 virtual int32_t GetLoudspeakerStatus(bool* enabled) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000203 virtual int32_t EnableBuiltInAEC(bool enable);
204 virtual bool BuiltInAECIsEnabled() const;
205
niklase@google.com470e71d2011-07-07 08:21:25 +0000206public:
pbos@webrtc.org25509882013-04-09 10:30:35 +0000207 int32_t Id() {return _id;}
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
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
pbos@webrtc.org25509882013-04-09 10:30:35 +0000225 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 AudioLayer _platformAudioLayer;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000227 uint32_t _lastProcessTime;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 PlatformType _platformType;
229 bool _initialized;
230 mutable ErrorCode _lastError;
231};
232
233} // namespace webrtc
234
235#endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_