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 |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 68 | rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create( |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 69 | const int32_t id, |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 70 | const AudioLayer audio_layer) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 71 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 72 | // Create the generic reference counted (platform independent) implementation. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 73 | rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice( |
| 74 | new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 76 | // Ensure that the current platform is supported. |
| 77 | if (audioDevice->CheckPlatform() == -1) { |
| 78 | return nullptr; |
| 79 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 81 | // Create the platform-dependent implementation. |
| 82 | if (audioDevice->CreatePlatformSpecificObjects() == -1) { |
| 83 | return nullptr; |
| 84 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 86 | // Ensure that the generic audio buffer can communicate with the platform |
| 87 | // specific parts. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 88 | if (audioDevice->AttachAudioBuffer() == -1) { |
| 89 | return nullptr; |
| 90 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 92 | return audioDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 95 | AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, |
| 96 | const AudioLayer audioLayer) |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 97 | : id_(id), 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 | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 134 | audio_device_.reset(new AudioDeviceDummy(Id())); |
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 | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 137 | audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice(Id())); |
| 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 | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 142 | audio_device_.reset(new AudioDeviceDummy(Id())); |
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) { |
| 255 | audio_device_.reset(new AudioDeviceDummy(Id())); |
| 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_buffer_.SetId(id_); |
| 271 | audio_device_->AttachAudioBuffer(&audio_device_buffer_); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 272 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 275 | AudioDeviceModuleImpl::~AudioDeviceModuleImpl() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 276 | LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 277 | } |
| 278 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 279 | int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 280 | LOG(INFO) << __FUNCTION__; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 281 | AudioLayer activeAudio; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 282 | if (audio_device_->ActiveAudioLayer(activeAudio) == -1) { |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 283 | return -1; |
| 284 | } |
| 285 | *audioLayer = activeAudio; |
| 286 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 287 | } |
| 288 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 289 | // TODO(henrika): remove this API. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 290 | AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 291 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 292 | LOG(WARNING) << "Not supported"; |
| 293 | return kAdmErrNone; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 296 | int32_t AudioDeviceModuleImpl::Init() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 297 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 298 | if (initialized_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 299 | return 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 300 | RTC_CHECK(audio_device_); |
| 301 | AudioDeviceGeneric::InitStatus status = audio_device_->Init(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 302 | RTC_HISTOGRAM_ENUMERATION( |
| 303 | "WebRTC.Audio.InitializationResult", static_cast<int>(status), |
| 304 | static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES)); |
| 305 | if (status != AudioDeviceGeneric::InitStatus::OK) { |
| 306 | LOG(LS_ERROR) << "Audio device initialization failed."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 307 | return -1; |
| 308 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 309 | initialized_ = true; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 310 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 313 | int32_t AudioDeviceModuleImpl::Terminate() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 314 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 315 | if (!initialized_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | return 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 317 | if (audio_device_->Terminate() == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 318 | return -1; |
| 319 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 320 | initialized_ = false; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 321 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 324 | bool AudioDeviceModuleImpl::Initialized() const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 325 | LOG(INFO) << __FUNCTION__ << ": " << initialized_; |
| 326 | return initialized_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 329 | int32_t AudioDeviceModuleImpl::InitSpeaker() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 330 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 331 | CHECKinitialized_(); |
| 332 | return audio_device_->InitSpeaker(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 335 | int32_t AudioDeviceModuleImpl::InitMicrophone() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 336 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 337 | CHECKinitialized_(); |
| 338 | return audio_device_->InitMicrophone(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 341 | int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 342 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 343 | CHECKinitialized_(); |
| 344 | bool isAvailable = false; |
| 345 | if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 346 | return -1; |
| 347 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 348 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 349 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 350 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 353 | int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 354 | LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 355 | CHECKinitialized_(); |
| 356 | return audio_device_->SetSpeakerVolume(volume); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 359 | int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 360 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 361 | CHECKinitialized_(); |
| 362 | uint32_t level = 0; |
| 363 | if (audio_device_->SpeakerVolume(level) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 364 | return -1; |
| 365 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 366 | *volume = level; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 367 | LOG(INFO) << "output: " << *volume; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 368 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 371 | bool AudioDeviceModuleImpl::SpeakerIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 372 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 373 | CHECKinitialized__BOOL(); |
| 374 | bool isInitialized = audio_device_->SpeakerIsInitialized(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 375 | LOG(INFO) << "output: " << isInitialized; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 376 | return isInitialized; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 379 | bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 380 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 381 | CHECKinitialized__BOOL(); |
| 382 | bool isInitialized = audio_device_->MicrophoneIsInitialized(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 383 | LOG(INFO) << "output: " << isInitialized; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 384 | return isInitialized; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 387 | int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 388 | CHECKinitialized_(); |
| 389 | uint32_t maxVol = 0; |
| 390 | if (audio_device_->MaxSpeakerVolume(maxVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 391 | return -1; |
| 392 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 393 | *maxVolume = maxVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 394 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 397 | int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 398 | CHECKinitialized_(); |
| 399 | uint32_t minVol = 0; |
| 400 | if (audio_device_->MinSpeakerVolume(minVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 401 | return -1; |
| 402 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 403 | *minVolume = minVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 404 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 407 | int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 408 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 409 | CHECKinitialized_(); |
| 410 | bool isAvailable = false; |
| 411 | if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 412 | return -1; |
| 413 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 414 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 415 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 416 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 419 | int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 420 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 421 | CHECKinitialized_(); |
| 422 | return audio_device_->SetSpeakerMute(enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 425 | int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 426 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 427 | CHECKinitialized_(); |
| 428 | bool muted = false; |
| 429 | if (audio_device_->SpeakerMute(muted) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 430 | return -1; |
| 431 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 432 | *enabled = muted; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 433 | LOG(INFO) << "output: " << muted; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 434 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 437 | int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 438 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 439 | CHECKinitialized_(); |
| 440 | bool isAvailable = false; |
| 441 | if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 442 | return -1; |
| 443 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 444 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 445 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 446 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 449 | int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 450 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 451 | CHECKinitialized_(); |
| 452 | return (audio_device_->SetMicrophoneMute(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 455 | int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 456 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 457 | CHECKinitialized_(); |
| 458 | bool muted = false; |
| 459 | if (audio_device_->MicrophoneMute(muted) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 460 | return -1; |
| 461 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 462 | *enabled = muted; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 463 | LOG(INFO) << "output: " << muted; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 464 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 467 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 468 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 469 | CHECKinitialized_(); |
| 470 | bool isAvailable = false; |
| 471 | if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 472 | return -1; |
| 473 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 474 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 475 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 476 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 479 | int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 480 | LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 481 | CHECKinitialized_(); |
| 482 | return (audio_device_->SetMicrophoneVolume(volume)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 485 | int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 486 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 487 | CHECKinitialized_(); |
| 488 | uint32_t level = 0; |
| 489 | if (audio_device_->MicrophoneVolume(level) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 490 | return -1; |
| 491 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 492 | *volume = level; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 493 | LOG(INFO) << "output: " << *volume; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 494 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 497 | int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable( |
| 498 | bool* available) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 499 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 500 | CHECKinitialized_(); |
| 501 | bool isAvailable = false; |
| 502 | if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 503 | return -1; |
| 504 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 505 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 506 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 507 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 510 | int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 511 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 512 | CHECKinitialized_(); |
| 513 | if (audio_device_->RecordingIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 514 | LOG(WARNING) << "recording in stereo is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 515 | return -1; |
| 516 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 517 | if (audio_device_->SetStereoRecording(enable) == -1) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 518 | LOG(WARNING) << "failed to change stereo recording"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 519 | return -1; |
| 520 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 521 | int8_t nChannels(1); |
| 522 | if (enable) { |
| 523 | nChannels = 2; |
| 524 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 525 | audio_device_buffer_.SetRecordingChannels(nChannels); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 526 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 529 | int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 530 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 531 | CHECKinitialized_(); |
| 532 | bool stereo = false; |
| 533 | if (audio_device_->StereoRecording(stereo) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 534 | return -1; |
| 535 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 536 | *enabled = stereo; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 537 | LOG(INFO) << "output: " << stereo; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 538 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 541 | int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) { |
| 542 | if (channel == kChannelBoth) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 543 | LOG(INFO) << __FUNCTION__ << "(both)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 544 | } else if (channel == kChannelLeft) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 545 | LOG(INFO) << __FUNCTION__ << "(left)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 546 | } else { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 547 | LOG(INFO) << __FUNCTION__ << "(right)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 548 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 549 | CHECKinitialized_(); |
| 550 | bool stereo = false; |
| 551 | if (audio_device_->StereoRecording(stereo) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 552 | LOG(WARNING) << "recording in stereo is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 553 | return -1; |
| 554 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 555 | return audio_device_buffer_.SetRecordingChannel(channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 558 | int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 559 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 560 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 561 | ChannelType chType; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 562 | if (audio_device_buffer_.RecordingChannel(chType) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 563 | return -1; |
| 564 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 565 | *channel = chType; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 566 | if (*channel == kChannelBoth) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 567 | LOG(INFO) << "output: both"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 568 | } else if (*channel == kChannelLeft) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 569 | LOG(INFO) << "output: left"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 570 | } else { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 571 | LOG(INFO) << "output: right"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 572 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 573 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 576 | int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 577 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 578 | CHECKinitialized_(); |
| 579 | bool isAvailable = false; |
| 580 | if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 581 | return -1; |
| 582 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 583 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 584 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 585 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 588 | int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 589 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 590 | CHECKinitialized_(); |
| 591 | if (audio_device_->PlayoutIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 592 | LOG(LERROR) |
| 593 | << "unable to set stereo mode while playing side is initialized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 594 | return -1; |
| 595 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 596 | if (audio_device_->SetStereoPlayout(enable)) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 597 | LOG(WARNING) << "stereo playout is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 598 | return -1; |
| 599 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 600 | int8_t nChannels(1); |
| 601 | if (enable) { |
| 602 | nChannels = 2; |
| 603 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 604 | audio_device_buffer_.SetPlayoutChannels(nChannels); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 605 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 608 | int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 609 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 610 | CHECKinitialized_(); |
| 611 | bool stereo = false; |
| 612 | if (audio_device_->StereoPlayout(stereo) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 613 | return -1; |
| 614 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 615 | *enabled = stereo; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 616 | LOG(INFO) << "output: " << stereo; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 617 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 620 | int32_t AudioDeviceModuleImpl::SetAGC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 621 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 622 | CHECKinitialized_(); |
| 623 | return (audio_device_->SetAGC(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 626 | bool AudioDeviceModuleImpl::AGC() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 627 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 628 | CHECKinitialized__BOOL(); |
| 629 | return audio_device_->AGC(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 632 | int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 633 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 634 | CHECKinitialized_(); |
| 635 | bool isAvailable = false; |
| 636 | if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 637 | return -1; |
| 638 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 639 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 640 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 641 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 644 | int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 645 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 646 | CHECKinitialized_(); |
| 647 | bool isAvailable = false; |
| 648 | if (audio_device_->RecordingIsAvailable(isAvailable) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 649 | return -1; |
| 650 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 651 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 652 | LOG(INFO) << "output: " << isAvailable; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 653 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 656 | int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 657 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 658 | uint32_t maxVol(0); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 659 | if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 660 | return -1; |
| 661 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 662 | *maxVolume = maxVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 663 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 666 | int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 667 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 668 | uint32_t minVol(0); |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 669 | if (audio_device_->MinMicrophoneVolume(minVol) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 670 | return -1; |
| 671 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 672 | *minVolume = minVol; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 673 | return 0; |
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 | int16_t AudioDeviceModuleImpl::PlayoutDevices() { |
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 | uint16_t nPlayoutDevices = audio_device_->PlayoutDevices(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 680 | LOG(INFO) << "output: " << nPlayoutDevices; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 681 | return (int16_t)(nPlayoutDevices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 684 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 685 | LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 686 | CHECKinitialized_(); |
| 687 | return audio_device_->SetPlayoutDevice(index); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 690 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 691 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 692 | CHECKinitialized_(); |
| 693 | return audio_device_->SetPlayoutDevice(device); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 694 | } |
| 695 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 696 | int32_t AudioDeviceModuleImpl::PlayoutDeviceName( |
| 697 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 698 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 699 | char guid[kAdmMaxGuidSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 700 | LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 701 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 702 | if (name == NULL) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 703 | return -1; |
| 704 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 705 | if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 706 | return -1; |
| 707 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 708 | if (name != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 709 | LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 710 | } |
| 711 | if (guid != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 712 | LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 713 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 714 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 715 | } |
| 716 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 717 | int32_t AudioDeviceModuleImpl::RecordingDeviceName( |
| 718 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 719 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 720 | char guid[kAdmMaxGuidSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 721 | LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 722 | CHECKinitialized_(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 723 | if (name == NULL) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 724 | return -1; |
| 725 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 726 | if (audio_device_->RecordingDeviceName(index, name, guid) == -1) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 727 | return -1; |
| 728 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 729 | if (name != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 730 | LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 731 | } |
| 732 | if (guid != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 733 | LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 734 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 735 | return 0; |
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 | int16_t AudioDeviceModuleImpl::RecordingDevices() { |
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 | uint16_t nRecordingDevices = audio_device_->RecordingDevices(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 742 | LOG(INFO) << "output: " << nRecordingDevices; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 743 | return (int16_t)nRecordingDevices; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 746 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 747 | LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 748 | CHECKinitialized_(); |
| 749 | return audio_device_->SetRecordingDevice(index); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 752 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 753 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 754 | CHECKinitialized_(); |
| 755 | return audio_device_->SetRecordingDevice(device); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 758 | int32_t AudioDeviceModuleImpl::InitPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 759 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 760 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 761 | if (PlayoutIsInitialized()) { |
| 762 | return 0; |
| 763 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 764 | int32_t result = audio_device_->InitPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 765 | LOG(INFO) << "output: " << result; |
| 766 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess", |
| 767 | static_cast<int>(result == 0)); |
| 768 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 771 | int32_t AudioDeviceModuleImpl::InitRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 772 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 773 | CHECKinitialized_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 774 | if (RecordingIsInitialized()) { |
| 775 | return 0; |
| 776 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 777 | int32_t result = audio_device_->InitRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 778 | LOG(INFO) << "output: " << result; |
| 779 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess", |
| 780 | static_cast<int>(result == 0)); |
| 781 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 784 | bool AudioDeviceModuleImpl::PlayoutIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 785 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 786 | CHECKinitialized__BOOL(); |
| 787 | return audio_device_->PlayoutIsInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 790 | bool AudioDeviceModuleImpl::RecordingIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 791 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 792 | CHECKinitialized__BOOL(); |
| 793 | return audio_device_->RecordingIsInitialized(); |
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::StartPlayout() { |
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_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 799 | if (Playing()) { |
| 800 | return 0; |
| 801 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 802 | audio_device_buffer_.StartPlayout(); |
| 803 | int32_t result = audio_device_->StartPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 804 | LOG(INFO) << "output: " << result; |
| 805 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess", |
| 806 | static_cast<int>(result == 0)); |
| 807 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 810 | int32_t AudioDeviceModuleImpl::StopPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 811 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 812 | CHECKinitialized_(); |
| 813 | int32_t result = audio_device_->StopPlayout(); |
| 814 | audio_device_buffer_.StopPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 815 | LOG(INFO) << "output: " << result; |
| 816 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess", |
| 817 | static_cast<int>(result == 0)); |
| 818 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 821 | bool AudioDeviceModuleImpl::Playing() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 822 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 823 | CHECKinitialized__BOOL(); |
| 824 | return audio_device_->Playing(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 827 | int32_t AudioDeviceModuleImpl::StartRecording() { |
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_(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 830 | if (Recording()) { |
| 831 | return 0; |
| 832 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 833 | audio_device_buffer_.StartRecording(); |
| 834 | int32_t result = audio_device_->StartRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 835 | LOG(INFO) << "output: " << result; |
| 836 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess", |
| 837 | static_cast<int>(result == 0)); |
| 838 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 839 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 840 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 841 | int32_t AudioDeviceModuleImpl::StopRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 842 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 843 | CHECKinitialized_(); |
| 844 | int32_t result = audio_device_->StopRecording(); |
| 845 | audio_device_buffer_.StopRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 846 | LOG(INFO) << "output: " << result; |
| 847 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess", |
| 848 | static_cast<int>(result == 0)); |
| 849 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 852 | bool AudioDeviceModuleImpl::Recording() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 853 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 854 | CHECKinitialized__BOOL(); |
| 855 | return audio_device_->Recording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 858 | int32_t AudioDeviceModuleImpl::RegisterAudioCallback( |
| 859 | AudioTransport* audioCallback) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 860 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 861 | return audio_device_buffer_.RegisterAudioCallback(audioCallback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 864 | int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const { |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 865 | CHECKinitialized_(); |
| 866 | uint16_t delay = 0; |
| 867 | if (audio_device_->PlayoutDelay(delay) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 868 | LOG(LERROR) << "failed to retrieve the playout delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 869 | return -1; |
| 870 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 871 | *delayMS = delay; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 872 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 875 | int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 876 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 877 | CHECKinitialized_(); |
| 878 | uint16_t delay = 0; |
| 879 | if (audio_device_->RecordingDelay(delay) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 880 | LOG(LERROR) << "failed to retrieve the recording delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 881 | return -1; |
| 882 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 883 | *delayMS = delay; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 884 | LOG(INFO) << "output: " << *delayMS; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 885 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 888 | int32_t AudioDeviceModuleImpl::SetRecordingSampleRate( |
| 889 | const uint32_t samplesPerSec) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 890 | LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 891 | CHECKinitialized_(); |
| 892 | if (audio_device_->SetRecordingSampleRate(samplesPerSec) != 0) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 893 | return -1; |
| 894 | } |
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::RecordingSampleRate( |
| 899 | uint32_t* samplesPerSec) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 900 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 901 | CHECKinitialized_(); |
| 902 | int32_t sampleRate = audio_device_buffer_.RecordingSampleRate(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 903 | if (sampleRate == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 904 | LOG(LERROR) << "failed to retrieve the sample rate"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 905 | return -1; |
| 906 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 907 | *samplesPerSec = sampleRate; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 908 | LOG(INFO) << "output: " << *samplesPerSec; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 909 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 912 | int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate( |
| 913 | const uint32_t samplesPerSec) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 914 | LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 915 | CHECKinitialized_(); |
| 916 | if (audio_device_->SetPlayoutSampleRate(samplesPerSec) != 0) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 917 | return -1; |
| 918 | } |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 919 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 922 | int32_t AudioDeviceModuleImpl::PlayoutSampleRate( |
| 923 | uint32_t* samplesPerSec) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 924 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 925 | CHECKinitialized_(); |
| 926 | int32_t sampleRate = audio_device_buffer_.PlayoutSampleRate(); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 927 | if (sampleRate == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 928 | LOG(LERROR) << "failed to retrieve the sample rate"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 929 | return -1; |
| 930 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 931 | *samplesPerSec = sampleRate; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 932 | LOG(INFO) << "output: " << *samplesPerSec; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 933 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 934 | } |
| 935 | |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 936 | int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) { |
| 937 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
| 938 | CHECKinitialized_(); |
| 939 | if (audio_device_->SetLoudspeakerStatus(enable) != 0) { |
| 940 | return -1; |
| 941 | } |
| 942 | return 0; |
| 943 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 944 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 945 | int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 946 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 947 | CHECKinitialized_(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 948 | int32_t ok = 0; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 949 | if (audio_device_->GetLoudspeakerStatus(*enabled) != 0) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 950 | ok = -1; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 951 | } |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 952 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 953 | return ok; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 954 | } |
| 955 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 956 | bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 957 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 958 | CHECKinitialized__BOOL(); |
| 959 | bool isAvailable = audio_device_->BuiltInAECIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 960 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 961 | return isAvailable; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 962 | } |
| 963 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 964 | int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 965 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 966 | CHECKinitialized_(); |
| 967 | int32_t ok = audio_device_->EnableBuiltInAEC(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 968 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 969 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 973 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 974 | CHECKinitialized__BOOL(); |
| 975 | bool isAvailable = audio_device_->BuiltInAGCIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 976 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 977 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 981 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 982 | CHECKinitialized_(); |
| 983 | int32_t ok = audio_device_->EnableBuiltInAGC(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 984 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 985 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 989 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 990 | CHECKinitialized__BOOL(); |
| 991 | bool isAvailable = audio_device_->BuiltInNSIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 992 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 993 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 997 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 998 | CHECKinitialized_(); |
| 999 | int32_t ok = audio_device_->EnableBuiltInNS(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1000 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1001 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 1004 | #if defined(WEBRTC_IOS) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1005 | int AudioDeviceModuleImpl::GetPlayoutAudioParameters( |
| 1006 | AudioParameters* params) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1007 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 1008 | int r = audio_device_->GetPlayoutAudioParameters(params); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1009 | LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1010 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | int AudioDeviceModuleImpl::GetRecordAudioParameters( |
| 1014 | AudioParameters* params) 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 | int r = audio_device_->GetRecordAudioParameters(params); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1017 | LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1018 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1019 | } |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 1020 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1021 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1022 | AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1023 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 1024 | return platform_type_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1027 | AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() |
| 1028 | const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1029 | LOG(INFO) << __FUNCTION__; |
henrika | 4af7366 | 2017-10-11 13:16:17 +0200 | [diff] [blame^] | 1030 | return audio_layer_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | } // namespace webrtc |