blob: bfcbb00e48a492bdcffa20b9870411ba3d04ad56 [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;
Max Morin2c332bb2016-07-04 09:03:42 +0200563 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200564 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000565}
566
567// ----------------------------------------------------------------------------
568// SetSpeakerVolume
569// ----------------------------------------------------------------------------
570
Max Morin787eeed2016-06-23 10:42:07 +0200571int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200572 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200573 CHECK_INITIALIZED();
574 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000575}
576
577// ----------------------------------------------------------------------------
578// SpeakerVolume
579// ----------------------------------------------------------------------------
580
Max Morin787eeed2016-06-23 10:42:07 +0200581int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200582 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200583 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000584
Max Morin787eeed2016-06-23 10:42:07 +0200585 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000586
Max Morin787eeed2016-06-23 10:42:07 +0200587 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
588 return -1;
589 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000590
Max Morin787eeed2016-06-23 10:42:07 +0200591 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200592 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200593 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000594}
595
596// ----------------------------------------------------------------------------
597// SetWaveOutVolume
598// ----------------------------------------------------------------------------
599
Max Morin787eeed2016-06-23 10:42:07 +0200600int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
601 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200602 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200603 CHECK_INITIALIZED();
604 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000605}
606
607// ----------------------------------------------------------------------------
608// WaveOutVolume
609// ----------------------------------------------------------------------------
610
Max Morin787eeed2016-06-23 10:42:07 +0200611int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
612 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200613 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200614 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000615
Max Morin787eeed2016-06-23 10:42:07 +0200616 uint16_t volLeft(0);
617 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000618
Max Morin787eeed2016-06-23 10:42:07 +0200619 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
620 return -1;
621 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000622
Max Morin787eeed2016-06-23 10:42:07 +0200623 *volumeLeft = volLeft;
624 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200625 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000626
Max Morin787eeed2016-06-23 10:42:07 +0200627 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000628}
629
630// ----------------------------------------------------------------------------
631// SpeakerIsInitialized
632// ----------------------------------------------------------------------------
633
Max Morin787eeed2016-06-23 10:42:07 +0200634bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200635 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200636 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000637
Max Morin787eeed2016-06-23 10:42:07 +0200638 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200639 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200640 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000641}
642
643// ----------------------------------------------------------------------------
644// MicrophoneIsInitialized
645// ----------------------------------------------------------------------------
646
Max Morin787eeed2016-06-23 10:42:07 +0200647bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200648 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200649 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000650
Max Morin787eeed2016-06-23 10:42:07 +0200651 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200652 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200653 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000654}
655
656// ----------------------------------------------------------------------------
657// MaxSpeakerVolume
658// ----------------------------------------------------------------------------
659
Max Morin787eeed2016-06-23 10:42:07 +0200660int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
661 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000662
Max Morin787eeed2016-06-23 10:42:07 +0200663 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000664
Max Morin787eeed2016-06-23 10:42:07 +0200665 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
666 return -1;
667 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000668
Max Morin787eeed2016-06-23 10:42:07 +0200669 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200670 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000671}
672
673// ----------------------------------------------------------------------------
674// MinSpeakerVolume
675// ----------------------------------------------------------------------------
676
Max Morin787eeed2016-06-23 10:42:07 +0200677int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
678 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000679
Max Morin787eeed2016-06-23 10:42:07 +0200680 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000681
Max Morin787eeed2016-06-23 10:42:07 +0200682 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
683 return -1;
684 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000685
Max Morin787eeed2016-06-23 10:42:07 +0200686 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200687 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000688}
689
690// ----------------------------------------------------------------------------
691// SpeakerVolumeStepSize
692// ----------------------------------------------------------------------------
693
Max Morin787eeed2016-06-23 10:42:07 +0200694int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200695 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200696 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000697
Max Morin787eeed2016-06-23 10:42:07 +0200698 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000699
Max Morin787eeed2016-06-23 10:42:07 +0200700 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200701 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200702 return -1;
703 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000704
Max Morin787eeed2016-06-23 10:42:07 +0200705 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200706 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200707 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000708}
709
710// ----------------------------------------------------------------------------
711// SpeakerMuteIsAvailable
712// ----------------------------------------------------------------------------
713
Max Morin787eeed2016-06-23 10:42:07 +0200714int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200715 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200716 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000717
Max Morin787eeed2016-06-23 10:42:07 +0200718 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000719
Max Morin787eeed2016-06-23 10:42:07 +0200720 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
721 return -1;
722 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000723
Max Morin787eeed2016-06-23 10:42:07 +0200724 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200725 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200726 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000727}
728
729// ----------------------------------------------------------------------------
730// SetSpeakerMute
731// ----------------------------------------------------------------------------
732
Max Morin787eeed2016-06-23 10:42:07 +0200733int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200734 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200735 CHECK_INITIALIZED();
736 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000737}
738
739// ----------------------------------------------------------------------------
740// SpeakerMute
741// ----------------------------------------------------------------------------
742
Max Morin787eeed2016-06-23 10:42:07 +0200743int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200744 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200745 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000746
Max Morin787eeed2016-06-23 10:42:07 +0200747 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000748
Max Morin787eeed2016-06-23 10:42:07 +0200749 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
750 return -1;
751 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000752
Max Morin787eeed2016-06-23 10:42:07 +0200753 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200754 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200755 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000756}
757
758// ----------------------------------------------------------------------------
759// MicrophoneMuteIsAvailable
760// ----------------------------------------------------------------------------
761
Max Morin787eeed2016-06-23 10:42:07 +0200762int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200763 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200764 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000765
Max Morin787eeed2016-06-23 10:42:07 +0200766 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000767
Max Morin787eeed2016-06-23 10:42:07 +0200768 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
769 return -1;
770 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000771
Max Morin787eeed2016-06-23 10:42:07 +0200772 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200773 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200774 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000775}
776
777// ----------------------------------------------------------------------------
778// SetMicrophoneMute
779// ----------------------------------------------------------------------------
780
Max Morin787eeed2016-06-23 10:42:07 +0200781int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200782 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200783 CHECK_INITIALIZED();
784 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000785}
786
787// ----------------------------------------------------------------------------
788// MicrophoneMute
789// ----------------------------------------------------------------------------
790
Max Morin787eeed2016-06-23 10:42:07 +0200791int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200792 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200793 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000794
Max Morin787eeed2016-06-23 10:42:07 +0200795 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000796
Max Morin787eeed2016-06-23 10:42:07 +0200797 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
798 return -1;
799 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000800
Max Morin787eeed2016-06-23 10:42:07 +0200801 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200802 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200803 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000804}
805
806// ----------------------------------------------------------------------------
807// MicrophoneBoostIsAvailable
808// ----------------------------------------------------------------------------
809
Max Morin787eeed2016-06-23 10:42:07 +0200810int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200811 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200812 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000813
Max Morin787eeed2016-06-23 10:42:07 +0200814 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000815
Max Morin787eeed2016-06-23 10:42:07 +0200816 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
817 return -1;
818 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000819
Max Morin787eeed2016-06-23 10:42:07 +0200820 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200821 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200822 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000823}
824
825// ----------------------------------------------------------------------------
826// SetMicrophoneBoost
827// ----------------------------------------------------------------------------
828
Max Morin787eeed2016-06-23 10:42:07 +0200829int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200830 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200831 CHECK_INITIALIZED();
832 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000833}
834
835// ----------------------------------------------------------------------------
836// MicrophoneBoost
837// ----------------------------------------------------------------------------
838
Max Morin787eeed2016-06-23 10:42:07 +0200839int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200840 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200841 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000842
Max Morin787eeed2016-06-23 10:42:07 +0200843 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000844
Max Morin787eeed2016-06-23 10:42:07 +0200845 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
846 return -1;
847 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000848
Max Morin787eeed2016-06-23 10:42:07 +0200849 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200850 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200851 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000852}
853
854// ----------------------------------------------------------------------------
855// MicrophoneVolumeIsAvailable
856// ----------------------------------------------------------------------------
857
Max Morin787eeed2016-06-23 10:42:07 +0200858int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200859 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200860 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000861
Max Morin787eeed2016-06-23 10:42:07 +0200862 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000863
Max Morin787eeed2016-06-23 10:42:07 +0200864 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
865 return -1;
866 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000867
Max Morin787eeed2016-06-23 10:42:07 +0200868 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200869 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200870 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000871}
872
873// ----------------------------------------------------------------------------
874// SetMicrophoneVolume
875// ----------------------------------------------------------------------------
876
Max Morin787eeed2016-06-23 10:42:07 +0200877int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200878 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200879 CHECK_INITIALIZED();
880 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000881}
882
883// ----------------------------------------------------------------------------
884// MicrophoneVolume
885// ----------------------------------------------------------------------------
886
Max Morin787eeed2016-06-23 10:42:07 +0200887int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200888 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200889 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000890
Max Morin787eeed2016-06-23 10:42:07 +0200891 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000892
Max Morin787eeed2016-06-23 10:42:07 +0200893 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
894 return -1;
895 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000896
Max Morin787eeed2016-06-23 10:42:07 +0200897 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200898 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200899 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000900}
901
902// ----------------------------------------------------------------------------
903// StereoRecordingIsAvailable
904// ----------------------------------------------------------------------------
905
Max Morin787eeed2016-06-23 10:42:07 +0200906int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
907 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200908 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200909 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000910
Max Morin787eeed2016-06-23 10:42:07 +0200911 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000912
Max Morin787eeed2016-06-23 10:42:07 +0200913 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
914 return -1;
915 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000916
Max Morin787eeed2016-06-23 10:42:07 +0200917 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200918 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200919 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000920}
921
922// ----------------------------------------------------------------------------
923// SetStereoRecording
924// ----------------------------------------------------------------------------
925
Max Morin787eeed2016-06-23 10:42:07 +0200926int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200927 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200928 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000929
Max Morin787eeed2016-06-23 10:42:07 +0200930 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200931 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200932 return -1;
933 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000934
Max Morin787eeed2016-06-23 10:42:07 +0200935 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200936 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200937 return -1;
938 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000939
Max Morin787eeed2016-06-23 10:42:07 +0200940 int8_t nChannels(1);
941 if (enable) {
942 nChannels = 2;
943 }
944 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000945
Max Morin787eeed2016-06-23 10:42:07 +0200946 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000947}
948
949// ----------------------------------------------------------------------------
950// StereoRecording
951// ----------------------------------------------------------------------------
952
Max Morin787eeed2016-06-23 10:42:07 +0200953int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200954 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200955 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000956
Max Morin787eeed2016-06-23 10:42:07 +0200957 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000958
Max Morin787eeed2016-06-23 10:42:07 +0200959 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
960 return -1;
961 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000962
Max Morin787eeed2016-06-23 10:42:07 +0200963 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200964 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200965 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000966}
967
968// ----------------------------------------------------------------------------
969// SetRecordingChannel
970// ----------------------------------------------------------------------------
971
Max Morin787eeed2016-06-23 10:42:07 +0200972int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
973 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200974 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200975 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200976 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200977 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200978 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200979 }
980 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000981
Max Morin787eeed2016-06-23 10:42:07 +0200982 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000983
Max Morin787eeed2016-06-23 10:42:07 +0200984 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200985 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200986 return -1;
987 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000988
Max Morin787eeed2016-06-23 10:42:07 +0200989 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000990}
991
992// ----------------------------------------------------------------------------
993// RecordingChannel
994// ----------------------------------------------------------------------------
995
Max Morin787eeed2016-06-23 10:42:07 +0200996int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200997 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200998 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000999
Max Morin787eeed2016-06-23 10:42:07 +02001000 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001001
Max Morin787eeed2016-06-23 10:42:07 +02001002 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
1003 return -1;
1004 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001005
Max Morin787eeed2016-06-23 10:42:07 +02001006 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +02001007 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +02001008 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001009 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +02001010 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001011 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001012 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001013 }
Max Morin787eeed2016-06-23 10:42:07 +02001014 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001015}
1016
1017// ----------------------------------------------------------------------------
1018// StereoPlayoutIsAvailable
1019// ----------------------------------------------------------------------------
1020
Max Morin787eeed2016-06-23 10:42:07 +02001021int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001022 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001023 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001024
Max Morin787eeed2016-06-23 10:42:07 +02001025 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001026
Max Morin787eeed2016-06-23 10:42:07 +02001027 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1028 return -1;
1029 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001030
Max Morin787eeed2016-06-23 10:42:07 +02001031 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001032 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001033 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001034}
1035
1036// ----------------------------------------------------------------------------
1037// SetStereoPlayout
1038// ----------------------------------------------------------------------------
1039
Max Morin787eeed2016-06-23 10:42:07 +02001040int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001041 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001042 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001043
Max Morin787eeed2016-06-23 10:42:07 +02001044 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001045 LOG(LERROR)
1046 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001047 return -1;
1048 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001049
Max Morin787eeed2016-06-23 10:42:07 +02001050 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001051 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001052 return -1;
1053 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001054
Max Morin787eeed2016-06-23 10:42:07 +02001055 int8_t nChannels(1);
1056 if (enable) {
1057 nChannels = 2;
1058 }
1059 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001060
Max Morin787eeed2016-06-23 10:42:07 +02001061 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001062}
1063
1064// ----------------------------------------------------------------------------
1065// StereoPlayout
1066// ----------------------------------------------------------------------------
1067
Max Morin787eeed2016-06-23 10:42:07 +02001068int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001069 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001070 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001071
Max Morin787eeed2016-06-23 10:42:07 +02001072 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001073
Max Morin787eeed2016-06-23 10:42:07 +02001074 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1075 return -1;
1076 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001077
Max Morin787eeed2016-06-23 10:42:07 +02001078 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001079 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001080 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001081}
1082
1083// ----------------------------------------------------------------------------
1084// SetAGC
1085// ----------------------------------------------------------------------------
1086
Max Morin787eeed2016-06-23 10:42:07 +02001087int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001088 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001089 CHECK_INITIALIZED();
1090 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001091}
1092
1093// ----------------------------------------------------------------------------
1094// AGC
1095// ----------------------------------------------------------------------------
1096
Max Morin787eeed2016-06-23 10:42:07 +02001097bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001098 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001099 CHECK_INITIALIZED_BOOL();
1100 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001101}
1102
1103// ----------------------------------------------------------------------------
1104// PlayoutIsAvailable
1105// ----------------------------------------------------------------------------
1106
Max Morin787eeed2016-06-23 10:42:07 +02001107int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001108 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001109 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001110
Max Morin787eeed2016-06-23 10:42:07 +02001111 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001112
Max Morin787eeed2016-06-23 10:42:07 +02001113 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1114 return -1;
1115 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001116
Max Morin787eeed2016-06-23 10:42:07 +02001117 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001118 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001119 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001120}
1121
1122// ----------------------------------------------------------------------------
1123// RecordingIsAvailable
1124// ----------------------------------------------------------------------------
1125
Max Morin787eeed2016-06-23 10:42:07 +02001126int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001127 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001128 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001129
Max Morin787eeed2016-06-23 10:42:07 +02001130 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001131
Max Morin787eeed2016-06-23 10:42:07 +02001132 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1133 return -1;
1134 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001135
Max Morin787eeed2016-06-23 10:42:07 +02001136 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001137 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001138 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001139}
1140
1141// ----------------------------------------------------------------------------
1142// MaxMicrophoneVolume
1143// ----------------------------------------------------------------------------
1144
Max Morin787eeed2016-06-23 10:42:07 +02001145int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001146 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001147
Max Morin787eeed2016-06-23 10:42:07 +02001148 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001149
Max Morin787eeed2016-06-23 10:42:07 +02001150 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1151 return -1;
1152 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001153
Max Morin787eeed2016-06-23 10:42:07 +02001154 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001155 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001156}
1157
1158// ----------------------------------------------------------------------------
1159// MinMicrophoneVolume
1160// ----------------------------------------------------------------------------
1161
Max Morin787eeed2016-06-23 10:42:07 +02001162int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1163 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001164
Max Morin787eeed2016-06-23 10:42:07 +02001165 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001166
Max Morin787eeed2016-06-23 10:42:07 +02001167 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1168 return -1;
1169 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001170
Max Morin787eeed2016-06-23 10:42:07 +02001171 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001172 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001173}
1174
1175// ----------------------------------------------------------------------------
1176// MicrophoneVolumeStepSize
1177// ----------------------------------------------------------------------------
1178
Max Morin787eeed2016-06-23 10:42:07 +02001179int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1180 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001181 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001182 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001183
Max Morin787eeed2016-06-23 10:42:07 +02001184 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001185
Max Morin787eeed2016-06-23 10:42:07 +02001186 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1187 return -1;
1188 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001189
Max Morin787eeed2016-06-23 10:42:07 +02001190 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001191 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001192 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001193}
1194
1195// ----------------------------------------------------------------------------
1196// PlayoutDevices
1197// ----------------------------------------------------------------------------
1198
Max Morin787eeed2016-06-23 10:42:07 +02001199int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001200 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001201 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001202
Max Morin787eeed2016-06-23 10:42:07 +02001203 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001204 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001205 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001206}
1207
1208// ----------------------------------------------------------------------------
1209// SetPlayoutDevice I (II)
1210// ----------------------------------------------------------------------------
1211
Max Morin787eeed2016-06-23 10:42:07 +02001212int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001213 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001214 CHECK_INITIALIZED();
1215 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001216}
1217
1218// ----------------------------------------------------------------------------
1219// SetPlayoutDevice II (II)
1220// ----------------------------------------------------------------------------
1221
Max Morin787eeed2016-06-23 10:42:07 +02001222int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001223 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001224 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001225
Max Morin787eeed2016-06-23 10:42:07 +02001226 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001227}
1228
1229// ----------------------------------------------------------------------------
1230// PlayoutDeviceName
1231// ----------------------------------------------------------------------------
1232
pbos@webrtc.org25509882013-04-09 10:30:35 +00001233int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1234 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001235 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001236 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001237 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001238 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001239
Max Morin787eeed2016-06-23 10:42:07 +02001240 if (name == NULL) {
1241 _lastError = kAdmErrArgument;
1242 return -1;
1243 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001244
Max Morin787eeed2016-06-23 10:42:07 +02001245 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1246 return -1;
1247 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001248
Max Morin787eeed2016-06-23 10:42:07 +02001249 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001250 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001251 }
1252 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001253 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001254 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001255
Max Morin787eeed2016-06-23 10:42:07 +02001256 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001257}
1258
1259// ----------------------------------------------------------------------------
1260// RecordingDeviceName
1261// ----------------------------------------------------------------------------
1262
pbos@webrtc.org25509882013-04-09 10:30:35 +00001263int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1264 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001265 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001266 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001267 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001268 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001269
Max Morin787eeed2016-06-23 10:42:07 +02001270 if (name == NULL) {
1271 _lastError = kAdmErrArgument;
1272 return -1;
1273 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001274
Max Morin787eeed2016-06-23 10:42:07 +02001275 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1276 return -1;
1277 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001278
Max Morin787eeed2016-06-23 10:42:07 +02001279 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001280 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001281 }
1282 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001283 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001284 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001285
Max Morin787eeed2016-06-23 10:42:07 +02001286 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001287}
1288
1289// ----------------------------------------------------------------------------
1290// RecordingDevices
1291// ----------------------------------------------------------------------------
1292
Max Morin787eeed2016-06-23 10:42:07 +02001293int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001294 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001295 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001296
Max Morin787eeed2016-06-23 10:42:07 +02001297 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001298
Max Morin2c332bb2016-07-04 09:03:42 +02001299 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001300 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001301}
1302
1303// ----------------------------------------------------------------------------
1304// SetRecordingDevice I (II)
1305// ----------------------------------------------------------------------------
1306
Max Morin787eeed2016-06-23 10:42:07 +02001307int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001308 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001309 CHECK_INITIALIZED();
1310 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001311}
1312
1313// ----------------------------------------------------------------------------
1314// SetRecordingDevice II (II)
1315// ----------------------------------------------------------------------------
1316
Max Morin787eeed2016-06-23 10:42:07 +02001317int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001318 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001319 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001320
Max Morin787eeed2016-06-23 10:42:07 +02001321 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001322}
1323
1324// ----------------------------------------------------------------------------
1325// InitPlayout
1326// ----------------------------------------------------------------------------
1327
Max Morin787eeed2016-06-23 10:42:07 +02001328int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001329 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001330 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001331 if (PlayoutIsInitialized()) {
1332 return 0;
1333 }
Max Morin787eeed2016-06-23 10:42:07 +02001334 _audioDeviceBuffer.InitPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001335 int32_t result = _ptrAudioDevice->InitPlayout();
1336 LOG(INFO) << "output: " << result;
1337 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1338 static_cast<int>(result == 0));
1339 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001340}
1341
1342// ----------------------------------------------------------------------------
1343// InitRecording
1344// ----------------------------------------------------------------------------
1345
Max Morin787eeed2016-06-23 10:42:07 +02001346int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001347 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001348 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001349 if (RecordingIsInitialized()) {
1350 return 0;
1351 }
Max Morin787eeed2016-06-23 10:42:07 +02001352 _audioDeviceBuffer.InitRecording();
Max Morin84cab202016-07-01 13:35:19 +02001353 int32_t result = _ptrAudioDevice->InitRecording();
1354 LOG(INFO) << "output: " << result;
1355 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1356 static_cast<int>(result == 0));
1357 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001358}
1359
1360// ----------------------------------------------------------------------------
1361// PlayoutIsInitialized
1362// ----------------------------------------------------------------------------
1363
Max Morin787eeed2016-06-23 10:42:07 +02001364bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001365 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001366 CHECK_INITIALIZED_BOOL();
1367 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001368}
1369
1370// ----------------------------------------------------------------------------
1371// RecordingIsInitialized
1372// ----------------------------------------------------------------------------
1373
Max Morin787eeed2016-06-23 10:42:07 +02001374bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001375 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001376 CHECK_INITIALIZED_BOOL();
1377 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001378}
1379
1380// ----------------------------------------------------------------------------
1381// StartPlayout
1382// ----------------------------------------------------------------------------
1383
Max Morin787eeed2016-06-23 10:42:07 +02001384int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001385 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001386 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001387 if (Playing()) {
1388 return 0;
1389 }
Max Morin84cab202016-07-01 13:35:19 +02001390 int32_t result = _ptrAudioDevice->StartPlayout();
1391 LOG(INFO) << "output: " << result;
1392 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1393 static_cast<int>(result == 0));
1394 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001395}
1396
1397// ----------------------------------------------------------------------------
1398// StopPlayout
1399// ----------------------------------------------------------------------------
1400
Max Morin787eeed2016-06-23 10:42:07 +02001401int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001402 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001403 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001404 int32_t result = _ptrAudioDevice->StopPlayout();
1405 LOG(INFO) << "output: " << result;
1406 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1407 static_cast<int>(result == 0));
1408 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001409}
1410
1411// ----------------------------------------------------------------------------
1412// Playing
1413// ----------------------------------------------------------------------------
1414
Max Morin787eeed2016-06-23 10:42:07 +02001415bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001416 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001417 CHECK_INITIALIZED_BOOL();
1418 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001419}
1420
1421// ----------------------------------------------------------------------------
1422// StartRecording
1423// ----------------------------------------------------------------------------
1424
Max Morin787eeed2016-06-23 10:42:07 +02001425int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001426 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001427 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001428 if (Recording()) {
1429 return 0;
1430 }
Max Morin84cab202016-07-01 13:35:19 +02001431 int32_t result = _ptrAudioDevice->StartRecording();
1432 LOG(INFO) << "output: " << result;
1433 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1434 static_cast<int>(result == 0));
1435 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001436}
1437// ----------------------------------------------------------------------------
1438// StopRecording
1439// ----------------------------------------------------------------------------
1440
Max Morin787eeed2016-06-23 10:42:07 +02001441int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001442 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001443 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001444 int32_t result = _ptrAudioDevice->StopRecording();
1445 LOG(INFO) << "output: " << result;
1446 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1447 static_cast<int>(result == 0));
1448 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001449}
1450
1451// ----------------------------------------------------------------------------
1452// Recording
1453// ----------------------------------------------------------------------------
1454
Max Morin787eeed2016-06-23 10:42:07 +02001455bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001456 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001457 CHECK_INITIALIZED_BOOL();
1458 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001459}
1460
1461// ----------------------------------------------------------------------------
1462// RegisterEventObserver
1463// ----------------------------------------------------------------------------
1464
Max Morin787eeed2016-06-23 10:42:07 +02001465int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1466 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001467 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001468 CriticalSectionScoped lock(&_critSectEventCb);
1469 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001470
Max Morin787eeed2016-06-23 10:42:07 +02001471 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001472}
1473
1474// ----------------------------------------------------------------------------
1475// RegisterAudioCallback
1476// ----------------------------------------------------------------------------
1477
Max Morin787eeed2016-06-23 10:42:07 +02001478int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1479 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001480 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001481 CriticalSectionScoped lock(&_critSectAudioCb);
1482 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001483
Max Morin787eeed2016-06-23 10:42:07 +02001484 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001485}
1486
1487// ----------------------------------------------------------------------------
1488// StartRawInputFileRecording
1489// ----------------------------------------------------------------------------
1490
pbos@webrtc.org25509882013-04-09 10:30:35 +00001491int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001492 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001493 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001494 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001495
Max Morin787eeed2016-06-23 10:42:07 +02001496 if (NULL == pcmFileNameUTF8) {
1497 return -1;
1498 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001499
Max Morin787eeed2016-06-23 10:42:07 +02001500 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001501}
1502
1503// ----------------------------------------------------------------------------
1504// StopRawInputFileRecording
1505// ----------------------------------------------------------------------------
1506
Max Morin787eeed2016-06-23 10:42:07 +02001507int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001508 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001509 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001510
Max Morin787eeed2016-06-23 10:42:07 +02001511 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001512}
1513
1514// ----------------------------------------------------------------------------
1515// StartRawOutputFileRecording
1516// ----------------------------------------------------------------------------
1517
pbos@webrtc.org25509882013-04-09 10:30:35 +00001518int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001519 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001520 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001521 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001522
Max Morin787eeed2016-06-23 10:42:07 +02001523 if (NULL == pcmFileNameUTF8) {
1524 return -1;
1525 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001526
Max Morin787eeed2016-06-23 10:42:07 +02001527 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001528}
1529
1530// ----------------------------------------------------------------------------
1531// StopRawOutputFileRecording
1532// ----------------------------------------------------------------------------
1533
Max Morin787eeed2016-06-23 10:42:07 +02001534int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001535 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001536 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001537
Max Morin787eeed2016-06-23 10:42:07 +02001538 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001539}
1540
1541// ----------------------------------------------------------------------------
1542// SetPlayoutBuffer
1543// ----------------------------------------------------------------------------
1544
Max Morin787eeed2016-06-23 10:42:07 +02001545int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1546 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001547 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001548 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001549 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001550 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001551 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001552 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001553 }
Max Morin787eeed2016-06-23 10:42:07 +02001554 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001555
Max Morin787eeed2016-06-23 10:42:07 +02001556 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001557 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1558 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001559 return -1;
1560 }
1561
1562 int32_t ret(0);
1563
1564 if (kFixedBufferSize == type) {
1565 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1566 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001567 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001568 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001569 }
Max Morin787eeed2016-06-23 10:42:07 +02001570 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001571
Max Morin787eeed2016-06-23 10:42:07 +02001572 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001573 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1574 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001575 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001576
Max Morin787eeed2016-06-23 10:42:07 +02001577 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001578}
1579
1580// ----------------------------------------------------------------------------
1581// PlayoutBuffer
1582// ----------------------------------------------------------------------------
1583
Max Morin787eeed2016-06-23 10:42:07 +02001584int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1585 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001586 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001587 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001588
Max Morin787eeed2016-06-23 10:42:07 +02001589 BufferType bufType;
1590 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001591
Max Morin787eeed2016-06-23 10:42:07 +02001592 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001593 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001594 return -1;
1595 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001596
Max Morin787eeed2016-06-23 10:42:07 +02001597 *type = bufType;
1598 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001599
Max Morin2c332bb2016-07-04 09:03:42 +02001600 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001601 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001602}
1603
1604// ----------------------------------------------------------------------------
1605// PlayoutDelay
1606// ----------------------------------------------------------------------------
1607
Max Morin787eeed2016-06-23 10:42:07 +02001608int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001609 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001610 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001611
Max Morin787eeed2016-06-23 10:42:07 +02001612 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001613
Max Morin787eeed2016-06-23 10:42:07 +02001614 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001615 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001616 return -1;
1617 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001618
Max Morin787eeed2016-06-23 10:42:07 +02001619 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001620 LOG(LS_VERBOSE) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001621 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001622}
1623
1624// ----------------------------------------------------------------------------
1625// RecordingDelay
1626// ----------------------------------------------------------------------------
1627
Max Morin787eeed2016-06-23 10:42:07 +02001628int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001629 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001630 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001631
Max Morin787eeed2016-06-23 10:42:07 +02001632 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001633
Max Morin787eeed2016-06-23 10:42:07 +02001634 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001635 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001636 return -1;
1637 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001638
Max Morin787eeed2016-06-23 10:42:07 +02001639 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001640 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001641 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001642}
1643
1644// ----------------------------------------------------------------------------
1645// CPULoad
1646// ----------------------------------------------------------------------------
1647
Max Morin787eeed2016-06-23 10:42:07 +02001648int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001649 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001650 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001651
Max Morin787eeed2016-06-23 10:42:07 +02001652 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001653
Max Morin787eeed2016-06-23 10:42:07 +02001654 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001655 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001656 return -1;
1657 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001658
Max Morin787eeed2016-06-23 10:42:07 +02001659 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001660 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001661 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001662}
1663
1664// ----------------------------------------------------------------------------
1665// SetRecordingSampleRate
1666// ----------------------------------------------------------------------------
1667
Max Morin787eeed2016-06-23 10:42:07 +02001668int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1669 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001670 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001671 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001672
Max Morin787eeed2016-06-23 10:42:07 +02001673 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1674 return -1;
1675 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001676
Max Morin787eeed2016-06-23 10:42:07 +02001677 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001678}
1679
1680// ----------------------------------------------------------------------------
1681// RecordingSampleRate
1682// ----------------------------------------------------------------------------
1683
Max Morin787eeed2016-06-23 10:42:07 +02001684int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1685 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001686 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001687 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001688
Max Morin787eeed2016-06-23 10:42:07 +02001689 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001690
Max Morin787eeed2016-06-23 10:42:07 +02001691 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001692 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001693 return -1;
1694 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001695
Max Morin787eeed2016-06-23 10:42:07 +02001696 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001697 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001698 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001699}
1700
1701// ----------------------------------------------------------------------------
1702// SetPlayoutSampleRate
1703// ----------------------------------------------------------------------------
1704
Max Morin787eeed2016-06-23 10:42:07 +02001705int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1706 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001707 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001708 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001709
Max Morin787eeed2016-06-23 10:42:07 +02001710 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1711 return -1;
1712 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001713
Max Morin787eeed2016-06-23 10:42:07 +02001714 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001715}
1716
1717// ----------------------------------------------------------------------------
1718// PlayoutSampleRate
1719// ----------------------------------------------------------------------------
1720
Max Morin787eeed2016-06-23 10:42:07 +02001721int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1722 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001723 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001724 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001725
Max Morin787eeed2016-06-23 10:42:07 +02001726 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001727
Max Morin787eeed2016-06-23 10:42:07 +02001728 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001729 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001730 return -1;
1731 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001732
Max Morin787eeed2016-06-23 10:42:07 +02001733 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001734 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001735 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001736}
1737
1738// ----------------------------------------------------------------------------
1739// ResetAudioDevice
1740// ----------------------------------------------------------------------------
1741
Max Morin787eeed2016-06-23 10:42:07 +02001742int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001743 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001744 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001745
Max Morin787eeed2016-06-23 10:42:07 +02001746 if (_ptrAudioDevice->ResetAudioDevice() == -1) {
1747 return -1;
1748 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001749
Max Morin787eeed2016-06-23 10:42:07 +02001750 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001751}
1752
1753// ----------------------------------------------------------------------------
1754// SetLoudspeakerStatus
1755// ----------------------------------------------------------------------------
1756
Max Morin787eeed2016-06-23 10:42:07 +02001757int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001758 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001759 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001760
Max Morin787eeed2016-06-23 10:42:07 +02001761 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1762 return -1;
1763 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001764
Max Morin787eeed2016-06-23 10:42:07 +02001765 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001766}
1767
1768// ----------------------------------------------------------------------------
1769// GetLoudspeakerStatus
1770// ----------------------------------------------------------------------------
1771
henrikac14f5ff2015-09-23 14:08:33 +02001772int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001773 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001774 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001775 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001776 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001777 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001778 }
Max Morin2c332bb2016-07-04 09:03:42 +02001779 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001780 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001781}
1782
henrikac14f5ff2015-09-23 14:08:33 +02001783bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
Max Morin098e6c52016-06-28 09:36:25 +02001784 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001785 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001786 bool isEnabled = _ptrAudioDevice->BuiltInAECIsEnabled();
Max Morin2c332bb2016-07-04 09:03:42 +02001787 LOG(INFO) << "output: " << isEnabled;
Max Morin098e6c52016-06-28 09:36:25 +02001788 return isEnabled;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001789}
1790
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001791bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001792 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001793 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001794 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001795 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001796 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001797}
1798
henrikac14f5ff2015-09-23 14:08:33 +02001799int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001800 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001801 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001802 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001803 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001804 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001805}
1806
1807bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001808 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001809 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001810 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001811 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001812 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001813}
1814
1815int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001816 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001817 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001818 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001819 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001820 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001821}
1822
1823bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001824 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001825 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001826 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001827 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001828 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001829}
1830
1831int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001832 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001833 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001834 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001835 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001836 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001837}
1838
henrikaba35d052015-07-14 17:04:08 +02001839int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1840 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001841 LOG(INFO) << __FUNCTION__;
1842 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001843 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001844 return r;
henrikaba35d052015-07-14 17:04:08 +02001845}
1846
1847int AudioDeviceModuleImpl::GetRecordAudioParameters(
1848 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001849 LOG(INFO) << __FUNCTION__;
1850 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001851 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001852 return r;
henrikaba35d052015-07-14 17:04:08 +02001853}
1854
niklase@google.com470e71d2011-07-07 08:21:25 +00001855// ============================================================================
1856// Private Methods
1857// ============================================================================
1858
1859// ----------------------------------------------------------------------------
1860// Platform
1861// ----------------------------------------------------------------------------
1862
Max Morin787eeed2016-06-23 10:42:07 +02001863AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001864 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001865 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001866}
1867
1868// ----------------------------------------------------------------------------
1869// PlatformAudioLayer
1870// ----------------------------------------------------------------------------
1871
Max Morin787eeed2016-06-23 10:42:07 +02001872AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1873 const {
Max Morin098e6c52016-06-28 09:36:25 +02001874 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001875 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001876}
1877
1878} // namespace webrtc