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