niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/audio_device/audio_device_buffer.h" |
| 15 | #include "webrtc/modules/audio_device/include/audio_device.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc |
| 18 | { |
| 19 | |
| 20 | class AudioDeviceGeneric; |
| 21 | class AudioDeviceUtility; |
| 22 | class CriticalSectionWrapper; |
| 23 | |
| 24 | class AudioDeviceModuleImpl : public AudioDeviceModule |
| 25 | { |
| 26 | public: |
| 27 | enum PlatformType |
| 28 | { |
| 29 | kPlatformNotSupported = 0, |
| 30 | kPlatformWin32 = 1, |
| 31 | kPlatformWinCe = 2, |
| 32 | kPlatformLinux = 3, |
leozwang@google.com | 522f42b | 2011-09-19 17:39:05 +0000 | [diff] [blame] | 33 | kPlatformMac = 4, |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 34 | kPlatformAndroid = 5, |
| 35 | kPlatformIOS = 6 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 38 | int32_t CheckPlatform(); |
| 39 | int32_t CreatePlatformSpecificObjects(); |
| 40 | int32_t AttachAudioBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 42 | AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | virtual ~AudioDeviceModuleImpl(); |
| 44 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 45 | public: // RefCountedModule |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 46 | virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE; |
| 47 | virtual int32_t TimeUntilNextProcess() OVERRIDE; |
| 48 | virtual int32_t Process() OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
| 50 | public: |
| 51 | // Factory methods (resource allocation/deallocation) |
| 52 | static AudioDeviceModule* Create( |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 53 | const int32_t id, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | const AudioLayer audioLayer = kPlatformDefaultAudio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
| 56 | // Retrieve the currently utilized audio layer |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 57 | virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
| 59 | // Error handling |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 60 | virtual ErrorCode LastError() const OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 61 | virtual int32_t RegisterEventObserver( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 62 | AudioDeviceObserver* eventCallback) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
| 64 | // Full-duplex transportation of PCM audio |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 65 | virtual int32_t RegisterAudioCallback( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 66 | AudioTransport* audioCallback) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
| 68 | // Main initializaton and termination |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 69 | virtual int32_t Init() OVERRIDE; |
| 70 | virtual int32_t Terminate() OVERRIDE; |
| 71 | virtual bool Initialized() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
| 73 | // Device enumeration |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 74 | virtual int16_t PlayoutDevices() OVERRIDE; |
| 75 | virtual int16_t RecordingDevices() OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 76 | virtual int32_t PlayoutDeviceName( |
| 77 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 78 | char name[kAdmMaxDeviceNameSize], |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 79 | char guid[kAdmMaxGuidSize]) OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 80 | virtual int32_t RecordingDeviceName( |
| 81 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 82 | char name[kAdmMaxDeviceNameSize], |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 83 | char guid[kAdmMaxGuidSize]) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
| 85 | // Device selection |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 86 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
| 91 | // Audio transport initialization |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 92 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
| 99 | // Audio transport control |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 100 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
| 107 | // Microphone Automatic Gain Control (AGC) |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 108 | virtual int32_t SetAGC(bool enable) OVERRIDE; |
| 109 | virtual bool AGC() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | |
| 111 | // Volume control based on the Windows Wave API (Windows only) |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 112 | virtual int32_t SetWaveOutVolume(uint16_t volumeLeft, |
| 113 | uint16_t volumeRight) OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 114 | virtual int32_t WaveOutVolume(uint16_t* volumeLeft, |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 115 | uint16_t* volumeRight) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
| 117 | // Audio mixer initialization |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 118 | virtual int32_t InitSpeaker() OVERRIDE; |
| 119 | virtual bool SpeakerIsInitialized() const OVERRIDE; |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 120 | virtual int32_t InitMicrophone() OVERRIDE; |
| 121 | virtual bool MicrophoneIsInitialized() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
| 123 | // Speaker volume controls |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 124 | 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.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 129 | virtual int32_t SpeakerVolumeStepSize( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 130 | uint16_t* stepSize) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | |
| 132 | // Microphone volume controls |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 133 | 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.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 136 | virtual int32_t MaxMicrophoneVolume( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 137 | uint32_t* maxVolume) const OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 138 | virtual int32_t MinMicrophoneVolume( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 139 | uint32_t* minVolume) const OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 140 | virtual int32_t MicrophoneVolumeStepSize( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 141 | uint16_t* stepSize) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
| 143 | // Speaker mute control |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 144 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
| 148 | // Microphone mute control |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 149 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
| 153 | // Microphone boost control |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 154 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | |
| 158 | // Stereo support |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 159 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | |
| 168 | // Delay information and control |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 169 | virtual int32_t SetPlayoutBuffer(const BufferType type, |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 170 | uint16_t sizeMS = 0) OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 171 | virtual int32_t PlayoutBuffer(BufferType* type, |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 172 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | |
| 176 | // CPU load |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 177 | virtual int32_t CPULoad(uint16_t* load) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | |
| 179 | // Recording of raw PCM data |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 180 | virtual int32_t StartRawOutputFileRecording( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 181 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) OVERRIDE; |
| 182 | virtual int32_t StopRawOutputFileRecording() OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 183 | virtual int32_t StartRawInputFileRecording( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 184 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) OVERRIDE; |
| 185 | virtual int32_t StopRawInputFileRecording() OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
| 187 | // Native sample rate controls (samples/sec) |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 188 | virtual int32_t SetRecordingSampleRate( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 189 | const uint32_t samplesPerSec) OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 190 | virtual int32_t RecordingSampleRate( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 191 | uint32_t* samplesPerSec) const OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 192 | virtual int32_t SetPlayoutSampleRate( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 193 | const uint32_t samplesPerSec) OVERRIDE; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 194 | virtual int32_t PlayoutSampleRate( |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 195 | uint32_t* samplesPerSec) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | |
| 197 | // Mobile device specific functions |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 198 | virtual int32_t ResetAudioDevice() OVERRIDE; |
| 199 | virtual int32_t SetLoudspeakerStatus(bool enable) OVERRIDE; |
| 200 | virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | |
pbos@webrtc.org | 096515b | 2013-07-30 12:32:59 +0000 | [diff] [blame] | 202 | virtual int32_t EnableBuiltInAEC(bool enable) OVERRIDE; |
| 203 | virtual bool BuiltInAECIsEnabled() const OVERRIDE; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 204 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | public: |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 206 | int32_t Id() {return _id;} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
| 208 | private: |
| 209 | PlatformType Platform() const; |
| 210 | AudioLayer PlatformAudioLayer() const; |
| 211 | |
| 212 | private: |
| 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.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 224 | int32_t _id; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 225 | AudioLayer _platformAudioLayer; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 226 | uint32_t _lastProcessTime; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | PlatformType _platformType; |
| 228 | bool _initialized; |
| 229 | mutable ErrorCode _lastError; |
| 230 | }; |
| 231 | |
| 232 | } // namespace webrtc |
| 233 | |
| 234 | #endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_ |