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" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/include/ref_count.h" |
| 15 | #include "webrtc/system_wrappers/include/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" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 51 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 52 | #include "webrtc/system_wrappers/include/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 | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame^] | 430 | void 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 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // ============================================================================ |
| 485 | // Public API |
| 486 | // ============================================================================ |
| 487 | |
| 488 | // ---------------------------------------------------------------------------- |
| 489 | // ActiveAudioLayer |
| 490 | // ---------------------------------------------------------------------------- |
| 491 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 492 | int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const { |
| 493 | AudioLayer activeAudio; |
| 494 | if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) { |
| 495 | return -1; |
| 496 | } |
| 497 | *audioLayer = activeAudio; |
| 498 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | // ---------------------------------------------------------------------------- |
| 502 | // LastError |
| 503 | // ---------------------------------------------------------------------------- |
| 504 | |
| 505 | AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const |
| 506 | { |
| 507 | return _lastError; |
| 508 | } |
| 509 | |
| 510 | // ---------------------------------------------------------------------------- |
| 511 | // Init |
| 512 | // ---------------------------------------------------------------------------- |
| 513 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 514 | int32_t AudioDeviceModuleImpl::Init() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 515 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 516 | |
| 517 | if (_initialized) |
| 518 | return 0; |
| 519 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 520 | if (!_ptrAudioDevice) |
| 521 | return -1; |
| 522 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 523 | if (_ptrAudioDevice->Init() == -1) |
| 524 | { |
| 525 | return -1; |
| 526 | } |
| 527 | |
| 528 | _initialized = true; |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | // ---------------------------------------------------------------------------- |
| 533 | // Terminate |
| 534 | // ---------------------------------------------------------------------------- |
| 535 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 536 | int32_t AudioDeviceModuleImpl::Terminate() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 537 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 538 | |
| 539 | if (!_initialized) |
| 540 | return 0; |
| 541 | |
| 542 | if (_ptrAudioDevice->Terminate() == -1) |
| 543 | { |
| 544 | return -1; |
| 545 | } |
| 546 | |
| 547 | _initialized = false; |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | // ---------------------------------------------------------------------------- |
| 552 | // Initialized |
| 553 | // ---------------------------------------------------------------------------- |
| 554 | |
| 555 | bool AudioDeviceModuleImpl::Initialized() const |
| 556 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 557 | |
| 558 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized); |
| 559 | return (_initialized); |
| 560 | } |
| 561 | |
| 562 | // ---------------------------------------------------------------------------- |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 563 | // InitSpeaker |
| 564 | // ---------------------------------------------------------------------------- |
| 565 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 566 | int32_t AudioDeviceModuleImpl::InitSpeaker() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 567 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 568 | CHECK_INITIALIZED(); |
| 569 | return (_ptrAudioDevice->InitSpeaker()); |
| 570 | } |
| 571 | |
| 572 | // ---------------------------------------------------------------------------- |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 573 | // InitMicrophone |
| 574 | // ---------------------------------------------------------------------------- |
| 575 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 576 | int32_t AudioDeviceModuleImpl::InitMicrophone() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 577 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 578 | CHECK_INITIALIZED(); |
| 579 | return (_ptrAudioDevice->InitMicrophone()); |
| 580 | } |
| 581 | |
| 582 | // ---------------------------------------------------------------------------- |
| 583 | // SpeakerVolumeIsAvailable |
| 584 | // ---------------------------------------------------------------------------- |
| 585 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 586 | int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 587 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 588 | CHECK_INITIALIZED(); |
| 589 | |
| 590 | bool isAvailable(0); |
| 591 | |
| 592 | if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) |
| 593 | { |
| 594 | return -1; |
| 595 | } |
| 596 | |
| 597 | *available = isAvailable; |
| 598 | |
| 599 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 600 | return (0); |
| 601 | } |
| 602 | |
| 603 | // ---------------------------------------------------------------------------- |
| 604 | // SetSpeakerVolume |
| 605 | // ---------------------------------------------------------------------------- |
| 606 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 607 | int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 608 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 609 | CHECK_INITIALIZED(); |
| 610 | return (_ptrAudioDevice->SetSpeakerVolume(volume)); |
| 611 | } |
| 612 | |
| 613 | // ---------------------------------------------------------------------------- |
| 614 | // SpeakerVolume |
| 615 | // ---------------------------------------------------------------------------- |
| 616 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 617 | int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 618 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 619 | CHECK_INITIALIZED(); |
| 620 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 621 | uint32_t level(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 622 | |
| 623 | if (_ptrAudioDevice->SpeakerVolume(level) == -1) |
| 624 | { |
| 625 | return -1; |
| 626 | } |
| 627 | |
| 628 | *volume = level; |
| 629 | |
| 630 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume); |
| 631 | return (0); |
| 632 | } |
| 633 | |
| 634 | // ---------------------------------------------------------------------------- |
| 635 | // SetWaveOutVolume |
| 636 | // ---------------------------------------------------------------------------- |
| 637 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 638 | int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 639 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 640 | CHECK_INITIALIZED(); |
| 641 | return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight)); |
| 642 | } |
| 643 | |
| 644 | // ---------------------------------------------------------------------------- |
| 645 | // WaveOutVolume |
| 646 | // ---------------------------------------------------------------------------- |
| 647 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 648 | int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 649 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 650 | CHECK_INITIALIZED(); |
| 651 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 652 | uint16_t volLeft(0); |
| 653 | uint16_t volRight(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 654 | |
| 655 | if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) |
| 656 | { |
| 657 | return -1; |
| 658 | } |
| 659 | |
| 660 | *volumeLeft = volLeft; |
| 661 | *volumeRight = volRight; |
| 662 | |
| 663 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u", |
| 664 | *volumeLeft, *volumeRight); |
| 665 | |
| 666 | return (0); |
| 667 | } |
| 668 | |
| 669 | // ---------------------------------------------------------------------------- |
| 670 | // SpeakerIsInitialized |
| 671 | // ---------------------------------------------------------------------------- |
| 672 | |
| 673 | bool AudioDeviceModuleImpl::SpeakerIsInitialized() const |
| 674 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 675 | CHECK_INITIALIZED_BOOL(); |
| 676 | |
| 677 | bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized(); |
| 678 | |
| 679 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized); |
| 680 | return (isInitialized); |
| 681 | } |
| 682 | |
| 683 | // ---------------------------------------------------------------------------- |
| 684 | // MicrophoneIsInitialized |
| 685 | // ---------------------------------------------------------------------------- |
| 686 | |
| 687 | bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const |
| 688 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 689 | CHECK_INITIALIZED_BOOL(); |
| 690 | |
| 691 | bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized(); |
| 692 | |
| 693 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized); |
| 694 | return (isInitialized); |
| 695 | } |
| 696 | |
| 697 | // ---------------------------------------------------------------------------- |
| 698 | // MaxSpeakerVolume |
| 699 | // ---------------------------------------------------------------------------- |
| 700 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 701 | int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 702 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 703 | CHECK_INITIALIZED(); |
| 704 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 705 | uint32_t maxVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 706 | |
| 707 | if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) |
| 708 | { |
| 709 | return -1; |
| 710 | } |
| 711 | |
| 712 | *maxVolume = maxVol; |
| 713 | |
| 714 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume); |
| 715 | return (0); |
| 716 | } |
| 717 | |
| 718 | // ---------------------------------------------------------------------------- |
| 719 | // MinSpeakerVolume |
| 720 | // ---------------------------------------------------------------------------- |
| 721 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 722 | int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 723 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 724 | CHECK_INITIALIZED(); |
| 725 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 726 | uint32_t minVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 727 | |
| 728 | if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) |
| 729 | { |
| 730 | return -1; |
| 731 | } |
| 732 | |
| 733 | *minVolume = minVol; |
| 734 | |
| 735 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume); |
| 736 | return (0); |
| 737 | } |
| 738 | |
| 739 | // ---------------------------------------------------------------------------- |
| 740 | // SpeakerVolumeStepSize |
| 741 | // ---------------------------------------------------------------------------- |
| 742 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 743 | int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 744 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 745 | CHECK_INITIALIZED(); |
| 746 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 747 | uint16_t delta(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 748 | |
| 749 | if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) |
| 750 | { |
| 751 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size"); |
| 752 | return -1; |
| 753 | } |
| 754 | |
| 755 | *stepSize = delta; |
| 756 | |
| 757 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize); |
| 758 | return (0); |
| 759 | } |
| 760 | |
| 761 | // ---------------------------------------------------------------------------- |
| 762 | // SpeakerMuteIsAvailable |
| 763 | // ---------------------------------------------------------------------------- |
| 764 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 765 | int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 766 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 767 | CHECK_INITIALIZED(); |
| 768 | |
| 769 | bool isAvailable(0); |
| 770 | |
| 771 | if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) |
| 772 | { |
| 773 | return -1; |
| 774 | } |
| 775 | |
| 776 | *available = isAvailable; |
| 777 | |
| 778 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 779 | return (0); |
| 780 | } |
| 781 | |
| 782 | // ---------------------------------------------------------------------------- |
| 783 | // SetSpeakerMute |
| 784 | // ---------------------------------------------------------------------------- |
| 785 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 786 | int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 787 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 788 | CHECK_INITIALIZED(); |
| 789 | return (_ptrAudioDevice->SetSpeakerMute(enable)); |
| 790 | } |
| 791 | |
| 792 | // ---------------------------------------------------------------------------- |
| 793 | // SpeakerMute |
| 794 | // ---------------------------------------------------------------------------- |
| 795 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 796 | int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 797 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 798 | CHECK_INITIALIZED(); |
| 799 | |
| 800 | bool muted(false); |
| 801 | |
| 802 | if (_ptrAudioDevice->SpeakerMute(muted) == -1) |
| 803 | { |
| 804 | return -1; |
| 805 | } |
| 806 | |
| 807 | *enabled = muted; |
| 808 | |
| 809 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled); |
| 810 | return (0); |
| 811 | } |
| 812 | |
| 813 | // ---------------------------------------------------------------------------- |
| 814 | // MicrophoneMuteIsAvailable |
| 815 | // ---------------------------------------------------------------------------- |
| 816 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 817 | int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 818 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 819 | CHECK_INITIALIZED(); |
| 820 | |
| 821 | bool isAvailable(0); |
| 822 | |
| 823 | if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) |
| 824 | { |
| 825 | return -1; |
| 826 | } |
| 827 | |
| 828 | *available = isAvailable; |
| 829 | |
| 830 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 831 | return (0); |
| 832 | } |
| 833 | |
| 834 | // ---------------------------------------------------------------------------- |
| 835 | // SetMicrophoneMute |
| 836 | // ---------------------------------------------------------------------------- |
| 837 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 838 | int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 839 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 840 | CHECK_INITIALIZED(); |
| 841 | return (_ptrAudioDevice->SetMicrophoneMute(enable)); |
| 842 | } |
| 843 | |
| 844 | // ---------------------------------------------------------------------------- |
| 845 | // MicrophoneMute |
| 846 | // ---------------------------------------------------------------------------- |
| 847 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 848 | int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 849 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 850 | CHECK_INITIALIZED(); |
| 851 | |
| 852 | bool muted(false); |
| 853 | |
| 854 | if (_ptrAudioDevice->MicrophoneMute(muted) == -1) |
| 855 | { |
| 856 | return -1; |
| 857 | } |
| 858 | |
| 859 | *enabled = muted; |
| 860 | |
| 861 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled); |
| 862 | return (0); |
| 863 | } |
| 864 | |
| 865 | // ---------------------------------------------------------------------------- |
| 866 | // MicrophoneBoostIsAvailable |
| 867 | // ---------------------------------------------------------------------------- |
| 868 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 869 | int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 870 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 871 | CHECK_INITIALIZED(); |
| 872 | |
| 873 | bool isAvailable(0); |
| 874 | |
| 875 | if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) |
| 876 | { |
| 877 | return -1; |
| 878 | } |
| 879 | |
| 880 | *available = isAvailable; |
| 881 | |
| 882 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 883 | return (0); |
| 884 | } |
| 885 | |
| 886 | // ---------------------------------------------------------------------------- |
| 887 | // SetMicrophoneBoost |
| 888 | // ---------------------------------------------------------------------------- |
| 889 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 890 | int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 891 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 892 | CHECK_INITIALIZED(); |
| 893 | return (_ptrAudioDevice->SetMicrophoneBoost(enable)); |
| 894 | } |
| 895 | |
| 896 | // ---------------------------------------------------------------------------- |
| 897 | // MicrophoneBoost |
| 898 | // ---------------------------------------------------------------------------- |
| 899 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 900 | int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 901 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 902 | CHECK_INITIALIZED(); |
| 903 | |
| 904 | bool onOff(false); |
| 905 | |
| 906 | if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) |
| 907 | { |
| 908 | return -1; |
| 909 | } |
| 910 | |
| 911 | *enabled = onOff; |
| 912 | |
| 913 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled); |
| 914 | return (0); |
| 915 | } |
| 916 | |
| 917 | // ---------------------------------------------------------------------------- |
| 918 | // MicrophoneVolumeIsAvailable |
| 919 | // ---------------------------------------------------------------------------- |
| 920 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 921 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 922 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 923 | CHECK_INITIALIZED(); |
| 924 | |
| 925 | bool isAvailable(0); |
| 926 | |
| 927 | if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) |
| 928 | { |
| 929 | return -1; |
| 930 | } |
| 931 | |
| 932 | *available = isAvailable; |
| 933 | |
| 934 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 935 | return (0); |
| 936 | } |
| 937 | |
| 938 | // ---------------------------------------------------------------------------- |
| 939 | // SetMicrophoneVolume |
| 940 | // ---------------------------------------------------------------------------- |
| 941 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 942 | int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 943 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 944 | CHECK_INITIALIZED(); |
| 945 | return (_ptrAudioDevice->SetMicrophoneVolume(volume)); |
| 946 | } |
| 947 | |
| 948 | // ---------------------------------------------------------------------------- |
| 949 | // MicrophoneVolume |
| 950 | // ---------------------------------------------------------------------------- |
| 951 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 952 | int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 953 | { |
| 954 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 955 | CHECK_INITIALIZED(); |
| 956 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 957 | uint32_t level(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 958 | |
| 959 | if (_ptrAudioDevice->MicrophoneVolume(level) == -1) |
| 960 | { |
| 961 | return -1; |
| 962 | } |
| 963 | |
| 964 | *volume = level; |
| 965 | |
| 966 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume); |
| 967 | return (0); |
| 968 | } |
| 969 | |
| 970 | // ---------------------------------------------------------------------------- |
| 971 | // StereoRecordingIsAvailable |
| 972 | // ---------------------------------------------------------------------------- |
| 973 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 974 | int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 975 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 976 | CHECK_INITIALIZED(); |
| 977 | |
| 978 | bool isAvailable(0); |
| 979 | |
| 980 | if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) |
| 981 | { |
| 982 | return -1; |
| 983 | } |
| 984 | |
| 985 | *available = isAvailable; |
| 986 | |
| 987 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 988 | return (0); |
| 989 | } |
| 990 | |
| 991 | // ---------------------------------------------------------------------------- |
| 992 | // SetStereoRecording |
| 993 | // ---------------------------------------------------------------------------- |
| 994 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 995 | int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 996 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 997 | CHECK_INITIALIZED(); |
| 998 | |
| 999 | if (_ptrAudioDevice->RecordingIsInitialized()) |
| 1000 | { |
| 1001 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported"); |
| 1002 | return -1; |
| 1003 | } |
| 1004 | |
| 1005 | if (_ptrAudioDevice->SetStereoRecording(enable) == -1) |
| 1006 | { |
| 1007 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording"); |
| 1008 | return -1; |
| 1009 | } |
| 1010 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1011 | int8_t nChannels(1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1012 | if (enable) |
| 1013 | { |
| 1014 | nChannels = 2; |
| 1015 | } |
| 1016 | _audioDeviceBuffer.SetRecordingChannels(nChannels); |
| 1017 | |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
| 1021 | // ---------------------------------------------------------------------------- |
| 1022 | // StereoRecording |
| 1023 | // ---------------------------------------------------------------------------- |
| 1024 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1025 | int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1026 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1027 | CHECK_INITIALIZED(); |
| 1028 | |
| 1029 | bool stereo(false); |
| 1030 | |
| 1031 | if (_ptrAudioDevice->StereoRecording(stereo) == -1) |
| 1032 | { |
| 1033 | return -1; |
| 1034 | } |
| 1035 | |
| 1036 | *enabled = stereo; |
| 1037 | |
| 1038 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled); |
| 1039 | return (0); |
| 1040 | } |
| 1041 | |
| 1042 | // ---------------------------------------------------------------------------- |
| 1043 | // SetRecordingChannel |
| 1044 | // ---------------------------------------------------------------------------- |
| 1045 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1046 | int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1047 | { |
| 1048 | if (channel == kChannelBoth) |
| 1049 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1050 | } |
| 1051 | else if (channel == kChannelLeft) |
| 1052 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1053 | } |
| 1054 | else |
| 1055 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1056 | } |
| 1057 | CHECK_INITIALIZED(); |
| 1058 | |
| 1059 | bool stereo(false); |
| 1060 | |
| 1061 | if (_ptrAudioDevice->StereoRecording(stereo) == -1) |
| 1062 | { |
| 1063 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported"); |
| 1064 | return -1; |
| 1065 | } |
| 1066 | |
| 1067 | return (_audioDeviceBuffer.SetRecordingChannel(channel)); |
| 1068 | } |
| 1069 | |
| 1070 | // ---------------------------------------------------------------------------- |
| 1071 | // RecordingChannel |
| 1072 | // ---------------------------------------------------------------------------- |
| 1073 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1074 | int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1075 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1076 | CHECK_INITIALIZED(); |
| 1077 | |
| 1078 | ChannelType chType; |
| 1079 | |
| 1080 | if (_audioDeviceBuffer.RecordingChannel(chType) == -1) |
| 1081 | { |
| 1082 | return -1; |
| 1083 | } |
| 1084 | |
| 1085 | *channel = chType; |
| 1086 | |
| 1087 | if (*channel == kChannelBoth) |
| 1088 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1089 | } |
| 1090 | else if (*channel == kChannelLeft) |
| 1091 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1092 | } |
| 1093 | else |
| 1094 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | return (0); |
| 1098 | } |
| 1099 | |
| 1100 | // ---------------------------------------------------------------------------- |
| 1101 | // StereoPlayoutIsAvailable |
| 1102 | // ---------------------------------------------------------------------------- |
| 1103 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1104 | int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1105 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1106 | CHECK_INITIALIZED(); |
| 1107 | |
| 1108 | bool isAvailable(0); |
| 1109 | |
| 1110 | if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) |
| 1111 | { |
| 1112 | return -1; |
| 1113 | } |
| 1114 | |
| 1115 | *available = isAvailable; |
| 1116 | |
| 1117 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 1118 | return (0); |
| 1119 | } |
| 1120 | |
| 1121 | // ---------------------------------------------------------------------------- |
| 1122 | // SetStereoPlayout |
| 1123 | // ---------------------------------------------------------------------------- |
| 1124 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1125 | int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1126 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1127 | CHECK_INITIALIZED(); |
| 1128 | |
| 1129 | if (_ptrAudioDevice->PlayoutIsInitialized()) |
| 1130 | { |
| 1131 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized"); |
| 1132 | return -1; |
| 1133 | } |
| 1134 | |
| 1135 | if (_ptrAudioDevice->SetStereoPlayout(enable)) |
| 1136 | { |
| 1137 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported"); |
| 1138 | return -1; |
| 1139 | } |
| 1140 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1141 | int8_t nChannels(1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1142 | if (enable) |
| 1143 | { |
| 1144 | nChannels = 2; |
| 1145 | } |
| 1146 | _audioDeviceBuffer.SetPlayoutChannels(nChannels); |
| 1147 | |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | // ---------------------------------------------------------------------------- |
| 1152 | // StereoPlayout |
| 1153 | // ---------------------------------------------------------------------------- |
| 1154 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1155 | int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1156 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1157 | CHECK_INITIALIZED(); |
| 1158 | |
| 1159 | bool stereo(false); |
| 1160 | |
| 1161 | if (_ptrAudioDevice->StereoPlayout(stereo) == -1) |
| 1162 | { |
| 1163 | return -1; |
| 1164 | } |
| 1165 | |
| 1166 | *enabled = stereo; |
| 1167 | |
| 1168 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled); |
| 1169 | return (0); |
| 1170 | } |
| 1171 | |
| 1172 | // ---------------------------------------------------------------------------- |
| 1173 | // SetAGC |
| 1174 | // ---------------------------------------------------------------------------- |
| 1175 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1176 | int32_t AudioDeviceModuleImpl::SetAGC(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1177 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1178 | CHECK_INITIALIZED(); |
| 1179 | return (_ptrAudioDevice->SetAGC(enable)); |
| 1180 | } |
| 1181 | |
| 1182 | // ---------------------------------------------------------------------------- |
| 1183 | // AGC |
| 1184 | // ---------------------------------------------------------------------------- |
| 1185 | |
| 1186 | bool AudioDeviceModuleImpl::AGC() const |
| 1187 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1188 | CHECK_INITIALIZED_BOOL(); |
| 1189 | return (_ptrAudioDevice->AGC()); |
| 1190 | } |
| 1191 | |
| 1192 | // ---------------------------------------------------------------------------- |
| 1193 | // PlayoutIsAvailable |
| 1194 | // ---------------------------------------------------------------------------- |
| 1195 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1196 | int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1197 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1198 | CHECK_INITIALIZED(); |
| 1199 | |
| 1200 | bool isAvailable(0); |
| 1201 | |
| 1202 | if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) |
| 1203 | { |
| 1204 | return -1; |
| 1205 | } |
| 1206 | |
| 1207 | *available = isAvailable; |
| 1208 | |
| 1209 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 1210 | return (0); |
| 1211 | } |
| 1212 | |
| 1213 | // ---------------------------------------------------------------------------- |
| 1214 | // RecordingIsAvailable |
| 1215 | // ---------------------------------------------------------------------------- |
| 1216 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1217 | int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1218 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1219 | CHECK_INITIALIZED(); |
| 1220 | |
| 1221 | bool isAvailable(0); |
| 1222 | |
| 1223 | if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) |
| 1224 | { |
| 1225 | return -1; |
| 1226 | } |
| 1227 | |
| 1228 | *available = isAvailable; |
| 1229 | |
| 1230 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available); |
| 1231 | return (0); |
| 1232 | } |
| 1233 | |
| 1234 | // ---------------------------------------------------------------------------- |
| 1235 | // MaxMicrophoneVolume |
| 1236 | // ---------------------------------------------------------------------------- |
| 1237 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1238 | int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1239 | { |
| 1240 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 1241 | CHECK_INITIALIZED(); |
| 1242 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1243 | uint32_t maxVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1244 | |
| 1245 | if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) |
| 1246 | { |
| 1247 | return -1; |
| 1248 | } |
| 1249 | |
| 1250 | *maxVolume = maxVol; |
| 1251 | |
| 1252 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume); |
| 1253 | return (0); |
| 1254 | } |
| 1255 | |
| 1256 | // ---------------------------------------------------------------------------- |
| 1257 | // MinMicrophoneVolume |
| 1258 | // ---------------------------------------------------------------------------- |
| 1259 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1260 | int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1261 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1262 | CHECK_INITIALIZED(); |
| 1263 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1264 | uint32_t minVol(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1265 | |
| 1266 | if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) |
| 1267 | { |
| 1268 | return -1; |
| 1269 | } |
| 1270 | |
| 1271 | *minVolume = minVol; |
| 1272 | |
| 1273 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume); |
| 1274 | return (0); |
| 1275 | } |
| 1276 | |
| 1277 | // ---------------------------------------------------------------------------- |
| 1278 | // MicrophoneVolumeStepSize |
| 1279 | // ---------------------------------------------------------------------------- |
| 1280 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1281 | int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1282 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1283 | CHECK_INITIALIZED(); |
| 1284 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1285 | uint16_t delta(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1286 | |
| 1287 | if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) |
| 1288 | { |
| 1289 | return -1; |
| 1290 | } |
| 1291 | |
| 1292 | *stepSize = delta; |
| 1293 | |
| 1294 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize); |
| 1295 | return (0); |
| 1296 | } |
| 1297 | |
| 1298 | // ---------------------------------------------------------------------------- |
| 1299 | // PlayoutDevices |
| 1300 | // ---------------------------------------------------------------------------- |
| 1301 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1302 | int16_t AudioDeviceModuleImpl::PlayoutDevices() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1303 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1304 | CHECK_INITIALIZED(); |
| 1305 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1306 | uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1307 | |
| 1308 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices); |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1309 | return ((int16_t)(nPlayoutDevices)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | // ---------------------------------------------------------------------------- |
| 1313 | // SetPlayoutDevice I (II) |
| 1314 | // ---------------------------------------------------------------------------- |
| 1315 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1316 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1317 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1318 | CHECK_INITIALIZED(); |
| 1319 | return (_ptrAudioDevice->SetPlayoutDevice(index)); |
| 1320 | } |
| 1321 | |
| 1322 | // ---------------------------------------------------------------------------- |
| 1323 | // SetPlayoutDevice II (II) |
| 1324 | // ---------------------------------------------------------------------------- |
| 1325 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1326 | int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1327 | { |
| 1328 | if (device == kDefaultDevice) |
| 1329 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1330 | } |
| 1331 | else |
| 1332 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1333 | } |
| 1334 | CHECK_INITIALIZED(); |
| 1335 | |
| 1336 | return (_ptrAudioDevice->SetPlayoutDevice(device)); |
| 1337 | } |
| 1338 | |
| 1339 | // ---------------------------------------------------------------------------- |
| 1340 | // PlayoutDeviceName |
| 1341 | // ---------------------------------------------------------------------------- |
| 1342 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1343 | int32_t AudioDeviceModuleImpl::PlayoutDeviceName( |
| 1344 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1345 | char name[kAdmMaxDeviceNameSize], |
| 1346 | char guid[kAdmMaxGuidSize]) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1347 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1348 | CHECK_INITIALIZED(); |
| 1349 | |
| 1350 | if (name == NULL) |
| 1351 | { |
| 1352 | _lastError = kAdmErrArgument; |
| 1353 | return -1; |
| 1354 | } |
| 1355 | |
| 1356 | if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) |
| 1357 | { |
| 1358 | return -1; |
| 1359 | } |
| 1360 | |
| 1361 | if (name != NULL) |
| 1362 | { |
| 1363 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name); |
| 1364 | } |
| 1365 | if (guid != NULL) |
| 1366 | { |
| 1367 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid); |
| 1368 | } |
| 1369 | |
| 1370 | return (0); |
| 1371 | } |
| 1372 | |
| 1373 | // ---------------------------------------------------------------------------- |
| 1374 | // RecordingDeviceName |
| 1375 | // ---------------------------------------------------------------------------- |
| 1376 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1377 | int32_t AudioDeviceModuleImpl::RecordingDeviceName( |
| 1378 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1379 | char name[kAdmMaxDeviceNameSize], |
| 1380 | char guid[kAdmMaxGuidSize]) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1381 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1382 | CHECK_INITIALIZED(); |
| 1383 | |
| 1384 | if (name == NULL) |
| 1385 | { |
| 1386 | _lastError = kAdmErrArgument; |
| 1387 | return -1; |
| 1388 | } |
| 1389 | |
| 1390 | if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) |
| 1391 | { |
| 1392 | return -1; |
| 1393 | } |
| 1394 | |
| 1395 | if (name != NULL) |
| 1396 | { |
| 1397 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name); |
| 1398 | } |
| 1399 | if (guid != NULL) |
| 1400 | { |
| 1401 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid); |
| 1402 | } |
| 1403 | |
| 1404 | return (0); |
| 1405 | } |
| 1406 | |
| 1407 | // ---------------------------------------------------------------------------- |
| 1408 | // RecordingDevices |
| 1409 | // ---------------------------------------------------------------------------- |
| 1410 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1411 | int16_t AudioDeviceModuleImpl::RecordingDevices() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1412 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1413 | CHECK_INITIALIZED(); |
| 1414 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1415 | uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1416 | |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1417 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, |
| 1418 | "output: #recording devices=%d", nRecordingDevices); |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1419 | return ((int16_t)nRecordingDevices); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | // ---------------------------------------------------------------------------- |
| 1423 | // SetRecordingDevice I (II) |
| 1424 | // ---------------------------------------------------------------------------- |
| 1425 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1426 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1427 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1428 | CHECK_INITIALIZED(); |
| 1429 | return (_ptrAudioDevice->SetRecordingDevice(index)); |
| 1430 | } |
| 1431 | |
| 1432 | // ---------------------------------------------------------------------------- |
| 1433 | // SetRecordingDevice II (II) |
| 1434 | // ---------------------------------------------------------------------------- |
| 1435 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1436 | int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1437 | { |
| 1438 | if (device == kDefaultDevice) |
| 1439 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1440 | } |
| 1441 | else |
| 1442 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1443 | } |
| 1444 | CHECK_INITIALIZED(); |
| 1445 | |
| 1446 | return (_ptrAudioDevice->SetRecordingDevice(device)); |
| 1447 | } |
| 1448 | |
| 1449 | // ---------------------------------------------------------------------------- |
| 1450 | // InitPlayout |
| 1451 | // ---------------------------------------------------------------------------- |
| 1452 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1453 | int32_t AudioDeviceModuleImpl::InitPlayout() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1454 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1455 | CHECK_INITIALIZED(); |
| 1456 | _audioDeviceBuffer.InitPlayout(); |
| 1457 | return (_ptrAudioDevice->InitPlayout()); |
| 1458 | } |
| 1459 | |
| 1460 | // ---------------------------------------------------------------------------- |
| 1461 | // InitRecording |
| 1462 | // ---------------------------------------------------------------------------- |
| 1463 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1464 | int32_t AudioDeviceModuleImpl::InitRecording() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1465 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1466 | CHECK_INITIALIZED(); |
| 1467 | _audioDeviceBuffer.InitRecording(); |
| 1468 | return (_ptrAudioDevice->InitRecording()); |
| 1469 | } |
| 1470 | |
| 1471 | // ---------------------------------------------------------------------------- |
| 1472 | // PlayoutIsInitialized |
| 1473 | // ---------------------------------------------------------------------------- |
| 1474 | |
| 1475 | bool AudioDeviceModuleImpl::PlayoutIsInitialized() const |
| 1476 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1477 | CHECK_INITIALIZED_BOOL(); |
| 1478 | return (_ptrAudioDevice->PlayoutIsInitialized()); |
| 1479 | } |
| 1480 | |
| 1481 | // ---------------------------------------------------------------------------- |
| 1482 | // RecordingIsInitialized |
| 1483 | // ---------------------------------------------------------------------------- |
| 1484 | |
| 1485 | bool AudioDeviceModuleImpl::RecordingIsInitialized() const |
| 1486 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1487 | CHECK_INITIALIZED_BOOL(); |
| 1488 | return (_ptrAudioDevice->RecordingIsInitialized()); |
| 1489 | } |
| 1490 | |
| 1491 | // ---------------------------------------------------------------------------- |
| 1492 | // StartPlayout |
| 1493 | // ---------------------------------------------------------------------------- |
| 1494 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1495 | int32_t AudioDeviceModuleImpl::StartPlayout() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1496 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1497 | CHECK_INITIALIZED(); |
| 1498 | return (_ptrAudioDevice->StartPlayout()); |
| 1499 | } |
| 1500 | |
| 1501 | // ---------------------------------------------------------------------------- |
| 1502 | // StopPlayout |
| 1503 | // ---------------------------------------------------------------------------- |
| 1504 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1505 | int32_t AudioDeviceModuleImpl::StopPlayout() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1506 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1507 | CHECK_INITIALIZED(); |
| 1508 | return (_ptrAudioDevice->StopPlayout()); |
| 1509 | } |
| 1510 | |
| 1511 | // ---------------------------------------------------------------------------- |
| 1512 | // Playing |
| 1513 | // ---------------------------------------------------------------------------- |
| 1514 | |
| 1515 | bool AudioDeviceModuleImpl::Playing() const |
| 1516 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1517 | CHECK_INITIALIZED_BOOL(); |
| 1518 | return (_ptrAudioDevice->Playing()); |
| 1519 | } |
| 1520 | |
| 1521 | // ---------------------------------------------------------------------------- |
| 1522 | // StartRecording |
| 1523 | // ---------------------------------------------------------------------------- |
| 1524 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1525 | int32_t AudioDeviceModuleImpl::StartRecording() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1526 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1527 | CHECK_INITIALIZED(); |
| 1528 | return (_ptrAudioDevice->StartRecording()); |
| 1529 | } |
| 1530 | // ---------------------------------------------------------------------------- |
| 1531 | // StopRecording |
| 1532 | // ---------------------------------------------------------------------------- |
| 1533 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1534 | int32_t AudioDeviceModuleImpl::StopRecording() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1535 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1536 | CHECK_INITIALIZED(); |
| 1537 | return (_ptrAudioDevice->StopRecording()); |
| 1538 | } |
| 1539 | |
| 1540 | // ---------------------------------------------------------------------------- |
| 1541 | // Recording |
| 1542 | // ---------------------------------------------------------------------------- |
| 1543 | |
| 1544 | bool AudioDeviceModuleImpl::Recording() const |
| 1545 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1546 | CHECK_INITIALIZED_BOOL(); |
| 1547 | return (_ptrAudioDevice->Recording()); |
| 1548 | } |
| 1549 | |
| 1550 | // ---------------------------------------------------------------------------- |
| 1551 | // RegisterEventObserver |
| 1552 | // ---------------------------------------------------------------------------- |
| 1553 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1554 | int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1555 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1556 | |
mflodman@webrtc.org | a014ecc | 2012-04-12 12:15:51 +0000 | [diff] [blame] | 1557 | CriticalSectionScoped lock(&_critSectEventCb); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1558 | _ptrCbAudioDeviceObserver = eventCallback; |
| 1559 | |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | // ---------------------------------------------------------------------------- |
| 1564 | // RegisterAudioCallback |
| 1565 | // ---------------------------------------------------------------------------- |
| 1566 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1567 | int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1568 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1569 | |
mflodman@webrtc.org | a014ecc | 2012-04-12 12:15:51 +0000 | [diff] [blame] | 1570 | CriticalSectionScoped lock(&_critSectAudioCb); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1571 | _audioDeviceBuffer.RegisterAudioCallback(audioCallback); |
| 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | // ---------------------------------------------------------------------------- |
| 1577 | // StartRawInputFileRecording |
| 1578 | // ---------------------------------------------------------------------------- |
| 1579 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1580 | int32_t AudioDeviceModuleImpl::StartRawInputFileRecording( |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1581 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1582 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1583 | CHECK_INITIALIZED(); |
| 1584 | |
| 1585 | if (NULL == pcmFileNameUTF8) |
| 1586 | { |
| 1587 | return -1; |
| 1588 | } |
| 1589 | |
| 1590 | return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8)); |
| 1591 | } |
| 1592 | |
| 1593 | // ---------------------------------------------------------------------------- |
| 1594 | // StopRawInputFileRecording |
| 1595 | // ---------------------------------------------------------------------------- |
| 1596 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1597 | int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1598 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1599 | CHECK_INITIALIZED(); |
| 1600 | |
| 1601 | return (_audioDeviceBuffer.StopInputFileRecording()); |
| 1602 | } |
| 1603 | |
| 1604 | // ---------------------------------------------------------------------------- |
| 1605 | // StartRawOutputFileRecording |
| 1606 | // ---------------------------------------------------------------------------- |
| 1607 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1608 | int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording( |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 1609 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1610 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1611 | CHECK_INITIALIZED(); |
| 1612 | |
| 1613 | if (NULL == pcmFileNameUTF8) |
| 1614 | { |
| 1615 | return -1; |
| 1616 | } |
| 1617 | |
| 1618 | return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8)); |
| 1619 | } |
| 1620 | |
| 1621 | // ---------------------------------------------------------------------------- |
| 1622 | // StopRawOutputFileRecording |
| 1623 | // ---------------------------------------------------------------------------- |
| 1624 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1625 | int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1626 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1627 | CHECK_INITIALIZED(); |
| 1628 | |
| 1629 | return (_audioDeviceBuffer.StopOutputFileRecording()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | // ---------------------------------------------------------------------------- |
| 1633 | // SetPlayoutBuffer |
| 1634 | // ---------------------------------------------------------------------------- |
| 1635 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1636 | int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1637 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1638 | CHECK_INITIALIZED(); |
| 1639 | |
| 1640 | if (_ptrAudioDevice->PlayoutIsInitialized()) |
| 1641 | { |
| 1642 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized"); |
| 1643 | return -1; |
| 1644 | } |
| 1645 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1646 | int32_t ret(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1647 | |
| 1648 | if (kFixedBufferSize == type) |
| 1649 | { |
| 1650 | if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs) |
| 1651 | { |
| 1652 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range"); |
| 1653 | return -1; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) |
| 1658 | { |
| 1659 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError()); |
| 1660 | } |
| 1661 | |
| 1662 | return ret; |
| 1663 | } |
| 1664 | |
| 1665 | // ---------------------------------------------------------------------------- |
| 1666 | // PlayoutBuffer |
| 1667 | // ---------------------------------------------------------------------------- |
| 1668 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1669 | int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1670 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1671 | CHECK_INITIALIZED(); |
| 1672 | |
| 1673 | BufferType bufType; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1674 | uint16_t size(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1675 | |
| 1676 | if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) |
| 1677 | { |
| 1678 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size"); |
| 1679 | return -1; |
| 1680 | } |
| 1681 | |
| 1682 | *type = bufType; |
| 1683 | *sizeMS = size; |
| 1684 | |
| 1685 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS); |
| 1686 | return (0); |
| 1687 | } |
| 1688 | |
| 1689 | // ---------------------------------------------------------------------------- |
| 1690 | // PlayoutDelay |
| 1691 | // ---------------------------------------------------------------------------- |
| 1692 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1693 | int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1694 | { |
| 1695 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 1696 | CHECK_INITIALIZED(); |
| 1697 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1698 | uint16_t delay(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1699 | |
| 1700 | if (_ptrAudioDevice->PlayoutDelay(delay) == -1) |
| 1701 | { |
| 1702 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay"); |
| 1703 | return -1; |
| 1704 | } |
| 1705 | |
| 1706 | *delayMS = delay; |
| 1707 | |
| 1708 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS); |
| 1709 | return (0); |
| 1710 | } |
| 1711 | |
| 1712 | // ---------------------------------------------------------------------------- |
| 1713 | // RecordingDelay |
| 1714 | // ---------------------------------------------------------------------------- |
| 1715 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1716 | int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1717 | { |
| 1718 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 1719 | CHECK_INITIALIZED(); |
| 1720 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1721 | uint16_t delay(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1722 | |
| 1723 | if (_ptrAudioDevice->RecordingDelay(delay) == -1) |
| 1724 | { |
| 1725 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay"); |
| 1726 | return -1; |
| 1727 | } |
| 1728 | |
| 1729 | *delayMS = delay; |
| 1730 | |
| 1731 | WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS); |
| 1732 | return (0); |
| 1733 | } |
| 1734 | |
| 1735 | // ---------------------------------------------------------------------------- |
| 1736 | // CPULoad |
| 1737 | // ---------------------------------------------------------------------------- |
| 1738 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1739 | int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1740 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1741 | CHECK_INITIALIZED(); |
| 1742 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1743 | uint16_t cpuLoad(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1744 | |
| 1745 | if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) |
| 1746 | { |
| 1747 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load"); |
| 1748 | return -1; |
| 1749 | } |
| 1750 | |
| 1751 | *load = cpuLoad; |
| 1752 | |
| 1753 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load); |
| 1754 | return (0); |
| 1755 | } |
| 1756 | |
| 1757 | // ---------------------------------------------------------------------------- |
| 1758 | // SetRecordingSampleRate |
| 1759 | // ---------------------------------------------------------------------------- |
| 1760 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1761 | int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1762 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1763 | CHECK_INITIALIZED(); |
| 1764 | |
| 1765 | if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) |
| 1766 | { |
| 1767 | return -1; |
| 1768 | } |
| 1769 | |
| 1770 | return (0); |
| 1771 | } |
| 1772 | |
| 1773 | // ---------------------------------------------------------------------------- |
| 1774 | // RecordingSampleRate |
| 1775 | // ---------------------------------------------------------------------------- |
| 1776 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1777 | int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1778 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1779 | CHECK_INITIALIZED(); |
| 1780 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1781 | int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1782 | |
| 1783 | if (sampleRate == -1) |
| 1784 | { |
| 1785 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate"); |
| 1786 | return -1; |
| 1787 | } |
| 1788 | |
| 1789 | *samplesPerSec = sampleRate; |
| 1790 | |
| 1791 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec); |
| 1792 | return (0); |
| 1793 | } |
| 1794 | |
| 1795 | // ---------------------------------------------------------------------------- |
| 1796 | // SetPlayoutSampleRate |
| 1797 | // ---------------------------------------------------------------------------- |
| 1798 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1799 | int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1800 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1801 | CHECK_INITIALIZED(); |
| 1802 | |
| 1803 | if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) |
| 1804 | { |
| 1805 | return -1; |
| 1806 | } |
| 1807 | |
| 1808 | return (0); |
| 1809 | } |
| 1810 | |
| 1811 | // ---------------------------------------------------------------------------- |
| 1812 | // PlayoutSampleRate |
| 1813 | // ---------------------------------------------------------------------------- |
| 1814 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1815 | int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1816 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1817 | CHECK_INITIALIZED(); |
| 1818 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1819 | int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1820 | |
| 1821 | if (sampleRate == -1) |
| 1822 | { |
| 1823 | WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate"); |
| 1824 | return -1; |
| 1825 | } |
| 1826 | |
| 1827 | *samplesPerSec = sampleRate; |
| 1828 | |
| 1829 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec); |
| 1830 | return (0); |
| 1831 | } |
| 1832 | |
| 1833 | // ---------------------------------------------------------------------------- |
| 1834 | // ResetAudioDevice |
| 1835 | // ---------------------------------------------------------------------------- |
| 1836 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1837 | int32_t AudioDeviceModuleImpl::ResetAudioDevice() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1838 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1839 | CHECK_INITIALIZED(); |
| 1840 | |
| 1841 | |
| 1842 | if (_ptrAudioDevice->ResetAudioDevice() == -1) |
| 1843 | { |
| 1844 | return -1; |
| 1845 | } |
| 1846 | |
| 1847 | return (0); |
| 1848 | } |
| 1849 | |
| 1850 | // ---------------------------------------------------------------------------- |
| 1851 | // SetLoudspeakerStatus |
| 1852 | // ---------------------------------------------------------------------------- |
| 1853 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 1854 | int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1855 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1856 | CHECK_INITIALIZED(); |
| 1857 | |
| 1858 | if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) |
| 1859 | { |
| 1860 | return -1; |
| 1861 | } |
| 1862 | |
| 1863 | return 0; |
| 1864 | } |
| 1865 | |
| 1866 | // ---------------------------------------------------------------------------- |
| 1867 | // GetLoudspeakerStatus |
| 1868 | // ---------------------------------------------------------------------------- |
| 1869 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1870 | int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const { |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 1871 | CHECK_INITIALIZED(); |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1872 | if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) { |
| 1873 | return -1; |
| 1874 | } |
| 1875 | return 0; |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1878 | bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const { |
| 1879 | CHECK_INITIALIZED_BOOL(); |
| 1880 | return _ptrAudioDevice->BuiltInAECIsEnabled(); |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
henrika@webrtc.org | a954c07 | 2014-12-09 16:22:09 +0000 | [diff] [blame] | 1883 | bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const { |
| 1884 | CHECK_INITIALIZED_BOOL(); |
| 1885 | return _ptrAudioDevice->BuiltInAECIsAvailable(); |
| 1886 | } |
| 1887 | |
henrika | c14f5ff | 2015-09-23 14:08:33 +0200 | [diff] [blame] | 1888 | int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) { |
| 1889 | CHECK_INITIALIZED(); |
| 1890 | return _ptrAudioDevice->EnableBuiltInAEC(enable); |
| 1891 | } |
| 1892 | |
| 1893 | bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const { |
| 1894 | CHECK_INITIALIZED_BOOL(); |
| 1895 | return _ptrAudioDevice->BuiltInAGCIsAvailable(); |
| 1896 | } |
| 1897 | |
| 1898 | int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) { |
| 1899 | CHECK_INITIALIZED(); |
| 1900 | return _ptrAudioDevice->EnableBuiltInAGC(enable); |
| 1901 | } |
| 1902 | |
| 1903 | bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const { |
| 1904 | CHECK_INITIALIZED_BOOL(); |
| 1905 | return _ptrAudioDevice->BuiltInNSIsAvailable(); |
| 1906 | } |
| 1907 | |
| 1908 | int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { |
| 1909 | CHECK_INITIALIZED(); |
| 1910 | return _ptrAudioDevice->EnableBuiltInNS(enable); |
| 1911 | } |
| 1912 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 1913 | int AudioDeviceModuleImpl::GetPlayoutAudioParameters( |
| 1914 | AudioParameters* params) const { |
| 1915 | return _ptrAudioDevice->GetPlayoutAudioParameters(params); |
| 1916 | } |
| 1917 | |
| 1918 | int AudioDeviceModuleImpl::GetRecordAudioParameters( |
| 1919 | AudioParameters* params) const { |
| 1920 | return _ptrAudioDevice->GetRecordAudioParameters(params); |
| 1921 | } |
| 1922 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1923 | // ============================================================================ |
| 1924 | // Private Methods |
| 1925 | // ============================================================================ |
| 1926 | |
| 1927 | // ---------------------------------------------------------------------------- |
| 1928 | // Platform |
| 1929 | // ---------------------------------------------------------------------------- |
| 1930 | |
| 1931 | AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const |
| 1932 | { |
| 1933 | return _platformType; |
| 1934 | } |
| 1935 | |
| 1936 | // ---------------------------------------------------------------------------- |
| 1937 | // PlatformAudioLayer |
| 1938 | // ---------------------------------------------------------------------------- |
| 1939 | |
| 1940 | AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const |
| 1941 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1942 | return _platformAudioLayer; |
| 1943 | } |
| 1944 | |
| 1945 | } // namespace webrtc |