niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
xians@webrtc.org | 20aabbb | 2012-02-20 09:17:41 +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 | #include "modules/audio_device/audio_device_impl.h" |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 15 | #include "api/scoped_refptr.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include "modules/audio_device/audio_device_config.h" // IWYU pragma: keep |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_device/audio_device_generic.h" |
| 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/logging.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "rtc_base/ref_counted_object.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "system_wrappers/include/metrics.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | #if defined(_WIN32) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 24 | #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 25 | #include "modules/audio_device/win/audio_device_core_win.h" |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 26 | #endif |
leozwang@google.com | 39f2051 | 2011-07-15 16:29:40 +0000 | [diff] [blame] | 27 | #elif defined(WEBRTC_ANDROID) |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 28 | #include <stdlib.h> |
Mirko Bonadei | 185e802 | 2019-03-27 21:11:17 +0100 | [diff] [blame] | 29 | #if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 30 | #include "modules/audio_device/android/aaudio_player.h" |
| 31 | #include "modules/audio_device/android/aaudio_recorder.h" |
| 32 | #endif |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "modules/audio_device/android/audio_device_template.h" |
| 34 | #include "modules/audio_device/android/audio_manager.h" |
| 35 | #include "modules/audio_device/android/audio_record_jni.h" |
| 36 | #include "modules/audio_device/android/audio_track_jni.h" |
| 37 | #include "modules/audio_device/android/opensles_player.h" |
| 38 | #include "modules/audio_device/android/opensles_recorder.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | #elif defined(WEBRTC_LINUX) |
Mirko Bonadei | fc9770c | 2020-03-24 12:56:47 +0100 | [diff] [blame] | 40 | #if defined(WEBRTC_ENABLE_LINUX_ALSA) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 41 | #include "modules/audio_device/linux/audio_device_alsa_linux.h" |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 42 | #endif |
Mirko Bonadei | fc9770c | 2020-03-24 12:56:47 +0100 | [diff] [blame] | 43 | #if defined(WEBRTC_ENABLE_LINUX_PULSE) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 44 | #include "modules/audio_device/linux/audio_device_pulse_linux.h" |
Tommi | 68898a2 | 2015-05-19 17:28:07 +0200 | [diff] [blame] | 45 | #endif |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 46 | #elif defined(WEBRTC_IOS) |
Kári Tristan Helgason | 7a930da | 2019-04-10 08:43:53 +0200 | [diff] [blame] | 47 | #include "sdk/objc/native/src/audio/audio_device_ios.h" |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 48 | #elif defined(WEBRTC_MAC) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 49 | #include "modules/audio_device/mac/audio_device_mac.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | #endif |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 51 | #if defined(WEBRTC_DUMMY_FILE_DEVICES) |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 52 | #include "modules/audio_device/dummy/file_audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 53 | #include "modules/audio_device/dummy/file_audio_device_factory.h" |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 54 | #endif |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 55 | #include "modules/audio_device/dummy/audio_device_dummy.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 57 | #define CHECKinitialized_() \ |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 58 | { \ |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 59 | if (!initialized_) { \ |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 60 | return -1; \ |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 61 | } \ |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 62 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 64 | #define CHECKinitialized__BOOL() \ |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 65 | { \ |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 66 | if (!initialized_) { \ |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 67 | return false; \ |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 68 | } \ |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 69 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 71 | namespace webrtc { |
henrike@webrtc.org | 70efc32 | 2012-02-23 17:45:33 +0000 | [diff] [blame] | 72 | |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 73 | rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create( |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 74 | AudioLayer audio_layer, |
| 75 | TaskQueueFactory* task_queue_factory) { |
Mirko Bonadei | 3b68aa3 | 2021-01-28 09:21:06 +0100 | [diff] [blame] | 76 | RTC_DLOG(INFO) << __FUNCTION__; |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 77 | return AudioDeviceModule::CreateForTest(audio_layer, task_queue_factory); |
henrika | 5b6afc0 | 2018-09-05 14:34:40 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // static |
| 81 | rtc::scoped_refptr<AudioDeviceModuleForTest> AudioDeviceModule::CreateForTest( |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 82 | AudioLayer audio_layer, |
| 83 | TaskQueueFactory* task_queue_factory) { |
Mirko Bonadei | 3b68aa3 | 2021-01-28 09:21:06 +0100 | [diff] [blame] | 84 | RTC_DLOG(INFO) << __FUNCTION__; |
henrika | ec9c745 | 2018-06-08 16:10:03 +0200 | [diff] [blame] | 85 | |
| 86 | // The "AudioDeviceModule::kWindowsCoreAudio2" audio layer has its own |
| 87 | // dedicated factory method which should be used instead. |
| 88 | if (audio_layer == AudioDeviceModule::kWindowsCoreAudio2) { |
| 89 | RTC_LOG(LS_ERROR) << "Use the CreateWindowsCoreAudioAudioDeviceModule() " |
| 90 | "factory method instead for this option."; |
| 91 | return nullptr; |
| 92 | } |
| 93 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 94 | // Create the generic reference counted (platform independent) implementation. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 95 | rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice( |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 96 | new rtc::RefCountedObject<AudioDeviceModuleImpl>(audio_layer, |
| 97 | task_queue_factory)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 99 | // Ensure that the current platform is supported. |
| 100 | if (audioDevice->CheckPlatform() == -1) { |
| 101 | return nullptr; |
| 102 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 104 | // Create the platform-dependent implementation. |
| 105 | if (audioDevice->CreatePlatformSpecificObjects() == -1) { |
| 106 | return nullptr; |
| 107 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 109 | // Ensure that the generic audio buffer can communicate with the platform |
| 110 | // specific parts. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 111 | if (audioDevice->AttachAudioBuffer() == -1) { |
| 112 | return nullptr; |
| 113 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 115 | return audioDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 118 | AudioDeviceModuleImpl::AudioDeviceModuleImpl( |
| 119 | AudioLayer audio_layer, |
| 120 | TaskQueueFactory* task_queue_factory) |
| 121 | : audio_layer_(audio_layer), audio_device_buffer_(task_queue_factory) { |
Mirko Bonadei | 3b68aa3 | 2021-01-28 09:21:06 +0100 | [diff] [blame] | 122 | RTC_DLOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 125 | int32_t AudioDeviceModuleImpl::CheckPlatform() { |
Mirko Bonadei | 3b68aa3 | 2021-01-28 09:21:06 +0100 | [diff] [blame] | 126 | RTC_DLOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 127 | // Ensure that the current platform is supported |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 128 | PlatformType platform(kPlatformNotSupported); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | #if defined(_WIN32) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 130 | platform = kPlatformWin32; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 131 | RTC_LOG(INFO) << "current platform is Win32"; |
leozwang@google.com | 522f42b | 2011-09-19 17:39:05 +0000 | [diff] [blame] | 132 | #elif defined(WEBRTC_ANDROID) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 133 | platform = kPlatformAndroid; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 134 | RTC_LOG(INFO) << "current platform is Android"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | #elif defined(WEBRTC_LINUX) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 136 | platform = kPlatformLinux; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 137 | RTC_LOG(INFO) << "current platform is Linux"; |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 138 | #elif defined(WEBRTC_IOS) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 139 | platform = kPlatformIOS; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 140 | RTC_LOG(INFO) << "current platform is IOS"; |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 141 | #elif defined(WEBRTC_MAC) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 142 | platform = kPlatformMac; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 143 | RTC_LOG(INFO) << "current platform is Mac"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | #endif |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 145 | if (platform == kPlatformNotSupported) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 146 | RTC_LOG(LERROR) |
| 147 | << "current platform is not supported => this module will self " |
| 148 | "destruct!"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 149 | return -1; |
| 150 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 151 | platform_type_ = platform; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 152 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 155 | int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 156 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 157 | // Dummy ADM implementations if build flags are set. |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 158 | #if defined(WEBRTC_DUMMY_AUDIO_BUILD) |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 159 | audio_device_.reset(new AudioDeviceDummy()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 160 | RTC_LOG(INFO) << "Dummy Audio APIs will be utilized"; |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 161 | #elif defined(WEBRTC_DUMMY_FILE_DEVICES) |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 162 | audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice()); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 163 | if (audio_device_) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 164 | RTC_LOG(INFO) << "Will use file-playing dummy device."; |
noahric | 6a35590 | 2016-08-17 15:19:50 -0700 | [diff] [blame] | 165 | } else { |
| 166 | // Create a dummy device instead. |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 167 | audio_device_.reset(new AudioDeviceDummy()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 168 | RTC_LOG(INFO) << "Dummy Audio APIs will be utilized"; |
noahric | 6a35590 | 2016-08-17 15:19:50 -0700 | [diff] [blame] | 169 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 170 | |
| 171 | // Real (non-dummy) ADM implementations. |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 172 | #else |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 173 | AudioLayer audio_layer(PlatformAudioLayer()); |
| 174 | // Windows ADM implementation. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 176 | if ((audio_layer == kWindowsCoreAudio) || |
| 177 | (audio_layer == kPlatformDefaultAudio)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 178 | RTC_LOG(INFO) << "Attempting to use the Windows Core Audio APIs..."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 179 | if (AudioDeviceWindowsCore::CoreAudioIsSupported()) { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 180 | audio_device_.reset(new AudioDeviceWindowsCore()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 181 | RTC_LOG(INFO) << "Windows Core Audio APIs will be utilized"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 183 | } |
| 184 | #endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | |
henrike@webrtc.org | 9ee75e9 | 2013-12-11 21:42:44 +0000 | [diff] [blame] | 186 | #if defined(WEBRTC_ANDROID) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 187 | // Create an Android audio manager. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 188 | audio_manager_android_.reset(new AudioManager()); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 189 | // Select best possible combination of audio layers. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 190 | if (audio_layer == kPlatformDefaultAudio) { |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 191 | if (audio_manager_android_->IsAAudioSupported()) { |
| 192 | // Use of AAudio for both playout and recording has highest priority. |
| 193 | audio_layer = kAndroidAAudioAudio; |
| 194 | } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() && |
| 195 | audio_manager_android_->IsLowLatencyRecordSupported()) { |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 196 | // Use OpenSL ES for both playout and recording. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 197 | audio_layer = kAndroidOpenSLESAudio; |
| 198 | } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() && |
| 199 | !audio_manager_android_->IsLowLatencyRecordSupported()) { |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 200 | // Use OpenSL ES for output on devices that only supports the |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 201 | // low-latency output audio path. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 202 | audio_layer = kAndroidJavaInputAndOpenSLESOutputAudio; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 203 | } else { |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 204 | // Use Java-based audio in both directions when low-latency output is |
| 205 | // not supported. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 206 | audio_layer = kAndroidJavaAudio; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 208 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 209 | AudioManager* audio_manager = audio_manager_android_.get(); |
| 210 | if (audio_layer == kAndroidJavaAudio) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 211 | // Java audio for both input and output audio. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 212 | audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>( |
| 213 | audio_layer, audio_manager)); |
| 214 | } else if (audio_layer == kAndroidOpenSLESAudio) { |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 215 | // OpenSL ES based audio for both input and output audio. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 216 | audio_device_.reset( |
| 217 | new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>( |
| 218 | audio_layer, audio_manager)); |
| 219 | } else if (audio_layer == kAndroidJavaInputAndOpenSLESOutputAudio) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 220 | // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs). |
| 221 | // This combination provides low-latency output audio and at the same |
| 222 | // time support for HW AEC using the AudioRecord Java API. |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 223 | audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>( |
| 224 | audio_layer, audio_manager)); |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 225 | } else if (audio_layer == kAndroidAAudioAudio) { |
Mirko Bonadei | 185e802 | 2019-03-27 21:11:17 +0100 | [diff] [blame] | 226 | #if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 227 | // AAudio based audio for both input and output. |
| 228 | audio_device_.reset(new AudioDeviceTemplate<AAudioRecorder, AAudioPlayer>( |
| 229 | audio_layer, audio_manager)); |
| 230 | #endif |
| 231 | } else if (audio_layer == kAndroidJavaInputAndAAudioOutputAudio) { |
Mirko Bonadei | 185e802 | 2019-03-27 21:11:17 +0100 | [diff] [blame] | 232 | #if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO) |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 233 | // Java audio for input and AAudio for output audio (i.e. mixed APIs). |
| 234 | audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AAudioPlayer>( |
| 235 | audio_layer, audio_manager)); |
| 236 | #endif |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 237 | } else { |
henrika | 883d00f | 2018-03-16 10:09:49 +0100 | [diff] [blame] | 238 | RTC_LOG(LS_ERROR) << "The requested audio layer is not supported"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 239 | audio_device_.reset(nullptr); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 240 | } |
| 241 | // END #if defined(WEBRTC_ANDROID) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 243 | // Linux ADM implementation. |
Mirko Bonadei | fc9770c | 2020-03-24 12:56:47 +0100 | [diff] [blame] | 244 | // Note that, WEBRTC_ENABLE_LINUX_ALSA is always defined by default when |
| 245 | // WEBRTC_LINUX is defined. WEBRTC_ENABLE_LINUX_PULSE depends on the |
| 246 | // 'rtc_include_pulse_audio' build flag. |
henrika | 68435f5 | 2018-04-09 13:31:45 +0200 | [diff] [blame] | 247 | // TODO(bugs.webrtc.org/9127): improve support and make it more clear that |
| 248 | // PulseAudio is the default selection. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 249 | #elif defined(WEBRTC_LINUX) |
Mirko Bonadei | fc9770c | 2020-03-24 12:56:47 +0100 | [diff] [blame] | 250 | #if !defined(WEBRTC_ENABLE_LINUX_PULSE) |
henrika | 68435f5 | 2018-04-09 13:31:45 +0200 | [diff] [blame] | 251 | // Build flag 'rtc_include_pulse_audio' is set to false. In this mode: |
| 252 | // - kPlatformDefaultAudio => ALSA, and |
| 253 | // - kLinuxAlsaAudio => ALSA, and |
| 254 | // - kLinuxPulseAudio => Invalid selection. |
| 255 | RTC_LOG(WARNING) << "PulseAudio is disabled using build flag."; |
| 256 | if ((audio_layer == kLinuxAlsaAudio) || |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 257 | (audio_layer == kPlatformDefaultAudio)) { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 258 | audio_device_.reset(new AudioDeviceLinuxALSA()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 259 | RTC_LOG(INFO) << "Linux ALSA APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 260 | } |
henrika | 68435f5 | 2018-04-09 13:31:45 +0200 | [diff] [blame] | 261 | #else |
| 262 | // Build flag 'rtc_include_pulse_audio' is set to true (default). In this |
| 263 | // mode: |
| 264 | // - kPlatformDefaultAudio => PulseAudio, and |
| 265 | // - kLinuxPulseAudio => PulseAudio, and |
| 266 | // - kLinuxAlsaAudio => ALSA (supported but not default). |
| 267 | RTC_LOG(INFO) << "PulseAudio support is enabled."; |
| 268 | if ((audio_layer == kLinuxPulseAudio) || |
| 269 | (audio_layer == kPlatformDefaultAudio)) { |
| 270 | // Linux PulseAudio implementation is default. |
| 271 | audio_device_.reset(new AudioDeviceLinuxPulse()); |
| 272 | RTC_LOG(INFO) << "Linux PulseAudio APIs will be utilized"; |
| 273 | } else if (audio_layer == kLinuxAlsaAudio) { |
| 274 | audio_device_.reset(new AudioDeviceLinuxALSA()); |
| 275 | RTC_LOG(WARNING) << "Linux ALSA APIs will be utilized."; |
| 276 | } |
Mirko Bonadei | fc9770c | 2020-03-24 12:56:47 +0100 | [diff] [blame] | 277 | #endif // #if !defined(WEBRTC_ENABLE_LINUX_PULSE) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 278 | #endif // #if defined(WEBRTC_LINUX) |
| 279 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 280 | // iOS ADM implementation. |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 281 | #if defined(WEBRTC_IOS) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 282 | if (audio_layer == kPlatformDefaultAudio) { |
Sam Zackrisson | 76443ea | 2020-11-26 12:18:11 +0100 | [diff] [blame] | 283 | audio_device_.reset( |
| 284 | new ios_adm::AudioDeviceIOS(/*bypass_voice_processing=*/false)); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 285 | RTC_LOG(INFO) << "iPhone Audio APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 286 | } |
| 287 | // END #if defined(WEBRTC_IOS) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 288 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 289 | // Mac OS X ADM implementation. |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 290 | #elif defined(WEBRTC_MAC) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 291 | if (audio_layer == kPlatformDefaultAudio) { |
| 292 | audio_device_.reset(new AudioDeviceMac()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 293 | RTC_LOG(INFO) << "Mac OS X Audio APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 294 | } |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 295 | #endif // WEBRTC_MAC |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 296 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 297 | // Dummy ADM implementation. |
| 298 | if (audio_layer == kDummyAudio) { |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 299 | audio_device_.reset(new AudioDeviceDummy()); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 300 | RTC_LOG(INFO) << "Dummy Audio APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 301 | } |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 302 | #endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 304 | if (!audio_device_) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 305 | RTC_LOG(LS_ERROR) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 306 | << "Failed to create the platform specific ADM implementation."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 307 | return -1; |
| 308 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 309 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 312 | int32_t AudioDeviceModuleImpl::AttachAudioBuffer() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 313 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 314 | audio_device_->AttachAudioBuffer(&audio_device_buffer_); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 315 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 318 | AudioDeviceModuleImpl::~AudioDeviceModuleImpl() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 319 | RTC_LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 320 | } |
| 321 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 322 | int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 323 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 324 | AudioLayer activeAudio; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 325 | if (audio_device_->ActiveAudioLayer(activeAudio) == -1) { |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 326 | return -1; |
| 327 | } |
| 328 | *audioLayer = activeAudio; |
| 329 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 332 | int32_t AudioDeviceModuleImpl::Init() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 333 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 334 | if (initialized_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 335 | return 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 336 | RTC_CHECK(audio_device_); |
| 337 | AudioDeviceGeneric::InitStatus status = audio_device_->Init(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 338 | RTC_HISTOGRAM_ENUMERATION( |
| 339 | "WebRTC.Audio.InitializationResult", static_cast<int>(status), |
| 340 | static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES)); |
| 341 | if (status != AudioDeviceGeneric::InitStatus::OK) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 342 | RTC_LOG(LS_ERROR) << "Audio device initialization failed."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 343 | return -1; |
| 344 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 345 | initialized_ = true; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 346 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 349 | int32_t AudioDeviceModuleImpl::Terminate() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 350 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 351 | if (!initialized_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 352 | return 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 353 | if (audio_device_->Terminate() == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 354 | return -1; |
| 355 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 356 | initialized_ = false; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 357 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 360 | bool AudioDeviceModuleImpl::Initialized() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 361 | RTC_LOG(INFO) << __FUNCTION__ << ": " << initialized_; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 362 | return initialized_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 365 | int32_t AudioDeviceModuleImpl::InitSpeaker() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 366 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 367 | CHECKinitialized_(); |
| 368 | return audio_device_->InitSpeaker(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 371 | int32_t AudioDeviceModuleImpl::InitMicrophone() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 372 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 373 | CHECKinitialized_(); |
| 374 | return audio_device_->InitMicrophone(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 377 | int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 378 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 379 | CHECKinitialized_(); |
| 380 | bool isAvailable = false; |
| 381 | if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 382 | return -1; |
| 383 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 384 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 385 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 386 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 389 | int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 390 | RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 391 | CHECKinitialized_(); |
| 392 | return audio_device_->SetSpeakerVolume(volume); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 395 | int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 396 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 397 | CHECKinitialized_(); |
| 398 | uint32_t level = 0; |
| 399 | if (audio_device_->SpeakerVolume(level) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 400 | return -1; |
| 401 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 402 | *volume = level; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 403 | RTC_LOG(INFO) << "output: " << *volume; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 404 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 407 | bool AudioDeviceModuleImpl::SpeakerIsInitialized() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 408 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 409 | CHECKinitialized__BOOL(); |
| 410 | bool isInitialized = audio_device_->SpeakerIsInitialized(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 411 | RTC_LOG(INFO) << "output: " << isInitialized; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 412 | return isInitialized; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 415 | bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 416 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 417 | CHECKinitialized__BOOL(); |
| 418 | bool isInitialized = audio_device_->MicrophoneIsInitialized(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 419 | RTC_LOG(INFO) << "output: " << isInitialized; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 420 | return isInitialized; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 423 | int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 424 | CHECKinitialized_(); |
| 425 | uint32_t maxVol = 0; |
| 426 | if (audio_device_->MaxSpeakerVolume(maxVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 427 | return -1; |
| 428 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 429 | *maxVolume = maxVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 430 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 433 | int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 434 | CHECKinitialized_(); |
| 435 | uint32_t minVol = 0; |
| 436 | if (audio_device_->MinSpeakerVolume(minVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 437 | return -1; |
| 438 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 439 | *minVolume = minVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 440 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 443 | int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 444 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 445 | CHECKinitialized_(); |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 446 | bool isAvailable = false; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 447 | if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 448 | return -1; |
| 449 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 450 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 451 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 452 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 455 | int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 456 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 457 | CHECKinitialized_(); |
| 458 | return audio_device_->SetSpeakerMute(enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 461 | int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 462 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 463 | CHECKinitialized_(); |
| 464 | bool muted = false; |
| 465 | if (audio_device_->SpeakerMute(muted) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 466 | return -1; |
| 467 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 468 | *enabled = muted; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 469 | RTC_LOG(INFO) << "output: " << muted; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 470 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 473 | int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 474 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 475 | CHECKinitialized_(); |
| 476 | bool isAvailable = false; |
| 477 | if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 478 | return -1; |
| 479 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 480 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 481 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 482 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 485 | int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 486 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 487 | CHECKinitialized_(); |
| 488 | return (audio_device_->SetMicrophoneMute(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 491 | int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 492 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 493 | CHECKinitialized_(); |
| 494 | bool muted = false; |
| 495 | if (audio_device_->MicrophoneMute(muted) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 496 | return -1; |
| 497 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 498 | *enabled = muted; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 499 | RTC_LOG(INFO) << "output: " << muted; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 500 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 503 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 504 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 505 | CHECKinitialized_(); |
| 506 | bool isAvailable = false; |
| 507 | if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 508 | return -1; |
| 509 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 510 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 511 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 512 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 515 | int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 516 | RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 517 | CHECKinitialized_(); |
| 518 | return (audio_device_->SetMicrophoneVolume(volume)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 521 | int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 522 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 523 | CHECKinitialized_(); |
| 524 | uint32_t level = 0; |
| 525 | if (audio_device_->MicrophoneVolume(level) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 526 | return -1; |
| 527 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 528 | *volume = level; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 529 | RTC_LOG(INFO) << "output: " << *volume; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 530 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 533 | int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable( |
| 534 | bool* available) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 535 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 536 | CHECKinitialized_(); |
| 537 | bool isAvailable = false; |
| 538 | if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 539 | return -1; |
| 540 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 541 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 542 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 543 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 546 | int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 547 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 548 | CHECKinitialized_(); |
| 549 | if (audio_device_->RecordingIsInitialized()) { |
Gustavo Garcia | ff98f4b | 2018-12-19 10:37:16 +0100 | [diff] [blame] | 550 | RTC_LOG(LERROR) |
| 551 | << "unable to set stereo mode after recording is initialized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 552 | return -1; |
| 553 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 554 | if (audio_device_->SetStereoRecording(enable) == -1) { |
Gustavo Garcia | ff98f4b | 2018-12-19 10:37:16 +0100 | [diff] [blame] | 555 | if (enable) { |
| 556 | RTC_LOG(WARNING) << "failed to enable stereo recording"; |
| 557 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 558 | return -1; |
| 559 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 560 | int8_t nChannels(1); |
| 561 | if (enable) { |
| 562 | nChannels = 2; |
| 563 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 564 | audio_device_buffer_.SetRecordingChannels(nChannels); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 565 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 568 | int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 569 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 570 | CHECKinitialized_(); |
| 571 | bool stereo = false; |
| 572 | if (audio_device_->StereoRecording(stereo) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 573 | return -1; |
| 574 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 575 | *enabled = stereo; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 576 | RTC_LOG(INFO) << "output: " << stereo; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 577 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 580 | int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 581 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 582 | CHECKinitialized_(); |
| 583 | bool isAvailable = false; |
| 584 | if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 585 | return -1; |
| 586 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 587 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 588 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 589 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 592 | int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 593 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 594 | CHECKinitialized_(); |
| 595 | if (audio_device_->PlayoutIsInitialized()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 596 | RTC_LOG(LERROR) |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 597 | << "unable to set stereo mode while playing side is initialized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 598 | return -1; |
| 599 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 600 | if (audio_device_->SetStereoPlayout(enable)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 601 | RTC_LOG(WARNING) << "stereo playout is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 602 | return -1; |
| 603 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 604 | int8_t nChannels(1); |
| 605 | if (enable) { |
| 606 | nChannels = 2; |
| 607 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 608 | audio_device_buffer_.SetPlayoutChannels(nChannels); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 609 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 612 | int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 613 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 614 | CHECKinitialized_(); |
| 615 | bool stereo = false; |
| 616 | if (audio_device_->StereoPlayout(stereo) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 617 | return -1; |
| 618 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 619 | *enabled = stereo; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 620 | RTC_LOG(INFO) << "output: " << stereo; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 621 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 624 | int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 625 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 626 | CHECKinitialized_(); |
| 627 | bool isAvailable = false; |
| 628 | if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 629 | return -1; |
| 630 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 631 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 632 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 633 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 636 | int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 637 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 638 | CHECKinitialized_(); |
| 639 | bool isAvailable = false; |
| 640 | if (audio_device_->RecordingIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 641 | return -1; |
| 642 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 643 | *available = isAvailable; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 644 | RTC_LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 645 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 648 | int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 649 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 650 | uint32_t maxVol(0); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 651 | if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 652 | return -1; |
| 653 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 654 | *maxVolume = maxVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 655 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 658 | int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 659 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 660 | uint32_t minVol(0); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 661 | if (audio_device_->MinMicrophoneVolume(minVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 662 | return -1; |
| 663 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 664 | *minVolume = minVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 665 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 668 | int16_t AudioDeviceModuleImpl::PlayoutDevices() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 669 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 670 | CHECKinitialized_(); |
| 671 | uint16_t nPlayoutDevices = audio_device_->PlayoutDevices(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 672 | RTC_LOG(INFO) << "output: " << nPlayoutDevices; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 673 | return (int16_t)(nPlayoutDevices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 676 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 677 | RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 678 | CHECKinitialized_(); |
| 679 | return audio_device_->SetPlayoutDevice(index); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 682 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 683 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 684 | CHECKinitialized_(); |
| 685 | return audio_device_->SetPlayoutDevice(device); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 686 | } |
| 687 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 688 | int32_t AudioDeviceModuleImpl::PlayoutDeviceName( |
| 689 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 690 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 691 | char guid[kAdmMaxGuidSize]) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 692 | RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 693 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 694 | if (name == NULL) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 695 | return -1; |
| 696 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 697 | if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 698 | return -1; |
| 699 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 700 | if (name != NULL) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 701 | RTC_LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 702 | } |
| 703 | if (guid != NULL) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 704 | RTC_LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 705 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 706 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 707 | } |
| 708 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 709 | int32_t AudioDeviceModuleImpl::RecordingDeviceName( |
| 710 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 711 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 712 | char guid[kAdmMaxGuidSize]) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 713 | RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 714 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 715 | if (name == NULL) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 716 | return -1; |
| 717 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 718 | if (audio_device_->RecordingDeviceName(index, name, guid) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 719 | return -1; |
| 720 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 721 | if (name != NULL) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 722 | RTC_LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 723 | } |
| 724 | if (guid != NULL) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 725 | RTC_LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 726 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 727 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 730 | int16_t AudioDeviceModuleImpl::RecordingDevices() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 731 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 732 | CHECKinitialized_(); |
| 733 | uint16_t nRecordingDevices = audio_device_->RecordingDevices(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 734 | RTC_LOG(INFO) << "output: " << nRecordingDevices; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 735 | return (int16_t)nRecordingDevices; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 738 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 739 | RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 740 | CHECKinitialized_(); |
| 741 | return audio_device_->SetRecordingDevice(index); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 744 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 745 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 746 | CHECKinitialized_(); |
| 747 | return audio_device_->SetRecordingDevice(device); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 750 | int32_t AudioDeviceModuleImpl::InitPlayout() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 751 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 752 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 753 | if (PlayoutIsInitialized()) { |
| 754 | return 0; |
| 755 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 756 | int32_t result = audio_device_->InitPlayout(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 757 | RTC_LOG(INFO) << "output: " << result; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 758 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess", |
| 759 | static_cast<int>(result == 0)); |
| 760 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 763 | int32_t AudioDeviceModuleImpl::InitRecording() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 764 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 765 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 766 | if (RecordingIsInitialized()) { |
| 767 | return 0; |
| 768 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 769 | int32_t result = audio_device_->InitRecording(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 770 | RTC_LOG(INFO) << "output: " << result; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 771 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess", |
| 772 | static_cast<int>(result == 0)); |
| 773 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 776 | bool AudioDeviceModuleImpl::PlayoutIsInitialized() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 777 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 778 | CHECKinitialized__BOOL(); |
| 779 | return audio_device_->PlayoutIsInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 782 | bool AudioDeviceModuleImpl::RecordingIsInitialized() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 783 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 784 | CHECKinitialized__BOOL(); |
| 785 | return audio_device_->RecordingIsInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 788 | int32_t AudioDeviceModuleImpl::StartPlayout() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 789 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 790 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 791 | if (Playing()) { |
| 792 | return 0; |
| 793 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 794 | audio_device_buffer_.StartPlayout(); |
| 795 | int32_t result = audio_device_->StartPlayout(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 796 | RTC_LOG(INFO) << "output: " << result; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 797 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess", |
| 798 | static_cast<int>(result == 0)); |
| 799 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 802 | int32_t AudioDeviceModuleImpl::StopPlayout() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 803 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 804 | CHECKinitialized_(); |
| 805 | int32_t result = audio_device_->StopPlayout(); |
| 806 | audio_device_buffer_.StopPlayout(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 807 | RTC_LOG(INFO) << "output: " << result; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 808 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess", |
| 809 | static_cast<int>(result == 0)); |
| 810 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 813 | bool AudioDeviceModuleImpl::Playing() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 814 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 815 | CHECKinitialized__BOOL(); |
| 816 | return audio_device_->Playing(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 819 | int32_t AudioDeviceModuleImpl::StartRecording() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 820 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 821 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 822 | if (Recording()) { |
| 823 | return 0; |
| 824 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 825 | audio_device_buffer_.StartRecording(); |
| 826 | int32_t result = audio_device_->StartRecording(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 827 | RTC_LOG(INFO) << "output: " << result; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 828 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess", |
| 829 | static_cast<int>(result == 0)); |
| 830 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 831 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 832 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 833 | int32_t AudioDeviceModuleImpl::StopRecording() { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 834 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 835 | CHECKinitialized_(); |
| 836 | int32_t result = audio_device_->StopRecording(); |
| 837 | audio_device_buffer_.StopRecording(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 838 | RTC_LOG(INFO) << "output: " << result; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 839 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess", |
| 840 | static_cast<int>(result == 0)); |
| 841 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 844 | bool AudioDeviceModuleImpl::Recording() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 845 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 846 | CHECKinitialized__BOOL(); |
| 847 | return audio_device_->Recording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 850 | int32_t AudioDeviceModuleImpl::RegisterAudioCallback( |
| 851 | AudioTransport* audioCallback) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 852 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 853 | return audio_device_buffer_.RegisterAudioCallback(audioCallback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 856 | int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 857 | CHECKinitialized_(); |
| 858 | uint16_t delay = 0; |
| 859 | if (audio_device_->PlayoutDelay(delay) == -1) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 860 | RTC_LOG(LERROR) << "failed to retrieve the playout delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 861 | return -1; |
| 862 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 863 | *delayMS = delay; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 864 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 865 | } |
| 866 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 867 | bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 868 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 869 | CHECKinitialized__BOOL(); |
| 870 | bool isAvailable = audio_device_->BuiltInAECIsAvailable(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 871 | RTC_LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 872 | return isAvailable; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 873 | } |
| 874 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 875 | int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 876 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 877 | CHECKinitialized_(); |
| 878 | int32_t ok = audio_device_->EnableBuiltInAEC(enable); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 879 | RTC_LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 880 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 884 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 885 | CHECKinitialized__BOOL(); |
| 886 | bool isAvailable = audio_device_->BuiltInAGCIsAvailable(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 887 | RTC_LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 888 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 892 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 893 | CHECKinitialized_(); |
| 894 | int32_t ok = audio_device_->EnableBuiltInAGC(enable); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 895 | RTC_LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 896 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 900 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 901 | CHECKinitialized__BOOL(); |
| 902 | bool isAvailable = audio_device_->BuiltInNSIsAvailable(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 903 | RTC_LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 904 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 908 | RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 909 | CHECKinitialized_(); |
| 910 | int32_t ok = audio_device_->EnableBuiltInNS(enable); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 911 | RTC_LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 912 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 913 | } |
| 914 | |
Alex Narest | bbeb109 | 2019-08-16 11:49:04 +0200 | [diff] [blame] | 915 | int32_t AudioDeviceModuleImpl::GetPlayoutUnderrunCount() const { |
| 916 | RTC_LOG(INFO) << __FUNCTION__; |
| 917 | CHECKinitialized_(); |
| 918 | int32_t underrunCount = audio_device_->GetPlayoutUnderrunCount(); |
| 919 | RTC_LOG(INFO) << "output: " << underrunCount; |
| 920 | return underrunCount; |
| 921 | } |
| 922 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 923 | #if defined(WEBRTC_IOS) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 924 | int AudioDeviceModuleImpl::GetPlayoutAudioParameters( |
| 925 | AudioParameters* params) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 926 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 927 | int r = audio_device_->GetPlayoutAudioParameters(params); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 928 | RTC_LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 929 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | int AudioDeviceModuleImpl::GetRecordAudioParameters( |
| 933 | AudioParameters* params) const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 934 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 935 | int r = audio_device_->GetRecordAudioParameters(params); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 936 | RTC_LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 937 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 938 | } |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 939 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 940 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 941 | AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 942 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 943 | return platform_type_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 946 | AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() |
| 947 | const { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 948 | RTC_LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 949 | return audio_layer_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | } // namespace webrtc |