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