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