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