blob: 0e8bd28c506623e4b1cf326915eba2354b1dcae0 [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
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stddef.h>
14
Mirko Bonadeid9708072019-01-25 20:26:48 +010015#include "api/scoped_refptr.h"
Yves Gerey988cc082018-10-23 12:03:01 +020016#include "modules/audio_device/audio_device_config.h" // IWYU pragma: keep
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_device/audio_device_generic.h"
18#include "rtc_base/checks.h"
19#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/ref_counted_object.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
niklase@google.com470e71d2011-07-07 08:21:25 +000023#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020024#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
henrika883d00f2018-03-16 10:09:49 +010025#include "modules/audio_device/win/audio_device_core_win.h"
Max Morin787eeed2016-06-23 10:42:07 +020026#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000027#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020028#include <stdlib.h>
Mirko Bonadei185e8022019-03-27 21:11:17 +010029#if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
henrika883d00f2018-03-16 10:09:49 +010030#include "modules/audio_device/android/aaudio_player.h"
31#include "modules/audio_device/android/aaudio_recorder.h"
32#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "modules/audio_device/android/audio_device_template.h"
34#include "modules/audio_device/android/audio_manager.h"
35#include "modules/audio_device/android/audio_record_jni.h"
36#include "modules/audio_device/android/audio_track_jni.h"
37#include "modules/audio_device/android/opensles_player.h"
38#include "modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000039#elif defined(WEBRTC_LINUX)
Mirko Bonadeifc9770c2020-03-24 12:56:47 +010040#if defined(WEBRTC_ENABLE_LINUX_ALSA)
henrika883d00f2018-03-16 10:09:49 +010041#include "modules/audio_device/linux/audio_device_alsa_linux.h"
Max Morin787eeed2016-06-23 10:42:07 +020042#endif
Mirko Bonadeifc9770c2020-03-24 12:56:47 +010043#if defined(WEBRTC_ENABLE_LINUX_PULSE)
henrika883d00f2018-03-16 10:09:49 +010044#include "modules/audio_device/linux/audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020045#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000046#elif defined(WEBRTC_IOS)
Kári Tristan Helgason7a930da2019-04-10 08:43:53 +020047#include "sdk/objc/native/src/audio/audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000048#elif defined(WEBRTC_MAC)
henrika883d00f2018-03-16 10:09:49 +010049#include "modules/audio_device/mac/audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000050#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000051#if defined(WEBRTC_DUMMY_FILE_DEVICES)
Yves Gerey988cc082018-10-23 12:03:01 +020052#include "modules/audio_device/dummy/file_audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020053#include "modules/audio_device/dummy/file_audio_device_factory.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000054#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#include "modules/audio_device/dummy/audio_device_dummy.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000056
henrika4af73662017-10-11 13:16:17 +020057#define CHECKinitialized_() \
Max Morin787eeed2016-06-23 10:42:07 +020058 { \
henrika4af73662017-10-11 13:16:17 +020059 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020060 return -1; \
henrika883d00f2018-03-16 10:09:49 +010061 } \
Max Morin787eeed2016-06-23 10:42:07 +020062 }
niklase@google.com470e71d2011-07-07 08:21:25 +000063
henrika4af73662017-10-11 13:16:17 +020064#define CHECKinitialized__BOOL() \
Max Morin787eeed2016-06-23 10:42:07 +020065 { \
henrika4af73662017-10-11 13:16:17 +020066 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020067 return false; \
henrika883d00f2018-03-16 10:09:49 +010068 } \
Max Morin787eeed2016-06-23 10:42:07 +020069 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
Peter Boström1d194412016-03-21 16:44:31 +010071namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000072
Peter Boström4adbbcf2016-05-03 15:51:26 -040073rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Danil Chapovalov1c41be62019-04-01 09:16:12 +020074 AudioLayer audio_layer,
75 TaskQueueFactory* task_queue_factory) {
Mirko Bonadei3b68aa32021-01-28 09:21:06 +010076 RTC_DLOG(INFO) << __FUNCTION__;
Danil Chapovalov1c41be62019-04-01 09:16:12 +020077 return AudioDeviceModule::CreateForTest(audio_layer, task_queue_factory);
henrika5b6afc02018-09-05 14:34:40 +020078}
79
80// static
81rtc::scoped_refptr<AudioDeviceModuleForTest> AudioDeviceModule::CreateForTest(
Danil Chapovalov1c41be62019-04-01 09:16:12 +020082 AudioLayer audio_layer,
83 TaskQueueFactory* task_queue_factory) {
Mirko Bonadei3b68aa32021-01-28 09:21:06 +010084 RTC_DLOG(INFO) << __FUNCTION__;
henrikaec9c7452018-06-08 16:10:03 +020085
86 // The "AudioDeviceModule::kWindowsCoreAudio2" audio layer has its own
87 // dedicated factory method which should be used instead.
88 if (audio_layer == AudioDeviceModule::kWindowsCoreAudio2) {
89 RTC_LOG(LS_ERROR) << "Use the CreateWindowsCoreAudioAudioDeviceModule() "
90 "factory method instead for this option.";
91 return nullptr;
92 }
93
henrika4af73662017-10-11 13:16:17 +020094 // Create the generic reference counted (platform independent) implementation.
Max Morin787eeed2016-06-23 10:42:07 +020095 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
Danil Chapovalov1c41be62019-04-01 09:16:12 +020096 new rtc::RefCountedObject<AudioDeviceModuleImpl>(audio_layer,
97 task_queue_factory));
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Max Morin787eeed2016-06-23 10:42:07 +020099 // Ensure that the current platform is supported.
100 if (audioDevice->CheckPlatform() == -1) {
101 return nullptr;
102 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
Max Morin787eeed2016-06-23 10:42:07 +0200104 // Create the platform-dependent implementation.
105 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
106 return nullptr;
107 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
henrika4af73662017-10-11 13:16:17 +0200109 // Ensure that the generic audio buffer can communicate with the platform
110 // specific parts.
Max Morin787eeed2016-06-23 10:42:07 +0200111 if (audioDevice->AttachAudioBuffer() == -1) {
112 return nullptr;
113 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
Max Morin787eeed2016-06-23 10:42:07 +0200115 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116}
117
Danil Chapovalov1c41be62019-04-01 09:16:12 +0200118AudioDeviceModuleImpl::AudioDeviceModuleImpl(
119 AudioLayer audio_layer,
120 TaskQueueFactory* task_queue_factory)
121 : audio_layer_(audio_layer), audio_device_buffer_(task_queue_factory) {
Mirko Bonadei3b68aa32021-01-28 09:21:06 +0100122 RTC_DLOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000123}
124
Max Morin787eeed2016-06-23 10:42:07 +0200125int32_t AudioDeviceModuleImpl::CheckPlatform() {
Mirko Bonadei3b68aa32021-01-28 09:21:06 +0100126 RTC_DLOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200127 // Ensure that the current platform is supported
Max Morin787eeed2016-06-23 10:42:07 +0200128 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200130 platform = kPlatformWin32;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100131 RTC_LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000132#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200133 platform = kPlatformAndroid;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100134 RTC_LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000135#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200136 platform = kPlatformLinux;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100137 RTC_LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000138#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200139 platform = kPlatformIOS;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100140 RTC_LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000141#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200142 platform = kPlatformMac;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100143 RTC_LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000144#endif
Max Morin787eeed2016-06-23 10:42:07 +0200145 if (platform == kPlatformNotSupported) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100146 RTC_LOG(LERROR)
147 << "current platform is not supported => this module will self "
148 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200149 return -1;
150 }
henrika4af73662017-10-11 13:16:17 +0200151 platform_type_ = platform;
Max Morin787eeed2016-06-23 10:42:07 +0200152 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000153}
154
Max Morin787eeed2016-06-23 10:42:07 +0200155int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100156 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200157// Dummy ADM implementations if build flags are set.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000158#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
henrika5ff64832017-10-11 15:14:51 +0200159 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100160 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000161#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
henrika5ff64832017-10-11 15:14:51 +0200162 audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice());
henrika4af73662017-10-11 13:16:17 +0200163 if (audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100164 RTC_LOG(INFO) << "Will use file-playing dummy device.";
noahric6a355902016-08-17 15:19:50 -0700165 } else {
166 // Create a dummy device instead.
henrika5ff64832017-10-11 15:14:51 +0200167 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100168 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized";
noahric6a355902016-08-17 15:19:50 -0700169 }
henrika4af73662017-10-11 13:16:17 +0200170
171// Real (non-dummy) ADM implementations.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000172#else
henrika4af73662017-10-11 13:16:17 +0200173 AudioLayer audio_layer(PlatformAudioLayer());
174// Windows ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000175#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
henrika4af73662017-10-11 13:16:17 +0200176 if ((audio_layer == kWindowsCoreAudio) ||
177 (audio_layer == kPlatformDefaultAudio)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100178 RTC_LOG(INFO) << "Attempting to use the Windows Core Audio APIs...";
Max Morin787eeed2016-06-23 10:42:07 +0200179 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
henrika4af73662017-10-11 13:16:17 +0200180 audio_device_.reset(new AudioDeviceWindowsCore());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100181 RTC_LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000182 }
Max Morin787eeed2016-06-23 10:42:07 +0200183 }
184#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000186#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200187 // Create an Android audio manager.
henrika4af73662017-10-11 13:16:17 +0200188 audio_manager_android_.reset(new AudioManager());
Max Morin787eeed2016-06-23 10:42:07 +0200189 // Select best possible combination of audio layers.
henrika4af73662017-10-11 13:16:17 +0200190 if (audio_layer == kPlatformDefaultAudio) {
henrika883d00f2018-03-16 10:09:49 +0100191 if (audio_manager_android_->IsAAudioSupported()) {
192 // Use of AAudio for both playout and recording has highest priority.
193 audio_layer = kAndroidAAudioAudio;
194 } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
195 audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200196 // Use OpenSL ES for both playout and recording.
henrika4af73662017-10-11 13:16:17 +0200197 audio_layer = kAndroidOpenSLESAudio;
198 } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
199 !audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200200 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200201 // low-latency output audio path.
henrika4af73662017-10-11 13:16:17 +0200202 audio_layer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200203 } else {
henrika918b5542016-09-19 15:44:09 +0200204 // Use Java-based audio in both directions when low-latency output is
205 // not supported.
henrika4af73662017-10-11 13:16:17 +0200206 audio_layer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 }
Max Morin787eeed2016-06-23 10:42:07 +0200208 }
henrika4af73662017-10-11 13:16:17 +0200209 AudioManager* audio_manager = audio_manager_android_.get();
210 if (audio_layer == kAndroidJavaAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200211 // Java audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200212 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
213 audio_layer, audio_manager));
214 } else if (audio_layer == kAndroidOpenSLESAudio) {
henrika918b5542016-09-19 15:44:09 +0200215 // OpenSL ES based audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200216 audio_device_.reset(
217 new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
218 audio_layer, audio_manager));
219 } else if (audio_layer == kAndroidJavaInputAndOpenSLESOutputAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200220 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
221 // This combination provides low-latency output audio and at the same
222 // time support for HW AEC using the AudioRecord Java API.
henrika4af73662017-10-11 13:16:17 +0200223 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
224 audio_layer, audio_manager));
henrika883d00f2018-03-16 10:09:49 +0100225 } else if (audio_layer == kAndroidAAudioAudio) {
Mirko Bonadei185e8022019-03-27 21:11:17 +0100226#if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
henrika883d00f2018-03-16 10:09:49 +0100227 // AAudio based audio for both input and output.
228 audio_device_.reset(new AudioDeviceTemplate<AAudioRecorder, AAudioPlayer>(
229 audio_layer, audio_manager));
230#endif
231 } else if (audio_layer == kAndroidJavaInputAndAAudioOutputAudio) {
Mirko Bonadei185e8022019-03-27 21:11:17 +0100232#if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
henrika883d00f2018-03-16 10:09:49 +0100233 // Java audio for input and AAudio for output audio (i.e. mixed APIs).
234 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AAudioPlayer>(
235 audio_layer, audio_manager));
236#endif
Max Morin787eeed2016-06-23 10:42:07 +0200237 } else {
henrika883d00f2018-03-16 10:09:49 +0100238 RTC_LOG(LS_ERROR) << "The requested audio layer is not supported";
henrika4af73662017-10-11 13:16:17 +0200239 audio_device_.reset(nullptr);
Max Morin787eeed2016-06-23 10:42:07 +0200240 }
241// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
henrika4af73662017-10-11 13:16:17 +0200243// Linux ADM implementation.
Mirko Bonadeifc9770c2020-03-24 12:56:47 +0100244// Note that, WEBRTC_ENABLE_LINUX_ALSA is always defined by default when
245// WEBRTC_LINUX is defined. WEBRTC_ENABLE_LINUX_PULSE depends on the
246// 'rtc_include_pulse_audio' build flag.
henrika68435f52018-04-09 13:31:45 +0200247// TODO(bugs.webrtc.org/9127): improve support and make it more clear that
248// PulseAudio is the default selection.
niklase@google.com470e71d2011-07-07 08:21:25 +0000249#elif defined(WEBRTC_LINUX)
Mirko Bonadeifc9770c2020-03-24 12:56:47 +0100250#if !defined(WEBRTC_ENABLE_LINUX_PULSE)
henrika68435f52018-04-09 13:31:45 +0200251 // Build flag 'rtc_include_pulse_audio' is set to false. In this mode:
252 // - kPlatformDefaultAudio => ALSA, and
253 // - kLinuxAlsaAudio => ALSA, and
254 // - kLinuxPulseAudio => Invalid selection.
255 RTC_LOG(WARNING) << "PulseAudio is disabled using build flag.";
256 if ((audio_layer == kLinuxAlsaAudio) ||
henrika4af73662017-10-11 13:16:17 +0200257 (audio_layer == kPlatformDefaultAudio)) {
henrika4af73662017-10-11 13:16:17 +0200258 audio_device_.reset(new AudioDeviceLinuxALSA());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100259 RTC_LOG(INFO) << "Linux ALSA APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200260 }
henrika68435f52018-04-09 13:31:45 +0200261#else
262 // Build flag 'rtc_include_pulse_audio' is set to true (default). In this
263 // mode:
264 // - kPlatformDefaultAudio => PulseAudio, and
265 // - kLinuxPulseAudio => PulseAudio, and
266 // - kLinuxAlsaAudio => ALSA (supported but not default).
267 RTC_LOG(INFO) << "PulseAudio support is enabled.";
268 if ((audio_layer == kLinuxPulseAudio) ||
269 (audio_layer == kPlatformDefaultAudio)) {
270 // Linux PulseAudio implementation is default.
271 audio_device_.reset(new AudioDeviceLinuxPulse());
272 RTC_LOG(INFO) << "Linux PulseAudio APIs will be utilized";
273 } else if (audio_layer == kLinuxAlsaAudio) {
274 audio_device_.reset(new AudioDeviceLinuxALSA());
275 RTC_LOG(WARNING) << "Linux ALSA APIs will be utilized.";
276 }
Mirko Bonadeifc9770c2020-03-24 12:56:47 +0100277#endif // #if !defined(WEBRTC_ENABLE_LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000278#endif // #if defined(WEBRTC_LINUX)
279
henrika4af73662017-10-11 13:16:17 +0200280// iOS ADM implementation.
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000281#if defined(WEBRTC_IOS)
henrika4af73662017-10-11 13:16:17 +0200282 if (audio_layer == kPlatformDefaultAudio) {
Sam Zackrisson76443ea2020-11-26 12:18:11 +0100283 audio_device_.reset(
284 new ios_adm::AudioDeviceIOS(/*bypass_voice_processing=*/false));
Mirko Bonadei675513b2017-11-09 11:09:25 +0100285 RTC_LOG(INFO) << "iPhone Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200286 }
287// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000288
henrika4af73662017-10-11 13:16:17 +0200289// Mac OS X ADM implementation.
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000290#elif defined(WEBRTC_MAC)
henrika4af73662017-10-11 13:16:17 +0200291 if (audio_layer == kPlatformDefaultAudio) {
292 audio_device_.reset(new AudioDeviceMac());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100293 RTC_LOG(INFO) << "Mac OS X Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200294 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000295#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
henrika4af73662017-10-11 13:16:17 +0200297 // Dummy ADM implementation.
298 if (audio_layer == kDummyAudio) {
henrika5ff64832017-10-11 15:14:51 +0200299 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100300 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200301 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000302#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000303
henrika4af73662017-10-11 13:16:17 +0200304 if (!audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100305 RTC_LOG(LS_ERROR)
henrika4af73662017-10-11 13:16:17 +0200306 << "Failed to create the platform specific ADM implementation.";
Max Morin787eeed2016-06-23 10:42:07 +0200307 return -1;
308 }
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::AttachAudioBuffer() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100313 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200314 audio_device_->AttachAudioBuffer(&audio_device_buffer_);
Max Morin787eeed2016-06-23 10:42:07 +0200315 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000316}
317
Max Morin787eeed2016-06-23 10:42:07 +0200318AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100319 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000320}
321
henrikab2619892015-05-18 16:49:16 +0200322int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100323 RTC_LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200324 AudioLayer activeAudio;
henrika4af73662017-10-11 13:16:17 +0200325 if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
henrikab2619892015-05-18 16:49:16 +0200326 return -1;
327 }
328 *audioLayer = activeAudio;
329 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000330}
331
Max Morin787eeed2016-06-23 10:42:07 +0200332int32_t AudioDeviceModuleImpl::Init() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100333 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200334 if (initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000335 return 0;
henrika4af73662017-10-11 13:16:17 +0200336 RTC_CHECK(audio_device_);
337 AudioDeviceGeneric::InitStatus status = audio_device_->Init();
Max Morin84cab202016-07-01 13:35:19 +0200338 RTC_HISTOGRAM_ENUMERATION(
339 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
340 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
341 if (status != AudioDeviceGeneric::InitStatus::OK) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100342 RTC_LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200343 return -1;
344 }
henrika4af73662017-10-11 13:16:17 +0200345 initialized_ = true;
Max Morin787eeed2016-06-23 10:42:07 +0200346 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000347}
348
Max Morin787eeed2016-06-23 10:42:07 +0200349int32_t AudioDeviceModuleImpl::Terminate() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100350 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200351 if (!initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000352 return 0;
henrika4af73662017-10-11 13:16:17 +0200353 if (audio_device_->Terminate() == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200354 return -1;
355 }
henrika4af73662017-10-11 13:16:17 +0200356 initialized_ = false;
Max Morin787eeed2016-06-23 10:42:07 +0200357 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000358}
359
Max Morin787eeed2016-06-23 10:42:07 +0200360bool AudioDeviceModuleImpl::Initialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100361 RTC_LOG(INFO) << __FUNCTION__ << ": " << initialized_;
henrika4af73662017-10-11 13:16:17 +0200362 return initialized_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000363}
364
Max Morin787eeed2016-06-23 10:42:07 +0200365int32_t AudioDeviceModuleImpl::InitSpeaker() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100366 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200367 CHECKinitialized_();
368 return audio_device_->InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000369}
370
Max Morin787eeed2016-06-23 10:42:07 +0200371int32_t AudioDeviceModuleImpl::InitMicrophone() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100372 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200373 CHECKinitialized_();
374 return audio_device_->InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000375}
376
Max Morin787eeed2016-06-23 10:42:07 +0200377int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100378 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200379 CHECKinitialized_();
380 bool isAvailable = false;
381 if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200382 return -1;
383 }
Max Morin787eeed2016-06-23 10:42:07 +0200384 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100385 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200386 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000387}
388
Max Morin787eeed2016-06-23 10:42:07 +0200389int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100390 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200391 CHECKinitialized_();
392 return audio_device_->SetSpeakerVolume(volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000393}
394
Max Morin787eeed2016-06-23 10:42:07 +0200395int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100396 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200397 CHECKinitialized_();
398 uint32_t level = 0;
399 if (audio_device_->SpeakerVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200400 return -1;
401 }
Max Morin787eeed2016-06-23 10:42:07 +0200402 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100403 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200404 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000405}
406
Max Morin787eeed2016-06-23 10:42:07 +0200407bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100408 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200409 CHECKinitialized__BOOL();
410 bool isInitialized = audio_device_->SpeakerIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100411 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200412 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000413}
414
Max Morin787eeed2016-06-23 10:42:07 +0200415bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100416 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200417 CHECKinitialized__BOOL();
418 bool isInitialized = audio_device_->MicrophoneIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100419 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200420 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000421}
422
Max Morin787eeed2016-06-23 10:42:07 +0200423int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200424 CHECKinitialized_();
425 uint32_t maxVol = 0;
426 if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200427 return -1;
428 }
Max Morin787eeed2016-06-23 10:42:07 +0200429 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200430 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000431}
432
Max Morin787eeed2016-06-23 10:42:07 +0200433int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200434 CHECKinitialized_();
435 uint32_t minVol = 0;
436 if (audio_device_->MinSpeakerVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200437 return -1;
438 }
Max Morin787eeed2016-06-23 10:42:07 +0200439 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200440 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000441}
442
Max Morin787eeed2016-06-23 10:42:07 +0200443int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100444 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200445 CHECKinitialized_();
Mirko Bonadei72c42502017-11-09 09:33:23 +0100446 bool isAvailable = false;
henrika4af73662017-10-11 13:16:17 +0200447 if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200448 return -1;
449 }
Max Morin787eeed2016-06-23 10:42:07 +0200450 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100451 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200452 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000453}
454
Max Morin787eeed2016-06-23 10:42:07 +0200455int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100456 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200457 CHECKinitialized_();
458 return audio_device_->SetSpeakerMute(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000459}
460
Max Morin787eeed2016-06-23 10:42:07 +0200461int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100462 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200463 CHECKinitialized_();
464 bool muted = false;
465 if (audio_device_->SpeakerMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200466 return -1;
467 }
Max Morin787eeed2016-06-23 10:42:07 +0200468 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100469 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200470 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000471}
472
Max Morin787eeed2016-06-23 10:42:07 +0200473int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100474 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200475 CHECKinitialized_();
476 bool isAvailable = false;
477 if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200478 return -1;
479 }
Max Morin787eeed2016-06-23 10:42:07 +0200480 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100481 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200482 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000483}
484
Max Morin787eeed2016-06-23 10:42:07 +0200485int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100486 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200487 CHECKinitialized_();
488 return (audio_device_->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000489}
490
Max Morin787eeed2016-06-23 10:42:07 +0200491int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100492 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200493 CHECKinitialized_();
494 bool muted = false;
495 if (audio_device_->MicrophoneMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200496 return -1;
497 }
Max Morin787eeed2016-06-23 10:42:07 +0200498 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100499 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200500 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000501}
502
Max Morin787eeed2016-06-23 10:42:07 +0200503int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100504 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200505 CHECKinitialized_();
506 bool isAvailable = false;
507 if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200508 return -1;
509 }
Max Morin787eeed2016-06-23 10:42:07 +0200510 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100511 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200512 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000513}
514
Max Morin787eeed2016-06-23 10:42:07 +0200515int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100516 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200517 CHECKinitialized_();
518 return (audio_device_->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000519}
520
Max Morin787eeed2016-06-23 10:42:07 +0200521int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100522 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200523 CHECKinitialized_();
524 uint32_t level = 0;
525 if (audio_device_->MicrophoneVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200526 return -1;
527 }
Max Morin787eeed2016-06-23 10:42:07 +0200528 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100529 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200530 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000531}
532
Max Morin787eeed2016-06-23 10:42:07 +0200533int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
534 bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100535 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200536 CHECKinitialized_();
537 bool isAvailable = false;
538 if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200539 return -1;
540 }
Max Morin787eeed2016-06-23 10:42:07 +0200541 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100542 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200543 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000544}
545
Max Morin787eeed2016-06-23 10:42:07 +0200546int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100547 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200548 CHECKinitialized_();
549 if (audio_device_->RecordingIsInitialized()) {
Gustavo Garciaff98f4b2018-12-19 10:37:16 +0100550 RTC_LOG(LERROR)
551 << "unable to set stereo mode after recording is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200552 return -1;
553 }
henrika4af73662017-10-11 13:16:17 +0200554 if (audio_device_->SetStereoRecording(enable) == -1) {
Gustavo Garciaff98f4b2018-12-19 10:37:16 +0100555 if (enable) {
556 RTC_LOG(WARNING) << "failed to enable stereo recording";
557 }
Max Morin787eeed2016-06-23 10:42:07 +0200558 return -1;
559 }
Max Morin787eeed2016-06-23 10:42:07 +0200560 int8_t nChannels(1);
561 if (enable) {
562 nChannels = 2;
563 }
henrika4af73662017-10-11 13:16:17 +0200564 audio_device_buffer_.SetRecordingChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200565 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000566}
567
Max Morin787eeed2016-06-23 10:42:07 +0200568int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100569 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200570 CHECKinitialized_();
571 bool stereo = false;
572 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200573 return -1;
574 }
Max Morin787eeed2016-06-23 10:42:07 +0200575 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100576 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200577 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000578}
579
Max Morin787eeed2016-06-23 10:42:07 +0200580int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100581 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200582 CHECKinitialized_();
583 bool isAvailable = false;
584 if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200585 return -1;
586 }
Max Morin787eeed2016-06-23 10:42:07 +0200587 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100588 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200589 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000590}
591
Max Morin787eeed2016-06-23 10:42:07 +0200592int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100593 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200594 CHECKinitialized_();
595 if (audio_device_->PlayoutIsInitialized()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100596 RTC_LOG(LERROR)
Max Morin098e6c52016-06-28 09:36:25 +0200597 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200598 return -1;
599 }
henrika4af73662017-10-11 13:16:17 +0200600 if (audio_device_->SetStereoPlayout(enable)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100601 RTC_LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200602 return -1;
603 }
Max Morin787eeed2016-06-23 10:42:07 +0200604 int8_t nChannels(1);
605 if (enable) {
606 nChannels = 2;
607 }
henrika4af73662017-10-11 13:16:17 +0200608 audio_device_buffer_.SetPlayoutChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200609 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000610}
611
Max Morin787eeed2016-06-23 10:42:07 +0200612int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100613 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200614 CHECKinitialized_();
615 bool stereo = false;
616 if (audio_device_->StereoPlayout(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200617 return -1;
618 }
Max Morin787eeed2016-06-23 10:42:07 +0200619 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100620 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200621 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000622}
623
Max Morin787eeed2016-06-23 10:42:07 +0200624int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100625 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200626 CHECKinitialized_();
627 bool isAvailable = false;
628 if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200629 return -1;
630 }
Max Morin787eeed2016-06-23 10:42:07 +0200631 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100632 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200633 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000634}
635
Max Morin787eeed2016-06-23 10:42:07 +0200636int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100637 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200638 CHECKinitialized_();
639 bool isAvailable = false;
640 if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200641 return -1;
642 }
Max Morin787eeed2016-06-23 10:42:07 +0200643 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100644 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200645 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000646}
647
Max Morin787eeed2016-06-23 10:42:07 +0200648int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200649 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200650 uint32_t maxVol(0);
henrika4af73662017-10-11 13:16:17 +0200651 if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200652 return -1;
653 }
Max Morin787eeed2016-06-23 10:42:07 +0200654 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200655 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000656}
657
Max Morin787eeed2016-06-23 10:42:07 +0200658int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200659 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200660 uint32_t minVol(0);
henrika4af73662017-10-11 13:16:17 +0200661 if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200662 return -1;
663 }
Max Morin787eeed2016-06-23 10:42:07 +0200664 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200665 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000666}
667
Max Morin787eeed2016-06-23 10:42:07 +0200668int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100669 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200670 CHECKinitialized_();
671 uint16_t nPlayoutDevices = audio_device_->PlayoutDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100672 RTC_LOG(INFO) << "output: " << nPlayoutDevices;
henrika4af73662017-10-11 13:16:17 +0200673 return (int16_t)(nPlayoutDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +0000674}
675
Max Morin787eeed2016-06-23 10:42:07 +0200676int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100677 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200678 CHECKinitialized_();
679 return audio_device_->SetPlayoutDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000680}
681
Max Morin787eeed2016-06-23 10:42:07 +0200682int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100683 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200684 CHECKinitialized_();
685 return audio_device_->SetPlayoutDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000686}
687
pbos@webrtc.org25509882013-04-09 10:30:35 +0000688int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
689 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000690 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200691 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100692 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200693 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200694 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200695 return -1;
696 }
henrika4af73662017-10-11 13:16:17 +0200697 if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200698 return -1;
699 }
Max Morin787eeed2016-06-23 10:42:07 +0200700 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100701 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200702 }
703 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100704 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200705 }
henrika4af73662017-10-11 13:16:17 +0200706 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000707}
708
pbos@webrtc.org25509882013-04-09 10:30:35 +0000709int32_t AudioDeviceModuleImpl::RecordingDeviceName(
710 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000711 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200712 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100713 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200714 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200715 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200716 return -1;
717 }
henrika4af73662017-10-11 13:16:17 +0200718 if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200719 return -1;
720 }
Max Morin787eeed2016-06-23 10:42:07 +0200721 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100722 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200723 }
724 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100725 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200726 }
henrika4af73662017-10-11 13:16:17 +0200727 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000728}
729
Max Morin787eeed2016-06-23 10:42:07 +0200730int16_t AudioDeviceModuleImpl::RecordingDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100731 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200732 CHECKinitialized_();
733 uint16_t nRecordingDevices = audio_device_->RecordingDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100734 RTC_LOG(INFO) << "output: " << nRecordingDevices;
henrika4af73662017-10-11 13:16:17 +0200735 return (int16_t)nRecordingDevices;
niklase@google.com470e71d2011-07-07 08:21:25 +0000736}
737
Max Morin787eeed2016-06-23 10:42:07 +0200738int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100739 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200740 CHECKinitialized_();
741 return audio_device_->SetRecordingDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000742}
743
Max Morin787eeed2016-06-23 10:42:07 +0200744int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100745 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200746 CHECKinitialized_();
747 return audio_device_->SetRecordingDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000748}
749
Max Morin787eeed2016-06-23 10:42:07 +0200750int32_t AudioDeviceModuleImpl::InitPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100751 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200752 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700753 if (PlayoutIsInitialized()) {
754 return 0;
755 }
henrika4af73662017-10-11 13:16:17 +0200756 int32_t result = audio_device_->InitPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100757 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200758 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
759 static_cast<int>(result == 0));
760 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000761}
762
Max Morin787eeed2016-06-23 10:42:07 +0200763int32_t AudioDeviceModuleImpl::InitRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100764 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200765 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700766 if (RecordingIsInitialized()) {
767 return 0;
768 }
henrika4af73662017-10-11 13:16:17 +0200769 int32_t result = audio_device_->InitRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100770 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200771 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
772 static_cast<int>(result == 0));
773 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000774}
775
Max Morin787eeed2016-06-23 10:42:07 +0200776bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100777 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200778 CHECKinitialized__BOOL();
779 return audio_device_->PlayoutIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000780}
781
Max Morin787eeed2016-06-23 10:42:07 +0200782bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100783 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200784 CHECKinitialized__BOOL();
785 return audio_device_->RecordingIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000786}
787
Max Morin787eeed2016-06-23 10:42:07 +0200788int32_t AudioDeviceModuleImpl::StartPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100789 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200790 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700791 if (Playing()) {
792 return 0;
793 }
henrika4af73662017-10-11 13:16:17 +0200794 audio_device_buffer_.StartPlayout();
795 int32_t result = audio_device_->StartPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100796 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200797 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
798 static_cast<int>(result == 0));
799 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000800}
801
Max Morin787eeed2016-06-23 10:42:07 +0200802int32_t AudioDeviceModuleImpl::StopPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100803 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200804 CHECKinitialized_();
805 int32_t result = audio_device_->StopPlayout();
806 audio_device_buffer_.StopPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100807 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200808 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
809 static_cast<int>(result == 0));
810 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000811}
812
Max Morin787eeed2016-06-23 10:42:07 +0200813bool AudioDeviceModuleImpl::Playing() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100814 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200815 CHECKinitialized__BOOL();
816 return audio_device_->Playing();
niklase@google.com470e71d2011-07-07 08:21:25 +0000817}
818
Max Morin787eeed2016-06-23 10:42:07 +0200819int32_t AudioDeviceModuleImpl::StartRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100820 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200821 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700822 if (Recording()) {
823 return 0;
824 }
henrika4af73662017-10-11 13:16:17 +0200825 audio_device_buffer_.StartRecording();
826 int32_t result = audio_device_->StartRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100827 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200828 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
829 static_cast<int>(result == 0));
830 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000831}
niklase@google.com470e71d2011-07-07 08:21:25 +0000832
Max Morin787eeed2016-06-23 10:42:07 +0200833int32_t AudioDeviceModuleImpl::StopRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100834 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200835 CHECKinitialized_();
836 int32_t result = audio_device_->StopRecording();
837 audio_device_buffer_.StopRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100838 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200839 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
840 static_cast<int>(result == 0));
841 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000842}
843
Max Morin787eeed2016-06-23 10:42:07 +0200844bool AudioDeviceModuleImpl::Recording() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100845 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200846 CHECKinitialized__BOOL();
847 return audio_device_->Recording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000848}
849
Max Morin787eeed2016-06-23 10:42:07 +0200850int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
851 AudioTransport* audioCallback) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100852 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200853 return audio_device_buffer_.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +0000854}
855
Max Morin787eeed2016-06-23 10:42:07 +0200856int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
henrika4af73662017-10-11 13:16:17 +0200857 CHECKinitialized_();
858 uint16_t delay = 0;
859 if (audio_device_->PlayoutDelay(delay) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100860 RTC_LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +0200861 return -1;
862 }
Max Morin787eeed2016-06-23 10:42:07 +0200863 *delayMS = delay;
henrika4af73662017-10-11 13:16:17 +0200864 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000865}
866
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000867bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100868 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200869 CHECKinitialized__BOOL();
870 bool isAvailable = audio_device_->BuiltInAECIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100871 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200872 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000873}
874
henrikac14f5ff2015-09-23 14:08:33 +0200875int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100876 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200877 CHECKinitialized_();
878 int32_t ok = audio_device_->EnableBuiltInAEC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100879 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200880 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200881}
882
883bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100884 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200885 CHECKinitialized__BOOL();
886 bool isAvailable = audio_device_->BuiltInAGCIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100887 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200888 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200889}
890
891int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100892 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200893 CHECKinitialized_();
894 int32_t ok = audio_device_->EnableBuiltInAGC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100895 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200896 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200897}
898
899bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100900 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200901 CHECKinitialized__BOOL();
902 bool isAvailable = audio_device_->BuiltInNSIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100903 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200904 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200905}
906
907int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100908 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200909 CHECKinitialized_();
910 int32_t ok = audio_device_->EnableBuiltInNS(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100911 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200912 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200913}
914
Alex Narestbbeb1092019-08-16 11:49:04 +0200915int32_t AudioDeviceModuleImpl::GetPlayoutUnderrunCount() const {
916 RTC_LOG(INFO) << __FUNCTION__;
917 CHECKinitialized_();
918 int32_t underrunCount = audio_device_->GetPlayoutUnderrunCount();
919 RTC_LOG(INFO) << "output: " << underrunCount;
920 return underrunCount;
921}
922
maxmorin88e31a32016-08-16 00:56:09 -0700923#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200924int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
925 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100926 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200927 int r = audio_device_->GetPlayoutAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100928 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200929 return r;
henrikaba35d052015-07-14 17:04:08 +0200930}
931
932int AudioDeviceModuleImpl::GetRecordAudioParameters(
933 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100934 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200935 int r = audio_device_->GetRecordAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100936 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200937 return r;
henrikaba35d052015-07-14 17:04:08 +0200938}
maxmorin88e31a32016-08-16 00:56:09 -0700939#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200940
Max Morin787eeed2016-06-23 10:42:07 +0200941AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100942 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200943 return platform_type_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000944}
945
Max Morin787eeed2016-06-23 10:42:07 +0200946AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
947 const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100948 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200949 return audio_layer_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000950}
951
952} // namespace webrtc