blob: f3aceffc42e46b8aeabf7048be187fbe5c9f5173 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
xians@webrtc.org20aabbb2012-02-20 09:17:41 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_device/audio_device_impl.h"
henrika4af73662017-10-11 13:16:17 +020012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_device/audio_device_config.h"
14#include "modules/audio_device/audio_device_generic.h"
15#include "rtc_base/checks.h"
16#include "rtc_base/logging.h"
17#include "rtc_base/refcount.h"
Niels Möller84255bb2017-10-06 13:43:23 +020018#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
niklase@google.com470e71d2011-07-07 08:21:25 +000021#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020022#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
23#include "audio_device_core_win.h"
24#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000025#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020026#include <stdlib.h>
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/audio_device/android/audio_device_template.h"
28#include "modules/audio_device/android/audio_manager.h"
29#include "modules/audio_device/android/audio_record_jni.h"
30#include "modules/audio_device/android/audio_track_jni.h"
31#include "modules/audio_device/android/opensles_player.h"
32#include "modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020034#if defined(LINUX_ALSA)
35#include "audio_device_alsa_linux.h"
36#endif
Tommi68898a22015-05-19 17:28:07 +020037#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020038#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020039#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000040#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000042#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020043#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000044#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000045#if defined(WEBRTC_DUMMY_FILE_DEVICES)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "modules/audio_device/dummy/file_audio_device_factory.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000047#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "modules/audio_device/dummy/audio_device_dummy.h"
49#include "modules/audio_device/dummy/file_audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000050
henrika4af73662017-10-11 13:16:17 +020051#define CHECKinitialized_() \
Max Morin787eeed2016-06-23 10:42:07 +020052 { \
henrika4af73662017-10-11 13:16:17 +020053 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020054 return -1; \
55 }; \
56 }
niklase@google.com470e71d2011-07-07 08:21:25 +000057
henrika4af73662017-10-11 13:16:17 +020058#define CHECKinitialized__BOOL() \
Max Morin787eeed2016-06-23 10:42:07 +020059 { \
henrika4af73662017-10-11 13:16:17 +020060 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020061 return false; \
62 }; \
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Peter Boström1d194412016-03-21 16:44:31 +010065namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000066
henrika4af73662017-10-11 13:16:17 +020067// static
Peter Boström4adbbcf2016-05-03 15:51:26 -040068rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström4adbbcf2016-05-03 15:51:26 -040069 const AudioLayer audio_layer) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010070 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +020071 // Create the generic reference counted (platform independent) implementation.
Max Morin787eeed2016-06-23 10:42:07 +020072 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
henrika5ff64832017-10-11 15:14:51 +020073 new rtc::RefCountedObject<AudioDeviceModuleImpl>(audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000074
Max Morin787eeed2016-06-23 10:42:07 +020075 // Ensure that the current platform is supported.
76 if (audioDevice->CheckPlatform() == -1) {
77 return nullptr;
78 }
niklase@google.com470e71d2011-07-07 08:21:25 +000079
Max Morin787eeed2016-06-23 10:42:07 +020080 // Create the platform-dependent implementation.
81 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
82 return nullptr;
83 }
niklase@google.com470e71d2011-07-07 08:21:25 +000084
henrika4af73662017-10-11 13:16:17 +020085 // Ensure that the generic audio buffer can communicate with the platform
86 // specific parts.
Max Morin787eeed2016-06-23 10:42:07 +020087 if (audioDevice->AttachAudioBuffer() == -1) {
88 return nullptr;
89 }
niklase@google.com470e71d2011-07-07 08:21:25 +000090
Max Morin787eeed2016-06-23 10:42:07 +020091 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
henrika616e3132017-11-13 12:47:59 +010094// TODO(bugs.webrtc.org/7306): deprecated.
95rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
96 const int32_t id,
97 const AudioLayer audio_layer) {
98 RTC_LOG(INFO) << __FUNCTION__;
99 return AudioDeviceModule::Create(audio_layer);
100}
101
henrika5ff64832017-10-11 15:14:51 +0200102AudioDeviceModuleImpl::AudioDeviceModuleImpl(const AudioLayer audioLayer)
103 : audio_layer_(audioLayer) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100104 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105}
106
Max Morin787eeed2016-06-23 10:42:07 +0200107int32_t AudioDeviceModuleImpl::CheckPlatform() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100108 RTC_LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200109 // Ensure that the current platform is supported
Max Morin787eeed2016-06-23 10:42:07 +0200110 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000111#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200112 platform = kPlatformWin32;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100113 RTC_LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000114#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200115 platform = kPlatformAndroid;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100116 RTC_LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000117#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200118 platform = kPlatformLinux;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100119 RTC_LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000120#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200121 platform = kPlatformIOS;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100122 RTC_LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000123#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200124 platform = kPlatformMac;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100125 RTC_LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000126#endif
Max Morin787eeed2016-06-23 10:42:07 +0200127 if (platform == kPlatformNotSupported) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100128 RTC_LOG(LERROR)
129 << "current platform is not supported => this module will self "
130 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200131 return -1;
132 }
henrika4af73662017-10-11 13:16:17 +0200133 platform_type_ = platform;
Max Morin787eeed2016-06-23 10:42:07 +0200134 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135}
136
Max Morin787eeed2016-06-23 10:42:07 +0200137int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100138 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200139// Dummy ADM implementations if build flags are set.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000140#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
henrika5ff64832017-10-11 15:14:51 +0200141 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100142 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000143#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
henrika5ff64832017-10-11 15:14:51 +0200144 audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice());
henrika4af73662017-10-11 13:16:17 +0200145 if (audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100146 RTC_LOG(INFO) << "Will use file-playing dummy device.";
noahric6a355902016-08-17 15:19:50 -0700147 } else {
148 // Create a dummy device instead.
henrika5ff64832017-10-11 15:14:51 +0200149 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100150 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized";
noahric6a355902016-08-17 15:19:50 -0700151 }
henrika4af73662017-10-11 13:16:17 +0200152
153// Real (non-dummy) ADM implementations.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000154#else
henrika4af73662017-10-11 13:16:17 +0200155 AudioLayer audio_layer(PlatformAudioLayer());
156// Windows ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000157#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
henrika4af73662017-10-11 13:16:17 +0200158 if ((audio_layer == kWindowsCoreAudio) ||
159 (audio_layer == kPlatformDefaultAudio)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100160 RTC_LOG(INFO) << "Attempting to use the Windows Core Audio APIs...";
Max Morin787eeed2016-06-23 10:42:07 +0200161 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
henrika4af73662017-10-11 13:16:17 +0200162 audio_device_.reset(new AudioDeviceWindowsCore());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100163 RTC_LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000164 }
Max Morin787eeed2016-06-23 10:42:07 +0200165 }
166#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000168#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200169 // Create an Android audio manager.
henrika4af73662017-10-11 13:16:17 +0200170 audio_manager_android_.reset(new AudioManager());
Max Morin787eeed2016-06-23 10:42:07 +0200171 // Select best possible combination of audio layers.
henrika4af73662017-10-11 13:16:17 +0200172 if (audio_layer == kPlatformDefaultAudio) {
173 if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
174 audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200175 // Use OpenSL ES for both playout and recording.
henrika4af73662017-10-11 13:16:17 +0200176 audio_layer = kAndroidOpenSLESAudio;
177 } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
178 !audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200179 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200180 // low-latency output audio path.
henrika4af73662017-10-11 13:16:17 +0200181 audio_layer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200182 } else {
henrika918b5542016-09-19 15:44:09 +0200183 // Use Java-based audio in both directions when low-latency output is
184 // not supported.
henrika4af73662017-10-11 13:16:17 +0200185 audio_layer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000186 }
Max Morin787eeed2016-06-23 10:42:07 +0200187 }
henrika4af73662017-10-11 13:16:17 +0200188 AudioManager* audio_manager = audio_manager_android_.get();
189 if (audio_layer == kAndroidJavaAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200190 // Java audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200191 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
192 audio_layer, audio_manager));
193 } else if (audio_layer == kAndroidOpenSLESAudio) {
henrika918b5542016-09-19 15:44:09 +0200194 // OpenSL ES based audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200195 audio_device_.reset(
196 new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
197 audio_layer, audio_manager));
198 } else if (audio_layer == kAndroidJavaInputAndOpenSLESOutputAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200199 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
200 // This combination provides low-latency output audio and at the same
201 // time support for HW AEC using the AudioRecord Java API.
henrika4af73662017-10-11 13:16:17 +0200202 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
203 audio_layer, audio_manager));
Max Morin787eeed2016-06-23 10:42:07 +0200204 } else {
205 // Invalid audio layer.
henrika4af73662017-10-11 13:16:17 +0200206 audio_device_.reset(nullptr);
Max Morin787eeed2016-06-23 10:42:07 +0200207 }
208// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
henrika4af73662017-10-11 13:16:17 +0200210// Linux ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000211#elif defined(WEBRTC_LINUX)
henrika4af73662017-10-11 13:16:17 +0200212 if ((audio_layer == kLinuxPulseAudio) ||
213 (audio_layer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000214#if defined(LINUX_PULSE)
Mirko Bonadei675513b2017-11-09 11:09:25 +0100215 RTC_LOG(INFO) << "Attempting to use Linux PulseAudio APIs...";
henrika4af73662017-10-11 13:16:17 +0200216 // Linux PulseAudio implementation.
217 audio_device_.reset(new AudioDeviceLinuxPulse());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100218 RTC_LOG(INFO) << "Linux PulseAudio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000219#endif
220#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +0200221#endif
henrika4af73662017-10-11 13:16:17 +0200222 } else if (audio_layer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#if defined(LINUX_ALSA)
henrika4af73662017-10-11 13:16:17 +0200224 // Linux ALSA implementation.
225 audio_device_.reset(new AudioDeviceLinuxALSA());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100226 RTC_LOG(INFO) << "Linux ALSA APIs will be utilized.";
niklase@google.com470e71d2011-07-07 08:21:25 +0000227#endif
Max Morin787eeed2016-06-23 10:42:07 +0200228 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000229#endif // #if defined(WEBRTC_LINUX)
230
henrika4af73662017-10-11 13:16:17 +0200231// iOS ADM implementation.
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000232#if defined(WEBRTC_IOS)
henrika4af73662017-10-11 13:16:17 +0200233 if (audio_layer == kPlatformDefaultAudio) {
234 audio_device_.reset(new AudioDeviceIOS());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100235 RTC_LOG(INFO) << "iPhone Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200236 }
237// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000238
henrika4af73662017-10-11 13:16:17 +0200239// Mac OS X ADM implementation.
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000240#elif defined(WEBRTC_MAC)
henrika4af73662017-10-11 13:16:17 +0200241 if (audio_layer == kPlatformDefaultAudio) {
242 audio_device_.reset(new AudioDeviceMac());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100243 RTC_LOG(INFO) << "Mac OS X Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200244 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000245#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
henrika4af73662017-10-11 13:16:17 +0200247 // Dummy ADM implementation.
248 if (audio_layer == kDummyAudio) {
henrika5ff64832017-10-11 15:14:51 +0200249 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100250 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200251 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000252#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
henrika4af73662017-10-11 13:16:17 +0200254 if (!audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100255 RTC_LOG(LS_ERROR)
henrika4af73662017-10-11 13:16:17 +0200256 << "Failed to create the platform specific ADM implementation.";
Max Morin787eeed2016-06-23 10:42:07 +0200257 return -1;
258 }
Max Morin787eeed2016-06-23 10:42:07 +0200259 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260}
261
Max Morin787eeed2016-06-23 10:42:07 +0200262int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100263 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200264 audio_device_->AttachAudioBuffer(&audio_device_buffer_);
Max Morin787eeed2016-06-23 10:42:07 +0200265 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000266}
267
Max Morin787eeed2016-06-23 10:42:07 +0200268AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100269 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000270}
271
henrikab2619892015-05-18 16:49:16 +0200272int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100273 RTC_LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200274 AudioLayer activeAudio;
henrika4af73662017-10-11 13:16:17 +0200275 if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
henrikab2619892015-05-18 16:49:16 +0200276 return -1;
277 }
278 *audioLayer = activeAudio;
279 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000280}
281
Max Morin787eeed2016-06-23 10:42:07 +0200282int32_t AudioDeviceModuleImpl::Init() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100283 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200284 if (initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000285 return 0;
henrika4af73662017-10-11 13:16:17 +0200286 RTC_CHECK(audio_device_);
287 AudioDeviceGeneric::InitStatus status = audio_device_->Init();
Max Morin84cab202016-07-01 13:35:19 +0200288 RTC_HISTOGRAM_ENUMERATION(
289 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
290 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
291 if (status != AudioDeviceGeneric::InitStatus::OK) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100292 RTC_LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200293 return -1;
294 }
henrika4af73662017-10-11 13:16:17 +0200295 initialized_ = true;
Max Morin787eeed2016-06-23 10:42:07 +0200296 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000297}
298
Max Morin787eeed2016-06-23 10:42:07 +0200299int32_t AudioDeviceModuleImpl::Terminate() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100300 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200301 if (!initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000302 return 0;
henrika4af73662017-10-11 13:16:17 +0200303 if (audio_device_->Terminate() == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200304 return -1;
305 }
henrika4af73662017-10-11 13:16:17 +0200306 initialized_ = false;
Max Morin787eeed2016-06-23 10:42:07 +0200307 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000308}
309
Max Morin787eeed2016-06-23 10:42:07 +0200310bool AudioDeviceModuleImpl::Initialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100311 RTC_LOG(INFO) << __FUNCTION__ << ": " << initialized_;
henrika4af73662017-10-11 13:16:17 +0200312 return initialized_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000313}
314
Max Morin787eeed2016-06-23 10:42:07 +0200315int32_t AudioDeviceModuleImpl::InitSpeaker() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100316 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200317 CHECKinitialized_();
318 return audio_device_->InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000319}
320
Max Morin787eeed2016-06-23 10:42:07 +0200321int32_t AudioDeviceModuleImpl::InitMicrophone() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100322 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200323 CHECKinitialized_();
324 return audio_device_->InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000325}
326
Max Morin787eeed2016-06-23 10:42:07 +0200327int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100328 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200329 CHECKinitialized_();
330 bool isAvailable = false;
331 if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200332 return -1;
333 }
Max Morin787eeed2016-06-23 10:42:07 +0200334 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100335 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200336 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
Max Morin787eeed2016-06-23 10:42:07 +0200339int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100340 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200341 CHECKinitialized_();
342 return audio_device_->SetSpeakerVolume(volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000343}
344
Max Morin787eeed2016-06-23 10:42:07 +0200345int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100346 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200347 CHECKinitialized_();
348 uint32_t level = 0;
349 if (audio_device_->SpeakerVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200350 return -1;
351 }
Max Morin787eeed2016-06-23 10:42:07 +0200352 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100353 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200354 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000355}
356
Max Morin787eeed2016-06-23 10:42:07 +0200357bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100358 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200359 CHECKinitialized__BOOL();
360 bool isInitialized = audio_device_->SpeakerIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100361 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200362 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000363}
364
Max Morin787eeed2016-06-23 10:42:07 +0200365bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100366 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200367 CHECKinitialized__BOOL();
368 bool isInitialized = audio_device_->MicrophoneIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100369 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200370 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000371}
372
Max Morin787eeed2016-06-23 10:42:07 +0200373int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200374 CHECKinitialized_();
375 uint32_t maxVol = 0;
376 if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200377 return -1;
378 }
Max Morin787eeed2016-06-23 10:42:07 +0200379 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200380 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000381}
382
Max Morin787eeed2016-06-23 10:42:07 +0200383int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200384 CHECKinitialized_();
385 uint32_t minVol = 0;
386 if (audio_device_->MinSpeakerVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200387 return -1;
388 }
Max Morin787eeed2016-06-23 10:42:07 +0200389 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200390 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000391}
392
Max Morin787eeed2016-06-23 10:42:07 +0200393int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100394 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200395 CHECKinitialized_();
Mirko Bonadei72c42502017-11-09 09:33:23 +0100396 bool isAvailable = false;
henrika4af73662017-10-11 13:16:17 +0200397 if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200398 return -1;
399 }
Max Morin787eeed2016-06-23 10:42:07 +0200400 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100401 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200402 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403}
404
Max Morin787eeed2016-06-23 10:42:07 +0200405int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100406 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200407 CHECKinitialized_();
408 return audio_device_->SetSpeakerMute(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000409}
410
Max Morin787eeed2016-06-23 10:42:07 +0200411int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100412 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200413 CHECKinitialized_();
414 bool muted = false;
415 if (audio_device_->SpeakerMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200416 return -1;
417 }
Max Morin787eeed2016-06-23 10:42:07 +0200418 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100419 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200420 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000421}
422
Max Morin787eeed2016-06-23 10:42:07 +0200423int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100424 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200425 CHECKinitialized_();
426 bool isAvailable = false;
427 if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200428 return -1;
429 }
Max Morin787eeed2016-06-23 10:42:07 +0200430 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100431 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200432 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000433}
434
Max Morin787eeed2016-06-23 10:42:07 +0200435int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100436 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200437 CHECKinitialized_();
438 return (audio_device_->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000439}
440
Max Morin787eeed2016-06-23 10:42:07 +0200441int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100442 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200443 CHECKinitialized_();
444 bool muted = false;
445 if (audio_device_->MicrophoneMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200446 return -1;
447 }
Max Morin787eeed2016-06-23 10:42:07 +0200448 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100449 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200450 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000451}
452
Max Morin787eeed2016-06-23 10:42:07 +0200453int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100454 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200455 CHECKinitialized_();
456 bool isAvailable = false;
457 if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200458 return -1;
459 }
Max Morin787eeed2016-06-23 10:42:07 +0200460 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100461 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200462 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000463}
464
Max Morin787eeed2016-06-23 10:42:07 +0200465int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100466 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200467 CHECKinitialized_();
468 return (audio_device_->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000469}
470
Max Morin787eeed2016-06-23 10:42:07 +0200471int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100472 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200473 CHECKinitialized_();
474 uint32_t level = 0;
475 if (audio_device_->MicrophoneVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200476 return -1;
477 }
Max Morin787eeed2016-06-23 10:42:07 +0200478 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100479 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200480 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000481}
482
Max Morin787eeed2016-06-23 10:42:07 +0200483int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
484 bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100485 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200486 CHECKinitialized_();
487 bool isAvailable = false;
488 if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200489 return -1;
490 }
Max Morin787eeed2016-06-23 10:42:07 +0200491 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100492 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200493 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000494}
495
Max Morin787eeed2016-06-23 10:42:07 +0200496int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100497 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200498 CHECKinitialized_();
499 if (audio_device_->RecordingIsInitialized()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100500 RTC_LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200501 return -1;
502 }
henrika4af73662017-10-11 13:16:17 +0200503 if (audio_device_->SetStereoRecording(enable) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100504 RTC_LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200505 return -1;
506 }
Max Morin787eeed2016-06-23 10:42:07 +0200507 int8_t nChannels(1);
508 if (enable) {
509 nChannels = 2;
510 }
henrika4af73662017-10-11 13:16:17 +0200511 audio_device_buffer_.SetRecordingChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200512 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000513}
514
Max Morin787eeed2016-06-23 10:42:07 +0200515int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100516 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200517 CHECKinitialized_();
518 bool stereo = false;
519 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200520 return -1;
521 }
Max Morin787eeed2016-06-23 10:42:07 +0200522 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100523 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200524 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000525}
526
Max Morin787eeed2016-06-23 10:42:07 +0200527int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100528 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200529 CHECKinitialized_();
530 bool isAvailable = false;
531 if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200532 return -1;
533 }
Max Morin787eeed2016-06-23 10:42:07 +0200534 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100535 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200536 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000537}
538
Max Morin787eeed2016-06-23 10:42:07 +0200539int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100540 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200541 CHECKinitialized_();
542 if (audio_device_->PlayoutIsInitialized()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100543 RTC_LOG(LERROR)
Max Morin098e6c52016-06-28 09:36:25 +0200544 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200545 return -1;
546 }
henrika4af73662017-10-11 13:16:17 +0200547 if (audio_device_->SetStereoPlayout(enable)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100548 RTC_LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200549 return -1;
550 }
Max Morin787eeed2016-06-23 10:42:07 +0200551 int8_t nChannels(1);
552 if (enable) {
553 nChannels = 2;
554 }
henrika4af73662017-10-11 13:16:17 +0200555 audio_device_buffer_.SetPlayoutChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200556 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000557}
558
Max Morin787eeed2016-06-23 10:42:07 +0200559int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100560 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200561 CHECKinitialized_();
562 bool stereo = false;
563 if (audio_device_->StereoPlayout(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200564 return -1;
565 }
Max Morin787eeed2016-06-23 10:42:07 +0200566 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100567 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200568 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000569}
570
Max Morin787eeed2016-06-23 10:42:07 +0200571int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100572 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200573 CHECKinitialized_();
574 return (audio_device_->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000575}
576
Max Morin787eeed2016-06-23 10:42:07 +0200577bool AudioDeviceModuleImpl::AGC() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100578 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200579 CHECKinitialized__BOOL();
580 return audio_device_->AGC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000581}
582
Max Morin787eeed2016-06-23 10:42:07 +0200583int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100584 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200585 CHECKinitialized_();
586 bool isAvailable = false;
587 if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200588 return -1;
589 }
Max Morin787eeed2016-06-23 10:42:07 +0200590 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100591 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200592 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000593}
594
Max Morin787eeed2016-06-23 10:42:07 +0200595int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100596 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200597 CHECKinitialized_();
598 bool isAvailable = false;
599 if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200600 return -1;
601 }
Max Morin787eeed2016-06-23 10:42:07 +0200602 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100603 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200604 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000605}
606
Max Morin787eeed2016-06-23 10:42:07 +0200607int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200608 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200609 uint32_t maxVol(0);
henrika4af73662017-10-11 13:16:17 +0200610 if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200611 return -1;
612 }
Max Morin787eeed2016-06-23 10:42:07 +0200613 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200614 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000615}
616
Max Morin787eeed2016-06-23 10:42:07 +0200617int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200618 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200619 uint32_t minVol(0);
henrika4af73662017-10-11 13:16:17 +0200620 if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200621 return -1;
622 }
Max Morin787eeed2016-06-23 10:42:07 +0200623 *minVolume = minVol;
henrika4af73662017-10-11 13:16:17 +0200624 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000625}
626
Max Morin787eeed2016-06-23 10:42:07 +0200627int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100628 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200629 CHECKinitialized_();
630 uint16_t nPlayoutDevices = audio_device_->PlayoutDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100631 RTC_LOG(INFO) << "output: " << nPlayoutDevices;
henrika4af73662017-10-11 13:16:17 +0200632 return (int16_t)(nPlayoutDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +0000633}
634
Max Morin787eeed2016-06-23 10:42:07 +0200635int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100636 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200637 CHECKinitialized_();
638 return audio_device_->SetPlayoutDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000639}
640
Max Morin787eeed2016-06-23 10:42:07 +0200641int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100642 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200643 CHECKinitialized_();
644 return audio_device_->SetPlayoutDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000645}
646
pbos@webrtc.org25509882013-04-09 10:30:35 +0000647int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
648 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000649 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200650 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100651 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200652 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200653 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200654 return -1;
655 }
henrika4af73662017-10-11 13:16:17 +0200656 if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200657 return -1;
658 }
Max Morin787eeed2016-06-23 10:42:07 +0200659 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100660 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200661 }
662 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100663 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200664 }
henrika4af73662017-10-11 13:16:17 +0200665 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000666}
667
pbos@webrtc.org25509882013-04-09 10:30:35 +0000668int32_t AudioDeviceModuleImpl::RecordingDeviceName(
669 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000670 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200671 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100672 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200673 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200674 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200675 return -1;
676 }
henrika4af73662017-10-11 13:16:17 +0200677 if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200678 return -1;
679 }
Max Morin787eeed2016-06-23 10:42:07 +0200680 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100681 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200682 }
683 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100684 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200685 }
henrika4af73662017-10-11 13:16:17 +0200686 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000687}
688
Max Morin787eeed2016-06-23 10:42:07 +0200689int16_t AudioDeviceModuleImpl::RecordingDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100690 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200691 CHECKinitialized_();
692 uint16_t nRecordingDevices = audio_device_->RecordingDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100693 RTC_LOG(INFO) << "output: " << nRecordingDevices;
henrika4af73662017-10-11 13:16:17 +0200694 return (int16_t)nRecordingDevices;
niklase@google.com470e71d2011-07-07 08:21:25 +0000695}
696
Max Morin787eeed2016-06-23 10:42:07 +0200697int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100698 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200699 CHECKinitialized_();
700 return audio_device_->SetRecordingDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000701}
702
Max Morin787eeed2016-06-23 10:42:07 +0200703int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100704 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200705 CHECKinitialized_();
706 return audio_device_->SetRecordingDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000707}
708
Max Morin787eeed2016-06-23 10:42:07 +0200709int32_t AudioDeviceModuleImpl::InitPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100710 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200711 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700712 if (PlayoutIsInitialized()) {
713 return 0;
714 }
henrika4af73662017-10-11 13:16:17 +0200715 int32_t result = audio_device_->InitPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100716 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200717 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
718 static_cast<int>(result == 0));
719 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000720}
721
Max Morin787eeed2016-06-23 10:42:07 +0200722int32_t AudioDeviceModuleImpl::InitRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100723 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200724 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700725 if (RecordingIsInitialized()) {
726 return 0;
727 }
henrika4af73662017-10-11 13:16:17 +0200728 int32_t result = audio_device_->InitRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100729 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200730 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
731 static_cast<int>(result == 0));
732 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000733}
734
Max Morin787eeed2016-06-23 10:42:07 +0200735bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100736 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200737 CHECKinitialized__BOOL();
738 return audio_device_->PlayoutIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000739}
740
Max Morin787eeed2016-06-23 10:42:07 +0200741bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100742 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200743 CHECKinitialized__BOOL();
744 return audio_device_->RecordingIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000745}
746
Max Morin787eeed2016-06-23 10:42:07 +0200747int32_t AudioDeviceModuleImpl::StartPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100748 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200749 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700750 if (Playing()) {
751 return 0;
752 }
henrika4af73662017-10-11 13:16:17 +0200753 audio_device_buffer_.StartPlayout();
754 int32_t result = audio_device_->StartPlayout();
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.StartPlayoutSuccess",
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::StopPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100762 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200763 CHECKinitialized_();
764 int32_t result = audio_device_->StopPlayout();
765 audio_device_buffer_.StopPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100766 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200767 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
768 static_cast<int>(result == 0));
769 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000770}
771
Max Morin787eeed2016-06-23 10:42:07 +0200772bool AudioDeviceModuleImpl::Playing() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100773 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200774 CHECKinitialized__BOOL();
775 return audio_device_->Playing();
niklase@google.com470e71d2011-07-07 08:21:25 +0000776}
777
Max Morin787eeed2016-06-23 10:42:07 +0200778int32_t AudioDeviceModuleImpl::StartRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100779 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200780 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700781 if (Recording()) {
782 return 0;
783 }
henrika4af73662017-10-11 13:16:17 +0200784 audio_device_buffer_.StartRecording();
785 int32_t result = audio_device_->StartRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100786 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200787 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
788 static_cast<int>(result == 0));
789 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000790}
niklase@google.com470e71d2011-07-07 08:21:25 +0000791
Max Morin787eeed2016-06-23 10:42:07 +0200792int32_t AudioDeviceModuleImpl::StopRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100793 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200794 CHECKinitialized_();
795 int32_t result = audio_device_->StopRecording();
796 audio_device_buffer_.StopRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100797 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200798 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
799 static_cast<int>(result == 0));
800 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000801}
802
Max Morin787eeed2016-06-23 10:42:07 +0200803bool AudioDeviceModuleImpl::Recording() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100804 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200805 CHECKinitialized__BOOL();
806 return audio_device_->Recording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000807}
808
Max Morin787eeed2016-06-23 10:42:07 +0200809int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
810 AudioTransport* audioCallback) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100811 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200812 return audio_device_buffer_.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +0000813}
814
Max Morin787eeed2016-06-23 10:42:07 +0200815int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
henrika4af73662017-10-11 13:16:17 +0200816 CHECKinitialized_();
817 uint16_t delay = 0;
818 if (audio_device_->PlayoutDelay(delay) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100819 RTC_LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +0200820 return -1;
821 }
Max Morin787eeed2016-06-23 10:42:07 +0200822 *delayMS = delay;
henrika4af73662017-10-11 13:16:17 +0200823 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000824}
825
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000826bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100827 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200828 CHECKinitialized__BOOL();
829 bool isAvailable = audio_device_->BuiltInAECIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100830 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200831 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000832}
833
henrikac14f5ff2015-09-23 14:08:33 +0200834int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100835 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200836 CHECKinitialized_();
837 int32_t ok = audio_device_->EnableBuiltInAEC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100838 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200839 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200840}
841
842bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100843 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200844 CHECKinitialized__BOOL();
845 bool isAvailable = audio_device_->BuiltInAGCIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100846 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200847 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200848}
849
850int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100851 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200852 CHECKinitialized_();
853 int32_t ok = audio_device_->EnableBuiltInAGC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100854 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200855 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200856}
857
858bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100859 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200860 CHECKinitialized__BOOL();
861 bool isAvailable = audio_device_->BuiltInNSIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100862 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200863 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200864}
865
866int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100867 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200868 CHECKinitialized_();
869 int32_t ok = audio_device_->EnableBuiltInNS(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100870 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200871 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200872}
873
maxmorin88e31a32016-08-16 00:56:09 -0700874#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200875int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
876 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100877 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200878 int r = audio_device_->GetPlayoutAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100879 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200880 return r;
henrikaba35d052015-07-14 17:04:08 +0200881}
882
883int AudioDeviceModuleImpl::GetRecordAudioParameters(
884 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100885 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200886 int r = audio_device_->GetRecordAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100887 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200888 return r;
henrikaba35d052015-07-14 17:04:08 +0200889}
maxmorin88e31a32016-08-16 00:56:09 -0700890#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200891
Max Morin787eeed2016-06-23 10:42:07 +0200892AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100893 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200894 return platform_type_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000895}
896
Max Morin787eeed2016-06-23 10:42:07 +0200897AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
898 const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100899 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200900 return audio_layer_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000901}
902
903} // namespace webrtc