blob: 95f9f039934c4d2a77514ea8a4dd923287a048e0 [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)
Max Morin787eeed2016-06-23 10:42:07 +020040#if defined(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
Tommi68898a22015-05-19 17:28:07 +020043#if defined(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) {
76 RTC_LOG(INFO) << __FUNCTION__;
77 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) {
henrika5b6afc02018-09-05 14:34:40 +020084 RTC_LOG(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 Bonadei675513b2017-11-09 11:09:25 +0100122 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000123}
124
Max Morin787eeed2016-06-23 10:42:07 +0200125int32_t AudioDeviceModuleImpl::CheckPlatform() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100126 RTC_LOG(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.
henrika68435f52018-04-09 13:31:45 +0200244// Note that, LINUX_ALSA is always defined by default when WEBRTC_LINUX is
245// defined. LINUX_PULSE depends on the 'rtc_include_pulse_audio' build flag.
246// TODO(bugs.webrtc.org/9127): improve support and make it more clear that
247// PulseAudio is the default selection.
niklase@google.com470e71d2011-07-07 08:21:25 +0000248#elif defined(WEBRTC_LINUX)
henrika68435f52018-04-09 13:31:45 +0200249#if !defined(LINUX_PULSE)
250 // Build flag 'rtc_include_pulse_audio' is set to false. In this mode:
251 // - kPlatformDefaultAudio => ALSA, and
252 // - kLinuxAlsaAudio => ALSA, and
253 // - kLinuxPulseAudio => Invalid selection.
254 RTC_LOG(WARNING) << "PulseAudio is disabled using build flag.";
255 if ((audio_layer == kLinuxAlsaAudio) ||
henrika4af73662017-10-11 13:16:17 +0200256 (audio_layer == kPlatformDefaultAudio)) {
henrika4af73662017-10-11 13:16:17 +0200257 audio_device_.reset(new AudioDeviceLinuxALSA());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100258 RTC_LOG(INFO) << "Linux ALSA APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200259 }
henrika68435f52018-04-09 13:31:45 +0200260#else
261 // Build flag 'rtc_include_pulse_audio' is set to true (default). In this
262 // mode:
263 // - kPlatformDefaultAudio => PulseAudio, and
264 // - kLinuxPulseAudio => PulseAudio, and
265 // - kLinuxAlsaAudio => ALSA (supported but not default).
266 RTC_LOG(INFO) << "PulseAudio support is enabled.";
267 if ((audio_layer == kLinuxPulseAudio) ||
268 (audio_layer == kPlatformDefaultAudio)) {
269 // Linux PulseAudio implementation is default.
270 audio_device_.reset(new AudioDeviceLinuxPulse());
271 RTC_LOG(INFO) << "Linux PulseAudio APIs will be utilized";
272 } else if (audio_layer == kLinuxAlsaAudio) {
273 audio_device_.reset(new AudioDeviceLinuxALSA());
274 RTC_LOG(WARNING) << "Linux ALSA APIs will be utilized.";
275 }
276#endif // #if !defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000277#endif // #if defined(WEBRTC_LINUX)
278
henrika4af73662017-10-11 13:16:17 +0200279// iOS ADM implementation.
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000280#if defined(WEBRTC_IOS)
henrika4af73662017-10-11 13:16:17 +0200281 if (audio_layer == kPlatformDefaultAudio) {
Kári Tristan Helgason7a930da2019-04-10 08:43:53 +0200282 audio_device_.reset(new ios_adm::AudioDeviceIOS());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100283 RTC_LOG(INFO) << "iPhone Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200284 }
285// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000286
henrika4af73662017-10-11 13:16:17 +0200287// Mac OS X ADM implementation.
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000288#elif defined(WEBRTC_MAC)
henrika4af73662017-10-11 13:16:17 +0200289 if (audio_layer == kPlatformDefaultAudio) {
290 audio_device_.reset(new AudioDeviceMac());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100291 RTC_LOG(INFO) << "Mac OS X Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200292 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000293#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000294
henrika4af73662017-10-11 13:16:17 +0200295 // Dummy ADM implementation.
296 if (audio_layer == kDummyAudio) {
henrika5ff64832017-10-11 15:14:51 +0200297 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100298 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200299 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000300#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
henrika4af73662017-10-11 13:16:17 +0200302 if (!audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100303 RTC_LOG(LS_ERROR)
henrika4af73662017-10-11 13:16:17 +0200304 << "Failed to create the platform specific ADM implementation.";
Max Morin787eeed2016-06-23 10:42:07 +0200305 return -1;
306 }
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 +0200310int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100311 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200312 audio_device_->AttachAudioBuffer(&audio_device_buffer_);
Max Morin787eeed2016-06-23 10:42:07 +0200313 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000314}
315
Max Morin787eeed2016-06-23 10:42:07 +0200316AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100317 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000318}
319
henrikab2619892015-05-18 16:49:16 +0200320int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100321 RTC_LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200322 AudioLayer activeAudio;
henrika4af73662017-10-11 13:16:17 +0200323 if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
henrikab2619892015-05-18 16:49:16 +0200324 return -1;
325 }
326 *audioLayer = activeAudio;
327 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000328}
329
Max Morin787eeed2016-06-23 10:42:07 +0200330int32_t AudioDeviceModuleImpl::Init() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100331 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200332 if (initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000333 return 0;
henrika4af73662017-10-11 13:16:17 +0200334 RTC_CHECK(audio_device_);
335 AudioDeviceGeneric::InitStatus status = audio_device_->Init();
Max Morin84cab202016-07-01 13:35:19 +0200336 RTC_HISTOGRAM_ENUMERATION(
337 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
338 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
339 if (status != AudioDeviceGeneric::InitStatus::OK) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100340 RTC_LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200341 return -1;
342 }
henrika4af73662017-10-11 13:16:17 +0200343 initialized_ = true;
Max Morin787eeed2016-06-23 10:42:07 +0200344 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000345}
346
Max Morin787eeed2016-06-23 10:42:07 +0200347int32_t AudioDeviceModuleImpl::Terminate() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100348 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200349 if (!initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000350 return 0;
henrika4af73662017-10-11 13:16:17 +0200351 if (audio_device_->Terminate() == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200352 return -1;
353 }
henrika4af73662017-10-11 13:16:17 +0200354 initialized_ = false;
Max Morin787eeed2016-06-23 10:42:07 +0200355 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000356}
357
Max Morin787eeed2016-06-23 10:42:07 +0200358bool AudioDeviceModuleImpl::Initialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100359 RTC_LOG(INFO) << __FUNCTION__ << ": " << initialized_;
henrika4af73662017-10-11 13:16:17 +0200360 return initialized_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000361}
362
Max Morin787eeed2016-06-23 10:42:07 +0200363int32_t AudioDeviceModuleImpl::InitSpeaker() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100364 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200365 CHECKinitialized_();
366 return audio_device_->InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000367}
368
Max Morin787eeed2016-06-23 10:42:07 +0200369int32_t AudioDeviceModuleImpl::InitMicrophone() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100370 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200371 CHECKinitialized_();
372 return audio_device_->InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000373}
374
Max Morin787eeed2016-06-23 10:42:07 +0200375int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100376 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200377 CHECKinitialized_();
378 bool isAvailable = false;
379 if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200380 return -1;
381 }
Max Morin787eeed2016-06-23 10:42:07 +0200382 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100383 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200384 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000385}
386
Max Morin787eeed2016-06-23 10:42:07 +0200387int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100388 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200389 CHECKinitialized_();
390 return audio_device_->SetSpeakerVolume(volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000391}
392
Max Morin787eeed2016-06-23 10:42:07 +0200393int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100394 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200395 CHECKinitialized_();
396 uint32_t level = 0;
397 if (audio_device_->SpeakerVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200398 return -1;
399 }
Max Morin787eeed2016-06-23 10:42:07 +0200400 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100401 RTC_LOG(INFO) << "output: " << *volume;
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 +0200405bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100406 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200407 CHECKinitialized__BOOL();
408 bool isInitialized = audio_device_->SpeakerIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100409 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200410 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000411}
412
Max Morin787eeed2016-06-23 10:42:07 +0200413bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100414 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200415 CHECKinitialized__BOOL();
416 bool isInitialized = audio_device_->MicrophoneIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100417 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200418 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000419}
420
Max Morin787eeed2016-06-23 10:42:07 +0200421int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200422 CHECKinitialized_();
423 uint32_t maxVol = 0;
424 if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200425 return -1;
426 }
Max Morin787eeed2016-06-23 10:42:07 +0200427 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200428 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000429}
430
Max Morin787eeed2016-06-23 10:42:07 +0200431int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200432 CHECKinitialized_();
433 uint32_t minVol = 0;
434 if (audio_device_->MinSpeakerVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200435 return -1;
436 }
Max Morin787eeed2016-06-23 10:42:07 +0200437 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200438 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000439}
440
Max Morin787eeed2016-06-23 10:42:07 +0200441int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100442 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200443 CHECKinitialized_();
Mirko Bonadei72c42502017-11-09 09:33:23 +0100444 bool isAvailable = false;
henrika4af73662017-10-11 13:16:17 +0200445 if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200446 return -1;
447 }
Max Morin787eeed2016-06-23 10:42:07 +0200448 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100449 RTC_LOG(INFO) << "output: " << isAvailable;
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::SetSpeakerMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100454 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200455 CHECKinitialized_();
456 return audio_device_->SetSpeakerMute(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000457}
458
Max Morin787eeed2016-06-23 10:42:07 +0200459int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100460 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200461 CHECKinitialized_();
462 bool muted = false;
463 if (audio_device_->SpeakerMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200464 return -1;
465 }
Max Morin787eeed2016-06-23 10:42:07 +0200466 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100467 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200468 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000469}
470
Max Morin787eeed2016-06-23 10:42:07 +0200471int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100472 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200473 CHECKinitialized_();
474 bool isAvailable = false;
475 if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200476 return -1;
477 }
Max Morin787eeed2016-06-23 10:42:07 +0200478 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100479 RTC_LOG(INFO) << "output: " << isAvailable;
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::SetMicrophoneMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100484 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200485 CHECKinitialized_();
486 return (audio_device_->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000487}
488
Max Morin787eeed2016-06-23 10:42:07 +0200489int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100490 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200491 CHECKinitialized_();
492 bool muted = false;
493 if (audio_device_->MicrophoneMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200494 return -1;
495 }
Max Morin787eeed2016-06-23 10:42:07 +0200496 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100497 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200498 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000499}
500
Max Morin787eeed2016-06-23 10:42:07 +0200501int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100502 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200503 CHECKinitialized_();
504 bool isAvailable = false;
505 if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200506 return -1;
507 }
Max Morin787eeed2016-06-23 10:42:07 +0200508 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100509 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200510 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000511}
512
Max Morin787eeed2016-06-23 10:42:07 +0200513int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100514 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200515 CHECKinitialized_();
516 return (audio_device_->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000517}
518
Max Morin787eeed2016-06-23 10:42:07 +0200519int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100520 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200521 CHECKinitialized_();
522 uint32_t level = 0;
523 if (audio_device_->MicrophoneVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200524 return -1;
525 }
Max Morin787eeed2016-06-23 10:42:07 +0200526 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100527 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200528 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000529}
530
Max Morin787eeed2016-06-23 10:42:07 +0200531int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
532 bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100533 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200534 CHECKinitialized_();
535 bool isAvailable = false;
536 if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200537 return -1;
538 }
Max Morin787eeed2016-06-23 10:42:07 +0200539 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100540 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200541 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000542}
543
Max Morin787eeed2016-06-23 10:42:07 +0200544int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100545 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200546 CHECKinitialized_();
547 if (audio_device_->RecordingIsInitialized()) {
Gustavo Garciaff98f4b2018-12-19 10:37:16 +0100548 RTC_LOG(LERROR)
549 << "unable to set stereo mode after recording is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200550 return -1;
551 }
henrika4af73662017-10-11 13:16:17 +0200552 if (audio_device_->SetStereoRecording(enable) == -1) {
Gustavo Garciaff98f4b2018-12-19 10:37:16 +0100553 if (enable) {
554 RTC_LOG(WARNING) << "failed to enable stereo recording";
555 }
Max Morin787eeed2016-06-23 10:42:07 +0200556 return -1;
557 }
Max Morin787eeed2016-06-23 10:42:07 +0200558 int8_t nChannels(1);
559 if (enable) {
560 nChannels = 2;
561 }
henrika4af73662017-10-11 13:16:17 +0200562 audio_device_buffer_.SetRecordingChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200563 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000564}
565
Max Morin787eeed2016-06-23 10:42:07 +0200566int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100567 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200568 CHECKinitialized_();
569 bool stereo = false;
570 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200571 return -1;
572 }
Max Morin787eeed2016-06-23 10:42:07 +0200573 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100574 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200575 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000576}
577
Max Morin787eeed2016-06-23 10:42:07 +0200578int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100579 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200580 CHECKinitialized_();
581 bool isAvailable = false;
582 if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200583 return -1;
584 }
Max Morin787eeed2016-06-23 10:42:07 +0200585 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100586 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200587 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000588}
589
Max Morin787eeed2016-06-23 10:42:07 +0200590int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100591 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200592 CHECKinitialized_();
593 if (audio_device_->PlayoutIsInitialized()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100594 RTC_LOG(LERROR)
Max Morin098e6c52016-06-28 09:36:25 +0200595 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200596 return -1;
597 }
henrika4af73662017-10-11 13:16:17 +0200598 if (audio_device_->SetStereoPlayout(enable)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100599 RTC_LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200600 return -1;
601 }
Max Morin787eeed2016-06-23 10:42:07 +0200602 int8_t nChannels(1);
603 if (enable) {
604 nChannels = 2;
605 }
henrika4af73662017-10-11 13:16:17 +0200606 audio_device_buffer_.SetPlayoutChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200607 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000608}
609
Max Morin787eeed2016-06-23 10:42:07 +0200610int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100611 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200612 CHECKinitialized_();
613 bool stereo = false;
614 if (audio_device_->StereoPlayout(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200615 return -1;
616 }
Max Morin787eeed2016-06-23 10:42:07 +0200617 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100618 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200619 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000620}
621
Max Morin787eeed2016-06-23 10:42:07 +0200622int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100623 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200624 CHECKinitialized_();
625 bool isAvailable = false;
626 if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200627 return -1;
628 }
Max Morin787eeed2016-06-23 10:42:07 +0200629 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100630 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200631 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000632}
633
Max Morin787eeed2016-06-23 10:42:07 +0200634int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100635 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200636 CHECKinitialized_();
637 bool isAvailable = false;
638 if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200639 return -1;
640 }
Max Morin787eeed2016-06-23 10:42:07 +0200641 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100642 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200643 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000644}
645
Max Morin787eeed2016-06-23 10:42:07 +0200646int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200647 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200648 uint32_t maxVol(0);
henrika4af73662017-10-11 13:16:17 +0200649 if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200650 return -1;
651 }
Max Morin787eeed2016-06-23 10:42:07 +0200652 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200653 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000654}
655
Max Morin787eeed2016-06-23 10:42:07 +0200656int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200657 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200658 uint32_t minVol(0);
henrika4af73662017-10-11 13:16:17 +0200659 if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200660 return -1;
661 }
Max Morin787eeed2016-06-23 10:42:07 +0200662 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200663 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000664}
665
Max Morin787eeed2016-06-23 10:42:07 +0200666int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100667 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200668 CHECKinitialized_();
669 uint16_t nPlayoutDevices = audio_device_->PlayoutDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100670 RTC_LOG(INFO) << "output: " << nPlayoutDevices;
henrika4af73662017-10-11 13:16:17 +0200671 return (int16_t)(nPlayoutDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +0000672}
673
Max Morin787eeed2016-06-23 10:42:07 +0200674int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100675 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200676 CHECKinitialized_();
677 return audio_device_->SetPlayoutDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000678}
679
Max Morin787eeed2016-06-23 10:42:07 +0200680int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100681 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200682 CHECKinitialized_();
683 return audio_device_->SetPlayoutDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000684}
685
pbos@webrtc.org25509882013-04-09 10:30:35 +0000686int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
687 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000688 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200689 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100690 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200691 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200692 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200693 return -1;
694 }
henrika4af73662017-10-11 13:16:17 +0200695 if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200696 return -1;
697 }
Max Morin787eeed2016-06-23 10:42:07 +0200698 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100699 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200700 }
701 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100702 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200703 }
henrika4af73662017-10-11 13:16:17 +0200704 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000705}
706
pbos@webrtc.org25509882013-04-09 10:30:35 +0000707int32_t AudioDeviceModuleImpl::RecordingDeviceName(
708 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000709 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200710 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100711 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200712 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200713 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200714 return -1;
715 }
henrika4af73662017-10-11 13:16:17 +0200716 if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200717 return -1;
718 }
Max Morin787eeed2016-06-23 10:42:07 +0200719 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100720 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200721 }
722 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100723 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200724 }
henrika4af73662017-10-11 13:16:17 +0200725 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000726}
727
Max Morin787eeed2016-06-23 10:42:07 +0200728int16_t AudioDeviceModuleImpl::RecordingDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100729 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200730 CHECKinitialized_();
731 uint16_t nRecordingDevices = audio_device_->RecordingDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100732 RTC_LOG(INFO) << "output: " << nRecordingDevices;
henrika4af73662017-10-11 13:16:17 +0200733 return (int16_t)nRecordingDevices;
niklase@google.com470e71d2011-07-07 08:21:25 +0000734}
735
Max Morin787eeed2016-06-23 10:42:07 +0200736int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100737 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200738 CHECKinitialized_();
739 return audio_device_->SetRecordingDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000740}
741
Max Morin787eeed2016-06-23 10:42:07 +0200742int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100743 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200744 CHECKinitialized_();
745 return audio_device_->SetRecordingDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000746}
747
Max Morin787eeed2016-06-23 10:42:07 +0200748int32_t AudioDeviceModuleImpl::InitPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100749 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200750 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700751 if (PlayoutIsInitialized()) {
752 return 0;
753 }
henrika4af73662017-10-11 13:16:17 +0200754 int32_t result = audio_device_->InitPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100755 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200756 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
757 static_cast<int>(result == 0));
758 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000759}
760
Max Morin787eeed2016-06-23 10:42:07 +0200761int32_t AudioDeviceModuleImpl::InitRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100762 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200763 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700764 if (RecordingIsInitialized()) {
765 return 0;
766 }
henrika4af73662017-10-11 13:16:17 +0200767 int32_t result = audio_device_->InitRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100768 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200769 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
770 static_cast<int>(result == 0));
771 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000772}
773
Max Morin787eeed2016-06-23 10:42:07 +0200774bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100775 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200776 CHECKinitialized__BOOL();
777 return audio_device_->PlayoutIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000778}
779
Max Morin787eeed2016-06-23 10:42:07 +0200780bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100781 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200782 CHECKinitialized__BOOL();
783 return audio_device_->RecordingIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000784}
785
Max Morin787eeed2016-06-23 10:42:07 +0200786int32_t AudioDeviceModuleImpl::StartPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100787 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200788 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700789 if (Playing()) {
790 return 0;
791 }
henrika4af73662017-10-11 13:16:17 +0200792 audio_device_buffer_.StartPlayout();
793 int32_t result = audio_device_->StartPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100794 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200795 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
796 static_cast<int>(result == 0));
797 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000798}
799
Max Morin787eeed2016-06-23 10:42:07 +0200800int32_t AudioDeviceModuleImpl::StopPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100801 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200802 CHECKinitialized_();
803 int32_t result = audio_device_->StopPlayout();
804 audio_device_buffer_.StopPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100805 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200806 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
807 static_cast<int>(result == 0));
808 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000809}
810
Max Morin787eeed2016-06-23 10:42:07 +0200811bool AudioDeviceModuleImpl::Playing() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100812 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200813 CHECKinitialized__BOOL();
814 return audio_device_->Playing();
niklase@google.com470e71d2011-07-07 08:21:25 +0000815}
816
Max Morin787eeed2016-06-23 10:42:07 +0200817int32_t AudioDeviceModuleImpl::StartRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100818 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200819 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700820 if (Recording()) {
821 return 0;
822 }
henrika4af73662017-10-11 13:16:17 +0200823 audio_device_buffer_.StartRecording();
824 int32_t result = audio_device_->StartRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100825 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200826 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
827 static_cast<int>(result == 0));
828 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000829}
niklase@google.com470e71d2011-07-07 08:21:25 +0000830
Max Morin787eeed2016-06-23 10:42:07 +0200831int32_t AudioDeviceModuleImpl::StopRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100832 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200833 CHECKinitialized_();
834 int32_t result = audio_device_->StopRecording();
835 audio_device_buffer_.StopRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100836 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200837 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
838 static_cast<int>(result == 0));
839 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000840}
841
Max Morin787eeed2016-06-23 10:42:07 +0200842bool AudioDeviceModuleImpl::Recording() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100843 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200844 CHECKinitialized__BOOL();
845 return audio_device_->Recording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000846}
847
Max Morin787eeed2016-06-23 10:42:07 +0200848int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
849 AudioTransport* audioCallback) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100850 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200851 return audio_device_buffer_.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +0000852}
853
Max Morin787eeed2016-06-23 10:42:07 +0200854int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
henrika4af73662017-10-11 13:16:17 +0200855 CHECKinitialized_();
856 uint16_t delay = 0;
857 if (audio_device_->PlayoutDelay(delay) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100858 RTC_LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +0200859 return -1;
860 }
Max Morin787eeed2016-06-23 10:42:07 +0200861 *delayMS = delay;
henrika4af73662017-10-11 13:16:17 +0200862 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000863}
864
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000865bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100866 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200867 CHECKinitialized__BOOL();
868 bool isAvailable = audio_device_->BuiltInAECIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100869 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200870 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000871}
872
henrikac14f5ff2015-09-23 14:08:33 +0200873int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100874 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200875 CHECKinitialized_();
876 int32_t ok = audio_device_->EnableBuiltInAEC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100877 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200878 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200879}
880
881bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100882 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200883 CHECKinitialized__BOOL();
884 bool isAvailable = audio_device_->BuiltInAGCIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100885 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200886 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200887}
888
889int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100890 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200891 CHECKinitialized_();
892 int32_t ok = audio_device_->EnableBuiltInAGC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100893 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200894 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200895}
896
897bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100898 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200899 CHECKinitialized__BOOL();
900 bool isAvailable = audio_device_->BuiltInNSIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100901 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200902 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200903}
904
905int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100906 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200907 CHECKinitialized_();
908 int32_t ok = audio_device_->EnableBuiltInNS(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100909 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200910 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200911}
912
Alex Narestbbeb1092019-08-16 11:49:04 +0200913int32_t AudioDeviceModuleImpl::GetPlayoutUnderrunCount() const {
914 RTC_LOG(INFO) << __FUNCTION__;
915 CHECKinitialized_();
916 int32_t underrunCount = audio_device_->GetPlayoutUnderrunCount();
917 RTC_LOG(INFO) << "output: " << underrunCount;
918 return underrunCount;
919}
920
maxmorin88e31a32016-08-16 00:56:09 -0700921#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200922int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
923 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100924 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200925 int r = audio_device_->GetPlayoutAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100926 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200927 return r;
henrikaba35d052015-07-14 17:04:08 +0200928}
929
930int AudioDeviceModuleImpl::GetRecordAudioParameters(
931 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100932 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200933 int r = audio_device_->GetRecordAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100934 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200935 return r;
henrikaba35d052015-07-14 17:04:08 +0200936}
maxmorin88e31a32016-08-16 00:56:09 -0700937#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200938
Max Morin787eeed2016-06-23 10:42:07 +0200939AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100940 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200941 return platform_type_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000942}
943
Max Morin787eeed2016-06-23 10:42:07 +0200944AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
945 const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100946 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200947 return audio_layer_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000948}
949
950} // namespace webrtc