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