niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
henrike@webrtc.org | 70efc32 | 2012-02-23 17:45:33 +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 | |
xians@webrtc.org | 597b447 | 2012-10-11 15:41:55 +0000 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_ |
| 12 | #define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/audio_device/include/audio_device_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/scoped_ref_ptr.h" |
Fredrik Solenberg | a32dd01 | 2017-10-04 13:27:21 +0200 | [diff] [blame] | 16 | #include "rtc_base/refcount.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
Fredrik Solenberg | a32dd01 | 2017-10-04 13:27:21 +0200 | [diff] [blame] | 20 | class AudioDeviceModule : public rtc::RefCountInterface { |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 21 | public: |
henrika | 6592f2c | 2017-10-17 14:47:44 +0200 | [diff] [blame] | 22 | // Deprecated. |
| 23 | // TODO(henrika): to be removed. |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 24 | enum ErrorCode { |
| 25 | kAdmErrNone = 0, |
| 26 | kAdmErrArgument = 1 |
| 27 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 29 | enum AudioLayer { |
| 30 | kPlatformDefaultAudio = 0, |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 31 | kWindowsCoreAudio = 2, |
| 32 | kLinuxAlsaAudio = 3, |
| 33 | kLinuxPulseAudio = 4, |
henrika@webrtc.org | 474d1eb | 2015-03-09 12:39:53 +0000 | [diff] [blame] | 34 | kAndroidJavaAudio = 5, |
henrika | 521f7a8 | 2016-05-31 07:03:17 -0700 | [diff] [blame] | 35 | kAndroidOpenSLESAudio = 6, |
| 36 | kAndroidJavaInputAndOpenSLESOutputAudio = 7, |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 37 | kDummyAudio = 8 |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 38 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 40 | enum WindowsDeviceType { |
| 41 | kDefaultCommunicationDevice = -1, |
| 42 | kDefaultDevice = -2 |
| 43 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
henrika | 8962b54 | 2017-11-13 16:57:58 +0100 | [diff] [blame] | 45 | // TODO(bugs.webrtc.org/7306): deprecated. |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 46 | enum ChannelType { |
| 47 | kChannelLeft = 0, |
| 48 | kChannelRight = 1, |
| 49 | kChannelBoth = 2 |
| 50 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 52 | public: |
henrika | 32026c3 | 2017-11-16 16:15:49 +0100 | [diff] [blame] | 53 | // Creates an ADM. |
henrika | 616e313 | 2017-11-13 12:47:59 +0100 | [diff] [blame] | 54 | static rtc::scoped_refptr<AudioDeviceModule> Create( |
| 55 | const AudioLayer audio_layer); |
henrika | 32026c3 | 2017-11-16 16:15:49 +0100 | [diff] [blame] | 56 | // TODO(bugs.webrtc.org/7306): deprecated (to be removed). |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 57 | static rtc::scoped_refptr<AudioDeviceModule> Create( |
| 58 | const int32_t id, |
| 59 | const AudioLayer audio_layer); |
| 60 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 61 | // Retrieve the currently utilized audio layer |
| 62 | virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 64 | // Full-duplex transportation of PCM audio |
| 65 | virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 67 | // Main initialization and termination |
| 68 | virtual int32_t Init() = 0; |
| 69 | virtual int32_t Terminate() = 0; |
| 70 | virtual bool Initialized() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 72 | // Device enumeration |
| 73 | virtual int16_t PlayoutDevices() = 0; |
| 74 | virtual int16_t RecordingDevices() = 0; |
| 75 | virtual int32_t PlayoutDeviceName(uint16_t index, |
| 76 | char name[kAdmMaxDeviceNameSize], |
| 77 | char guid[kAdmMaxGuidSize]) = 0; |
| 78 | virtual int32_t RecordingDeviceName(uint16_t index, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | char name[kAdmMaxDeviceNameSize], |
| 80 | char guid[kAdmMaxGuidSize]) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 82 | // Device selection |
| 83 | virtual int32_t SetPlayoutDevice(uint16_t index) = 0; |
| 84 | virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0; |
| 85 | virtual int32_t SetRecordingDevice(uint16_t index) = 0; |
| 86 | virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 88 | // Audio transport initialization |
| 89 | virtual int32_t PlayoutIsAvailable(bool* available) = 0; |
| 90 | virtual int32_t InitPlayout() = 0; |
| 91 | virtual bool PlayoutIsInitialized() const = 0; |
| 92 | virtual int32_t RecordingIsAvailable(bool* available) = 0; |
| 93 | virtual int32_t InitRecording() = 0; |
| 94 | virtual bool RecordingIsInitialized() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 96 | // Audio transport control |
| 97 | virtual int32_t StartPlayout() = 0; |
| 98 | virtual int32_t StopPlayout() = 0; |
| 99 | virtual bool Playing() const = 0; |
| 100 | virtual int32_t StartRecording() = 0; |
| 101 | virtual int32_t StopRecording() = 0; |
| 102 | virtual bool Recording() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 104 | // Microphone Automatic Gain Control (AGC) |
| 105 | virtual int32_t SetAGC(bool enable) = 0; |
| 106 | virtual bool AGC() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 108 | // Audio mixer initialization |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 109 | virtual int32_t InitSpeaker() = 0; |
| 110 | virtual bool SpeakerIsInitialized() const = 0; |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 111 | virtual int32_t InitMicrophone() = 0; |
| 112 | virtual bool MicrophoneIsInitialized() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 114 | // Speaker volume controls |
| 115 | virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0; |
| 116 | virtual int32_t SetSpeakerVolume(uint32_t volume) = 0; |
| 117 | virtual int32_t SpeakerVolume(uint32_t* volume) const = 0; |
| 118 | virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0; |
| 119 | virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 121 | // Microphone volume controls |
| 122 | virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0; |
| 123 | virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0; |
| 124 | virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0; |
| 125 | virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0; |
| 126 | virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 128 | // Speaker mute control |
| 129 | virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0; |
| 130 | virtual int32_t SetSpeakerMute(bool enable) = 0; |
| 131 | virtual int32_t SpeakerMute(bool* enabled) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 133 | // Microphone mute control |
| 134 | virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0; |
| 135 | virtual int32_t SetMicrophoneMute(bool enable) = 0; |
| 136 | virtual int32_t MicrophoneMute(bool* enabled) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 138 | // Stereo support |
| 139 | virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0; |
| 140 | virtual int32_t SetStereoPlayout(bool enable) = 0; |
| 141 | virtual int32_t StereoPlayout(bool* enabled) const = 0; |
| 142 | virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0; |
| 143 | virtual int32_t SetStereoRecording(bool enable) = 0; |
| 144 | virtual int32_t StereoRecording(bool* enabled) const = 0; |
Zhi Huang | 2efe87f | 2017-11-22 18:40:05 +0000 | [diff] [blame] | 145 | // TODO(bugs.webrtc.org/7306): deprecated. |
| 146 | virtual int32_t SetRecordingChannel(const ChannelType channel) { return -1; } |
| 147 | virtual int32_t RecordingChannel(ChannelType* channel) const { return -1; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | |
henrika | 6592f2c | 2017-10-17 14:47:44 +0200 | [diff] [blame] | 149 | // Playout delay |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 150 | virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0; |
henrika | 6592f2c | 2017-10-17 14:47:44 +0200 | [diff] [blame] | 151 | |
Zhi Huang | 2efe87f | 2017-11-22 18:40:05 +0000 | [diff] [blame] | 152 | // TODO(bugs.webrtc.org/7306): deprecated (to be removed). |
| 153 | virtual int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) { |
| 154 | return -1; |
| 155 | } |
| 156 | virtual int32_t RecordingSampleRate(uint32_t* samplesPerSec) const { |
| 157 | return -1; |
| 158 | } |
| 159 | virtual int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) { |
| 160 | return -1; |
| 161 | } |
| 162 | virtual int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const { |
| 163 | return -1; |
| 164 | } |
| 165 | |
| 166 | // TODO(bugs.webrtc.org/7306): deprecated (to be removed). |
| 167 | virtual int32_t SetLoudspeakerStatus(bool enable) { return -1; } |
| 168 | virtual int32_t GetLoudspeakerStatus(bool* enabled) const { return -1; } |
| 169 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 170 | // Only supported on Android. |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 171 | virtual bool BuiltInAECIsAvailable() const = 0; |
| 172 | virtual bool BuiltInAGCIsAvailable() const = 0; |
| 173 | virtual bool BuiltInNSIsAvailable() const = 0; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 174 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 175 | // Enables the built-in audio effects. Only supported on Android. |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 176 | virtual int32_t EnableBuiltInAEC(bool enable) = 0; |
| 177 | virtual int32_t EnableBuiltInAGC(bool enable) = 0; |
| 178 | virtual int32_t EnableBuiltInNS(bool enable) = 0; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 179 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 180 | // Only supported on iOS. |
| 181 | #if defined(WEBRTC_IOS) |
| 182 | virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0; |
| 183 | virtual int GetRecordAudioParameters(AudioParameters* params) const = 0; |
| 184 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 185 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 186 | protected: |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 187 | ~AudioDeviceModule() override {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | } // namespace webrtc |
| 191 | |
xians@webrtc.org | 597b447 | 2012-10-11 15:41:55 +0000 | [diff] [blame] | 192 | #endif // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_ |