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