Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 1 | /* |
henrike@webrtc.org | 70efc32 | 2012-02-23 17:45:33 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [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 | [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 | [diff] [blame] | 13 | |
Fredrik Hernqvist | efbe753 | 2023-01-13 15:42:36 | [diff] [blame] | 14 | #include "absl/types/optional.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 15 | #include "api/scoped_refptr.h" |
Danil Chapovalov | 1c41be6 | 2019-04-01 07:16:12 | [diff] [blame] | 16 | #include "api/task_queue/task_queue_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "modules/audio_device/include/audio_device_defines.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 18 | #include "rtc_base/ref_count.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
henrika | 5b6afc0 | 2018-09-05 12:34:40 | [diff] [blame] | 22 | class AudioDeviceModuleForTest; |
| 23 | |
Fredrik Solenberg | a32dd01 | 2017-10-04 11:27:21 | [diff] [blame] | 24 | class AudioDeviceModule : public rtc::RefCountInterface { |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 25 | public: |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 26 | enum AudioLayer { |
| 27 | kPlatformDefaultAudio = 0, |
henrika | ec9c745 | 2018-06-08 14:10:03 | [diff] [blame] | 28 | kWindowsCoreAudio, |
Anders Klemets | eb8c4ca | 2019-12-06 02:41:39 | [diff] [blame] | 29 | kWindowsCoreAudio2, |
henrika | ec9c745 | 2018-06-08 14:10:03 | [diff] [blame] | 30 | kLinuxAlsaAudio, |
| 31 | kLinuxPulseAudio, |
| 32 | kAndroidJavaAudio, |
| 33 | kAndroidOpenSLESAudio, |
| 34 | kAndroidJavaInputAndOpenSLESOutputAudio, |
| 35 | kAndroidAAudioAudio, |
| 36 | kAndroidJavaInputAndAAudioOutputAudio, |
| 37 | kDummyAudio, |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 38 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 39 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 40 | enum WindowsDeviceType { |
| 41 | kDefaultCommunicationDevice = -1, |
| 42 | kDefaultDevice = -2 |
| 43 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 44 | |
Fredrik Hernqvist | efbe753 | 2023-01-13 15:42:36 | [diff] [blame] | 45 | struct Stats { |
| 46 | // The fields below correspond to similarly-named fields in the WebRTC stats |
| 47 | // spec. https://w3c.github.io/webrtc-stats/#playoutstats-dict* |
| 48 | double synthesized_samples_duration_s = 0; |
| 49 | uint64_t synthesized_samples_events = 0; |
| 50 | double total_samples_duration_s = 0; |
| 51 | double total_playout_delay_s = 0; |
| 52 | uint64_t total_samples_count = 0; |
| 53 | }; |
| 54 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 55 | public: |
henrika | 5b6afc0 | 2018-09-05 12:34:40 | [diff] [blame] | 56 | // Creates a default ADM for usage in production code. |
henrika | 616e313 | 2017-11-13 11:47:59 | [diff] [blame] | 57 | static rtc::scoped_refptr<AudioDeviceModule> Create( |
Danil Chapovalov | 1c41be6 | 2019-04-01 07:16:12 | [diff] [blame] | 58 | AudioLayer audio_layer, |
| 59 | TaskQueueFactory* task_queue_factory); |
henrika | 5b6afc0 | 2018-09-05 12:34:40 | [diff] [blame] | 60 | // Creates an ADM with support for extra test methods. Don't use this factory |
| 61 | // in production code. |
| 62 | static rtc::scoped_refptr<AudioDeviceModuleForTest> CreateForTest( |
Danil Chapovalov | 1c41be6 | 2019-04-01 07:16:12 | [diff] [blame] | 63 | AudioLayer audio_layer, |
| 64 | TaskQueueFactory* task_queue_factory); |
Peter Boström | 4adbbcf | 2016-05-03 19:51:26 | [diff] [blame] | 65 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 66 | // Retrieve the currently utilized audio layer |
| 67 | virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 68 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 69 | // Full-duplex transportation of PCM audio |
| 70 | virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 71 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 72 | // Main initialization and termination |
| 73 | virtual int32_t Init() = 0; |
| 74 | virtual int32_t Terminate() = 0; |
| 75 | virtual bool Initialized() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 76 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 77 | // Device enumeration |
| 78 | virtual int16_t PlayoutDevices() = 0; |
| 79 | virtual int16_t RecordingDevices() = 0; |
| 80 | virtual int32_t PlayoutDeviceName(uint16_t index, |
| 81 | char name[kAdmMaxDeviceNameSize], |
| 82 | char guid[kAdmMaxGuidSize]) = 0; |
| 83 | virtual int32_t RecordingDeviceName(uint16_t index, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 84 | char name[kAdmMaxDeviceNameSize], |
| 85 | char guid[kAdmMaxGuidSize]) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 86 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 87 | // Device selection |
| 88 | virtual int32_t SetPlayoutDevice(uint16_t index) = 0; |
| 89 | virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0; |
| 90 | virtual int32_t SetRecordingDevice(uint16_t index) = 0; |
| 91 | virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 92 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 93 | // Audio transport initialization |
| 94 | virtual int32_t PlayoutIsAvailable(bool* available) = 0; |
| 95 | virtual int32_t InitPlayout() = 0; |
| 96 | virtual bool PlayoutIsInitialized() const = 0; |
| 97 | virtual int32_t RecordingIsAvailable(bool* available) = 0; |
| 98 | virtual int32_t InitRecording() = 0; |
| 99 | virtual bool RecordingIsInitialized() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 100 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 101 | // Audio transport control |
| 102 | virtual int32_t StartPlayout() = 0; |
| 103 | virtual int32_t StopPlayout() = 0; |
| 104 | virtual bool Playing() const = 0; |
| 105 | virtual int32_t StartRecording() = 0; |
| 106 | virtual int32_t StopRecording() = 0; |
| 107 | virtual bool Recording() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 108 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 109 | // Audio mixer initialization |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 110 | virtual int32_t InitSpeaker() = 0; |
| 111 | virtual bool SpeakerIsInitialized() const = 0; |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 112 | virtual int32_t InitMicrophone() = 0; |
| 113 | virtual bool MicrophoneIsInitialized() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 114 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 115 | // Speaker volume controls |
| 116 | virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0; |
| 117 | virtual int32_t SetSpeakerVolume(uint32_t volume) = 0; |
| 118 | virtual int32_t SpeakerVolume(uint32_t* volume) const = 0; |
| 119 | virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0; |
| 120 | virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 121 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 122 | // Microphone volume controls |
| 123 | virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0; |
| 124 | virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0; |
| 125 | virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0; |
| 126 | virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0; |
| 127 | virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 128 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 129 | // Speaker mute control |
| 130 | virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0; |
| 131 | virtual int32_t SetSpeakerMute(bool enable) = 0; |
| 132 | virtual int32_t SpeakerMute(bool* enabled) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 133 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 134 | // Microphone mute control |
| 135 | virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0; |
| 136 | virtual int32_t SetMicrophoneMute(bool enable) = 0; |
| 137 | virtual int32_t MicrophoneMute(bool* enabled) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 138 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 139 | // Stereo support |
| 140 | virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0; |
| 141 | virtual int32_t SetStereoPlayout(bool enable) = 0; |
| 142 | virtual int32_t StereoPlayout(bool* enabled) const = 0; |
| 143 | virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0; |
| 144 | virtual int32_t SetStereoRecording(bool enable) = 0; |
| 145 | virtual int32_t StereoRecording(bool* enabled) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 146 | |
henrika | 6592f2c | 2017-10-17 12:47:44 | [diff] [blame] | 147 | // Playout delay |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 148 | virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0; |
henrika | 6592f2c | 2017-10-17 12:47:44 | [diff] [blame] | 149 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 | [diff] [blame] | 150 | // Only supported on Android. |
maxmorin | 88e31a3 | 2016-08-16 07:56:09 | [diff] [blame] | 151 | virtual bool BuiltInAECIsAvailable() const = 0; |
| 152 | virtual bool BuiltInAGCIsAvailable() const = 0; |
| 153 | virtual bool BuiltInNSIsAvailable() const = 0; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 | [diff] [blame] | 154 | |
henrika | c14f5ff | 2015-09-23 12:08:33 | [diff] [blame] | 155 | // Enables the built-in audio effects. Only supported on Android. |
maxmorin | 88e31a3 | 2016-08-16 07:56:09 | [diff] [blame] | 156 | virtual int32_t EnableBuiltInAEC(bool enable) = 0; |
| 157 | virtual int32_t EnableBuiltInAGC(bool enable) = 0; |
| 158 | virtual int32_t EnableBuiltInNS(bool enable) = 0; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 | [diff] [blame] | 159 | |
Alex Narest | bbeb109 | 2019-08-16 09:49:04 | [diff] [blame] | 160 | // Play underrun count. Only supported on Android. |
| 161 | // TODO(alexnarest): Make it abstract after upstream projects support it. |
| 162 | virtual int32_t GetPlayoutUnderrunCount() const { return -1; } |
| 163 | |
Fredrik Hernqvist | efbe753 | 2023-01-13 15:42:36 | [diff] [blame] | 164 | // Used to generate RTC stats. If not implemented, RTCAudioPlayoutStats will |
| 165 | // not be present in the stats. |
| 166 | virtual absl::optional<Stats> GetStats() const { return absl::nullopt; } |
| 167 | |
maxmorin | 88e31a3 | 2016-08-16 07:56:09 | [diff] [blame] | 168 | // Only supported on iOS. |
| 169 | #if defined(WEBRTC_IOS) |
| 170 | virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0; |
| 171 | virtual int GetRecordAudioParameters(AudioParameters* params) const = 0; |
| 172 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 15:04:08 | [diff] [blame] | 173 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 | [diff] [blame] | 174 | protected: |
maxmorin | 88e31a3 | 2016-08-16 07:56:09 | [diff] [blame] | 175 | ~AudioDeviceModule() override {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 176 | }; |
| 177 | |
henrika | 5b6afc0 | 2018-09-05 12:34:40 | [diff] [blame] | 178 | // Extends the default ADM interface with some extra test methods. |
| 179 | // Intended for usage in tests only and requires a unique factory method. |
| 180 | class AudioDeviceModuleForTest : public AudioDeviceModule { |
| 181 | public: |
| 182 | // Triggers internal restart sequences of audio streaming. Can be used by |
| 183 | // tests to emulate events corresponding to e.g. removal of an active audio |
| 184 | // device or other actions which causes the stream to be disconnected. |
| 185 | virtual int RestartPlayoutInternally() = 0; |
| 186 | virtual int RestartRecordingInternally() = 0; |
| 187 | |
| 188 | virtual int SetPlayoutSampleRate(uint32_t sample_rate) = 0; |
| 189 | virtual int SetRecordingSampleRate(uint32_t sample_rate) = 0; |
| 190 | }; |
| 191 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 192 | } // namespace webrtc |
| 193 | |
xians@webrtc.org | 597b447 | 2012-10-11 15:41:55 | [diff] [blame] | 194 | #endif // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_ |