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