blob: a545d580f4bcadaecf6ff94933a8db7e22a674ac [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
pbos@webrtc.org096515b2013-07-30 12:32:59 +000046 virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
47 virtual int32_t TimeUntilNextProcess() OVERRIDE;
48 virtual int32_t Process() OVERRIDE;
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.org096515b2013-07-30 12:32:59 +000057 virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59 // Error handling
pbos@webrtc.org096515b2013-07-30 12:32:59 +000060 virtual ErrorCode LastError() const OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +000061 virtual int32_t RegisterEventObserver(
pbos@webrtc.org096515b2013-07-30 12:32:59 +000062 AudioDeviceObserver* eventCallback) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
64 // Full-duplex transportation of PCM audio
pbos@webrtc.org25509882013-04-09 10:30:35 +000065 virtual int32_t RegisterAudioCallback(
pbos@webrtc.org096515b2013-07-30 12:32:59 +000066 AudioTransport* audioCallback) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000067
68 // Main initializaton and termination
pbos@webrtc.org096515b2013-07-30 12:32:59 +000069 virtual int32_t Init() OVERRIDE;
70 virtual int32_t Terminate() OVERRIDE;
71 virtual bool Initialized() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
73 // Device enumeration
pbos@webrtc.org096515b2013-07-30 12:32:59 +000074 virtual int16_t PlayoutDevices() OVERRIDE;
75 virtual int16_t RecordingDevices() OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +000076 virtual int32_t PlayoutDeviceName(
77 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +000078 char name[kAdmMaxDeviceNameSize],
pbos@webrtc.org096515b2013-07-30 12:32:59 +000079 char guid[kAdmMaxGuidSize]) OVERRIDE;
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],
pbos@webrtc.org096515b2013-07-30 12:32:59 +000083 char guid[kAdmMaxGuidSize]) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
85 // Device selection
pbos@webrtc.org096515b2013-07-30 12:32:59 +000086 virtual int32_t SetPlayoutDevice(uint16_t index) OVERRIDE;
87 virtual int32_t SetPlayoutDevice(WindowsDeviceType device) OVERRIDE;
88 virtual int32_t SetRecordingDevice(uint16_t index) OVERRIDE;
89 virtual int32_t SetRecordingDevice(WindowsDeviceType device) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000090
91 // Audio transport initialization
pbos@webrtc.org096515b2013-07-30 12:32:59 +000092 virtual int32_t PlayoutIsAvailable(bool* available) OVERRIDE;
93 virtual int32_t InitPlayout() OVERRIDE;
94 virtual bool PlayoutIsInitialized() const OVERRIDE;
95 virtual int32_t RecordingIsAvailable(bool* available) OVERRIDE;
96 virtual int32_t InitRecording() OVERRIDE;
97 virtual bool RecordingIsInitialized() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
99 // Audio transport control
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000100 virtual int32_t StartPlayout() OVERRIDE;
101 virtual int32_t StopPlayout() OVERRIDE;
102 virtual bool Playing() const OVERRIDE;
103 virtual int32_t StartRecording() OVERRIDE;
104 virtual int32_t StopRecording() OVERRIDE;
105 virtual bool Recording() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
107 // Microphone Automatic Gain Control (AGC)
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000108 virtual int32_t SetAGC(bool enable) OVERRIDE;
109 virtual bool AGC() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
111 // Volume control based on the Windows Wave API (Windows only)
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000112 virtual int32_t SetWaveOutVolume(uint16_t volumeLeft,
113 uint16_t volumeRight) OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000114 virtual int32_t WaveOutVolume(uint16_t* volumeLeft,
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000115 uint16_t* volumeRight) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
117 // Audio mixer initialization
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000118 virtual int32_t InitSpeaker() OVERRIDE;
119 virtual bool SpeakerIsInitialized() const OVERRIDE;
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000120 virtual int32_t InitMicrophone() OVERRIDE;
121 virtual bool MicrophoneIsInitialized() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
123 // Speaker volume controls
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000124 virtual int32_t SpeakerVolumeIsAvailable(bool* available) OVERRIDE;
125 virtual int32_t SetSpeakerVolume(uint32_t volume) OVERRIDE;
126 virtual int32_t SpeakerVolume(uint32_t* volume) const OVERRIDE;
127 virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const OVERRIDE;
128 virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000129 virtual int32_t SpeakerVolumeStepSize(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000130 uint16_t* stepSize) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
132 // Microphone volume controls
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000133 virtual int32_t MicrophoneVolumeIsAvailable(bool* available) OVERRIDE;
134 virtual int32_t SetMicrophoneVolume(uint32_t volume) OVERRIDE;
135 virtual int32_t MicrophoneVolume(uint32_t* volume) const OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000136 virtual int32_t MaxMicrophoneVolume(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000137 uint32_t* maxVolume) const OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000138 virtual int32_t MinMicrophoneVolume(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000139 uint32_t* minVolume) const OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000140 virtual int32_t MicrophoneVolumeStepSize(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000141 uint16_t* stepSize) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
143 // Speaker mute control
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000144 virtual int32_t SpeakerMuteIsAvailable(bool* available) OVERRIDE;
145 virtual int32_t SetSpeakerMute(bool enable) OVERRIDE;
146 virtual int32_t SpeakerMute(bool* enabled) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
148 // Microphone mute control
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000149 virtual int32_t MicrophoneMuteIsAvailable(bool* available) OVERRIDE;
150 virtual int32_t SetMicrophoneMute(bool enable) OVERRIDE;
151 virtual int32_t MicrophoneMute(bool* enabled) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
153 // Microphone boost control
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000154 virtual int32_t MicrophoneBoostIsAvailable(bool* available) OVERRIDE;
155 virtual int32_t SetMicrophoneBoost(bool enable) OVERRIDE;
156 virtual int32_t MicrophoneBoost(bool* enabled) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
158 // Stereo support
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000159 virtual int32_t StereoPlayoutIsAvailable(bool* available) const OVERRIDE;
160 virtual int32_t SetStereoPlayout(bool enable) OVERRIDE;
161 virtual int32_t StereoPlayout(bool* enabled) const OVERRIDE;
162 virtual int32_t StereoRecordingIsAvailable(bool* available) const OVERRIDE;
163 virtual int32_t SetStereoRecording(bool enable) OVERRIDE;
164 virtual int32_t StereoRecording(bool* enabled) const OVERRIDE;
165 virtual int32_t SetRecordingChannel(const ChannelType channel) OVERRIDE;
166 virtual int32_t RecordingChannel(ChannelType* channel) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
168 // Delay information and control
pbos@webrtc.org25509882013-04-09 10:30:35 +0000169 virtual int32_t SetPlayoutBuffer(const BufferType type,
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000170 uint16_t sizeMS = 0) OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000171 virtual int32_t PlayoutBuffer(BufferType* type,
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000172 uint16_t* sizeMS) const OVERRIDE;
173 virtual int32_t PlayoutDelay(uint16_t* delayMS) const OVERRIDE;
174 virtual int32_t RecordingDelay(uint16_t* delayMS) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
176 // CPU load
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000177 virtual int32_t CPULoad(uint16_t* load) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
179 // Recording of raw PCM data
pbos@webrtc.org25509882013-04-09 10:30:35 +0000180 virtual int32_t StartRawOutputFileRecording(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000181 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) OVERRIDE;
182 virtual int32_t StopRawOutputFileRecording() OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000183 virtual int32_t StartRawInputFileRecording(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000184 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) OVERRIDE;
185 virtual int32_t StopRawInputFileRecording() OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
187 // Native sample rate controls (samples/sec)
pbos@webrtc.org25509882013-04-09 10:30:35 +0000188 virtual int32_t SetRecordingSampleRate(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000189 const uint32_t samplesPerSec) OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000190 virtual int32_t RecordingSampleRate(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000191 uint32_t* samplesPerSec) const OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000192 virtual int32_t SetPlayoutSampleRate(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000193 const uint32_t samplesPerSec) OVERRIDE;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000194 virtual int32_t PlayoutSampleRate(
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000195 uint32_t* samplesPerSec) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
197 // Mobile device specific functions
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000198 virtual int32_t ResetAudioDevice() OVERRIDE;
199 virtual int32_t SetLoudspeakerStatus(bool enable) OVERRIDE;
200 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
pbos@webrtc.org096515b2013-07-30 12:32:59 +0000202 virtual int32_t EnableBuiltInAEC(bool enable) OVERRIDE;
203 virtual bool BuiltInAECIsEnabled() const OVERRIDE;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000204
niklase@google.com470e71d2011-07-07 08:21:25 +0000205public:
pbos@webrtc.org25509882013-04-09 10:30:35 +0000206 int32_t Id() {return _id;}
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
208private:
209 PlatformType Platform() const;
210 AudioLayer PlatformAudioLayer() const;
211
212private:
213 CriticalSectionWrapper& _critSect;
214 CriticalSectionWrapper& _critSectEventCb;
215 CriticalSectionWrapper& _critSectAudioCb;
216
217 AudioDeviceObserver* _ptrCbAudioDeviceObserver;
218
219 AudioDeviceUtility* _ptrAudioDeviceUtility;
220 AudioDeviceGeneric* _ptrAudioDevice;
221
222 AudioDeviceBuffer _audioDeviceBuffer;
223
pbos@webrtc.org25509882013-04-09 10:30:35 +0000224 int32_t _id;
niklase@google.com470e71d2011-07-07 08:21:25 +0000225 AudioLayer _platformAudioLayer;
pbos@webrtc.org25509882013-04-09 10:30:35 +0000226 uint32_t _lastProcessTime;
niklase@google.com470e71d2011-07-07 08:21:25 +0000227 PlatformType _platformType;
228 bool _initialized;
229 mutable ErrorCode _lastError;
230};
231
232} // namespace webrtc
233
234#endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_