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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ |
| 12 | #define AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 14 | #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 15 | |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 18 | #include "modules/audio_device/audio_device_buffer.h" |
| 19 | #include "modules/audio_device/include/audio_device.h" |
| 20 | #include "rtc_base/checks.h" |
| 21 | #include "rtc_base/criticalsection.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 23 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | class AudioDeviceGeneric; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 26 | class AudioManager; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 28 | class AudioDeviceModuleImpl : public AudioDeviceModule { |
| 29 | public: |
| 30 | enum PlatformType { |
| 31 | kPlatformNotSupported = 0, |
| 32 | kPlatformWin32 = 1, |
| 33 | kPlatformWinCe = 2, |
| 34 | kPlatformLinux = 3, |
| 35 | kPlatformMac = 4, |
| 36 | kPlatformAndroid = 5, |
| 37 | kPlatformIOS = 6 |
| 38 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 40 | int32_t CheckPlatform(); |
| 41 | int32_t CreatePlatformSpecificObjects(); |
| 42 | int32_t AttachAudioBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 44 | AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer); |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 45 | ~AudioDeviceModuleImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 47 | int64_t TimeUntilNextProcess() override; |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 48 | void Process() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 50 | // Retrieve the currently utilized audio layer |
| 51 | int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 53 | // Error handling |
| 54 | ErrorCode LastError() const override; |
| 55 | int32_t RegisterEventObserver(AudioDeviceObserver* eventCallback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 57 | // Full-duplex transportation of PCM audio |
| 58 | int32_t RegisterAudioCallback(AudioTransport* audioCallback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 60 | // Main initializaton and termination |
| 61 | int32_t Init() override; |
| 62 | int32_t Terminate() override; |
| 63 | bool Initialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 65 | // Device enumeration |
| 66 | int16_t PlayoutDevices() override; |
| 67 | int16_t RecordingDevices() override; |
| 68 | int32_t PlayoutDeviceName(uint16_t index, |
| 69 | char name[kAdmMaxDeviceNameSize], |
| 70 | char guid[kAdmMaxGuidSize]) override; |
| 71 | int32_t RecordingDeviceName(uint16_t index, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 72 | char name[kAdmMaxDeviceNameSize], |
| 73 | char guid[kAdmMaxGuidSize]) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 75 | // Device selection |
| 76 | int32_t SetPlayoutDevice(uint16_t index) override; |
| 77 | int32_t SetPlayoutDevice(WindowsDeviceType device) override; |
| 78 | int32_t SetRecordingDevice(uint16_t index) override; |
| 79 | int32_t SetRecordingDevice(WindowsDeviceType device) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 81 | // Audio transport initialization |
| 82 | int32_t PlayoutIsAvailable(bool* available) override; |
| 83 | int32_t InitPlayout() override; |
| 84 | bool PlayoutIsInitialized() const override; |
| 85 | int32_t RecordingIsAvailable(bool* available) override; |
| 86 | int32_t InitRecording() override; |
| 87 | bool RecordingIsInitialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 89 | // Audio transport control |
| 90 | int32_t StartPlayout() override; |
| 91 | int32_t StopPlayout() override; |
| 92 | bool Playing() const override; |
| 93 | int32_t StartRecording() override; |
| 94 | int32_t StopRecording() override; |
| 95 | bool Recording() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 97 | // Microphone Automatic Gain Control (AGC) |
| 98 | int32_t SetAGC(bool enable) override; |
| 99 | bool AGC() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 101 | // Audio mixer initialization |
| 102 | int32_t InitSpeaker() override; |
| 103 | bool SpeakerIsInitialized() const override; |
| 104 | int32_t InitMicrophone() override; |
| 105 | bool MicrophoneIsInitialized() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 107 | // Speaker volume controls |
| 108 | int32_t SpeakerVolumeIsAvailable(bool* available) override; |
| 109 | int32_t SetSpeakerVolume(uint32_t volume) override; |
| 110 | int32_t SpeakerVolume(uint32_t* volume) const override; |
| 111 | int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override; |
| 112 | int32_t MinSpeakerVolume(uint32_t* minVolume) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 114 | // Microphone volume controls |
| 115 | int32_t MicrophoneVolumeIsAvailable(bool* available) override; |
| 116 | int32_t SetMicrophoneVolume(uint32_t volume) override; |
| 117 | int32_t MicrophoneVolume(uint32_t* volume) const override; |
| 118 | int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override; |
| 119 | int32_t MinMicrophoneVolume(uint32_t* minVolume) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 121 | // Speaker mute control |
| 122 | int32_t SpeakerMuteIsAvailable(bool* available) override; |
| 123 | int32_t SetSpeakerMute(bool enable) override; |
| 124 | int32_t SpeakerMute(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 126 | // Microphone mute control |
| 127 | int32_t MicrophoneMuteIsAvailable(bool* available) override; |
| 128 | int32_t SetMicrophoneMute(bool enable) override; |
| 129 | int32_t MicrophoneMute(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 131 | // Stereo support |
| 132 | int32_t StereoPlayoutIsAvailable(bool* available) const override; |
| 133 | int32_t SetStereoPlayout(bool enable) override; |
| 134 | int32_t StereoPlayout(bool* enabled) const override; |
| 135 | int32_t StereoRecordingIsAvailable(bool* available) const override; |
| 136 | int32_t SetStereoRecording(bool enable) override; |
| 137 | int32_t StereoRecording(bool* enabled) const override; |
| 138 | int32_t SetRecordingChannel(const ChannelType channel) override; |
| 139 | int32_t RecordingChannel(ChannelType* channel) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 141 | // Delay information and control |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 142 | int32_t PlayoutDelay(uint16_t* delayMS) const override; |
| 143 | int32_t RecordingDelay(uint16_t* delayMS) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 145 | // Native sample rate controls (samples/sec) |
| 146 | int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) override; |
| 147 | int32_t RecordingSampleRate(uint32_t* samplesPerSec) const override; |
| 148 | int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) override; |
| 149 | int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 151 | // Mobile device specific functions |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 152 | int32_t SetLoudspeakerStatus(bool enable) override; |
| 153 | int32_t GetLoudspeakerStatus(bool* enabled) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 155 | bool BuiltInAECIsAvailable() const override; |
| 156 | int32_t EnableBuiltInAEC(bool enable) override; |
| 157 | bool BuiltInAGCIsAvailable() const override; |
| 158 | int32_t EnableBuiltInAGC(bool enable) override; |
| 159 | bool BuiltInNSIsAvailable() const override; |
| 160 | int32_t EnableBuiltInNS(bool enable) override; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 161 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 162 | #if defined(WEBRTC_IOS) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 163 | int GetPlayoutAudioParameters(AudioParameters* params) const override; |
| 164 | int GetRecordAudioParameters(AudioParameters* params) const override; |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 165 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 166 | |
| 167 | int32_t Id() { return _id; } |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 168 | #if defined(WEBRTC_ANDROID) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 169 | // Only use this acccessor for test purposes on Android. |
| 170 | AudioManager* GetAndroidAudioManagerForTest() { |
| 171 | return _audioManagerAndroid.get(); |
| 172 | } |
henrika | 24e56e3 | 2015-05-19 11:48:51 +0200 | [diff] [blame] | 173 | #endif |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 174 | AudioDeviceBuffer* GetAudioDeviceBuffer() { return &_audioDeviceBuffer; } |
henrika@webrtc.org | 474d1eb | 2015-03-09 12:39:53 +0000 | [diff] [blame] | 175 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 176 | private: |
| 177 | PlatformType Platform() const; |
| 178 | AudioLayer PlatformAudioLayer() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
kthelgason | 6bfe49c | 2017-03-30 01:14:41 -0700 | [diff] [blame] | 180 | rtc::CriticalSection _critSect; |
| 181 | rtc::CriticalSection _critSectEventCb; |
| 182 | rtc::CriticalSection _critSectAudioCb; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 184 | AudioDeviceObserver* _ptrCbAudioDeviceObserver; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 186 | AudioDeviceGeneric* _ptrAudioDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 187 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 188 | AudioDeviceBuffer _audioDeviceBuffer; |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 189 | #if defined(WEBRTC_ANDROID) |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 190 | std::unique_ptr<AudioManager> _audioManagerAndroid; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 191 | #endif |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 192 | int32_t _id; |
| 193 | AudioLayer _platformAudioLayer; |
| 194 | int64_t _lastProcessTime; |
| 195 | PlatformType _platformType; |
| 196 | bool _initialized; |
| 197 | mutable ErrorCode _lastError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | } // namespace webrtc |
| 201 | |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 202 | #endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 203 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 204 | #endif // MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_ |