blob: f4fdd119d6dc94febd530250dbacef1125d856c1 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
xians@webrtc.org20aabbb2012-02-20 09:17:41 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_device/audio_device_impl.h"
henrika4af73662017-10-11 13:16:17 +020012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_device/audio_device_config.h"
14#include "modules/audio_device/audio_device_generic.h"
15#include "rtc_base/checks.h"
16#include "rtc_base/logging.h"
17#include "rtc_base/refcount.h"
Niels Möller84255bb2017-10-06 13:43:23 +020018#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
niklase@google.com470e71d2011-07-07 08:21:25 +000021#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020022#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
23#include "audio_device_core_win.h"
24#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000025#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020026#include <stdlib.h>
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/audio_device/android/audio_device_template.h"
28#include "modules/audio_device/android/audio_manager.h"
29#include "modules/audio_device/android/audio_record_jni.h"
30#include "modules/audio_device/android/audio_track_jni.h"
31#include "modules/audio_device/android/opensles_player.h"
32#include "modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020034#if defined(LINUX_ALSA)
35#include "audio_device_alsa_linux.h"
36#endif
Tommi68898a22015-05-19 17:28:07 +020037#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020038#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020039#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000040#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000042#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020043#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000044#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000045#if defined(WEBRTC_DUMMY_FILE_DEVICES)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "modules/audio_device/dummy/file_audio_device_factory.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000047#endif
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "modules/audio_device/dummy/audio_device_dummy.h"
49#include "modules/audio_device/dummy/file_audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000050
henrika4af73662017-10-11 13:16:17 +020051#define CHECKinitialized_() \
Max Morin787eeed2016-06-23 10:42:07 +020052 { \
henrika4af73662017-10-11 13:16:17 +020053 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020054 return -1; \
55 }; \
56 }
niklase@google.com470e71d2011-07-07 08:21:25 +000057
henrika4af73662017-10-11 13:16:17 +020058#define CHECKinitialized__BOOL() \
Max Morin787eeed2016-06-23 10:42:07 +020059 { \
henrika4af73662017-10-11 13:16:17 +020060 if (!initialized_) { \
Max Morin787eeed2016-06-23 10:42:07 +020061 return false; \
62 }; \
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Peter Boström1d194412016-03-21 16:44:31 +010065namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000066
henrika4af73662017-10-11 13:16:17 +020067// static
henrika5ff64832017-10-11 15:14:51 +020068// TODO(henrika): remove id parameter when all clients are updated.
Peter Boström4adbbcf2016-05-03 15:51:26 -040069rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010070 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040071 const AudioLayer audio_layer) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010072 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +020073 // Create the generic reference counted (platform independent) implementation.
Max Morin787eeed2016-06-23 10:42:07 +020074 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
henrika5ff64832017-10-11 15:14:51 +020075 new rtc::RefCountedObject<AudioDeviceModuleImpl>(audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000076
Max Morin787eeed2016-06-23 10:42:07 +020077 // Ensure that the current platform is supported.
78 if (audioDevice->CheckPlatform() == -1) {
79 return nullptr;
80 }
niklase@google.com470e71d2011-07-07 08:21:25 +000081
Max Morin787eeed2016-06-23 10:42:07 +020082 // Create the platform-dependent implementation.
83 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
84 return nullptr;
85 }
niklase@google.com470e71d2011-07-07 08:21:25 +000086
henrika4af73662017-10-11 13:16:17 +020087 // Ensure that the generic audio buffer can communicate with the platform
88 // specific parts.
Max Morin787eeed2016-06-23 10:42:07 +020089 if (audioDevice->AttachAudioBuffer() == -1) {
90 return nullptr;
91 }
niklase@google.com470e71d2011-07-07 08:21:25 +000092
Max Morin787eeed2016-06-23 10:42:07 +020093 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +000094}
95
henrika5ff64832017-10-11 15:14:51 +020096AudioDeviceModuleImpl::AudioDeviceModuleImpl(const AudioLayer audioLayer)
97 : audio_layer_(audioLayer) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010098 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +000099}
100
Max Morin787eeed2016-06-23 10:42:07 +0200101int32_t AudioDeviceModuleImpl::CheckPlatform() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100102 RTC_LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200103 // Ensure that the current platform is supported
Max Morin787eeed2016-06-23 10:42:07 +0200104 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000105#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200106 platform = kPlatformWin32;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100107 RTC_LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000108#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200109 platform = kPlatformAndroid;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100110 RTC_LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000111#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200112 platform = kPlatformLinux;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100113 RTC_LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000114#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200115 platform = kPlatformIOS;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100116 RTC_LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000117#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200118 platform = kPlatformMac;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100119 RTC_LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000120#endif
Max Morin787eeed2016-06-23 10:42:07 +0200121 if (platform == kPlatformNotSupported) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100122 RTC_LOG(LERROR)
123 << "current platform is not supported => this module will self "
124 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200125 return -1;
126 }
henrika4af73662017-10-11 13:16:17 +0200127 platform_type_ = platform;
Max Morin787eeed2016-06-23 10:42:07 +0200128 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129}
130
Max Morin787eeed2016-06-23 10:42:07 +0200131int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100132 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200133// Dummy ADM implementations if build flags are set.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000134#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
henrika5ff64832017-10-11 15:14:51 +0200135 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100136 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000137#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
henrika5ff64832017-10-11 15:14:51 +0200138 audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice());
henrika4af73662017-10-11 13:16:17 +0200139 if (audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100140 RTC_LOG(INFO) << "Will use file-playing dummy device.";
noahric6a355902016-08-17 15:19:50 -0700141 } else {
142 // Create a dummy device instead.
henrika5ff64832017-10-11 15:14:51 +0200143 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100144 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized";
noahric6a355902016-08-17 15:19:50 -0700145 }
henrika4af73662017-10-11 13:16:17 +0200146
147// Real (non-dummy) ADM implementations.
xians@google.combf5d2ba2011-08-16 07:44:19 +0000148#else
henrika4af73662017-10-11 13:16:17 +0200149 AudioLayer audio_layer(PlatformAudioLayer());
150// Windows ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000151#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
henrika4af73662017-10-11 13:16:17 +0200152 if ((audio_layer == kWindowsCoreAudio) ||
153 (audio_layer == kPlatformDefaultAudio)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100154 RTC_LOG(INFO) << "Attempting to use the Windows Core Audio APIs...";
Max Morin787eeed2016-06-23 10:42:07 +0200155 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
henrika4af73662017-10-11 13:16:17 +0200156 audio_device_.reset(new AudioDeviceWindowsCore());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100157 RTC_LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 }
Max Morin787eeed2016-06-23 10:42:07 +0200159 }
160#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000162#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200163 // Create an Android audio manager.
henrika4af73662017-10-11 13:16:17 +0200164 audio_manager_android_.reset(new AudioManager());
Max Morin787eeed2016-06-23 10:42:07 +0200165 // Select best possible combination of audio layers.
henrika4af73662017-10-11 13:16:17 +0200166 if (audio_layer == kPlatformDefaultAudio) {
167 if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
168 audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200169 // Use OpenSL ES for both playout and recording.
henrika4af73662017-10-11 13:16:17 +0200170 audio_layer = kAndroidOpenSLESAudio;
171 } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() &&
172 !audio_manager_android_->IsLowLatencyRecordSupported()) {
henrika918b5542016-09-19 15:44:09 +0200173 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200174 // low-latency output audio path.
henrika4af73662017-10-11 13:16:17 +0200175 audio_layer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200176 } else {
henrika918b5542016-09-19 15:44:09 +0200177 // Use Java-based audio in both directions when low-latency output is
178 // not supported.
henrika4af73662017-10-11 13:16:17 +0200179 audio_layer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000180 }
Max Morin787eeed2016-06-23 10:42:07 +0200181 }
henrika4af73662017-10-11 13:16:17 +0200182 AudioManager* audio_manager = audio_manager_android_.get();
183 if (audio_layer == kAndroidJavaAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200184 // Java audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200185 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
186 audio_layer, audio_manager));
187 } else if (audio_layer == kAndroidOpenSLESAudio) {
henrika918b5542016-09-19 15:44:09 +0200188 // OpenSL ES based audio for both input and output audio.
henrika4af73662017-10-11 13:16:17 +0200189 audio_device_.reset(
190 new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
191 audio_layer, audio_manager));
192 } else if (audio_layer == kAndroidJavaInputAndOpenSLESOutputAudio) {
Max Morin787eeed2016-06-23 10:42:07 +0200193 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
194 // This combination provides low-latency output audio and at the same
195 // time support for HW AEC using the AudioRecord Java API.
henrika4af73662017-10-11 13:16:17 +0200196 audio_device_.reset(new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
197 audio_layer, audio_manager));
Max Morin787eeed2016-06-23 10:42:07 +0200198 } else {
199 // Invalid audio layer.
henrika4af73662017-10-11 13:16:17 +0200200 audio_device_.reset(nullptr);
Max Morin787eeed2016-06-23 10:42:07 +0200201 }
202// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
henrika4af73662017-10-11 13:16:17 +0200204// Linux ADM implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000205#elif defined(WEBRTC_LINUX)
henrika4af73662017-10-11 13:16:17 +0200206 if ((audio_layer == kLinuxPulseAudio) ||
207 (audio_layer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000208#if defined(LINUX_PULSE)
Mirko Bonadei675513b2017-11-09 11:09:25 +0100209 RTC_LOG(INFO) << "Attempting to use Linux PulseAudio APIs...";
henrika4af73662017-10-11 13:16:17 +0200210 // Linux PulseAudio implementation.
211 audio_device_.reset(new AudioDeviceLinuxPulse());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100212 RTC_LOG(INFO) << "Linux PulseAudio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000213#endif
214#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +0200215#endif
henrika4af73662017-10-11 13:16:17 +0200216 } else if (audio_layer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000217#if defined(LINUX_ALSA)
henrika4af73662017-10-11 13:16:17 +0200218 // Linux ALSA implementation.
219 audio_device_.reset(new AudioDeviceLinuxALSA());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100220 RTC_LOG(INFO) << "Linux ALSA APIs will be utilized.";
niklase@google.com470e71d2011-07-07 08:21:25 +0000221#endif
Max Morin787eeed2016-06-23 10:42:07 +0200222 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#endif // #if defined(WEBRTC_LINUX)
224
henrika4af73662017-10-11 13:16:17 +0200225// iOS ADM implementation.
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000226#if defined(WEBRTC_IOS)
henrika4af73662017-10-11 13:16:17 +0200227 if (audio_layer == kPlatformDefaultAudio) {
228 audio_device_.reset(new AudioDeviceIOS());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100229 RTC_LOG(INFO) << "iPhone Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200230 }
231// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
henrika4af73662017-10-11 13:16:17 +0200233// Mac OS X ADM implementation.
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000234#elif defined(WEBRTC_MAC)
henrika4af73662017-10-11 13:16:17 +0200235 if (audio_layer == kPlatformDefaultAudio) {
236 audio_device_.reset(new AudioDeviceMac());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100237 RTC_LOG(INFO) << "Mac OS X Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200238 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000239#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
henrika4af73662017-10-11 13:16:17 +0200241 // Dummy ADM implementation.
242 if (audio_layer == kDummyAudio) {
henrika5ff64832017-10-11 15:14:51 +0200243 audio_device_.reset(new AudioDeviceDummy());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100244 RTC_LOG(INFO) << "Dummy Audio APIs will be utilized.";
Max Morin787eeed2016-06-23 10:42:07 +0200245 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000246#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000247
henrika4af73662017-10-11 13:16:17 +0200248 if (!audio_device_) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100249 RTC_LOG(LS_ERROR)
henrika4af73662017-10-11 13:16:17 +0200250 << "Failed to create the platform specific ADM implementation.";
Max Morin787eeed2016-06-23 10:42:07 +0200251 return -1;
252 }
Max Morin787eeed2016-06-23 10:42:07 +0200253 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000254}
255
Max Morin787eeed2016-06-23 10:42:07 +0200256int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100257 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200258 audio_device_->AttachAudioBuffer(&audio_device_buffer_);
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 +0200262AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100263 RTC_LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000264}
265
henrikab2619892015-05-18 16:49:16 +0200266int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100267 RTC_LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200268 AudioLayer activeAudio;
henrika4af73662017-10-11 13:16:17 +0200269 if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
henrikab2619892015-05-18 16:49:16 +0200270 return -1;
271 }
272 *audioLayer = activeAudio;
273 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274}
275
Max Morin787eeed2016-06-23 10:42:07 +0200276int32_t AudioDeviceModuleImpl::Init() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100277 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200278 if (initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000279 return 0;
henrika4af73662017-10-11 13:16:17 +0200280 RTC_CHECK(audio_device_);
281 AudioDeviceGeneric::InitStatus status = audio_device_->Init();
Max Morin84cab202016-07-01 13:35:19 +0200282 RTC_HISTOGRAM_ENUMERATION(
283 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
284 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
285 if (status != AudioDeviceGeneric::InitStatus::OK) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100286 RTC_LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200287 return -1;
288 }
henrika4af73662017-10-11 13:16:17 +0200289 initialized_ = true;
Max Morin787eeed2016-06-23 10:42:07 +0200290 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000291}
292
Max Morin787eeed2016-06-23 10:42:07 +0200293int32_t AudioDeviceModuleImpl::Terminate() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100294 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200295 if (!initialized_)
niklase@google.com470e71d2011-07-07 08:21:25 +0000296 return 0;
henrika4af73662017-10-11 13:16:17 +0200297 if (audio_device_->Terminate() == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200298 return -1;
299 }
henrika4af73662017-10-11 13:16:17 +0200300 initialized_ = false;
Max Morin787eeed2016-06-23 10:42:07 +0200301 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000302}
303
Max Morin787eeed2016-06-23 10:42:07 +0200304bool AudioDeviceModuleImpl::Initialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100305 RTC_LOG(INFO) << __FUNCTION__ << ": " << initialized_;
henrika4af73662017-10-11 13:16:17 +0200306 return initialized_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000307}
308
Max Morin787eeed2016-06-23 10:42:07 +0200309int32_t AudioDeviceModuleImpl::InitSpeaker() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100310 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200311 CHECKinitialized_();
312 return audio_device_->InitSpeaker();
niklase@google.com470e71d2011-07-07 08:21:25 +0000313}
314
Max Morin787eeed2016-06-23 10:42:07 +0200315int32_t AudioDeviceModuleImpl::InitMicrophone() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100316 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200317 CHECKinitialized_();
318 return audio_device_->InitMicrophone();
niklase@google.com470e71d2011-07-07 08:21:25 +0000319}
320
Max Morin787eeed2016-06-23 10:42:07 +0200321int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100322 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200323 CHECKinitialized_();
324 bool isAvailable = false;
325 if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200326 return -1;
327 }
Max Morin787eeed2016-06-23 10:42:07 +0200328 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100329 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200330 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000331}
332
Max Morin787eeed2016-06-23 10:42:07 +0200333int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100334 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200335 CHECKinitialized_();
336 return audio_device_->SetSpeakerVolume(volume);
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
Max Morin787eeed2016-06-23 10:42:07 +0200339int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100340 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200341 CHECKinitialized_();
342 uint32_t level = 0;
343 if (audio_device_->SpeakerVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200344 return -1;
345 }
Max Morin787eeed2016-06-23 10:42:07 +0200346 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100347 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200348 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000349}
350
Max Morin787eeed2016-06-23 10:42:07 +0200351bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100352 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200353 CHECKinitialized__BOOL();
354 bool isInitialized = audio_device_->SpeakerIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100355 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200356 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000357}
358
Max Morin787eeed2016-06-23 10:42:07 +0200359bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100360 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200361 CHECKinitialized__BOOL();
362 bool isInitialized = audio_device_->MicrophoneIsInitialized();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100363 RTC_LOG(INFO) << "output: " << isInitialized;
henrika4af73662017-10-11 13:16:17 +0200364 return isInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000365}
366
Max Morin787eeed2016-06-23 10:42:07 +0200367int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200368 CHECKinitialized_();
369 uint32_t maxVol = 0;
370 if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200371 return -1;
372 }
Max Morin787eeed2016-06-23 10:42:07 +0200373 *maxVolume = maxVol;
henrika4af73662017-10-11 13:16:17 +0200374 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000375}
376
Max Morin787eeed2016-06-23 10:42:07 +0200377int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200378 CHECKinitialized_();
379 uint32_t minVol = 0;
380 if (audio_device_->MinSpeakerVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200381 return -1;
382 }
Max Morin787eeed2016-06-23 10:42:07 +0200383 *minVolume = minVol;
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::SpeakerMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100388 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200389 CHECKinitialized_();
Mirko Bonadei72c42502017-11-09 09:33:23 +0100390 bool isAvailable = false;
henrika4af73662017-10-11 13:16:17 +0200391 if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200392 return -1;
393 }
Max Morin787eeed2016-06-23 10:42:07 +0200394 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100395 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200396 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000397}
398
Max Morin787eeed2016-06-23 10:42:07 +0200399int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100400 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200401 CHECKinitialized_();
402 return audio_device_->SetSpeakerMute(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000403}
404
Max Morin787eeed2016-06-23 10:42:07 +0200405int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100406 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200407 CHECKinitialized_();
408 bool muted = false;
409 if (audio_device_->SpeakerMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200410 return -1;
411 }
Max Morin787eeed2016-06-23 10:42:07 +0200412 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100413 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200414 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000415}
416
Max Morin787eeed2016-06-23 10:42:07 +0200417int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100418 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200419 CHECKinitialized_();
420 bool isAvailable = false;
421 if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200422 return -1;
423 }
Max Morin787eeed2016-06-23 10:42:07 +0200424 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100425 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200426 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000427}
428
Max Morin787eeed2016-06-23 10:42:07 +0200429int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100430 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200431 CHECKinitialized_();
432 return (audio_device_->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000433}
434
Max Morin787eeed2016-06-23 10:42:07 +0200435int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100436 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200437 CHECKinitialized_();
438 bool muted = false;
439 if (audio_device_->MicrophoneMute(muted) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200440 return -1;
441 }
Max Morin787eeed2016-06-23 10:42:07 +0200442 *enabled = muted;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100443 RTC_LOG(INFO) << "output: " << muted;
henrika4af73662017-10-11 13:16:17 +0200444 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000445}
446
Max Morin787eeed2016-06-23 10:42:07 +0200447int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100448 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200449 CHECKinitialized_();
450 bool isAvailable = false;
451 if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200452 return -1;
453 }
Max Morin787eeed2016-06-23 10:42:07 +0200454 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100455 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200456 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000457}
458
Max Morin787eeed2016-06-23 10:42:07 +0200459int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100460 RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
henrika4af73662017-10-11 13:16:17 +0200461 CHECKinitialized_();
462 return (audio_device_->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000463}
464
Max Morin787eeed2016-06-23 10:42:07 +0200465int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100466 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200467 CHECKinitialized_();
468 uint32_t level = 0;
469 if (audio_device_->MicrophoneVolume(level) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200470 return -1;
471 }
Max Morin787eeed2016-06-23 10:42:07 +0200472 *volume = level;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100473 RTC_LOG(INFO) << "output: " << *volume;
henrika4af73662017-10-11 13:16:17 +0200474 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000475}
476
Max Morin787eeed2016-06-23 10:42:07 +0200477int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
478 bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100479 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200480 CHECKinitialized_();
481 bool isAvailable = false;
482 if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200483 return -1;
484 }
Max Morin787eeed2016-06-23 10:42:07 +0200485 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100486 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200487 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000488}
489
Max Morin787eeed2016-06-23 10:42:07 +0200490int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100491 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200492 CHECKinitialized_();
493 if (audio_device_->RecordingIsInitialized()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100494 RTC_LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200495 return -1;
496 }
henrika4af73662017-10-11 13:16:17 +0200497 if (audio_device_->SetStereoRecording(enable) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100498 RTC_LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200499 return -1;
500 }
Max Morin787eeed2016-06-23 10:42:07 +0200501 int8_t nChannels(1);
502 if (enable) {
503 nChannels = 2;
504 }
henrika4af73662017-10-11 13:16:17 +0200505 audio_device_buffer_.SetRecordingChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200506 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000507}
508
Max Morin787eeed2016-06-23 10:42:07 +0200509int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100510 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200511 CHECKinitialized_();
512 bool stereo = false;
513 if (audio_device_->StereoRecording(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200514 return -1;
515 }
Max Morin787eeed2016-06-23 10:42:07 +0200516 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100517 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200518 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000519}
520
Max Morin787eeed2016-06-23 10:42:07 +0200521int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
522 if (channel == kChannelBoth) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100523 RTC_LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200524 } else if (channel == kChannelLeft) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100525 RTC_LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200526 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100527 RTC_LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200528 }
henrika4af73662017-10-11 13:16:17 +0200529 CHECKinitialized_();
530 bool stereo = false;
531 if (audio_device_->StereoRecording(stereo) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100532 RTC_LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200533 return -1;
534 }
henrika4af73662017-10-11 13:16:17 +0200535 return audio_device_buffer_.SetRecordingChannel(channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000536}
537
Max Morin787eeed2016-06-23 10:42:07 +0200538int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100539 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200540 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200541 ChannelType chType;
henrika4af73662017-10-11 13:16:17 +0200542 if (audio_device_buffer_.RecordingChannel(chType) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200543 return -1;
544 }
Max Morin787eeed2016-06-23 10:42:07 +0200545 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200546 if (*channel == kChannelBoth) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100547 RTC_LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200548 } else if (*channel == kChannelLeft) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100549 RTC_LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200550 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100551 RTC_LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200552 }
henrika4af73662017-10-11 13:16:17 +0200553 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000554}
555
Max Morin787eeed2016-06-23 10:42:07 +0200556int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100557 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200558 CHECKinitialized_();
559 bool isAvailable = false;
560 if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200561 return -1;
562 }
Max Morin787eeed2016-06-23 10:42:07 +0200563 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100564 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200565 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000566}
567
Max Morin787eeed2016-06-23 10:42:07 +0200568int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100569 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200570 CHECKinitialized_();
571 if (audio_device_->PlayoutIsInitialized()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100572 RTC_LOG(LERROR)
Max Morin098e6c52016-06-28 09:36:25 +0200573 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200574 return -1;
575 }
henrika4af73662017-10-11 13:16:17 +0200576 if (audio_device_->SetStereoPlayout(enable)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100577 RTC_LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200578 return -1;
579 }
Max Morin787eeed2016-06-23 10:42:07 +0200580 int8_t nChannels(1);
581 if (enable) {
582 nChannels = 2;
583 }
henrika4af73662017-10-11 13:16:17 +0200584 audio_device_buffer_.SetPlayoutChannels(nChannels);
Max Morin787eeed2016-06-23 10:42:07 +0200585 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000586}
587
Max Morin787eeed2016-06-23 10:42:07 +0200588int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100589 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200590 CHECKinitialized_();
591 bool stereo = false;
592 if (audio_device_->StereoPlayout(stereo) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200593 return -1;
594 }
Max Morin787eeed2016-06-23 10:42:07 +0200595 *enabled = stereo;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100596 RTC_LOG(INFO) << "output: " << stereo;
henrika4af73662017-10-11 13:16:17 +0200597 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000598}
599
Max Morin787eeed2016-06-23 10:42:07 +0200600int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100601 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200602 CHECKinitialized_();
603 return (audio_device_->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000604}
605
Max Morin787eeed2016-06-23 10:42:07 +0200606bool AudioDeviceModuleImpl::AGC() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100607 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200608 CHECKinitialized__BOOL();
609 return audio_device_->AGC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000610}
611
Max Morin787eeed2016-06-23 10:42:07 +0200612int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100613 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200614 CHECKinitialized_();
615 bool isAvailable = false;
616 if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200617 return -1;
618 }
Max Morin787eeed2016-06-23 10:42:07 +0200619 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100620 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200621 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000622}
623
Max Morin787eeed2016-06-23 10:42:07 +0200624int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100625 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200626 CHECKinitialized_();
627 bool isAvailable = false;
628 if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200629 return -1;
630 }
Max Morin787eeed2016-06-23 10:42:07 +0200631 *available = isAvailable;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100632 RTC_LOG(INFO) << "output: " << isAvailable;
henrika4af73662017-10-11 13:16:17 +0200633 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000634}
635
Max Morin787eeed2016-06-23 10:42:07 +0200636int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
henrika4af73662017-10-11 13:16:17 +0200637 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200638 uint32_t maxVol(0);
henrika4af73662017-10-11 13:16:17 +0200639 if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200640 return -1;
641 }
Max Morin787eeed2016-06-23 10:42:07 +0200642 *maxVolume = maxVol;
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::MinMicrophoneVolume(uint32_t* minVolume) const {
henrika4af73662017-10-11 13:16:17 +0200647 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200648 uint32_t minVol(0);
henrika4af73662017-10-11 13:16:17 +0200649 if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200650 return -1;
651 }
Max Morin787eeed2016-06-23 10:42:07 +0200652 *minVolume = minVol;
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 +0200656int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100657 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200658 CHECKinitialized_();
659 uint16_t nPlayoutDevices = audio_device_->PlayoutDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100660 RTC_LOG(INFO) << "output: " << nPlayoutDevices;
henrika4af73662017-10-11 13:16:17 +0200661 return (int16_t)(nPlayoutDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +0000662}
663
Max Morin787eeed2016-06-23 10:42:07 +0200664int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100665 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200666 CHECKinitialized_();
667 return audio_device_->SetPlayoutDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000668}
669
Max Morin787eeed2016-06-23 10:42:07 +0200670int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100671 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200672 CHECKinitialized_();
673 return audio_device_->SetPlayoutDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000674}
675
pbos@webrtc.org25509882013-04-09 10:30:35 +0000676int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
677 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000678 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200679 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100680 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200681 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200682 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200683 return -1;
684 }
henrika4af73662017-10-11 13:16:17 +0200685 if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200686 return -1;
687 }
Max Morin787eeed2016-06-23 10:42:07 +0200688 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100689 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200690 }
691 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100692 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200693 }
henrika4af73662017-10-11 13:16:17 +0200694 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000695}
696
pbos@webrtc.org25509882013-04-09 10:30:35 +0000697int32_t AudioDeviceModuleImpl::RecordingDeviceName(
698 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +0000699 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +0200700 char guid[kAdmMaxGuidSize]) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100701 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
henrika4af73662017-10-11 13:16:17 +0200702 CHECKinitialized_();
Max Morin787eeed2016-06-23 10:42:07 +0200703 if (name == NULL) {
Max Morin787eeed2016-06-23 10:42:07 +0200704 return -1;
705 }
henrika4af73662017-10-11 13:16:17 +0200706 if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
Max Morin787eeed2016-06-23 10:42:07 +0200707 return -1;
708 }
Max Morin787eeed2016-06-23 10:42:07 +0200709 if (name != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100710 RTC_LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +0200711 }
712 if (guid != NULL) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100713 RTC_LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +0200714 }
henrika4af73662017-10-11 13:16:17 +0200715 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000716}
717
Max Morin787eeed2016-06-23 10:42:07 +0200718int16_t AudioDeviceModuleImpl::RecordingDevices() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100719 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200720 CHECKinitialized_();
721 uint16_t nRecordingDevices = audio_device_->RecordingDevices();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100722 RTC_LOG(INFO) << "output: " << nRecordingDevices;
henrika4af73662017-10-11 13:16:17 +0200723 return (int16_t)nRecordingDevices;
niklase@google.com470e71d2011-07-07 08:21:25 +0000724}
725
Max Morin787eeed2016-06-23 10:42:07 +0200726int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100727 RTC_LOG(INFO) << __FUNCTION__ << "(" << index << ")";
henrika4af73662017-10-11 13:16:17 +0200728 CHECKinitialized_();
729 return audio_device_->SetRecordingDevice(index);
niklase@google.com470e71d2011-07-07 08:21:25 +0000730}
731
Max Morin787eeed2016-06-23 10:42:07 +0200732int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100733 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200734 CHECKinitialized_();
735 return audio_device_->SetRecordingDevice(device);
niklase@google.com470e71d2011-07-07 08:21:25 +0000736}
737
Max Morin787eeed2016-06-23 10:42:07 +0200738int32_t AudioDeviceModuleImpl::InitPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100739 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200740 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700741 if (PlayoutIsInitialized()) {
742 return 0;
743 }
henrika4af73662017-10-11 13:16:17 +0200744 int32_t result = audio_device_->InitPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100745 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200746 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
747 static_cast<int>(result == 0));
748 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000749}
750
Max Morin787eeed2016-06-23 10:42:07 +0200751int32_t AudioDeviceModuleImpl::InitRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100752 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200753 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700754 if (RecordingIsInitialized()) {
755 return 0;
756 }
henrika4af73662017-10-11 13:16:17 +0200757 int32_t result = audio_device_->InitRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100758 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200759 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
760 static_cast<int>(result == 0));
761 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000762}
763
Max Morin787eeed2016-06-23 10:42:07 +0200764bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100765 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200766 CHECKinitialized__BOOL();
767 return audio_device_->PlayoutIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000768}
769
Max Morin787eeed2016-06-23 10:42:07 +0200770bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100771 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200772 CHECKinitialized__BOOL();
773 return audio_device_->RecordingIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000774}
775
Max Morin787eeed2016-06-23 10:42:07 +0200776int32_t AudioDeviceModuleImpl::StartPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100777 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200778 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700779 if (Playing()) {
780 return 0;
781 }
henrika4af73662017-10-11 13:16:17 +0200782 audio_device_buffer_.StartPlayout();
783 int32_t result = audio_device_->StartPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100784 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200785 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
786 static_cast<int>(result == 0));
787 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000788}
789
Max Morin787eeed2016-06-23 10:42:07 +0200790int32_t AudioDeviceModuleImpl::StopPlayout() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100791 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200792 CHECKinitialized_();
793 int32_t result = audio_device_->StopPlayout();
794 audio_device_buffer_.StopPlayout();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100795 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200796 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
797 static_cast<int>(result == 0));
798 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000799}
800
Max Morin787eeed2016-06-23 10:42:07 +0200801bool AudioDeviceModuleImpl::Playing() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100802 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200803 CHECKinitialized__BOOL();
804 return audio_device_->Playing();
niklase@google.com470e71d2011-07-07 08:21:25 +0000805}
806
Max Morin787eeed2016-06-23 10:42:07 +0200807int32_t AudioDeviceModuleImpl::StartRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100808 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200809 CHECKinitialized_();
maxmorin8c695b42016-07-25 02:46:44 -0700810 if (Recording()) {
811 return 0;
812 }
henrika4af73662017-10-11 13:16:17 +0200813 audio_device_buffer_.StartRecording();
814 int32_t result = audio_device_->StartRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100815 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200816 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
817 static_cast<int>(result == 0));
818 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000819}
niklase@google.com470e71d2011-07-07 08:21:25 +0000820
Max Morin787eeed2016-06-23 10:42:07 +0200821int32_t AudioDeviceModuleImpl::StopRecording() {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100822 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200823 CHECKinitialized_();
824 int32_t result = audio_device_->StopRecording();
825 audio_device_buffer_.StopRecording();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100826 RTC_LOG(INFO) << "output: " << result;
Max Morin84cab202016-07-01 13:35:19 +0200827 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
828 static_cast<int>(result == 0));
829 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000830}
831
Max Morin787eeed2016-06-23 10:42:07 +0200832bool AudioDeviceModuleImpl::Recording() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100833 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200834 CHECKinitialized__BOOL();
835 return audio_device_->Recording();
niklase@google.com470e71d2011-07-07 08:21:25 +0000836}
837
Max Morin787eeed2016-06-23 10:42:07 +0200838int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
839 AudioTransport* audioCallback) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100840 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200841 return audio_device_buffer_.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +0000842}
843
Max Morin787eeed2016-06-23 10:42:07 +0200844int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
henrika4af73662017-10-11 13:16:17 +0200845 CHECKinitialized_();
846 uint16_t delay = 0;
847 if (audio_device_->PlayoutDelay(delay) == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100848 RTC_LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +0200849 return -1;
850 }
Max Morin787eeed2016-06-23 10:42:07 +0200851 *delayMS = delay;
henrika4af73662017-10-11 13:16:17 +0200852 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000853}
854
Max Morin787eeed2016-06-23 10:42:07 +0200855int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
856 const uint32_t samplesPerSec) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100857 RTC_LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
henrika4af73662017-10-11 13:16:17 +0200858 CHECKinitialized_();
859 if (audio_device_->SetRecordingSampleRate(samplesPerSec) != 0) {
Max Morin787eeed2016-06-23 10:42:07 +0200860 return -1;
861 }
henrika4af73662017-10-11 13:16:17 +0200862 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000863}
864
Max Morin787eeed2016-06-23 10:42:07 +0200865int32_t AudioDeviceModuleImpl::RecordingSampleRate(
866 uint32_t* samplesPerSec) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100867 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200868 CHECKinitialized_();
869 int32_t sampleRate = audio_device_buffer_.RecordingSampleRate();
Max Morin787eeed2016-06-23 10:42:07 +0200870 if (sampleRate == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100871 RTC_LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +0200872 return -1;
873 }
Max Morin787eeed2016-06-23 10:42:07 +0200874 *samplesPerSec = sampleRate;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100875 RTC_LOG(INFO) << "output: " << *samplesPerSec;
henrika4af73662017-10-11 13:16:17 +0200876 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000877}
878
Max Morin787eeed2016-06-23 10:42:07 +0200879int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
880 const uint32_t samplesPerSec) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100881 RTC_LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
henrika4af73662017-10-11 13:16:17 +0200882 CHECKinitialized_();
883 if (audio_device_->SetPlayoutSampleRate(samplesPerSec) != 0) {
Max Morin787eeed2016-06-23 10:42:07 +0200884 return -1;
885 }
henrika4af73662017-10-11 13:16:17 +0200886 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000887}
888
Max Morin787eeed2016-06-23 10:42:07 +0200889int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
890 uint32_t* samplesPerSec) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100891 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200892 CHECKinitialized_();
893 int32_t sampleRate = audio_device_buffer_.PlayoutSampleRate();
Max Morin787eeed2016-06-23 10:42:07 +0200894 if (sampleRate == -1) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100895 RTC_LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +0200896 return -1;
897 }
Max Morin787eeed2016-06-23 10:42:07 +0200898 *samplesPerSec = sampleRate;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100899 RTC_LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +0200900 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000901}
902
henrika4af73662017-10-11 13:16:17 +0200903int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100904 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200905 CHECKinitialized_();
906 if (audio_device_->SetLoudspeakerStatus(enable) != 0) {
907 return -1;
908 }
909 return 0;
910}
niklase@google.com470e71d2011-07-07 08:21:25 +0000911
henrikac14f5ff2015-09-23 14:08:33 +0200912int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100913 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200914 CHECKinitialized_();
Max Morin098e6c52016-06-28 09:36:25 +0200915 int32_t ok = 0;
henrika4af73662017-10-11 13:16:17 +0200916 if (audio_device_->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +0200917 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +0200918 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100919 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200920 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +0000921}
922
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000923bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100924 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200925 CHECKinitialized__BOOL();
926 bool isAvailable = audio_device_->BuiltInAECIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100927 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200928 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000929}
930
henrikac14f5ff2015-09-23 14:08:33 +0200931int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100932 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200933 CHECKinitialized_();
934 int32_t ok = audio_device_->EnableBuiltInAEC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100935 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200936 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200937}
938
939bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100940 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200941 CHECKinitialized__BOOL();
942 bool isAvailable = audio_device_->BuiltInAGCIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100943 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200944 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200945}
946
947int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100948 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200949 CHECKinitialized_();
950 int32_t ok = audio_device_->EnableBuiltInAGC(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100951 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200952 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200953}
954
955bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100956 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200957 CHECKinitialized__BOOL();
958 bool isAvailable = audio_device_->BuiltInNSIsAvailable();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100959 RTC_LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +0200960 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +0200961}
962
963int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100964 RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrika4af73662017-10-11 13:16:17 +0200965 CHECKinitialized_();
966 int32_t ok = audio_device_->EnableBuiltInNS(enable);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100967 RTC_LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +0200968 return ok;
henrikac14f5ff2015-09-23 14:08:33 +0200969}
970
maxmorin88e31a32016-08-16 00:56:09 -0700971#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +0200972int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
973 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100974 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200975 int r = audio_device_->GetPlayoutAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100976 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200977 return r;
henrikaba35d052015-07-14 17:04:08 +0200978}
979
980int AudioDeviceModuleImpl::GetRecordAudioParameters(
981 AudioParameters* params) const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100982 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200983 int r = audio_device_->GetRecordAudioParameters(params);
Mirko Bonadei675513b2017-11-09 11:09:25 +0100984 RTC_LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +0200985 return r;
henrikaba35d052015-07-14 17:04:08 +0200986}
maxmorin88e31a32016-08-16 00:56:09 -0700987#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +0200988
Max Morin787eeed2016-06-23 10:42:07 +0200989AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100990 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200991 return platform_type_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000992}
993
Max Morin787eeed2016-06-23 10:42:07 +0200994AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
995 const {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100996 RTC_LOG(INFO) << __FUNCTION__;
henrika4af73662017-10-11 13:16:17 +0200997 return audio_layer_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000998}
999
1000} // namespace webrtc