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