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