blob: 1296ddb73e6c3042cfab224086495f727b5f6727 [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"
12#include "common_audio/signal_processing/include/signal_processing_library.h"
13#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öllerbf6937a2017-10-03 10:42:04 +020018#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/timeutils.h"
20#include "system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000022#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000023#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020026#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
27#include "audio_device_core_win.h"
28#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000029#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020030#include <stdlib.h>
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "modules/audio_device/android/audio_device_template.h"
32#include "modules/audio_device/android/audio_manager.h"
33#include "modules/audio_device/android/audio_record_jni.h"
34#include "modules/audio_device/android/audio_track_jni.h"
35#include "modules/audio_device/android/opensles_player.h"
36#include "modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000037#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020038#if defined(LINUX_ALSA)
39#include "audio_device_alsa_linux.h"
40#endif
Tommi68898a22015-05-19 17:28:07 +020041#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020042#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020043#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000044#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020045#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000046#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020047#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000048#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000049
50#if defined(WEBRTC_DUMMY_FILE_DEVICES)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#include "modules/audio_device/dummy/file_audio_device_factory.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000052#endif
53
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#include "modules/audio_device/dummy/audio_device_dummy.h"
55#include "modules/audio_device/dummy/file_audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000056
Max Morin787eeed2016-06-23 10:42:07 +020057#define CHECK_INITIALIZED() \
58 { \
59 if (!_initialized) { \
60 return -1; \
61 }; \
62 }
niklase@google.com470e71d2011-07-07 08:21:25 +000063
Max Morin787eeed2016-06-23 10:42:07 +020064#define CHECK_INITIALIZED_BOOL() \
65 { \
66 if (!_initialized) { \
67 return false; \
68 }; \
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
Peter Boström1d194412016-03-21 16:44:31 +010071namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000072
niklase@google.com470e71d2011-07-07 08:21:25 +000073// ============================================================================
74// Static methods
75// ============================================================================
76
77// ----------------------------------------------------------------------------
78// AudioDeviceModule::Create()
79// ----------------------------------------------------------------------------
80
Peter Boström4adbbcf2016-05-03 15:51:26 -040081rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010082 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040083 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020084 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020085 // Create the generic ref counted (platform independent) implementation.
86 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
87 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000088
Max Morin787eeed2016-06-23 10:42:07 +020089 // Ensure that the current platform is supported.
90 if (audioDevice->CheckPlatform() == -1) {
91 return nullptr;
92 }
niklase@google.com470e71d2011-07-07 08:21:25 +000093
Max Morin787eeed2016-06-23 10:42:07 +020094 // Create the platform-dependent implementation.
95 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
96 return nullptr;
97 }
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Max Morin787eeed2016-06-23 10:42:07 +020099 // Ensure that the generic audio buffer can communicate with the
100 // platform-specific parts.
101 if (audioDevice->AttachAudioBuffer() == -1) {
102 return nullptr;
103 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
Max Morin787eeed2016-06-23 10:42:07 +0200105 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000106
Max Morin787eeed2016-06-23 10:42:07 +0200107 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
niklase@google.com470e71d2011-07-07 08:21:25 +0000110// ============================================================================
111// Construction & Destruction
112// ============================================================================
113
114// ----------------------------------------------------------------------------
115// AudioDeviceModuleImpl - ctor
116// ----------------------------------------------------------------------------
117
Max Morin787eeed2016-06-23 10:42:07 +0200118AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
119 const AudioLayer audioLayer)
Fredrik Solenberga32dd012017-10-04 13:27:21 +0200120 : _ptrAudioDevice(NULL),
Max Morin787eeed2016-06-23 10:42:07 +0200121 _id(id),
122 _platformAudioLayer(audioLayer),
Max Morin787eeed2016-06-23 10:42:07 +0200123 _platformType(kPlatformNotSupported),
124 _initialized(false),
125 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200126 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127}
128
129// ----------------------------------------------------------------------------
130// CheckPlatform
131// ----------------------------------------------------------------------------
132
Max Morin787eeed2016-06-23 10:42:07 +0200133int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200134 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
Max Morin787eeed2016-06-23 10:42:07 +0200136 // Ensure that the current platform is supported
137 //
138 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
140#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200141 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200142 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000143#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200144 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200145 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000146#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200147 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200148 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000149#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200150 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200151 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000152#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200153 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200154 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000155#endif
156
Max Morin787eeed2016-06-23 10:42:07 +0200157 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200158 LOG(LERROR) << "current platform is not supported => this module will self "
159 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200160 return -1;
161 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
Max Morin787eeed2016-06-23 10:42:07 +0200163 // Store valid output results
164 //
165 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000166
Max Morin787eeed2016-06-23 10:42:07 +0200167 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168}
169
niklase@google.com470e71d2011-07-07 08:21:25 +0000170// ----------------------------------------------------------------------------
171// CreatePlatformSpecificObjects
172// ----------------------------------------------------------------------------
173
Max Morin787eeed2016-06-23 10:42:07 +0200174int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200175 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
Max Morin787eeed2016-06-23 10:42:07 +0200177 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
xians@google.combf5d2ba2011-08-16 07:44:19 +0000179#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200180 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200181 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000182#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200183 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
noahric6a355902016-08-17 15:19:50 -0700184 if (ptrAudioDevice) {
185 LOG(INFO) << "Will use file-playing dummy device.";
186 } else {
187 // Create a dummy device instead.
188 ptrAudioDevice = new AudioDeviceDummy(Id());
189 LOG(INFO) << "Dummy Audio APIs will be utilized";
190 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000191#else
Max Morin787eeed2016-06-23 10:42:07 +0200192 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
Max Morin787eeed2016-06-23 10:42:07 +0200194// Create the *Windows* implementation of the Audio Device
195//
niklase@google.com470e71d2011-07-07 08:21:25 +0000196#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200197 if ((audioLayer == kWindowsCoreAudio) ||
198 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200199 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
Max Morin787eeed2016-06-23 10:42:07 +0200201 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
202 // create *Windows Core Audio* implementation
sazab4aa4eb2017-07-19 01:12:36 -0700203 ptrAudioDevice = new AudioDeviceWindowsCore();
Max Morin098e6c52016-06-28 09:36:25 +0200204 LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000205 }
Max Morin787eeed2016-06-23 10:42:07 +0200206 }
207#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000209#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200210 // Create an Android audio manager.
211 _audioManagerAndroid.reset(new AudioManager());
212 // Select best possible combination of audio layers.
213 if (audioLayer == kPlatformDefaultAudio) {
henrika918b5542016-09-19 15:44:09 +0200214 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
215 _audioManagerAndroid->IsLowLatencyRecordSupported()) {
216 // Use OpenSL ES for both playout and recording.
217 audioLayer = kAndroidOpenSLESAudio;
218 } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
219 !_audioManagerAndroid->IsLowLatencyRecordSupported()) {
220 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200221 // low-latency output audio path.
222 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200223 } else {
henrika918b5542016-09-19 15:44:09 +0200224 // Use Java-based audio in both directions when low-latency output is
225 // not supported.
Max Morin787eeed2016-06-23 10:42:07 +0200226 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000227 }
Max Morin787eeed2016-06-23 10:42:07 +0200228 }
229 AudioManager* audio_manager = _audioManagerAndroid.get();
230 if (audioLayer == kAndroidJavaAudio) {
231 // Java audio for both input and output audio.
232 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
233 audioLayer, audio_manager);
henrika918b5542016-09-19 15:44:09 +0200234 } else if (audioLayer == kAndroidOpenSLESAudio) {
235 // OpenSL ES based audio for both input and output audio.
236 ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
237 audioLayer, audio_manager);
Max Morin787eeed2016-06-23 10:42:07 +0200238 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
239 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
240 // This combination provides low-latency output audio and at the same
241 // time support for HW AEC using the AudioRecord Java API.
242 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
243 audioLayer, audio_manager);
244 } else {
245 // Invalid audio layer.
henrika918b5542016-09-19 15:44:09 +0200246 ptrAudioDevice = nullptr;
Max Morin787eeed2016-06-23 10:42:07 +0200247 }
248// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000249
Max Morin787eeed2016-06-23 10:42:07 +0200250// Create the *Linux* implementation of the Audio Device
251//
niklase@google.com470e71d2011-07-07 08:21:25 +0000252#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200253 if ((audioLayer == kLinuxPulseAudio) ||
254 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000255#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200256 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000257
Max Morin787eeed2016-06-23 10:42:07 +0200258 // create *Linux PulseAudio* implementation
saza43a85f02017-07-18 04:12:29 -0700259 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse();
Max Morin84cab202016-07-01 13:35:19 +0200260 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200261 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200262 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200263 } else {
264 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000265#endif
266#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200267 // create *Linux ALSA Audio* implementation
saza43a85f02017-07-18 04:12:29 -0700268 ptrAudioDevice = new AudioDeviceLinuxALSA();
Max Morin787eeed2016-06-23 10:42:07 +0200269 if (ptrAudioDevice != NULL) {
270 // Pulse Audio was not supported => revert to ALSA instead
271 _platformAudioLayer =
272 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200273 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
274 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200275 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000276#endif
277#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000278 }
Max Morin787eeed2016-06-23 10:42:07 +0200279#endif
280 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000281#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200282 // create *Linux ALSA Audio* implementation
saza43a85f02017-07-18 04:12:29 -0700283 ptrAudioDevice = new AudioDeviceLinuxALSA();
Max Morin098e6c52016-06-28 09:36:25 +0200284 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000285#endif
Max Morin787eeed2016-06-23 10:42:07 +0200286 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000287#endif // #if defined(WEBRTC_LINUX)
288
Max Morin787eeed2016-06-23 10:42:07 +0200289// Create the *iPhone* implementation of the Audio Device
290//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000291#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200292 if (audioLayer == kPlatformDefaultAudio) {
293 // Create iOS Audio Device implementation.
294 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200295 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200296 }
297// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
Max Morin787eeed2016-06-23 10:42:07 +0200299// Create the *Mac* implementation of the Audio Device
300//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000301#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200302 if (audioLayer == kPlatformDefaultAudio) {
303 // Create *Mac Audio* implementation
sazab4aa4eb2017-07-19 01:12:36 -0700304 ptrAudioDevice = new AudioDeviceMac();
Max Morin098e6c52016-06-28 09:36:25 +0200305 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200306 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000307#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000308
Max Morin787eeed2016-06-23 10:42:07 +0200309 // Create the *Dummy* implementation of the Audio Device
310 // Available for all platforms
311 //
312 if (audioLayer == kDummyAudio) {
313 // Create *Dummy Audio* implementation
314 assert(!ptrAudioDevice);
315 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200316 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200317 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000318#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000319
Max Morin787eeed2016-06-23 10:42:07 +0200320 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200321 LOG(LERROR)
322 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200323 return -1;
324 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
Max Morin787eeed2016-06-23 10:42:07 +0200326 // Store valid output pointers
327 //
328 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000329
Max Morin787eeed2016-06-23 10:42:07 +0200330 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000331}
332
333// ----------------------------------------------------------------------------
334// AttachAudioBuffer
335//
336// Install "bridge" between the platform implemetation and the generic
337// implementation. The "child" shall set the native sampling rate and the
338// number of channels in this function call.
339// ----------------------------------------------------------------------------
340
Max Morin787eeed2016-06-23 10:42:07 +0200341int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200342 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000343
Max Morin787eeed2016-06-23 10:42:07 +0200344 _audioDeviceBuffer.SetId(_id);
345 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
346 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000347}
348
349// ----------------------------------------------------------------------------
350// ~AudioDeviceModuleImpl - dtor
351// ----------------------------------------------------------------------------
352
Max Morin787eeed2016-06-23 10:42:07 +0200353AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200354 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200355 if (_ptrAudioDevice) {
356 delete _ptrAudioDevice;
357 _ptrAudioDevice = NULL;
358 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000359}
360
361// ============================================================================
niklase@google.com470e71d2011-07-07 08:21:25 +0000362// Public API
363// ============================================================================
364
365// ----------------------------------------------------------------------------
366// ActiveAudioLayer
367// ----------------------------------------------------------------------------
368
henrikab2619892015-05-18 16:49:16 +0200369int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200370 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200371 AudioLayer activeAudio;
372 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
373 return -1;
374 }
375 *audioLayer = activeAudio;
376 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377}
378
379// ----------------------------------------------------------------------------
380// LastError
381// ----------------------------------------------------------------------------
382
Max Morin787eeed2016-06-23 10:42:07 +0200383AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200384 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200385 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000386}
387
388// ----------------------------------------------------------------------------
389// Init
390// ----------------------------------------------------------------------------
391
Max Morin787eeed2016-06-23 10:42:07 +0200392int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200393 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200394 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200396 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200397
Max Morin84cab202016-07-01 13:35:19 +0200398 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
399 RTC_HISTOGRAM_ENUMERATION(
400 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
401 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
402 if (status != AudioDeviceGeneric::InitStatus::OK) {
403 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200404 return -1;
405 }
406
407 _initialized = true;
408 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000409}
410
411// ----------------------------------------------------------------------------
412// Terminate
413// ----------------------------------------------------------------------------
414
Max Morin787eeed2016-06-23 10:42:07 +0200415int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200416 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200417 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000418 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200419
420 if (_ptrAudioDevice->Terminate() == -1) {
421 return -1;
422 }
423
424 _initialized = false;
425 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000426}
427
428// ----------------------------------------------------------------------------
429// Initialized
430// ----------------------------------------------------------------------------
431
Max Morin787eeed2016-06-23 10:42:07 +0200432bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200433 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200434 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000435}
436
437// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000438// InitSpeaker
439// ----------------------------------------------------------------------------
440
Max Morin787eeed2016-06-23 10:42:07 +0200441int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200442 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200443 CHECK_INITIALIZED();
444 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000445}
446
447// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000448// InitMicrophone
449// ----------------------------------------------------------------------------
450
Max Morin787eeed2016-06-23 10:42:07 +0200451int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200452 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200453 CHECK_INITIALIZED();
454 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000455}
456
457// ----------------------------------------------------------------------------
458// SpeakerVolumeIsAvailable
459// ----------------------------------------------------------------------------
460
Max Morin787eeed2016-06-23 10:42:07 +0200461int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200462 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200463 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000464
Max Morin787eeed2016-06-23 10:42:07 +0200465 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000466
Max Morin787eeed2016-06-23 10:42:07 +0200467 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
468 return -1;
469 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000470
Max Morin787eeed2016-06-23 10:42:07 +0200471 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200472 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200473 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000474}
475
476// ----------------------------------------------------------------------------
477// SetSpeakerVolume
478// ----------------------------------------------------------------------------
479
Max Morin787eeed2016-06-23 10:42:07 +0200480int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200481 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200482 CHECK_INITIALIZED();
483 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000484}
485
486// ----------------------------------------------------------------------------
487// SpeakerVolume
488// ----------------------------------------------------------------------------
489
Max Morin787eeed2016-06-23 10:42:07 +0200490int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200491 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200492 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000493
Max Morin787eeed2016-06-23 10:42:07 +0200494 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000495
Max Morin787eeed2016-06-23 10:42:07 +0200496 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
497 return -1;
498 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000499
Max Morin787eeed2016-06-23 10:42:07 +0200500 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200501 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200502 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000503}
504
505// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000506// SpeakerIsInitialized
507// ----------------------------------------------------------------------------
508
Max Morin787eeed2016-06-23 10:42:07 +0200509bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200510 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200511 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000512
Max Morin787eeed2016-06-23 10:42:07 +0200513 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200514 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200515 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000516}
517
518// ----------------------------------------------------------------------------
519// MicrophoneIsInitialized
520// ----------------------------------------------------------------------------
521
Max Morin787eeed2016-06-23 10:42:07 +0200522bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200523 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200524 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000525
Max Morin787eeed2016-06-23 10:42:07 +0200526 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200527 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200528 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000529}
530
531// ----------------------------------------------------------------------------
532// MaxSpeakerVolume
533// ----------------------------------------------------------------------------
534
Max Morin787eeed2016-06-23 10:42:07 +0200535int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
536 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000537
Max Morin787eeed2016-06-23 10:42:07 +0200538 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000539
Max Morin787eeed2016-06-23 10:42:07 +0200540 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
541 return -1;
542 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000543
Max Morin787eeed2016-06-23 10:42:07 +0200544 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200545 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000546}
547
548// ----------------------------------------------------------------------------
549// MinSpeakerVolume
550// ----------------------------------------------------------------------------
551
Max Morin787eeed2016-06-23 10:42:07 +0200552int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
553 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000554
Max Morin787eeed2016-06-23 10:42:07 +0200555 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000556
Max Morin787eeed2016-06-23 10:42:07 +0200557 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
558 return -1;
559 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000560
Max Morin787eeed2016-06-23 10:42:07 +0200561 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200562 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000563}
564
565// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000566// SpeakerMuteIsAvailable
567// ----------------------------------------------------------------------------
568
Max Morin787eeed2016-06-23 10:42:07 +0200569int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200570 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200571 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000572
Max Morin787eeed2016-06-23 10:42:07 +0200573 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000574
Max Morin787eeed2016-06-23 10:42:07 +0200575 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
576 return -1;
577 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000578
Max Morin787eeed2016-06-23 10:42:07 +0200579 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200580 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200581 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000582}
583
584// ----------------------------------------------------------------------------
585// SetSpeakerMute
586// ----------------------------------------------------------------------------
587
Max Morin787eeed2016-06-23 10:42:07 +0200588int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200589 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200590 CHECK_INITIALIZED();
591 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000592}
593
594// ----------------------------------------------------------------------------
595// SpeakerMute
596// ----------------------------------------------------------------------------
597
Max Morin787eeed2016-06-23 10:42:07 +0200598int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200599 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200600 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000601
Max Morin787eeed2016-06-23 10:42:07 +0200602 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000603
Max Morin787eeed2016-06-23 10:42:07 +0200604 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
605 return -1;
606 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000607
Max Morin787eeed2016-06-23 10:42:07 +0200608 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200609 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200610 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000611}
612
613// ----------------------------------------------------------------------------
614// MicrophoneMuteIsAvailable
615// ----------------------------------------------------------------------------
616
Max Morin787eeed2016-06-23 10:42:07 +0200617int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200618 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200619 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000620
Max Morin787eeed2016-06-23 10:42:07 +0200621 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000622
Max Morin787eeed2016-06-23 10:42:07 +0200623 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
624 return -1;
625 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000626
Max Morin787eeed2016-06-23 10:42:07 +0200627 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200628 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200629 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000630}
631
632// ----------------------------------------------------------------------------
633// SetMicrophoneMute
634// ----------------------------------------------------------------------------
635
Max Morin787eeed2016-06-23 10:42:07 +0200636int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200637 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200638 CHECK_INITIALIZED();
639 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000640}
641
642// ----------------------------------------------------------------------------
643// MicrophoneMute
644// ----------------------------------------------------------------------------
645
Max Morin787eeed2016-06-23 10:42:07 +0200646int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200647 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200648 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000649
Max Morin787eeed2016-06-23 10:42:07 +0200650 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000651
Max Morin787eeed2016-06-23 10:42:07 +0200652 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
653 return -1;
654 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000655
Max Morin787eeed2016-06-23 10:42:07 +0200656 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200657 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200658 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000659}
660
661// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000662// MicrophoneVolumeIsAvailable
663// ----------------------------------------------------------------------------
664
Max Morin787eeed2016-06-23 10:42:07 +0200665int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200666 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200667 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000668
Max Morin787eeed2016-06-23 10:42:07 +0200669 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000670
Max Morin787eeed2016-06-23 10:42:07 +0200671 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
672 return -1;
673 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000674
Max Morin787eeed2016-06-23 10:42:07 +0200675 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200676 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200677 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000678}
679
680// ----------------------------------------------------------------------------
681// SetMicrophoneVolume
682// ----------------------------------------------------------------------------
683
Max Morin787eeed2016-06-23 10:42:07 +0200684int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200685 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200686 CHECK_INITIALIZED();
687 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000688}
689
690// ----------------------------------------------------------------------------
691// MicrophoneVolume
692// ----------------------------------------------------------------------------
693
Max Morin787eeed2016-06-23 10:42:07 +0200694int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200695 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200696 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000697
Max Morin787eeed2016-06-23 10:42:07 +0200698 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000699
Max Morin787eeed2016-06-23 10:42:07 +0200700 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
701 return -1;
702 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000703
Max Morin787eeed2016-06-23 10:42:07 +0200704 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200705 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200706 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000707}
708
709// ----------------------------------------------------------------------------
710// StereoRecordingIsAvailable
711// ----------------------------------------------------------------------------
712
Max Morin787eeed2016-06-23 10:42:07 +0200713int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
714 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200715 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200716 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000717
Max Morin787eeed2016-06-23 10:42:07 +0200718 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000719
Max Morin787eeed2016-06-23 10:42:07 +0200720 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
721 return -1;
722 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000723
Max Morin787eeed2016-06-23 10:42:07 +0200724 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200725 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200726 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000727}
728
729// ----------------------------------------------------------------------------
730// SetStereoRecording
731// ----------------------------------------------------------------------------
732
Max Morin787eeed2016-06-23 10:42:07 +0200733int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200734 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200735 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000736
Max Morin787eeed2016-06-23 10:42:07 +0200737 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200738 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200739 return -1;
740 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000741
Max Morin787eeed2016-06-23 10:42:07 +0200742 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200743 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200744 return -1;
745 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000746
Max Morin787eeed2016-06-23 10:42:07 +0200747 int8_t nChannels(1);
748 if (enable) {
749 nChannels = 2;
750 }
751 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000752
Max Morin787eeed2016-06-23 10:42:07 +0200753 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000754}
755
756// ----------------------------------------------------------------------------
757// StereoRecording
758// ----------------------------------------------------------------------------
759
Max Morin787eeed2016-06-23 10:42:07 +0200760int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200761 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200762 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000763
Max Morin787eeed2016-06-23 10:42:07 +0200764 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000765
Max Morin787eeed2016-06-23 10:42:07 +0200766 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
767 return -1;
768 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000769
Max Morin787eeed2016-06-23 10:42:07 +0200770 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200771 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200772 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000773}
774
775// ----------------------------------------------------------------------------
776// SetRecordingChannel
777// ----------------------------------------------------------------------------
778
Max Morin787eeed2016-06-23 10:42:07 +0200779int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
780 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200781 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200782 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200783 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200784 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200785 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200786 }
787 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000788
Max Morin787eeed2016-06-23 10:42:07 +0200789 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000790
Max Morin787eeed2016-06-23 10:42:07 +0200791 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200792 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200793 return -1;
794 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000795
Max Morin787eeed2016-06-23 10:42:07 +0200796 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000797}
798
799// ----------------------------------------------------------------------------
800// RecordingChannel
801// ----------------------------------------------------------------------------
802
Max Morin787eeed2016-06-23 10:42:07 +0200803int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200804 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200805 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000806
Max Morin787eeed2016-06-23 10:42:07 +0200807 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000808
Max Morin787eeed2016-06-23 10:42:07 +0200809 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
810 return -1;
811 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000812
Max Morin787eeed2016-06-23 10:42:07 +0200813 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200814 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +0200815 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200816 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +0200817 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200818 } else {
Max Morin2c332bb2016-07-04 09:03:42 +0200819 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200820 }
Max Morin787eeed2016-06-23 10:42:07 +0200821 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000822}
823
824// ----------------------------------------------------------------------------
825// StereoPlayoutIsAvailable
826// ----------------------------------------------------------------------------
827
Max Morin787eeed2016-06-23 10:42:07 +0200828int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200829 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200830 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000831
Max Morin787eeed2016-06-23 10:42:07 +0200832 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000833
Max Morin787eeed2016-06-23 10:42:07 +0200834 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
835 return -1;
836 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000837
Max Morin787eeed2016-06-23 10:42:07 +0200838 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200839 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200840 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000841}
842
843// ----------------------------------------------------------------------------
844// SetStereoPlayout
845// ----------------------------------------------------------------------------
846
Max Morin787eeed2016-06-23 10:42:07 +0200847int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200848 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200849 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000850
Max Morin787eeed2016-06-23 10:42:07 +0200851 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200852 LOG(LERROR)
853 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200854 return -1;
855 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000856
Max Morin787eeed2016-06-23 10:42:07 +0200857 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +0200858 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200859 return -1;
860 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000861
Max Morin787eeed2016-06-23 10:42:07 +0200862 int8_t nChannels(1);
863 if (enable) {
864 nChannels = 2;
865 }
866 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000867
Max Morin787eeed2016-06-23 10:42:07 +0200868 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000869}
870
871// ----------------------------------------------------------------------------
872// StereoPlayout
873// ----------------------------------------------------------------------------
874
Max Morin787eeed2016-06-23 10:42:07 +0200875int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200876 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200877 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000878
Max Morin787eeed2016-06-23 10:42:07 +0200879 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000880
Max Morin787eeed2016-06-23 10:42:07 +0200881 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
882 return -1;
883 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000884
Max Morin787eeed2016-06-23 10:42:07 +0200885 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200886 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200887 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000888}
889
890// ----------------------------------------------------------------------------
891// SetAGC
892// ----------------------------------------------------------------------------
893
Max Morin787eeed2016-06-23 10:42:07 +0200894int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200895 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200896 CHECK_INITIALIZED();
897 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000898}
899
900// ----------------------------------------------------------------------------
901// AGC
902// ----------------------------------------------------------------------------
903
Max Morin787eeed2016-06-23 10:42:07 +0200904bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +0200905 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200906 CHECK_INITIALIZED_BOOL();
907 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +0000908}
909
910// ----------------------------------------------------------------------------
911// PlayoutIsAvailable
912// ----------------------------------------------------------------------------
913
Max Morin787eeed2016-06-23 10:42:07 +0200914int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200915 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200916 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000917
Max Morin787eeed2016-06-23 10:42:07 +0200918 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000919
Max Morin787eeed2016-06-23 10:42:07 +0200920 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
921 return -1;
922 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000923
Max Morin787eeed2016-06-23 10:42:07 +0200924 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200925 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200926 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000927}
928
929// ----------------------------------------------------------------------------
930// RecordingIsAvailable
931// ----------------------------------------------------------------------------
932
Max Morin787eeed2016-06-23 10:42:07 +0200933int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200934 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200935 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000936
Max Morin787eeed2016-06-23 10:42:07 +0200937 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000938
Max Morin787eeed2016-06-23 10:42:07 +0200939 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
940 return -1;
941 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000942
Max Morin787eeed2016-06-23 10:42:07 +0200943 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200944 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200945 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000946}
947
948// ----------------------------------------------------------------------------
949// MaxMicrophoneVolume
950// ----------------------------------------------------------------------------
951
Max Morin787eeed2016-06-23 10:42:07 +0200952int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +0200953 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000954
Max Morin787eeed2016-06-23 10:42:07 +0200955 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000956
Max Morin787eeed2016-06-23 10:42:07 +0200957 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
958 return -1;
959 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000960
Max Morin787eeed2016-06-23 10:42:07 +0200961 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200962 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000963}
964
965// ----------------------------------------------------------------------------
966// MinMicrophoneVolume
967// ----------------------------------------------------------------------------
968
Max Morin787eeed2016-06-23 10:42:07 +0200969int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
970 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000971
Max Morin787eeed2016-06-23 10:42:07 +0200972 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000973
Max Morin787eeed2016-06-23 10:42:07 +0200974 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
975 return -1;
976 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000977
Max Morin787eeed2016-06-23 10:42:07 +0200978 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200979 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000980}
981
982// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000983// PlayoutDevices
984// ----------------------------------------------------------------------------
985
Max Morin787eeed2016-06-23 10:42:07 +0200986int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +0200987 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200988 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000989
Max Morin787eeed2016-06-23 10:42:07 +0200990 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +0200991 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +0200992 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +0000993}
994
995// ----------------------------------------------------------------------------
996// SetPlayoutDevice I (II)
997// ----------------------------------------------------------------------------
998
Max Morin787eeed2016-06-23 10:42:07 +0200999int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001000 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001001 CHECK_INITIALIZED();
1002 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001003}
1004
1005// ----------------------------------------------------------------------------
1006// SetPlayoutDevice II (II)
1007// ----------------------------------------------------------------------------
1008
Max Morin787eeed2016-06-23 10:42:07 +02001009int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001010 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001011 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001012
Max Morin787eeed2016-06-23 10:42:07 +02001013 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001014}
1015
1016// ----------------------------------------------------------------------------
1017// PlayoutDeviceName
1018// ----------------------------------------------------------------------------
1019
pbos@webrtc.org25509882013-04-09 10:30:35 +00001020int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1021 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001022 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001023 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001024 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001025 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001026
Max Morin787eeed2016-06-23 10:42:07 +02001027 if (name == NULL) {
1028 _lastError = kAdmErrArgument;
1029 return -1;
1030 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001031
Max Morin787eeed2016-06-23 10:42:07 +02001032 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1033 return -1;
1034 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001035
Max Morin787eeed2016-06-23 10:42:07 +02001036 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001037 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001038 }
1039 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001040 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001041 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001042
Max Morin787eeed2016-06-23 10:42:07 +02001043 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001044}
1045
1046// ----------------------------------------------------------------------------
1047// RecordingDeviceName
1048// ----------------------------------------------------------------------------
1049
pbos@webrtc.org25509882013-04-09 10:30:35 +00001050int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1051 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001052 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001053 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001054 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001055 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001056
Max Morin787eeed2016-06-23 10:42:07 +02001057 if (name == NULL) {
1058 _lastError = kAdmErrArgument;
1059 return -1;
1060 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001061
Max Morin787eeed2016-06-23 10:42:07 +02001062 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1063 return -1;
1064 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001065
Max Morin787eeed2016-06-23 10:42:07 +02001066 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001067 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001068 }
1069 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001070 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001071 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001072
Max Morin787eeed2016-06-23 10:42:07 +02001073 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001074}
1075
1076// ----------------------------------------------------------------------------
1077// RecordingDevices
1078// ----------------------------------------------------------------------------
1079
Max Morin787eeed2016-06-23 10:42:07 +02001080int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001081 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001082 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001083
Max Morin787eeed2016-06-23 10:42:07 +02001084 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001085
Max Morin2c332bb2016-07-04 09:03:42 +02001086 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001087 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001088}
1089
1090// ----------------------------------------------------------------------------
1091// SetRecordingDevice I (II)
1092// ----------------------------------------------------------------------------
1093
Max Morin787eeed2016-06-23 10:42:07 +02001094int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001095 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001096 CHECK_INITIALIZED();
1097 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001098}
1099
1100// ----------------------------------------------------------------------------
1101// SetRecordingDevice II (II)
1102// ----------------------------------------------------------------------------
1103
Max Morin787eeed2016-06-23 10:42:07 +02001104int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001105 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001106 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001107
Max Morin787eeed2016-06-23 10:42:07 +02001108 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001109}
1110
1111// ----------------------------------------------------------------------------
1112// InitPlayout
1113// ----------------------------------------------------------------------------
1114
Max Morin787eeed2016-06-23 10:42:07 +02001115int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001116 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001117 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001118 if (PlayoutIsInitialized()) {
1119 return 0;
1120 }
Max Morin84cab202016-07-01 13:35:19 +02001121 int32_t result = _ptrAudioDevice->InitPlayout();
1122 LOG(INFO) << "output: " << result;
1123 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1124 static_cast<int>(result == 0));
1125 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001126}
1127
1128// ----------------------------------------------------------------------------
1129// InitRecording
1130// ----------------------------------------------------------------------------
1131
Max Morin787eeed2016-06-23 10:42:07 +02001132int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001133 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001134 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001135 if (RecordingIsInitialized()) {
1136 return 0;
1137 }
Max Morin84cab202016-07-01 13:35:19 +02001138 int32_t result = _ptrAudioDevice->InitRecording();
1139 LOG(INFO) << "output: " << result;
1140 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1141 static_cast<int>(result == 0));
1142 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001143}
1144
1145// ----------------------------------------------------------------------------
1146// PlayoutIsInitialized
1147// ----------------------------------------------------------------------------
1148
Max Morin787eeed2016-06-23 10:42:07 +02001149bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001150 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001151 CHECK_INITIALIZED_BOOL();
1152 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001153}
1154
1155// ----------------------------------------------------------------------------
1156// RecordingIsInitialized
1157// ----------------------------------------------------------------------------
1158
Max Morin787eeed2016-06-23 10:42:07 +02001159bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001160 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001161 CHECK_INITIALIZED_BOOL();
1162 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001163}
1164
1165// ----------------------------------------------------------------------------
1166// StartPlayout
1167// ----------------------------------------------------------------------------
1168
Max Morin787eeed2016-06-23 10:42:07 +02001169int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001170 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001171 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001172 if (Playing()) {
1173 return 0;
1174 }
henrikaba156cf2016-10-31 08:18:50 -07001175 _audioDeviceBuffer.StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001176 int32_t result = _ptrAudioDevice->StartPlayout();
1177 LOG(INFO) << "output: " << result;
1178 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1179 static_cast<int>(result == 0));
1180 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001181}
1182
1183// ----------------------------------------------------------------------------
1184// StopPlayout
1185// ----------------------------------------------------------------------------
1186
Max Morin787eeed2016-06-23 10:42:07 +02001187int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001188 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001189 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001190 int32_t result = _ptrAudioDevice->StopPlayout();
henrikaba156cf2016-10-31 08:18:50 -07001191 _audioDeviceBuffer.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001192 LOG(INFO) << "output: " << result;
1193 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1194 static_cast<int>(result == 0));
1195 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001196}
1197
1198// ----------------------------------------------------------------------------
1199// Playing
1200// ----------------------------------------------------------------------------
1201
Max Morin787eeed2016-06-23 10:42:07 +02001202bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001203 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001204 CHECK_INITIALIZED_BOOL();
1205 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001206}
1207
1208// ----------------------------------------------------------------------------
1209// StartRecording
1210// ----------------------------------------------------------------------------
1211
Max Morin787eeed2016-06-23 10:42:07 +02001212int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001213 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001214 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001215 if (Recording()) {
1216 return 0;
1217 }
henrikaba156cf2016-10-31 08:18:50 -07001218 _audioDeviceBuffer.StartRecording();
Max Morin84cab202016-07-01 13:35:19 +02001219 int32_t result = _ptrAudioDevice->StartRecording();
1220 LOG(INFO) << "output: " << result;
1221 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1222 static_cast<int>(result == 0));
1223 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001224}
1225// ----------------------------------------------------------------------------
1226// StopRecording
1227// ----------------------------------------------------------------------------
1228
Max Morin787eeed2016-06-23 10:42:07 +02001229int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001230 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001231 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001232 int32_t result = _ptrAudioDevice->StopRecording();
henrikaba156cf2016-10-31 08:18:50 -07001233 _audioDeviceBuffer.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +02001234 LOG(INFO) << "output: " << result;
1235 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1236 static_cast<int>(result == 0));
1237 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001238}
1239
1240// ----------------------------------------------------------------------------
1241// Recording
1242// ----------------------------------------------------------------------------
1243
Max Morin787eeed2016-06-23 10:42:07 +02001244bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001245 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001246 CHECK_INITIALIZED_BOOL();
1247 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001248}
1249
1250// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001251// RegisterAudioCallback
1252// ----------------------------------------------------------------------------
1253
Max Morin787eeed2016-06-23 10:42:07 +02001254int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1255 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001256 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001257 rtc::CritScope lock(&_critSectAudioCb);
henrikaf5022222016-11-07 15:56:59 +01001258 return _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001259}
1260
1261// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001262// PlayoutDelay
1263// ----------------------------------------------------------------------------
1264
Max Morin787eeed2016-06-23 10:42:07 +02001265int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001266 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001267
Max Morin787eeed2016-06-23 10:42:07 +02001268 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001269
Max Morin787eeed2016-06-23 10:42:07 +02001270 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001271 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001272 return -1;
1273 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001274
Max Morin787eeed2016-06-23 10:42:07 +02001275 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001276 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001277}
1278
1279// ----------------------------------------------------------------------------
1280// RecordingDelay
1281// ----------------------------------------------------------------------------
1282
Max Morin787eeed2016-06-23 10:42:07 +02001283int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001284 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001285 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001286
Max Morin787eeed2016-06-23 10:42:07 +02001287 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001288
Max Morin787eeed2016-06-23 10:42:07 +02001289 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001290 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001291 return -1;
1292 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001293
Max Morin787eeed2016-06-23 10:42:07 +02001294 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001295 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001296 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001297}
1298
1299// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001300// SetRecordingSampleRate
1301// ----------------------------------------------------------------------------
1302
Max Morin787eeed2016-06-23 10:42:07 +02001303int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1304 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001305 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001306 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001307
Max Morin787eeed2016-06-23 10:42:07 +02001308 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1309 return -1;
1310 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001311
Max Morin787eeed2016-06-23 10:42:07 +02001312 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001313}
1314
1315// ----------------------------------------------------------------------------
1316// RecordingSampleRate
1317// ----------------------------------------------------------------------------
1318
Max Morin787eeed2016-06-23 10:42:07 +02001319int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1320 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001321 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001322 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001323
Max Morin787eeed2016-06-23 10:42:07 +02001324 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001325
Max Morin787eeed2016-06-23 10:42:07 +02001326 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001327 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001328 return -1;
1329 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001330
Max Morin787eeed2016-06-23 10:42:07 +02001331 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001332 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001333 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001334}
1335
1336// ----------------------------------------------------------------------------
1337// SetPlayoutSampleRate
1338// ----------------------------------------------------------------------------
1339
Max Morin787eeed2016-06-23 10:42:07 +02001340int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1341 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001342 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001343 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001344
Max Morin787eeed2016-06-23 10:42:07 +02001345 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1346 return -1;
1347 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001348
Max Morin787eeed2016-06-23 10:42:07 +02001349 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001350}
1351
1352// ----------------------------------------------------------------------------
1353// PlayoutSampleRate
1354// ----------------------------------------------------------------------------
1355
Max Morin787eeed2016-06-23 10:42:07 +02001356int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1357 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001358 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001359 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001360
Max Morin787eeed2016-06-23 10:42:07 +02001361 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001362
Max Morin787eeed2016-06-23 10:42:07 +02001363 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001364 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001365 return -1;
1366 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001367
Max Morin787eeed2016-06-23 10:42:07 +02001368 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001369 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001370 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001371}
1372
1373// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001374// SetLoudspeakerStatus
1375// ----------------------------------------------------------------------------
1376
Max Morin787eeed2016-06-23 10:42:07 +02001377int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001378 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001379 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001380
Max Morin787eeed2016-06-23 10:42:07 +02001381 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1382 return -1;
1383 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001384
Max Morin787eeed2016-06-23 10:42:07 +02001385 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001386}
1387
1388// ----------------------------------------------------------------------------
1389// GetLoudspeakerStatus
1390// ----------------------------------------------------------------------------
1391
henrikac14f5ff2015-09-23 14:08:33 +02001392int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001393 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001394 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001395 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001396 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001397 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001398 }
Max Morin2c332bb2016-07-04 09:03:42 +02001399 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001400 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001401}
1402
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001403bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001404 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001405 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001406 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001407 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001408 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001409}
1410
henrikac14f5ff2015-09-23 14:08:33 +02001411int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001412 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001413 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001414 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001415 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001416 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001417}
1418
1419bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001420 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001421 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001422 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001423 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001424 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001425}
1426
1427int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001428 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001429 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001430 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001431 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001432 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001433}
1434
1435bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001436 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001437 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001438 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001439 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001440 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001441}
1442
1443int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001444 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001445 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001446 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001447 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001448 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001449}
1450
maxmorin88e31a32016-08-16 00:56:09 -07001451#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001452int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1453 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001454 LOG(INFO) << __FUNCTION__;
1455 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001456 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001457 return r;
henrikaba35d052015-07-14 17:04:08 +02001458}
1459
1460int AudioDeviceModuleImpl::GetRecordAudioParameters(
1461 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001462 LOG(INFO) << __FUNCTION__;
1463 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001464 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001465 return r;
henrikaba35d052015-07-14 17:04:08 +02001466}
maxmorin88e31a32016-08-16 00:56:09 -07001467#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001468
niklase@google.com470e71d2011-07-07 08:21:25 +00001469// ============================================================================
1470// Private Methods
1471// ============================================================================
1472
1473// ----------------------------------------------------------------------------
1474// Platform
1475// ----------------------------------------------------------------------------
1476
Max Morin787eeed2016-06-23 10:42:07 +02001477AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001478 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001479 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001480}
1481
1482// ----------------------------------------------------------------------------
1483// PlatformAudioLayer
1484// ----------------------------------------------------------------------------
1485
Max Morin787eeed2016-06-23 10:42:07 +02001486AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1487 const {
Max Morin098e6c52016-06-28 09:36:25 +02001488 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001489 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001490}
1491
1492} // namespace webrtc