blob: 45bc3a5aaf659e65e3e49d02f9ca9194720bac24 [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"
henrika918b5542016-09-19 15:44:09 +020013#include "webrtc/base/checks.h"
Peter Boström1d194412016-03-21 16:44:31 +010014#include "webrtc/base/refcount.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020015#include "webrtc/base/timeutils.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000016#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
17#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020018#include "webrtc/modules/audio_device/audio_device_generic.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000019#include "webrtc/modules/audio_device/audio_device_impl.h"
Max Morin84cab202016-07-01 13:35:19 +020020#include "webrtc/system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000022#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000023#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020026#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"
henrika918b5542016-09-19 15:44:09 +020036#include "webrtc/modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000037#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020038#if defined(LINUX_ALSA)
39#include "audio_device_alsa_linux.h"
40#endif
Tommi68898a22015-05-19 17:28:07 +020041#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020042#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020043#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000044#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020045#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000046#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020047#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000048#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000049
50#if defined(WEBRTC_DUMMY_FILE_DEVICES)
51#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
52#endif
53
pbos@webrtc.org811269d2013-07-11 13:24:38 +000054#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000055#include "webrtc/modules/audio_device/dummy/file_audio_device.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)
kthelgason6bfe49c2017-03-30 01:14:41 -0700120 : _ptrCbAudioDeviceObserver(NULL),
Max Morin787eeed2016-06-23 10:42:07 +0200121 _ptrAudioDevice(NULL),
122 _id(id),
123 _platformAudioLayer(audioLayer),
124 _lastProcessTime(rtc::TimeMillis()),
125 _platformType(kPlatformNotSupported),
126 _initialized(false),
127 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200128 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129}
130
131// ----------------------------------------------------------------------------
132// CheckPlatform
133// ----------------------------------------------------------------------------
134
Max Morin787eeed2016-06-23 10:42:07 +0200135int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200136 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
Max Morin787eeed2016-06-23 10:42:07 +0200138 // Ensure that the current platform is supported
139 //
140 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
142#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200143 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200144 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000145#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200146 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200147 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000148#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200149 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200150 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000151#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200152 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200153 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000154#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200155 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200156 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000157#endif
158
Max Morin787eeed2016-06-23 10:42:07 +0200159 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200160 LOG(LERROR) << "current platform is not supported => this module will self "
161 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200162 return -1;
163 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
Max Morin787eeed2016-06-23 10:42:07 +0200165 // Store valid output results
166 //
167 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
Max Morin787eeed2016-06-23 10:42:07 +0200169 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000170}
171
niklase@google.com470e71d2011-07-07 08:21:25 +0000172// ----------------------------------------------------------------------------
173// CreatePlatformSpecificObjects
174// ----------------------------------------------------------------------------
175
Max Morin787eeed2016-06-23 10:42:07 +0200176int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200177 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
Max Morin787eeed2016-06-23 10:42:07 +0200179 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
xians@google.combf5d2ba2011-08-16 07:44:19 +0000181#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200182 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200183 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000184#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200185 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
noahric6a355902016-08-17 15:19:50 -0700186 if (ptrAudioDevice) {
187 LOG(INFO) << "Will use file-playing dummy device.";
188 } else {
189 // Create a dummy device instead.
190 ptrAudioDevice = new AudioDeviceDummy(Id());
191 LOG(INFO) << "Dummy Audio APIs will be utilized";
192 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000193#else
Max Morin787eeed2016-06-23 10:42:07 +0200194 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
Max Morin787eeed2016-06-23 10:42:07 +0200196// Create the *Windows* implementation of the Audio Device
197//
niklase@google.com470e71d2011-07-07 08:21:25 +0000198#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200199 if ((audioLayer == kWindowsCoreAudio) ||
200 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200201 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
Max Morin787eeed2016-06-23 10:42:07 +0200203 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
204 // create *Windows Core Audio* implementation
205 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200206 LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 }
Max Morin787eeed2016-06-23 10:42:07 +0200208 }
209#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000211#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200212 // Create an Android audio manager.
213 _audioManagerAndroid.reset(new AudioManager());
214 // Select best possible combination of audio layers.
215 if (audioLayer == kPlatformDefaultAudio) {
henrika918b5542016-09-19 15:44:09 +0200216 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
217 _audioManagerAndroid->IsLowLatencyRecordSupported()) {
218 // Use OpenSL ES for both playout and recording.
219 audioLayer = kAndroidOpenSLESAudio;
220 } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
221 !_audioManagerAndroid->IsLowLatencyRecordSupported()) {
222 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200223 // low-latency output audio path.
224 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200225 } else {
henrika918b5542016-09-19 15:44:09 +0200226 // Use Java-based audio in both directions when low-latency output is
227 // not supported.
Max Morin787eeed2016-06-23 10:42:07 +0200228 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000229 }
Max Morin787eeed2016-06-23 10:42:07 +0200230 }
231 AudioManager* audio_manager = _audioManagerAndroid.get();
232 if (audioLayer == kAndroidJavaAudio) {
233 // Java audio for both input and output audio.
234 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
235 audioLayer, audio_manager);
henrika918b5542016-09-19 15:44:09 +0200236 } else if (audioLayer == kAndroidOpenSLESAudio) {
237 // OpenSL ES based audio for both input and output audio.
238 ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
239 audioLayer, audio_manager);
Max Morin787eeed2016-06-23 10:42:07 +0200240 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
241 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
242 // This combination provides low-latency output audio and at the same
243 // time support for HW AEC using the AudioRecord Java API.
244 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
245 audioLayer, audio_manager);
246 } else {
247 // Invalid audio layer.
henrika918b5542016-09-19 15:44:09 +0200248 ptrAudioDevice = nullptr;
Max Morin787eeed2016-06-23 10:42:07 +0200249 }
250// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
Max Morin787eeed2016-06-23 10:42:07 +0200252// Create the *Linux* implementation of the Audio Device
253//
niklase@google.com470e71d2011-07-07 08:21:25 +0000254#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200255 if ((audioLayer == kLinuxPulseAudio) ||
256 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000257#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200258 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000259
Max Morin787eeed2016-06-23 10:42:07 +0200260 // create *Linux PulseAudio* implementation
261 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200262 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200263 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200264 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200265 } else {
266 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000267#endif
268#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200269 // create *Linux ALSA Audio* implementation
270 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
271 if (ptrAudioDevice != NULL) {
272 // Pulse Audio was not supported => revert to ALSA instead
273 _platformAudioLayer =
274 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200275 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
276 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200277 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000278#endif
279#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 }
Max Morin787eeed2016-06-23 10:42:07 +0200281#endif
282 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000283#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200284 // create *Linux ALSA Audio* implementation
285 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200286 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000287#endif
Max Morin787eeed2016-06-23 10:42:07 +0200288 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000289#endif // #if defined(WEBRTC_LINUX)
290
Max Morin787eeed2016-06-23 10:42:07 +0200291// Create the *iPhone* implementation of the Audio Device
292//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000293#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200294 if (audioLayer == kPlatformDefaultAudio) {
295 // Create iOS Audio Device implementation.
296 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200297 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200298 }
299// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
Max Morin787eeed2016-06-23 10:42:07 +0200301// Create the *Mac* implementation of the Audio Device
302//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000303#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200304 if (audioLayer == kPlatformDefaultAudio) {
305 // Create *Mac Audio* implementation
306 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200307 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200308 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000309#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
Max Morin787eeed2016-06-23 10:42:07 +0200311 // Create the *Dummy* implementation of the Audio Device
312 // Available for all platforms
313 //
314 if (audioLayer == kDummyAudio) {
315 // Create *Dummy Audio* implementation
316 assert(!ptrAudioDevice);
317 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200318 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200319 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000320#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000321
Max Morin787eeed2016-06-23 10:42:07 +0200322 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200323 LOG(LERROR)
324 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200325 return -1;
326 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000327
Max Morin787eeed2016-06-23 10:42:07 +0200328 // Store valid output pointers
329 //
330 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
Max Morin787eeed2016-06-23 10:42:07 +0200332 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000333}
334
335// ----------------------------------------------------------------------------
336// AttachAudioBuffer
337//
338// Install "bridge" between the platform implemetation and the generic
339// implementation. The "child" shall set the native sampling rate and the
340// number of channels in this function call.
341// ----------------------------------------------------------------------------
342
Max Morin787eeed2016-06-23 10:42:07 +0200343int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200344 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
Max Morin787eeed2016-06-23 10:42:07 +0200346 _audioDeviceBuffer.SetId(_id);
347 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
348 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000349}
350
351// ----------------------------------------------------------------------------
352// ~AudioDeviceModuleImpl - dtor
353// ----------------------------------------------------------------------------
354
Max Morin787eeed2016-06-23 10:42:07 +0200355AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200356 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200357 if (_ptrAudioDevice) {
358 delete _ptrAudioDevice;
359 _ptrAudioDevice = NULL;
360 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000361}
362
363// ============================================================================
364// Module
365// ============================================================================
366
367// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000368// Module::TimeUntilNextProcess
369//
370// Returns the number of milliseconds until the module want a worker thread
371// to call Process().
372// ----------------------------------------------------------------------------
373
Max Morin787eeed2016-06-23 10:42:07 +0200374int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
375 int64_t now = rtc::TimeMillis();
376 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
377 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000378}
379
380// ----------------------------------------------------------------------------
381// Module::Process
382//
383// Check for posted error and warning reports. Generate callbacks if
384// new reports exists.
385// ----------------------------------------------------------------------------
386
Max Morin787eeed2016-06-23 10:42:07 +0200387void AudioDeviceModuleImpl::Process() {
388 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000389
Max Morin787eeed2016-06-23 10:42:07 +0200390 // kPlayoutWarning
391 if (_ptrAudioDevice->PlayoutWarning()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700392 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200393 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200394 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200395 _ptrCbAudioDeviceObserver->OnWarningIsReported(
396 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000397 }
Max Morin787eeed2016-06-23 10:42:07 +0200398 _ptrAudioDevice->ClearPlayoutWarning();
399 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000400
Max Morin787eeed2016-06-23 10:42:07 +0200401 // kPlayoutError
402 if (_ptrAudioDevice->PlayoutError()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700403 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200404 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200405 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200406 _ptrCbAudioDeviceObserver->OnErrorIsReported(
407 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000408 }
Max Morin787eeed2016-06-23 10:42:07 +0200409 _ptrAudioDevice->ClearPlayoutError();
410 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000411
Max Morin787eeed2016-06-23 10:42:07 +0200412 // kRecordingWarning
413 if (_ptrAudioDevice->RecordingWarning()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700414 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200415 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200416 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200417 _ptrCbAudioDeviceObserver->OnWarningIsReported(
418 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000419 }
Max Morin787eeed2016-06-23 10:42:07 +0200420 _ptrAudioDevice->ClearRecordingWarning();
421 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000422
Max Morin787eeed2016-06-23 10:42:07 +0200423 // kRecordingError
424 if (_ptrAudioDevice->RecordingError()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700425 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200426 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200427 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200428 _ptrCbAudioDeviceObserver->OnErrorIsReported(
429 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 }
Max Morin787eeed2016-06-23 10:42:07 +0200431 _ptrAudioDevice->ClearRecordingError();
432 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000433}
434
435// ============================================================================
436// Public API
437// ============================================================================
438
439// ----------------------------------------------------------------------------
440// ActiveAudioLayer
441// ----------------------------------------------------------------------------
442
henrikab2619892015-05-18 16:49:16 +0200443int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200444 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200445 AudioLayer activeAudio;
446 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
447 return -1;
448 }
449 *audioLayer = activeAudio;
450 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000451}
452
453// ----------------------------------------------------------------------------
454// LastError
455// ----------------------------------------------------------------------------
456
Max Morin787eeed2016-06-23 10:42:07 +0200457AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200458 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200459 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000460}
461
462// ----------------------------------------------------------------------------
463// Init
464// ----------------------------------------------------------------------------
465
Max Morin787eeed2016-06-23 10:42:07 +0200466int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200467 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200468 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000469 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200470 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200471
Max Morin84cab202016-07-01 13:35:19 +0200472 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
473 RTC_HISTOGRAM_ENUMERATION(
474 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
475 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
476 if (status != AudioDeviceGeneric::InitStatus::OK) {
477 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200478 return -1;
479 }
480
481 _initialized = true;
482 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000483}
484
485// ----------------------------------------------------------------------------
486// Terminate
487// ----------------------------------------------------------------------------
488
Max Morin787eeed2016-06-23 10:42:07 +0200489int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200490 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200491 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000492 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200493
494 if (_ptrAudioDevice->Terminate() == -1) {
495 return -1;
496 }
497
498 _initialized = false;
499 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000500}
501
502// ----------------------------------------------------------------------------
503// Initialized
504// ----------------------------------------------------------------------------
505
Max Morin787eeed2016-06-23 10:42:07 +0200506bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200507 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200508 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000509}
510
511// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000512// InitSpeaker
513// ----------------------------------------------------------------------------
514
Max Morin787eeed2016-06-23 10:42:07 +0200515int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200516 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200517 CHECK_INITIALIZED();
518 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000519}
520
521// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000522// InitMicrophone
523// ----------------------------------------------------------------------------
524
Max Morin787eeed2016-06-23 10:42:07 +0200525int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200526 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200527 CHECK_INITIALIZED();
528 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000529}
530
531// ----------------------------------------------------------------------------
532// SpeakerVolumeIsAvailable
533// ----------------------------------------------------------------------------
534
Max Morin787eeed2016-06-23 10:42:07 +0200535int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200536 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200537 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000538
Max Morin787eeed2016-06-23 10:42:07 +0200539 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000540
Max Morin787eeed2016-06-23 10:42:07 +0200541 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
542 return -1;
543 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000544
Max Morin787eeed2016-06-23 10:42:07 +0200545 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200546 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200547 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000548}
549
550// ----------------------------------------------------------------------------
551// SetSpeakerVolume
552// ----------------------------------------------------------------------------
553
Max Morin787eeed2016-06-23 10:42:07 +0200554int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200555 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200556 CHECK_INITIALIZED();
557 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000558}
559
560// ----------------------------------------------------------------------------
561// SpeakerVolume
562// ----------------------------------------------------------------------------
563
Max Morin787eeed2016-06-23 10:42:07 +0200564int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200565 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200566 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000567
Max Morin787eeed2016-06-23 10:42:07 +0200568 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000569
Max Morin787eeed2016-06-23 10:42:07 +0200570 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
571 return -1;
572 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000573
Max Morin787eeed2016-06-23 10:42:07 +0200574 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200575 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200576 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000577}
578
579// ----------------------------------------------------------------------------
580// SetWaveOutVolume
581// ----------------------------------------------------------------------------
582
Max Morin787eeed2016-06-23 10:42:07 +0200583int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
584 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200585 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200586 CHECK_INITIALIZED();
587 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000588}
589
590// ----------------------------------------------------------------------------
591// WaveOutVolume
592// ----------------------------------------------------------------------------
593
Max Morin787eeed2016-06-23 10:42:07 +0200594int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
595 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200596 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200597 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000598
Max Morin787eeed2016-06-23 10:42:07 +0200599 uint16_t volLeft(0);
600 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000601
Max Morin787eeed2016-06-23 10:42:07 +0200602 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
603 return -1;
604 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000605
Max Morin787eeed2016-06-23 10:42:07 +0200606 *volumeLeft = volLeft;
607 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200608 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000609
Max Morin787eeed2016-06-23 10:42:07 +0200610 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000611}
612
613// ----------------------------------------------------------------------------
614// SpeakerIsInitialized
615// ----------------------------------------------------------------------------
616
Max Morin787eeed2016-06-23 10:42:07 +0200617bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200618 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200619 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000620
Max Morin787eeed2016-06-23 10:42:07 +0200621 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200622 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200623 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000624}
625
626// ----------------------------------------------------------------------------
627// MicrophoneIsInitialized
628// ----------------------------------------------------------------------------
629
Max Morin787eeed2016-06-23 10:42:07 +0200630bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200631 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200632 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000633
Max Morin787eeed2016-06-23 10:42:07 +0200634 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200635 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200636 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000637}
638
639// ----------------------------------------------------------------------------
640// MaxSpeakerVolume
641// ----------------------------------------------------------------------------
642
Max Morin787eeed2016-06-23 10:42:07 +0200643int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
644 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000645
Max Morin787eeed2016-06-23 10:42:07 +0200646 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000647
Max Morin787eeed2016-06-23 10:42:07 +0200648 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
649 return -1;
650 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000651
Max Morin787eeed2016-06-23 10:42:07 +0200652 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200653 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000654}
655
656// ----------------------------------------------------------------------------
657// MinSpeakerVolume
658// ----------------------------------------------------------------------------
659
Max Morin787eeed2016-06-23 10:42:07 +0200660int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
661 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000662
Max Morin787eeed2016-06-23 10:42:07 +0200663 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000664
Max Morin787eeed2016-06-23 10:42:07 +0200665 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
666 return -1;
667 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000668
Max Morin787eeed2016-06-23 10:42:07 +0200669 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200670 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000671}
672
673// ----------------------------------------------------------------------------
674// SpeakerVolumeStepSize
675// ----------------------------------------------------------------------------
676
Max Morin787eeed2016-06-23 10:42:07 +0200677int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200678 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200679 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000680
Max Morin787eeed2016-06-23 10:42:07 +0200681 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000682
Max Morin787eeed2016-06-23 10:42:07 +0200683 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200684 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200685 return -1;
686 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000687
Max Morin787eeed2016-06-23 10:42:07 +0200688 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200689 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200690 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000691}
692
693// ----------------------------------------------------------------------------
694// SpeakerMuteIsAvailable
695// ----------------------------------------------------------------------------
696
Max Morin787eeed2016-06-23 10:42:07 +0200697int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200698 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200699 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000700
Max Morin787eeed2016-06-23 10:42:07 +0200701 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000702
Max Morin787eeed2016-06-23 10:42:07 +0200703 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
704 return -1;
705 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000706
Max Morin787eeed2016-06-23 10:42:07 +0200707 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200708 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200709 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000710}
711
712// ----------------------------------------------------------------------------
713// SetSpeakerMute
714// ----------------------------------------------------------------------------
715
Max Morin787eeed2016-06-23 10:42:07 +0200716int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200717 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200718 CHECK_INITIALIZED();
719 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000720}
721
722// ----------------------------------------------------------------------------
723// SpeakerMute
724// ----------------------------------------------------------------------------
725
Max Morin787eeed2016-06-23 10:42:07 +0200726int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200727 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200728 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000729
Max Morin787eeed2016-06-23 10:42:07 +0200730 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000731
Max Morin787eeed2016-06-23 10:42:07 +0200732 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
733 return -1;
734 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000735
Max Morin787eeed2016-06-23 10:42:07 +0200736 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200737 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200738 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000739}
740
741// ----------------------------------------------------------------------------
742// MicrophoneMuteIsAvailable
743// ----------------------------------------------------------------------------
744
Max Morin787eeed2016-06-23 10:42:07 +0200745int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200746 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200747 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000748
Max Morin787eeed2016-06-23 10:42:07 +0200749 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000750
Max Morin787eeed2016-06-23 10:42:07 +0200751 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
752 return -1;
753 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000754
Max Morin787eeed2016-06-23 10:42:07 +0200755 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200756 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200757 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000758}
759
760// ----------------------------------------------------------------------------
761// SetMicrophoneMute
762// ----------------------------------------------------------------------------
763
Max Morin787eeed2016-06-23 10:42:07 +0200764int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200765 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200766 CHECK_INITIALIZED();
767 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000768}
769
770// ----------------------------------------------------------------------------
771// MicrophoneMute
772// ----------------------------------------------------------------------------
773
Max Morin787eeed2016-06-23 10:42:07 +0200774int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200775 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200776 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000777
Max Morin787eeed2016-06-23 10:42:07 +0200778 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000779
Max Morin787eeed2016-06-23 10:42:07 +0200780 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
781 return -1;
782 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000783
Max Morin787eeed2016-06-23 10:42:07 +0200784 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200785 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200786 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000787}
788
789// ----------------------------------------------------------------------------
790// MicrophoneBoostIsAvailable
791// ----------------------------------------------------------------------------
792
Max Morin787eeed2016-06-23 10:42:07 +0200793int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200794 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200795 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000796
Max Morin787eeed2016-06-23 10:42:07 +0200797 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000798
Max Morin787eeed2016-06-23 10:42:07 +0200799 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
800 return -1;
801 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000802
Max Morin787eeed2016-06-23 10:42:07 +0200803 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200804 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200805 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000806}
807
808// ----------------------------------------------------------------------------
809// SetMicrophoneBoost
810// ----------------------------------------------------------------------------
811
Max Morin787eeed2016-06-23 10:42:07 +0200812int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200813 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200814 CHECK_INITIALIZED();
815 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000816}
817
818// ----------------------------------------------------------------------------
819// MicrophoneBoost
820// ----------------------------------------------------------------------------
821
Max Morin787eeed2016-06-23 10:42:07 +0200822int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200823 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200824 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000825
Max Morin787eeed2016-06-23 10:42:07 +0200826 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000827
Max Morin787eeed2016-06-23 10:42:07 +0200828 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
829 return -1;
830 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000831
Max Morin787eeed2016-06-23 10:42:07 +0200832 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200833 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200834 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000835}
836
837// ----------------------------------------------------------------------------
838// MicrophoneVolumeIsAvailable
839// ----------------------------------------------------------------------------
840
Max Morin787eeed2016-06-23 10:42:07 +0200841int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200842 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200843 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000844
Max Morin787eeed2016-06-23 10:42:07 +0200845 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000846
Max Morin787eeed2016-06-23 10:42:07 +0200847 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
848 return -1;
849 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000850
Max Morin787eeed2016-06-23 10:42:07 +0200851 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200852 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200853 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000854}
855
856// ----------------------------------------------------------------------------
857// SetMicrophoneVolume
858// ----------------------------------------------------------------------------
859
Max Morin787eeed2016-06-23 10:42:07 +0200860int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200861 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200862 CHECK_INITIALIZED();
863 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000864}
865
866// ----------------------------------------------------------------------------
867// MicrophoneVolume
868// ----------------------------------------------------------------------------
869
Max Morin787eeed2016-06-23 10:42:07 +0200870int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200871 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200872 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000873
Max Morin787eeed2016-06-23 10:42:07 +0200874 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000875
Max Morin787eeed2016-06-23 10:42:07 +0200876 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
877 return -1;
878 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000879
Max Morin787eeed2016-06-23 10:42:07 +0200880 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200881 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200882 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000883}
884
885// ----------------------------------------------------------------------------
886// StereoRecordingIsAvailable
887// ----------------------------------------------------------------------------
888
Max Morin787eeed2016-06-23 10:42:07 +0200889int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
890 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200891 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200892 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000893
Max Morin787eeed2016-06-23 10:42:07 +0200894 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000895
Max Morin787eeed2016-06-23 10:42:07 +0200896 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
897 return -1;
898 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000899
Max Morin787eeed2016-06-23 10:42:07 +0200900 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200901 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200902 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000903}
904
905// ----------------------------------------------------------------------------
906// SetStereoRecording
907// ----------------------------------------------------------------------------
908
Max Morin787eeed2016-06-23 10:42:07 +0200909int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200910 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200911 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000912
Max Morin787eeed2016-06-23 10:42:07 +0200913 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200914 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200915 return -1;
916 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000917
Max Morin787eeed2016-06-23 10:42:07 +0200918 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200919 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200920 return -1;
921 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000922
Max Morin787eeed2016-06-23 10:42:07 +0200923 int8_t nChannels(1);
924 if (enable) {
925 nChannels = 2;
926 }
927 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000928
Max Morin787eeed2016-06-23 10:42:07 +0200929 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000930}
931
932// ----------------------------------------------------------------------------
933// StereoRecording
934// ----------------------------------------------------------------------------
935
Max Morin787eeed2016-06-23 10:42:07 +0200936int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200937 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200938 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000939
Max Morin787eeed2016-06-23 10:42:07 +0200940 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000941
Max Morin787eeed2016-06-23 10:42:07 +0200942 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
943 return -1;
944 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000945
Max Morin787eeed2016-06-23 10:42:07 +0200946 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200947 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200948 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000949}
950
951// ----------------------------------------------------------------------------
952// SetRecordingChannel
953// ----------------------------------------------------------------------------
954
Max Morin787eeed2016-06-23 10:42:07 +0200955int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
956 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200957 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200958 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200959 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200960 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200961 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200962 }
963 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000964
Max Morin787eeed2016-06-23 10:42:07 +0200965 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000966
Max Morin787eeed2016-06-23 10:42:07 +0200967 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200968 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200969 return -1;
970 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000971
Max Morin787eeed2016-06-23 10:42:07 +0200972 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000973}
974
975// ----------------------------------------------------------------------------
976// RecordingChannel
977// ----------------------------------------------------------------------------
978
Max Morin787eeed2016-06-23 10:42:07 +0200979int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200980 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200981 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000982
Max Morin787eeed2016-06-23 10:42:07 +0200983 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000984
Max Morin787eeed2016-06-23 10:42:07 +0200985 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
986 return -1;
987 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000988
Max Morin787eeed2016-06-23 10:42:07 +0200989 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200990 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +0200991 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200992 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +0200993 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200994 } else {
Max Morin2c332bb2016-07-04 09:03:42 +0200995 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200996 }
Max Morin787eeed2016-06-23 10:42:07 +0200997 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000998}
999
1000// ----------------------------------------------------------------------------
1001// StereoPlayoutIsAvailable
1002// ----------------------------------------------------------------------------
1003
Max Morin787eeed2016-06-23 10:42:07 +02001004int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001005 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001006 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001007
Max Morin787eeed2016-06-23 10:42:07 +02001008 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001009
Max Morin787eeed2016-06-23 10:42:07 +02001010 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1011 return -1;
1012 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001013
Max Morin787eeed2016-06-23 10:42:07 +02001014 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001015 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001016 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001017}
1018
1019// ----------------------------------------------------------------------------
1020// SetStereoPlayout
1021// ----------------------------------------------------------------------------
1022
Max Morin787eeed2016-06-23 10:42:07 +02001023int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001024 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001025 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001026
Max Morin787eeed2016-06-23 10:42:07 +02001027 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001028 LOG(LERROR)
1029 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001030 return -1;
1031 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001032
Max Morin787eeed2016-06-23 10:42:07 +02001033 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001034 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001035 return -1;
1036 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001037
Max Morin787eeed2016-06-23 10:42:07 +02001038 int8_t nChannels(1);
1039 if (enable) {
1040 nChannels = 2;
1041 }
1042 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001043
Max Morin787eeed2016-06-23 10:42:07 +02001044 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001045}
1046
1047// ----------------------------------------------------------------------------
1048// StereoPlayout
1049// ----------------------------------------------------------------------------
1050
Max Morin787eeed2016-06-23 10:42:07 +02001051int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001052 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001053 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001054
Max Morin787eeed2016-06-23 10:42:07 +02001055 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001056
Max Morin787eeed2016-06-23 10:42:07 +02001057 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1058 return -1;
1059 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001060
Max Morin787eeed2016-06-23 10:42:07 +02001061 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001062 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001063 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001064}
1065
1066// ----------------------------------------------------------------------------
1067// SetAGC
1068// ----------------------------------------------------------------------------
1069
Max Morin787eeed2016-06-23 10:42:07 +02001070int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001071 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001072 CHECK_INITIALIZED();
1073 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001074}
1075
1076// ----------------------------------------------------------------------------
1077// AGC
1078// ----------------------------------------------------------------------------
1079
Max Morin787eeed2016-06-23 10:42:07 +02001080bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001081 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001082 CHECK_INITIALIZED_BOOL();
1083 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001084}
1085
1086// ----------------------------------------------------------------------------
1087// PlayoutIsAvailable
1088// ----------------------------------------------------------------------------
1089
Max Morin787eeed2016-06-23 10:42:07 +02001090int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001091 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001092 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001093
Max Morin787eeed2016-06-23 10:42:07 +02001094 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001095
Max Morin787eeed2016-06-23 10:42:07 +02001096 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1097 return -1;
1098 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001099
Max Morin787eeed2016-06-23 10:42:07 +02001100 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001101 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001102 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001103}
1104
1105// ----------------------------------------------------------------------------
1106// RecordingIsAvailable
1107// ----------------------------------------------------------------------------
1108
Max Morin787eeed2016-06-23 10:42:07 +02001109int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001110 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001111 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001112
Max Morin787eeed2016-06-23 10:42:07 +02001113 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001114
Max Morin787eeed2016-06-23 10:42:07 +02001115 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1116 return -1;
1117 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001118
Max Morin787eeed2016-06-23 10:42:07 +02001119 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001120 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001121 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001122}
1123
1124// ----------------------------------------------------------------------------
1125// MaxMicrophoneVolume
1126// ----------------------------------------------------------------------------
1127
Max Morin787eeed2016-06-23 10:42:07 +02001128int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001129 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001130
Max Morin787eeed2016-06-23 10:42:07 +02001131 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001132
Max Morin787eeed2016-06-23 10:42:07 +02001133 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1134 return -1;
1135 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001136
Max Morin787eeed2016-06-23 10:42:07 +02001137 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001138 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001139}
1140
1141// ----------------------------------------------------------------------------
1142// MinMicrophoneVolume
1143// ----------------------------------------------------------------------------
1144
Max Morin787eeed2016-06-23 10:42:07 +02001145int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1146 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001147
Max Morin787eeed2016-06-23 10:42:07 +02001148 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001149
Max Morin787eeed2016-06-23 10:42:07 +02001150 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1151 return -1;
1152 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001153
Max Morin787eeed2016-06-23 10:42:07 +02001154 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001155 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001156}
1157
1158// ----------------------------------------------------------------------------
1159// MicrophoneVolumeStepSize
1160// ----------------------------------------------------------------------------
1161
Max Morin787eeed2016-06-23 10:42:07 +02001162int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1163 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001164 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001165 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001166
Max Morin787eeed2016-06-23 10:42:07 +02001167 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001168
Max Morin787eeed2016-06-23 10:42:07 +02001169 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1170 return -1;
1171 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001172
Max Morin787eeed2016-06-23 10:42:07 +02001173 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001174 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001175 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001176}
1177
1178// ----------------------------------------------------------------------------
1179// PlayoutDevices
1180// ----------------------------------------------------------------------------
1181
Max Morin787eeed2016-06-23 10:42:07 +02001182int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001183 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001184 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001185
Max Morin787eeed2016-06-23 10:42:07 +02001186 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001187 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001188 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001189}
1190
1191// ----------------------------------------------------------------------------
1192// SetPlayoutDevice I (II)
1193// ----------------------------------------------------------------------------
1194
Max Morin787eeed2016-06-23 10:42:07 +02001195int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001196 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001197 CHECK_INITIALIZED();
1198 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001199}
1200
1201// ----------------------------------------------------------------------------
1202// SetPlayoutDevice II (II)
1203// ----------------------------------------------------------------------------
1204
Max Morin787eeed2016-06-23 10:42:07 +02001205int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001206 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001207 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001208
Max Morin787eeed2016-06-23 10:42:07 +02001209 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001210}
1211
1212// ----------------------------------------------------------------------------
1213// PlayoutDeviceName
1214// ----------------------------------------------------------------------------
1215
pbos@webrtc.org25509882013-04-09 10:30:35 +00001216int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1217 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001218 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001219 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001220 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001221 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001222
Max Morin787eeed2016-06-23 10:42:07 +02001223 if (name == NULL) {
1224 _lastError = kAdmErrArgument;
1225 return -1;
1226 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001227
Max Morin787eeed2016-06-23 10:42:07 +02001228 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1229 return -1;
1230 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001231
Max Morin787eeed2016-06-23 10:42:07 +02001232 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001233 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001234 }
1235 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001236 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001237 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001238
Max Morin787eeed2016-06-23 10:42:07 +02001239 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001240}
1241
1242// ----------------------------------------------------------------------------
1243// RecordingDeviceName
1244// ----------------------------------------------------------------------------
1245
pbos@webrtc.org25509882013-04-09 10:30:35 +00001246int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1247 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001248 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001249 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001250 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001251 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001252
Max Morin787eeed2016-06-23 10:42:07 +02001253 if (name == NULL) {
1254 _lastError = kAdmErrArgument;
1255 return -1;
1256 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001257
Max Morin787eeed2016-06-23 10:42:07 +02001258 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1259 return -1;
1260 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001261
Max Morin787eeed2016-06-23 10:42:07 +02001262 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001263 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001264 }
1265 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001266 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001267 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001268
Max Morin787eeed2016-06-23 10:42:07 +02001269 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001270}
1271
1272// ----------------------------------------------------------------------------
1273// RecordingDevices
1274// ----------------------------------------------------------------------------
1275
Max Morin787eeed2016-06-23 10:42:07 +02001276int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001277 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001278 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001279
Max Morin787eeed2016-06-23 10:42:07 +02001280 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001281
Max Morin2c332bb2016-07-04 09:03:42 +02001282 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001283 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001284}
1285
1286// ----------------------------------------------------------------------------
1287// SetRecordingDevice I (II)
1288// ----------------------------------------------------------------------------
1289
Max Morin787eeed2016-06-23 10:42:07 +02001290int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001291 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001292 CHECK_INITIALIZED();
1293 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001294}
1295
1296// ----------------------------------------------------------------------------
1297// SetRecordingDevice II (II)
1298// ----------------------------------------------------------------------------
1299
Max Morin787eeed2016-06-23 10:42:07 +02001300int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001301 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001302 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001303
Max Morin787eeed2016-06-23 10:42:07 +02001304 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001305}
1306
1307// ----------------------------------------------------------------------------
1308// InitPlayout
1309// ----------------------------------------------------------------------------
1310
Max Morin787eeed2016-06-23 10:42:07 +02001311int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001312 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001313 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001314 if (PlayoutIsInitialized()) {
1315 return 0;
1316 }
Max Morin84cab202016-07-01 13:35:19 +02001317 int32_t result = _ptrAudioDevice->InitPlayout();
1318 LOG(INFO) << "output: " << result;
1319 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1320 static_cast<int>(result == 0));
1321 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001322}
1323
1324// ----------------------------------------------------------------------------
1325// InitRecording
1326// ----------------------------------------------------------------------------
1327
Max Morin787eeed2016-06-23 10:42:07 +02001328int32_t AudioDeviceModuleImpl::InitRecording() {
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 (RecordingIsInitialized()) {
1332 return 0;
1333 }
Max Morin84cab202016-07-01 13:35:19 +02001334 int32_t result = _ptrAudioDevice->InitRecording();
1335 LOG(INFO) << "output: " << result;
1336 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1337 static_cast<int>(result == 0));
1338 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001339}
1340
1341// ----------------------------------------------------------------------------
1342// PlayoutIsInitialized
1343// ----------------------------------------------------------------------------
1344
Max Morin787eeed2016-06-23 10:42:07 +02001345bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001346 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001347 CHECK_INITIALIZED_BOOL();
1348 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001349}
1350
1351// ----------------------------------------------------------------------------
1352// RecordingIsInitialized
1353// ----------------------------------------------------------------------------
1354
Max Morin787eeed2016-06-23 10:42:07 +02001355bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001356 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001357 CHECK_INITIALIZED_BOOL();
1358 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001359}
1360
1361// ----------------------------------------------------------------------------
1362// StartPlayout
1363// ----------------------------------------------------------------------------
1364
Max Morin787eeed2016-06-23 10:42:07 +02001365int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001366 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001367 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001368 if (Playing()) {
1369 return 0;
1370 }
henrikaba156cf2016-10-31 08:18:50 -07001371 _audioDeviceBuffer.StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001372 int32_t result = _ptrAudioDevice->StartPlayout();
1373 LOG(INFO) << "output: " << result;
1374 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1375 static_cast<int>(result == 0));
1376 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001377}
1378
1379// ----------------------------------------------------------------------------
1380// StopPlayout
1381// ----------------------------------------------------------------------------
1382
Max Morin787eeed2016-06-23 10:42:07 +02001383int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001384 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001385 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001386 int32_t result = _ptrAudioDevice->StopPlayout();
henrikaba156cf2016-10-31 08:18:50 -07001387 _audioDeviceBuffer.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001388 LOG(INFO) << "output: " << result;
1389 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1390 static_cast<int>(result == 0));
1391 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001392}
1393
1394// ----------------------------------------------------------------------------
1395// Playing
1396// ----------------------------------------------------------------------------
1397
Max Morin787eeed2016-06-23 10:42:07 +02001398bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001399 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001400 CHECK_INITIALIZED_BOOL();
1401 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001402}
1403
1404// ----------------------------------------------------------------------------
1405// StartRecording
1406// ----------------------------------------------------------------------------
1407
Max Morin787eeed2016-06-23 10:42:07 +02001408int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001409 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001410 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001411 if (Recording()) {
1412 return 0;
1413 }
henrikaba156cf2016-10-31 08:18:50 -07001414 _audioDeviceBuffer.StartRecording();
Max Morin84cab202016-07-01 13:35:19 +02001415 int32_t result = _ptrAudioDevice->StartRecording();
1416 LOG(INFO) << "output: " << result;
1417 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1418 static_cast<int>(result == 0));
1419 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001420}
1421// ----------------------------------------------------------------------------
1422// StopRecording
1423// ----------------------------------------------------------------------------
1424
Max Morin787eeed2016-06-23 10:42:07 +02001425int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001426 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001427 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001428 int32_t result = _ptrAudioDevice->StopRecording();
henrikaba156cf2016-10-31 08:18:50 -07001429 _audioDeviceBuffer.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +02001430 LOG(INFO) << "output: " << result;
1431 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1432 static_cast<int>(result == 0));
1433 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001434}
1435
1436// ----------------------------------------------------------------------------
1437// Recording
1438// ----------------------------------------------------------------------------
1439
Max Morin787eeed2016-06-23 10:42:07 +02001440bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001441 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001442 CHECK_INITIALIZED_BOOL();
1443 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001444}
1445
1446// ----------------------------------------------------------------------------
1447// RegisterEventObserver
1448// ----------------------------------------------------------------------------
1449
Max Morin787eeed2016-06-23 10:42:07 +02001450int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1451 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001452 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001453 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +02001454 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001455
Max Morin787eeed2016-06-23 10:42:07 +02001456 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001457}
1458
1459// ----------------------------------------------------------------------------
1460// RegisterAudioCallback
1461// ----------------------------------------------------------------------------
1462
Max Morin787eeed2016-06-23 10:42:07 +02001463int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1464 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001465 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001466 rtc::CritScope lock(&_critSectAudioCb);
henrikaf5022222016-11-07 15:56:59 +01001467 return _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001468}
1469
1470// ----------------------------------------------------------------------------
1471// StartRawInputFileRecording
1472// ----------------------------------------------------------------------------
1473
pbos@webrtc.org25509882013-04-09 10:30:35 +00001474int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001475 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001476 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001477 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001478
Max Morin787eeed2016-06-23 10:42:07 +02001479 if (NULL == pcmFileNameUTF8) {
1480 return -1;
1481 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001482
Max Morin787eeed2016-06-23 10:42:07 +02001483 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001484}
1485
1486// ----------------------------------------------------------------------------
1487// StopRawInputFileRecording
1488// ----------------------------------------------------------------------------
1489
Max Morin787eeed2016-06-23 10:42:07 +02001490int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001491 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001492 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001493
Max Morin787eeed2016-06-23 10:42:07 +02001494 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001495}
1496
1497// ----------------------------------------------------------------------------
1498// StartRawOutputFileRecording
1499// ----------------------------------------------------------------------------
1500
pbos@webrtc.org25509882013-04-09 10:30:35 +00001501int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001502 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001503 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001504 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001505
Max Morin787eeed2016-06-23 10:42:07 +02001506 if (NULL == pcmFileNameUTF8) {
1507 return -1;
1508 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001509
Max Morin787eeed2016-06-23 10:42:07 +02001510 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001511}
1512
1513// ----------------------------------------------------------------------------
1514// StopRawOutputFileRecording
1515// ----------------------------------------------------------------------------
1516
Max Morin787eeed2016-06-23 10:42:07 +02001517int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001518 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001519 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001520
Max Morin787eeed2016-06-23 10:42:07 +02001521 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001522}
1523
1524// ----------------------------------------------------------------------------
1525// SetPlayoutBuffer
1526// ----------------------------------------------------------------------------
1527
Max Morin787eeed2016-06-23 10:42:07 +02001528int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1529 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001530 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001531 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001532 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001533 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001534 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001535 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001536 }
Max Morin787eeed2016-06-23 10:42:07 +02001537 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001538
Max Morin787eeed2016-06-23 10:42:07 +02001539 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001540 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1541 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001542 return -1;
1543 }
1544
1545 int32_t ret(0);
1546
1547 if (kFixedBufferSize == type) {
1548 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1549 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001550 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001551 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001552 }
Max Morin787eeed2016-06-23 10:42:07 +02001553 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001554
Max Morin787eeed2016-06-23 10:42:07 +02001555 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001556 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1557 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001558 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001559
Max Morin787eeed2016-06-23 10:42:07 +02001560 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001561}
1562
1563// ----------------------------------------------------------------------------
1564// PlayoutBuffer
1565// ----------------------------------------------------------------------------
1566
Max Morin787eeed2016-06-23 10:42:07 +02001567int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1568 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001569 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001570 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001571
Max Morin787eeed2016-06-23 10:42:07 +02001572 BufferType bufType;
1573 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001574
Max Morin787eeed2016-06-23 10:42:07 +02001575 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001576 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001577 return -1;
1578 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001579
Max Morin787eeed2016-06-23 10:42:07 +02001580 *type = bufType;
1581 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001582
Max Morin2c332bb2016-07-04 09:03:42 +02001583 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001584 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001585}
1586
1587// ----------------------------------------------------------------------------
1588// PlayoutDelay
1589// ----------------------------------------------------------------------------
1590
Max Morin787eeed2016-06-23 10:42:07 +02001591int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001592 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001593
Max Morin787eeed2016-06-23 10:42:07 +02001594 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001595
Max Morin787eeed2016-06-23 10:42:07 +02001596 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001597 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001598 return -1;
1599 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001600
Max Morin787eeed2016-06-23 10:42:07 +02001601 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001602 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001603}
1604
1605// ----------------------------------------------------------------------------
1606// RecordingDelay
1607// ----------------------------------------------------------------------------
1608
Max Morin787eeed2016-06-23 10:42:07 +02001609int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001610 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001611 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001612
Max Morin787eeed2016-06-23 10:42:07 +02001613 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001614
Max Morin787eeed2016-06-23 10:42:07 +02001615 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001616 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001617 return -1;
1618 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001619
Max Morin787eeed2016-06-23 10:42:07 +02001620 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001621 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001622 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001623}
1624
1625// ----------------------------------------------------------------------------
1626// CPULoad
1627// ----------------------------------------------------------------------------
1628
Max Morin787eeed2016-06-23 10:42:07 +02001629int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001630 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001631 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001632
Max Morin787eeed2016-06-23 10:42:07 +02001633 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001634
Max Morin787eeed2016-06-23 10:42:07 +02001635 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001636 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001637 return -1;
1638 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001639
Max Morin787eeed2016-06-23 10:42:07 +02001640 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001641 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001642 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001643}
1644
1645// ----------------------------------------------------------------------------
1646// SetRecordingSampleRate
1647// ----------------------------------------------------------------------------
1648
Max Morin787eeed2016-06-23 10:42:07 +02001649int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1650 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001651 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001652 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001653
Max Morin787eeed2016-06-23 10:42:07 +02001654 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1655 return -1;
1656 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001657
Max Morin787eeed2016-06-23 10:42:07 +02001658 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001659}
1660
1661// ----------------------------------------------------------------------------
1662// RecordingSampleRate
1663// ----------------------------------------------------------------------------
1664
Max Morin787eeed2016-06-23 10:42:07 +02001665int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1666 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001667 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001668 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001669
Max Morin787eeed2016-06-23 10:42:07 +02001670 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001671
Max Morin787eeed2016-06-23 10:42:07 +02001672 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001673 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001674 return -1;
1675 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001676
Max Morin787eeed2016-06-23 10:42:07 +02001677 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001678 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001679 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001680}
1681
1682// ----------------------------------------------------------------------------
1683// SetPlayoutSampleRate
1684// ----------------------------------------------------------------------------
1685
Max Morin787eeed2016-06-23 10:42:07 +02001686int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1687 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001688 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001689 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001690
Max Morin787eeed2016-06-23 10:42:07 +02001691 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1692 return -1;
1693 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001694
Max Morin787eeed2016-06-23 10:42:07 +02001695 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001696}
1697
1698// ----------------------------------------------------------------------------
1699// PlayoutSampleRate
1700// ----------------------------------------------------------------------------
1701
Max Morin787eeed2016-06-23 10:42:07 +02001702int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1703 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001704 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001705 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001706
Max Morin787eeed2016-06-23 10:42:07 +02001707 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001708
Max Morin787eeed2016-06-23 10:42:07 +02001709 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001710 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001711 return -1;
1712 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001713
Max Morin787eeed2016-06-23 10:42:07 +02001714 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001715 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001716 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001717}
1718
1719// ----------------------------------------------------------------------------
1720// ResetAudioDevice
1721// ----------------------------------------------------------------------------
1722
Max Morin787eeed2016-06-23 10:42:07 +02001723int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001724 LOG(INFO) << __FUNCTION__;
henrikaf5022222016-11-07 15:56:59 +01001725 FATAL() << "Should never be called";
1726 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001727}
1728
1729// ----------------------------------------------------------------------------
1730// SetLoudspeakerStatus
1731// ----------------------------------------------------------------------------
1732
Max Morin787eeed2016-06-23 10:42:07 +02001733int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001734 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001735 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001736
Max Morin787eeed2016-06-23 10:42:07 +02001737 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1738 return -1;
1739 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001740
Max Morin787eeed2016-06-23 10:42:07 +02001741 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001742}
1743
1744// ----------------------------------------------------------------------------
1745// GetLoudspeakerStatus
1746// ----------------------------------------------------------------------------
1747
henrikac14f5ff2015-09-23 14:08:33 +02001748int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001749 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001750 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001751 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001752 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001753 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001754 }
Max Morin2c332bb2016-07-04 09:03:42 +02001755 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001756 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001757}
1758
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001759bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001760 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001761 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001762 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001763 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001764 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001765}
1766
henrikac14f5ff2015-09-23 14:08:33 +02001767int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001768 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001769 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001770 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001771 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001772 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001773}
1774
1775bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001776 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001777 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001778 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001779 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001780 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001781}
1782
1783int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001784 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001785 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001786 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001787 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001788 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001789}
1790
1791bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001792 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001793 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001794 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001795 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001796 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001797}
1798
1799int32_t AudioDeviceModuleImpl::EnableBuiltInNS(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->EnableBuiltInNS(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
maxmorin88e31a32016-08-16 00:56:09 -07001807#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001808int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1809 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001810 LOG(INFO) << __FUNCTION__;
1811 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001812 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001813 return r;
henrikaba35d052015-07-14 17:04:08 +02001814}
1815
1816int AudioDeviceModuleImpl::GetRecordAudioParameters(
1817 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001818 LOG(INFO) << __FUNCTION__;
1819 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001820 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001821 return r;
henrikaba35d052015-07-14 17:04:08 +02001822}
maxmorin88e31a32016-08-16 00:56:09 -07001823#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001824
niklase@google.com470e71d2011-07-07 08:21:25 +00001825// ============================================================================
1826// Private Methods
1827// ============================================================================
1828
1829// ----------------------------------------------------------------------------
1830// Platform
1831// ----------------------------------------------------------------------------
1832
Max Morin787eeed2016-06-23 10:42:07 +02001833AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001834 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001835 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001836}
1837
1838// ----------------------------------------------------------------------------
1839// PlatformAudioLayer
1840// ----------------------------------------------------------------------------
1841
Max Morin787eeed2016-06-23 10:42:07 +02001842AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1843 const {
Max Morin098e6c52016-06-28 09:36:25 +02001844 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001845 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001846}
1847
1848} // namespace webrtc