blob: 5040189eebfac7de1cba8453acbde40514a1fcef [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
Max Morin84cab202016-07-01 13:35:19 +020011#include "webrtc/base/checks.h"
Max Morin098e6c52016-06-28 09:36:25 +020012#include "webrtc/base/logging.h"
henrika918b5542016-09-19 15:44:09 +020013#include "webrtc/base/checks.h"
Peter Boström1d194412016-03-21 16:44:31 +010014#include "webrtc/base/refcount.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020015#include "webrtc/base/timeutils.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000016#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
17#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020018#include "webrtc/modules/audio_device/audio_device_generic.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000019#include "webrtc/modules/audio_device/audio_device_impl.h"
Max Morin84cab202016-07-01 13:35:19 +020020#include "webrtc/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>
henrikab2619892015-05-18 16:49:16 +020031#include "webrtc/modules/audio_device/android/audio_device_template.h"
32#include "webrtc/modules/audio_device/android/audio_manager.h"
33#include "webrtc/modules/audio_device/android/audio_record_jni.h"
34#include "webrtc/modules/audio_device/android/audio_track_jni.h"
35#include "webrtc/modules/audio_device/android/opensles_player.h"
henrika918b5542016-09-19 15:44:09 +020036#include "webrtc/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)
51#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
52#endif
53
pbos@webrtc.org811269d2013-07-11 13:24:38 +000054#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000055#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010056#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000057
Max Morin787eeed2016-06-23 10:42:07 +020058#define CHECK_INITIALIZED() \
59 { \
60 if (!_initialized) { \
61 return -1; \
62 }; \
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064
Max Morin787eeed2016-06-23 10:42:07 +020065#define CHECK_INITIALIZED_BOOL() \
66 { \
67 if (!_initialized) { \
68 return false; \
69 }; \
70 }
niklase@google.com470e71d2011-07-07 08:21:25 +000071
Peter Boström1d194412016-03-21 16:44:31 +010072namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000073
niklase@google.com470e71d2011-07-07 08:21:25 +000074// ============================================================================
75// Static methods
76// ============================================================================
77
78// ----------------------------------------------------------------------------
79// AudioDeviceModule::Create()
80// ----------------------------------------------------------------------------
81
Peter Boström4adbbcf2016-05-03 15:51:26 -040082rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010083 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040084 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020085 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020086 // Create the generic ref counted (platform independent) implementation.
87 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
88 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000089
Max Morin787eeed2016-06-23 10:42:07 +020090 // Ensure that the current platform is supported.
91 if (audioDevice->CheckPlatform() == -1) {
92 return nullptr;
93 }
niklase@google.com470e71d2011-07-07 08:21:25 +000094
Max Morin787eeed2016-06-23 10:42:07 +020095 // Create the platform-dependent implementation.
96 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
97 return nullptr;
98 }
niklase@google.com470e71d2011-07-07 08:21:25 +000099
Max Morin787eeed2016-06-23 10:42:07 +0200100 // Ensure that the generic audio buffer can communicate with the
101 // platform-specific parts.
102 if (audioDevice->AttachAudioBuffer() == -1) {
103 return nullptr;
104 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
Max Morin787eeed2016-06-23 10:42:07 +0200106 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000107
Max Morin787eeed2016-06-23 10:42:07 +0200108 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
niklase@google.com470e71d2011-07-07 08:21:25 +0000111// ============================================================================
112// Construction & Destruction
113// ============================================================================
114
115// ----------------------------------------------------------------------------
116// AudioDeviceModuleImpl - ctor
117// ----------------------------------------------------------------------------
118
Max Morin787eeed2016-06-23 10:42:07 +0200119AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
120 const AudioLayer audioLayer)
121 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
122 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
123 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
124 _ptrCbAudioDeviceObserver(NULL),
125 _ptrAudioDevice(NULL),
126 _id(id),
127 _platformAudioLayer(audioLayer),
128 _lastProcessTime(rtc::TimeMillis()),
129 _platformType(kPlatformNotSupported),
130 _initialized(false),
131 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200132 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133}
134
135// ----------------------------------------------------------------------------
136// CheckPlatform
137// ----------------------------------------------------------------------------
138
Max Morin787eeed2016-06-23 10:42:07 +0200139int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200140 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
Max Morin787eeed2016-06-23 10:42:07 +0200142 // Ensure that the current platform is supported
143 //
144 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
146#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200147 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200148 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000149#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200150 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200151 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000152#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200153 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200154 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000155#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200156 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200157 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000158#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200159 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200160 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000161#endif
162
Max Morin787eeed2016-06-23 10:42:07 +0200163 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200164 LOG(LERROR) << "current platform is not supported => this module will self "
165 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200166 return -1;
167 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
Max Morin787eeed2016-06-23 10:42:07 +0200169 // Store valid output results
170 //
171 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000172
Max Morin787eeed2016-06-23 10:42:07 +0200173 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000174}
175
niklase@google.com470e71d2011-07-07 08:21:25 +0000176// ----------------------------------------------------------------------------
177// CreatePlatformSpecificObjects
178// ----------------------------------------------------------------------------
179
Max Morin787eeed2016-06-23 10:42:07 +0200180int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200181 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
Max Morin787eeed2016-06-23 10:42:07 +0200183 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
xians@google.combf5d2ba2011-08-16 07:44:19 +0000185#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200186 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200187 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000188#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200189 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
noahric6a355902016-08-17 15:19:50 -0700190 if (ptrAudioDevice) {
191 LOG(INFO) << "Will use file-playing dummy device.";
192 } else {
193 // Create a dummy device instead.
194 ptrAudioDevice = new AudioDeviceDummy(Id());
195 LOG(INFO) << "Dummy Audio APIs will be utilized";
196 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000197#else
Max Morin787eeed2016-06-23 10:42:07 +0200198 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
Max Morin787eeed2016-06-23 10:42:07 +0200200// Create the *Windows* implementation of the Audio Device
201//
niklase@google.com470e71d2011-07-07 08:21:25 +0000202#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200203 if ((audioLayer == kWindowsCoreAudio) ||
204 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200205 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000206
Max Morin787eeed2016-06-23 10:42:07 +0200207 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
208 // create *Windows Core Audio* implementation
209 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200210 LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000211 }
Max Morin787eeed2016-06-23 10:42:07 +0200212 }
213#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000215#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200216 // Create an Android audio manager.
217 _audioManagerAndroid.reset(new AudioManager());
218 // Select best possible combination of audio layers.
219 if (audioLayer == kPlatformDefaultAudio) {
henrika918b5542016-09-19 15:44:09 +0200220 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
221 _audioManagerAndroid->IsLowLatencyRecordSupported()) {
222 // Use OpenSL ES for both playout and recording.
223 audioLayer = kAndroidOpenSLESAudio;
224 } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
225 !_audioManagerAndroid->IsLowLatencyRecordSupported()) {
226 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200227 // low-latency output audio path.
228 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200229 } else {
henrika918b5542016-09-19 15:44:09 +0200230 // Use Java-based audio in both directions when low-latency output is
231 // not supported.
Max Morin787eeed2016-06-23 10:42:07 +0200232 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000233 }
Max Morin787eeed2016-06-23 10:42:07 +0200234 }
235 AudioManager* audio_manager = _audioManagerAndroid.get();
236 if (audioLayer == kAndroidJavaAudio) {
237 // Java audio for both input and output audio.
238 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
239 audioLayer, audio_manager);
henrika918b5542016-09-19 15:44:09 +0200240 } else if (audioLayer == kAndroidOpenSLESAudio) {
241 // OpenSL ES based audio for both input and output audio.
242 ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
243 audioLayer, audio_manager);
Max Morin787eeed2016-06-23 10:42:07 +0200244 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
245 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
246 // This combination provides low-latency output audio and at the same
247 // time support for HW AEC using the AudioRecord Java API.
248 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
249 audioLayer, audio_manager);
250 } else {
251 // Invalid audio layer.
henrika918b5542016-09-19 15:44:09 +0200252 ptrAudioDevice = nullptr;
Max Morin787eeed2016-06-23 10:42:07 +0200253 }
254// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
Max Morin787eeed2016-06-23 10:42:07 +0200256// Create the *Linux* implementation of the Audio Device
257//
niklase@google.com470e71d2011-07-07 08:21:25 +0000258#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200259 if ((audioLayer == kLinuxPulseAudio) ||
260 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000261#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200262 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000263
Max Morin787eeed2016-06-23 10:42:07 +0200264 // create *Linux PulseAudio* implementation
265 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200266 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200267 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200268 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200269 } else {
270 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000271#endif
272#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200273 // create *Linux ALSA Audio* implementation
274 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
275 if (ptrAudioDevice != NULL) {
276 // Pulse Audio was not supported => revert to ALSA instead
277 _platformAudioLayer =
278 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200279 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
280 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200281 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000282#endif
283#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000284 }
Max Morin787eeed2016-06-23 10:42:07 +0200285#endif
286 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000287#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200288 // create *Linux ALSA Audio* implementation
289 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200290 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000291#endif
Max Morin787eeed2016-06-23 10:42:07 +0200292 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000293#endif // #if defined(WEBRTC_LINUX)
294
Max Morin787eeed2016-06-23 10:42:07 +0200295// Create the *iPhone* implementation of the Audio Device
296//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000297#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200298 if (audioLayer == kPlatformDefaultAudio) {
299 // Create iOS Audio Device implementation.
300 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200301 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200302 }
303// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000304
Max Morin787eeed2016-06-23 10:42:07 +0200305// Create the *Mac* implementation of the Audio Device
306//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000307#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200308 if (audioLayer == kPlatformDefaultAudio) {
309 // Create *Mac Audio* implementation
310 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200311 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200312 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000313#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
Max Morin787eeed2016-06-23 10:42:07 +0200315 // Create the *Dummy* implementation of the Audio Device
316 // Available for all platforms
317 //
318 if (audioLayer == kDummyAudio) {
319 // Create *Dummy Audio* implementation
320 assert(!ptrAudioDevice);
321 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200322 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200323 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000324#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
Max Morin787eeed2016-06-23 10:42:07 +0200326 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200327 LOG(LERROR)
328 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200329 return -1;
330 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
Max Morin787eeed2016-06-23 10:42:07 +0200332 // Store valid output pointers
333 //
334 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000335
Max Morin787eeed2016-06-23 10:42:07 +0200336 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
339// ----------------------------------------------------------------------------
340// AttachAudioBuffer
341//
342// Install "bridge" between the platform implemetation and the generic
343// implementation. The "child" shall set the native sampling rate and the
344// number of channels in this function call.
345// ----------------------------------------------------------------------------
346
Max Morin787eeed2016-06-23 10:42:07 +0200347int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200348 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000349
Max Morin787eeed2016-06-23 10:42:07 +0200350 _audioDeviceBuffer.SetId(_id);
351 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
352 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000353}
354
355// ----------------------------------------------------------------------------
356// ~AudioDeviceModuleImpl - dtor
357// ----------------------------------------------------------------------------
358
Max Morin787eeed2016-06-23 10:42:07 +0200359AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200360 LOG(INFO) << __FUNCTION__;
henrika@google.com73d65512011-09-07 15:11:18 +0000361
Max Morin787eeed2016-06-23 10:42:07 +0200362 if (_ptrAudioDevice) {
363 delete _ptrAudioDevice;
364 _ptrAudioDevice = NULL;
365 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
Max Morin787eeed2016-06-23 10:42:07 +0200367 delete &_critSect;
368 delete &_critSectEventCb;
369 delete &_critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000370}
371
372// ============================================================================
373// Module
374// ============================================================================
375
376// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000377// Module::TimeUntilNextProcess
378//
379// Returns the number of milliseconds until the module want a worker thread
380// to call Process().
381// ----------------------------------------------------------------------------
382
Max Morin787eeed2016-06-23 10:42:07 +0200383int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
384 int64_t now = rtc::TimeMillis();
385 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
386 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000387}
388
389// ----------------------------------------------------------------------------
390// Module::Process
391//
392// Check for posted error and warning reports. Generate callbacks if
393// new reports exists.
394// ----------------------------------------------------------------------------
395
Max Morin787eeed2016-06-23 10:42:07 +0200396void AudioDeviceModuleImpl::Process() {
397 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000398
Max Morin787eeed2016-06-23 10:42:07 +0200399 // kPlayoutWarning
400 if (_ptrAudioDevice->PlayoutWarning()) {
401 CriticalSectionScoped lock(&_critSectEventCb);
402 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200403 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200404 _ptrCbAudioDeviceObserver->OnWarningIsReported(
405 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000406 }
Max Morin787eeed2016-06-23 10:42:07 +0200407 _ptrAudioDevice->ClearPlayoutWarning();
408 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000409
Max Morin787eeed2016-06-23 10:42:07 +0200410 // kPlayoutError
411 if (_ptrAudioDevice->PlayoutError()) {
412 CriticalSectionScoped lock(&_critSectEventCb);
413 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200414 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200415 _ptrCbAudioDeviceObserver->OnErrorIsReported(
416 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000417 }
Max Morin787eeed2016-06-23 10:42:07 +0200418 _ptrAudioDevice->ClearPlayoutError();
419 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000420
Max Morin787eeed2016-06-23 10:42:07 +0200421 // kRecordingWarning
422 if (_ptrAudioDevice->RecordingWarning()) {
423 CriticalSectionScoped lock(&_critSectEventCb);
424 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200425 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200426 _ptrCbAudioDeviceObserver->OnWarningIsReported(
427 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000428 }
Max Morin787eeed2016-06-23 10:42:07 +0200429 _ptrAudioDevice->ClearRecordingWarning();
430 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000431
Max Morin787eeed2016-06-23 10:42:07 +0200432 // kRecordingError
433 if (_ptrAudioDevice->RecordingError()) {
434 CriticalSectionScoped lock(&_critSectEventCb);
435 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200436 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200437 _ptrCbAudioDeviceObserver->OnErrorIsReported(
438 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 }
Max Morin787eeed2016-06-23 10:42:07 +0200440 _ptrAudioDevice->ClearRecordingError();
441 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000442}
443
444// ============================================================================
445// Public API
446// ============================================================================
447
448// ----------------------------------------------------------------------------
449// ActiveAudioLayer
450// ----------------------------------------------------------------------------
451
henrikab2619892015-05-18 16:49:16 +0200452int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200453 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200454 AudioLayer activeAudio;
455 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
456 return -1;
457 }
458 *audioLayer = activeAudio;
459 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000460}
461
462// ----------------------------------------------------------------------------
463// LastError
464// ----------------------------------------------------------------------------
465
Max Morin787eeed2016-06-23 10:42:07 +0200466AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200467 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200468 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000469}
470
471// ----------------------------------------------------------------------------
472// Init
473// ----------------------------------------------------------------------------
474
Max Morin787eeed2016-06-23 10:42:07 +0200475int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200476 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200477 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000478 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200479 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200480
Max Morin84cab202016-07-01 13:35:19 +0200481 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
482 RTC_HISTOGRAM_ENUMERATION(
483 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
484 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
485 if (status != AudioDeviceGeneric::InitStatus::OK) {
486 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200487 return -1;
488 }
489
490 _initialized = true;
491 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000492}
493
494// ----------------------------------------------------------------------------
495// Terminate
496// ----------------------------------------------------------------------------
497
Max Morin787eeed2016-06-23 10:42:07 +0200498int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200499 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200500 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000501 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200502
503 if (_ptrAudioDevice->Terminate() == -1) {
504 return -1;
505 }
506
507 _initialized = false;
508 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000509}
510
511// ----------------------------------------------------------------------------
512// Initialized
513// ----------------------------------------------------------------------------
514
Max Morin787eeed2016-06-23 10:42:07 +0200515bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200516 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200517 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000518}
519
520// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000521// InitSpeaker
522// ----------------------------------------------------------------------------
523
Max Morin787eeed2016-06-23 10:42:07 +0200524int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200525 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200526 CHECK_INITIALIZED();
527 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000528}
529
530// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000531// InitMicrophone
532// ----------------------------------------------------------------------------
533
Max Morin787eeed2016-06-23 10:42:07 +0200534int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200535 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200536 CHECK_INITIALIZED();
537 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000538}
539
540// ----------------------------------------------------------------------------
541// SpeakerVolumeIsAvailable
542// ----------------------------------------------------------------------------
543
Max Morin787eeed2016-06-23 10:42:07 +0200544int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200545 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200546 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000547
Max Morin787eeed2016-06-23 10:42:07 +0200548 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000549
Max Morin787eeed2016-06-23 10:42:07 +0200550 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
551 return -1;
552 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000553
Max Morin787eeed2016-06-23 10:42:07 +0200554 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200555 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200556 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000557}
558
559// ----------------------------------------------------------------------------
560// SetSpeakerVolume
561// ----------------------------------------------------------------------------
562
Max Morin787eeed2016-06-23 10:42:07 +0200563int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200564 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200565 CHECK_INITIALIZED();
566 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000567}
568
569// ----------------------------------------------------------------------------
570// SpeakerVolume
571// ----------------------------------------------------------------------------
572
Max Morin787eeed2016-06-23 10:42:07 +0200573int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200574 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200575 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000576
Max Morin787eeed2016-06-23 10:42:07 +0200577 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000578
Max Morin787eeed2016-06-23 10:42:07 +0200579 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
580 return -1;
581 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000582
Max Morin787eeed2016-06-23 10:42:07 +0200583 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200584 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200585 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000586}
587
588// ----------------------------------------------------------------------------
589// SetWaveOutVolume
590// ----------------------------------------------------------------------------
591
Max Morin787eeed2016-06-23 10:42:07 +0200592int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
593 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200594 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200595 CHECK_INITIALIZED();
596 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000597}
598
599// ----------------------------------------------------------------------------
600// WaveOutVolume
601// ----------------------------------------------------------------------------
602
Max Morin787eeed2016-06-23 10:42:07 +0200603int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
604 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200605 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200606 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000607
Max Morin787eeed2016-06-23 10:42:07 +0200608 uint16_t volLeft(0);
609 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000610
Max Morin787eeed2016-06-23 10:42:07 +0200611 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
612 return -1;
613 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000614
Max Morin787eeed2016-06-23 10:42:07 +0200615 *volumeLeft = volLeft;
616 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200617 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000618
Max Morin787eeed2016-06-23 10:42:07 +0200619 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000620}
621
622// ----------------------------------------------------------------------------
623// SpeakerIsInitialized
624// ----------------------------------------------------------------------------
625
Max Morin787eeed2016-06-23 10:42:07 +0200626bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200627 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200628 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000629
Max Morin787eeed2016-06-23 10:42:07 +0200630 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200631 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200632 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000633}
634
635// ----------------------------------------------------------------------------
636// MicrophoneIsInitialized
637// ----------------------------------------------------------------------------
638
Max Morin787eeed2016-06-23 10:42:07 +0200639bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200640 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200641 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000642
Max Morin787eeed2016-06-23 10:42:07 +0200643 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200644 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200645 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000646}
647
648// ----------------------------------------------------------------------------
649// MaxSpeakerVolume
650// ----------------------------------------------------------------------------
651
Max Morin787eeed2016-06-23 10:42:07 +0200652int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
653 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000654
Max Morin787eeed2016-06-23 10:42:07 +0200655 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000656
Max Morin787eeed2016-06-23 10:42:07 +0200657 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
658 return -1;
659 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000660
Max Morin787eeed2016-06-23 10:42:07 +0200661 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200662 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000663}
664
665// ----------------------------------------------------------------------------
666// MinSpeakerVolume
667// ----------------------------------------------------------------------------
668
Max Morin787eeed2016-06-23 10:42:07 +0200669int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
670 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000671
Max Morin787eeed2016-06-23 10:42:07 +0200672 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000673
Max Morin787eeed2016-06-23 10:42:07 +0200674 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
675 return -1;
676 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000677
Max Morin787eeed2016-06-23 10:42:07 +0200678 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200679 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000680}
681
682// ----------------------------------------------------------------------------
683// SpeakerVolumeStepSize
684// ----------------------------------------------------------------------------
685
Max Morin787eeed2016-06-23 10:42:07 +0200686int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200687 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200688 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000689
Max Morin787eeed2016-06-23 10:42:07 +0200690 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000691
Max Morin787eeed2016-06-23 10:42:07 +0200692 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200693 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200694 return -1;
695 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000696
Max Morin787eeed2016-06-23 10:42:07 +0200697 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200698 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200699 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000700}
701
702// ----------------------------------------------------------------------------
703// SpeakerMuteIsAvailable
704// ----------------------------------------------------------------------------
705
Max Morin787eeed2016-06-23 10:42:07 +0200706int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200707 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200708 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000709
Max Morin787eeed2016-06-23 10:42:07 +0200710 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000711
Max Morin787eeed2016-06-23 10:42:07 +0200712 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
713 return -1;
714 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000715
Max Morin787eeed2016-06-23 10:42:07 +0200716 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200717 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200718 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000719}
720
721// ----------------------------------------------------------------------------
722// SetSpeakerMute
723// ----------------------------------------------------------------------------
724
Max Morin787eeed2016-06-23 10:42:07 +0200725int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200726 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200727 CHECK_INITIALIZED();
728 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000729}
730
731// ----------------------------------------------------------------------------
732// SpeakerMute
733// ----------------------------------------------------------------------------
734
Max Morin787eeed2016-06-23 10:42:07 +0200735int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200736 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200737 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000738
Max Morin787eeed2016-06-23 10:42:07 +0200739 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000740
Max Morin787eeed2016-06-23 10:42:07 +0200741 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
742 return -1;
743 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000744
Max Morin787eeed2016-06-23 10:42:07 +0200745 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200746 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200747 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000748}
749
750// ----------------------------------------------------------------------------
751// MicrophoneMuteIsAvailable
752// ----------------------------------------------------------------------------
753
Max Morin787eeed2016-06-23 10:42:07 +0200754int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200755 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200756 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000757
Max Morin787eeed2016-06-23 10:42:07 +0200758 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000759
Max Morin787eeed2016-06-23 10:42:07 +0200760 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
761 return -1;
762 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000763
Max Morin787eeed2016-06-23 10:42:07 +0200764 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200765 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200766 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000767}
768
769// ----------------------------------------------------------------------------
770// SetMicrophoneMute
771// ----------------------------------------------------------------------------
772
Max Morin787eeed2016-06-23 10:42:07 +0200773int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200774 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200775 CHECK_INITIALIZED();
776 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000777}
778
779// ----------------------------------------------------------------------------
780// MicrophoneMute
781// ----------------------------------------------------------------------------
782
Max Morin787eeed2016-06-23 10:42:07 +0200783int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200784 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200785 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000786
Max Morin787eeed2016-06-23 10:42:07 +0200787 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000788
Max Morin787eeed2016-06-23 10:42:07 +0200789 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
790 return -1;
791 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000792
Max Morin787eeed2016-06-23 10:42:07 +0200793 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200794 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200795 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000796}
797
798// ----------------------------------------------------------------------------
799// MicrophoneBoostIsAvailable
800// ----------------------------------------------------------------------------
801
Max Morin787eeed2016-06-23 10:42:07 +0200802int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200803 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200804 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000805
Max Morin787eeed2016-06-23 10:42:07 +0200806 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000807
Max Morin787eeed2016-06-23 10:42:07 +0200808 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
809 return -1;
810 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000811
Max Morin787eeed2016-06-23 10:42:07 +0200812 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200813 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200814 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000815}
816
817// ----------------------------------------------------------------------------
818// SetMicrophoneBoost
819// ----------------------------------------------------------------------------
820
Max Morin787eeed2016-06-23 10:42:07 +0200821int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200822 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200823 CHECK_INITIALIZED();
824 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000825}
826
827// ----------------------------------------------------------------------------
828// MicrophoneBoost
829// ----------------------------------------------------------------------------
830
Max Morin787eeed2016-06-23 10:42:07 +0200831int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200832 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200833 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000834
Max Morin787eeed2016-06-23 10:42:07 +0200835 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000836
Max Morin787eeed2016-06-23 10:42:07 +0200837 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
838 return -1;
839 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000840
Max Morin787eeed2016-06-23 10:42:07 +0200841 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200842 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200843 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000844}
845
846// ----------------------------------------------------------------------------
847// MicrophoneVolumeIsAvailable
848// ----------------------------------------------------------------------------
849
Max Morin787eeed2016-06-23 10:42:07 +0200850int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200851 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200852 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000853
Max Morin787eeed2016-06-23 10:42:07 +0200854 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000855
Max Morin787eeed2016-06-23 10:42:07 +0200856 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
857 return -1;
858 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000859
Max Morin787eeed2016-06-23 10:42:07 +0200860 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200861 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200862 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000863}
864
865// ----------------------------------------------------------------------------
866// SetMicrophoneVolume
867// ----------------------------------------------------------------------------
868
Max Morin787eeed2016-06-23 10:42:07 +0200869int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200870 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200871 CHECK_INITIALIZED();
872 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000873}
874
875// ----------------------------------------------------------------------------
876// MicrophoneVolume
877// ----------------------------------------------------------------------------
878
Max Morin787eeed2016-06-23 10:42:07 +0200879int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200880 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200881 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000882
Max Morin787eeed2016-06-23 10:42:07 +0200883 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000884
Max Morin787eeed2016-06-23 10:42:07 +0200885 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
886 return -1;
887 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000888
Max Morin787eeed2016-06-23 10:42:07 +0200889 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200890 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200891 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000892}
893
894// ----------------------------------------------------------------------------
895// StereoRecordingIsAvailable
896// ----------------------------------------------------------------------------
897
Max Morin787eeed2016-06-23 10:42:07 +0200898int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
899 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200900 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200901 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000902
Max Morin787eeed2016-06-23 10:42:07 +0200903 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000904
Max Morin787eeed2016-06-23 10:42:07 +0200905 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
906 return -1;
907 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000908
Max Morin787eeed2016-06-23 10:42:07 +0200909 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200910 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200911 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000912}
913
914// ----------------------------------------------------------------------------
915// SetStereoRecording
916// ----------------------------------------------------------------------------
917
Max Morin787eeed2016-06-23 10:42:07 +0200918int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200919 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200920 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000921
Max Morin787eeed2016-06-23 10:42:07 +0200922 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200923 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200924 return -1;
925 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000926
Max Morin787eeed2016-06-23 10:42:07 +0200927 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200928 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200929 return -1;
930 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000931
Max Morin787eeed2016-06-23 10:42:07 +0200932 int8_t nChannels(1);
933 if (enable) {
934 nChannels = 2;
935 }
936 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000937
Max Morin787eeed2016-06-23 10:42:07 +0200938 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000939}
940
941// ----------------------------------------------------------------------------
942// StereoRecording
943// ----------------------------------------------------------------------------
944
Max Morin787eeed2016-06-23 10:42:07 +0200945int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200946 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200947 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000948
Max Morin787eeed2016-06-23 10:42:07 +0200949 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000950
Max Morin787eeed2016-06-23 10:42:07 +0200951 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
952 return -1;
953 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000954
Max Morin787eeed2016-06-23 10:42:07 +0200955 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200956 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200957 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000958}
959
960// ----------------------------------------------------------------------------
961// SetRecordingChannel
962// ----------------------------------------------------------------------------
963
Max Morin787eeed2016-06-23 10:42:07 +0200964int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
965 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200966 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200967 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200968 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200969 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200970 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200971 }
972 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000973
Max Morin787eeed2016-06-23 10:42:07 +0200974 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000975
Max Morin787eeed2016-06-23 10:42:07 +0200976 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200977 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200978 return -1;
979 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000980
Max Morin787eeed2016-06-23 10:42:07 +0200981 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000982}
983
984// ----------------------------------------------------------------------------
985// RecordingChannel
986// ----------------------------------------------------------------------------
987
Max Morin787eeed2016-06-23 10:42:07 +0200988int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200989 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200990 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000991
Max Morin787eeed2016-06-23 10:42:07 +0200992 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000993
Max Morin787eeed2016-06-23 10:42:07 +0200994 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
995 return -1;
996 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000997
Max Morin787eeed2016-06-23 10:42:07 +0200998 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200999 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +02001000 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001001 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +02001002 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001003 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001004 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001005 }
Max Morin787eeed2016-06-23 10:42:07 +02001006 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001007}
1008
1009// ----------------------------------------------------------------------------
1010// StereoPlayoutIsAvailable
1011// ----------------------------------------------------------------------------
1012
Max Morin787eeed2016-06-23 10:42:07 +02001013int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001014 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001015 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001016
Max Morin787eeed2016-06-23 10:42:07 +02001017 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001018
Max Morin787eeed2016-06-23 10:42:07 +02001019 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1020 return -1;
1021 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001022
Max Morin787eeed2016-06-23 10:42:07 +02001023 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001024 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001025 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001026}
1027
1028// ----------------------------------------------------------------------------
1029// SetStereoPlayout
1030// ----------------------------------------------------------------------------
1031
Max Morin787eeed2016-06-23 10:42:07 +02001032int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001033 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001034 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001035
Max Morin787eeed2016-06-23 10:42:07 +02001036 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001037 LOG(LERROR)
1038 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001039 return -1;
1040 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001041
Max Morin787eeed2016-06-23 10:42:07 +02001042 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001043 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001044 return -1;
1045 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001046
Max Morin787eeed2016-06-23 10:42:07 +02001047 int8_t nChannels(1);
1048 if (enable) {
1049 nChannels = 2;
1050 }
1051 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001052
Max Morin787eeed2016-06-23 10:42:07 +02001053 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001054}
1055
1056// ----------------------------------------------------------------------------
1057// StereoPlayout
1058// ----------------------------------------------------------------------------
1059
Max Morin787eeed2016-06-23 10:42:07 +02001060int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001061 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001062 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001063
Max Morin787eeed2016-06-23 10:42:07 +02001064 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001065
Max Morin787eeed2016-06-23 10:42:07 +02001066 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1067 return -1;
1068 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001069
Max Morin787eeed2016-06-23 10:42:07 +02001070 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001071 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001072 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001073}
1074
1075// ----------------------------------------------------------------------------
1076// SetAGC
1077// ----------------------------------------------------------------------------
1078
Max Morin787eeed2016-06-23 10:42:07 +02001079int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001080 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001081 CHECK_INITIALIZED();
1082 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001083}
1084
1085// ----------------------------------------------------------------------------
1086// AGC
1087// ----------------------------------------------------------------------------
1088
Max Morin787eeed2016-06-23 10:42:07 +02001089bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001090 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001091 CHECK_INITIALIZED_BOOL();
1092 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001093}
1094
1095// ----------------------------------------------------------------------------
1096// PlayoutIsAvailable
1097// ----------------------------------------------------------------------------
1098
Max Morin787eeed2016-06-23 10:42:07 +02001099int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001100 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001101 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001102
Max Morin787eeed2016-06-23 10:42:07 +02001103 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001104
Max Morin787eeed2016-06-23 10:42:07 +02001105 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1106 return -1;
1107 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001108
Max Morin787eeed2016-06-23 10:42:07 +02001109 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001110 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001111 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001112}
1113
1114// ----------------------------------------------------------------------------
1115// RecordingIsAvailable
1116// ----------------------------------------------------------------------------
1117
Max Morin787eeed2016-06-23 10:42:07 +02001118int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001119 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001120 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001121
Max Morin787eeed2016-06-23 10:42:07 +02001122 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001123
Max Morin787eeed2016-06-23 10:42:07 +02001124 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1125 return -1;
1126 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001127
Max Morin787eeed2016-06-23 10:42:07 +02001128 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001129 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001130 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001131}
1132
1133// ----------------------------------------------------------------------------
1134// MaxMicrophoneVolume
1135// ----------------------------------------------------------------------------
1136
Max Morin787eeed2016-06-23 10:42:07 +02001137int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001138 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001139
Max Morin787eeed2016-06-23 10:42:07 +02001140 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001141
Max Morin787eeed2016-06-23 10:42:07 +02001142 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1143 return -1;
1144 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001145
Max Morin787eeed2016-06-23 10:42:07 +02001146 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001147 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001148}
1149
1150// ----------------------------------------------------------------------------
1151// MinMicrophoneVolume
1152// ----------------------------------------------------------------------------
1153
Max Morin787eeed2016-06-23 10:42:07 +02001154int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1155 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001156
Max Morin787eeed2016-06-23 10:42:07 +02001157 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001158
Max Morin787eeed2016-06-23 10:42:07 +02001159 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1160 return -1;
1161 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001162
Max Morin787eeed2016-06-23 10:42:07 +02001163 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001164 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001165}
1166
1167// ----------------------------------------------------------------------------
1168// MicrophoneVolumeStepSize
1169// ----------------------------------------------------------------------------
1170
Max Morin787eeed2016-06-23 10:42:07 +02001171int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1172 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001173 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001174 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001175
Max Morin787eeed2016-06-23 10:42:07 +02001176 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001177
Max Morin787eeed2016-06-23 10:42:07 +02001178 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1179 return -1;
1180 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001181
Max Morin787eeed2016-06-23 10:42:07 +02001182 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001183 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001184 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001185}
1186
1187// ----------------------------------------------------------------------------
1188// PlayoutDevices
1189// ----------------------------------------------------------------------------
1190
Max Morin787eeed2016-06-23 10:42:07 +02001191int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001192 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001193 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001194
Max Morin787eeed2016-06-23 10:42:07 +02001195 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001196 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001197 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001198}
1199
1200// ----------------------------------------------------------------------------
1201// SetPlayoutDevice I (II)
1202// ----------------------------------------------------------------------------
1203
Max Morin787eeed2016-06-23 10:42:07 +02001204int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001205 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001206 CHECK_INITIALIZED();
1207 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001208}
1209
1210// ----------------------------------------------------------------------------
1211// SetPlayoutDevice II (II)
1212// ----------------------------------------------------------------------------
1213
Max Morin787eeed2016-06-23 10:42:07 +02001214int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001215 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001216 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001217
Max Morin787eeed2016-06-23 10:42:07 +02001218 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001219}
1220
1221// ----------------------------------------------------------------------------
1222// PlayoutDeviceName
1223// ----------------------------------------------------------------------------
1224
pbos@webrtc.org25509882013-04-09 10:30:35 +00001225int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1226 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001227 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001228 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001229 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001230 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001231
Max Morin787eeed2016-06-23 10:42:07 +02001232 if (name == NULL) {
1233 _lastError = kAdmErrArgument;
1234 return -1;
1235 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001236
Max Morin787eeed2016-06-23 10:42:07 +02001237 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1238 return -1;
1239 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001240
Max Morin787eeed2016-06-23 10:42:07 +02001241 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001242 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001243 }
1244 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001245 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001246 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001247
Max Morin787eeed2016-06-23 10:42:07 +02001248 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001249}
1250
1251// ----------------------------------------------------------------------------
1252// RecordingDeviceName
1253// ----------------------------------------------------------------------------
1254
pbos@webrtc.org25509882013-04-09 10:30:35 +00001255int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1256 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001257 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001258 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001259 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001260 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001261
Max Morin787eeed2016-06-23 10:42:07 +02001262 if (name == NULL) {
1263 _lastError = kAdmErrArgument;
1264 return -1;
1265 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001266
Max Morin787eeed2016-06-23 10:42:07 +02001267 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1268 return -1;
1269 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001270
Max Morin787eeed2016-06-23 10:42:07 +02001271 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001272 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001273 }
1274 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001275 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001276 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001277
Max Morin787eeed2016-06-23 10:42:07 +02001278 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001279}
1280
1281// ----------------------------------------------------------------------------
1282// RecordingDevices
1283// ----------------------------------------------------------------------------
1284
Max Morin787eeed2016-06-23 10:42:07 +02001285int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001286 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001287 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001288
Max Morin787eeed2016-06-23 10:42:07 +02001289 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001290
Max Morin2c332bb2016-07-04 09:03:42 +02001291 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001292 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001293}
1294
1295// ----------------------------------------------------------------------------
1296// SetRecordingDevice I (II)
1297// ----------------------------------------------------------------------------
1298
Max Morin787eeed2016-06-23 10:42:07 +02001299int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001300 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001301 CHECK_INITIALIZED();
1302 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001303}
1304
1305// ----------------------------------------------------------------------------
1306// SetRecordingDevice II (II)
1307// ----------------------------------------------------------------------------
1308
Max Morin787eeed2016-06-23 10:42:07 +02001309int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001310 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001311 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001312
Max Morin787eeed2016-06-23 10:42:07 +02001313 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001314}
1315
1316// ----------------------------------------------------------------------------
1317// InitPlayout
1318// ----------------------------------------------------------------------------
1319
Max Morin787eeed2016-06-23 10:42:07 +02001320int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001321 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001322 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001323 if (PlayoutIsInitialized()) {
1324 return 0;
1325 }
Max Morin84cab202016-07-01 13:35:19 +02001326 int32_t result = _ptrAudioDevice->InitPlayout();
1327 LOG(INFO) << "output: " << result;
1328 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1329 static_cast<int>(result == 0));
1330 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001331}
1332
1333// ----------------------------------------------------------------------------
1334// InitRecording
1335// ----------------------------------------------------------------------------
1336
Max Morin787eeed2016-06-23 10:42:07 +02001337int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001338 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001339 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001340 if (RecordingIsInitialized()) {
1341 return 0;
1342 }
Max Morin84cab202016-07-01 13:35:19 +02001343 int32_t result = _ptrAudioDevice->InitRecording();
1344 LOG(INFO) << "output: " << result;
1345 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1346 static_cast<int>(result == 0));
1347 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001348}
1349
1350// ----------------------------------------------------------------------------
1351// PlayoutIsInitialized
1352// ----------------------------------------------------------------------------
1353
Max Morin787eeed2016-06-23 10:42:07 +02001354bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001355 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001356 CHECK_INITIALIZED_BOOL();
1357 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001358}
1359
1360// ----------------------------------------------------------------------------
1361// RecordingIsInitialized
1362// ----------------------------------------------------------------------------
1363
Max Morin787eeed2016-06-23 10:42:07 +02001364bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001365 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001366 CHECK_INITIALIZED_BOOL();
1367 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001368}
1369
1370// ----------------------------------------------------------------------------
1371// StartPlayout
1372// ----------------------------------------------------------------------------
1373
Max Morin787eeed2016-06-23 10:42:07 +02001374int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001375 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001376 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001377 if (Playing()) {
1378 return 0;
1379 }
henrikaba156cf2016-10-31 08:18:50 -07001380 _audioDeviceBuffer.StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001381 int32_t result = _ptrAudioDevice->StartPlayout();
1382 LOG(INFO) << "output: " << result;
1383 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1384 static_cast<int>(result == 0));
1385 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001386}
1387
1388// ----------------------------------------------------------------------------
1389// StopPlayout
1390// ----------------------------------------------------------------------------
1391
Max Morin787eeed2016-06-23 10:42:07 +02001392int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001393 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001394 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001395 int32_t result = _ptrAudioDevice->StopPlayout();
henrikaba156cf2016-10-31 08:18:50 -07001396 _audioDeviceBuffer.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001397 LOG(INFO) << "output: " << result;
1398 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1399 static_cast<int>(result == 0));
1400 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001401}
1402
1403// ----------------------------------------------------------------------------
1404// Playing
1405// ----------------------------------------------------------------------------
1406
Max Morin787eeed2016-06-23 10:42:07 +02001407bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001408 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001409 CHECK_INITIALIZED_BOOL();
1410 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001411}
1412
1413// ----------------------------------------------------------------------------
1414// StartRecording
1415// ----------------------------------------------------------------------------
1416
Max Morin787eeed2016-06-23 10:42:07 +02001417int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001418 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001419 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001420 if (Recording()) {
1421 return 0;
1422 }
henrikaba156cf2016-10-31 08:18:50 -07001423 _audioDeviceBuffer.StartRecording();
Max Morin84cab202016-07-01 13:35:19 +02001424 int32_t result = _ptrAudioDevice->StartRecording();
1425 LOG(INFO) << "output: " << result;
1426 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1427 static_cast<int>(result == 0));
1428 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001429}
1430// ----------------------------------------------------------------------------
1431// StopRecording
1432// ----------------------------------------------------------------------------
1433
Max Morin787eeed2016-06-23 10:42:07 +02001434int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001435 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001436 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001437 int32_t result = _ptrAudioDevice->StopRecording();
henrikaba156cf2016-10-31 08:18:50 -07001438 _audioDeviceBuffer.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +02001439 LOG(INFO) << "output: " << result;
1440 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1441 static_cast<int>(result == 0));
1442 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001443}
1444
1445// ----------------------------------------------------------------------------
1446// Recording
1447// ----------------------------------------------------------------------------
1448
Max Morin787eeed2016-06-23 10:42:07 +02001449bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001450 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001451 CHECK_INITIALIZED_BOOL();
1452 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001453}
1454
1455// ----------------------------------------------------------------------------
1456// RegisterEventObserver
1457// ----------------------------------------------------------------------------
1458
Max Morin787eeed2016-06-23 10:42:07 +02001459int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1460 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001461 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001462 CriticalSectionScoped lock(&_critSectEventCb);
1463 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001464
Max Morin787eeed2016-06-23 10:42:07 +02001465 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001466}
1467
1468// ----------------------------------------------------------------------------
1469// RegisterAudioCallback
1470// ----------------------------------------------------------------------------
1471
Max Morin787eeed2016-06-23 10:42:07 +02001472int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1473 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001474 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001475 CriticalSectionScoped lock(&_critSectAudioCb);
henrikaf5022222016-11-07 15:56:59 +01001476 return _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001477}
1478
1479// ----------------------------------------------------------------------------
1480// StartRawInputFileRecording
1481// ----------------------------------------------------------------------------
1482
pbos@webrtc.org25509882013-04-09 10:30:35 +00001483int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001484 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001485 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001486 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001487
Max Morin787eeed2016-06-23 10:42:07 +02001488 if (NULL == pcmFileNameUTF8) {
1489 return -1;
1490 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001491
Max Morin787eeed2016-06-23 10:42:07 +02001492 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001493}
1494
1495// ----------------------------------------------------------------------------
1496// StopRawInputFileRecording
1497// ----------------------------------------------------------------------------
1498
Max Morin787eeed2016-06-23 10:42:07 +02001499int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001500 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001501 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001502
Max Morin787eeed2016-06-23 10:42:07 +02001503 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001504}
1505
1506// ----------------------------------------------------------------------------
1507// StartRawOutputFileRecording
1508// ----------------------------------------------------------------------------
1509
pbos@webrtc.org25509882013-04-09 10:30:35 +00001510int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001511 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001512 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001513 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001514
Max Morin787eeed2016-06-23 10:42:07 +02001515 if (NULL == pcmFileNameUTF8) {
1516 return -1;
1517 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001518
Max Morin787eeed2016-06-23 10:42:07 +02001519 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001520}
1521
1522// ----------------------------------------------------------------------------
1523// StopRawOutputFileRecording
1524// ----------------------------------------------------------------------------
1525
Max Morin787eeed2016-06-23 10:42:07 +02001526int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001527 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001528 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001529
Max Morin787eeed2016-06-23 10:42:07 +02001530 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001531}
1532
1533// ----------------------------------------------------------------------------
1534// SetPlayoutBuffer
1535// ----------------------------------------------------------------------------
1536
Max Morin787eeed2016-06-23 10:42:07 +02001537int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1538 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001539 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001540 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001541 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001542 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001543 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001544 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001545 }
Max Morin787eeed2016-06-23 10:42:07 +02001546 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001547
Max Morin787eeed2016-06-23 10:42:07 +02001548 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001549 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1550 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001551 return -1;
1552 }
1553
1554 int32_t ret(0);
1555
1556 if (kFixedBufferSize == type) {
1557 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1558 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001559 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001560 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001561 }
Max Morin787eeed2016-06-23 10:42:07 +02001562 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001563
Max Morin787eeed2016-06-23 10:42:07 +02001564 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001565 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1566 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001567 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001568
Max Morin787eeed2016-06-23 10:42:07 +02001569 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001570}
1571
1572// ----------------------------------------------------------------------------
1573// PlayoutBuffer
1574// ----------------------------------------------------------------------------
1575
Max Morin787eeed2016-06-23 10:42:07 +02001576int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1577 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001578 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001579 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001580
Max Morin787eeed2016-06-23 10:42:07 +02001581 BufferType bufType;
1582 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001583
Max Morin787eeed2016-06-23 10:42:07 +02001584 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001585 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001586 return -1;
1587 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001588
Max Morin787eeed2016-06-23 10:42:07 +02001589 *type = bufType;
1590 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001591
Max Morin2c332bb2016-07-04 09:03:42 +02001592 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001593 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001594}
1595
1596// ----------------------------------------------------------------------------
1597// PlayoutDelay
1598// ----------------------------------------------------------------------------
1599
Max Morin787eeed2016-06-23 10:42:07 +02001600int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001601 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001602
Max Morin787eeed2016-06-23 10:42:07 +02001603 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001604
Max Morin787eeed2016-06-23 10:42:07 +02001605 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001606 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001607 return -1;
1608 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001609
Max Morin787eeed2016-06-23 10:42:07 +02001610 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001611 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001612}
1613
1614// ----------------------------------------------------------------------------
1615// RecordingDelay
1616// ----------------------------------------------------------------------------
1617
Max Morin787eeed2016-06-23 10:42:07 +02001618int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001619 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001620 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001621
Max Morin787eeed2016-06-23 10:42:07 +02001622 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001623
Max Morin787eeed2016-06-23 10:42:07 +02001624 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001625 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001626 return -1;
1627 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001628
Max Morin787eeed2016-06-23 10:42:07 +02001629 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001630 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001631 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001632}
1633
1634// ----------------------------------------------------------------------------
1635// CPULoad
1636// ----------------------------------------------------------------------------
1637
Max Morin787eeed2016-06-23 10:42:07 +02001638int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001639 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001640 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001641
Max Morin787eeed2016-06-23 10:42:07 +02001642 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001643
Max Morin787eeed2016-06-23 10:42:07 +02001644 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001645 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001646 return -1;
1647 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001648
Max Morin787eeed2016-06-23 10:42:07 +02001649 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001650 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001651 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001652}
1653
1654// ----------------------------------------------------------------------------
1655// SetRecordingSampleRate
1656// ----------------------------------------------------------------------------
1657
Max Morin787eeed2016-06-23 10:42:07 +02001658int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1659 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001660 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001661 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001662
Max Morin787eeed2016-06-23 10:42:07 +02001663 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1664 return -1;
1665 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001666
Max Morin787eeed2016-06-23 10:42:07 +02001667 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001668}
1669
1670// ----------------------------------------------------------------------------
1671// RecordingSampleRate
1672// ----------------------------------------------------------------------------
1673
Max Morin787eeed2016-06-23 10:42:07 +02001674int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1675 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001676 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001677 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001678
Max Morin787eeed2016-06-23 10:42:07 +02001679 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001680
Max Morin787eeed2016-06-23 10:42:07 +02001681 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001682 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001683 return -1;
1684 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001685
Max Morin787eeed2016-06-23 10:42:07 +02001686 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001687 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001688 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001689}
1690
1691// ----------------------------------------------------------------------------
1692// SetPlayoutSampleRate
1693// ----------------------------------------------------------------------------
1694
Max Morin787eeed2016-06-23 10:42:07 +02001695int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1696 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001697 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001698 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001699
Max Morin787eeed2016-06-23 10:42:07 +02001700 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1701 return -1;
1702 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001703
Max Morin787eeed2016-06-23 10:42:07 +02001704 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001705}
1706
1707// ----------------------------------------------------------------------------
1708// PlayoutSampleRate
1709// ----------------------------------------------------------------------------
1710
Max Morin787eeed2016-06-23 10:42:07 +02001711int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1712 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001713 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001714 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001715
Max Morin787eeed2016-06-23 10:42:07 +02001716 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001717
Max Morin787eeed2016-06-23 10:42:07 +02001718 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001719 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001720 return -1;
1721 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001722
Max Morin787eeed2016-06-23 10:42:07 +02001723 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001724 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001725 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001726}
1727
1728// ----------------------------------------------------------------------------
1729// ResetAudioDevice
1730// ----------------------------------------------------------------------------
1731
Max Morin787eeed2016-06-23 10:42:07 +02001732int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001733 LOG(INFO) << __FUNCTION__;
henrikaf5022222016-11-07 15:56:59 +01001734 FATAL() << "Should never be called";
1735 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001736}
1737
1738// ----------------------------------------------------------------------------
1739// SetLoudspeakerStatus
1740// ----------------------------------------------------------------------------
1741
Max Morin787eeed2016-06-23 10:42:07 +02001742int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001743 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001744 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001745
Max Morin787eeed2016-06-23 10:42:07 +02001746 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1747 return -1;
1748 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001749
Max Morin787eeed2016-06-23 10:42:07 +02001750 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001751}
1752
1753// ----------------------------------------------------------------------------
1754// GetLoudspeakerStatus
1755// ----------------------------------------------------------------------------
1756
henrikac14f5ff2015-09-23 14:08:33 +02001757int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001758 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001759 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001760 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001761 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001762 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001763 }
Max Morin2c332bb2016-07-04 09:03:42 +02001764 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001765 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001766}
1767
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001768bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001769 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001770 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001771 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001772 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001773 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001774}
1775
henrikac14f5ff2015-09-23 14:08:33 +02001776int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001777 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001778 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001779 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001780 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001781 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001782}
1783
1784bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001785 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001786 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001787 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001788 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001789 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001790}
1791
1792int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001793 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001794 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001795 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001796 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001797 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001798}
1799
1800bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001801 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001802 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001803 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001804 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001805 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001806}
1807
1808int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001809 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001810 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001811 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001812 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001813 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001814}
1815
maxmorin88e31a32016-08-16 00:56:09 -07001816#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001817int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1818 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001819 LOG(INFO) << __FUNCTION__;
1820 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001821 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001822 return r;
henrikaba35d052015-07-14 17:04:08 +02001823}
1824
1825int AudioDeviceModuleImpl::GetRecordAudioParameters(
1826 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001827 LOG(INFO) << __FUNCTION__;
1828 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001829 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001830 return r;
henrikaba35d052015-07-14 17:04:08 +02001831}
maxmorin88e31a32016-08-16 00:56:09 -07001832#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001833
niklase@google.com470e71d2011-07-07 08:21:25 +00001834// ============================================================================
1835// Private Methods
1836// ============================================================================
1837
1838// ----------------------------------------------------------------------------
1839// Platform
1840// ----------------------------------------------------------------------------
1841
Max Morin787eeed2016-06-23 10:42:07 +02001842AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001843 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001844 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001845}
1846
1847// ----------------------------------------------------------------------------
1848// PlatformAudioLayer
1849// ----------------------------------------------------------------------------
1850
Max Morin787eeed2016-06-23 10:42:07 +02001851AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1852 const {
Max Morin098e6c52016-06-28 09:36:25 +02001853 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001854 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001855}
1856
1857} // namespace webrtc