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