blob: ccbfb1867924c200246bbc112a9d84b848995e25 [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());
henrika919dc2e2017-10-12 14:24:55 +0200211 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000212#endif
213#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +0200214#endif
henrika4af73662017-10-11 13:16:17 +0200215 } else if (audio_layer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000216#if defined(LINUX_ALSA)
henrika4af73662017-10-11 13:16:17 +0200217 // Linux ALSA implementation.
218 audio_device_.reset(new AudioDeviceLinuxALSA());
219 LOG(INFO) << "Linux ALSA APIs will be utilized.";
niklase@google.com470e71d2011-07-07 08:21:25 +0000220#endif
Max Morin787eeed2016-06-23 10:42:07 +0200221 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000222#endif // #if defined(WEBRTC_LINUX)
223
henrika4af73662017-10-11 13:16:17 +0200224// iOS ADM implementation.
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000225#if defined(WEBRTC_IOS)
henrika4af73662017-10-11 13:16:17 +0200226 if (audio_layer == kPlatformDefaultAudio) {
227 audio_device_.reset(new AudioDeviceIOS());
228 LOG(INFO) << "iPhone Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200229 }
230// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
henrika4af73662017-10-11 13:16:17 +0200232// Mac OS X ADM implementation.
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000233#elif defined(WEBRTC_MAC)
henrika4af73662017-10-11 13:16:17 +0200234 if (audio_layer == kPlatformDefaultAudio) {
235 audio_device_.reset(new AudioDeviceMac());
236 LOG(INFO) << "Mac OS X Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200237 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000238#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000239
henrika4af73662017-10-11 13:16:17 +0200240 // Dummy ADM implementation.
241 if (audio_layer == kDummyAudio) {
henrika5ff64832017-10-11 15:14:51 +0200242 audio_device_.reset(new AudioDeviceDummy());
henrika4af73662017-10-11 13:16:17 +0200243 LOG(INFO) << "Dummy Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200244 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000245#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
henrika4af73662017-10-11 13:16:17 +0200247 if (!audio_device_) {
248 LOG(LS_ERROR)
249 << "Failed to create the platform specific ADM implementation.";
Max Morin787eeed2016-06-23 10:42:07 +0200250 return -1;
251 }
Max Morin787eeed2016-06-23 10:42:07 +0200252 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000253}
254
Max Morin787eeed2016-06-23 10:42:07 +0200255int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200256 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200257 audio_device_->AttachAudioBuffer(&audio_device_buffer_);
Max Morin787eeed2016-06-23 10:42:07 +0200258 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000259}
260
Max Morin787eeed2016-06-23 10:42:07 +0200261AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200262 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000263}
264
henrikab2619892015-05-18 16:49:16 +0200265int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200266 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200267 AudioLayer activeAudio;
henrika4af73662017-10-11 13:16:17 +0200268 if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
henrikab2619892015-05-18 16:49:16 +0200269 return -1;
270 }
271 *audioLayer = activeAudio;
272 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000273}
274
henrika4af73662017-10-11 13:16:17 +0200275// TODO(henrika): remove this API.
Max Morin787eeed2016-06-23 10:42:07 +0200276AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200277 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200278 LOG(WARNING) << "Not supported";
279 return kAdmErrNone;
niklase@google.com470e71d2011-07-07 08:21:25 +0000280}
281
Max Morin787eeed2016-06-23 10:42:07 +0200282int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200283 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200284 if (initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000285 return 0;
henrika4af73662017-10-11 13:16:17 +0200286 RTC_CHECK(audio_device_);
287 AudioDeviceGeneric::InitStatus status = audio_device_->Init();
Max Morin84cab202016-07-01 13:35:19 +0200288 RTC_HISTOGRAM_ENUMERATION(
289 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
290 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
291 if (status != AudioDeviceGeneric::InitStatus::OK) {
292 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200293 return -1;
294 }
henrika4af73662017-10-11 13:16:17 +0200295 initialized_ = true;
Max Morin787eeed2016-06-23 10:42:07 +0200296 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000297}
298
Max Morin787eeed2016-06-23 10:42:07 +0200299int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200300 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200301 if (!initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000302 return 0;
henrika4af73662017-10-11 13:16:17 +0200303 if (audio_device_->Terminate() == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200304 return -1;
305 }
henrika4af73662017-10-11 13:16:17 +0200306 initialized_ = false;
Max Morin787eeed2016-06-23 10:42:07 +0200307 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000308}
309
Max Morin787eeed2016-06-23 10:42:07 +0200310bool AudioDeviceModuleImpl::Initialized() const {
henrika4af73662017-10-11 13:16:17 +0200311 LOG(INFO) << __FUNCTION__ << ": " << initialized_;
312 return initialized_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000313}
314
Max Morin787eeed2016-06-23 10:42:07 +0200315int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200316 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200317 CHECKinitialized_();
318 return audio_device_->InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000319}
320
Max Morin787eeed2016-06-23 10:42:07 +0200321int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200322 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200323 CHECKinitialized_();
324 return audio_device_->InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000325}
326
Max Morin787eeed2016-06-23 10:42:07 +0200327int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200328 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200329 CHECKinitialized_();
330 bool isAvailable = false;
331 if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200332 return -1;
333 }
Max Morin787eeed2016-06-23 10:42:07 +0200334 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200335 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200336 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
Max Morin787eeed2016-06-23 10:42:07 +0200339int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200340 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200341 CHECKinitialized_();
342 return audio_device_->SetSpeakerVolume(volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000343}
344
Max Morin787eeed2016-06-23 10:42:07 +0200345int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200346 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200347 CHECKinitialized_();
348 uint32_t level = 0;
349 if (audio_device_->SpeakerVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200350 return -1;
351 }
Max Morin787eeed2016-06-23 10:42:07 +0200352 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200353 LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200354 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000355}
356
Max Morin787eeed2016-06-23 10:42:07 +0200357bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200358 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200359 CHECKinitialized__BOOL();
360 bool isInitialized = audio_device_->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200361 LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200362 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000363}
364
Max Morin787eeed2016-06-23 10:42:07 +0200365bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200366 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200367 CHECKinitialized__BOOL();
368 bool isInitialized = audio_device_->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200369 LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200370 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000371}
372
Max Morin787eeed2016-06-23 10:42:07 +0200373int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200374 CHECKinitialized_();
375 uint32_t maxVol = 0;
376 if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200377 return -1;
378 }
Max Morin787eeed2016-06-23 10:42:07 +0200379 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200380 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000381}
382
Max Morin787eeed2016-06-23 10:42:07 +0200383int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200384 CHECKinitialized_();
385 uint32_t minVol = 0;
386 if (audio_device_->MinSpeakerVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200387 return -1;
388 }
Max Morin787eeed2016-06-23 10:42:07 +0200389 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200390 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000391}
392
Max Morin787eeed2016-06-23 10:42:07 +0200393int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200394 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200395 CHECKinitialized_();
396 bool isAvailable = false;
397 if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200398 return -1;
399 }
Max Morin787eeed2016-06-23 10:42:07 +0200400 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200401 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200402 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403}
404
Max Morin787eeed2016-06-23 10:42:07 +0200405int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200406 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200407 CHECKinitialized_();
408 return audio_device_->SetSpeakerMute(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000409}
410
Max Morin787eeed2016-06-23 10:42:07 +0200411int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200412 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200413 CHECKinitialized_();
414 bool muted = false;
415 if (audio_device_->SpeakerMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200416 return -1;
417 }
Max Morin787eeed2016-06-23 10:42:07 +0200418 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200419 LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200420 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000421}
422
Max Morin787eeed2016-06-23 10:42:07 +0200423int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200424 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200425 CHECKinitialized_();
426 bool isAvailable = false;
427 if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200428 return -1;
429 }
Max Morin787eeed2016-06-23 10:42:07 +0200430 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200431 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200432 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000433}
434
Max Morin787eeed2016-06-23 10:42:07 +0200435int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200436 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200437 CHECKinitialized_();
438 return (audio_device_->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000439}
440
Max Morin787eeed2016-06-23 10:42:07 +0200441int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200442 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200443 CHECKinitialized_();
444 bool muted = false;
445 if (audio_device_->MicrophoneMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200446 return -1;
447 }
Max Morin787eeed2016-06-23 10:42:07 +0200448 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200449 LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200450 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000451}
452
Max Morin787eeed2016-06-23 10:42:07 +0200453int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200454 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200455 CHECKinitialized_();
456 bool isAvailable = false;
457 if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200458 return -1;
459 }
Max Morin787eeed2016-06-23 10:42:07 +0200460 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200461 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200462 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000463}
464
Max Morin787eeed2016-06-23 10:42:07 +0200465int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200466 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200467 CHECKinitialized_();
468 return (audio_device_->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000469}
470
Max Morin787eeed2016-06-23 10:42:07 +0200471int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200472 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200473 CHECKinitialized_();
474 uint32_t level = 0;
475 if (audio_device_->MicrophoneVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200476 return -1;
477 }
Max Morin787eeed2016-06-23 10:42:07 +0200478 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200479 LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200480 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000481}
482
Max Morin787eeed2016-06-23 10:42:07 +0200483int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
484 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200485 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200486 CHECKinitialized_();
487 bool isAvailable = false;
488 if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200489 return -1;
490 }
Max Morin787eeed2016-06-23 10:42:07 +0200491 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200492 LOG(INFO) << "output: " << isAvailable;
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::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200497 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200498 CHECKinitialized_();
499 if (audio_device_->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200500 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200501 return -1;
502 }
henrika4af73662017-10-11 13:16:17 +0200503 if (audio_device_->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200504 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200505 return -1;
506 }
Max Morin787eeed2016-06-23 10:42:07 +0200507 int8_t nChannels(1);
508 if (enable) {
509 nChannels = 2;
510 }
henrika4af73662017-10-11 13:16:17 +0200511 audio_device_buffer_.SetRecordingChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200512 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000513}
514
Max Morin787eeed2016-06-23 10:42:07 +0200515int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200516 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200517 CHECKinitialized_();
518 bool stereo = false;
519 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200520 return -1;
521 }
Max Morin787eeed2016-06-23 10:42:07 +0200522 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200523 LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200524 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000525}
526
Max Morin787eeed2016-06-23 10:42:07 +0200527int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
528 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200529 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200530 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200531 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200532 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200533 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200534 }
henrika4af73662017-10-11 13:16:17 +0200535 CHECKinitialized_();
536 bool stereo = false;
537 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200538 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200539 return -1;
540 }
henrika4af73662017-10-11 13:16:17 +0200541 return audio_device_buffer_.SetRecordingChannel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000542}
543
Max Morin787eeed2016-06-23 10:42:07 +0200544int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200545 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200546 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200547 ChannelType chType;
henrika4af73662017-10-11 13:16:17 +0200548 if (audio_device_buffer_.RecordingChannel(chType) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200549 return -1;
550 }
Max Morin787eeed2016-06-23 10:42:07 +0200551 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200552 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +0200553 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200554 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +0200555 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200556 } else {
Max Morin2c332bb2016-07-04 09:03:42 +0200557 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200558 }
henrika4af73662017-10-11 13:16:17 +0200559 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000560}
561
Max Morin787eeed2016-06-23 10:42:07 +0200562int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200563 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200564 CHECKinitialized_();
565 bool isAvailable = false;
566 if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200567 return -1;
568 }
Max Morin787eeed2016-06-23 10:42:07 +0200569 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200570 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200571 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000572}
573
Max Morin787eeed2016-06-23 10:42:07 +0200574int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200575 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200576 CHECKinitialized_();
577 if (audio_device_->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200578 LOG(LERROR)
579 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200580 return -1;
581 }
henrika4af73662017-10-11 13:16:17 +0200582 if (audio_device_->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +0200583 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200584 return -1;
585 }
Max Morin787eeed2016-06-23 10:42:07 +0200586 int8_t nChannels(1);
587 if (enable) {
588 nChannels = 2;
589 }
henrika4af73662017-10-11 13:16:17 +0200590 audio_device_buffer_.SetPlayoutChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200591 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000592}
593
Max Morin787eeed2016-06-23 10:42:07 +0200594int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200595 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200596 CHECKinitialized_();
597 bool stereo = false;
598 if (audio_device_->StereoPlayout(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200599 return -1;
600 }
Max Morin787eeed2016-06-23 10:42:07 +0200601 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200602 LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200603 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000604}
605
Max Morin787eeed2016-06-23 10:42:07 +0200606int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200607 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200608 CHECKinitialized_();
609 return (audio_device_->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000610}
611
Max Morin787eeed2016-06-23 10:42:07 +0200612bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +0200613 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200614 CHECKinitialized__BOOL();
615 return audio_device_->AGC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000616}
617
Max Morin787eeed2016-06-23 10:42:07 +0200618int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200619 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200620 CHECKinitialized_();
621 bool isAvailable = false;
622 if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200623 return -1;
624 }
Max Morin787eeed2016-06-23 10:42:07 +0200625 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200626 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200627 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000628}
629
Max Morin787eeed2016-06-23 10:42:07 +0200630int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200631 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200632 CHECKinitialized_();
633 bool isAvailable = false;
634 if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200635 return -1;
636 }
Max Morin787eeed2016-06-23 10:42:07 +0200637 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200638 LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200639 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000640}
641
Max Morin787eeed2016-06-23 10:42:07 +0200642int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200643 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200644 uint32_t maxVol(0);
henrika4af73662017-10-11 13:16:17 +0200645 if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200646 return -1;
647 }
Max Morin787eeed2016-06-23 10:42:07 +0200648 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200649 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000650}
651
Max Morin787eeed2016-06-23 10:42:07 +0200652int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200653 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200654 uint32_t minVol(0);
henrika4af73662017-10-11 13:16:17 +0200655 if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200656 return -1;
657 }
Max Morin787eeed2016-06-23 10:42:07 +0200658 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200659 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000660}
661
Max Morin787eeed2016-06-23 10:42:07 +0200662int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +0200663 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200664 CHECKinitialized_();
665 uint16_t nPlayoutDevices = audio_device_->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +0200666 LOG(INFO) << "output: " << nPlayoutDevices;
henrika4af73662017-10-11 13:16:17 +0200667 return (int16_t)(nPlayoutDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +0000668}
669
Max Morin787eeed2016-06-23 10:42:07 +0200670int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +0200671 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200672 CHECKinitialized_();
673 return audio_device_->SetPlayoutDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000674}
675
Max Morin787eeed2016-06-23 10:42:07 +0200676int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +0200677 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200678 CHECKinitialized_();
679 return audio_device_->SetPlayoutDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000680}
681
pbos@webrtc.org25509882013-04-09 10:30:35 +0000682int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
683 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000684 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200685 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +0200686 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200687 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200688 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200689 return -1;
690 }
henrika4af73662017-10-11 13:16:17 +0200691 if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200692 return -1;
693 }
Max Morin787eeed2016-06-23 10:42:07 +0200694 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200695 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200696 }
697 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200698 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200699 }
henrika4af73662017-10-11 13:16:17 +0200700 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000701}
702
pbos@webrtc.org25509882013-04-09 10:30:35 +0000703int32_t AudioDeviceModuleImpl::RecordingDeviceName(
704 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000705 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200706 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +0200707 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200708 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200709 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200710 return -1;
711 }
henrika4af73662017-10-11 13:16:17 +0200712 if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200713 return -1;
714 }
Max Morin787eeed2016-06-23 10:42:07 +0200715 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200716 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200717 }
718 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +0200719 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200720 }
henrika4af73662017-10-11 13:16:17 +0200721 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000722}
723
Max Morin787eeed2016-06-23 10:42:07 +0200724int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +0200725 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200726 CHECKinitialized_();
727 uint16_t nRecordingDevices = audio_device_->RecordingDevices();
Max Morin2c332bb2016-07-04 09:03:42 +0200728 LOG(INFO) << "output: " << nRecordingDevices;
henrika4af73662017-10-11 13:16:17 +0200729 return (int16_t)nRecordingDevices;
niklase@google.com470e71d2011-07-07 08:21:25 +0000730}
731
Max Morin787eeed2016-06-23 10:42:07 +0200732int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +0200733 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200734 CHECKinitialized_();
735 return audio_device_->SetRecordingDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000736}
737
Max Morin787eeed2016-06-23 10:42:07 +0200738int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +0200739 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200740 CHECKinitialized_();
741 return audio_device_->SetRecordingDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000742}
743
Max Morin787eeed2016-06-23 10:42:07 +0200744int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +0200745 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200746 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700747 if (PlayoutIsInitialized()) {
748 return 0;
749 }
henrika4af73662017-10-11 13:16:17 +0200750 int32_t result = audio_device_->InitPlayout();
Max Morin84cab202016-07-01 13:35:19 +0200751 LOG(INFO) << "output: " << result;
752 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
753 static_cast<int>(result == 0));
754 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000755}
756
Max Morin787eeed2016-06-23 10:42:07 +0200757int32_t AudioDeviceModuleImpl::InitRecording() {
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 (RecordingIsInitialized()) {
761 return 0;
762 }
henrika4af73662017-10-11 13:16:17 +0200763 int32_t result = audio_device_->InitRecording();
Max Morin84cab202016-07-01 13:35:19 +0200764 LOG(INFO) << "output: " << result;
765 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
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 +0200770bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200771 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200772 CHECKinitialized__BOOL();
773 return audio_device_->PlayoutIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000774}
775
Max Morin787eeed2016-06-23 10:42:07 +0200776bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200777 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200778 CHECKinitialized__BOOL();
779 return audio_device_->RecordingIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000780}
781
Max Morin787eeed2016-06-23 10:42:07 +0200782int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +0200783 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200784 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700785 if (Playing()) {
786 return 0;
787 }
henrika4af73662017-10-11 13:16:17 +0200788 audio_device_buffer_.StartPlayout();
789 int32_t result = audio_device_->StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +0200790 LOG(INFO) << "output: " << result;
791 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
792 static_cast<int>(result == 0));
793 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000794}
795
Max Morin787eeed2016-06-23 10:42:07 +0200796int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +0200797 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200798 CHECKinitialized_();
799 int32_t result = audio_device_->StopPlayout();
800 audio_device_buffer_.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +0200801 LOG(INFO) << "output: " << result;
802 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
803 static_cast<int>(result == 0));
804 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000805}
806
Max Morin787eeed2016-06-23 10:42:07 +0200807bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +0200808 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200809 CHECKinitialized__BOOL();
810 return audio_device_->Playing();
niklase@google.com470e71d2011-07-07 08:21:25 +0000811}
812
Max Morin787eeed2016-06-23 10:42:07 +0200813int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +0200814 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200815 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700816 if (Recording()) {
817 return 0;
818 }
henrika4af73662017-10-11 13:16:17 +0200819 audio_device_buffer_.StartRecording();
820 int32_t result = audio_device_->StartRecording();
Max Morin84cab202016-07-01 13:35:19 +0200821 LOG(INFO) << "output: " << result;
822 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
823 static_cast<int>(result == 0));
824 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000825}
niklase@google.com470e71d2011-07-07 08:21:25 +0000826
Max Morin787eeed2016-06-23 10:42:07 +0200827int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +0200828 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200829 CHECKinitialized_();
830 int32_t result = audio_device_->StopRecording();
831 audio_device_buffer_.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +0200832 LOG(INFO) << "output: " << result;
833 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
834 static_cast<int>(result == 0));
835 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000836}
837
Max Morin787eeed2016-06-23 10:42:07 +0200838bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +0200839 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200840 CHECKinitialized__BOOL();
841 return audio_device_->Recording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000842}
843
Max Morin787eeed2016-06-23 10:42:07 +0200844int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
845 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +0200846 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200847 return audio_device_buffer_.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +0000848}
849
Max Morin787eeed2016-06-23 10:42:07 +0200850int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
henrika4af73662017-10-11 13:16:17 +0200851 CHECKinitialized_();
852 uint16_t delay = 0;
853 if (audio_device_->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200854 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +0200855 return -1;
856 }
Max Morin787eeed2016-06-23 10:42:07 +0200857 *delayMS = delay;
henrika4af73662017-10-11 13:16:17 +0200858 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000859}
860
Max Morin787eeed2016-06-23 10:42:07 +0200861int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +0200862 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200863 CHECKinitialized_();
864 uint16_t delay = 0;
865 if (audio_device_->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200866 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +0200867 return -1;
868 }
Max Morin787eeed2016-06-23 10:42:07 +0200869 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +0200870 LOG(INFO) << "output: " << *delayMS;
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::SetRecordingSampleRate(
875 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +0200876 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
henrika4af73662017-10-11 13:16:17 +0200877 CHECKinitialized_();
878 if (audio_device_->SetRecordingSampleRate(samplesPerSec) != 0) {
Max Morin787eeed2016-06-23 10:42:07 +0200879 return -1;
880 }
henrika4af73662017-10-11 13:16:17 +0200881 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000882}
883
Max Morin787eeed2016-06-23 10:42:07 +0200884int32_t AudioDeviceModuleImpl::RecordingSampleRate(
885 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +0200886 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200887 CHECKinitialized_();
888 int32_t sampleRate = audio_device_buffer_.RecordingSampleRate();
Max Morin787eeed2016-06-23 10:42:07 +0200889 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200890 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +0200891 return -1;
892 }
Max Morin787eeed2016-06-23 10:42:07 +0200893 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +0200894 LOG(INFO) << "output: " << *samplesPerSec;
henrika4af73662017-10-11 13:16:17 +0200895 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000896}
897
Max Morin787eeed2016-06-23 10:42:07 +0200898int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
899 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +0200900 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
henrika4af73662017-10-11 13:16:17 +0200901 CHECKinitialized_();
902 if (audio_device_->SetPlayoutSampleRate(samplesPerSec) != 0) {
Max Morin787eeed2016-06-23 10:42:07 +0200903 return -1;
904 }
henrika4af73662017-10-11 13:16:17 +0200905 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000906}
907
Max Morin787eeed2016-06-23 10:42:07 +0200908int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
909 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +0200910 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200911 CHECKinitialized_();
912 int32_t sampleRate = audio_device_buffer_.PlayoutSampleRate();
Max Morin787eeed2016-06-23 10:42:07 +0200913 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200914 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +0200915 return -1;
916 }
Max Morin787eeed2016-06-23 10:42:07 +0200917 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +0200918 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +0200919 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000920}
921
henrika4af73662017-10-11 13:16:17 +0200922int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
923 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
924 CHECKinitialized_();
925 if (audio_device_->SetLoudspeakerStatus(enable) != 0) {
926 return -1;
927 }
928 return 0;
929}
niklase@google.com470e71d2011-07-07 08:21:25 +0000930
henrikac14f5ff2015-09-23 14:08:33 +0200931int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200932 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200933 CHECKinitialized_();
Max Morin098e6c52016-06-28 09:36:25 +0200934 int32_t ok = 0;
henrika4af73662017-10-11 13:16:17 +0200935 if (audio_device_->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +0200936 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +0200937 }
Max Morin2c332bb2016-07-04 09:03:42 +0200938 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200939 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000940}
941
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000942bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +0200943 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200944 CHECKinitialized__BOOL();
945 bool isAvailable = audio_device_->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +0200946 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200947 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000948}
949
henrikac14f5ff2015-09-23 14:08:33 +0200950int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200951 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200952 CHECKinitialized_();
953 int32_t ok = audio_device_->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +0200954 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200955 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200956}
957
958bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +0200959 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200960 CHECKinitialized__BOOL();
961 bool isAvailable = audio_device_->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +0200962 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200963 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200964}
965
966int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200967 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200968 CHECKinitialized_();
969 int32_t ok = audio_device_->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +0200970 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200971 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200972}
973
974bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +0200975 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200976 CHECKinitialized__BOOL();
977 bool isAvailable = audio_device_->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +0200978 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200979 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200980}
981
982int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200983 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200984 CHECKinitialized_();
985 int32_t ok = audio_device_->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +0200986 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200987 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200988}
989
maxmorin88e31a32016-08-16 00:56:09 -0700990#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200991int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
992 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +0200993 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200994 int r = audio_device_->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +0200995 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200996 return r;
henrikaba35d052015-07-14 17:04:08 +0200997}
998
999int AudioDeviceModuleImpl::GetRecordAudioParameters(
1000 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001001 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001002 int r = audio_device_->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001003 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001004 return r;
henrikaba35d052015-07-14 17:04:08 +02001005}
maxmorin88e31a32016-08-16 00:56:09 -07001006#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001007
Max Morin787eeed2016-06-23 10:42:07 +02001008AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001009 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001010 return platform_type_;
niklase@google.com470e71d2011-07-07 08:21:25 +00001011}
1012
Max Morin787eeed2016-06-23 10:42:07 +02001013AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1014 const {
Max Morin098e6c52016-06-28 09:36:25 +02001015 LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +02001016 return audio_layer_;
niklase@google.com470e71d2011-07-07 08:21:25 +00001017}
1018
1019} // namespace webrtc