blob: 97f266afd7634cc4f35d730cd3f10e40166b38b6 [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
pbos@webrtc.org811269d2013-07-11 13:24:38 +000014#include "webrtc/modules/audio_device/audio_device_buffer.h"
15#include "webrtc/modules/audio_device/include/audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
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
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000046 int64_t TimeUntilNextProcess() override;
47 int32_t Process() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
49public:
50 // Factory methods (resource allocation/deallocation)
51 static AudioDeviceModule* Create(
pbos@webrtc.org25509882013-04-09 10:30:35 +000052 const int32_t id,
niklase@google.com470e71d2011-07-07 08:21:25 +000053 const AudioLayer audioLayer = kPlatformDefaultAudio);
niklase@google.com470e71d2011-07-07 08:21:25 +000054
55 // Retrieve the currently utilized audio layer
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000057
58 // Error handling
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 ErrorCode LastError() const override;
60 int32_t RegisterEventObserver(AudioDeviceObserver* eventCallback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
62 // Full-duplex transportation of PCM audio
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000063 int32_t RegisterAudioCallback(AudioTransport* audioCallback) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
65 // Main initializaton and termination
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000066 int32_t Init() override;
67 int32_t Terminate() override;
68 bool Initialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
70 // Device enumeration
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000071 int16_t PlayoutDevices() override;
72 int16_t RecordingDevices() override;
73 int32_t PlayoutDeviceName(uint16_t index,
74 char name[kAdmMaxDeviceNameSize],
75 char guid[kAdmMaxGuidSize]) override;
76 int32_t RecordingDeviceName(uint16_t index,
77 char name[kAdmMaxDeviceNameSize],
78 char guid[kAdmMaxGuidSize]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
80 // Device selection
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000081 int32_t SetPlayoutDevice(uint16_t index) override;
82 int32_t SetPlayoutDevice(WindowsDeviceType device) override;
83 int32_t SetRecordingDevice(uint16_t index) override;
84 int32_t SetRecordingDevice(WindowsDeviceType device) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
86 // Audio transport initialization
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000087 int32_t PlayoutIsAvailable(bool* available) override;
88 int32_t InitPlayout() override;
89 bool PlayoutIsInitialized() const override;
90 int32_t RecordingIsAvailable(bool* available) override;
91 int32_t InitRecording() override;
92 bool RecordingIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000093
94 // Audio transport control
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000095 int32_t StartPlayout() override;
96 int32_t StopPlayout() override;
97 bool Playing() const override;
98 int32_t StartRecording() override;
99 int32_t StopRecording() override;
100 bool Recording() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
102 // Microphone Automatic Gain Control (AGC)
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000103 int32_t SetAGC(bool enable) override;
104 bool AGC() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
106 // Volume control based on the Windows Wave API (Windows only)
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000107 int32_t SetWaveOutVolume(uint16_t volumeLeft,
108 uint16_t volumeRight) override;
109 int32_t WaveOutVolume(uint16_t* volumeLeft,
110 uint16_t* volumeRight) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
112 // Audio mixer initialization
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000113 int32_t InitSpeaker() override;
114 bool SpeakerIsInitialized() const override;
115 int32_t InitMicrophone() override;
116 bool MicrophoneIsInitialized() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
118 // Speaker volume controls
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000119 int32_t SpeakerVolumeIsAvailable(bool* available) override;
120 int32_t SetSpeakerVolume(uint32_t volume) override;
121 int32_t SpeakerVolume(uint32_t* volume) const override;
122 int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override;
123 int32_t MinSpeakerVolume(uint32_t* minVolume) const override;
124 int32_t SpeakerVolumeStepSize(uint16_t* stepSize) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
126 // Microphone volume controls
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000127 int32_t MicrophoneVolumeIsAvailable(bool* available) override;
128 int32_t SetMicrophoneVolume(uint32_t volume) override;
129 int32_t MicrophoneVolume(uint32_t* volume) const override;
130 int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override;
131 int32_t MinMicrophoneVolume(uint32_t* minVolume) const override;
132 int32_t MicrophoneVolumeStepSize(uint16_t* stepSize) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
134 // Speaker mute control
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000135 int32_t SpeakerMuteIsAvailable(bool* available) override;
136 int32_t SetSpeakerMute(bool enable) override;
137 int32_t SpeakerMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
139 // Microphone mute control
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000140 int32_t MicrophoneMuteIsAvailable(bool* available) override;
141 int32_t SetMicrophoneMute(bool enable) override;
142 int32_t MicrophoneMute(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
144 // Microphone boost control
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000145 int32_t MicrophoneBoostIsAvailable(bool* available) override;
146 int32_t SetMicrophoneBoost(bool enable) override;
147 int32_t MicrophoneBoost(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
149 // Stereo support
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000150 int32_t StereoPlayoutIsAvailable(bool* available) const override;
151 int32_t SetStereoPlayout(bool enable) override;
152 int32_t StereoPlayout(bool* enabled) const override;
153 int32_t StereoRecordingIsAvailable(bool* available) const override;
154 int32_t SetStereoRecording(bool enable) override;
155 int32_t StereoRecording(bool* enabled) const override;
156 int32_t SetRecordingChannel(const ChannelType channel) override;
157 int32_t RecordingChannel(ChannelType* channel) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
159 // Delay information and control
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000160 int32_t SetPlayoutBuffer(const BufferType type,
161 uint16_t sizeMS = 0) override;
162 int32_t PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const override;
163 int32_t PlayoutDelay(uint16_t* delayMS) const override;
164 int32_t RecordingDelay(uint16_t* delayMS) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
166 // CPU load
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000167 int32_t CPULoad(uint16_t* load) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
169 // Recording of raw PCM data
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000170 int32_t StartRawOutputFileRecording(
171 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) override;
172 int32_t StopRawOutputFileRecording() override;
173 int32_t StartRawInputFileRecording(
174 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) override;
175 int32_t StopRawInputFileRecording() override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
177 // Native sample rate controls (samples/sec)
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000178 int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) override;
179 int32_t RecordingSampleRate(uint32_t* samplesPerSec) const override;
180 int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) override;
181 int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
183 // Mobile device specific functions
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000184 int32_t ResetAudioDevice() override;
185 int32_t SetLoudspeakerStatus(bool enable) override;
186 int32_t GetLoudspeakerStatus(bool* enabled) const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000188 bool BuiltInAECIsAvailable() const override;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000189
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000190 int32_t EnableBuiltInAEC(bool enable) override;
191 bool BuiltInAECIsEnabled() const override;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000192
niklase@google.com470e71d2011-07-07 08:21:25 +0000193public:
pbos@webrtc.org25509882013-04-09 10:30:35 +0000194 int32_t Id() {return _id;}
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000196 AudioDeviceBuffer* GetAudioDeviceBuffer() {
197 return &_audioDeviceBuffer;
198 }
199
niklase@google.com470e71d2011-07-07 08:21:25 +0000200private:
201 PlatformType Platform() const;
202 AudioLayer PlatformAudioLayer() const;
203
204private:
205 CriticalSectionWrapper& _critSect;
206 CriticalSectionWrapper& _critSectEventCb;
207 CriticalSectionWrapper& _critSectAudioCb;
208
209 AudioDeviceObserver* _ptrCbAudioDeviceObserver;
210
211 AudioDeviceUtility* _ptrAudioDeviceUtility;
212 AudioDeviceGeneric* _ptrAudioDevice;
213
214 AudioDeviceBuffer _audioDeviceBuffer;
215
pbos@webrtc.org25509882013-04-09 10:30:35 +0000216 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217 AudioLayer _platformAudioLayer;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000218 uint32_t _lastProcessTime;
niklase@google.com470e71d2011-07-07 08:21:25 +0000219 PlatformType _platformType;
220 bool _initialized;
221 mutable ErrorCode _lastError;
222};
223
224} // namespace webrtc
225
226#endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_