blob: 2cfae0a5694726ff768d817625f121532b0c5972 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_device/audio_device_impl.h"
henrika4af73662017-10-11 13:16:17 +020012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_device/audio_device_config.h"
14#include "modules/audio_device/audio_device_generic.h"
15#include "rtc_base/checks.h"
16#include "rtc_base/logging.h"
17#include "rtc_base/refcount.h"
Niels Möller84255bb2017-10-06 13:43:23 +020018#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
niklase@google.com470e71d2011-07-07 08:21:25 +000021#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020022#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
23#include "audio_device_core_win.h"
24#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000025#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020026#include <stdlib.h>
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/audio_device/android/audio_device_template.h"
28#include "modules/audio_device/android/audio_manager.h"
29#include "modules/audio_device/android/audio_record_jni.h"
30#include "modules/audio_device/android/audio_track_jni.h"
31#include "modules/audio_device/android/opensles_player.h"
32#include "modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020034#if defined(LINUX_ALSA)
35#include "audio_device_alsa_linux.h"
36#endif
Tommi68898a22015-05-19 17:28:07 +020037#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020038#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020039#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000040#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000042#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020043#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000044#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000045#if defined(WEBRTC_DUMMY_FILE_DEVICES)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "modules/audio_device/dummy/file_audio_device_factory.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000047#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "modules/audio_device/dummy/audio_device_dummy.h"
49#include "modules/audio_device/dummy/file_audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000050
henrika4af73662017-10-11 13:16:17 +020051#define CHECKinitialized_() \
Max Morin787eeed2016-06-23 10:42:07 +020052 { \
henrika4af73662017-10-11 13:16:17 +020053 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020054 return -1; \
55 }; \
56 }
niklase@google.com470e71d2011-07-07 08:21:25 +000057
henrika4af73662017-10-11 13:16:17 +020058#define CHECKinitialized__BOOL() \
Max Morin787eeed2016-06-23 10:42:07 +020059 { \
henrika4af73662017-10-11 13:16:17 +020060 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020061 return false; \
62 }; \
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Peter Boström1d194412016-03-21 16:44:31 +010065namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000066
henrika4af73662017-10-11 13:16:17 +020067// static
henrika5ff64832017-10-11 15:14:51 +020068// TODO(henrika): remove id parameter when all clients are updated.
Peter Boström4adbbcf2016-05-03 15:51:26 -040069rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010070 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040071 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020072 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +020073 // Create the generic reference counted (platform independent) implementation.
Max Morin787eeed2016-06-23 10:42:07 +020074 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
henrika5ff64832017-10-11 15:14:51 +020075 new rtc::RefCountedObject<AudioDeviceModuleImpl>(audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000076
Max Morin787eeed2016-06-23 10:42:07 +020077 // Ensure that the current platform is supported.
78 if (audioDevice->CheckPlatform() == -1) {
79 return nullptr;
80 }
niklase@google.com470e71d2011-07-07 08:21:25 +000081
Max Morin787eeed2016-06-23 10:42:07 +020082 // Create the platform-dependent implementation.
83 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
84 return nullptr;
85 }
niklase@google.com470e71d2011-07-07 08:21:25 +000086
henrika4af73662017-10-11 13:16:17 +020087 // Ensure that the generic audio buffer can communicate with the platform
88 // specific parts.
Max Morin787eeed2016-06-23 10:42:07 +020089 if (audioDevice->AttachAudioBuffer() == -1) {
90 return nullptr;
91 }
niklase@google.com470e71d2011-07-07 08:21:25 +000092
Max Morin787eeed2016-06-23 10:42:07 +020093 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +000094}
95
henrika5ff64832017-10-11 15:14:51 +020096AudioDeviceModuleImpl::AudioDeviceModuleImpl(const AudioLayer audioLayer)
97 : audio_layer_(audioLayer) {
Max Morin098e6c52016-06-28 09:36:25 +020098 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +000099}
100
Max Morin787eeed2016-06-23 10:42:07 +0200101int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200102 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200103 // Ensure that the current platform is supported
Max Morin787eeed2016-06-23 10:42:07 +0200104 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000105#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200106 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200107 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000108#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200109 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200110 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000111#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200112 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200113 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000114#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200115 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200116 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000117#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200118 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200119 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000120#endif
Max Morin787eeed2016-06-23 10:42:07 +0200121 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200122 LOG(LERROR) << "current platform is not supported => this module will self "
123 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200124 return -1;
125 }
henrika4af73662017-10-11 13:16:17 +0200126 platform_type_ = platform;
Max Morin787eeed2016-06-23 10:42:07 +0200127 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128}
129
Max Morin787eeed2016-06-23 10:42:07 +0200130int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200131 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200132// Dummy ADM implementations if build flags are set.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000133#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
henrika5ff64832017-10-11 15:14:51 +0200134 audio_device_.reset(new AudioDeviceDummy());
Max Morin098e6c52016-06-28 09:36:25 +0200135 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000136#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
henrika5ff64832017-10-11 15:14:51 +0200137 audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice());
henrika4af73662017-10-11 13:16:17 +0200138 if (audio_device_) {
noahric6a355902016-08-17 15:19:50 -0700139 LOG(INFO) << "Will use file-playing dummy device.";
140 } else {
141 // Create a dummy device instead.
henrika5ff64832017-10-11 15:14:51 +0200142 audio_device_.reset(new AudioDeviceDummy());
noahric6a355902016-08-17 15:19:50 -0700143 LOG(INFO) << "Dummy Audio APIs will be utilized";
144 }
henrika4af73662017-10-11 13:16:17 +0200145
146// Real (non-dummy) ADM implementations.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000147#else
henrika4af73662017-10-11 13:16:17 +0200148 AudioLayer audio_layer(PlatformAudioLayer());
149// Windows ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000150#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
henrika4af73662017-10-11 13:16:17 +0200151 if ((audio_layer == kWindowsCoreAudio) ||
152 (audio_layer == kPlatformDefaultAudio)) {
153 LOG(INFO) << "Attempting to use the Windows Core Audio APIs...";
Max Morin787eeed2016-06-23 10:42:07 +0200154 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
henrika4af73662017-10-11 13:16:17 +0200155 audio_device_.reset(new AudioDeviceWindowsCore());
Max Morin098e6c52016-06-28 09:36:25 +0200156 LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000157 }
Max Morin787eeed2016-06-23 10:42:07 +0200158 }
159#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000161#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200162 // Create an Android audio manager.
henrika4af73662017-10-11 13:16:17 +0200163 audio_manager_android_.reset(new AudioManager());
Max Morin787eeed2016-06-23 10:42:07 +0200164 // Select best possible combination of audio layers.
henrika4af73662017-10-11 13:16:17 +0200165 if (audio_layer == kPlatformDefaultAudio) {
166 if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
167 audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200168 // Use OpenSL ES for both playout and recording.
henrika4af73662017-10-11 13:16:17 +0200169 audio_layer = kAndroidOpenSLESAudio;
170 } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
171 !audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200172 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200173 // low-latency output audio path.
henrika4af73662017-10-11 13:16:17 +0200174 audio_layer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200175 } else {
henrika918b5542016-09-19 15:44:09 +0200176 // Use Java-based audio in both directions when low-latency output is
177 // not supported.
henrika4af73662017-10-11 13:16:17 +0200178 audio_layer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000179 }
Max Morin787eeed2016-06-23 10:42:07 +0200180 }
henrika4af73662017-10-11 13:16:17 +0200181 AudioManager* audio_manager = audio_manager_android_.get();
182 if (audio_layer == kAndroidJavaAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200183 // Java audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200184 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
185 audio_layer, audio_manager));
186 } else if (audio_layer == kAndroidOpenSLESAudio) {
henrika918b5542016-09-19 15:44:09 +0200187 // OpenSL ES based audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200188 audio_device_.reset(
189 new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
190 audio_layer, audio_manager));
191 } else if (audio_layer == kAndroidJavaInputAndOpenSLESOutputAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200192 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
193 // This combination provides low-latency output audio and at the same
194 // time support for HW AEC using the AudioRecord Java API.
henrika4af73662017-10-11 13:16:17 +0200195 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
196 audio_layer, audio_manager));
Max Morin787eeed2016-06-23 10:42:07 +0200197 } else {
198 // Invalid audio layer.
henrika4af73662017-10-11 13:16:17 +0200199 audio_device_.reset(nullptr);
Max Morin787eeed2016-06-23 10:42:07 +0200200 }
201// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
henrika4af73662017-10-11 13:16:17 +0200203// Linux ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000204#elif defined(WEBRTC_LINUX)
henrika4af73662017-10-11 13:16:17 +0200205 if ((audio_layer == kLinuxPulseAudio) ||
206 (audio_layer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000207#if defined(LINUX_PULSE)
henrika4af73662017-10-11 13:16:17 +0200208 LOG(INFO) << "Attempting to use Linux PulseAudio APIs...";
209 // Linux PulseAudio implementation.
210 audio_device_.reset(new AudioDeviceLinuxPulse());
211 if (audio_device_->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin098e6c52016-06-28 09:36:25 +0200212 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200213 } else {
henrika4af73662017-10-11 13:16:17 +0200214 LOG(WARNING) << "Failed to initialize Linux PulseAudio "
215 "implementation.";
216 audio_device_.reset(nullptr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217#endif
218#if defined(LINUX_ALSA)
henrika4af73662017-10-11 13:16:17 +0200219 // Revert to Linux ALSA implementation instead.
220 audio_device_.reset(new AudioDeviceLinuxALSA());
221 audio_layer_ = kLinuxAlsaAudio;
222 LOG(WARNING) << "Linux PulseAudio is not supported => ALSA APIs will "
223 "be utilized instead.";
niklase@google.com470e71d2011-07-07 08:21:25 +0000224#endif
225#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 }
Max Morin787eeed2016-06-23 10:42:07 +0200227#endif
henrika4af73662017-10-11 13:16:17 +0200228 } else if (audio_layer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000229#if defined(LINUX_ALSA)
henrika4af73662017-10-11 13:16:17 +0200230 // Linux ALSA implementation.
231 audio_device_.reset(new AudioDeviceLinuxALSA());
232 LOG(INFO) << "Linux ALSA APIs will be utilized.";
niklase@google.com470e71d2011-07-07 08:21:25 +0000233#endif
Max Morin787eeed2016-06-23 10:42:07 +0200234 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000235#endif // #if defined(WEBRTC_LINUX)
236
henrika4af73662017-10-11 13:16:17 +0200237// iOS ADM implementation.
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000238#if defined(WEBRTC_IOS)
henrika4af73662017-10-11 13:16:17 +0200239 if (audio_layer == kPlatformDefaultAudio) {
240 audio_device_.reset(new AudioDeviceIOS());
241 LOG(INFO) << "iPhone Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200242 }
243// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
henrika4af73662017-10-11 13:16:17 +0200245// Mac OS X ADM implementation.
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000246#elif defined(WEBRTC_MAC)
henrika4af73662017-10-11 13:16:17 +0200247 if (audio_layer == kPlatformDefaultAudio) {
248 audio_device_.reset(new AudioDeviceMac());
249 LOG(INFO) << "Mac OS X Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200250 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000251#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000252
henrika4af73662017-10-11 13:16:17 +0200253 // Dummy ADM implementation.
254 if (audio_layer == kDummyAudio) {
henrika5ff64832017-10-11 15:14:51 +0200255 audio_device_.reset(new AudioDeviceDummy());
henrika4af73662017-10-11 13:16:17 +0200256 LOG(INFO) << "Dummy Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200257 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000258#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000259
henrika4af73662017-10-11 13:16:17 +0200260 if (!audio_device_) {
261 LOG(LS_ERROR)
262 << "Failed to create the platform specific ADM implementation.";
Max Morin787eeed2016-06-23 10:42:07 +0200263 return -1;
264 }
Max Morin787eeed2016-06-23 10:42:07 +0200265 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000266}
267
Max Morin787eeed2016-06-23 10:42:07 +0200268int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200269 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200270 audio_device_->AttachAudioBuffer(&audio_device_buffer_);
Max Morin787eeed2016-06-23 10:42:07 +0200271 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000272}
273
Max Morin787eeed2016-06-23 10:42:07 +0200274AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200275 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000276}
277
henrikab2619892015-05-18 16:49:16 +0200278int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200279 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200280 AudioLayer activeAudio;
henrika4af73662017-10-11 13:16:17 +0200281 if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
henrikab2619892015-05-18 16:49:16 +0200282 return -1;
283 }
284 *audioLayer = activeAudio;
285 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000286}
287
henrika4af73662017-10-11 13:16:17 +0200288// TODO(henrika): remove this API.
Max Morin787eeed2016-06-23 10:42:07 +0200289AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200290 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200291 LOG(WARNING) << "Not supported";
292 return kAdmErrNone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000293}
294
Max Morin787eeed2016-06-23 10:42:07 +0200295int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200296 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200297 if (initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000298 return 0;
henrika4af73662017-10-11 13:16:17 +0200299 RTC_CHECK(audio_device_);
300 AudioDeviceGeneric::InitStatus status = audio_device_->Init();
Max Morin84cab202016-07-01 13:35:19 +0200301 RTC_HISTOGRAM_ENUMERATION(
302 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
303 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
304 if (status != AudioDeviceGeneric::InitStatus::OK) {
305 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200306 return -1;
307 }
henrika4af73662017-10-11 13:16:17 +0200308 initialized_ = true;
Max Morin787eeed2016-06-23 10:42:07 +0200309 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000310}
311
Max Morin787eeed2016-06-23 10:42:07 +0200312int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200313 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200314 if (!initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000315 return 0;
henrika4af73662017-10-11 13:16:17 +0200316 if (audio_device_->Terminate() == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200317 return -1;
318 }
henrika4af73662017-10-11 13:16:17 +0200319 initialized_ = false;
Max Morin787eeed2016-06-23 10:42:07 +0200320 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000321}
322
Max Morin787eeed2016-06-23 10:42:07 +0200323bool AudioDeviceModuleImpl::Initialized() const {
henrika4af73662017-10-11 13:16:17 +0200324 LOG(INFO) << __FUNCTION__ << ": " << initialized_;
325 return initialized_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000326}
327
Max Morin787eeed2016-06-23 10:42:07 +0200328int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200329 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200330 CHECKinitialized_();
331 return audio_device_->InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000332}
333
Max Morin787eeed2016-06-23 10:42:07 +0200334int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200335 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200336 CHECKinitialized_();
337 return audio_device_->InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000338}
339
Max Morin787eeed2016-06-23 10:42:07 +0200340int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200341 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200342 CHECKinitialized_();
343 bool isAvailable = false;
344 if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200345 return -1;
346 }
Max Morin787eeed2016-06-23 10:42:07 +0200347 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200348 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200349 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000350}
351
Max Morin787eeed2016-06-23 10:42:07 +0200352int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200353 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200354 CHECKinitialized_();
355 return audio_device_->SetSpeakerVolume(volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000356}
357
Max Morin787eeed2016-06-23 10:42:07 +0200358int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200359 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200360 CHECKinitialized_();
361 uint32_t level = 0;
362 if (audio_device_->SpeakerVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200363 return -1;
364 }
Max Morin787eeed2016-06-23 10:42:07 +0200365 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200366 LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200367 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000368}
369
Max Morin787eeed2016-06-23 10:42:07 +0200370bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200371 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200372 CHECKinitialized__BOOL();
373 bool isInitialized = audio_device_->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200374 LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200375 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000376}
377
Max Morin787eeed2016-06-23 10:42:07 +0200378bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200379 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200380 CHECKinitialized__BOOL();
381 bool isInitialized = audio_device_->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200382 LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200383 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000384}
385
Max Morin787eeed2016-06-23 10:42:07 +0200386int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200387 CHECKinitialized_();
388 uint32_t maxVol = 0;
389 if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200390 return -1;
391 }
Max Morin787eeed2016-06-23 10:42:07 +0200392 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200393 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394}
395
Max Morin787eeed2016-06-23 10:42:07 +0200396int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200397 CHECKinitialized_();
398 uint32_t minVol = 0;
399 if (audio_device_->MinSpeakerVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200400 return -1;
401 }
Max Morin787eeed2016-06-23 10:42:07 +0200402 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200403 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000404}
405
Max Morin787eeed2016-06-23 10:42:07 +0200406int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200407 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200408 CHECKinitialized_();
409 bool isAvailable = false;
410 if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200411 return -1;
412 }
Max Morin787eeed2016-06-23 10:42:07 +0200413 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200414 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200415 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000416}
417
Max Morin787eeed2016-06-23 10:42:07 +0200418int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200419 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200420 CHECKinitialized_();
421 return audio_device_->SetSpeakerMute(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000422}
423
Max Morin787eeed2016-06-23 10:42:07 +0200424int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200425 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200426 CHECKinitialized_();
427 bool muted = false;
428 if (audio_device_->SpeakerMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200429 return -1;
430 }
Max Morin787eeed2016-06-23 10:42:07 +0200431 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200432 LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200433 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000434}
435
Max Morin787eeed2016-06-23 10:42:07 +0200436int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200437 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200438 CHECKinitialized_();
439 bool isAvailable = false;
440 if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200441 return -1;
442 }
Max Morin787eeed2016-06-23 10:42:07 +0200443 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200444 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200445 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000446}
447
Max Morin787eeed2016-06-23 10:42:07 +0200448int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200449 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200450 CHECKinitialized_();
451 return (audio_device_->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000452}
453
Max Morin787eeed2016-06-23 10:42:07 +0200454int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200455 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200456 CHECKinitialized_();
457 bool muted = false;
458 if (audio_device_->MicrophoneMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200459 return -1;
460 }
Max Morin787eeed2016-06-23 10:42:07 +0200461 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200462 LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200463 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000464}
465
Max Morin787eeed2016-06-23 10:42:07 +0200466int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200467 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200468 CHECKinitialized_();
469 bool isAvailable = false;
470 if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200471 return -1;
472 }
Max Morin787eeed2016-06-23 10:42:07 +0200473 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200474 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200475 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000476}
477
Max Morin787eeed2016-06-23 10:42:07 +0200478int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200479 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200480 CHECKinitialized_();
481 return (audio_device_->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000482}
483
Max Morin787eeed2016-06-23 10:42:07 +0200484int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200485 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200486 CHECKinitialized_();
487 uint32_t level = 0;
488 if (audio_device_->MicrophoneVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200489 return -1;
490 }
Max Morin787eeed2016-06-23 10:42:07 +0200491 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200492 LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200493 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000494}
495
Max Morin787eeed2016-06-23 10:42:07 +0200496int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
497 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200498 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200499 CHECKinitialized_();
500 bool isAvailable = false;
501 if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200502 return -1;
503 }
Max Morin787eeed2016-06-23 10:42:07 +0200504 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200505 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200506 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000507}
508
Max Morin787eeed2016-06-23 10:42:07 +0200509int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200510 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200511 CHECKinitialized_();
512 if (audio_device_->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200513 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200514 return -1;
515 }
henrika4af73662017-10-11 13:16:17 +0200516 if (audio_device_->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200517 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200518 return -1;
519 }
Max Morin787eeed2016-06-23 10:42:07 +0200520 int8_t nChannels(1);
521 if (enable) {
522 nChannels = 2;
523 }
henrika4af73662017-10-11 13:16:17 +0200524 audio_device_buffer_.SetRecordingChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200525 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000526}
527
Max Morin787eeed2016-06-23 10:42:07 +0200528int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200529 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200530 CHECKinitialized_();
531 bool stereo = false;
532 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200533 return -1;
534 }
Max Morin787eeed2016-06-23 10:42:07 +0200535 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200536 LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200537 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000538}
539
Max Morin787eeed2016-06-23 10:42:07 +0200540int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
541 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200542 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200543 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200544 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200545 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200546 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200547 }
henrika4af73662017-10-11 13:16:17 +0200548 CHECKinitialized_();
549 bool stereo = false;
550 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200551 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200552 return -1;
553 }
henrika4af73662017-10-11 13:16:17 +0200554 return audio_device_buffer_.SetRecordingChannel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000555}
556
Max Morin787eeed2016-06-23 10:42:07 +0200557int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200558 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200559 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200560 ChannelType chType;
henrika4af73662017-10-11 13:16:17 +0200561 if (audio_device_buffer_.RecordingChannel(chType) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200562 return -1;
563 }
Max Morin787eeed2016-06-23 10:42:07 +0200564 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200565 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +0200566 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200567 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +0200568 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200569 } else {
Max Morin2c332bb2016-07-04 09:03:42 +0200570 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200571 }
henrika4af73662017-10-11 13:16:17 +0200572 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000573}
574
Max Morin787eeed2016-06-23 10:42:07 +0200575int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200576 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200577 CHECKinitialized_();
578 bool isAvailable = false;
579 if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200580 return -1;
581 }
Max Morin787eeed2016-06-23 10:42:07 +0200582 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200583 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200584 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000585}
586
Max Morin787eeed2016-06-23 10:42:07 +0200587int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200588 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200589 CHECKinitialized_();
590 if (audio_device_->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200591 LOG(LERROR)
592 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200593 return -1;
594 }
henrika4af73662017-10-11 13:16:17 +0200595 if (audio_device_->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +0200596 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200597 return -1;
598 }
Max Morin787eeed2016-06-23 10:42:07 +0200599 int8_t nChannels(1);
600 if (enable) {
601 nChannels = 2;
602 }
henrika4af73662017-10-11 13:16:17 +0200603 audio_device_buffer_.SetPlayoutChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200604 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000605}
606
Max Morin787eeed2016-06-23 10:42:07 +0200607int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200608 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200609 CHECKinitialized_();
610 bool stereo = false;
611 if (audio_device_->StereoPlayout(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200612 return -1;
613 }
Max Morin787eeed2016-06-23 10:42:07 +0200614 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200615 LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200616 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000617}
618
Max Morin787eeed2016-06-23 10:42:07 +0200619int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200620 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200621 CHECKinitialized_();
622 return (audio_device_->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000623}
624
Max Morin787eeed2016-06-23 10:42:07 +0200625bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +0200626 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200627 CHECKinitialized__BOOL();
628 return audio_device_->AGC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000629}
630
Max Morin787eeed2016-06-23 10:42:07 +0200631int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200632 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200633 CHECKinitialized_();
634 bool isAvailable = false;
635 if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200636 return -1;
637 }
Max Morin787eeed2016-06-23 10:42:07 +0200638 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200639 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200640 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000641}
642
Max Morin787eeed2016-06-23 10:42:07 +0200643int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200644 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200645 CHECKinitialized_();
646 bool isAvailable = false;
647 if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200648 return -1;
649 }
Max Morin787eeed2016-06-23 10:42:07 +0200650 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200651 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200652 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000653}
654
Max Morin787eeed2016-06-23 10:42:07 +0200655int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200656 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200657 uint32_t maxVol(0);
henrika4af73662017-10-11 13:16:17 +0200658 if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200659 return -1;
660 }
Max Morin787eeed2016-06-23 10:42:07 +0200661 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200662 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000663}
664
Max Morin787eeed2016-06-23 10:42:07 +0200665int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200666 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200667 uint32_t minVol(0);
henrika4af73662017-10-11 13:16:17 +0200668 if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200669 return -1;
670 }
Max Morin787eeed2016-06-23 10:42:07 +0200671 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200672 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000673}
674
Max Morin787eeed2016-06-23 10:42:07 +0200675int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +0200676 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200677 CHECKinitialized_();
678 uint16_t nPlayoutDevices = audio_device_->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +0200679 LOG(INFO) << "output: " << nPlayoutDevices;
henrika4af73662017-10-11 13:16:17 +0200680 return (int16_t)(nPlayoutDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +0000681}
682
Max Morin787eeed2016-06-23 10:42:07 +0200683int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +0200684 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200685 CHECKinitialized_();
686 return audio_device_->SetPlayoutDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000687}
688
Max Morin787eeed2016-06-23 10:42:07 +0200689int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +0200690 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200691 CHECKinitialized_();
692 return audio_device_->SetPlayoutDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000693}
694
pbos@webrtc.org25509882013-04-09 10:30:35 +0000695int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
696 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000697 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200698 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +0200699 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200700 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200701 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200702 return -1;
703 }
henrika4af73662017-10-11 13:16:17 +0200704 if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200705 return -1;
706 }
Max Morin787eeed2016-06-23 10:42:07 +0200707 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200708 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200709 }
710 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200711 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200712 }
henrika4af73662017-10-11 13:16:17 +0200713 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000714}
715
pbos@webrtc.org25509882013-04-09 10:30:35 +0000716int32_t AudioDeviceModuleImpl::RecordingDeviceName(
717 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000718 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200719 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +0200720 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200721 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200722 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200723 return -1;
724 }
henrika4af73662017-10-11 13:16:17 +0200725 if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200726 return -1;
727 }
Max Morin787eeed2016-06-23 10:42:07 +0200728 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200729 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200730 }
731 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200732 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200733 }
henrika4af73662017-10-11 13:16:17 +0200734 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000735}
736
Max Morin787eeed2016-06-23 10:42:07 +0200737int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +0200738 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200739 CHECKinitialized_();
740 uint16_t nRecordingDevices = audio_device_->RecordingDevices();
Max Morin2c332bb2016-07-04 09:03:42 +0200741 LOG(INFO) << "output: " << nRecordingDevices;
henrika4af73662017-10-11 13:16:17 +0200742 return (int16_t)nRecordingDevices;
niklase@google.com470e71d2011-07-07 08:21:25 +0000743}
744
Max Morin787eeed2016-06-23 10:42:07 +0200745int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +0200746 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200747 CHECKinitialized_();
748 return audio_device_->SetRecordingDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000749}
750
Max Morin787eeed2016-06-23 10:42:07 +0200751int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +0200752 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200753 CHECKinitialized_();
754 return audio_device_->SetRecordingDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000755}
756
Max Morin787eeed2016-06-23 10:42:07 +0200757int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +0200758 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200759 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700760 if (PlayoutIsInitialized()) {
761 return 0;
762 }
henrika4af73662017-10-11 13:16:17 +0200763 int32_t result = audio_device_->InitPlayout();
Max Morin84cab202016-07-01 13:35:19 +0200764 LOG(INFO) << "output: " << result;
765 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
766 static_cast<int>(result == 0));
767 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000768}
769
Max Morin787eeed2016-06-23 10:42:07 +0200770int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +0200771 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200772 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700773 if (RecordingIsInitialized()) {
774 return 0;
775 }
henrika4af73662017-10-11 13:16:17 +0200776 int32_t result = audio_device_->InitRecording();
Max Morin84cab202016-07-01 13:35:19 +0200777 LOG(INFO) << "output: " << result;
778 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
779 static_cast<int>(result == 0));
780 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000781}
782
Max Morin787eeed2016-06-23 10:42:07 +0200783bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200784 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200785 CHECKinitialized__BOOL();
786 return audio_device_->PlayoutIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000787}
788
Max Morin787eeed2016-06-23 10:42:07 +0200789bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200790 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200791 CHECKinitialized__BOOL();
792 return audio_device_->RecordingIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000793}
794
Max Morin787eeed2016-06-23 10:42:07 +0200795int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +0200796 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200797 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700798 if (Playing()) {
799 return 0;
800 }
henrika4af73662017-10-11 13:16:17 +0200801 audio_device_buffer_.StartPlayout();
802 int32_t result = audio_device_->StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +0200803 LOG(INFO) << "output: " << result;
804 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
805 static_cast<int>(result == 0));
806 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000807}
808
Max Morin787eeed2016-06-23 10:42:07 +0200809int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +0200810 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200811 CHECKinitialized_();
812 int32_t result = audio_device_->StopPlayout();
813 audio_device_buffer_.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +0200814 LOG(INFO) << "output: " << result;
815 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
816 static_cast<int>(result == 0));
817 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000818}
819
Max Morin787eeed2016-06-23 10:42:07 +0200820bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +0200821 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200822 CHECKinitialized__BOOL();
823 return audio_device_->Playing();
niklase@google.com470e71d2011-07-07 08:21:25 +0000824}
825
Max Morin787eeed2016-06-23 10:42:07 +0200826int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +0200827 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200828 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700829 if (Recording()) {
830 return 0;
831 }
henrika4af73662017-10-11 13:16:17 +0200832 audio_device_buffer_.StartRecording();
833 int32_t result = audio_device_->StartRecording();
Max Morin84cab202016-07-01 13:35:19 +0200834 LOG(INFO) << "output: " << result;
835 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
836 static_cast<int>(result == 0));
837 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000838}
niklase@google.com470e71d2011-07-07 08:21:25 +0000839
Max Morin787eeed2016-06-23 10:42:07 +0200840int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +0200841 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200842 CHECKinitialized_();
843 int32_t result = audio_device_->StopRecording();
844 audio_device_buffer_.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +0200845 LOG(INFO) << "output: " << result;
846 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
847 static_cast<int>(result == 0));
848 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000849}
850
Max Morin787eeed2016-06-23 10:42:07 +0200851bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +0200852 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200853 CHECKinitialized__BOOL();
854 return audio_device_->Recording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000855}
856
Max Morin787eeed2016-06-23 10:42:07 +0200857int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
858 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +0200859 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200860 return audio_device_buffer_.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +0000861}
862
Max Morin787eeed2016-06-23 10:42:07 +0200863int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
henrika4af73662017-10-11 13:16:17 +0200864 CHECKinitialized_();
865 uint16_t delay = 0;
866 if (audio_device_->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200867 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +0200868 return -1;
869 }
Max Morin787eeed2016-06-23 10:42:07 +0200870 *delayMS = delay;
henrika4af73662017-10-11 13:16:17 +0200871 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000872}
873
Max Morin787eeed2016-06-23 10:42:07 +0200874int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +0200875 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200876 CHECKinitialized_();
877 uint16_t delay = 0;
878 if (audio_device_->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200879 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +0200880 return -1;
881 }
Max Morin787eeed2016-06-23 10:42:07 +0200882 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +0200883 LOG(INFO) << "output: " << *delayMS;
henrika4af73662017-10-11 13:16:17 +0200884 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000885}
886
Max Morin787eeed2016-06-23 10:42:07 +0200887int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
888 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +0200889 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
henrika4af73662017-10-11 13:16:17 +0200890 CHECKinitialized_();
891 if (audio_device_->SetRecordingSampleRate(samplesPerSec) != 0) {
Max Morin787eeed2016-06-23 10:42:07 +0200892 return -1;
893 }
henrika4af73662017-10-11 13:16:17 +0200894 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000895}
896
Max Morin787eeed2016-06-23 10:42:07 +0200897int32_t AudioDeviceModuleImpl::RecordingSampleRate(
898 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +0200899 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200900 CHECKinitialized_();
901 int32_t sampleRate = audio_device_buffer_.RecordingSampleRate();
Max Morin787eeed2016-06-23 10:42:07 +0200902 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200903 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +0200904 return -1;
905 }
Max Morin787eeed2016-06-23 10:42:07 +0200906 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +0200907 LOG(INFO) << "output: " << *samplesPerSec;
henrika4af73662017-10-11 13:16:17 +0200908 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000909}
910
Max Morin787eeed2016-06-23 10:42:07 +0200911int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
912 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +0200913 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
henrika4af73662017-10-11 13:16:17 +0200914 CHECKinitialized_();
915 if (audio_device_->SetPlayoutSampleRate(samplesPerSec) != 0) {
Max Morin787eeed2016-06-23 10:42:07 +0200916 return -1;
917 }
henrika4af73662017-10-11 13:16:17 +0200918 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000919}
920
Max Morin787eeed2016-06-23 10:42:07 +0200921int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
922 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +0200923 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200924 CHECKinitialized_();
925 int32_t sampleRate = audio_device_buffer_.PlayoutSampleRate();
Max Morin787eeed2016-06-23 10:42:07 +0200926 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200927 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +0200928 return -1;
929 }
Max Morin787eeed2016-06-23 10:42:07 +0200930 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +0200931 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +0200932 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000933}
934
henrika4af73662017-10-11 13:16:17 +0200935int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
936 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
937 CHECKinitialized_();
938 if (audio_device_->SetLoudspeakerStatus(enable) != 0) {
939 return -1;
940 }
941 return 0;
942}
niklase@google.com470e71d2011-07-07 08:21:25 +0000943
henrikac14f5ff2015-09-23 14:08:33 +0200944int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200945 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200946 CHECKinitialized_();
Max Morin098e6c52016-06-28 09:36:25 +0200947 int32_t ok = 0;
henrika4af73662017-10-11 13:16:17 +0200948 if (audio_device_->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +0200949 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +0200950 }
Max Morin2c332bb2016-07-04 09:03:42 +0200951 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200952 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000953}
954
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000955bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +0200956 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200957 CHECKinitialized__BOOL();
958 bool isAvailable = audio_device_->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +0200959 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200960 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000961}
962
henrikac14f5ff2015-09-23 14:08:33 +0200963int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200964 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200965 CHECKinitialized_();
966 int32_t ok = audio_device_->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +0200967 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200968 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200969}
970
971bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +0200972 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200973 CHECKinitialized__BOOL();
974 bool isAvailable = audio_device_->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +0200975 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200976 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200977}
978
979int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200980 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200981 CHECKinitialized_();
982 int32_t ok = audio_device_->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +0200983 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200984 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200985}
986
987bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +0200988 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200989 CHECKinitialized__BOOL();
990 bool isAvailable = audio_device_->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +0200991 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200992 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200993}
994
995int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200996 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200997 CHECKinitialized_();
998 int32_t ok = audio_device_->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +0200999 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001000 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001001}
1002
maxmorin88e31a32016-08-16 00:56:09 -07001003#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001004int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1005 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001006 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001007 int r = audio_device_->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001008 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001009 return r;
henrikaba35d052015-07-14 17:04:08 +02001010}
1011
1012int AudioDeviceModuleImpl::GetRecordAudioParameters(
1013 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001014 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001015 int r = audio_device_->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001016 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001017 return r;
henrikaba35d052015-07-14 17:04:08 +02001018}
maxmorin88e31a32016-08-16 00:56:09 -07001019#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001020
Max Morin787eeed2016-06-23 10:42:07 +02001021AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001022 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001023 return platform_type_;
niklase@google.com470e71d2011-07-07 08:21:25 +00001024}
1025
Max Morin787eeed2016-06-23 10:42:07 +02001026AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1027 const {
Max Morin098e6c52016-06-28 09:36:25 +02001028 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001029 return audio_layer_;
niklase@google.com470e71d2011-07-07 08:21:25 +00001030}
1031
1032} // namespace webrtc