blob: 1731c3871642912d7f7d74ec0eeedfb0c6dddbcc [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
kjellanderc8fa6922017-06-30 14:02:00 -070011#include "webrtc/modules/audio_device/audio_device_impl.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000012#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
13#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020014#include "webrtc/modules/audio_device/audio_device_generic.h"
kjellanderc8fa6922017-06-30 14:02:00 -070015#include "webrtc/rtc_base/checks.h"
16#include "webrtc/rtc_base/logging.h"
17#include "webrtc/rtc_base/refcount.h"
18#include "webrtc/rtc_base/timeutils.h"
Max Morin84cab202016-07-01 13:35:19 +020019#include "webrtc/system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000021#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000022#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020025#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
26#include "audio_device_core_win.h"
27#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000028#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020029#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020030#include "webrtc/modules/audio_device/android/audio_device_template.h"
31#include "webrtc/modules/audio_device/android/audio_manager.h"
32#include "webrtc/modules/audio_device/android/audio_record_jni.h"
33#include "webrtc/modules/audio_device/android/audio_track_jni.h"
34#include "webrtc/modules/audio_device/android/opensles_player.h"
henrika918b5542016-09-19 15:44:09 +020035#include "webrtc/modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020037#if defined(LINUX_ALSA)
38#include "audio_device_alsa_linux.h"
39#endif
Tommi68898a22015-05-19 17:28:07 +020040#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020042#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000043#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020044#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000045#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020046#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000047#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000048
49#if defined(WEBRTC_DUMMY_FILE_DEVICES)
50#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
51#endif
52
pbos@webrtc.org811269d2013-07-11 13:24:38 +000053#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000054#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000055
Max Morin787eeed2016-06-23 10:42:07 +020056#define CHECK_INITIALIZED() \
57 { \
58 if (!_initialized) { \
59 return -1; \
60 }; \
61 }
niklase@google.com470e71d2011-07-07 08:21:25 +000062
Max Morin787eeed2016-06-23 10:42:07 +020063#define CHECK_INITIALIZED_BOOL() \
64 { \
65 if (!_initialized) { \
66 return false; \
67 }; \
68 }
niklase@google.com470e71d2011-07-07 08:21:25 +000069
Peter Boström1d194412016-03-21 16:44:31 +010070namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000071
niklase@google.com470e71d2011-07-07 08:21:25 +000072// ============================================================================
73// Static methods
74// ============================================================================
75
76// ----------------------------------------------------------------------------
77// AudioDeviceModule::Create()
78// ----------------------------------------------------------------------------
79
Peter Boström4adbbcf2016-05-03 15:51:26 -040080rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010081 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040082 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020083 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020084 // Create the generic ref counted (platform independent) implementation.
85 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
86 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000087
Max Morin787eeed2016-06-23 10:42:07 +020088 // Ensure that the current platform is supported.
89 if (audioDevice->CheckPlatform() == -1) {
90 return nullptr;
91 }
niklase@google.com470e71d2011-07-07 08:21:25 +000092
Max Morin787eeed2016-06-23 10:42:07 +020093 // Create the platform-dependent implementation.
94 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
95 return nullptr;
96 }
niklase@google.com470e71d2011-07-07 08:21:25 +000097
Max Morin787eeed2016-06-23 10:42:07 +020098 // Ensure that the generic audio buffer can communicate with the
99 // platform-specific parts.
100 if (audioDevice->AttachAudioBuffer() == -1) {
101 return nullptr;
102 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
Max Morin787eeed2016-06-23 10:42:07 +0200104 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000105
Max Morin787eeed2016-06-23 10:42:07 +0200106 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107}
108
niklase@google.com470e71d2011-07-07 08:21:25 +0000109// ============================================================================
110// Construction & Destruction
111// ============================================================================
112
113// ----------------------------------------------------------------------------
114// AudioDeviceModuleImpl - ctor
115// ----------------------------------------------------------------------------
116
Max Morin787eeed2016-06-23 10:42:07 +0200117AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
118 const AudioLayer audioLayer)
kthelgason6bfe49c2017-03-30 01:14:41 -0700119 : _ptrCbAudioDeviceObserver(NULL),
Max Morin787eeed2016-06-23 10:42:07 +0200120 _ptrAudioDevice(NULL),
121 _id(id),
122 _platformAudioLayer(audioLayer),
123 _lastProcessTime(rtc::TimeMillis()),
124 _platformType(kPlatformNotSupported),
125 _initialized(false),
126 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200127 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128}
129
130// ----------------------------------------------------------------------------
131// CheckPlatform
132// ----------------------------------------------------------------------------
133
Max Morin787eeed2016-06-23 10:42:07 +0200134int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200135 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
Max Morin787eeed2016-06-23 10:42:07 +0200137 // Ensure that the current platform is supported
138 //
139 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
141#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200142 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200143 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000144#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200145 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200146 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000147#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200148 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200149 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000150#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200151 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200152 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000153#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200154 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200155 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000156#endif
157
Max Morin787eeed2016-06-23 10:42:07 +0200158 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200159 LOG(LERROR) << "current platform is not supported => this module will self "
160 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200161 return -1;
162 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
Max Morin787eeed2016-06-23 10:42:07 +0200164 // Store valid output results
165 //
166 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
Max Morin787eeed2016-06-23 10:42:07 +0200168 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000169}
170
niklase@google.com470e71d2011-07-07 08:21:25 +0000171// ----------------------------------------------------------------------------
172// CreatePlatformSpecificObjects
173// ----------------------------------------------------------------------------
174
Max Morin787eeed2016-06-23 10:42:07 +0200175int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200176 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
Max Morin787eeed2016-06-23 10:42:07 +0200178 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
xians@google.combf5d2ba2011-08-16 07:44:19 +0000180#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200181 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200182 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000183#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200184 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
noahric6a355902016-08-17 15:19:50 -0700185 if (ptrAudioDevice) {
186 LOG(INFO) << "Will use file-playing dummy device.";
187 } else {
188 // Create a dummy device instead.
189 ptrAudioDevice = new AudioDeviceDummy(Id());
190 LOG(INFO) << "Dummy Audio APIs will be utilized";
191 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000192#else
Max Morin787eeed2016-06-23 10:42:07 +0200193 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
Max Morin787eeed2016-06-23 10:42:07 +0200195// Create the *Windows* implementation of the Audio Device
196//
niklase@google.com470e71d2011-07-07 08:21:25 +0000197#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200198 if ((audioLayer == kWindowsCoreAudio) ||
199 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200200 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
Max Morin787eeed2016-06-23 10:42:07 +0200202 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
203 // create *Windows Core Audio* implementation
204 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200205 LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000206 }
Max Morin787eeed2016-06-23 10:42:07 +0200207 }
208#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000210#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200211 // Create an Android audio manager.
212 _audioManagerAndroid.reset(new AudioManager());
213 // Select best possible combination of audio layers.
214 if (audioLayer == kPlatformDefaultAudio) {
henrika918b5542016-09-19 15:44:09 +0200215 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
216 _audioManagerAndroid->IsLowLatencyRecordSupported()) {
217 // Use OpenSL ES for both playout and recording.
218 audioLayer = kAndroidOpenSLESAudio;
219 } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
220 !_audioManagerAndroid->IsLowLatencyRecordSupported()) {
221 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200222 // low-latency output audio path.
223 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200224 } else {
henrika918b5542016-09-19 15:44:09 +0200225 // Use Java-based audio in both directions when low-latency output is
226 // not supported.
Max Morin787eeed2016-06-23 10:42:07 +0200227 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 }
Max Morin787eeed2016-06-23 10:42:07 +0200229 }
230 AudioManager* audio_manager = _audioManagerAndroid.get();
231 if (audioLayer == kAndroidJavaAudio) {
232 // Java audio for both input and output audio.
233 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
234 audioLayer, audio_manager);
henrika918b5542016-09-19 15:44:09 +0200235 } else if (audioLayer == kAndroidOpenSLESAudio) {
236 // OpenSL ES based audio for both input and output audio.
237 ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
238 audioLayer, audio_manager);
Max Morin787eeed2016-06-23 10:42:07 +0200239 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
240 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
241 // This combination provides low-latency output audio and at the same
242 // time support for HW AEC using the AudioRecord Java API.
243 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
244 audioLayer, audio_manager);
245 } else {
246 // Invalid audio layer.
henrika918b5542016-09-19 15:44:09 +0200247 ptrAudioDevice = nullptr;
Max Morin787eeed2016-06-23 10:42:07 +0200248 }
249// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000250
Max Morin787eeed2016-06-23 10:42:07 +0200251// Create the *Linux* implementation of the Audio Device
252//
niklase@google.com470e71d2011-07-07 08:21:25 +0000253#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200254 if ((audioLayer == kLinuxPulseAudio) ||
255 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000256#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200257 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
Max Morin787eeed2016-06-23 10:42:07 +0200259 // create *Linux PulseAudio* implementation
260 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200261 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200262 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200263 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200264 } else {
265 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000266#endif
267#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200268 // create *Linux ALSA Audio* implementation
269 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
270 if (ptrAudioDevice != NULL) {
271 // Pulse Audio was not supported => revert to ALSA instead
272 _platformAudioLayer =
273 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200274 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
275 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200276 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000277#endif
278#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000279 }
Max Morin787eeed2016-06-23 10:42:07 +0200280#endif
281 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000282#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200283 // create *Linux ALSA Audio* implementation
284 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200285 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000286#endif
Max Morin787eeed2016-06-23 10:42:07 +0200287 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000288#endif // #if defined(WEBRTC_LINUX)
289
Max Morin787eeed2016-06-23 10:42:07 +0200290// Create the *iPhone* implementation of the Audio Device
291//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000292#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200293 if (audioLayer == kPlatformDefaultAudio) {
294 // Create iOS Audio Device implementation.
295 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200296 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200297 }
298// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000299
Max Morin787eeed2016-06-23 10:42:07 +0200300// Create the *Mac* implementation of the Audio Device
301//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000302#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200303 if (audioLayer == kPlatformDefaultAudio) {
304 // Create *Mac Audio* implementation
305 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200306 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200307 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000308#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000309
Max Morin787eeed2016-06-23 10:42:07 +0200310 // Create the *Dummy* implementation of the Audio Device
311 // Available for all platforms
312 //
313 if (audioLayer == kDummyAudio) {
314 // Create *Dummy Audio* implementation
315 assert(!ptrAudioDevice);
316 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200317 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200318 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000319#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
Max Morin787eeed2016-06-23 10:42:07 +0200321 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200322 LOG(LERROR)
323 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200324 return -1;
325 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
Max Morin787eeed2016-06-23 10:42:07 +0200327 // Store valid output pointers
328 //
329 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000330
Max Morin787eeed2016-06-23 10:42:07 +0200331 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000332}
333
334// ----------------------------------------------------------------------------
335// AttachAudioBuffer
336//
337// Install "bridge" between the platform implemetation and the generic
338// implementation. The "child" shall set the native sampling rate and the
339// number of channels in this function call.
340// ----------------------------------------------------------------------------
341
Max Morin787eeed2016-06-23 10:42:07 +0200342int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200343 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000344
Max Morin787eeed2016-06-23 10:42:07 +0200345 _audioDeviceBuffer.SetId(_id);
346 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
347 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000348}
349
350// ----------------------------------------------------------------------------
351// ~AudioDeviceModuleImpl - dtor
352// ----------------------------------------------------------------------------
353
Max Morin787eeed2016-06-23 10:42:07 +0200354AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200355 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200356 if (_ptrAudioDevice) {
357 delete _ptrAudioDevice;
358 _ptrAudioDevice = NULL;
359 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000360}
361
362// ============================================================================
363// Module
364// ============================================================================
365
366// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000367// Module::TimeUntilNextProcess
368//
369// Returns the number of milliseconds until the module want a worker thread
370// to call Process().
371// ----------------------------------------------------------------------------
372
Max Morin787eeed2016-06-23 10:42:07 +0200373int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
374 int64_t now = rtc::TimeMillis();
375 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
376 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377}
378
379// ----------------------------------------------------------------------------
380// Module::Process
381//
382// Check for posted error and warning reports. Generate callbacks if
383// new reports exists.
384// ----------------------------------------------------------------------------
385
Max Morin787eeed2016-06-23 10:42:07 +0200386void AudioDeviceModuleImpl::Process() {
387 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000388
Max Morin787eeed2016-06-23 10:42:07 +0200389 // kPlayoutWarning
390 if (_ptrAudioDevice->PlayoutWarning()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700391 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200392 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200393 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200394 _ptrCbAudioDeviceObserver->OnWarningIsReported(
395 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 }
Max Morin787eeed2016-06-23 10:42:07 +0200397 _ptrAudioDevice->ClearPlayoutWarning();
398 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
Max Morin787eeed2016-06-23 10:42:07 +0200400 // kPlayoutError
401 if (_ptrAudioDevice->PlayoutError()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700402 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200403 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200404 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200405 _ptrCbAudioDeviceObserver->OnErrorIsReported(
406 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000407 }
Max Morin787eeed2016-06-23 10:42:07 +0200408 _ptrAudioDevice->ClearPlayoutError();
409 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000410
Max Morin787eeed2016-06-23 10:42:07 +0200411 // kRecordingWarning
412 if (_ptrAudioDevice->RecordingWarning()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700413 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200414 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200415 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200416 _ptrCbAudioDeviceObserver->OnWarningIsReported(
417 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000418 }
Max Morin787eeed2016-06-23 10:42:07 +0200419 _ptrAudioDevice->ClearRecordingWarning();
420 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
Max Morin787eeed2016-06-23 10:42:07 +0200422 // kRecordingError
423 if (_ptrAudioDevice->RecordingError()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700424 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200425 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200426 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200427 _ptrCbAudioDeviceObserver->OnErrorIsReported(
428 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429 }
Max Morin787eeed2016-06-23 10:42:07 +0200430 _ptrAudioDevice->ClearRecordingError();
431 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000432}
433
434// ============================================================================
435// Public API
436// ============================================================================
437
438// ----------------------------------------------------------------------------
439// ActiveAudioLayer
440// ----------------------------------------------------------------------------
441
henrikab2619892015-05-18 16:49:16 +0200442int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200443 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200444 AudioLayer activeAudio;
445 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
446 return -1;
447 }
448 *audioLayer = activeAudio;
449 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000450}
451
452// ----------------------------------------------------------------------------
453// LastError
454// ----------------------------------------------------------------------------
455
Max Morin787eeed2016-06-23 10:42:07 +0200456AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200457 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200458 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000459}
460
461// ----------------------------------------------------------------------------
462// Init
463// ----------------------------------------------------------------------------
464
Max Morin787eeed2016-06-23 10:42:07 +0200465int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200466 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200467 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000468 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200469 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200470
Max Morin84cab202016-07-01 13:35:19 +0200471 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
472 RTC_HISTOGRAM_ENUMERATION(
473 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
474 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
475 if (status != AudioDeviceGeneric::InitStatus::OK) {
476 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200477 return -1;
478 }
479
480 _initialized = true;
481 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000482}
483
484// ----------------------------------------------------------------------------
485// Terminate
486// ----------------------------------------------------------------------------
487
Max Morin787eeed2016-06-23 10:42:07 +0200488int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200489 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200490 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000491 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200492
493 if (_ptrAudioDevice->Terminate() == -1) {
494 return -1;
495 }
496
497 _initialized = false;
498 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000499}
500
501// ----------------------------------------------------------------------------
502// Initialized
503// ----------------------------------------------------------------------------
504
Max Morin787eeed2016-06-23 10:42:07 +0200505bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200506 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200507 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000508}
509
510// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000511// InitSpeaker
512// ----------------------------------------------------------------------------
513
Max Morin787eeed2016-06-23 10:42:07 +0200514int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200515 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200516 CHECK_INITIALIZED();
517 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000518}
519
520// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000521// InitMicrophone
522// ----------------------------------------------------------------------------
523
Max Morin787eeed2016-06-23 10:42:07 +0200524int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200525 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200526 CHECK_INITIALIZED();
527 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000528}
529
530// ----------------------------------------------------------------------------
531// SpeakerVolumeIsAvailable
532// ----------------------------------------------------------------------------
533
Max Morin787eeed2016-06-23 10:42:07 +0200534int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200535 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200536 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000537
Max Morin787eeed2016-06-23 10:42:07 +0200538 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000539
Max Morin787eeed2016-06-23 10:42:07 +0200540 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
541 return -1;
542 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000543
Max Morin787eeed2016-06-23 10:42:07 +0200544 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200545 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200546 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000547}
548
549// ----------------------------------------------------------------------------
550// SetSpeakerVolume
551// ----------------------------------------------------------------------------
552
Max Morin787eeed2016-06-23 10:42:07 +0200553int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200554 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200555 CHECK_INITIALIZED();
556 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000557}
558
559// ----------------------------------------------------------------------------
560// SpeakerVolume
561// ----------------------------------------------------------------------------
562
Max Morin787eeed2016-06-23 10:42:07 +0200563int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200564 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200565 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000566
Max Morin787eeed2016-06-23 10:42:07 +0200567 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000568
Max Morin787eeed2016-06-23 10:42:07 +0200569 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
570 return -1;
571 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000572
Max Morin787eeed2016-06-23 10:42:07 +0200573 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200574 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200575 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000576}
577
578// ----------------------------------------------------------------------------
579// SetWaveOutVolume
580// ----------------------------------------------------------------------------
581
Max Morin787eeed2016-06-23 10:42:07 +0200582int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
583 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200584 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200585 CHECK_INITIALIZED();
586 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000587}
588
589// ----------------------------------------------------------------------------
590// WaveOutVolume
591// ----------------------------------------------------------------------------
592
Max Morin787eeed2016-06-23 10:42:07 +0200593int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
594 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200595 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200596 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000597
Max Morin787eeed2016-06-23 10:42:07 +0200598 uint16_t volLeft(0);
599 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000600
Max Morin787eeed2016-06-23 10:42:07 +0200601 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
602 return -1;
603 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000604
Max Morin787eeed2016-06-23 10:42:07 +0200605 *volumeLeft = volLeft;
606 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200607 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000608
Max Morin787eeed2016-06-23 10:42:07 +0200609 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000610}
611
612// ----------------------------------------------------------------------------
613// SpeakerIsInitialized
614// ----------------------------------------------------------------------------
615
Max Morin787eeed2016-06-23 10:42:07 +0200616bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200617 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200618 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000619
Max Morin787eeed2016-06-23 10:42:07 +0200620 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200621 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200622 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000623}
624
625// ----------------------------------------------------------------------------
626// MicrophoneIsInitialized
627// ----------------------------------------------------------------------------
628
Max Morin787eeed2016-06-23 10:42:07 +0200629bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200630 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200631 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000632
Max Morin787eeed2016-06-23 10:42:07 +0200633 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200634 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200635 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000636}
637
638// ----------------------------------------------------------------------------
639// MaxSpeakerVolume
640// ----------------------------------------------------------------------------
641
Max Morin787eeed2016-06-23 10:42:07 +0200642int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
643 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000644
Max Morin787eeed2016-06-23 10:42:07 +0200645 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000646
Max Morin787eeed2016-06-23 10:42:07 +0200647 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
648 return -1;
649 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000650
Max Morin787eeed2016-06-23 10:42:07 +0200651 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200652 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000653}
654
655// ----------------------------------------------------------------------------
656// MinSpeakerVolume
657// ----------------------------------------------------------------------------
658
Max Morin787eeed2016-06-23 10:42:07 +0200659int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
660 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000661
Max Morin787eeed2016-06-23 10:42:07 +0200662 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000663
Max Morin787eeed2016-06-23 10:42:07 +0200664 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
665 return -1;
666 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000667
Max Morin787eeed2016-06-23 10:42:07 +0200668 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200669 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000670}
671
672// ----------------------------------------------------------------------------
673// SpeakerVolumeStepSize
674// ----------------------------------------------------------------------------
675
Max Morin787eeed2016-06-23 10:42:07 +0200676int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200677 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200678 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000679
Max Morin787eeed2016-06-23 10:42:07 +0200680 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000681
Max Morin787eeed2016-06-23 10:42:07 +0200682 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200683 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200684 return -1;
685 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000686
Max Morin787eeed2016-06-23 10:42:07 +0200687 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200688 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200689 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000690}
691
692// ----------------------------------------------------------------------------
693// SpeakerMuteIsAvailable
694// ----------------------------------------------------------------------------
695
Max Morin787eeed2016-06-23 10:42:07 +0200696int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200697 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200698 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000699
Max Morin787eeed2016-06-23 10:42:07 +0200700 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000701
Max Morin787eeed2016-06-23 10:42:07 +0200702 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
703 return -1;
704 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000705
Max Morin787eeed2016-06-23 10:42:07 +0200706 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200707 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200708 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000709}
710
711// ----------------------------------------------------------------------------
712// SetSpeakerMute
713// ----------------------------------------------------------------------------
714
Max Morin787eeed2016-06-23 10:42:07 +0200715int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200716 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200717 CHECK_INITIALIZED();
718 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000719}
720
721// ----------------------------------------------------------------------------
722// SpeakerMute
723// ----------------------------------------------------------------------------
724
Max Morin787eeed2016-06-23 10:42:07 +0200725int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200726 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200727 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000728
Max Morin787eeed2016-06-23 10:42:07 +0200729 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000730
Max Morin787eeed2016-06-23 10:42:07 +0200731 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
732 return -1;
733 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000734
Max Morin787eeed2016-06-23 10:42:07 +0200735 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200736 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200737 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000738}
739
740// ----------------------------------------------------------------------------
741// MicrophoneMuteIsAvailable
742// ----------------------------------------------------------------------------
743
Max Morin787eeed2016-06-23 10:42:07 +0200744int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200745 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200746 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000747
Max Morin787eeed2016-06-23 10:42:07 +0200748 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000749
Max Morin787eeed2016-06-23 10:42:07 +0200750 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
751 return -1;
752 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000753
Max Morin787eeed2016-06-23 10:42:07 +0200754 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200755 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200756 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000757}
758
759// ----------------------------------------------------------------------------
760// SetMicrophoneMute
761// ----------------------------------------------------------------------------
762
Max Morin787eeed2016-06-23 10:42:07 +0200763int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200764 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200765 CHECK_INITIALIZED();
766 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000767}
768
769// ----------------------------------------------------------------------------
770// MicrophoneMute
771// ----------------------------------------------------------------------------
772
Max Morin787eeed2016-06-23 10:42:07 +0200773int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200774 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200775 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000776
Max Morin787eeed2016-06-23 10:42:07 +0200777 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000778
Max Morin787eeed2016-06-23 10:42:07 +0200779 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
780 return -1;
781 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000782
Max Morin787eeed2016-06-23 10:42:07 +0200783 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200784 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200785 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000786}
787
788// ----------------------------------------------------------------------------
789// MicrophoneBoostIsAvailable
790// ----------------------------------------------------------------------------
791
Max Morin787eeed2016-06-23 10:42:07 +0200792int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200793 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200794 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000795
Max Morin787eeed2016-06-23 10:42:07 +0200796 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000797
Max Morin787eeed2016-06-23 10:42:07 +0200798 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
799 return -1;
800 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000801
Max Morin787eeed2016-06-23 10:42:07 +0200802 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200803 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200804 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000805}
806
807// ----------------------------------------------------------------------------
808// SetMicrophoneBoost
809// ----------------------------------------------------------------------------
810
Max Morin787eeed2016-06-23 10:42:07 +0200811int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200812 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200813 CHECK_INITIALIZED();
814 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000815}
816
817// ----------------------------------------------------------------------------
818// MicrophoneBoost
819// ----------------------------------------------------------------------------
820
Max Morin787eeed2016-06-23 10:42:07 +0200821int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200822 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200823 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000824
Max Morin787eeed2016-06-23 10:42:07 +0200825 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000826
Max Morin787eeed2016-06-23 10:42:07 +0200827 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
828 return -1;
829 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000830
Max Morin787eeed2016-06-23 10:42:07 +0200831 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200832 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200833 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000834}
835
836// ----------------------------------------------------------------------------
837// MicrophoneVolumeIsAvailable
838// ----------------------------------------------------------------------------
839
Max Morin787eeed2016-06-23 10:42:07 +0200840int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200841 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200842 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000843
Max Morin787eeed2016-06-23 10:42:07 +0200844 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000845
Max Morin787eeed2016-06-23 10:42:07 +0200846 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
847 return -1;
848 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000849
Max Morin787eeed2016-06-23 10:42:07 +0200850 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200851 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200852 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000853}
854
855// ----------------------------------------------------------------------------
856// SetMicrophoneVolume
857// ----------------------------------------------------------------------------
858
Max Morin787eeed2016-06-23 10:42:07 +0200859int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200860 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200861 CHECK_INITIALIZED();
862 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000863}
864
865// ----------------------------------------------------------------------------
866// MicrophoneVolume
867// ----------------------------------------------------------------------------
868
Max Morin787eeed2016-06-23 10:42:07 +0200869int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200870 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200871 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000872
Max Morin787eeed2016-06-23 10:42:07 +0200873 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000874
Max Morin787eeed2016-06-23 10:42:07 +0200875 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
876 return -1;
877 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000878
Max Morin787eeed2016-06-23 10:42:07 +0200879 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200880 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200881 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000882}
883
884// ----------------------------------------------------------------------------
885// StereoRecordingIsAvailable
886// ----------------------------------------------------------------------------
887
Max Morin787eeed2016-06-23 10:42:07 +0200888int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
889 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200890 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200891 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000892
Max Morin787eeed2016-06-23 10:42:07 +0200893 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000894
Max Morin787eeed2016-06-23 10:42:07 +0200895 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
896 return -1;
897 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000898
Max Morin787eeed2016-06-23 10:42:07 +0200899 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200900 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200901 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000902}
903
904// ----------------------------------------------------------------------------
905// SetStereoRecording
906// ----------------------------------------------------------------------------
907
Max Morin787eeed2016-06-23 10:42:07 +0200908int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200909 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200910 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000911
Max Morin787eeed2016-06-23 10:42:07 +0200912 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200913 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200914 return -1;
915 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000916
Max Morin787eeed2016-06-23 10:42:07 +0200917 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200918 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200919 return -1;
920 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000921
Max Morin787eeed2016-06-23 10:42:07 +0200922 int8_t nChannels(1);
923 if (enable) {
924 nChannels = 2;
925 }
926 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000927
Max Morin787eeed2016-06-23 10:42:07 +0200928 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000929}
930
931// ----------------------------------------------------------------------------
932// StereoRecording
933// ----------------------------------------------------------------------------
934
Max Morin787eeed2016-06-23 10:42:07 +0200935int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200936 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200937 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000938
Max Morin787eeed2016-06-23 10:42:07 +0200939 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000940
Max Morin787eeed2016-06-23 10:42:07 +0200941 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
942 return -1;
943 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000944
Max Morin787eeed2016-06-23 10:42:07 +0200945 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200946 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200947 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000948}
949
950// ----------------------------------------------------------------------------
951// SetRecordingChannel
952// ----------------------------------------------------------------------------
953
Max Morin787eeed2016-06-23 10:42:07 +0200954int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
955 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200956 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200957 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200958 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200959 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200960 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200961 }
962 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000963
Max Morin787eeed2016-06-23 10:42:07 +0200964 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000965
Max Morin787eeed2016-06-23 10:42:07 +0200966 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200967 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200968 return -1;
969 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000970
Max Morin787eeed2016-06-23 10:42:07 +0200971 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000972}
973
974// ----------------------------------------------------------------------------
975// RecordingChannel
976// ----------------------------------------------------------------------------
977
Max Morin787eeed2016-06-23 10:42:07 +0200978int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200979 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200980 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000981
Max Morin787eeed2016-06-23 10:42:07 +0200982 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000983
Max Morin787eeed2016-06-23 10:42:07 +0200984 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
985 return -1;
986 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000987
Max Morin787eeed2016-06-23 10:42:07 +0200988 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200989 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +0200990 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200991 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +0200992 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200993 } else {
Max Morin2c332bb2016-07-04 09:03:42 +0200994 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200995 }
Max Morin787eeed2016-06-23 10:42:07 +0200996 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000997}
998
999// ----------------------------------------------------------------------------
1000// StereoPlayoutIsAvailable
1001// ----------------------------------------------------------------------------
1002
Max Morin787eeed2016-06-23 10:42:07 +02001003int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001004 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001005 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001006
Max Morin787eeed2016-06-23 10:42:07 +02001007 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001008
Max Morin787eeed2016-06-23 10:42:07 +02001009 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1010 return -1;
1011 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001012
Max Morin787eeed2016-06-23 10:42:07 +02001013 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001014 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001015 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001016}
1017
1018// ----------------------------------------------------------------------------
1019// SetStereoPlayout
1020// ----------------------------------------------------------------------------
1021
Max Morin787eeed2016-06-23 10:42:07 +02001022int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001023 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001024 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001025
Max Morin787eeed2016-06-23 10:42:07 +02001026 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001027 LOG(LERROR)
1028 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001029 return -1;
1030 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001031
Max Morin787eeed2016-06-23 10:42:07 +02001032 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001033 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001034 return -1;
1035 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001036
Max Morin787eeed2016-06-23 10:42:07 +02001037 int8_t nChannels(1);
1038 if (enable) {
1039 nChannels = 2;
1040 }
1041 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001042
Max Morin787eeed2016-06-23 10:42:07 +02001043 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001044}
1045
1046// ----------------------------------------------------------------------------
1047// StereoPlayout
1048// ----------------------------------------------------------------------------
1049
Max Morin787eeed2016-06-23 10:42:07 +02001050int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001051 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001052 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001053
Max Morin787eeed2016-06-23 10:42:07 +02001054 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001055
Max Morin787eeed2016-06-23 10:42:07 +02001056 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1057 return -1;
1058 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001059
Max Morin787eeed2016-06-23 10:42:07 +02001060 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001061 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001062 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001063}
1064
1065// ----------------------------------------------------------------------------
1066// SetAGC
1067// ----------------------------------------------------------------------------
1068
Max Morin787eeed2016-06-23 10:42:07 +02001069int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001070 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001071 CHECK_INITIALIZED();
1072 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001073}
1074
1075// ----------------------------------------------------------------------------
1076// AGC
1077// ----------------------------------------------------------------------------
1078
Max Morin787eeed2016-06-23 10:42:07 +02001079bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001080 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001081 CHECK_INITIALIZED_BOOL();
1082 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001083}
1084
1085// ----------------------------------------------------------------------------
1086// PlayoutIsAvailable
1087// ----------------------------------------------------------------------------
1088
Max Morin787eeed2016-06-23 10:42:07 +02001089int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001090 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001091 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001092
Max Morin787eeed2016-06-23 10:42:07 +02001093 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001094
Max Morin787eeed2016-06-23 10:42:07 +02001095 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1096 return -1;
1097 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001098
Max Morin787eeed2016-06-23 10:42:07 +02001099 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001100 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001101 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001102}
1103
1104// ----------------------------------------------------------------------------
1105// RecordingIsAvailable
1106// ----------------------------------------------------------------------------
1107
Max Morin787eeed2016-06-23 10:42:07 +02001108int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001109 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001110 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001111
Max Morin787eeed2016-06-23 10:42:07 +02001112 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001113
Max Morin787eeed2016-06-23 10:42:07 +02001114 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1115 return -1;
1116 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001117
Max Morin787eeed2016-06-23 10:42:07 +02001118 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001119 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001120 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001121}
1122
1123// ----------------------------------------------------------------------------
1124// MaxMicrophoneVolume
1125// ----------------------------------------------------------------------------
1126
Max Morin787eeed2016-06-23 10:42:07 +02001127int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001128 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001129
Max Morin787eeed2016-06-23 10:42:07 +02001130 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001131
Max Morin787eeed2016-06-23 10:42:07 +02001132 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1133 return -1;
1134 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001135
Max Morin787eeed2016-06-23 10:42:07 +02001136 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001137 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001138}
1139
1140// ----------------------------------------------------------------------------
1141// MinMicrophoneVolume
1142// ----------------------------------------------------------------------------
1143
Max Morin787eeed2016-06-23 10:42:07 +02001144int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1145 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001146
Max Morin787eeed2016-06-23 10:42:07 +02001147 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001148
Max Morin787eeed2016-06-23 10:42:07 +02001149 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1150 return -1;
1151 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001152
Max Morin787eeed2016-06-23 10:42:07 +02001153 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001154 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001155}
1156
1157// ----------------------------------------------------------------------------
1158// MicrophoneVolumeStepSize
1159// ----------------------------------------------------------------------------
1160
Max Morin787eeed2016-06-23 10:42:07 +02001161int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1162 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001163 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001164 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001165
Max Morin787eeed2016-06-23 10:42:07 +02001166 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001167
Max Morin787eeed2016-06-23 10:42:07 +02001168 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1169 return -1;
1170 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001171
Max Morin787eeed2016-06-23 10:42:07 +02001172 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001173 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001174 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001175}
1176
1177// ----------------------------------------------------------------------------
1178// PlayoutDevices
1179// ----------------------------------------------------------------------------
1180
Max Morin787eeed2016-06-23 10:42:07 +02001181int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001182 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001183 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001184
Max Morin787eeed2016-06-23 10:42:07 +02001185 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001186 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001187 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001188}
1189
1190// ----------------------------------------------------------------------------
1191// SetPlayoutDevice I (II)
1192// ----------------------------------------------------------------------------
1193
Max Morin787eeed2016-06-23 10:42:07 +02001194int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001195 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001196 CHECK_INITIALIZED();
1197 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001198}
1199
1200// ----------------------------------------------------------------------------
1201// SetPlayoutDevice II (II)
1202// ----------------------------------------------------------------------------
1203
Max Morin787eeed2016-06-23 10:42:07 +02001204int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001205 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001206 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001207
Max Morin787eeed2016-06-23 10:42:07 +02001208 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001209}
1210
1211// ----------------------------------------------------------------------------
1212// PlayoutDeviceName
1213// ----------------------------------------------------------------------------
1214
pbos@webrtc.org25509882013-04-09 10:30:35 +00001215int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1216 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001217 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001218 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001219 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001220 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001221
Max Morin787eeed2016-06-23 10:42:07 +02001222 if (name == NULL) {
1223 _lastError = kAdmErrArgument;
1224 return -1;
1225 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001226
Max Morin787eeed2016-06-23 10:42:07 +02001227 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1228 return -1;
1229 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001230
Max Morin787eeed2016-06-23 10:42:07 +02001231 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001232 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001233 }
1234 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001235 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001236 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001237
Max Morin787eeed2016-06-23 10:42:07 +02001238 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001239}
1240
1241// ----------------------------------------------------------------------------
1242// RecordingDeviceName
1243// ----------------------------------------------------------------------------
1244
pbos@webrtc.org25509882013-04-09 10:30:35 +00001245int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1246 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001247 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001248 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001249 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001250 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001251
Max Morin787eeed2016-06-23 10:42:07 +02001252 if (name == NULL) {
1253 _lastError = kAdmErrArgument;
1254 return -1;
1255 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001256
Max Morin787eeed2016-06-23 10:42:07 +02001257 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1258 return -1;
1259 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001260
Max Morin787eeed2016-06-23 10:42:07 +02001261 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001262 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001263 }
1264 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001265 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001266 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001267
Max Morin787eeed2016-06-23 10:42:07 +02001268 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001269}
1270
1271// ----------------------------------------------------------------------------
1272// RecordingDevices
1273// ----------------------------------------------------------------------------
1274
Max Morin787eeed2016-06-23 10:42:07 +02001275int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001276 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001277 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001278
Max Morin787eeed2016-06-23 10:42:07 +02001279 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001280
Max Morin2c332bb2016-07-04 09:03:42 +02001281 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001282 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001283}
1284
1285// ----------------------------------------------------------------------------
1286// SetRecordingDevice I (II)
1287// ----------------------------------------------------------------------------
1288
Max Morin787eeed2016-06-23 10:42:07 +02001289int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001290 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001291 CHECK_INITIALIZED();
1292 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001293}
1294
1295// ----------------------------------------------------------------------------
1296// SetRecordingDevice II (II)
1297// ----------------------------------------------------------------------------
1298
Max Morin787eeed2016-06-23 10:42:07 +02001299int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001300 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001301 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001302
Max Morin787eeed2016-06-23 10:42:07 +02001303 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001304}
1305
1306// ----------------------------------------------------------------------------
1307// InitPlayout
1308// ----------------------------------------------------------------------------
1309
Max Morin787eeed2016-06-23 10:42:07 +02001310int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001311 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001312 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001313 if (PlayoutIsInitialized()) {
1314 return 0;
1315 }
Max Morin84cab202016-07-01 13:35:19 +02001316 int32_t result = _ptrAudioDevice->InitPlayout();
1317 LOG(INFO) << "output: " << result;
1318 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1319 static_cast<int>(result == 0));
1320 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001321}
1322
1323// ----------------------------------------------------------------------------
1324// InitRecording
1325// ----------------------------------------------------------------------------
1326
Max Morin787eeed2016-06-23 10:42:07 +02001327int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001328 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001329 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001330 if (RecordingIsInitialized()) {
1331 return 0;
1332 }
Max Morin84cab202016-07-01 13:35:19 +02001333 int32_t result = _ptrAudioDevice->InitRecording();
1334 LOG(INFO) << "output: " << result;
1335 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1336 static_cast<int>(result == 0));
1337 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001338}
1339
1340// ----------------------------------------------------------------------------
1341// PlayoutIsInitialized
1342// ----------------------------------------------------------------------------
1343
Max Morin787eeed2016-06-23 10:42:07 +02001344bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001345 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001346 CHECK_INITIALIZED_BOOL();
1347 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001348}
1349
1350// ----------------------------------------------------------------------------
1351// RecordingIsInitialized
1352// ----------------------------------------------------------------------------
1353
Max Morin787eeed2016-06-23 10:42:07 +02001354bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001355 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001356 CHECK_INITIALIZED_BOOL();
1357 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001358}
1359
1360// ----------------------------------------------------------------------------
1361// StartPlayout
1362// ----------------------------------------------------------------------------
1363
Max Morin787eeed2016-06-23 10:42:07 +02001364int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001365 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001366 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001367 if (Playing()) {
1368 return 0;
1369 }
henrikaba156cf2016-10-31 08:18:50 -07001370 _audioDeviceBuffer.StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001371 int32_t result = _ptrAudioDevice->StartPlayout();
1372 LOG(INFO) << "output: " << result;
1373 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1374 static_cast<int>(result == 0));
1375 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001376}
1377
1378// ----------------------------------------------------------------------------
1379// StopPlayout
1380// ----------------------------------------------------------------------------
1381
Max Morin787eeed2016-06-23 10:42:07 +02001382int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001383 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001384 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001385 int32_t result = _ptrAudioDevice->StopPlayout();
henrikaba156cf2016-10-31 08:18:50 -07001386 _audioDeviceBuffer.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001387 LOG(INFO) << "output: " << result;
1388 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1389 static_cast<int>(result == 0));
1390 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001391}
1392
1393// ----------------------------------------------------------------------------
1394// Playing
1395// ----------------------------------------------------------------------------
1396
Max Morin787eeed2016-06-23 10:42:07 +02001397bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001398 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001399 CHECK_INITIALIZED_BOOL();
1400 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001401}
1402
1403// ----------------------------------------------------------------------------
1404// StartRecording
1405// ----------------------------------------------------------------------------
1406
Max Morin787eeed2016-06-23 10:42:07 +02001407int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001408 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001409 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001410 if (Recording()) {
1411 return 0;
1412 }
henrikaba156cf2016-10-31 08:18:50 -07001413 _audioDeviceBuffer.StartRecording();
Max Morin84cab202016-07-01 13:35:19 +02001414 int32_t result = _ptrAudioDevice->StartRecording();
1415 LOG(INFO) << "output: " << result;
1416 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1417 static_cast<int>(result == 0));
1418 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001419}
1420// ----------------------------------------------------------------------------
1421// StopRecording
1422// ----------------------------------------------------------------------------
1423
Max Morin787eeed2016-06-23 10:42:07 +02001424int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001425 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001426 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001427 int32_t result = _ptrAudioDevice->StopRecording();
henrikaba156cf2016-10-31 08:18:50 -07001428 _audioDeviceBuffer.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +02001429 LOG(INFO) << "output: " << result;
1430 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1431 static_cast<int>(result == 0));
1432 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001433}
1434
1435// ----------------------------------------------------------------------------
1436// Recording
1437// ----------------------------------------------------------------------------
1438
Max Morin787eeed2016-06-23 10:42:07 +02001439bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001440 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001441 CHECK_INITIALIZED_BOOL();
1442 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001443}
1444
1445// ----------------------------------------------------------------------------
1446// RegisterEventObserver
1447// ----------------------------------------------------------------------------
1448
Max Morin787eeed2016-06-23 10:42:07 +02001449int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1450 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001451 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001452 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +02001453 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001454
Max Morin787eeed2016-06-23 10:42:07 +02001455 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001456}
1457
1458// ----------------------------------------------------------------------------
1459// RegisterAudioCallback
1460// ----------------------------------------------------------------------------
1461
Max Morin787eeed2016-06-23 10:42:07 +02001462int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1463 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001464 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001465 rtc::CritScope lock(&_critSectAudioCb);
henrikaf5022222016-11-07 15:56:59 +01001466 return _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001467}
1468
1469// ----------------------------------------------------------------------------
1470// StartRawInputFileRecording
1471// ----------------------------------------------------------------------------
1472
pbos@webrtc.org25509882013-04-09 10:30:35 +00001473int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001474 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001475 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001476 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001477
Max Morin787eeed2016-06-23 10:42:07 +02001478 if (NULL == pcmFileNameUTF8) {
1479 return -1;
1480 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001481
Max Morin787eeed2016-06-23 10:42:07 +02001482 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001483}
1484
1485// ----------------------------------------------------------------------------
1486// StopRawInputFileRecording
1487// ----------------------------------------------------------------------------
1488
Max Morin787eeed2016-06-23 10:42:07 +02001489int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001490 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001491 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001492
Max Morin787eeed2016-06-23 10:42:07 +02001493 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001494}
1495
1496// ----------------------------------------------------------------------------
1497// StartRawOutputFileRecording
1498// ----------------------------------------------------------------------------
1499
pbos@webrtc.org25509882013-04-09 10:30:35 +00001500int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001501 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001502 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001503 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001504
Max Morin787eeed2016-06-23 10:42:07 +02001505 if (NULL == pcmFileNameUTF8) {
1506 return -1;
1507 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001508
Max Morin787eeed2016-06-23 10:42:07 +02001509 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001510}
1511
1512// ----------------------------------------------------------------------------
1513// StopRawOutputFileRecording
1514// ----------------------------------------------------------------------------
1515
Max Morin787eeed2016-06-23 10:42:07 +02001516int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001517 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001518 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001519
Max Morin787eeed2016-06-23 10:42:07 +02001520 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001521}
1522
1523// ----------------------------------------------------------------------------
1524// SetPlayoutBuffer
1525// ----------------------------------------------------------------------------
1526
Max Morin787eeed2016-06-23 10:42:07 +02001527int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1528 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001529 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001530 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001531 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001532 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001533 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001534 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001535 }
Max Morin787eeed2016-06-23 10:42:07 +02001536 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001537
Max Morin787eeed2016-06-23 10:42:07 +02001538 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001539 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1540 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001541 return -1;
1542 }
1543
1544 int32_t ret(0);
1545
1546 if (kFixedBufferSize == type) {
1547 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1548 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001549 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001550 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001551 }
Max Morin787eeed2016-06-23 10:42:07 +02001552 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001553
Max Morin787eeed2016-06-23 10:42:07 +02001554 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001555 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1556 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001557 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001558
Max Morin787eeed2016-06-23 10:42:07 +02001559 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001560}
1561
1562// ----------------------------------------------------------------------------
1563// PlayoutBuffer
1564// ----------------------------------------------------------------------------
1565
Max Morin787eeed2016-06-23 10:42:07 +02001566int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1567 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001568 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001569 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001570
Max Morin787eeed2016-06-23 10:42:07 +02001571 BufferType bufType;
1572 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001573
Max Morin787eeed2016-06-23 10:42:07 +02001574 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001575 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001576 return -1;
1577 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001578
Max Morin787eeed2016-06-23 10:42:07 +02001579 *type = bufType;
1580 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001581
Max Morin2c332bb2016-07-04 09:03:42 +02001582 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001583 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001584}
1585
1586// ----------------------------------------------------------------------------
1587// PlayoutDelay
1588// ----------------------------------------------------------------------------
1589
Max Morin787eeed2016-06-23 10:42:07 +02001590int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001591 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001592
Max Morin787eeed2016-06-23 10:42:07 +02001593 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001594
Max Morin787eeed2016-06-23 10:42:07 +02001595 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001596 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001597 return -1;
1598 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001599
Max Morin787eeed2016-06-23 10:42:07 +02001600 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001601 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001602}
1603
1604// ----------------------------------------------------------------------------
1605// RecordingDelay
1606// ----------------------------------------------------------------------------
1607
Max Morin787eeed2016-06-23 10:42:07 +02001608int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001609 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001610 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001611
Max Morin787eeed2016-06-23 10:42:07 +02001612 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001613
Max Morin787eeed2016-06-23 10:42:07 +02001614 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001615 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001616 return -1;
1617 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001618
Max Morin787eeed2016-06-23 10:42:07 +02001619 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001620 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001621 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001622}
1623
1624// ----------------------------------------------------------------------------
1625// CPULoad
1626// ----------------------------------------------------------------------------
1627
Max Morin787eeed2016-06-23 10:42:07 +02001628int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001629 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001630 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001631
Max Morin787eeed2016-06-23 10:42:07 +02001632 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001633
Max Morin787eeed2016-06-23 10:42:07 +02001634 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001635 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001636 return -1;
1637 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001638
Max Morin787eeed2016-06-23 10:42:07 +02001639 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001640 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001641 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001642}
1643
1644// ----------------------------------------------------------------------------
1645// SetRecordingSampleRate
1646// ----------------------------------------------------------------------------
1647
Max Morin787eeed2016-06-23 10:42:07 +02001648int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1649 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001650 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001651 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001652
Max Morin787eeed2016-06-23 10:42:07 +02001653 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1654 return -1;
1655 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001656
Max Morin787eeed2016-06-23 10:42:07 +02001657 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001658}
1659
1660// ----------------------------------------------------------------------------
1661// RecordingSampleRate
1662// ----------------------------------------------------------------------------
1663
Max Morin787eeed2016-06-23 10:42:07 +02001664int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1665 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001666 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001667 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001668
Max Morin787eeed2016-06-23 10:42:07 +02001669 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001670
Max Morin787eeed2016-06-23 10:42:07 +02001671 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001672 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001673 return -1;
1674 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001675
Max Morin787eeed2016-06-23 10:42:07 +02001676 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001677 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001678 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001679}
1680
1681// ----------------------------------------------------------------------------
1682// SetPlayoutSampleRate
1683// ----------------------------------------------------------------------------
1684
Max Morin787eeed2016-06-23 10:42:07 +02001685int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1686 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001687 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001688 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001689
Max Morin787eeed2016-06-23 10:42:07 +02001690 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1691 return -1;
1692 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001693
Max Morin787eeed2016-06-23 10:42:07 +02001694 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001695}
1696
1697// ----------------------------------------------------------------------------
1698// PlayoutSampleRate
1699// ----------------------------------------------------------------------------
1700
Max Morin787eeed2016-06-23 10:42:07 +02001701int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1702 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001703 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001704 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001705
Max Morin787eeed2016-06-23 10:42:07 +02001706 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001707
Max Morin787eeed2016-06-23 10:42:07 +02001708 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001709 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001710 return -1;
1711 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001712
Max Morin787eeed2016-06-23 10:42:07 +02001713 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001714 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001715 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001716}
1717
1718// ----------------------------------------------------------------------------
1719// ResetAudioDevice
1720// ----------------------------------------------------------------------------
1721
Max Morin787eeed2016-06-23 10:42:07 +02001722int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001723 LOG(INFO) << __FUNCTION__;
henrikaf5022222016-11-07 15:56:59 +01001724 FATAL() << "Should never be called";
1725 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001726}
1727
1728// ----------------------------------------------------------------------------
1729// SetLoudspeakerStatus
1730// ----------------------------------------------------------------------------
1731
Max Morin787eeed2016-06-23 10:42:07 +02001732int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001733 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001734 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001735
Max Morin787eeed2016-06-23 10:42:07 +02001736 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1737 return -1;
1738 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001739
Max Morin787eeed2016-06-23 10:42:07 +02001740 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001741}
1742
1743// ----------------------------------------------------------------------------
1744// GetLoudspeakerStatus
1745// ----------------------------------------------------------------------------
1746
henrikac14f5ff2015-09-23 14:08:33 +02001747int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001748 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001749 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001750 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001751 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001752 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001753 }
Max Morin2c332bb2016-07-04 09:03:42 +02001754 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001755 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001756}
1757
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001758bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001759 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001760 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001761 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001762 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001763 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001764}
1765
henrikac14f5ff2015-09-23 14:08:33 +02001766int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001767 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001768 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001769 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001770 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001771 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001772}
1773
1774bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001775 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001776 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001777 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001778 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001779 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001780}
1781
1782int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001783 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001784 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001785 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001786 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001787 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001788}
1789
1790bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001791 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001792 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001793 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001794 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001795 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001796}
1797
1798int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001799 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001800 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001801 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001802 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001803 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001804}
1805
maxmorin88e31a32016-08-16 00:56:09 -07001806#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001807int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1808 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001809 LOG(INFO) << __FUNCTION__;
1810 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001811 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001812 return r;
henrikaba35d052015-07-14 17:04:08 +02001813}
1814
1815int AudioDeviceModuleImpl::GetRecordAudioParameters(
1816 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001817 LOG(INFO) << __FUNCTION__;
1818 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001819 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001820 return r;
henrikaba35d052015-07-14 17:04:08 +02001821}
maxmorin88e31a32016-08-16 00:56:09 -07001822#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001823
niklase@google.com470e71d2011-07-07 08:21:25 +00001824// ============================================================================
1825// Private Methods
1826// ============================================================================
1827
1828// ----------------------------------------------------------------------------
1829// Platform
1830// ----------------------------------------------------------------------------
1831
Max Morin787eeed2016-06-23 10:42:07 +02001832AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001833 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001834 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001835}
1836
1837// ----------------------------------------------------------------------------
1838// PlatformAudioLayer
1839// ----------------------------------------------------------------------------
1840
Max Morin787eeed2016-06-23 10:42:07 +02001841AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1842 const {
Max Morin098e6c52016-06-28 09:36:25 +02001843 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001844 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001845}
1846
1847} // namespace webrtc