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 | |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 11 | #include "webrtc/base/checks.h" |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 12 | #include "webrtc/base/logging.h" |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 13 | #include "webrtc/base/checks.h" |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 14 | #include "webrtc/base/refcount.h" |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 15 | #include "webrtc/base/timeutils.h" |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 16 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
| 17 | #include "webrtc/modules/audio_device/audio_device_config.h" |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 18 | #include "webrtc/modules/audio_device/audio_device_generic.h" |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/audio_device/audio_device_impl.h" |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 20 | #include "webrtc/system_wrappers/include/metrics.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 22 | #include <assert.h> |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 23 | #include <string.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | #if defined(_WIN32) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 26 | #include "audio_device_wave_win.h" |
| 27 | #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
| 28 | #include "audio_device_core_win.h" |
| 29 | #endif |
leozwang@google.com | 39f2051 | 2011-07-15 16:29:40 +0000 | [diff] [blame] | 30 | #elif defined(WEBRTC_ANDROID) |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 31 | #include <stdlib.h> |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 32 | #include "webrtc/modules/audio_device/android/audio_device_template.h" |
| 33 | #include "webrtc/modules/audio_device/android/audio_manager.h" |
| 34 | #include "webrtc/modules/audio_device/android/audio_record_jni.h" |
| 35 | #include "webrtc/modules/audio_device/android/audio_track_jni.h" |
| 36 | #include "webrtc/modules/audio_device/android/opensles_player.h" |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 37 | #include "webrtc/modules/audio_device/android/opensles_recorder.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | #elif defined(WEBRTC_LINUX) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 39 | #if defined(LINUX_ALSA) |
| 40 | #include "audio_device_alsa_linux.h" |
| 41 | #endif |
Tommi | 68898a2 | 2015-05-19 17:28:07 +0200 | [diff] [blame] | 42 | #if defined(LINUX_PULSE) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 43 | #include "audio_device_pulse_linux.h" |
Tommi | 68898a2 | 2015-05-19 17:28:07 +0200 | [diff] [blame] | 44 | #endif |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 45 | #elif defined(WEBRTC_IOS) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 46 | #include "audio_device_ios.h" |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 47 | #elif defined(WEBRTC_MAC) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 48 | #include "audio_device_mac.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | #endif |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 50 | |
| 51 | #if defined(WEBRTC_DUMMY_FILE_DEVICES) |
| 52 | #include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h" |
| 53 | #endif |
| 54 | |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 55 | #include "webrtc/modules/audio_device/dummy/audio_device_dummy.h" |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 56 | #include "webrtc/modules/audio_device/dummy/file_audio_device.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 57 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 59 | #define CHECK_INITIALIZED() \ |
| 60 | { \ |
| 61 | if (!_initialized) { \ |
| 62 | return -1; \ |
| 63 | }; \ |
| 64 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 66 | #define CHECK_INITIALIZED_BOOL() \ |
| 67 | { \ |
| 68 | if (!_initialized) { \ |
| 69 | return false; \ |
| 70 | }; \ |
| 71 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 73 | namespace webrtc { |
henrike@webrtc.org | 70efc32 | 2012-02-23 17:45:33 +0000 | [diff] [blame] | 74 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | // ============================================================================ |
| 76 | // Static methods |
| 77 | // ============================================================================ |
| 78 | |
| 79 | // ---------------------------------------------------------------------------- |
| 80 | // AudioDeviceModule::Create() |
| 81 | // ---------------------------------------------------------------------------- |
| 82 | |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 83 | rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create( |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 84 | const int32_t id, |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 85 | const AudioLayer audio_layer) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 86 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 87 | // Create the generic ref counted (platform independent) implementation. |
| 88 | rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice( |
| 89 | new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 91 | // Ensure that the current platform is supported. |
| 92 | if (audioDevice->CheckPlatform() == -1) { |
| 93 | return nullptr; |
| 94 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 96 | // Create the platform-dependent implementation. |
| 97 | if (audioDevice->CreatePlatformSpecificObjects() == -1) { |
| 98 | return nullptr; |
| 99 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 101 | // Ensure that the generic audio buffer can communicate with the |
| 102 | // platform-specific parts. |
| 103 | if (audioDevice->AttachAudioBuffer() == -1) { |
| 104 | return nullptr; |
| 105 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 107 | WebRtcSpl_Init(); |
kma@webrtc.org | ac4d70d | 2012-10-05 00:19:01 +0000 | [diff] [blame] | 108 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 109 | return audioDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | } |
| 111 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | // ============================================================================ |
| 113 | // Construction & Destruction |
| 114 | // ============================================================================ |
| 115 | |
| 116 | // ---------------------------------------------------------------------------- |
| 117 | // AudioDeviceModuleImpl - ctor |
| 118 | // ---------------------------------------------------------------------------- |
| 119 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 120 | AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, |
| 121 | const AudioLayer audioLayer) |
| 122 | : _critSect(*CriticalSectionWrapper::CreateCriticalSection()), |
| 123 | _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()), |
| 124 | _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()), |
| 125 | _ptrCbAudioDeviceObserver(NULL), |
| 126 | _ptrAudioDevice(NULL), |
| 127 | _id(id), |
| 128 | _platformAudioLayer(audioLayer), |
| 129 | _lastProcessTime(rtc::TimeMillis()), |
| 130 | _platformType(kPlatformNotSupported), |
| 131 | _initialized(false), |
| 132 | _lastError(kAdmErrNone) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 133 | LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | // ---------------------------------------------------------------------------- |
| 137 | // CheckPlatform |
| 138 | // ---------------------------------------------------------------------------- |
| 139 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 140 | int32_t AudioDeviceModuleImpl::CheckPlatform() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 141 | LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 143 | // Ensure that the current platform is supported |
| 144 | // |
| 145 | PlatformType platform(kPlatformNotSupported); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
| 147 | #if defined(_WIN32) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 148 | platform = kPlatformWin32; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 149 | LOG(INFO) << "current platform is Win32"; |
leozwang@google.com | 522f42b | 2011-09-19 17:39:05 +0000 | [diff] [blame] | 150 | #elif defined(WEBRTC_ANDROID) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 151 | platform = kPlatformAndroid; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 152 | LOG(INFO) << "current platform is Android"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | #elif defined(WEBRTC_LINUX) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 154 | platform = kPlatformLinux; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 155 | LOG(INFO) << "current platform is Linux"; |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 156 | #elif defined(WEBRTC_IOS) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 157 | platform = kPlatformIOS; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 158 | LOG(INFO) << "current platform is IOS"; |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 159 | #elif defined(WEBRTC_MAC) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 160 | platform = kPlatformMac; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 161 | LOG(INFO) << "current platform is Mac"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | #endif |
| 163 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 164 | if (platform == kPlatformNotSupported) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 165 | LOG(LERROR) << "current platform is not supported => this module will self " |
| 166 | "destruct!"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 167 | return -1; |
| 168 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 170 | // Store valid output results |
| 171 | // |
| 172 | _platformType = platform; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 174 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | } |
| 176 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | // ---------------------------------------------------------------------------- |
| 178 | // CreatePlatformSpecificObjects |
| 179 | // ---------------------------------------------------------------------------- |
| 180 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 181 | int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 182 | LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 184 | AudioDeviceGeneric* ptrAudioDevice(NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 186 | #if defined(WEBRTC_DUMMY_AUDIO_BUILD) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 187 | ptrAudioDevice = new AudioDeviceDummy(Id()); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 188 | LOG(INFO) << "Dummy Audio APIs will be utilized"; |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 189 | #elif defined(WEBRTC_DUMMY_FILE_DEVICES) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 190 | ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id()); |
noahric | 6a35590 | 2016-08-17 15:19:50 -0700 | [diff] [blame] | 191 | if (ptrAudioDevice) { |
| 192 | LOG(INFO) << "Will use file-playing dummy device."; |
| 193 | } else { |
| 194 | // Create a dummy device instead. |
| 195 | ptrAudioDevice = new AudioDeviceDummy(Id()); |
| 196 | LOG(INFO) << "Dummy Audio APIs will be utilized"; |
| 197 | } |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 198 | #else |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 199 | AudioLayer audioLayer(PlatformAudioLayer()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 201 | // Create the *Windows* implementation of the Audio Device |
| 202 | // |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | #if defined(_WIN32) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 204 | if ((audioLayer == kWindowsWaveAudio) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | #if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 206 | // Wave audio is default if Core audio is not supported in this build |
| 207 | || (audioLayer == kPlatformDefaultAudio) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | #endif |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 209 | ) { |
| 210 | // create *Windows Wave Audio* implementation |
| 211 | ptrAudioDevice = new AudioDeviceWindowsWave(Id()); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 212 | LOG(INFO) << "Windows Wave APIs will be utilized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 213 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 215 | if ((audioLayer == kWindowsCoreAudio) || |
| 216 | (audioLayer == kPlatformDefaultAudio)) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 217 | LOG(INFO) << "attempting to use the Windows Core Audio APIs..."; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 218 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 219 | if (AudioDeviceWindowsCore::CoreAudioIsSupported()) { |
| 220 | // create *Windows Core Audio* implementation |
| 221 | ptrAudioDevice = new AudioDeviceWindowsCore(Id()); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 222 | LOG(INFO) << "Windows Core Audio APIs will be utilized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 223 | } else { |
| 224 | // create *Windows Wave Audio* implementation |
| 225 | ptrAudioDevice = new AudioDeviceWindowsWave(Id()); |
| 226 | if (ptrAudioDevice != NULL) { |
| 227 | // Core Audio was not supported => revert to Windows Wave instead |
| 228 | _platformAudioLayer = |
| 229 | kWindowsWaveAudio; // modify the state set at construction |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 230 | LOG(WARNING) << "Windows Core Audio is *not* supported => Wave APIs " |
| 231 | "will be utilized instead"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 232 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 233 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 234 | } |
| 235 | #endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | #endif // #if defined(_WIN32) |
| 237 | |
henrike@webrtc.org | 9ee75e9 | 2013-12-11 21:42:44 +0000 | [diff] [blame] | 238 | #if defined(WEBRTC_ANDROID) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 239 | // Create an Android audio manager. |
| 240 | _audioManagerAndroid.reset(new AudioManager()); |
| 241 | // Select best possible combination of audio layers. |
| 242 | if (audioLayer == kPlatformDefaultAudio) { |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 243 | if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() && |
| 244 | _audioManagerAndroid->IsLowLatencyRecordSupported()) { |
| 245 | // Use OpenSL ES for both playout and recording. |
| 246 | audioLayer = kAndroidOpenSLESAudio; |
| 247 | } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() && |
| 248 | !_audioManagerAndroid->IsLowLatencyRecordSupported()) { |
| 249 | // Use OpenSL ES for output on devices that only supports the |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 250 | // low-latency output audio path. |
| 251 | audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 252 | } else { |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 253 | // Use Java-based audio in both directions when low-latency output is |
| 254 | // not supported. |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 255 | audioLayer = kAndroidJavaAudio; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 256 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 257 | } |
| 258 | AudioManager* audio_manager = _audioManagerAndroid.get(); |
| 259 | if (audioLayer == kAndroidJavaAudio) { |
| 260 | // Java audio for both input and output audio. |
| 261 | ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>( |
| 262 | audioLayer, audio_manager); |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 263 | } else if (audioLayer == kAndroidOpenSLESAudio) { |
| 264 | // OpenSL ES based audio for both input and output audio. |
| 265 | ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>( |
| 266 | audioLayer, audio_manager); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 267 | } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) { |
| 268 | // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs). |
| 269 | // This combination provides low-latency output audio and at the same |
| 270 | // time support for HW AEC using the AudioRecord Java API. |
| 271 | ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>( |
| 272 | audioLayer, audio_manager); |
| 273 | } else { |
| 274 | // Invalid audio layer. |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 275 | ptrAudioDevice = nullptr; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 276 | } |
| 277 | // END #if defined(WEBRTC_ANDROID) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 278 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 279 | // Create the *Linux* implementation of the Audio Device |
| 280 | // |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 281 | #elif defined(WEBRTC_LINUX) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 282 | if ((audioLayer == kLinuxPulseAudio) || |
| 283 | (audioLayer == kPlatformDefaultAudio)) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 284 | #if defined(LINUX_PULSE) |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 285 | LOG(INFO) << "attempting to use the Linux PulseAudio APIs..."; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 286 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 287 | // create *Linux PulseAudio* implementation |
| 288 | AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id()); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 289 | if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 290 | ptrAudioDevice = pulseDevice; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 291 | LOG(INFO) << "Linux PulseAudio APIs will be utilized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 292 | } else { |
| 293 | delete pulseDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | #endif |
| 295 | #if defined(LINUX_ALSA) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 296 | // create *Linux ALSA Audio* implementation |
| 297 | ptrAudioDevice = new AudioDeviceLinuxALSA(Id()); |
| 298 | if (ptrAudioDevice != NULL) { |
| 299 | // Pulse Audio was not supported => revert to ALSA instead |
| 300 | _platformAudioLayer = |
| 301 | kLinuxAlsaAudio; // modify the state set at construction |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 302 | LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will " |
| 303 | "be utilized instead"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 304 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 305 | #endif |
| 306 | #if defined(LINUX_PULSE) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 307 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 308 | #endif |
| 309 | } else if (audioLayer == kLinuxAlsaAudio) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | #if defined(LINUX_ALSA) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 311 | // create *Linux ALSA Audio* implementation |
| 312 | ptrAudioDevice = new AudioDeviceLinuxALSA(Id()); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 313 | LOG(INFO) << "Linux ALSA APIs will be utilized"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 314 | #endif |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 315 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | #endif // #if defined(WEBRTC_LINUX) |
| 317 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 318 | // Create the *iPhone* implementation of the Audio Device |
| 319 | // |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 320 | #if defined(WEBRTC_IOS) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 321 | if (audioLayer == kPlatformDefaultAudio) { |
| 322 | // Create iOS Audio Device implementation. |
| 323 | ptrAudioDevice = new AudioDeviceIOS(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 324 | LOG(INFO) << "iPhone Audio APIs will be utilized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 325 | } |
| 326 | // END #if defined(WEBRTC_IOS) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 328 | // Create the *Mac* implementation of the Audio Device |
| 329 | // |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 330 | #elif defined(WEBRTC_MAC) |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 331 | if (audioLayer == kPlatformDefaultAudio) { |
| 332 | // Create *Mac Audio* implementation |
| 333 | ptrAudioDevice = new AudioDeviceMac(Id()); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 334 | LOG(INFO) << "Mac OS X Audio APIs will be utilized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 335 | } |
andrew@webrtc.org | f3b65db | 2012-09-06 18:17:00 +0000 | [diff] [blame] | 336 | #endif // WEBRTC_MAC |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 337 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 338 | // Create the *Dummy* implementation of the Audio Device |
| 339 | // Available for all platforms |
| 340 | // |
| 341 | if (audioLayer == kDummyAudio) { |
| 342 | // Create *Dummy Audio* implementation |
| 343 | assert(!ptrAudioDevice); |
| 344 | ptrAudioDevice = new AudioDeviceDummy(Id()); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 345 | LOG(INFO) << "Dummy Audio APIs will be utilized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 346 | } |
xians@google.com | bf5d2ba | 2011-08-16 07:44:19 +0000 | [diff] [blame] | 347 | #endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 349 | if (ptrAudioDevice == NULL) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 350 | LOG(LERROR) |
| 351 | << "unable to create the platform specific audio device implementation"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 352 | return -1; |
| 353 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 355 | // Store valid output pointers |
| 356 | // |
| 357 | _ptrAudioDevice = ptrAudioDevice; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 358 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 359 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | // ---------------------------------------------------------------------------- |
| 363 | // AttachAudioBuffer |
| 364 | // |
| 365 | // Install "bridge" between the platform implemetation and the generic |
| 366 | // implementation. The "child" shall set the native sampling rate and the |
| 367 | // number of channels in this function call. |
| 368 | // ---------------------------------------------------------------------------- |
| 369 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 370 | int32_t AudioDeviceModuleImpl::AttachAudioBuffer() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 371 | LOG(INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 372 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 373 | _audioDeviceBuffer.SetId(_id); |
| 374 | _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer); |
| 375 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | // ---------------------------------------------------------------------------- |
| 379 | // ~AudioDeviceModuleImpl - dtor |
| 380 | // ---------------------------------------------------------------------------- |
| 381 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 382 | AudioDeviceModuleImpl::~AudioDeviceModuleImpl() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 383 | LOG(INFO) << __FUNCTION__; |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 384 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 385 | if (_ptrAudioDevice) { |
| 386 | delete _ptrAudioDevice; |
| 387 | _ptrAudioDevice = NULL; |
| 388 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 389 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 390 | delete &_critSect; |
| 391 | delete &_critSectEventCb; |
| 392 | delete &_critSectAudioCb; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // ============================================================================ |
| 396 | // Module |
| 397 | // ============================================================================ |
| 398 | |
| 399 | // ---------------------------------------------------------------------------- |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 400 | // Module::TimeUntilNextProcess |
| 401 | // |
| 402 | // Returns the number of milliseconds until the module want a worker thread |
| 403 | // to call Process(). |
| 404 | // ---------------------------------------------------------------------------- |
| 405 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 406 | int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() { |
| 407 | int64_t now = rtc::TimeMillis(); |
| 408 | int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime); |
| 409 | return deltaProcess; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | // ---------------------------------------------------------------------------- |
| 413 | // Module::Process |
| 414 | // |
| 415 | // Check for posted error and warning reports. Generate callbacks if |
| 416 | // new reports exists. |
| 417 | // ---------------------------------------------------------------------------- |
| 418 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 419 | void AudioDeviceModuleImpl::Process() { |
| 420 | _lastProcessTime = rtc::TimeMillis(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 421 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 422 | // kPlayoutWarning |
| 423 | if (_ptrAudioDevice->PlayoutWarning()) { |
| 424 | CriticalSectionScoped lock(&_critSectEventCb); |
| 425 | if (_ptrCbAudioDeviceObserver) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 426 | LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 427 | _ptrCbAudioDeviceObserver->OnWarningIsReported( |
| 428 | AudioDeviceObserver::kPlayoutWarning); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 429 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 430 | _ptrAudioDevice->ClearPlayoutWarning(); |
| 431 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 432 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 433 | // kPlayoutError |
| 434 | if (_ptrAudioDevice->PlayoutError()) { |
| 435 | CriticalSectionScoped lock(&_critSectEventCb); |
| 436 | if (_ptrCbAudioDeviceObserver) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 437 | LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 438 | _ptrCbAudioDeviceObserver->OnErrorIsReported( |
| 439 | AudioDeviceObserver::kPlayoutError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 440 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 441 | _ptrAudioDevice->ClearPlayoutError(); |
| 442 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 443 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 444 | // kRecordingWarning |
| 445 | if (_ptrAudioDevice->RecordingWarning()) { |
| 446 | CriticalSectionScoped lock(&_critSectEventCb); |
| 447 | if (_ptrCbAudioDeviceObserver) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 448 | LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 449 | _ptrCbAudioDeviceObserver->OnWarningIsReported( |
| 450 | AudioDeviceObserver::kRecordingWarning); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 451 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 452 | _ptrAudioDevice->ClearRecordingWarning(); |
| 453 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 454 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 455 | // kRecordingError |
| 456 | if (_ptrAudioDevice->RecordingError()) { |
| 457 | CriticalSectionScoped lock(&_critSectEventCb); |
| 458 | if (_ptrCbAudioDeviceObserver) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 459 | LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 460 | _ptrCbAudioDeviceObserver->OnErrorIsReported( |
| 461 | AudioDeviceObserver::kRecordingError); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 462 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 463 | _ptrAudioDevice->ClearRecordingError(); |
| 464 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | // ============================================================================ |
| 468 | // Public API |
| 469 | // ============================================================================ |
| 470 | |
| 471 | // ---------------------------------------------------------------------------- |
| 472 | // ActiveAudioLayer |
| 473 | // ---------------------------------------------------------------------------- |
| 474 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 475 | int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 476 | LOG(INFO) << __FUNCTION__; |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 477 | AudioLayer activeAudio; |
| 478 | if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) { |
| 479 | return -1; |
| 480 | } |
| 481 | *audioLayer = activeAudio; |
| 482 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | // ---------------------------------------------------------------------------- |
| 486 | // LastError |
| 487 | // ---------------------------------------------------------------------------- |
| 488 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 489 | AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 490 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 491 | return _lastError; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | // ---------------------------------------------------------------------------- |
| 495 | // Init |
| 496 | // ---------------------------------------------------------------------------- |
| 497 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 498 | int32_t AudioDeviceModuleImpl::Init() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 499 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 500 | if (_initialized) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 501 | return 0; |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 502 | RTC_CHECK(_ptrAudioDevice); |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 503 | |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 504 | AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init(); |
| 505 | RTC_HISTOGRAM_ENUMERATION( |
| 506 | "WebRTC.Audio.InitializationResult", static_cast<int>(status), |
| 507 | static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES)); |
| 508 | if (status != AudioDeviceGeneric::InitStatus::OK) { |
| 509 | LOG(LS_ERROR) << "Audio device initialization failed."; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 510 | return -1; |
| 511 | } |
| 512 | |
| 513 | _initialized = true; |
| 514 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | // ---------------------------------------------------------------------------- |
| 518 | // Terminate |
| 519 | // ---------------------------------------------------------------------------- |
| 520 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 521 | int32_t AudioDeviceModuleImpl::Terminate() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 522 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 523 | if (!_initialized) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 524 | return 0; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 525 | |
| 526 | if (_ptrAudioDevice->Terminate() == -1) { |
| 527 | return -1; |
| 528 | } |
| 529 | |
| 530 | _initialized = false; |
| 531 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | // ---------------------------------------------------------------------------- |
| 535 | // Initialized |
| 536 | // ---------------------------------------------------------------------------- |
| 537 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 538 | bool AudioDeviceModuleImpl::Initialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 539 | LOG(INFO) << __FUNCTION__ << ": " << _initialized; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 540 | return (_initialized); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | // ---------------------------------------------------------------------------- |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 544 | // InitSpeaker |
| 545 | // ---------------------------------------------------------------------------- |
| 546 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 547 | int32_t AudioDeviceModuleImpl::InitSpeaker() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 548 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 549 | CHECK_INITIALIZED(); |
| 550 | return (_ptrAudioDevice->InitSpeaker()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // ---------------------------------------------------------------------------- |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 554 | // InitMicrophone |
| 555 | // ---------------------------------------------------------------------------- |
| 556 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 557 | int32_t AudioDeviceModuleImpl::InitMicrophone() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 558 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 559 | CHECK_INITIALIZED(); |
| 560 | return (_ptrAudioDevice->InitMicrophone()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | // ---------------------------------------------------------------------------- |
| 564 | // SpeakerVolumeIsAvailable |
| 565 | // ---------------------------------------------------------------------------- |
| 566 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 567 | int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 568 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 569 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 570 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 571 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 572 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 573 | if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) { |
| 574 | return -1; |
| 575 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 576 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 577 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 578 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 579 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | // ---------------------------------------------------------------------------- |
| 583 | // SetSpeakerVolume |
| 584 | // ---------------------------------------------------------------------------- |
| 585 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 586 | int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 587 | LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 588 | CHECK_INITIALIZED(); |
| 589 | return (_ptrAudioDevice->SetSpeakerVolume(volume)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | // ---------------------------------------------------------------------------- |
| 593 | // SpeakerVolume |
| 594 | // ---------------------------------------------------------------------------- |
| 595 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 596 | int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 597 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 598 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 599 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 600 | uint32_t level(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 601 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 602 | if (_ptrAudioDevice->SpeakerVolume(level) == -1) { |
| 603 | return -1; |
| 604 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 605 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 606 | *volume = level; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 607 | LOG(INFO) << "output: " << *volume; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 608 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | // ---------------------------------------------------------------------------- |
| 612 | // SetWaveOutVolume |
| 613 | // ---------------------------------------------------------------------------- |
| 614 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 615 | int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, |
| 616 | uint16_t volumeRight) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 617 | LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 618 | CHECK_INITIALIZED(); |
| 619 | return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // ---------------------------------------------------------------------------- |
| 623 | // WaveOutVolume |
| 624 | // ---------------------------------------------------------------------------- |
| 625 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 626 | int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, |
| 627 | uint16_t* volumeRight) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 628 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 629 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 630 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 631 | uint16_t volLeft(0); |
| 632 | uint16_t volRight(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 633 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 634 | if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) { |
| 635 | return -1; |
| 636 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 637 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 638 | *volumeLeft = volLeft; |
| 639 | *volumeRight = volRight; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 640 | LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 641 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 642 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | // ---------------------------------------------------------------------------- |
| 646 | // SpeakerIsInitialized |
| 647 | // ---------------------------------------------------------------------------- |
| 648 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 649 | bool AudioDeviceModuleImpl::SpeakerIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 650 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 651 | CHECK_INITIALIZED_BOOL(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 652 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 653 | bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 654 | LOG(INFO) << "output: " << isInitialized; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 655 | return (isInitialized); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | // ---------------------------------------------------------------------------- |
| 659 | // MicrophoneIsInitialized |
| 660 | // ---------------------------------------------------------------------------- |
| 661 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 662 | bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 663 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 664 | CHECK_INITIALIZED_BOOL(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 665 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 666 | bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 667 | LOG(INFO) << "output: " << isInitialized; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 668 | return (isInitialized); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | // ---------------------------------------------------------------------------- |
| 672 | // MaxSpeakerVolume |
| 673 | // ---------------------------------------------------------------------------- |
| 674 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 675 | int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const { |
| 676 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 677 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 678 | uint32_t maxVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 679 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 680 | if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) { |
| 681 | return -1; |
| 682 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 683 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 684 | *maxVolume = maxVol; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 685 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | // ---------------------------------------------------------------------------- |
| 689 | // MinSpeakerVolume |
| 690 | // ---------------------------------------------------------------------------- |
| 691 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 692 | int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const { |
| 693 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 694 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 695 | uint32_t minVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 696 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 697 | if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) { |
| 698 | return -1; |
| 699 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 700 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 701 | *minVolume = minVol; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 702 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // ---------------------------------------------------------------------------- |
| 706 | // SpeakerVolumeStepSize |
| 707 | // ---------------------------------------------------------------------------- |
| 708 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 709 | int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 710 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 711 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 712 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 713 | uint16_t delta(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 714 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 715 | if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 716 | LOG(LERROR) << "failed to retrieve the speaker-volume step size"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 717 | return -1; |
| 718 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 719 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 720 | *stepSize = delta; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 721 | LOG(INFO) << "output: " << *stepSize; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 722 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | // ---------------------------------------------------------------------------- |
| 726 | // SpeakerMuteIsAvailable |
| 727 | // ---------------------------------------------------------------------------- |
| 728 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 729 | int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 730 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 731 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 732 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 733 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 734 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 735 | if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) { |
| 736 | return -1; |
| 737 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 738 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 739 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 740 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 741 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | // ---------------------------------------------------------------------------- |
| 745 | // SetSpeakerMute |
| 746 | // ---------------------------------------------------------------------------- |
| 747 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 748 | int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 749 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 750 | CHECK_INITIALIZED(); |
| 751 | return (_ptrAudioDevice->SetSpeakerMute(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | // ---------------------------------------------------------------------------- |
| 755 | // SpeakerMute |
| 756 | // ---------------------------------------------------------------------------- |
| 757 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 758 | int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 759 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 760 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 761 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 762 | bool muted(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 763 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 764 | if (_ptrAudioDevice->SpeakerMute(muted) == -1) { |
| 765 | return -1; |
| 766 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 767 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 768 | *enabled = muted; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 769 | LOG(INFO) << "output: " << muted; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 770 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | // ---------------------------------------------------------------------------- |
| 774 | // MicrophoneMuteIsAvailable |
| 775 | // ---------------------------------------------------------------------------- |
| 776 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 777 | int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 778 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 779 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 780 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 781 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 782 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 783 | if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) { |
| 784 | return -1; |
| 785 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 786 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 787 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 788 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 789 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | // ---------------------------------------------------------------------------- |
| 793 | // SetMicrophoneMute |
| 794 | // ---------------------------------------------------------------------------- |
| 795 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 796 | int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 797 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 798 | CHECK_INITIALIZED(); |
| 799 | return (_ptrAudioDevice->SetMicrophoneMute(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | // ---------------------------------------------------------------------------- |
| 803 | // MicrophoneMute |
| 804 | // ---------------------------------------------------------------------------- |
| 805 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 806 | int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 807 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 808 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 809 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 810 | bool muted(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 811 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 812 | if (_ptrAudioDevice->MicrophoneMute(muted) == -1) { |
| 813 | return -1; |
| 814 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 815 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 816 | *enabled = muted; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 817 | LOG(INFO) << "output: " << muted; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 818 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | // ---------------------------------------------------------------------------- |
| 822 | // MicrophoneBoostIsAvailable |
| 823 | // ---------------------------------------------------------------------------- |
| 824 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 825 | int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 826 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 827 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 828 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 829 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 830 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 831 | if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) { |
| 832 | return -1; |
| 833 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 834 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 835 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 836 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 837 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | // ---------------------------------------------------------------------------- |
| 841 | // SetMicrophoneBoost |
| 842 | // ---------------------------------------------------------------------------- |
| 843 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 844 | int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 845 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 846 | CHECK_INITIALIZED(); |
| 847 | return (_ptrAudioDevice->SetMicrophoneBoost(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | // ---------------------------------------------------------------------------- |
| 851 | // MicrophoneBoost |
| 852 | // ---------------------------------------------------------------------------- |
| 853 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 854 | int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 855 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 856 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 857 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 858 | bool onOff(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 859 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 860 | if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) { |
| 861 | return -1; |
| 862 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 863 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 864 | *enabled = onOff; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 865 | LOG(INFO) << "output: " << onOff; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 866 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | // ---------------------------------------------------------------------------- |
| 870 | // MicrophoneVolumeIsAvailable |
| 871 | // ---------------------------------------------------------------------------- |
| 872 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 873 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 874 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 875 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 876 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 877 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 878 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 879 | if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) { |
| 880 | return -1; |
| 881 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 882 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 883 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 884 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 885 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | // ---------------------------------------------------------------------------- |
| 889 | // SetMicrophoneVolume |
| 890 | // ---------------------------------------------------------------------------- |
| 891 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 892 | int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 893 | LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 894 | CHECK_INITIALIZED(); |
| 895 | return (_ptrAudioDevice->SetMicrophoneVolume(volume)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | // ---------------------------------------------------------------------------- |
| 899 | // MicrophoneVolume |
| 900 | // ---------------------------------------------------------------------------- |
| 901 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 902 | int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 903 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 904 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 905 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 906 | uint32_t level(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 907 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 908 | if (_ptrAudioDevice->MicrophoneVolume(level) == -1) { |
| 909 | return -1; |
| 910 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 911 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 912 | *volume = level; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 913 | LOG(INFO) << "output: " << *volume; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 914 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | // ---------------------------------------------------------------------------- |
| 918 | // StereoRecordingIsAvailable |
| 919 | // ---------------------------------------------------------------------------- |
| 920 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 921 | int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable( |
| 922 | bool* available) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 923 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 924 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 925 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 926 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 927 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 928 | if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) { |
| 929 | return -1; |
| 930 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 931 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 932 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 933 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 934 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // ---------------------------------------------------------------------------- |
| 938 | // SetStereoRecording |
| 939 | // ---------------------------------------------------------------------------- |
| 940 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 941 | int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 942 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 943 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 944 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 945 | if (_ptrAudioDevice->RecordingIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 946 | LOG(WARNING) << "recording in stereo is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 947 | return -1; |
| 948 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 949 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 950 | if (_ptrAudioDevice->SetStereoRecording(enable) == -1) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 951 | LOG(WARNING) << "failed to change stereo recording"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 952 | return -1; |
| 953 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 954 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 955 | int8_t nChannels(1); |
| 956 | if (enable) { |
| 957 | nChannels = 2; |
| 958 | } |
| 959 | _audioDeviceBuffer.SetRecordingChannels(nChannels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 960 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 961 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | // ---------------------------------------------------------------------------- |
| 965 | // StereoRecording |
| 966 | // ---------------------------------------------------------------------------- |
| 967 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 968 | int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 969 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 970 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 971 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 972 | bool stereo(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 973 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 974 | if (_ptrAudioDevice->StereoRecording(stereo) == -1) { |
| 975 | return -1; |
| 976 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 977 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 978 | *enabled = stereo; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 979 | LOG(INFO) << "output: " << stereo; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 980 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | // ---------------------------------------------------------------------------- |
| 984 | // SetRecordingChannel |
| 985 | // ---------------------------------------------------------------------------- |
| 986 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 987 | int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) { |
| 988 | if (channel == kChannelBoth) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 989 | LOG(INFO) << __FUNCTION__ << "(both)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 990 | } else if (channel == kChannelLeft) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 991 | LOG(INFO) << __FUNCTION__ << "(left)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 992 | } else { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 993 | LOG(INFO) << __FUNCTION__ << "(right)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 994 | } |
| 995 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 996 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 997 | bool stereo(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 998 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 999 | if (_ptrAudioDevice->StereoRecording(stereo) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1000 | LOG(WARNING) << "recording in stereo is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1001 | return -1; |
| 1002 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1003 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1004 | return (_audioDeviceBuffer.SetRecordingChannel(channel)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | // ---------------------------------------------------------------------------- |
| 1008 | // RecordingChannel |
| 1009 | // ---------------------------------------------------------------------------- |
| 1010 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1011 | int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1012 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1013 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1014 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1015 | ChannelType chType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1016 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1017 | if (_audioDeviceBuffer.RecordingChannel(chType) == -1) { |
| 1018 | return -1; |
| 1019 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1020 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1021 | *channel = chType; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1022 | if (*channel == kChannelBoth) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1023 | LOG(INFO) << "output: both"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1024 | } else if (*channel == kChannelLeft) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1025 | LOG(INFO) << "output: left"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1026 | } else { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1027 | LOG(INFO) << "output: right"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1028 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1029 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | // ---------------------------------------------------------------------------- |
| 1033 | // StereoPlayoutIsAvailable |
| 1034 | // ---------------------------------------------------------------------------- |
| 1035 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1036 | int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1037 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1038 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1039 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1040 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1041 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1042 | if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) { |
| 1043 | return -1; |
| 1044 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1045 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1046 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1047 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1048 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | // ---------------------------------------------------------------------------- |
| 1052 | // SetStereoPlayout |
| 1053 | // ---------------------------------------------------------------------------- |
| 1054 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1055 | int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1056 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1057 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1058 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1059 | if (_ptrAudioDevice->PlayoutIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1060 | LOG(LERROR) |
| 1061 | << "unable to set stereo mode while playing side is initialized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1062 | return -1; |
| 1063 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1064 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1065 | if (_ptrAudioDevice->SetStereoPlayout(enable)) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1066 | LOG(WARNING) << "stereo playout is not supported"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1067 | return -1; |
| 1068 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1069 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1070 | int8_t nChannels(1); |
| 1071 | if (enable) { |
| 1072 | nChannels = 2; |
| 1073 | } |
| 1074 | _audioDeviceBuffer.SetPlayoutChannels(nChannels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1075 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1076 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | // ---------------------------------------------------------------------------- |
| 1080 | // StereoPlayout |
| 1081 | // ---------------------------------------------------------------------------- |
| 1082 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1083 | int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1084 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1085 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1086 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1087 | bool stereo(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1088 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1089 | if (_ptrAudioDevice->StereoPlayout(stereo) == -1) { |
| 1090 | return -1; |
| 1091 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1092 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1093 | *enabled = stereo; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1094 | LOG(INFO) << "output: " << stereo; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1095 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | // ---------------------------------------------------------------------------- |
| 1099 | // SetAGC |
| 1100 | // ---------------------------------------------------------------------------- |
| 1101 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1102 | int32_t AudioDeviceModuleImpl::SetAGC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1103 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1104 | CHECK_INITIALIZED(); |
| 1105 | return (_ptrAudioDevice->SetAGC(enable)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | // ---------------------------------------------------------------------------- |
| 1109 | // AGC |
| 1110 | // ---------------------------------------------------------------------------- |
| 1111 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1112 | bool AudioDeviceModuleImpl::AGC() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1113 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1114 | CHECK_INITIALIZED_BOOL(); |
| 1115 | return (_ptrAudioDevice->AGC()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | // ---------------------------------------------------------------------------- |
| 1119 | // PlayoutIsAvailable |
| 1120 | // ---------------------------------------------------------------------------- |
| 1121 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1122 | int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1123 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1124 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1125 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1126 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1127 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1128 | if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) { |
| 1129 | return -1; |
| 1130 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1131 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1132 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1133 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1134 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | // ---------------------------------------------------------------------------- |
| 1138 | // RecordingIsAvailable |
| 1139 | // ---------------------------------------------------------------------------- |
| 1140 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1141 | int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1142 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1143 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1144 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1145 | bool isAvailable(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1146 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1147 | if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) { |
| 1148 | return -1; |
| 1149 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1150 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1151 | *available = isAvailable; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1152 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1153 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | // ---------------------------------------------------------------------------- |
| 1157 | // MaxMicrophoneVolume |
| 1158 | // ---------------------------------------------------------------------------- |
| 1159 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1160 | int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1161 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1162 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1163 | uint32_t maxVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1164 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1165 | if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) { |
| 1166 | return -1; |
| 1167 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1168 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1169 | *maxVolume = maxVol; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1170 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | // ---------------------------------------------------------------------------- |
| 1174 | // MinMicrophoneVolume |
| 1175 | // ---------------------------------------------------------------------------- |
| 1176 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1177 | int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const { |
| 1178 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1179 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1180 | uint32_t minVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1181 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1182 | if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) { |
| 1183 | return -1; |
| 1184 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1185 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1186 | *minVolume = minVol; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1187 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | // ---------------------------------------------------------------------------- |
| 1191 | // MicrophoneVolumeStepSize |
| 1192 | // ---------------------------------------------------------------------------- |
| 1193 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1194 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize( |
| 1195 | uint16_t* stepSize) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1196 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1197 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1198 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1199 | uint16_t delta(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1200 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1201 | if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) { |
| 1202 | return -1; |
| 1203 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1204 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1205 | *stepSize = delta; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1206 | LOG(INFO) << "output: " << *stepSize; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1207 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | // ---------------------------------------------------------------------------- |
| 1211 | // PlayoutDevices |
| 1212 | // ---------------------------------------------------------------------------- |
| 1213 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1214 | int16_t AudioDeviceModuleImpl::PlayoutDevices() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1215 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1216 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1217 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1218 | uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1219 | LOG(INFO) << "output: " << nPlayoutDevices; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1220 | return ((int16_t)(nPlayoutDevices)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | // ---------------------------------------------------------------------------- |
| 1224 | // SetPlayoutDevice I (II) |
| 1225 | // ---------------------------------------------------------------------------- |
| 1226 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1227 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1228 | LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1229 | CHECK_INITIALIZED(); |
| 1230 | return (_ptrAudioDevice->SetPlayoutDevice(index)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | // ---------------------------------------------------------------------------- |
| 1234 | // SetPlayoutDevice II (II) |
| 1235 | // ---------------------------------------------------------------------------- |
| 1236 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1237 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1238 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1239 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1240 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1241 | return (_ptrAudioDevice->SetPlayoutDevice(device)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | // ---------------------------------------------------------------------------- |
| 1245 | // PlayoutDeviceName |
| 1246 | // ---------------------------------------------------------------------------- |
| 1247 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1248 | int32_t AudioDeviceModuleImpl::PlayoutDeviceName( |
| 1249 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1250 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1251 | char guid[kAdmMaxGuidSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1252 | LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1253 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1254 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1255 | if (name == NULL) { |
| 1256 | _lastError = kAdmErrArgument; |
| 1257 | return -1; |
| 1258 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1259 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1260 | if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) { |
| 1261 | return -1; |
| 1262 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1263 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1264 | if (name != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1265 | LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1266 | } |
| 1267 | if (guid != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1268 | LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1269 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1270 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1271 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | // ---------------------------------------------------------------------------- |
| 1275 | // RecordingDeviceName |
| 1276 | // ---------------------------------------------------------------------------- |
| 1277 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1278 | int32_t AudioDeviceModuleImpl::RecordingDeviceName( |
| 1279 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1280 | char name[kAdmMaxDeviceNameSize], |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1281 | char guid[kAdmMaxGuidSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1282 | LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1283 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1284 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1285 | if (name == NULL) { |
| 1286 | _lastError = kAdmErrArgument; |
| 1287 | return -1; |
| 1288 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1289 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1290 | if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) { |
| 1291 | return -1; |
| 1292 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1293 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1294 | if (name != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1295 | LOG(INFO) << "output: name = " << name; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1296 | } |
| 1297 | if (guid != NULL) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1298 | LOG(INFO) << "output: guid = " << guid; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1299 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1300 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1301 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | // ---------------------------------------------------------------------------- |
| 1305 | // RecordingDevices |
| 1306 | // ---------------------------------------------------------------------------- |
| 1307 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1308 | int16_t AudioDeviceModuleImpl::RecordingDevices() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1309 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1310 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1311 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1312 | uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1313 | |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1314 | LOG(INFO) << "output: " << nRecordingDevices; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1315 | return ((int16_t)nRecordingDevices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | // ---------------------------------------------------------------------------- |
| 1319 | // SetRecordingDevice I (II) |
| 1320 | // ---------------------------------------------------------------------------- |
| 1321 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1322 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1323 | LOG(INFO) << __FUNCTION__ << "(" << index << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1324 | CHECK_INITIALIZED(); |
| 1325 | return (_ptrAudioDevice->SetRecordingDevice(index)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | // ---------------------------------------------------------------------------- |
| 1329 | // SetRecordingDevice II (II) |
| 1330 | // ---------------------------------------------------------------------------- |
| 1331 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1332 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1333 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1334 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1335 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1336 | return (_ptrAudioDevice->SetRecordingDevice(device)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | // ---------------------------------------------------------------------------- |
| 1340 | // InitPlayout |
| 1341 | // ---------------------------------------------------------------------------- |
| 1342 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1343 | int32_t AudioDeviceModuleImpl::InitPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1344 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1345 | CHECK_INITIALIZED(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 1346 | if (PlayoutIsInitialized()) { |
| 1347 | return 0; |
| 1348 | } |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1349 | int32_t result = _ptrAudioDevice->InitPlayout(); |
| 1350 | LOG(INFO) << "output: " << result; |
| 1351 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess", |
| 1352 | static_cast<int>(result == 0)); |
| 1353 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | // ---------------------------------------------------------------------------- |
| 1357 | // InitRecording |
| 1358 | // ---------------------------------------------------------------------------- |
| 1359 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1360 | int32_t AudioDeviceModuleImpl::InitRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1361 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1362 | CHECK_INITIALIZED(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 1363 | if (RecordingIsInitialized()) { |
| 1364 | return 0; |
| 1365 | } |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1366 | int32_t result = _ptrAudioDevice->InitRecording(); |
| 1367 | LOG(INFO) << "output: " << result; |
| 1368 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess", |
| 1369 | static_cast<int>(result == 0)); |
| 1370 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | // ---------------------------------------------------------------------------- |
| 1374 | // PlayoutIsInitialized |
| 1375 | // ---------------------------------------------------------------------------- |
| 1376 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1377 | bool AudioDeviceModuleImpl::PlayoutIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1378 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1379 | CHECK_INITIALIZED_BOOL(); |
| 1380 | return (_ptrAudioDevice->PlayoutIsInitialized()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | // ---------------------------------------------------------------------------- |
| 1384 | // RecordingIsInitialized |
| 1385 | // ---------------------------------------------------------------------------- |
| 1386 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1387 | bool AudioDeviceModuleImpl::RecordingIsInitialized() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1388 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1389 | CHECK_INITIALIZED_BOOL(); |
| 1390 | return (_ptrAudioDevice->RecordingIsInitialized()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | // ---------------------------------------------------------------------------- |
| 1394 | // StartPlayout |
| 1395 | // ---------------------------------------------------------------------------- |
| 1396 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1397 | int32_t AudioDeviceModuleImpl::StartPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1398 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1399 | CHECK_INITIALIZED(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 1400 | if (Playing()) { |
| 1401 | return 0; |
| 1402 | } |
henrika | ba156cf | 2016-10-31 08:18:50 -0700 | [diff] [blame] | 1403 | _audioDeviceBuffer.StartPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1404 | int32_t result = _ptrAudioDevice->StartPlayout(); |
| 1405 | LOG(INFO) << "output: " << result; |
| 1406 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess", |
| 1407 | static_cast<int>(result == 0)); |
| 1408 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | // ---------------------------------------------------------------------------- |
| 1412 | // StopPlayout |
| 1413 | // ---------------------------------------------------------------------------- |
| 1414 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1415 | int32_t AudioDeviceModuleImpl::StopPlayout() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1416 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1417 | CHECK_INITIALIZED(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1418 | int32_t result = _ptrAudioDevice->StopPlayout(); |
henrika | ba156cf | 2016-10-31 08:18:50 -0700 | [diff] [blame] | 1419 | _audioDeviceBuffer.StopPlayout(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1420 | LOG(INFO) << "output: " << result; |
| 1421 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess", |
| 1422 | static_cast<int>(result == 0)); |
| 1423 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | // ---------------------------------------------------------------------------- |
| 1427 | // Playing |
| 1428 | // ---------------------------------------------------------------------------- |
| 1429 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1430 | bool AudioDeviceModuleImpl::Playing() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1431 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1432 | CHECK_INITIALIZED_BOOL(); |
| 1433 | return (_ptrAudioDevice->Playing()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | // ---------------------------------------------------------------------------- |
| 1437 | // StartRecording |
| 1438 | // ---------------------------------------------------------------------------- |
| 1439 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1440 | int32_t AudioDeviceModuleImpl::StartRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1441 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1442 | CHECK_INITIALIZED(); |
maxmorin | 8c695b4 | 2016-07-25 02:46:44 -0700 | [diff] [blame] | 1443 | if (Recording()) { |
| 1444 | return 0; |
| 1445 | } |
henrika | ba156cf | 2016-10-31 08:18:50 -0700 | [diff] [blame] | 1446 | _audioDeviceBuffer.StartRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1447 | int32_t result = _ptrAudioDevice->StartRecording(); |
| 1448 | LOG(INFO) << "output: " << result; |
| 1449 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess", |
| 1450 | static_cast<int>(result == 0)); |
| 1451 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1452 | } |
| 1453 | // ---------------------------------------------------------------------------- |
| 1454 | // StopRecording |
| 1455 | // ---------------------------------------------------------------------------- |
| 1456 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1457 | int32_t AudioDeviceModuleImpl::StopRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1458 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1459 | CHECK_INITIALIZED(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1460 | int32_t result = _ptrAudioDevice->StopRecording(); |
henrika | ba156cf | 2016-10-31 08:18:50 -0700 | [diff] [blame] | 1461 | _audioDeviceBuffer.StopRecording(); |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 1462 | LOG(INFO) << "output: " << result; |
| 1463 | RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess", |
| 1464 | static_cast<int>(result == 0)); |
| 1465 | return result; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | // ---------------------------------------------------------------------------- |
| 1469 | // Recording |
| 1470 | // ---------------------------------------------------------------------------- |
| 1471 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1472 | bool AudioDeviceModuleImpl::Recording() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1473 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1474 | CHECK_INITIALIZED_BOOL(); |
| 1475 | return (_ptrAudioDevice->Recording()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | // ---------------------------------------------------------------------------- |
| 1479 | // RegisterEventObserver |
| 1480 | // ---------------------------------------------------------------------------- |
| 1481 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1482 | int32_t AudioDeviceModuleImpl::RegisterEventObserver( |
| 1483 | AudioDeviceObserver* eventCallback) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1484 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1485 | CriticalSectionScoped lock(&_critSectEventCb); |
| 1486 | _ptrCbAudioDeviceObserver = eventCallback; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1487 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1488 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | // ---------------------------------------------------------------------------- |
| 1492 | // RegisterAudioCallback |
| 1493 | // ---------------------------------------------------------------------------- |
| 1494 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1495 | int32_t AudioDeviceModuleImpl::RegisterAudioCallback( |
| 1496 | AudioTransport* audioCallback) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1497 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1498 | CriticalSectionScoped lock(&_critSectAudioCb); |
henrika | f502222 | 2016-11-07 15:56:59 +0100 | [diff] [blame^] | 1499 | return _audioDeviceBuffer.RegisterAudioCallback(audioCallback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | // ---------------------------------------------------------------------------- |
| 1503 | // StartRawInputFileRecording |
| 1504 | // ---------------------------------------------------------------------------- |
| 1505 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1506 | int32_t AudioDeviceModuleImpl::StartRawInputFileRecording( |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1507 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1508 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1509 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1510 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1511 | if (NULL == pcmFileNameUTF8) { |
| 1512 | return -1; |
| 1513 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1514 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1515 | return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | // ---------------------------------------------------------------------------- |
| 1519 | // StopRawInputFileRecording |
| 1520 | // ---------------------------------------------------------------------------- |
| 1521 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1522 | int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1523 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1524 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1525 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1526 | return (_audioDeviceBuffer.StopInputFileRecording()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | // ---------------------------------------------------------------------------- |
| 1530 | // StartRawOutputFileRecording |
| 1531 | // ---------------------------------------------------------------------------- |
| 1532 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1533 | int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording( |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1534 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1535 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1536 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1537 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1538 | if (NULL == pcmFileNameUTF8) { |
| 1539 | return -1; |
| 1540 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1541 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1542 | return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | // ---------------------------------------------------------------------------- |
| 1546 | // StopRawOutputFileRecording |
| 1547 | // ---------------------------------------------------------------------------- |
| 1548 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1549 | int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1550 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1551 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1552 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1553 | return (_audioDeviceBuffer.StopOutputFileRecording()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | // ---------------------------------------------------------------------------- |
| 1557 | // SetPlayoutBuffer |
| 1558 | // ---------------------------------------------------------------------------- |
| 1559 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1560 | int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, |
| 1561 | uint16_t sizeMS) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1562 | if (type == kFixedBufferSize) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1563 | LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)"; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1564 | } else if (type == kAdaptiveBufferSize) { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1565 | LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)"; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1566 | } else { |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1567 | LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)"; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1568 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1569 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1570 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1571 | if (_ptrAudioDevice->PlayoutIsInitialized()) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1572 | LOG(LERROR) << "unable to modify the playout buffer while playing side is " |
| 1573 | "initialized"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1574 | return -1; |
| 1575 | } |
| 1576 | |
| 1577 | int32_t ret(0); |
| 1578 | |
| 1579 | if (kFixedBufferSize == type) { |
| 1580 | if (sizeMS < kAdmMinPlayoutBufferSizeMs || |
| 1581 | sizeMS > kAdmMaxPlayoutBufferSizeMs) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1582 | LOG(LERROR) << "size parameter is out of range"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1583 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1584 | } |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1585 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1586 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1587 | if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1588 | LOG(LERROR) << "failed to set the playout buffer (error: " << LastError() |
| 1589 | << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1590 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1591 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1592 | return ret; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | // ---------------------------------------------------------------------------- |
| 1596 | // PlayoutBuffer |
| 1597 | // ---------------------------------------------------------------------------- |
| 1598 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1599 | int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, |
| 1600 | uint16_t* sizeMS) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1601 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1602 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1603 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1604 | BufferType bufType; |
| 1605 | uint16_t size(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1606 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1607 | if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1608 | LOG(LERROR) << "failed to retrieve the buffer type and size"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1609 | return -1; |
| 1610 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1611 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1612 | *type = bufType; |
| 1613 | *sizeMS = size; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1614 | |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1615 | LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1616 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | // ---------------------------------------------------------------------------- |
| 1620 | // PlayoutDelay |
| 1621 | // ---------------------------------------------------------------------------- |
| 1622 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1623 | int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const { |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1624 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1625 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1626 | uint16_t delay(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1627 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1628 | if (_ptrAudioDevice->PlayoutDelay(delay) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1629 | LOG(LERROR) << "failed to retrieve the playout delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1630 | return -1; |
| 1631 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1632 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1633 | *delayMS = delay; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1634 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | // ---------------------------------------------------------------------------- |
| 1638 | // RecordingDelay |
| 1639 | // ---------------------------------------------------------------------------- |
| 1640 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1641 | int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1642 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1643 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1644 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1645 | uint16_t delay(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1646 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1647 | if (_ptrAudioDevice->RecordingDelay(delay) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1648 | LOG(LERROR) << "failed to retrieve the recording delay"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1649 | return -1; |
| 1650 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1651 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1652 | *delayMS = delay; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1653 | LOG(INFO) << "output: " << *delayMS; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1654 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | // ---------------------------------------------------------------------------- |
| 1658 | // CPULoad |
| 1659 | // ---------------------------------------------------------------------------- |
| 1660 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1661 | int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1662 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1663 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1664 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1665 | uint16_t cpuLoad(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1666 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1667 | if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1668 | LOG(LERROR) << "failed to retrieve the CPU load"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1669 | return -1; |
| 1670 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1671 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1672 | *load = cpuLoad; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1673 | LOG(INFO) << "output: " << *load; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1674 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | // ---------------------------------------------------------------------------- |
| 1678 | // SetRecordingSampleRate |
| 1679 | // ---------------------------------------------------------------------------- |
| 1680 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1681 | int32_t AudioDeviceModuleImpl::SetRecordingSampleRate( |
| 1682 | const uint32_t samplesPerSec) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1683 | LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1684 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1685 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1686 | if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) { |
| 1687 | return -1; |
| 1688 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1689 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1690 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | // ---------------------------------------------------------------------------- |
| 1694 | // RecordingSampleRate |
| 1695 | // ---------------------------------------------------------------------------- |
| 1696 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1697 | int32_t AudioDeviceModuleImpl::RecordingSampleRate( |
| 1698 | uint32_t* samplesPerSec) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1699 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1700 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1701 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1702 | int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1703 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1704 | if (sampleRate == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1705 | LOG(LERROR) << "failed to retrieve the sample rate"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1706 | return -1; |
| 1707 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1708 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1709 | *samplesPerSec = sampleRate; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1710 | LOG(INFO) << "output: " << *samplesPerSec; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1711 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | // ---------------------------------------------------------------------------- |
| 1715 | // SetPlayoutSampleRate |
| 1716 | // ---------------------------------------------------------------------------- |
| 1717 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1718 | int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate( |
| 1719 | const uint32_t samplesPerSec) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1720 | LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1721 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1722 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1723 | if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) { |
| 1724 | return -1; |
| 1725 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1726 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1727 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | // ---------------------------------------------------------------------------- |
| 1731 | // PlayoutSampleRate |
| 1732 | // ---------------------------------------------------------------------------- |
| 1733 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1734 | int32_t AudioDeviceModuleImpl::PlayoutSampleRate( |
| 1735 | uint32_t* samplesPerSec) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1736 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1737 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1738 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1739 | int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1740 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1741 | if (sampleRate == -1) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1742 | LOG(LERROR) << "failed to retrieve the sample rate"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1743 | return -1; |
| 1744 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1745 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1746 | *samplesPerSec = sampleRate; |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1747 | LOG(INFO) << "output: " << *samplesPerSec; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1748 | return (0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | // ---------------------------------------------------------------------------- |
| 1752 | // ResetAudioDevice |
| 1753 | // ---------------------------------------------------------------------------- |
| 1754 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1755 | int32_t AudioDeviceModuleImpl::ResetAudioDevice() { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1756 | LOG(INFO) << __FUNCTION__; |
henrika | f502222 | 2016-11-07 15:56:59 +0100 | [diff] [blame^] | 1757 | FATAL() << "Should never be called"; |
| 1758 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | // ---------------------------------------------------------------------------- |
| 1762 | // SetLoudspeakerStatus |
| 1763 | // ---------------------------------------------------------------------------- |
| 1764 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1765 | int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1766 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1767 | CHECK_INITIALIZED(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1768 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1769 | if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) { |
| 1770 | return -1; |
| 1771 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1772 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1773 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | // ---------------------------------------------------------------------------- |
| 1777 | // GetLoudspeakerStatus |
| 1778 | // ---------------------------------------------------------------------------- |
| 1779 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1780 | int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1781 | LOG(INFO) << __FUNCTION__; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 1782 | CHECK_INITIALIZED(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1783 | int32_t ok = 0; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1784 | if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1785 | ok = -1; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1786 | } |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1787 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1788 | return ok; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 1791 | bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1792 | LOG(INFO) << __FUNCTION__; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 1793 | CHECK_INITIALIZED_BOOL(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1794 | bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1795 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1796 | return isAvailable; |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1799 | int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1800 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1801 | CHECK_INITIALIZED(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1802 | int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1803 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1804 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1808 | LOG(INFO) << __FUNCTION__; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1809 | CHECK_INITIALIZED_BOOL(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1810 | bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1811 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1812 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1816 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1817 | CHECK_INITIALIZED(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1818 | int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1819 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1820 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1824 | LOG(INFO) << __FUNCTION__; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1825 | CHECK_INITIALIZED_BOOL(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1826 | bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable(); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1827 | LOG(INFO) << "output: " << isAvailable; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1828 | return isAvailable; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1832 | LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1833 | CHECK_INITIALIZED(); |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1834 | int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1835 | LOG(INFO) << "output: " << ok; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1836 | return ok; |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1837 | } |
| 1838 | |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 1839 | #if defined(WEBRTC_IOS) |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1840 | int AudioDeviceModuleImpl::GetPlayoutAudioParameters( |
| 1841 | AudioParameters* params) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1842 | LOG(INFO) << __FUNCTION__; |
| 1843 | int r = _ptrAudioDevice->GetPlayoutAudioParameters(params); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1844 | LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1845 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | int AudioDeviceModuleImpl::GetRecordAudioParameters( |
| 1849 | AudioParameters* params) const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1850 | LOG(INFO) << __FUNCTION__; |
| 1851 | int r = _ptrAudioDevice->GetRecordAudioParameters(params); |
Max Morin | 2c332bb | 2016-07-04 09:03:42 +0200 | [diff] [blame] | 1852 | LOG(INFO) << "output: " << r; |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1853 | return r; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1854 | } |
maxmorin | 88e31a3 | 2016-08-16 00:56:09 -0700 | [diff] [blame] | 1855 | #endif // WEBRTC_IOS |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1856 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1857 | // ============================================================================ |
| 1858 | // Private Methods |
| 1859 | // ============================================================================ |
| 1860 | |
| 1861 | // ---------------------------------------------------------------------------- |
| 1862 | // Platform |
| 1863 | // ---------------------------------------------------------------------------- |
| 1864 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1865 | AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1866 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1867 | return _platformType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | // ---------------------------------------------------------------------------- |
| 1871 | // PlatformAudioLayer |
| 1872 | // ---------------------------------------------------------------------------- |
| 1873 | |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1874 | AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() |
| 1875 | const { |
Max Morin | 098e6c5 | 2016-06-28 09:36:25 +0200 | [diff] [blame] | 1876 | LOG(INFO) << __FUNCTION__; |
Max Morin | 787eeed | 2016-06-23 10:42:07 +0200 | [diff] [blame] | 1877 | return _platformAudioLayer; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | } // namespace webrtc |