blob: 7c8840a5f9b07ccebb81ea01676f41a7467244d6 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
xians@webrtc.org20aabbb2012-02-20 09:17:41 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Max Morin84cab202016-07-01 13:35:19 +020011#include "webrtc/base/checks.h"
Max Morin098e6c52016-06-28 09:36:25 +020012#include "webrtc/base/logging.h"
Peter Boström1d194412016-03-21 16:44:31 +010013#include "webrtc/base/refcount.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020014#include "webrtc/base/timeutils.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000015#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
16#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020017#include "webrtc/modules/audio_device/audio_device_generic.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000018#include "webrtc/modules/audio_device/audio_device_impl.h"
Max Morin84cab202016-07-01 13:35:19 +020019#include "webrtc/system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000021#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000022#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020025#include "audio_device_wave_win.h"
26#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
27#include "audio_device_core_win.h"
28#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000029#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020030#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020031#include "webrtc/modules/audio_device/android/audio_device_template.h"
32#include "webrtc/modules/audio_device/android/audio_manager.h"
33#include "webrtc/modules/audio_device/android/audio_record_jni.h"
34#include "webrtc/modules/audio_device/android/audio_track_jni.h"
35#include "webrtc/modules/audio_device/android/opensles_player.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020037#if defined(LINUX_ALSA)
38#include "audio_device_alsa_linux.h"
39#endif
Tommi68898a22015-05-19 17:28:07 +020040#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020042#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000043#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020044#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000045#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020046#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000047#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000048
49#if defined(WEBRTC_DUMMY_FILE_DEVICES)
50#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
51#endif
52
pbos@webrtc.org811269d2013-07-11 13:24:38 +000053#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000054#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010055#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000056
Max Morin787eeed2016-06-23 10:42:07 +020057#define CHECK_INITIALIZED() \
58 { \
59 if (!_initialized) { \
60 return -1; \
61 }; \
62 }
niklase@google.com470e71d2011-07-07 08:21:25 +000063
Max Morin787eeed2016-06-23 10:42:07 +020064#define CHECK_INITIALIZED_BOOL() \
65 { \
66 if (!_initialized) { \
67 return false; \
68 }; \
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
Peter Boström1d194412016-03-21 16:44:31 +010071namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000072
niklase@google.com470e71d2011-07-07 08:21:25 +000073// ============================================================================
74// Static methods
75// ============================================================================
76
77// ----------------------------------------------------------------------------
78// AudioDeviceModule::Create()
79// ----------------------------------------------------------------------------
80
Peter Boström4adbbcf2016-05-03 15:51:26 -040081rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010082 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040083 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020084 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020085 // Create the generic ref counted (platform independent) implementation.
86 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
87 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000088
Max Morin787eeed2016-06-23 10:42:07 +020089 // Ensure that the current platform is supported.
90 if (audioDevice->CheckPlatform() == -1) {
91 return nullptr;
92 }
niklase@google.com470e71d2011-07-07 08:21:25 +000093
Max Morin787eeed2016-06-23 10:42:07 +020094 // Create the platform-dependent implementation.
95 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
96 return nullptr;
97 }
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Max Morin787eeed2016-06-23 10:42:07 +020099 // Ensure that the generic audio buffer can communicate with the
100 // platform-specific parts.
101 if (audioDevice->AttachAudioBuffer() == -1) {
102 return nullptr;
103 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
Max Morin787eeed2016-06-23 10:42:07 +0200105 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000106
Max Morin787eeed2016-06-23 10:42:07 +0200107 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
niklase@google.com470e71d2011-07-07 08:21:25 +0000110// ============================================================================
111// Construction & Destruction
112// ============================================================================
113
114// ----------------------------------------------------------------------------
115// AudioDeviceModuleImpl - ctor
116// ----------------------------------------------------------------------------
117
Max Morin787eeed2016-06-23 10:42:07 +0200118AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
119 const AudioLayer audioLayer)
120 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
121 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
122 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
123 _ptrCbAudioDeviceObserver(NULL),
124 _ptrAudioDevice(NULL),
125 _id(id),
126 _platformAudioLayer(audioLayer),
127 _lastProcessTime(rtc::TimeMillis()),
128 _platformType(kPlatformNotSupported),
129 _initialized(false),
130 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200131 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132}
133
134// ----------------------------------------------------------------------------
135// CheckPlatform
136// ----------------------------------------------------------------------------
137
Max Morin787eeed2016-06-23 10:42:07 +0200138int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200139 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
Max Morin787eeed2016-06-23 10:42:07 +0200141 // Ensure that the current platform is supported
142 //
143 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
145#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200146 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200147 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000148#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200149 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200150 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000151#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200152 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200153 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000154#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200155 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200156 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000157#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200158 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200159 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000160#endif
161
Max Morin787eeed2016-06-23 10:42:07 +0200162 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200163 LOG(LERROR) << "current platform is not supported => this module will self "
164 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200165 return -1;
166 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
Max Morin787eeed2016-06-23 10:42:07 +0200168 // Store valid output results
169 //
170 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
Max Morin787eeed2016-06-23 10:42:07 +0200172 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000173}
174
niklase@google.com470e71d2011-07-07 08:21:25 +0000175// ----------------------------------------------------------------------------
176// CreatePlatformSpecificObjects
177// ----------------------------------------------------------------------------
178
Max Morin787eeed2016-06-23 10:42:07 +0200179int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200180 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
Max Morin787eeed2016-06-23 10:42:07 +0200182 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
xians@google.combf5d2ba2011-08-16 07:44:19 +0000184#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200185 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200186 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000187#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200188 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200189 LOG(INFO) << "Will use file-playing dummy device.";
xians@google.combf5d2ba2011-08-16 07:44:19 +0000190#else
Max Morin787eeed2016-06-23 10:42:07 +0200191 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
Max Morin787eeed2016-06-23 10:42:07 +0200193// Create the *Windows* implementation of the Audio Device
194//
niklase@google.com470e71d2011-07-07 08:21:25 +0000195#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200196 if ((audioLayer == kWindowsWaveAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000197#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200198 // Wave audio is default if Core audio is not supported in this build
199 || (audioLayer == kPlatformDefaultAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000200#endif
Max Morin787eeed2016-06-23 10:42:07 +0200201 ) {
202 // create *Windows Wave Audio* implementation
203 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200204 LOG(INFO) << "Windows Wave APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200205 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000206#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200207 if ((audioLayer == kWindowsCoreAudio) ||
208 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200209 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
Max Morin787eeed2016-06-23 10:42:07 +0200211 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
212 // create *Windows Core Audio* implementation
213 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200214 LOG(INFO) << "Windows Core Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200215 } else {
216 // create *Windows Wave Audio* implementation
217 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
218 if (ptrAudioDevice != NULL) {
219 // Core Audio was not supported => revert to Windows Wave instead
220 _platformAudioLayer =
221 kWindowsWaveAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200222 LOG(WARNING) << "Windows Core Audio is *not* supported => Wave APIs "
223 "will be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200224 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000225 }
Max Morin787eeed2016-06-23 10:42:07 +0200226 }
227#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000228#endif // #if defined(_WIN32)
229
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000230#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200231 // Create an Android audio manager.
232 _audioManagerAndroid.reset(new AudioManager());
233 // Select best possible combination of audio layers.
234 if (audioLayer == kPlatformDefaultAudio) {
235 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
236 // Always use OpenSL ES for output on devices that supports the
237 // low-latency output audio path.
238 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200239 } else {
Max Morin787eeed2016-06-23 10:42:07 +0200240 // Use Java-based audio in both directions when low-latency output
241 // is not supported.
242 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000243 }
Max Morin787eeed2016-06-23 10:42:07 +0200244 }
245 AudioManager* audio_manager = _audioManagerAndroid.get();
246 if (audioLayer == kAndroidJavaAudio) {
247 // Java audio for both input and output audio.
248 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
249 audioLayer, audio_manager);
250 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
251 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
252 // This combination provides low-latency output audio and at the same
253 // time support for HW AEC using the AudioRecord Java API.
254 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
255 audioLayer, audio_manager);
256 } else {
257 // Invalid audio layer.
258 ptrAudioDevice = NULL;
259 }
260// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
Max Morin787eeed2016-06-23 10:42:07 +0200262// Create the *Linux* implementation of the Audio Device
263//
niklase@google.com470e71d2011-07-07 08:21:25 +0000264#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200265 if ((audioLayer == kLinuxPulseAudio) ||
266 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000267#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200268 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
Max Morin787eeed2016-06-23 10:42:07 +0200270 // create *Linux PulseAudio* implementation
271 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200272 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200273 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200274 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200275 } else {
276 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000277#endif
278#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200279 // create *Linux ALSA Audio* implementation
280 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
281 if (ptrAudioDevice != NULL) {
282 // Pulse Audio was not supported => revert to ALSA instead
283 _platformAudioLayer =
284 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200285 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
286 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200287 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000288#endif
289#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000290 }
Max Morin787eeed2016-06-23 10:42:07 +0200291#endif
292 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000293#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200294 // create *Linux ALSA Audio* implementation
295 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200296 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000297#endif
Max Morin787eeed2016-06-23 10:42:07 +0200298 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000299#endif // #if defined(WEBRTC_LINUX)
300
Max Morin787eeed2016-06-23 10:42:07 +0200301// Create the *iPhone* implementation of the Audio Device
302//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000303#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200304 if (audioLayer == kPlatformDefaultAudio) {
305 // Create iOS Audio Device implementation.
306 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200307 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200308 }
309// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
Max Morin787eeed2016-06-23 10:42:07 +0200311// Create the *Mac* implementation of the Audio Device
312//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000313#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200314 if (audioLayer == kPlatformDefaultAudio) {
315 // Create *Mac Audio* implementation
316 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200317 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200318 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000319#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
Max Morin787eeed2016-06-23 10:42:07 +0200321 // Create the *Dummy* implementation of the Audio Device
322 // Available for all platforms
323 //
324 if (audioLayer == kDummyAudio) {
325 // Create *Dummy Audio* implementation
326 assert(!ptrAudioDevice);
327 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200328 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200329 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000330#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
Max Morin787eeed2016-06-23 10:42:07 +0200332 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200333 LOG(LERROR)
334 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200335 return -1;
336 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
Max Morin787eeed2016-06-23 10:42:07 +0200338 // Store valid output pointers
339 //
340 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000341
Max Morin787eeed2016-06-23 10:42:07 +0200342 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000343}
344
345// ----------------------------------------------------------------------------
346// AttachAudioBuffer
347//
348// Install "bridge" between the platform implemetation and the generic
349// implementation. The "child" shall set the native sampling rate and the
350// number of channels in this function call.
351// ----------------------------------------------------------------------------
352
Max Morin787eeed2016-06-23 10:42:07 +0200353int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200354 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000355
Max Morin787eeed2016-06-23 10:42:07 +0200356 _audioDeviceBuffer.SetId(_id);
357 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
358 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000359}
360
361// ----------------------------------------------------------------------------
362// ~AudioDeviceModuleImpl - dtor
363// ----------------------------------------------------------------------------
364
Max Morin787eeed2016-06-23 10:42:07 +0200365AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200366 LOG(INFO) << __FUNCTION__;
henrika@google.com73d65512011-09-07 15:11:18 +0000367
Max Morin787eeed2016-06-23 10:42:07 +0200368 if (_ptrAudioDevice) {
369 delete _ptrAudioDevice;
370 _ptrAudioDevice = NULL;
371 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
Max Morin787eeed2016-06-23 10:42:07 +0200373 delete &_critSect;
374 delete &_critSectEventCb;
375 delete &_critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000376}
377
378// ============================================================================
379// Module
380// ============================================================================
381
382// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000383// Module::TimeUntilNextProcess
384//
385// Returns the number of milliseconds until the module want a worker thread
386// to call Process().
387// ----------------------------------------------------------------------------
388
Max Morin787eeed2016-06-23 10:42:07 +0200389int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
Max Morin098e6c52016-06-28 09:36:25 +0200390 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200391 int64_t now = rtc::TimeMillis();
392 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
393 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394}
395
396// ----------------------------------------------------------------------------
397// Module::Process
398//
399// Check for posted error and warning reports. Generate callbacks if
400// new reports exists.
401// ----------------------------------------------------------------------------
402
Max Morin787eeed2016-06-23 10:42:07 +0200403void AudioDeviceModuleImpl::Process() {
Max Morin098e6c52016-06-28 09:36:25 +0200404 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200405 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000406
Max Morin787eeed2016-06-23 10:42:07 +0200407 // kPlayoutWarning
408 if (_ptrAudioDevice->PlayoutWarning()) {
409 CriticalSectionScoped lock(&_critSectEventCb);
410 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200411 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200412 _ptrCbAudioDeviceObserver->OnWarningIsReported(
413 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000414 }
Max Morin787eeed2016-06-23 10:42:07 +0200415 _ptrAudioDevice->ClearPlayoutWarning();
416 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000417
Max Morin787eeed2016-06-23 10:42:07 +0200418 // kPlayoutError
419 if (_ptrAudioDevice->PlayoutError()) {
420 CriticalSectionScoped lock(&_critSectEventCb);
421 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200422 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200423 _ptrCbAudioDeviceObserver->OnErrorIsReported(
424 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000425 }
Max Morin787eeed2016-06-23 10:42:07 +0200426 _ptrAudioDevice->ClearPlayoutError();
427 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000428
Max Morin787eeed2016-06-23 10:42:07 +0200429 // kRecordingWarning
430 if (_ptrAudioDevice->RecordingWarning()) {
431 CriticalSectionScoped lock(&_critSectEventCb);
432 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200433 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200434 _ptrCbAudioDeviceObserver->OnWarningIsReported(
435 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000436 }
Max Morin787eeed2016-06-23 10:42:07 +0200437 _ptrAudioDevice->ClearRecordingWarning();
438 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000439
Max Morin787eeed2016-06-23 10:42:07 +0200440 // kRecordingError
441 if (_ptrAudioDevice->RecordingError()) {
442 CriticalSectionScoped lock(&_critSectEventCb);
443 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200444 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200445 _ptrCbAudioDeviceObserver->OnErrorIsReported(
446 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000447 }
Max Morin787eeed2016-06-23 10:42:07 +0200448 _ptrAudioDevice->ClearRecordingError();
449 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000450}
451
452// ============================================================================
453// Public API
454// ============================================================================
455
456// ----------------------------------------------------------------------------
457// ActiveAudioLayer
458// ----------------------------------------------------------------------------
459
henrikab2619892015-05-18 16:49:16 +0200460int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200461 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200462 AudioLayer activeAudio;
463 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
464 return -1;
465 }
466 *audioLayer = activeAudio;
467 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000468}
469
470// ----------------------------------------------------------------------------
471// LastError
472// ----------------------------------------------------------------------------
473
Max Morin787eeed2016-06-23 10:42:07 +0200474AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200475 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200476 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000477}
478
479// ----------------------------------------------------------------------------
480// Init
481// ----------------------------------------------------------------------------
482
Max Morin787eeed2016-06-23 10:42:07 +0200483int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200484 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200485 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000486 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200487 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200488
Max Morin84cab202016-07-01 13:35:19 +0200489 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
490 RTC_HISTOGRAM_ENUMERATION(
491 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
492 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
493 if (status != AudioDeviceGeneric::InitStatus::OK) {
494 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200495 return -1;
496 }
497
498 _initialized = true;
499 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000500}
501
502// ----------------------------------------------------------------------------
503// Terminate
504// ----------------------------------------------------------------------------
505
Max Morin787eeed2016-06-23 10:42:07 +0200506int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200507 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200508 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000509 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200510
511 if (_ptrAudioDevice->Terminate() == -1) {
512 return -1;
513 }
514
515 _initialized = false;
516 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000517}
518
519// ----------------------------------------------------------------------------
520// Initialized
521// ----------------------------------------------------------------------------
522
Max Morin787eeed2016-06-23 10:42:07 +0200523bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200524 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200525 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000526}
527
528// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000529// InitSpeaker
530// ----------------------------------------------------------------------------
531
Max Morin787eeed2016-06-23 10:42:07 +0200532int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200533 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200534 CHECK_INITIALIZED();
535 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000536}
537
538// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000539// InitMicrophone
540// ----------------------------------------------------------------------------
541
Max Morin787eeed2016-06-23 10:42:07 +0200542int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200543 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200544 CHECK_INITIALIZED();
545 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000546}
547
548// ----------------------------------------------------------------------------
549// SpeakerVolumeIsAvailable
550// ----------------------------------------------------------------------------
551
Max Morin787eeed2016-06-23 10:42:07 +0200552int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200553 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200554 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000555
Max Morin787eeed2016-06-23 10:42:07 +0200556 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000557
Max Morin787eeed2016-06-23 10:42:07 +0200558 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
559 return -1;
560 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000561
Max Morin787eeed2016-06-23 10:42:07 +0200562 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000563
Max Morin098e6c52016-06-28 09:36:25 +0200564 if (isAvailable) {
565 LOG(INFO) << __FUNCTION__ << " output: available";
566 } else {
567 LOG(INFO) << __FUNCTION__ << " output: not available";
568 }
Max Morin787eeed2016-06-23 10:42:07 +0200569 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000570}
571
572// ----------------------------------------------------------------------------
573// SetSpeakerVolume
574// ----------------------------------------------------------------------------
575
Max Morin787eeed2016-06-23 10:42:07 +0200576int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200577 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200578 CHECK_INITIALIZED();
579 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000580}
581
582// ----------------------------------------------------------------------------
583// SpeakerVolume
584// ----------------------------------------------------------------------------
585
Max Morin787eeed2016-06-23 10:42:07 +0200586int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200587 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200588 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000589
Max Morin787eeed2016-06-23 10:42:07 +0200590 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000591
Max Morin787eeed2016-06-23 10:42:07 +0200592 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
593 return -1;
594 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000595
Max Morin787eeed2016-06-23 10:42:07 +0200596 *volume = level;
niklase@google.com470e71d2011-07-07 08:21:25 +0000597
Max Morin098e6c52016-06-28 09:36:25 +0200598 LOG(INFO) << __FUNCTION__ << " output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200599 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000600}
601
602// ----------------------------------------------------------------------------
603// SetWaveOutVolume
604// ----------------------------------------------------------------------------
605
Max Morin787eeed2016-06-23 10:42:07 +0200606int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
607 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200608 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200609 CHECK_INITIALIZED();
610 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000611}
612
613// ----------------------------------------------------------------------------
614// WaveOutVolume
615// ----------------------------------------------------------------------------
616
Max Morin787eeed2016-06-23 10:42:07 +0200617int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
618 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200619 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200620 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000621
Max Morin787eeed2016-06-23 10:42:07 +0200622 uint16_t volLeft(0);
623 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000624
Max Morin787eeed2016-06-23 10:42:07 +0200625 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
626 return -1;
627 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000628
Max Morin787eeed2016-06-23 10:42:07 +0200629 *volumeLeft = volLeft;
630 *volumeRight = volRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000631
Max Morin098e6c52016-06-28 09:36:25 +0200632 LOG(INFO) << __FUNCTION__ << " output: volumeLeft = " << *volumeLeft
633 << ", volumeRight = " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000634
Max Morin787eeed2016-06-23 10:42:07 +0200635 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000636}
637
638// ----------------------------------------------------------------------------
639// SpeakerIsInitialized
640// ----------------------------------------------------------------------------
641
Max Morin787eeed2016-06-23 10:42:07 +0200642bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200643 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200644 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000645
Max Morin787eeed2016-06-23 10:42:07 +0200646 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000647
Max Morin098e6c52016-06-28 09:36:25 +0200648 if (isInitialized) {
649 LOG(INFO) << __FUNCTION__ << " output: initialized";
650 } else {
651 LOG(INFO) << __FUNCTION__ << " output: not initialized";
652 }
Max Morin787eeed2016-06-23 10:42:07 +0200653 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000654}
655
656// ----------------------------------------------------------------------------
657// MicrophoneIsInitialized
658// ----------------------------------------------------------------------------
659
Max Morin787eeed2016-06-23 10:42:07 +0200660bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200661 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200662 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000663
Max Morin787eeed2016-06-23 10:42:07 +0200664 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000665
Max Morin098e6c52016-06-28 09:36:25 +0200666 if (isInitialized) {
667 LOG(INFO) << __FUNCTION__ << " output: initialized";
668 } else {
669 LOG(INFO) << __FUNCTION__ << " output: not initialized";
670 }
Max Morin787eeed2016-06-23 10:42:07 +0200671 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000672}
673
674// ----------------------------------------------------------------------------
675// MaxSpeakerVolume
676// ----------------------------------------------------------------------------
677
Max Morin787eeed2016-06-23 10:42:07 +0200678int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200679 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200680 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000681
Max Morin787eeed2016-06-23 10:42:07 +0200682 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000683
Max Morin787eeed2016-06-23 10:42:07 +0200684 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
685 return -1;
686 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000687
Max Morin787eeed2016-06-23 10:42:07 +0200688 *maxVolume = maxVol;
niklase@google.com470e71d2011-07-07 08:21:25 +0000689
Max Morin098e6c52016-06-28 09:36:25 +0200690 LOG(INFO) << __FUNCTION__ << " output: maxVolume = " << *maxVolume;
Max Morin787eeed2016-06-23 10:42:07 +0200691 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000692}
693
694// ----------------------------------------------------------------------------
695// MinSpeakerVolume
696// ----------------------------------------------------------------------------
697
Max Morin787eeed2016-06-23 10:42:07 +0200698int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200699 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200700 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000701
Max Morin787eeed2016-06-23 10:42:07 +0200702 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000703
Max Morin787eeed2016-06-23 10:42:07 +0200704 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
705 return -1;
706 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000707
Max Morin787eeed2016-06-23 10:42:07 +0200708 *minVolume = minVol;
niklase@google.com470e71d2011-07-07 08:21:25 +0000709
Max Morin098e6c52016-06-28 09:36:25 +0200710 LOG(INFO) << __FUNCTION__ << " output: " << *minVolume;
Max Morin787eeed2016-06-23 10:42:07 +0200711 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000712}
713
714// ----------------------------------------------------------------------------
715// SpeakerVolumeStepSize
716// ----------------------------------------------------------------------------
717
Max Morin787eeed2016-06-23 10:42:07 +0200718int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200719 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200720 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000721
Max Morin787eeed2016-06-23 10:42:07 +0200722 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723
Max Morin787eeed2016-06-23 10:42:07 +0200724 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200725 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200726 return -1;
727 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000728
Max Morin787eeed2016-06-23 10:42:07 +0200729 *stepSize = delta;
niklase@google.com470e71d2011-07-07 08:21:25 +0000730
Max Morin098e6c52016-06-28 09:36:25 +0200731 LOG(INFO) << __FUNCTION__ << " output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200732 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000733}
734
735// ----------------------------------------------------------------------------
736// SpeakerMuteIsAvailable
737// ----------------------------------------------------------------------------
738
Max Morin787eeed2016-06-23 10:42:07 +0200739int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200740 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200741 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000742
Max Morin787eeed2016-06-23 10:42:07 +0200743 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000744
Max Morin787eeed2016-06-23 10:42:07 +0200745 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
746 return -1;
747 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000748
Max Morin787eeed2016-06-23 10:42:07 +0200749 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000750
Max Morin098e6c52016-06-28 09:36:25 +0200751 if (isAvailable) {
752 LOG(INFO) << __FUNCTION__ << " output: available";
753 } else {
754 LOG(INFO) << __FUNCTION__ << " output: not available";
755 }
Max Morin787eeed2016-06-23 10:42:07 +0200756 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000757}
758
759// ----------------------------------------------------------------------------
760// SetSpeakerMute
761// ----------------------------------------------------------------------------
762
Max Morin787eeed2016-06-23 10:42:07 +0200763int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200764 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200765 CHECK_INITIALIZED();
766 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000767}
768
769// ----------------------------------------------------------------------------
770// SpeakerMute
771// ----------------------------------------------------------------------------
772
Max Morin787eeed2016-06-23 10:42:07 +0200773int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200774 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200775 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000776
Max Morin787eeed2016-06-23 10:42:07 +0200777 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000778
Max Morin787eeed2016-06-23 10:42:07 +0200779 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
780 return -1;
781 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000782
Max Morin787eeed2016-06-23 10:42:07 +0200783 *enabled = muted;
niklase@google.com470e71d2011-07-07 08:21:25 +0000784
Max Morin098e6c52016-06-28 09:36:25 +0200785 if (muted) {
786 LOG(INFO) << __FUNCTION__ << " output: muted";
787 } else {
788 LOG(INFO) << __FUNCTION__ << " output: not muted";
789 }
Max Morin787eeed2016-06-23 10:42:07 +0200790 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000791}
792
793// ----------------------------------------------------------------------------
794// MicrophoneMuteIsAvailable
795// ----------------------------------------------------------------------------
796
Max Morin787eeed2016-06-23 10:42:07 +0200797int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200798 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200799 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000800
Max Morin787eeed2016-06-23 10:42:07 +0200801 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000802
Max Morin787eeed2016-06-23 10:42:07 +0200803 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
804 return -1;
805 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000806
Max Morin787eeed2016-06-23 10:42:07 +0200807 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000808
Max Morin098e6c52016-06-28 09:36:25 +0200809 if (isAvailable) {
810 LOG(INFO) << __FUNCTION__ << " output: available";
811 } else {
812 LOG(INFO) << __FUNCTION__ << " output: not available";
813 }
Max Morin787eeed2016-06-23 10:42:07 +0200814 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000815}
816
817// ----------------------------------------------------------------------------
818// SetMicrophoneMute
819// ----------------------------------------------------------------------------
820
Max Morin787eeed2016-06-23 10:42:07 +0200821int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200822 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200823 CHECK_INITIALIZED();
824 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000825}
826
827// ----------------------------------------------------------------------------
828// MicrophoneMute
829// ----------------------------------------------------------------------------
830
Max Morin787eeed2016-06-23 10:42:07 +0200831int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200832 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200833 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000834
Max Morin787eeed2016-06-23 10:42:07 +0200835 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000836
Max Morin787eeed2016-06-23 10:42:07 +0200837 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
838 return -1;
839 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000840
Max Morin787eeed2016-06-23 10:42:07 +0200841 *enabled = muted;
niklase@google.com470e71d2011-07-07 08:21:25 +0000842
Max Morin098e6c52016-06-28 09:36:25 +0200843 if (muted) {
844 LOG(INFO) << __FUNCTION__ << " output: muted";
845 } else {
846 LOG(INFO) << __FUNCTION__ << " output: not muted";
847 }
Max Morin787eeed2016-06-23 10:42:07 +0200848 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000849}
850
851// ----------------------------------------------------------------------------
852// MicrophoneBoostIsAvailable
853// ----------------------------------------------------------------------------
854
Max Morin787eeed2016-06-23 10:42:07 +0200855int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200856 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200857 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000858
Max Morin787eeed2016-06-23 10:42:07 +0200859 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000860
Max Morin787eeed2016-06-23 10:42:07 +0200861 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
862 return -1;
863 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000864
Max Morin787eeed2016-06-23 10:42:07 +0200865 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000866
Max Morin098e6c52016-06-28 09:36:25 +0200867 if (isAvailable) {
868 LOG(INFO) << __FUNCTION__ << " output: available";
869 } else {
870 LOG(INFO) << __FUNCTION__ << " output: not available";
871 }
Max Morin787eeed2016-06-23 10:42:07 +0200872 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000873}
874
875// ----------------------------------------------------------------------------
876// SetMicrophoneBoost
877// ----------------------------------------------------------------------------
878
Max Morin787eeed2016-06-23 10:42:07 +0200879int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200880 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200881 CHECK_INITIALIZED();
882 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000883}
884
885// ----------------------------------------------------------------------------
886// MicrophoneBoost
887// ----------------------------------------------------------------------------
888
Max Morin787eeed2016-06-23 10:42:07 +0200889int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200890 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200891 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000892
Max Morin787eeed2016-06-23 10:42:07 +0200893 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000894
Max Morin787eeed2016-06-23 10:42:07 +0200895 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
896 return -1;
897 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000898
Max Morin787eeed2016-06-23 10:42:07 +0200899 *enabled = onOff;
niklase@google.com470e71d2011-07-07 08:21:25 +0000900
Max Morin098e6c52016-06-28 09:36:25 +0200901 if (onOff) {
902 LOG(INFO) << __FUNCTION__ << " output: enabled";
903 } else {
904 LOG(INFO) << __FUNCTION__ << " output: not enabled";
905 }
Max Morin787eeed2016-06-23 10:42:07 +0200906 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000907}
908
909// ----------------------------------------------------------------------------
910// MicrophoneVolumeIsAvailable
911// ----------------------------------------------------------------------------
912
Max Morin787eeed2016-06-23 10:42:07 +0200913int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200914 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200915 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000916
Max Morin787eeed2016-06-23 10:42:07 +0200917 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000918
Max Morin787eeed2016-06-23 10:42:07 +0200919 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
920 return -1;
921 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000922
Max Morin787eeed2016-06-23 10:42:07 +0200923 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000924
Max Morin098e6c52016-06-28 09:36:25 +0200925 if (isAvailable) {
926 LOG(INFO) << __FUNCTION__ << " output: available";
927 } else {
928 LOG(INFO) << __FUNCTION__ << " output: not available";
929 }
Max Morin787eeed2016-06-23 10:42:07 +0200930 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000931}
932
933// ----------------------------------------------------------------------------
934// SetMicrophoneVolume
935// ----------------------------------------------------------------------------
936
Max Morin787eeed2016-06-23 10:42:07 +0200937int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200938 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200939 CHECK_INITIALIZED();
940 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000941}
942
943// ----------------------------------------------------------------------------
944// MicrophoneVolume
945// ----------------------------------------------------------------------------
946
Max Morin787eeed2016-06-23 10:42:07 +0200947int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200948 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200949 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000950
Max Morin787eeed2016-06-23 10:42:07 +0200951 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000952
Max Morin787eeed2016-06-23 10:42:07 +0200953 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
954 return -1;
955 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000956
Max Morin787eeed2016-06-23 10:42:07 +0200957 *volume = level;
niklase@google.com470e71d2011-07-07 08:21:25 +0000958
Max Morin098e6c52016-06-28 09:36:25 +0200959 LOG(INFO) << __FUNCTION__ << " output: volume = " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200960 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000961}
962
963// ----------------------------------------------------------------------------
964// StereoRecordingIsAvailable
965// ----------------------------------------------------------------------------
966
Max Morin787eeed2016-06-23 10:42:07 +0200967int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
968 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200969 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200970 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000971
Max Morin787eeed2016-06-23 10:42:07 +0200972 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000973
Max Morin787eeed2016-06-23 10:42:07 +0200974 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
975 return -1;
976 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000977
Max Morin787eeed2016-06-23 10:42:07 +0200978 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000979
Max Morin098e6c52016-06-28 09:36:25 +0200980 if (isAvailable) {
981 LOG(INFO) << __FUNCTION__ << " output: available";
982 } else {
983 LOG(INFO) << __FUNCTION__ << " output: not available";
984 }
Max Morin787eeed2016-06-23 10:42:07 +0200985 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000986}
987
988// ----------------------------------------------------------------------------
989// SetStereoRecording
990// ----------------------------------------------------------------------------
991
Max Morin787eeed2016-06-23 10:42:07 +0200992int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200993 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200994 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000995
Max Morin787eeed2016-06-23 10:42:07 +0200996 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200997 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200998 return -1;
999 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001000
Max Morin787eeed2016-06-23 10:42:07 +02001001 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001002 if (enable) {
1003 LOG(WARNING) << "failed to enable stereo recording";
1004 } else {
1005 LOG(WARNING) << "failed to disable stereo recording";
1006 }
Max Morin787eeed2016-06-23 10:42:07 +02001007 return -1;
1008 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001009
Max Morin787eeed2016-06-23 10:42:07 +02001010 int8_t nChannels(1);
1011 if (enable) {
1012 nChannels = 2;
1013 }
1014 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001015
Max Morin787eeed2016-06-23 10:42:07 +02001016 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001017}
1018
1019// ----------------------------------------------------------------------------
1020// StereoRecording
1021// ----------------------------------------------------------------------------
1022
Max Morin787eeed2016-06-23 10:42:07 +02001023int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001024 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001025 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001026
Max Morin787eeed2016-06-23 10:42:07 +02001027 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001028
Max Morin787eeed2016-06-23 10:42:07 +02001029 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
1030 return -1;
1031 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001032
Max Morin787eeed2016-06-23 10:42:07 +02001033 *enabled = stereo;
niklase@google.com470e71d2011-07-07 08:21:25 +00001034
Max Morin098e6c52016-06-28 09:36:25 +02001035 if (stereo) {
1036 LOG(INFO) << __FUNCTION__ << " output: enabled";
1037 } else {
1038 LOG(INFO) << __FUNCTION__ << " output: not enabled";
1039 }
Max Morin787eeed2016-06-23 10:42:07 +02001040 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001041}
1042
1043// ----------------------------------------------------------------------------
1044// SetRecordingChannel
1045// ----------------------------------------------------------------------------
1046
Max Morin787eeed2016-06-23 10:42:07 +02001047int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
1048 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +02001049 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +02001050 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +02001051 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +02001052 } else {
Max Morin098e6c52016-06-28 09:36:25 +02001053 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +02001054 }
1055 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001056
Max Morin787eeed2016-06-23 10:42:07 +02001057 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001058
Max Morin787eeed2016-06-23 10:42:07 +02001059 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001060 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001061 return -1;
1062 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001063
Max Morin787eeed2016-06-23 10:42:07 +02001064 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +00001065}
1066
1067// ----------------------------------------------------------------------------
1068// RecordingChannel
1069// ----------------------------------------------------------------------------
1070
Max Morin787eeed2016-06-23 10:42:07 +02001071int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +02001072 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001073 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001074
Max Morin787eeed2016-06-23 10:42:07 +02001075 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001076
Max Morin787eeed2016-06-23 10:42:07 +02001077 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
1078 return -1;
1079 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001080
Max Morin787eeed2016-06-23 10:42:07 +02001081 *channel = chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001082
Max Morin787eeed2016-06-23 10:42:07 +02001083 if (*channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +02001084 LOG(INFO) << __FUNCTION__ << " output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001085 } else if (*channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +02001086 LOG(INFO) << __FUNCTION__ << " output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001087 } else {
Max Morin098e6c52016-06-28 09:36:25 +02001088 LOG(INFO) << __FUNCTION__ << " output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001089 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001090
Max Morin787eeed2016-06-23 10:42:07 +02001091 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001092}
1093
1094// ----------------------------------------------------------------------------
1095// StereoPlayoutIsAvailable
1096// ----------------------------------------------------------------------------
1097
Max Morin787eeed2016-06-23 10:42:07 +02001098int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001099 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001100 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001101
Max Morin787eeed2016-06-23 10:42:07 +02001102 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001103
Max Morin787eeed2016-06-23 10:42:07 +02001104 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1105 return -1;
1106 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001107
Max Morin787eeed2016-06-23 10:42:07 +02001108 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001109
Max Morin098e6c52016-06-28 09:36:25 +02001110 if (isAvailable) {
1111 LOG(INFO) << __FUNCTION__ << " output: available";
1112 } else {
1113 LOG(INFO) << __FUNCTION__ << " output: not available";
1114 }
Max Morin787eeed2016-06-23 10:42:07 +02001115 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001116}
1117
1118// ----------------------------------------------------------------------------
1119// SetStereoPlayout
1120// ----------------------------------------------------------------------------
1121
Max Morin787eeed2016-06-23 10:42:07 +02001122int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001123 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001124 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001125
Max Morin787eeed2016-06-23 10:42:07 +02001126 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001127 LOG(LERROR)
1128 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001129 return -1;
1130 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001131
Max Morin787eeed2016-06-23 10:42:07 +02001132 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001133 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001134 return -1;
1135 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001136
Max Morin787eeed2016-06-23 10:42:07 +02001137 int8_t nChannels(1);
1138 if (enable) {
1139 nChannels = 2;
1140 }
1141 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001142
Max Morin787eeed2016-06-23 10:42:07 +02001143 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001144}
1145
1146// ----------------------------------------------------------------------------
1147// StereoPlayout
1148// ----------------------------------------------------------------------------
1149
Max Morin787eeed2016-06-23 10:42:07 +02001150int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001151 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001152 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001153
Max Morin787eeed2016-06-23 10:42:07 +02001154 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001155
Max Morin787eeed2016-06-23 10:42:07 +02001156 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1157 return -1;
1158 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001159
Max Morin787eeed2016-06-23 10:42:07 +02001160 *enabled = stereo;
niklase@google.com470e71d2011-07-07 08:21:25 +00001161
Max Morin098e6c52016-06-28 09:36:25 +02001162 if (stereo) {
1163 LOG(INFO) << __FUNCTION__ << " output: enabled";
1164 } else {
1165 LOG(INFO) << __FUNCTION__ << " output: not enabled";
1166 }
Max Morin787eeed2016-06-23 10:42:07 +02001167 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001168}
1169
1170// ----------------------------------------------------------------------------
1171// SetAGC
1172// ----------------------------------------------------------------------------
1173
Max Morin787eeed2016-06-23 10:42:07 +02001174int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001175 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001176 CHECK_INITIALIZED();
1177 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001178}
1179
1180// ----------------------------------------------------------------------------
1181// AGC
1182// ----------------------------------------------------------------------------
1183
Max Morin787eeed2016-06-23 10:42:07 +02001184bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001185 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001186 CHECK_INITIALIZED_BOOL();
1187 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001188}
1189
1190// ----------------------------------------------------------------------------
1191// PlayoutIsAvailable
1192// ----------------------------------------------------------------------------
1193
Max Morin787eeed2016-06-23 10:42:07 +02001194int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001195 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001196 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001197
Max Morin787eeed2016-06-23 10:42:07 +02001198 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001199
Max Morin787eeed2016-06-23 10:42:07 +02001200 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1201 return -1;
1202 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001203
Max Morin787eeed2016-06-23 10:42:07 +02001204 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001205
Max Morin098e6c52016-06-28 09:36:25 +02001206 if (isAvailable) {
1207 LOG(INFO) << __FUNCTION__ << " output: available";
1208 } else {
1209 LOG(INFO) << __FUNCTION__ << " output: not available";
1210 }
Max Morin787eeed2016-06-23 10:42:07 +02001211 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001212}
1213
1214// ----------------------------------------------------------------------------
1215// RecordingIsAvailable
1216// ----------------------------------------------------------------------------
1217
Max Morin787eeed2016-06-23 10:42:07 +02001218int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001219 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001220 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001221
Max Morin787eeed2016-06-23 10:42:07 +02001222 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001223
Max Morin787eeed2016-06-23 10:42:07 +02001224 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1225 return -1;
1226 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001227
Max Morin787eeed2016-06-23 10:42:07 +02001228 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001229
Max Morin098e6c52016-06-28 09:36:25 +02001230 if (isAvailable) {
1231 LOG(INFO) << __FUNCTION__ << " output: available";
1232 } else {
1233 LOG(INFO) << __FUNCTION__ << " output: not available";
1234 }
Max Morin787eeed2016-06-23 10:42:07 +02001235 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001236}
1237
1238// ----------------------------------------------------------------------------
1239// MaxMicrophoneVolume
1240// ----------------------------------------------------------------------------
1241
Max Morin787eeed2016-06-23 10:42:07 +02001242int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +02001243 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001244 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001245
Max Morin787eeed2016-06-23 10:42:07 +02001246 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001247
Max Morin787eeed2016-06-23 10:42:07 +02001248 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1249 return -1;
1250 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001251
Max Morin787eeed2016-06-23 10:42:07 +02001252 *maxVolume = maxVol;
niklase@google.com470e71d2011-07-07 08:21:25 +00001253
Max Morin098e6c52016-06-28 09:36:25 +02001254 LOG(INFO) << __FUNCTION__ << " output: = " << *maxVolume;
Max Morin787eeed2016-06-23 10:42:07 +02001255 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001256}
1257
1258// ----------------------------------------------------------------------------
1259// MinMicrophoneVolume
1260// ----------------------------------------------------------------------------
1261
Max Morin787eeed2016-06-23 10:42:07 +02001262int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +02001263 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001264 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001265
Max Morin787eeed2016-06-23 10:42:07 +02001266 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001267
Max Morin787eeed2016-06-23 10:42:07 +02001268 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1269 return -1;
1270 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001271
Max Morin787eeed2016-06-23 10:42:07 +02001272 *minVolume = minVol;
niklase@google.com470e71d2011-07-07 08:21:25 +00001273
Max Morin098e6c52016-06-28 09:36:25 +02001274 LOG(INFO) << __FUNCTION__ << " output: = " << *minVolume;
Max Morin787eeed2016-06-23 10:42:07 +02001275 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001276}
1277
1278// ----------------------------------------------------------------------------
1279// MicrophoneVolumeStepSize
1280// ----------------------------------------------------------------------------
1281
Max Morin787eeed2016-06-23 10:42:07 +02001282int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1283 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001284 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001285 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001286
Max Morin787eeed2016-06-23 10:42:07 +02001287 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001288
Max Morin787eeed2016-06-23 10:42:07 +02001289 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1290 return -1;
1291 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001292
Max Morin787eeed2016-06-23 10:42:07 +02001293 *stepSize = delta;
niklase@google.com470e71d2011-07-07 08:21:25 +00001294
Max Morin098e6c52016-06-28 09:36:25 +02001295 LOG(INFO) << __FUNCTION__ << " output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001296 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001297}
1298
1299// ----------------------------------------------------------------------------
1300// PlayoutDevices
1301// ----------------------------------------------------------------------------
1302
Max Morin787eeed2016-06-23 10:42:07 +02001303int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001304 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001305 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001306
Max Morin787eeed2016-06-23 10:42:07 +02001307 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001308
Max Morin098e6c52016-06-28 09:36:25 +02001309 LOG(INFO) << __FUNCTION__ << " output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001310 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001311}
1312
1313// ----------------------------------------------------------------------------
1314// SetPlayoutDevice I (II)
1315// ----------------------------------------------------------------------------
1316
Max Morin787eeed2016-06-23 10:42:07 +02001317int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001318 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001319 CHECK_INITIALIZED();
1320 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001321}
1322
1323// ----------------------------------------------------------------------------
1324// SetPlayoutDevice II (II)
1325// ----------------------------------------------------------------------------
1326
Max Morin787eeed2016-06-23 10:42:07 +02001327int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
1328 if (device == kDefaultDevice) {
1329 } else {
1330 }
Max Morin098e6c52016-06-28 09:36:25 +02001331 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001332 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001333
Max Morin787eeed2016-06-23 10:42:07 +02001334 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001335}
1336
1337// ----------------------------------------------------------------------------
1338// PlayoutDeviceName
1339// ----------------------------------------------------------------------------
1340
pbos@webrtc.org25509882013-04-09 10:30:35 +00001341int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1342 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001343 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001344 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001345 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001346 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001347
Max Morin787eeed2016-06-23 10:42:07 +02001348 if (name == NULL) {
1349 _lastError = kAdmErrArgument;
1350 return -1;
1351 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001352
Max Morin787eeed2016-06-23 10:42:07 +02001353 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1354 return -1;
1355 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001356
Max Morin787eeed2016-06-23 10:42:07 +02001357 if (name != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001358 LOG(INFO) << __FUNCTION__ << " output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001359 }
1360 if (guid != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001361 LOG(INFO) << __FUNCTION__ << " output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001362 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001363
Max Morin787eeed2016-06-23 10:42:07 +02001364 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001365}
1366
1367// ----------------------------------------------------------------------------
1368// RecordingDeviceName
1369// ----------------------------------------------------------------------------
1370
pbos@webrtc.org25509882013-04-09 10:30:35 +00001371int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1372 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001373 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001374 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001375 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001376 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001377
Max Morin787eeed2016-06-23 10:42:07 +02001378 if (name == NULL) {
1379 _lastError = kAdmErrArgument;
1380 return -1;
1381 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001382
Max Morin787eeed2016-06-23 10:42:07 +02001383 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1384 return -1;
1385 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001386
Max Morin787eeed2016-06-23 10:42:07 +02001387 if (name != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001388 LOG(INFO) << __FUNCTION__ << " output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001389 }
1390 if (guid != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001391 LOG(INFO) << __FUNCTION__ << " output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001392 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001393
Max Morin787eeed2016-06-23 10:42:07 +02001394 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001395}
1396
1397// ----------------------------------------------------------------------------
1398// RecordingDevices
1399// ----------------------------------------------------------------------------
1400
Max Morin787eeed2016-06-23 10:42:07 +02001401int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001402 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001403 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001404
Max Morin787eeed2016-06-23 10:42:07 +02001405 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001406
Max Morin098e6c52016-06-28 09:36:25 +02001407 LOG(INFO) << __FUNCTION__ << " output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001408 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001409}
1410
1411// ----------------------------------------------------------------------------
1412// SetRecordingDevice I (II)
1413// ----------------------------------------------------------------------------
1414
Max Morin787eeed2016-06-23 10:42:07 +02001415int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001416 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001417 CHECK_INITIALIZED();
1418 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001419}
1420
1421// ----------------------------------------------------------------------------
1422// SetRecordingDevice II (II)
1423// ----------------------------------------------------------------------------
1424
Max Morin787eeed2016-06-23 10:42:07 +02001425int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
1426 if (device == kDefaultDevice) {
1427 } else {
1428 }
Max Morin098e6c52016-06-28 09:36:25 +02001429 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001430 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001431
Max Morin787eeed2016-06-23 10:42:07 +02001432 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001433}
1434
1435// ----------------------------------------------------------------------------
1436// InitPlayout
1437// ----------------------------------------------------------------------------
1438
Max Morin787eeed2016-06-23 10:42:07 +02001439int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001440 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001441 CHECK_INITIALIZED();
1442 _audioDeviceBuffer.InitPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001443 int32_t result = _ptrAudioDevice->InitPlayout();
1444 LOG(INFO) << "output: " << result;
1445 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1446 static_cast<int>(result == 0));
1447 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001448}
1449
1450// ----------------------------------------------------------------------------
1451// InitRecording
1452// ----------------------------------------------------------------------------
1453
Max Morin787eeed2016-06-23 10:42:07 +02001454int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001455 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001456 CHECK_INITIALIZED();
1457 _audioDeviceBuffer.InitRecording();
Max Morin84cab202016-07-01 13:35:19 +02001458 int32_t result = _ptrAudioDevice->InitRecording();
1459 LOG(INFO) << "output: " << result;
1460 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1461 static_cast<int>(result == 0));
1462 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001463}
1464
1465// ----------------------------------------------------------------------------
1466// PlayoutIsInitialized
1467// ----------------------------------------------------------------------------
1468
Max Morin787eeed2016-06-23 10:42:07 +02001469bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001470 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001471 CHECK_INITIALIZED_BOOL();
1472 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001473}
1474
1475// ----------------------------------------------------------------------------
1476// RecordingIsInitialized
1477// ----------------------------------------------------------------------------
1478
Max Morin787eeed2016-06-23 10:42:07 +02001479bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001480 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001481 CHECK_INITIALIZED_BOOL();
1482 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001483}
1484
1485// ----------------------------------------------------------------------------
1486// StartPlayout
1487// ----------------------------------------------------------------------------
1488
Max Morin787eeed2016-06-23 10:42:07 +02001489int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001490 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001491 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001492 int32_t result = _ptrAudioDevice->StartPlayout();
1493 LOG(INFO) << "output: " << result;
1494 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1495 static_cast<int>(result == 0));
1496 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001497}
1498
1499// ----------------------------------------------------------------------------
1500// StopPlayout
1501// ----------------------------------------------------------------------------
1502
Max Morin787eeed2016-06-23 10:42:07 +02001503int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001504 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001505 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001506 int32_t result = _ptrAudioDevice->StopPlayout();
1507 LOG(INFO) << "output: " << result;
1508 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1509 static_cast<int>(result == 0));
1510 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001511}
1512
1513// ----------------------------------------------------------------------------
1514// Playing
1515// ----------------------------------------------------------------------------
1516
Max Morin787eeed2016-06-23 10:42:07 +02001517bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001518 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001519 CHECK_INITIALIZED_BOOL();
1520 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001521}
1522
1523// ----------------------------------------------------------------------------
1524// StartRecording
1525// ----------------------------------------------------------------------------
1526
Max Morin787eeed2016-06-23 10:42:07 +02001527int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001528 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001529 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001530 int32_t result = _ptrAudioDevice->StartRecording();
1531 LOG(INFO) << "output: " << result;
1532 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1533 static_cast<int>(result == 0));
1534 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001535}
1536// ----------------------------------------------------------------------------
1537// StopRecording
1538// ----------------------------------------------------------------------------
1539
Max Morin787eeed2016-06-23 10:42:07 +02001540int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001541 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001542 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001543 int32_t result = _ptrAudioDevice->StopRecording();
1544 LOG(INFO) << "output: " << result;
1545 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1546 static_cast<int>(result == 0));
1547 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001548}
1549
1550// ----------------------------------------------------------------------------
1551// Recording
1552// ----------------------------------------------------------------------------
1553
Max Morin787eeed2016-06-23 10:42:07 +02001554bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001555 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001556 CHECK_INITIALIZED_BOOL();
1557 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001558}
1559
1560// ----------------------------------------------------------------------------
1561// RegisterEventObserver
1562// ----------------------------------------------------------------------------
1563
Max Morin787eeed2016-06-23 10:42:07 +02001564int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1565 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001566 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001567 CriticalSectionScoped lock(&_critSectEventCb);
1568 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001569
Max Morin787eeed2016-06-23 10:42:07 +02001570 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001571}
1572
1573// ----------------------------------------------------------------------------
1574// RegisterAudioCallback
1575// ----------------------------------------------------------------------------
1576
Max Morin787eeed2016-06-23 10:42:07 +02001577int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1578 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001579 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001580 CriticalSectionScoped lock(&_critSectAudioCb);
1581 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001582
Max Morin787eeed2016-06-23 10:42:07 +02001583 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001584}
1585
1586// ----------------------------------------------------------------------------
1587// StartRawInputFileRecording
1588// ----------------------------------------------------------------------------
1589
pbos@webrtc.org25509882013-04-09 10:30:35 +00001590int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001591 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001592 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001593 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001594
Max Morin787eeed2016-06-23 10:42:07 +02001595 if (NULL == pcmFileNameUTF8) {
1596 return -1;
1597 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001598
Max Morin787eeed2016-06-23 10:42:07 +02001599 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001600}
1601
1602// ----------------------------------------------------------------------------
1603// StopRawInputFileRecording
1604// ----------------------------------------------------------------------------
1605
Max Morin787eeed2016-06-23 10:42:07 +02001606int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001607 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001608 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001609
Max Morin787eeed2016-06-23 10:42:07 +02001610 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001611}
1612
1613// ----------------------------------------------------------------------------
1614// StartRawOutputFileRecording
1615// ----------------------------------------------------------------------------
1616
pbos@webrtc.org25509882013-04-09 10:30:35 +00001617int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001618 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001619 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001620 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001621
Max Morin787eeed2016-06-23 10:42:07 +02001622 if (NULL == pcmFileNameUTF8) {
1623 return -1;
1624 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001625
Max Morin787eeed2016-06-23 10:42:07 +02001626 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001627}
1628
1629// ----------------------------------------------------------------------------
1630// StopRawOutputFileRecording
1631// ----------------------------------------------------------------------------
1632
Max Morin787eeed2016-06-23 10:42:07 +02001633int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001634 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001635 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001636
Max Morin787eeed2016-06-23 10:42:07 +02001637 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001638}
1639
1640// ----------------------------------------------------------------------------
1641// SetPlayoutBuffer
1642// ----------------------------------------------------------------------------
1643
Max Morin787eeed2016-06-23 10:42:07 +02001644int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1645 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001646 if (type == kFixedBufferSize) {
1647 LOG(INFO) << __FUNCTION__ << "("
1648 << "fixed buffer, " << sizeMS << "ms"
1649 << ")";
1650 } else if (type == kAdaptiveBufferSize) {
1651 LOG(INFO) << __FUNCTION__ << "("
1652 << "adaptive buffer, " << sizeMS << "ms"
1653 << ")";
1654 } else {
1655 LOG(INFO) << __FUNCTION__ << "("
1656 << "?, " << sizeMS << "ms"
1657 << ")";
1658 }
Max Morin787eeed2016-06-23 10:42:07 +02001659 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001660
Max Morin787eeed2016-06-23 10:42:07 +02001661 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001662 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1663 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001664 return -1;
1665 }
1666
1667 int32_t ret(0);
1668
1669 if (kFixedBufferSize == type) {
1670 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1671 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001672 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001673 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001674 }
Max Morin787eeed2016-06-23 10:42:07 +02001675 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001676
Max Morin787eeed2016-06-23 10:42:07 +02001677 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001678 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1679 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001680 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001681
Max Morin787eeed2016-06-23 10:42:07 +02001682 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001683}
1684
1685// ----------------------------------------------------------------------------
1686// PlayoutBuffer
1687// ----------------------------------------------------------------------------
1688
Max Morin787eeed2016-06-23 10:42:07 +02001689int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1690 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001691 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001692 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001693
Max Morin787eeed2016-06-23 10:42:07 +02001694 BufferType bufType;
1695 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001696
Max Morin787eeed2016-06-23 10:42:07 +02001697 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001698 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001699 return -1;
1700 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001701
Max Morin787eeed2016-06-23 10:42:07 +02001702 *type = bufType;
1703 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001704
Max Morin098e6c52016-06-28 09:36:25 +02001705 LOG(INFO) << __FUNCTION__ << " output: type = " << *type
1706 << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001707 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001708}
1709
1710// ----------------------------------------------------------------------------
1711// PlayoutDelay
1712// ----------------------------------------------------------------------------
1713
Max Morin787eeed2016-06-23 10:42:07 +02001714int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001715 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001716 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001717
Max Morin787eeed2016-06-23 10:42:07 +02001718 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001719
Max Morin787eeed2016-06-23 10:42:07 +02001720 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001721 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001722 return -1;
1723 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001724
Max Morin787eeed2016-06-23 10:42:07 +02001725 *delayMS = delay;
niklase@google.com470e71d2011-07-07 08:21:25 +00001726
Max Morin098e6c52016-06-28 09:36:25 +02001727 LOG(LS_VERBOSE) << __FUNCTION__ << " output: delayMS = " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001728 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001729}
1730
1731// ----------------------------------------------------------------------------
1732// RecordingDelay
1733// ----------------------------------------------------------------------------
1734
Max Morin787eeed2016-06-23 10:42:07 +02001735int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001736 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001737 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001738
Max Morin787eeed2016-06-23 10:42:07 +02001739 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001740
Max Morin787eeed2016-06-23 10:42:07 +02001741 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001742 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001743 return -1;
1744 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001745
Max Morin787eeed2016-06-23 10:42:07 +02001746 *delayMS = delay;
niklase@google.com470e71d2011-07-07 08:21:25 +00001747
Max Morin098e6c52016-06-28 09:36:25 +02001748 LOG(INFO) << __FUNCTION__ << " output: delayMS = " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001749 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001750}
1751
1752// ----------------------------------------------------------------------------
1753// CPULoad
1754// ----------------------------------------------------------------------------
1755
Max Morin787eeed2016-06-23 10:42:07 +02001756int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001757 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001758 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001759
Max Morin787eeed2016-06-23 10:42:07 +02001760 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001761
Max Morin787eeed2016-06-23 10:42:07 +02001762 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001763 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001764 return -1;
1765 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001766
Max Morin787eeed2016-06-23 10:42:07 +02001767 *load = cpuLoad;
niklase@google.com470e71d2011-07-07 08:21:25 +00001768
Max Morin098e6c52016-06-28 09:36:25 +02001769 LOG(INFO) << __FUNCTION__ << " output: load = " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001770 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001771}
1772
1773// ----------------------------------------------------------------------------
1774// SetRecordingSampleRate
1775// ----------------------------------------------------------------------------
1776
Max Morin787eeed2016-06-23 10:42:07 +02001777int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1778 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001779 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001780 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001781
Max Morin787eeed2016-06-23 10:42:07 +02001782 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1783 return -1;
1784 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001785
Max Morin787eeed2016-06-23 10:42:07 +02001786 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001787}
1788
1789// ----------------------------------------------------------------------------
1790// RecordingSampleRate
1791// ----------------------------------------------------------------------------
1792
Max Morin787eeed2016-06-23 10:42:07 +02001793int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1794 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001795 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001796 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001797
Max Morin787eeed2016-06-23 10:42:07 +02001798 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001799
Max Morin787eeed2016-06-23 10:42:07 +02001800 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001801 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001802 return -1;
1803 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001804
Max Morin787eeed2016-06-23 10:42:07 +02001805 *samplesPerSec = sampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +00001806
Max Morin098e6c52016-06-28 09:36:25 +02001807 LOG(INFO) << __FUNCTION__ << " output: samplesPerSec = " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001808 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001809}
1810
1811// ----------------------------------------------------------------------------
1812// SetPlayoutSampleRate
1813// ----------------------------------------------------------------------------
1814
Max Morin787eeed2016-06-23 10:42:07 +02001815int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1816 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001817 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001818 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001819
Max Morin787eeed2016-06-23 10:42:07 +02001820 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1821 return -1;
1822 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001823
Max Morin787eeed2016-06-23 10:42:07 +02001824 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001825}
1826
1827// ----------------------------------------------------------------------------
1828// PlayoutSampleRate
1829// ----------------------------------------------------------------------------
1830
Max Morin787eeed2016-06-23 10:42:07 +02001831int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1832 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001833 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001834 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001835
Max Morin787eeed2016-06-23 10:42:07 +02001836 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001837
Max Morin787eeed2016-06-23 10:42:07 +02001838 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001839 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001840 return -1;
1841 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001842
Max Morin787eeed2016-06-23 10:42:07 +02001843 *samplesPerSec = sampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +00001844
Max Morin098e6c52016-06-28 09:36:25 +02001845 LOG(INFO) << __FUNCTION__ << " output: samplesPerSec = " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001846 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001847}
1848
1849// ----------------------------------------------------------------------------
1850// ResetAudioDevice
1851// ----------------------------------------------------------------------------
1852
Max Morin787eeed2016-06-23 10:42:07 +02001853int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001854 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001855 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001856
Max Morin787eeed2016-06-23 10:42:07 +02001857 if (_ptrAudioDevice->ResetAudioDevice() == -1) {
1858 return -1;
1859 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001860
Max Morin787eeed2016-06-23 10:42:07 +02001861 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001862}
1863
1864// ----------------------------------------------------------------------------
1865// SetLoudspeakerStatus
1866// ----------------------------------------------------------------------------
1867
Max Morin787eeed2016-06-23 10:42:07 +02001868int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001869 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001870 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001871
Max Morin787eeed2016-06-23 10:42:07 +02001872 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1873 return -1;
1874 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001875
Max Morin787eeed2016-06-23 10:42:07 +02001876 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001877}
1878
1879// ----------------------------------------------------------------------------
1880// GetLoudspeakerStatus
1881// ----------------------------------------------------------------------------
1882
henrikac14f5ff2015-09-23 14:08:33 +02001883int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001884 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001885 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001886 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001887 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001888 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001889 }
Max Morin098e6c52016-06-28 09:36:25 +02001890 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1891 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001892}
1893
henrikac14f5ff2015-09-23 14:08:33 +02001894bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
Max Morin098e6c52016-06-28 09:36:25 +02001895 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001896 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001897 bool isEnabled = _ptrAudioDevice->BuiltInAECIsEnabled();
1898 if (isEnabled) {
1899 LOG(INFO) << __FUNCTION__ << " output: enabled";
1900 } else {
1901 LOG(INFO) << __FUNCTION__ << " output: not enabled";
1902 }
1903 return isEnabled;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001904}
1905
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001906bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001907 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001908 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001909 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
1910 if (isAvailable) {
1911 LOG(INFO) << __FUNCTION__ << " output: available";
1912 } else {
1913 LOG(INFO) << __FUNCTION__ << " output: not available";
1914 }
1915 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001916}
1917
henrikac14f5ff2015-09-23 14:08:33 +02001918int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001919 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001920 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001921 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
1922 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1923 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001924}
1925
1926bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001927 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001928 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001929 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
1930 if (isAvailable) {
1931 LOG(INFO) << __FUNCTION__ << " output: available";
1932 } else {
1933 LOG(INFO) << __FUNCTION__ << " output: not available";
1934 }
1935 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001936}
1937
1938int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001939 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001940 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001941 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
1942 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1943 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001944}
1945
1946bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001947 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001948 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001949 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
1950 if (isAvailable) {
1951 LOG(INFO) << __FUNCTION__ << " output: available";
1952 } else {
1953 LOG(INFO) << __FUNCTION__ << " output: not available";
1954 }
1955 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001956}
1957
1958int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001959 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001960 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001961 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
1962 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1963 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001964}
1965
henrikaba35d052015-07-14 17:04:08 +02001966int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1967 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001968 LOG(INFO) << __FUNCTION__;
1969 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
1970 LOG(INFO) << __FUNCTION__ << " output: " << r;
1971 return r;
henrikaba35d052015-07-14 17:04:08 +02001972}
1973
1974int AudioDeviceModuleImpl::GetRecordAudioParameters(
1975 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001976 LOG(INFO) << __FUNCTION__;
1977 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
1978 LOG(INFO) << __FUNCTION__ << " output: " << r;
1979 return r;
henrikaba35d052015-07-14 17:04:08 +02001980}
1981
niklase@google.com470e71d2011-07-07 08:21:25 +00001982// ============================================================================
1983// Private Methods
1984// ============================================================================
1985
1986// ----------------------------------------------------------------------------
1987// Platform
1988// ----------------------------------------------------------------------------
1989
Max Morin787eeed2016-06-23 10:42:07 +02001990AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001991 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001992 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001993}
1994
1995// ----------------------------------------------------------------------------
1996// PlatformAudioLayer
1997// ----------------------------------------------------------------------------
1998
Max Morin787eeed2016-06-23 10:42:07 +02001999AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
2000 const {
Max Morin098e6c52016-06-28 09:36:25 +02002001 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02002002 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00002003}
2004
2005} // namespace webrtc