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()); |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame^] | 211 | LOG(INFO) << "Linux PulseAudio APIs will be utilized"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | #endif |
| 213 | #if defined(LINUX_PULSE) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 214 | #endif |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 215 | } else if (audio_layer == kLinuxAlsaAudio) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | #if defined(LINUX_ALSA) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 217 | // Linux ALSA implementation. |
| 218 | audio_device_.reset(new AudioDeviceLinuxALSA()); |
| 219 | LOG(INFO) << "Linux ALSA APIs will be utilized."; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | #endif |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 221 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 222 | #endif // #if defined(WEBRTC_LINUX) |
| 223 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 224 | // iOS ADM implementation. |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 225 | #if defined(WEBRTC_IOS) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 226 | if (audio_layer == kPlatformDefaultAudio) { |
| 227 | audio_device_.reset(new AudioDeviceIOS()); |
| 228 | LOG(INFO) << "iPhone Audio APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 229 | } |
| 230 | // END #if defined(WEBRTC_IOS) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 232 | // Mac OS X ADM implementation. |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 233 | #elif defined(WEBRTC_MAC) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 234 | if (audio_layer == kPlatformDefaultAudio) { |
| 235 | audio_device_.reset(new AudioDeviceMac()); |
| 236 | LOG(INFO) << "Mac OS X Audio APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 237 | } |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 238 | #endif // WEBRTC_MAC |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 240 | // Dummy ADM implementation. |
| 241 | if (audio_layer == kDummyAudio) { |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 242 | audio_device_.reset(new AudioDeviceDummy()); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 243 | LOG(INFO) << "Dummy Audio APIs will be utilized."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 244 | } |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 245 | #endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 246 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 247 | if (!audio_device_) { |
| 248 | LOG(LS_ERROR) |
| 249 | << "Failed to create the platform specific ADM implementation."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 250 | return -1; |
| 251 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 252 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 255 | int32_t AudioDeviceModuleImpl::AttachAudioBuffer() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 256 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 257 | audio_device_->AttachAudioBuffer(&audio_device_buffer_); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 258 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 261 | AudioDeviceModuleImpl::~AudioDeviceModuleImpl() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 262 | LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 263 | } |
| 264 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 265 | int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 266 | LOG(INFO) << __FUNCTION__; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 267 | AudioLayer activeAudio; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 268 | if (audio_device_->ActiveAudioLayer(activeAudio) == -1) { |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 269 | return -1; |
| 270 | } |
| 271 | *audioLayer = activeAudio; |
| 272 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 275 | // TODO(henrika): remove this API. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 276 | AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 277 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 278 | LOG(WARNING) << "Not supported"; |
| 279 | return kAdmErrNone; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 282 | int32_t AudioDeviceModuleImpl::Init() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 283 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 284 | if (initialized_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 285 | return 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 286 | RTC_CHECK(audio_device_); |
| 287 | AudioDeviceGeneric::InitStatus status = audio_device_->Init(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 288 | RTC_HISTOGRAM_ENUMERATION( |
| 289 | "WebRTC.Audio.InitializationResult", static_cast<int>(status), |
| 290 | static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES)); |
| 291 | if (status != AudioDeviceGeneric::InitStatus::OK) { |
| 292 | LOG(LS_ERROR) << "Audio device initialization failed."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 293 | return -1; |
| 294 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 295 | initialized_ = true; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 296 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 299 | int32_t AudioDeviceModuleImpl::Terminate() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 300 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 301 | if (!initialized_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 302 | return 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 303 | if (audio_device_->Terminate() == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 304 | return -1; |
| 305 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 306 | initialized_ = false; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 307 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 310 | bool AudioDeviceModuleImpl::Initialized() const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 311 | LOG(INFO) << __FUNCTION__ << ": " << initialized_; |
| 312 | return initialized_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 315 | int32_t AudioDeviceModuleImpl::InitSpeaker() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 316 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 317 | CHECKinitialized_(); |
| 318 | return audio_device_->InitSpeaker(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 321 | int32_t AudioDeviceModuleImpl::InitMicrophone() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 322 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 323 | CHECKinitialized_(); |
| 324 | return audio_device_->InitMicrophone(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 327 | int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 328 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 329 | CHECKinitialized_(); |
| 330 | bool isAvailable = false; |
| 331 | if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 332 | return -1; |
| 333 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 334 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 335 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 336 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 339 | int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 340 | LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 341 | CHECKinitialized_(); |
| 342 | return audio_device_->SetSpeakerVolume(volume); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 345 | int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 346 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 347 | CHECKinitialized_(); |
| 348 | uint32_t level = 0; |
| 349 | if (audio_device_->SpeakerVolume(level) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 350 | return -1; |
| 351 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 352 | *volume = level; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 353 | LOG(INFO) << "output: " << *volume; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 354 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 357 | bool AudioDeviceModuleImpl::SpeakerIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 358 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 359 | CHECKinitialized__BOOL(); |
| 360 | bool isInitialized = audio_device_->SpeakerIsInitialized(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 361 | LOG(INFO) << "output: " << isInitialized; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 362 | return isInitialized; |
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 | bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 366 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 367 | CHECKinitialized__BOOL(); |
| 368 | bool isInitialized = audio_device_->MicrophoneIsInitialized(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 369 | LOG(INFO) << "output: " << isInitialized; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 370 | return isInitialized; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 373 | int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 374 | CHECKinitialized_(); |
| 375 | uint32_t maxVol = 0; |
| 376 | if (audio_device_->MaxSpeakerVolume(maxVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 377 | return -1; |
| 378 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 379 | *maxVolume = maxVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 380 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 383 | int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 384 | CHECKinitialized_(); |
| 385 | uint32_t minVol = 0; |
| 386 | if (audio_device_->MinSpeakerVolume(minVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 387 | return -1; |
| 388 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 389 | *minVolume = minVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 390 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 393 | int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 394 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 395 | CHECKinitialized_(); |
| 396 | bool isAvailable = false; |
| 397 | if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 398 | return -1; |
| 399 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 400 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 401 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 402 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 405 | int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 406 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 407 | CHECKinitialized_(); |
| 408 | return audio_device_->SetSpeakerMute(enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 411 | int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 412 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 413 | CHECKinitialized_(); |
| 414 | bool muted = false; |
| 415 | if (audio_device_->SpeakerMute(muted) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 416 | return -1; |
| 417 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 418 | *enabled = muted; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 419 | LOG(INFO) << "output: " << muted; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 420 | return 0; |
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::MicrophoneMuteIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 424 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 425 | CHECKinitialized_(); |
| 426 | bool isAvailable = false; |
| 427 | if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 428 | return -1; |
| 429 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 430 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 431 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 432 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 435 | int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 436 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 437 | CHECKinitialized_(); |
| 438 | return (audio_device_->SetMicrophoneMute(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 441 | int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 442 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 443 | CHECKinitialized_(); |
| 444 | bool muted = false; |
| 445 | if (audio_device_->MicrophoneMute(muted) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 446 | return -1; |
| 447 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 448 | *enabled = muted; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 449 | LOG(INFO) << "output: " << muted; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 450 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 453 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 454 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 455 | CHECKinitialized_(); |
| 456 | bool isAvailable = false; |
| 457 | if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 458 | return -1; |
| 459 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 460 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 461 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 462 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 465 | int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 466 | LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 467 | CHECKinitialized_(); |
| 468 | return (audio_device_->SetMicrophoneVolume(volume)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 471 | int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 472 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 473 | CHECKinitialized_(); |
| 474 | uint32_t level = 0; |
| 475 | if (audio_device_->MicrophoneVolume(level) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 476 | return -1; |
| 477 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 478 | *volume = level; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 479 | LOG(INFO) << "output: " << *volume; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 480 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 483 | int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable( |
| 484 | bool* available) 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 | bool isAvailable = false; |
| 488 | if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -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 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 492 | LOG(INFO) << "output: " << isAvailable; |
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::SetStereoRecording(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 497 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 498 | CHECKinitialized_(); |
| 499 | if (audio_device_->RecordingIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 500 | LOG(WARNING) << "recording in stereo is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 501 | return -1; |
| 502 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 503 | if (audio_device_->SetStereoRecording(enable) == -1) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 504 | LOG(WARNING) << "failed to change stereo recording"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 505 | return -1; |
| 506 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 507 | int8_t nChannels(1); |
| 508 | if (enable) { |
| 509 | nChannels = 2; |
| 510 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 511 | audio_device_buffer_.SetRecordingChannels(nChannels); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +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::StereoRecording(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 516 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 517 | CHECKinitialized_(); |
| 518 | bool stereo = false; |
| 519 | if (audio_device_->StereoRecording(stereo) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 520 | return -1; |
| 521 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 522 | *enabled = stereo; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 523 | LOG(INFO) << "output: " << stereo; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 524 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 527 | int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) { |
| 528 | if (channel == kChannelBoth) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 529 | LOG(INFO) << __FUNCTION__ << "(both)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 530 | } else if (channel == kChannelLeft) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 531 | LOG(INFO) << __FUNCTION__ << "(left)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 532 | } else { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 533 | LOG(INFO) << __FUNCTION__ << "(right)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 534 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 535 | CHECKinitialized_(); |
| 536 | bool stereo = false; |
| 537 | if (audio_device_->StereoRecording(stereo) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 538 | LOG(WARNING) << "recording in stereo is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 539 | return -1; |
| 540 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 541 | return audio_device_buffer_.SetRecordingChannel(channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 544 | int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 545 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 546 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 547 | ChannelType chType; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 548 | if (audio_device_buffer_.RecordingChannel(chType) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 549 | return -1; |
| 550 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 551 | *channel = chType; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 552 | if (*channel == kChannelBoth) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 553 | LOG(INFO) << "output: both"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 554 | } else if (*channel == kChannelLeft) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 555 | LOG(INFO) << "output: left"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 556 | } else { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 557 | LOG(INFO) << "output: right"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 558 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 559 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 562 | int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 563 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 564 | CHECKinitialized_(); |
| 565 | bool isAvailable = false; |
| 566 | if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 567 | return -1; |
| 568 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 569 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 570 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 571 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 574 | int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 575 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 576 | CHECKinitialized_(); |
| 577 | if (audio_device_->PlayoutIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 578 | LOG(LERROR) |
| 579 | << "unable to set stereo mode while playing side is initialized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 580 | return -1; |
| 581 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 582 | if (audio_device_->SetStereoPlayout(enable)) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 583 | LOG(WARNING) << "stereo playout is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 584 | return -1; |
| 585 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 586 | int8_t nChannels(1); |
| 587 | if (enable) { |
| 588 | nChannels = 2; |
| 589 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 590 | audio_device_buffer_.SetPlayoutChannels(nChannels); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 591 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 594 | int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 595 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 596 | CHECKinitialized_(); |
| 597 | bool stereo = false; |
| 598 | if (audio_device_->StereoPlayout(stereo) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 599 | return -1; |
| 600 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 601 | *enabled = stereo; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 602 | LOG(INFO) << "output: " << stereo; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 603 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 606 | int32_t AudioDeviceModuleImpl::SetAGC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 607 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 608 | CHECKinitialized_(); |
| 609 | return (audio_device_->SetAGC(enable)); |
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 | bool AudioDeviceModuleImpl::AGC() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 613 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 614 | CHECKinitialized__BOOL(); |
| 615 | return audio_device_->AGC(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 618 | int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 619 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 620 | CHECKinitialized_(); |
| 621 | bool isAvailable = false; |
| 622 | if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 623 | return -1; |
| 624 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 625 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 626 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 627 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 630 | int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 631 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 632 | CHECKinitialized_(); |
| 633 | bool isAvailable = false; |
| 634 | if (audio_device_->RecordingIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 635 | return -1; |
| 636 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 637 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 638 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 639 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 642 | int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 643 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 644 | uint32_t maxVol(0); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 645 | if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 646 | return -1; |
| 647 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 648 | *maxVolume = maxVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 649 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 652 | int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 653 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 654 | uint32_t minVol(0); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 655 | if (audio_device_->MinMicrophoneVolume(minVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 656 | return -1; |
| 657 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 658 | *minVolume = minVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 659 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 662 | int16_t AudioDeviceModuleImpl::PlayoutDevices() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 663 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 664 | CHECKinitialized_(); |
| 665 | uint16_t nPlayoutDevices = audio_device_->PlayoutDevices(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 666 | LOG(INFO) << "output: " << nPlayoutDevices; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 667 | return (int16_t)(nPlayoutDevices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 670 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 671 | LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 672 | CHECKinitialized_(); |
| 673 | return audio_device_->SetPlayoutDevice(index); |
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(WindowsDeviceType device) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 677 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 678 | CHECKinitialized_(); |
| 679 | return audio_device_->SetPlayoutDevice(device); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 680 | } |
| 681 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 682 | int32_t AudioDeviceModuleImpl::PlayoutDeviceName( |
| 683 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 684 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 685 | char guid[kAdmMaxGuidSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 686 | LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 687 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 688 | if (name == NULL) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 689 | return -1; |
| 690 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 691 | if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 692 | return -1; |
| 693 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 694 | if (name != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 695 | LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 696 | } |
| 697 | if (guid != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 698 | LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 699 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 700 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 701 | } |
| 702 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 703 | int32_t AudioDeviceModuleImpl::RecordingDeviceName( |
| 704 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 705 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 706 | char guid[kAdmMaxGuidSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 707 | LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 708 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 709 | if (name == NULL) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 710 | return -1; |
| 711 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 712 | if (audio_device_->RecordingDeviceName(index, name, guid) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 713 | return -1; |
| 714 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 715 | if (name != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 716 | LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 717 | } |
| 718 | if (guid != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 719 | LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 720 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 721 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 724 | int16_t AudioDeviceModuleImpl::RecordingDevices() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 725 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 726 | CHECKinitialized_(); |
| 727 | uint16_t nRecordingDevices = audio_device_->RecordingDevices(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 728 | LOG(INFO) << "output: " << nRecordingDevices; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 729 | return (int16_t)nRecordingDevices; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 732 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 733 | LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 734 | CHECKinitialized_(); |
| 735 | return audio_device_->SetRecordingDevice(index); |
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(WindowsDeviceType device) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 739 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 740 | CHECKinitialized_(); |
| 741 | return audio_device_->SetRecordingDevice(device); |
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::InitPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 745 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 746 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 747 | if (PlayoutIsInitialized()) { |
| 748 | return 0; |
| 749 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 750 | int32_t result = audio_device_->InitPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 751 | LOG(INFO) << "output: " << result; |
| 752 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess", |
| 753 | static_cast<int>(result == 0)); |
| 754 | return result; |
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::InitRecording() { |
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 (RecordingIsInitialized()) { |
| 761 | return 0; |
| 762 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 763 | int32_t result = audio_device_->InitRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 764 | LOG(INFO) << "output: " << result; |
| 765 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess", |
| 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 | bool AudioDeviceModuleImpl::PlayoutIsInitialized() const { |
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__BOOL(); |
| 773 | return audio_device_->PlayoutIsInitialized(); |
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::RecordingIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 777 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 778 | CHECKinitialized__BOOL(); |
| 779 | return audio_device_->RecordingIsInitialized(); |
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 | int32_t AudioDeviceModuleImpl::StartPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 783 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 784 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 785 | if (Playing()) { |
| 786 | return 0; |
| 787 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 788 | audio_device_buffer_.StartPlayout(); |
| 789 | int32_t result = audio_device_->StartPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 790 | LOG(INFO) << "output: " << result; |
| 791 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess", |
| 792 | static_cast<int>(result == 0)); |
| 793 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 796 | int32_t AudioDeviceModuleImpl::StopPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 797 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 798 | CHECKinitialized_(); |
| 799 | int32_t result = audio_device_->StopPlayout(); |
| 800 | audio_device_buffer_.StopPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 801 | LOG(INFO) << "output: " << result; |
| 802 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess", |
| 803 | static_cast<int>(result == 0)); |
| 804 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 807 | bool AudioDeviceModuleImpl::Playing() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 808 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 809 | CHECKinitialized__BOOL(); |
| 810 | return audio_device_->Playing(); |
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 | int32_t AudioDeviceModuleImpl::StartRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 814 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 815 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 816 | if (Recording()) { |
| 817 | return 0; |
| 818 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 819 | audio_device_buffer_.StartRecording(); |
| 820 | int32_t result = audio_device_->StartRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 821 | LOG(INFO) << "output: " << result; |
| 822 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess", |
| 823 | static_cast<int>(result == 0)); |
| 824 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 825 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 826 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 827 | int32_t AudioDeviceModuleImpl::StopRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 828 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 829 | CHECKinitialized_(); |
| 830 | int32_t result = audio_device_->StopRecording(); |
| 831 | audio_device_buffer_.StopRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 832 | LOG(INFO) << "output: " << result; |
| 833 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess", |
| 834 | static_cast<int>(result == 0)); |
| 835 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 838 | bool AudioDeviceModuleImpl::Recording() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 839 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 840 | CHECKinitialized__BOOL(); |
| 841 | return audio_device_->Recording(); |
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 | int32_t AudioDeviceModuleImpl::RegisterAudioCallback( |
| 845 | AudioTransport* audioCallback) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 846 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 847 | return audio_device_buffer_.RegisterAudioCallback(audioCallback); |
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::PlayoutDelay(uint16_t* delayMS) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 851 | CHECKinitialized_(); |
| 852 | uint16_t delay = 0; |
| 853 | if (audio_device_->PlayoutDelay(delay) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 854 | LOG(LERROR) << "failed to retrieve the playout delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 855 | return -1; |
| 856 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 857 | *delayMS = delay; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 858 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 861 | int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 862 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 863 | CHECKinitialized_(); |
| 864 | uint16_t delay = 0; |
| 865 | if (audio_device_->RecordingDelay(delay) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 866 | LOG(LERROR) << "failed to retrieve the recording delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 867 | return -1; |
| 868 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 869 | *delayMS = delay; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 870 | LOG(INFO) << "output: " << *delayMS; |
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::SetRecordingSampleRate( |
| 875 | const uint32_t samplesPerSec) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 876 | LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 877 | CHECKinitialized_(); |
| 878 | if (audio_device_->SetRecordingSampleRate(samplesPerSec) != 0) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 879 | return -1; |
| 880 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 881 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 884 | int32_t AudioDeviceModuleImpl::RecordingSampleRate( |
| 885 | uint32_t* samplesPerSec) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 886 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 887 | CHECKinitialized_(); |
| 888 | int32_t sampleRate = audio_device_buffer_.RecordingSampleRate(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 889 | if (sampleRate == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 890 | LOG(LERROR) << "failed to retrieve the sample rate"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 891 | return -1; |
| 892 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 893 | *samplesPerSec = sampleRate; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 894 | LOG(INFO) << "output: " << *samplesPerSec; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 895 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 898 | int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate( |
| 899 | const uint32_t samplesPerSec) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 900 | LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 901 | CHECKinitialized_(); |
| 902 | if (audio_device_->SetPlayoutSampleRate(samplesPerSec) != 0) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 903 | return -1; |
| 904 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 905 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 908 | int32_t AudioDeviceModuleImpl::PlayoutSampleRate( |
| 909 | uint32_t* samplesPerSec) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 910 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 911 | CHECKinitialized_(); |
| 912 | int32_t sampleRate = audio_device_buffer_.PlayoutSampleRate(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 913 | if (sampleRate == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 914 | LOG(LERROR) << "failed to retrieve the sample rate"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 915 | return -1; |
| 916 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 917 | *samplesPerSec = sampleRate; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 918 | LOG(INFO) << "output: " << *samplesPerSec; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 919 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 920 | } |
| 921 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 922 | int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) { |
| 923 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
| 924 | CHECKinitialized_(); |
| 925 | if (audio_device_->SetLoudspeakerStatus(enable) != 0) { |
| 926 | return -1; |
| 927 | } |
| 928 | return 0; |
| 929 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 930 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 931 | int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 932 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 933 | CHECKinitialized_(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 934 | int32_t ok = 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 935 | if (audio_device_->GetLoudspeakerStatus(*enabled) != 0) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 936 | ok = -1; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 937 | } |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 938 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 939 | return ok; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 940 | } |
| 941 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 942 | bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 943 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 944 | CHECKinitialized__BOOL(); |
| 945 | bool isAvailable = audio_device_->BuiltInAECIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 946 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 947 | return isAvailable; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 948 | } |
| 949 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 950 | int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 951 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 952 | CHECKinitialized_(); |
| 953 | int32_t ok = audio_device_->EnableBuiltInAEC(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 954 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 955 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 959 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 960 | CHECKinitialized__BOOL(); |
| 961 | bool isAvailable = audio_device_->BuiltInAGCIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 962 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 963 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 967 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 968 | CHECKinitialized_(); |
| 969 | int32_t ok = audio_device_->EnableBuiltInAGC(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 970 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 971 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 975 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 976 | CHECKinitialized__BOOL(); |
| 977 | bool isAvailable = audio_device_->BuiltInNSIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 978 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 979 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 983 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 984 | CHECKinitialized_(); |
| 985 | int32_t ok = audio_device_->EnableBuiltInNS(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 986 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 987 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 988 | } |
| 989 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 990 | #if defined(WEBRTC_IOS) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 991 | int AudioDeviceModuleImpl::GetPlayoutAudioParameters( |
| 992 | AudioParameters* params) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 993 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 994 | int r = audio_device_->GetPlayoutAudioParameters(params); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 995 | LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 996 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | int AudioDeviceModuleImpl::GetRecordAudioParameters( |
| 1000 | AudioParameters* params) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1001 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 1002 | int r = audio_device_->GetRecordAudioParameters(params); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1003 | LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1004 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1005 | } |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 1006 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1007 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1008 | AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1009 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 1010 | return platform_type_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1013 | AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() |
| 1014 | const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1015 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame] | 1016 | return audio_layer_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | } // namespace webrtc |