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