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 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame^] | 14 | #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 15 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
| 17 | #include "webrtc/base/scoped_ptr.h" |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/audio_device/audio_device_buffer.h" |
| 19 | #include "webrtc/modules/audio_device/include/audio_device.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc |
| 22 | { |
| 23 | |
| 24 | class AudioDeviceGeneric; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 25 | class AudioManager; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | class CriticalSectionWrapper; |
| 27 | |
| 28 | class AudioDeviceModuleImpl : public AudioDeviceModule |
| 29 | { |
| 30 | public: |
| 31 | enum PlatformType |
| 32 | { |
| 33 | kPlatformNotSupported = 0, |
| 34 | kPlatformWin32 = 1, |
| 35 | kPlatformWinCe = 2, |
| 36 | kPlatformLinux = 3, |
leozwang@google.com | 522f42b | 2011-09-19 17:39:05 +0000 | [diff] [blame] | 37 | kPlatformMac = 4, |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 38 | kPlatformAndroid = 5, |
| 39 | kPlatformIOS = 6 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 42 | int32_t CheckPlatform(); |
| 43 | int32_t CreatePlatformSpecificObjects(); |
| 44 | int32_t AttachAudioBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 46 | AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | virtual ~AudioDeviceModuleImpl(); |
| 48 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 49 | public: // RefCountedModule |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 50 | int64_t TimeUntilNextProcess() override; |
| 51 | int32_t Process() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
| 53 | public: |
| 54 | // Factory methods (resource allocation/deallocation) |
| 55 | static AudioDeviceModule* Create( |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 56 | const int32_t id, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | const AudioLayer audioLayer = kPlatformDefaultAudio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
| 59 | // Retrieve the currently utilized audio layer |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 60 | int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
| 62 | // Error handling |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 63 | ErrorCode LastError() const override; |
| 64 | int32_t RegisterEventObserver(AudioDeviceObserver* eventCallback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
| 66 | // Full-duplex transportation of PCM audio |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 67 | int32_t RegisterAudioCallback(AudioTransport* audioCallback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
| 69 | // Main initializaton and termination |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 70 | int32_t Init() override; |
| 71 | int32_t Terminate() override; |
| 72 | bool Initialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
| 74 | // Device enumeration |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 75 | int16_t PlayoutDevices() override; |
| 76 | int16_t RecordingDevices() override; |
| 77 | int32_t PlayoutDeviceName(uint16_t index, |
| 78 | char name[kAdmMaxDeviceNameSize], |
| 79 | char guid[kAdmMaxGuidSize]) override; |
| 80 | int32_t RecordingDeviceName(uint16_t index, |
| 81 | char name[kAdmMaxDeviceNameSize], |
| 82 | char guid[kAdmMaxGuidSize]) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
| 84 | // Device selection |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 85 | int32_t SetPlayoutDevice(uint16_t index) override; |
| 86 | int32_t SetPlayoutDevice(WindowsDeviceType device) override; |
| 87 | int32_t SetRecordingDevice(uint16_t index) override; |
| 88 | int32_t SetRecordingDevice(WindowsDeviceType device) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | // Audio transport initialization |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 91 | int32_t PlayoutIsAvailable(bool* available) override; |
| 92 | int32_t InitPlayout() override; |
| 93 | bool PlayoutIsInitialized() const override; |
| 94 | int32_t RecordingIsAvailable(bool* available) override; |
| 95 | int32_t InitRecording() override; |
| 96 | bool RecordingIsInitialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
| 98 | // Audio transport control |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 99 | int32_t StartPlayout() override; |
| 100 | int32_t StopPlayout() override; |
| 101 | bool Playing() const override; |
| 102 | int32_t StartRecording() override; |
| 103 | int32_t StopRecording() override; |
| 104 | bool Recording() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
| 106 | // Microphone Automatic Gain Control (AGC) |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 107 | int32_t SetAGC(bool enable) override; |
| 108 | bool AGC() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
| 110 | // Volume control based on the Windows Wave API (Windows only) |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 111 | int32_t SetWaveOutVolume(uint16_t volumeLeft, |
| 112 | uint16_t volumeRight) override; |
| 113 | int32_t WaveOutVolume(uint16_t* volumeLeft, |
| 114 | uint16_t* volumeRight) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
| 116 | // Audio mixer initialization |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 117 | int32_t InitSpeaker() override; |
| 118 | bool SpeakerIsInitialized() const override; |
| 119 | int32_t InitMicrophone() override; |
| 120 | bool MicrophoneIsInitialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
| 122 | // Speaker volume controls |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 123 | int32_t SpeakerVolumeIsAvailable(bool* available) override; |
| 124 | int32_t SetSpeakerVolume(uint32_t volume) override; |
| 125 | int32_t SpeakerVolume(uint32_t* volume) const override; |
| 126 | int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override; |
| 127 | int32_t MinSpeakerVolume(uint32_t* minVolume) const override; |
| 128 | int32_t SpeakerVolumeStepSize(uint16_t* stepSize) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
| 130 | // Microphone volume controls |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 131 | int32_t MicrophoneVolumeIsAvailable(bool* available) override; |
| 132 | int32_t SetMicrophoneVolume(uint32_t volume) override; |
| 133 | int32_t MicrophoneVolume(uint32_t* volume) const override; |
| 134 | int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override; |
| 135 | int32_t MinMicrophoneVolume(uint32_t* minVolume) const override; |
| 136 | int32_t MicrophoneVolumeStepSize(uint16_t* stepSize) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | |
| 138 | // Speaker mute control |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 139 | int32_t SpeakerMuteIsAvailable(bool* available) override; |
| 140 | int32_t SetSpeakerMute(bool enable) override; |
| 141 | int32_t SpeakerMute(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
| 143 | // Microphone mute control |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 144 | int32_t MicrophoneMuteIsAvailable(bool* available) override; |
| 145 | int32_t SetMicrophoneMute(bool enable) override; |
| 146 | int32_t MicrophoneMute(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
| 148 | // Microphone boost control |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 149 | int32_t MicrophoneBoostIsAvailable(bool* available) override; |
| 150 | int32_t SetMicrophoneBoost(bool enable) override; |
| 151 | int32_t MicrophoneBoost(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
| 153 | // Stereo support |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 154 | int32_t StereoPlayoutIsAvailable(bool* available) const override; |
| 155 | int32_t SetStereoPlayout(bool enable) override; |
| 156 | int32_t StereoPlayout(bool* enabled) const override; |
| 157 | int32_t StereoRecordingIsAvailable(bool* available) const override; |
| 158 | int32_t SetStereoRecording(bool enable) override; |
| 159 | int32_t StereoRecording(bool* enabled) const override; |
| 160 | int32_t SetRecordingChannel(const ChannelType channel) override; |
| 161 | int32_t RecordingChannel(ChannelType* channel) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | |
| 163 | // Delay information and control |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 164 | int32_t SetPlayoutBuffer(const BufferType type, |
| 165 | uint16_t sizeMS = 0) override; |
| 166 | int32_t PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const override; |
| 167 | int32_t PlayoutDelay(uint16_t* delayMS) const override; |
| 168 | int32_t RecordingDelay(uint16_t* delayMS) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
| 170 | // CPU load |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 171 | int32_t CPULoad(uint16_t* load) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | |
| 173 | // Recording of raw PCM data |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 174 | int32_t StartRawOutputFileRecording( |
| 175 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) override; |
| 176 | int32_t StopRawOutputFileRecording() override; |
| 177 | int32_t StartRawInputFileRecording( |
| 178 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) override; |
| 179 | int32_t StopRawInputFileRecording() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 180 | |
| 181 | // Native sample rate controls (samples/sec) |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 182 | int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) override; |
| 183 | int32_t RecordingSampleRate(uint32_t* samplesPerSec) const override; |
| 184 | int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) override; |
| 185 | int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
| 187 | // Mobile device specific functions |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 188 | int32_t ResetAudioDevice() override; |
| 189 | int32_t SetLoudspeakerStatus(bool enable) override; |
| 190 | int32_t GetLoudspeakerStatus(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 192 | bool BuiltInAECIsAvailable() const override; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 193 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 194 | int32_t EnableBuiltInAEC(bool enable) override; |
| 195 | bool BuiltInAECIsEnabled() const override; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 196 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | public: |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 198 | int32_t Id() {return _id;} |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame^] | 199 | #if defined(WEBRTC_ANDROID) |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 200 | // Only use this acccessor for test purposes on Android. |
| 201 | AudioManager* GetAndroidAudioManagerForTest() { |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 202 | return _audioManagerAndroid.get(); |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 203 | } |
henrika | 24e56e3 | 2015-05-19 11:48:51 +0200 | [diff] [blame] | 204 | #endif |
henrika@webrtc.org | 474d1eb | 2015-03-09 12:39:53 +0000 | [diff] [blame] | 205 | AudioDeviceBuffer* GetAudioDeviceBuffer() { |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 206 | return &_audioDeviceBuffer; |
henrika@webrtc.org | 474d1eb | 2015-03-09 12:39:53 +0000 | [diff] [blame] | 207 | } |
| 208 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 209 | private: |
| 210 | PlatformType Platform() const; |
| 211 | AudioLayer PlatformAudioLayer() const; |
| 212 | |
| 213 | private: |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 214 | CriticalSectionWrapper& _critSect; |
| 215 | CriticalSectionWrapper& _critSectEventCb; |
| 216 | CriticalSectionWrapper& _critSectAudioCb; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 218 | AudioDeviceObserver* _ptrCbAudioDeviceObserver; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 219 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 220 | AudioDeviceGeneric* _ptrAudioDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 222 | AudioDeviceBuffer _audioDeviceBuffer; |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame^] | 223 | #if defined(WEBRTC_ANDROID) |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 224 | rtc::scoped_ptr<AudioManager> _audioManagerAndroid; |
| 225 | #endif |
| 226 | int32_t _id; |
| 227 | AudioLayer _platformAudioLayer; |
Tommi | 68898a2 | 2015-05-19 17:28:07 +0200 | [diff] [blame] | 228 | int64_t _lastProcessTime; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 229 | PlatformType _platformType; |
| 230 | bool _initialized; |
| 231 | mutable ErrorCode _lastError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | } // namespace webrtc |
| 235 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame^] | 236 | #endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 237 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 238 | #endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_ |