blob: 9f141675bce96d6168e2bbfef14e76fd1cefd65e [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"
Peter Boström1d194412016-03-21 16:44:31 +010013#include "webrtc/base/refcount.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020014#include "webrtc/base/timeutils.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000015#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
16#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020017#include "webrtc/modules/audio_device/audio_device_generic.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000018#include "webrtc/modules/audio_device/audio_device_impl.h"
Max Morin84cab202016-07-01 13:35:19 +020019#include "webrtc/system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000021#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000022#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020025#include "audio_device_wave_win.h"
26#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"
niklase@google.com470e71d2011-07-07 08:21:25 +000036#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020037#if defined(LINUX_ALSA)
38#include "audio_device_alsa_linux.h"
39#endif
Tommi68898a22015-05-19 17:28:07 +020040#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020042#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000043#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020044#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000045#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020046#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000047#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000048
49#if defined(WEBRTC_DUMMY_FILE_DEVICES)
50#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
51#endif
52
pbos@webrtc.org811269d2013-07-11 13:24:38 +000053#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000054#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010055#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000056
Max Morin787eeed2016-06-23 10:42:07 +020057#define CHECK_INITIALIZED() \
58 { \
59 if (!_initialized) { \
60 return -1; \
61 }; \
62 }
niklase@google.com470e71d2011-07-07 08:21:25 +000063
Max Morin787eeed2016-06-23 10:42:07 +020064#define CHECK_INITIALIZED_BOOL() \
65 { \
66 if (!_initialized) { \
67 return false; \
68 }; \
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070
Peter Boström1d194412016-03-21 16:44:31 +010071namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000072
niklase@google.com470e71d2011-07-07 08:21:25 +000073// ============================================================================
74// Static methods
75// ============================================================================
76
77// ----------------------------------------------------------------------------
78// AudioDeviceModule::Create()
79// ----------------------------------------------------------------------------
80
Peter Boström4adbbcf2016-05-03 15:51:26 -040081rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010082 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040083 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020084 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020085 // Create the generic ref counted (platform independent) implementation.
86 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
87 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000088
Max Morin787eeed2016-06-23 10:42:07 +020089 // Ensure that the current platform is supported.
90 if (audioDevice->CheckPlatform() == -1) {
91 return nullptr;
92 }
niklase@google.com470e71d2011-07-07 08:21:25 +000093
Max Morin787eeed2016-06-23 10:42:07 +020094 // Create the platform-dependent implementation.
95 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
96 return nullptr;
97 }
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Max Morin787eeed2016-06-23 10:42:07 +020099 // Ensure that the generic audio buffer can communicate with the
100 // platform-specific parts.
101 if (audioDevice->AttachAudioBuffer() == -1) {
102 return nullptr;
103 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
Max Morin787eeed2016-06-23 10:42:07 +0200105 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000106
Max Morin787eeed2016-06-23 10:42:07 +0200107 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
niklase@google.com470e71d2011-07-07 08:21:25 +0000110// ============================================================================
111// Construction & Destruction
112// ============================================================================
113
114// ----------------------------------------------------------------------------
115// AudioDeviceModuleImpl - ctor
116// ----------------------------------------------------------------------------
117
Max Morin787eeed2016-06-23 10:42:07 +0200118AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
119 const AudioLayer audioLayer)
120 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
121 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
122 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
123 _ptrCbAudioDeviceObserver(NULL),
124 _ptrAudioDevice(NULL),
125 _id(id),
126 _platformAudioLayer(audioLayer),
127 _lastProcessTime(rtc::TimeMillis()),
128 _platformType(kPlatformNotSupported),
129 _initialized(false),
130 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200131 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132}
133
134// ----------------------------------------------------------------------------
135// CheckPlatform
136// ----------------------------------------------------------------------------
137
Max Morin787eeed2016-06-23 10:42:07 +0200138int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200139 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
Max Morin787eeed2016-06-23 10:42:07 +0200141 // Ensure that the current platform is supported
142 //
143 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
145#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200146 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200147 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000148#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200149 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200150 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000151#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200152 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200153 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000154#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200155 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200156 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000157#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200158 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200159 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000160#endif
161
Max Morin787eeed2016-06-23 10:42:07 +0200162 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200163 LOG(LERROR) << "current platform is not supported => this module will self "
164 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200165 return -1;
166 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
Max Morin787eeed2016-06-23 10:42:07 +0200168 // Store valid output results
169 //
170 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
Max Morin787eeed2016-06-23 10:42:07 +0200172 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000173}
174
niklase@google.com470e71d2011-07-07 08:21:25 +0000175// ----------------------------------------------------------------------------
176// CreatePlatformSpecificObjects
177// ----------------------------------------------------------------------------
178
Max Morin787eeed2016-06-23 10:42:07 +0200179int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200180 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
Max Morin787eeed2016-06-23 10:42:07 +0200182 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
xians@google.combf5d2ba2011-08-16 07:44:19 +0000184#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200185 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200186 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000187#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200188 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200189 LOG(INFO) << "Will use file-playing dummy device.";
xians@google.combf5d2ba2011-08-16 07:44:19 +0000190#else
Max Morin787eeed2016-06-23 10:42:07 +0200191 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
Max Morin787eeed2016-06-23 10:42:07 +0200193// Create the *Windows* implementation of the Audio Device
194//
niklase@google.com470e71d2011-07-07 08:21:25 +0000195#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200196 if ((audioLayer == kWindowsWaveAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000197#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200198 // Wave audio is default if Core audio is not supported in this build
199 || (audioLayer == kPlatformDefaultAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000200#endif
Max Morin787eeed2016-06-23 10:42:07 +0200201 ) {
202 // create *Windows Wave Audio* implementation
203 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200204 LOG(INFO) << "Windows Wave APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200205 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000206#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200207 if ((audioLayer == kWindowsCoreAudio) ||
208 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200209 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
Max Morin787eeed2016-06-23 10:42:07 +0200211 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
212 // create *Windows Core Audio* implementation
213 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200214 LOG(INFO) << "Windows Core Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200215 } else {
216 // create *Windows Wave Audio* implementation
217 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
218 if (ptrAudioDevice != NULL) {
219 // Core Audio was not supported => revert to Windows Wave instead
220 _platformAudioLayer =
221 kWindowsWaveAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200222 LOG(WARNING) << "Windows Core Audio is *not* supported => Wave APIs "
223 "will be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200224 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000225 }
Max Morin787eeed2016-06-23 10:42:07 +0200226 }
227#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000228#endif // #if defined(_WIN32)
229
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000230#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200231 // Create an Android audio manager.
232 _audioManagerAndroid.reset(new AudioManager());
233 // Select best possible combination of audio layers.
234 if (audioLayer == kPlatformDefaultAudio) {
235 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
236 // Always use OpenSL ES for output on devices that supports the
237 // low-latency output audio path.
238 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200239 } else {
Max Morin787eeed2016-06-23 10:42:07 +0200240 // Use Java-based audio in both directions when low-latency output
241 // is not supported.
242 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000243 }
Max Morin787eeed2016-06-23 10:42:07 +0200244 }
245 AudioManager* audio_manager = _audioManagerAndroid.get();
246 if (audioLayer == kAndroidJavaAudio) {
247 // Java audio for both input and output audio.
248 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
249 audioLayer, audio_manager);
250 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
251 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
252 // This combination provides low-latency output audio and at the same
253 // time support for HW AEC using the AudioRecord Java API.
254 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
255 audioLayer, audio_manager);
256 } else {
257 // Invalid audio layer.
258 ptrAudioDevice = NULL;
259 }
260// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
Max Morin787eeed2016-06-23 10:42:07 +0200262// Create the *Linux* implementation of the Audio Device
263//
niklase@google.com470e71d2011-07-07 08:21:25 +0000264#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200265 if ((audioLayer == kLinuxPulseAudio) ||
266 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000267#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200268 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
Max Morin787eeed2016-06-23 10:42:07 +0200270 // create *Linux PulseAudio* implementation
271 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200272 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200273 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200274 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200275 } else {
276 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000277#endif
278#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200279 // create *Linux ALSA Audio* implementation
280 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
281 if (ptrAudioDevice != NULL) {
282 // Pulse Audio was not supported => revert to ALSA instead
283 _platformAudioLayer =
284 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200285 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
286 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200287 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000288#endif
289#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000290 }
Max Morin787eeed2016-06-23 10:42:07 +0200291#endif
292 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000293#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200294 // create *Linux ALSA Audio* implementation
295 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200296 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000297#endif
Max Morin787eeed2016-06-23 10:42:07 +0200298 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000299#endif // #if defined(WEBRTC_LINUX)
300
Max Morin787eeed2016-06-23 10:42:07 +0200301// Create the *iPhone* implementation of the Audio Device
302//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000303#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200304 if (audioLayer == kPlatformDefaultAudio) {
305 // Create iOS Audio Device implementation.
306 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200307 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200308 }
309// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
Max Morin787eeed2016-06-23 10:42:07 +0200311// Create the *Mac* implementation of the Audio Device
312//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000313#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200314 if (audioLayer == kPlatformDefaultAudio) {
315 // Create *Mac Audio* implementation
316 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200317 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200318 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000319#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
Max Morin787eeed2016-06-23 10:42:07 +0200321 // Create the *Dummy* implementation of the Audio Device
322 // Available for all platforms
323 //
324 if (audioLayer == kDummyAudio) {
325 // Create *Dummy Audio* implementation
326 assert(!ptrAudioDevice);
327 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200328 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200329 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000330#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
Max Morin787eeed2016-06-23 10:42:07 +0200332 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200333 LOG(LERROR)
334 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200335 return -1;
336 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
Max Morin787eeed2016-06-23 10:42:07 +0200338 // Store valid output pointers
339 //
340 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000341
Max Morin787eeed2016-06-23 10:42:07 +0200342 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000343}
344
345// ----------------------------------------------------------------------------
346// AttachAudioBuffer
347//
348// Install "bridge" between the platform implemetation and the generic
349// implementation. The "child" shall set the native sampling rate and the
350// number of channels in this function call.
351// ----------------------------------------------------------------------------
352
Max Morin787eeed2016-06-23 10:42:07 +0200353int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200354 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000355
Max Morin787eeed2016-06-23 10:42:07 +0200356 _audioDeviceBuffer.SetId(_id);
357 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
358 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000359}
360
361// ----------------------------------------------------------------------------
362// ~AudioDeviceModuleImpl - dtor
363// ----------------------------------------------------------------------------
364
Max Morin787eeed2016-06-23 10:42:07 +0200365AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200366 LOG(INFO) << __FUNCTION__;
henrika@google.com73d65512011-09-07 15:11:18 +0000367
Max Morin787eeed2016-06-23 10:42:07 +0200368 if (_ptrAudioDevice) {
369 delete _ptrAudioDevice;
370 _ptrAudioDevice = NULL;
371 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
Max Morin787eeed2016-06-23 10:42:07 +0200373 delete &_critSect;
374 delete &_critSectEventCb;
375 delete &_critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000376}
377
378// ============================================================================
379// Module
380// ============================================================================
381
382// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000383// Module::TimeUntilNextProcess
384//
385// Returns the number of milliseconds until the module want a worker thread
386// to call Process().
387// ----------------------------------------------------------------------------
388
Max Morin787eeed2016-06-23 10:42:07 +0200389int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
390 int64_t now = rtc::TimeMillis();
391 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
392 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000393}
394
395// ----------------------------------------------------------------------------
396// Module::Process
397//
398// Check for posted error and warning reports. Generate callbacks if
399// new reports exists.
400// ----------------------------------------------------------------------------
401
Max Morin787eeed2016-06-23 10:42:07 +0200402void AudioDeviceModuleImpl::Process() {
403 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000404
Max Morin787eeed2016-06-23 10:42:07 +0200405 // kPlayoutWarning
406 if (_ptrAudioDevice->PlayoutWarning()) {
407 CriticalSectionScoped lock(&_critSectEventCb);
408 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200409 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200410 _ptrCbAudioDeviceObserver->OnWarningIsReported(
411 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000412 }
Max Morin787eeed2016-06-23 10:42:07 +0200413 _ptrAudioDevice->ClearPlayoutWarning();
414 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000415
Max Morin787eeed2016-06-23 10:42:07 +0200416 // kPlayoutError
417 if (_ptrAudioDevice->PlayoutError()) {
418 CriticalSectionScoped lock(&_critSectEventCb);
419 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200420 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200421 _ptrCbAudioDeviceObserver->OnErrorIsReported(
422 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000423 }
Max Morin787eeed2016-06-23 10:42:07 +0200424 _ptrAudioDevice->ClearPlayoutError();
425 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000426
Max Morin787eeed2016-06-23 10:42:07 +0200427 // kRecordingWarning
428 if (_ptrAudioDevice->RecordingWarning()) {
429 CriticalSectionScoped lock(&_critSectEventCb);
430 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200431 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200432 _ptrCbAudioDeviceObserver->OnWarningIsReported(
433 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000434 }
Max Morin787eeed2016-06-23 10:42:07 +0200435 _ptrAudioDevice->ClearRecordingWarning();
436 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000437
Max Morin787eeed2016-06-23 10:42:07 +0200438 // kRecordingError
439 if (_ptrAudioDevice->RecordingError()) {
440 CriticalSectionScoped lock(&_critSectEventCb);
441 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200442 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200443 _ptrCbAudioDeviceObserver->OnErrorIsReported(
444 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 }
Max Morin787eeed2016-06-23 10:42:07 +0200446 _ptrAudioDevice->ClearRecordingError();
447 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000448}
449
450// ============================================================================
451// Public API
452// ============================================================================
453
454// ----------------------------------------------------------------------------
455// ActiveAudioLayer
456// ----------------------------------------------------------------------------
457
henrikab2619892015-05-18 16:49:16 +0200458int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200459 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200460 AudioLayer activeAudio;
461 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
462 return -1;
463 }
464 *audioLayer = activeAudio;
465 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000466}
467
468// ----------------------------------------------------------------------------
469// LastError
470// ----------------------------------------------------------------------------
471
Max Morin787eeed2016-06-23 10:42:07 +0200472AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200473 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200474 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000475}
476
477// ----------------------------------------------------------------------------
478// Init
479// ----------------------------------------------------------------------------
480
Max Morin787eeed2016-06-23 10:42:07 +0200481int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200482 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200483 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000484 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200485 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200486
Max Morin84cab202016-07-01 13:35:19 +0200487 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
488 RTC_HISTOGRAM_ENUMERATION(
489 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
490 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
491 if (status != AudioDeviceGeneric::InitStatus::OK) {
492 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200493 return -1;
494 }
495
496 _initialized = true;
497 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000498}
499
500// ----------------------------------------------------------------------------
501// Terminate
502// ----------------------------------------------------------------------------
503
Max Morin787eeed2016-06-23 10:42:07 +0200504int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200505 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200506 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000507 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200508
509 if (_ptrAudioDevice->Terminate() == -1) {
510 return -1;
511 }
512
513 _initialized = false;
514 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000515}
516
517// ----------------------------------------------------------------------------
518// Initialized
519// ----------------------------------------------------------------------------
520
Max Morin787eeed2016-06-23 10:42:07 +0200521bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200522 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200523 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000524}
525
526// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000527// InitSpeaker
528// ----------------------------------------------------------------------------
529
Max Morin787eeed2016-06-23 10:42:07 +0200530int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200531 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200532 CHECK_INITIALIZED();
533 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000534}
535
536// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000537// InitMicrophone
538// ----------------------------------------------------------------------------
539
Max Morin787eeed2016-06-23 10:42:07 +0200540int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200541 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200542 CHECK_INITIALIZED();
543 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000544}
545
546// ----------------------------------------------------------------------------
547// SpeakerVolumeIsAvailable
548// ----------------------------------------------------------------------------
549
Max Morin787eeed2016-06-23 10:42:07 +0200550int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200551 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200552 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000553
Max Morin787eeed2016-06-23 10:42:07 +0200554 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000555
Max Morin787eeed2016-06-23 10:42:07 +0200556 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
557 return -1;
558 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000559
Max Morin787eeed2016-06-23 10:42:07 +0200560 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200561 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200562 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000563}
564
565// ----------------------------------------------------------------------------
566// SetSpeakerVolume
567// ----------------------------------------------------------------------------
568
Max Morin787eeed2016-06-23 10:42:07 +0200569int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200570 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200571 CHECK_INITIALIZED();
572 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000573}
574
575// ----------------------------------------------------------------------------
576// SpeakerVolume
577// ----------------------------------------------------------------------------
578
Max Morin787eeed2016-06-23 10:42:07 +0200579int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200580 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200581 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000582
Max Morin787eeed2016-06-23 10:42:07 +0200583 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000584
Max Morin787eeed2016-06-23 10:42:07 +0200585 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
586 return -1;
587 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000588
Max Morin787eeed2016-06-23 10:42:07 +0200589 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200590 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200591 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000592}
593
594// ----------------------------------------------------------------------------
595// SetWaveOutVolume
596// ----------------------------------------------------------------------------
597
Max Morin787eeed2016-06-23 10:42:07 +0200598int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
599 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200600 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200601 CHECK_INITIALIZED();
602 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000603}
604
605// ----------------------------------------------------------------------------
606// WaveOutVolume
607// ----------------------------------------------------------------------------
608
Max Morin787eeed2016-06-23 10:42:07 +0200609int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
610 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200611 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200612 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000613
Max Morin787eeed2016-06-23 10:42:07 +0200614 uint16_t volLeft(0);
615 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000616
Max Morin787eeed2016-06-23 10:42:07 +0200617 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
618 return -1;
619 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000620
Max Morin787eeed2016-06-23 10:42:07 +0200621 *volumeLeft = volLeft;
622 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200623 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000624
Max Morin787eeed2016-06-23 10:42:07 +0200625 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000626}
627
628// ----------------------------------------------------------------------------
629// SpeakerIsInitialized
630// ----------------------------------------------------------------------------
631
Max Morin787eeed2016-06-23 10:42:07 +0200632bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200633 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200634 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000635
Max Morin787eeed2016-06-23 10:42:07 +0200636 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200637 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200638 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000639}
640
641// ----------------------------------------------------------------------------
642// MicrophoneIsInitialized
643// ----------------------------------------------------------------------------
644
Max Morin787eeed2016-06-23 10:42:07 +0200645bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200646 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200647 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000648
Max Morin787eeed2016-06-23 10:42:07 +0200649 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200650 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200651 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000652}
653
654// ----------------------------------------------------------------------------
655// MaxSpeakerVolume
656// ----------------------------------------------------------------------------
657
Max Morin787eeed2016-06-23 10:42:07 +0200658int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
659 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000660
Max Morin787eeed2016-06-23 10:42:07 +0200661 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000662
Max Morin787eeed2016-06-23 10:42:07 +0200663 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
664 return -1;
665 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000666
Max Morin787eeed2016-06-23 10:42:07 +0200667 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200668 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000669}
670
671// ----------------------------------------------------------------------------
672// MinSpeakerVolume
673// ----------------------------------------------------------------------------
674
Max Morin787eeed2016-06-23 10:42:07 +0200675int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
676 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000677
Max Morin787eeed2016-06-23 10:42:07 +0200678 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000679
Max Morin787eeed2016-06-23 10:42:07 +0200680 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
681 return -1;
682 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000683
Max Morin787eeed2016-06-23 10:42:07 +0200684 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200685 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000686}
687
688// ----------------------------------------------------------------------------
689// SpeakerVolumeStepSize
690// ----------------------------------------------------------------------------
691
Max Morin787eeed2016-06-23 10:42:07 +0200692int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200693 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200694 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000695
Max Morin787eeed2016-06-23 10:42:07 +0200696 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000697
Max Morin787eeed2016-06-23 10:42:07 +0200698 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200699 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200700 return -1;
701 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000702
Max Morin787eeed2016-06-23 10:42:07 +0200703 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200704 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200705 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000706}
707
708// ----------------------------------------------------------------------------
709// SpeakerMuteIsAvailable
710// ----------------------------------------------------------------------------
711
Max Morin787eeed2016-06-23 10:42:07 +0200712int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200713 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200714 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000715
Max Morin787eeed2016-06-23 10:42:07 +0200716 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000717
Max Morin787eeed2016-06-23 10:42:07 +0200718 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
719 return -1;
720 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000721
Max Morin787eeed2016-06-23 10:42:07 +0200722 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200723 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200724 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000725}
726
727// ----------------------------------------------------------------------------
728// SetSpeakerMute
729// ----------------------------------------------------------------------------
730
Max Morin787eeed2016-06-23 10:42:07 +0200731int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200732 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200733 CHECK_INITIALIZED();
734 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000735}
736
737// ----------------------------------------------------------------------------
738// SpeakerMute
739// ----------------------------------------------------------------------------
740
Max Morin787eeed2016-06-23 10:42:07 +0200741int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200742 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200743 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000744
Max Morin787eeed2016-06-23 10:42:07 +0200745 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000746
Max Morin787eeed2016-06-23 10:42:07 +0200747 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
748 return -1;
749 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000750
Max Morin787eeed2016-06-23 10:42:07 +0200751 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200752 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200753 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000754}
755
756// ----------------------------------------------------------------------------
757// MicrophoneMuteIsAvailable
758// ----------------------------------------------------------------------------
759
Max Morin787eeed2016-06-23 10:42:07 +0200760int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200761 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200762 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000763
Max Morin787eeed2016-06-23 10:42:07 +0200764 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000765
Max Morin787eeed2016-06-23 10:42:07 +0200766 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
767 return -1;
768 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000769
Max Morin787eeed2016-06-23 10:42:07 +0200770 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200771 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200772 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000773}
774
775// ----------------------------------------------------------------------------
776// SetMicrophoneMute
777// ----------------------------------------------------------------------------
778
Max Morin787eeed2016-06-23 10:42:07 +0200779int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200780 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200781 CHECK_INITIALIZED();
782 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000783}
784
785// ----------------------------------------------------------------------------
786// MicrophoneMute
787// ----------------------------------------------------------------------------
788
Max Morin787eeed2016-06-23 10:42:07 +0200789int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200790 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200791 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000792
Max Morin787eeed2016-06-23 10:42:07 +0200793 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000794
Max Morin787eeed2016-06-23 10:42:07 +0200795 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
796 return -1;
797 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000798
Max Morin787eeed2016-06-23 10:42:07 +0200799 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200800 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200801 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000802}
803
804// ----------------------------------------------------------------------------
805// MicrophoneBoostIsAvailable
806// ----------------------------------------------------------------------------
807
Max Morin787eeed2016-06-23 10:42:07 +0200808int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200809 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200810 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000811
Max Morin787eeed2016-06-23 10:42:07 +0200812 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000813
Max Morin787eeed2016-06-23 10:42:07 +0200814 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
815 return -1;
816 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000817
Max Morin787eeed2016-06-23 10:42:07 +0200818 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200819 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200820 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000821}
822
823// ----------------------------------------------------------------------------
824// SetMicrophoneBoost
825// ----------------------------------------------------------------------------
826
Max Morin787eeed2016-06-23 10:42:07 +0200827int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200828 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200829 CHECK_INITIALIZED();
830 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000831}
832
833// ----------------------------------------------------------------------------
834// MicrophoneBoost
835// ----------------------------------------------------------------------------
836
Max Morin787eeed2016-06-23 10:42:07 +0200837int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200838 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200839 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000840
Max Morin787eeed2016-06-23 10:42:07 +0200841 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000842
Max Morin787eeed2016-06-23 10:42:07 +0200843 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
844 return -1;
845 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000846
Max Morin787eeed2016-06-23 10:42:07 +0200847 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200848 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200849 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000850}
851
852// ----------------------------------------------------------------------------
853// MicrophoneVolumeIsAvailable
854// ----------------------------------------------------------------------------
855
Max Morin787eeed2016-06-23 10:42:07 +0200856int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200857 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200858 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000859
Max Morin787eeed2016-06-23 10:42:07 +0200860 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000861
Max Morin787eeed2016-06-23 10:42:07 +0200862 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
863 return -1;
864 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000865
Max Morin787eeed2016-06-23 10:42:07 +0200866 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200867 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200868 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000869}
870
871// ----------------------------------------------------------------------------
872// SetMicrophoneVolume
873// ----------------------------------------------------------------------------
874
Max Morin787eeed2016-06-23 10:42:07 +0200875int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200876 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200877 CHECK_INITIALIZED();
878 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000879}
880
881// ----------------------------------------------------------------------------
882// MicrophoneVolume
883// ----------------------------------------------------------------------------
884
Max Morin787eeed2016-06-23 10:42:07 +0200885int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200886 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200887 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000888
Max Morin787eeed2016-06-23 10:42:07 +0200889 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000890
Max Morin787eeed2016-06-23 10:42:07 +0200891 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
892 return -1;
893 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000894
Max Morin787eeed2016-06-23 10:42:07 +0200895 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200896 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200897 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000898}
899
900// ----------------------------------------------------------------------------
901// StereoRecordingIsAvailable
902// ----------------------------------------------------------------------------
903
Max Morin787eeed2016-06-23 10:42:07 +0200904int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
905 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200906 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200907 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000908
Max Morin787eeed2016-06-23 10:42:07 +0200909 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000910
Max Morin787eeed2016-06-23 10:42:07 +0200911 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
912 return -1;
913 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000914
Max Morin787eeed2016-06-23 10:42:07 +0200915 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200916 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200917 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000918}
919
920// ----------------------------------------------------------------------------
921// SetStereoRecording
922// ----------------------------------------------------------------------------
923
Max Morin787eeed2016-06-23 10:42:07 +0200924int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200925 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200926 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000927
Max Morin787eeed2016-06-23 10:42:07 +0200928 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200929 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200930 return -1;
931 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000932
Max Morin787eeed2016-06-23 10:42:07 +0200933 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200934 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200935 return -1;
936 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000937
Max Morin787eeed2016-06-23 10:42:07 +0200938 int8_t nChannels(1);
939 if (enable) {
940 nChannels = 2;
941 }
942 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000943
Max Morin787eeed2016-06-23 10:42:07 +0200944 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000945}
946
947// ----------------------------------------------------------------------------
948// StereoRecording
949// ----------------------------------------------------------------------------
950
Max Morin787eeed2016-06-23 10:42:07 +0200951int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200952 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200953 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000954
Max Morin787eeed2016-06-23 10:42:07 +0200955 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000956
Max Morin787eeed2016-06-23 10:42:07 +0200957 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
958 return -1;
959 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000960
Max Morin787eeed2016-06-23 10:42:07 +0200961 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200962 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200963 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000964}
965
966// ----------------------------------------------------------------------------
967// SetRecordingChannel
968// ----------------------------------------------------------------------------
969
Max Morin787eeed2016-06-23 10:42:07 +0200970int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
971 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200972 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200973 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200974 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200975 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200976 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200977 }
978 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000979
Max Morin787eeed2016-06-23 10:42:07 +0200980 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000981
Max Morin787eeed2016-06-23 10:42:07 +0200982 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200983 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200984 return -1;
985 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000986
Max Morin787eeed2016-06-23 10:42:07 +0200987 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000988}
989
990// ----------------------------------------------------------------------------
991// RecordingChannel
992// ----------------------------------------------------------------------------
993
Max Morin787eeed2016-06-23 10:42:07 +0200994int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200995 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200996 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000997
Max Morin787eeed2016-06-23 10:42:07 +0200998 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000999
Max Morin787eeed2016-06-23 10:42:07 +02001000 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
1001 return -1;
1002 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001003
Max Morin787eeed2016-06-23 10:42:07 +02001004 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +02001005 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +02001006 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001007 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +02001008 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001009 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001010 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001011 }
Max Morin787eeed2016-06-23 10:42:07 +02001012 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001013}
1014
1015// ----------------------------------------------------------------------------
1016// StereoPlayoutIsAvailable
1017// ----------------------------------------------------------------------------
1018
Max Morin787eeed2016-06-23 10:42:07 +02001019int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001020 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001021 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001022
Max Morin787eeed2016-06-23 10:42:07 +02001023 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001024
Max Morin787eeed2016-06-23 10:42:07 +02001025 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1026 return -1;
1027 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001028
Max Morin787eeed2016-06-23 10:42:07 +02001029 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001030 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001031 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001032}
1033
1034// ----------------------------------------------------------------------------
1035// SetStereoPlayout
1036// ----------------------------------------------------------------------------
1037
Max Morin787eeed2016-06-23 10:42:07 +02001038int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001039 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001040 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001041
Max Morin787eeed2016-06-23 10:42:07 +02001042 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001043 LOG(LERROR)
1044 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001045 return -1;
1046 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001047
Max Morin787eeed2016-06-23 10:42:07 +02001048 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001049 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001050 return -1;
1051 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001052
Max Morin787eeed2016-06-23 10:42:07 +02001053 int8_t nChannels(1);
1054 if (enable) {
1055 nChannels = 2;
1056 }
1057 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001058
Max Morin787eeed2016-06-23 10:42:07 +02001059 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001060}
1061
1062// ----------------------------------------------------------------------------
1063// StereoPlayout
1064// ----------------------------------------------------------------------------
1065
Max Morin787eeed2016-06-23 10:42:07 +02001066int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001067 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001068 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001069
Max Morin787eeed2016-06-23 10:42:07 +02001070 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001071
Max Morin787eeed2016-06-23 10:42:07 +02001072 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1073 return -1;
1074 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001075
Max Morin787eeed2016-06-23 10:42:07 +02001076 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001077 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001078 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001079}
1080
1081// ----------------------------------------------------------------------------
1082// SetAGC
1083// ----------------------------------------------------------------------------
1084
Max Morin787eeed2016-06-23 10:42:07 +02001085int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001086 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001087 CHECK_INITIALIZED();
1088 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001089}
1090
1091// ----------------------------------------------------------------------------
1092// AGC
1093// ----------------------------------------------------------------------------
1094
Max Morin787eeed2016-06-23 10:42:07 +02001095bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001096 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001097 CHECK_INITIALIZED_BOOL();
1098 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001099}
1100
1101// ----------------------------------------------------------------------------
1102// PlayoutIsAvailable
1103// ----------------------------------------------------------------------------
1104
Max Morin787eeed2016-06-23 10:42:07 +02001105int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001106 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001107 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001108
Max Morin787eeed2016-06-23 10:42:07 +02001109 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001110
Max Morin787eeed2016-06-23 10:42:07 +02001111 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1112 return -1;
1113 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001114
Max Morin787eeed2016-06-23 10:42:07 +02001115 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001116 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001117 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001118}
1119
1120// ----------------------------------------------------------------------------
1121// RecordingIsAvailable
1122// ----------------------------------------------------------------------------
1123
Max Morin787eeed2016-06-23 10:42:07 +02001124int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001125 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001126 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001127
Max Morin787eeed2016-06-23 10:42:07 +02001128 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001129
Max Morin787eeed2016-06-23 10:42:07 +02001130 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1131 return -1;
1132 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001133
Max Morin787eeed2016-06-23 10:42:07 +02001134 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001135 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001136 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001137}
1138
1139// ----------------------------------------------------------------------------
1140// MaxMicrophoneVolume
1141// ----------------------------------------------------------------------------
1142
Max Morin787eeed2016-06-23 10:42:07 +02001143int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001144 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001145
Max Morin787eeed2016-06-23 10:42:07 +02001146 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001147
Max Morin787eeed2016-06-23 10:42:07 +02001148 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1149 return -1;
1150 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001151
Max Morin787eeed2016-06-23 10:42:07 +02001152 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001153 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001154}
1155
1156// ----------------------------------------------------------------------------
1157// MinMicrophoneVolume
1158// ----------------------------------------------------------------------------
1159
Max Morin787eeed2016-06-23 10:42:07 +02001160int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1161 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001162
Max Morin787eeed2016-06-23 10:42:07 +02001163 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001164
Max Morin787eeed2016-06-23 10:42:07 +02001165 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1166 return -1;
1167 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001168
Max Morin787eeed2016-06-23 10:42:07 +02001169 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001170 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001171}
1172
1173// ----------------------------------------------------------------------------
1174// MicrophoneVolumeStepSize
1175// ----------------------------------------------------------------------------
1176
Max Morin787eeed2016-06-23 10:42:07 +02001177int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1178 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001179 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001180 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001181
Max Morin787eeed2016-06-23 10:42:07 +02001182 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001183
Max Morin787eeed2016-06-23 10:42:07 +02001184 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1185 return -1;
1186 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001187
Max Morin787eeed2016-06-23 10:42:07 +02001188 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001189 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001190 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001191}
1192
1193// ----------------------------------------------------------------------------
1194// PlayoutDevices
1195// ----------------------------------------------------------------------------
1196
Max Morin787eeed2016-06-23 10:42:07 +02001197int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001198 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001199 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001200
Max Morin787eeed2016-06-23 10:42:07 +02001201 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001202 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001203 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001204}
1205
1206// ----------------------------------------------------------------------------
1207// SetPlayoutDevice I (II)
1208// ----------------------------------------------------------------------------
1209
Max Morin787eeed2016-06-23 10:42:07 +02001210int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001211 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001212 CHECK_INITIALIZED();
1213 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001214}
1215
1216// ----------------------------------------------------------------------------
1217// SetPlayoutDevice II (II)
1218// ----------------------------------------------------------------------------
1219
Max Morin787eeed2016-06-23 10:42:07 +02001220int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001221 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001222 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001223
Max Morin787eeed2016-06-23 10:42:07 +02001224 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001225}
1226
1227// ----------------------------------------------------------------------------
1228// PlayoutDeviceName
1229// ----------------------------------------------------------------------------
1230
pbos@webrtc.org25509882013-04-09 10:30:35 +00001231int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1232 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001233 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001234 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001235 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001236 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001237
Max Morin787eeed2016-06-23 10:42:07 +02001238 if (name == NULL) {
1239 _lastError = kAdmErrArgument;
1240 return -1;
1241 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001242
Max Morin787eeed2016-06-23 10:42:07 +02001243 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1244 return -1;
1245 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001246
Max Morin787eeed2016-06-23 10:42:07 +02001247 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001248 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001249 }
1250 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001251 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001252 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001253
Max Morin787eeed2016-06-23 10:42:07 +02001254 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001255}
1256
1257// ----------------------------------------------------------------------------
1258// RecordingDeviceName
1259// ----------------------------------------------------------------------------
1260
pbos@webrtc.org25509882013-04-09 10:30:35 +00001261int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1262 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001263 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001264 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001265 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001266 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001267
Max Morin787eeed2016-06-23 10:42:07 +02001268 if (name == NULL) {
1269 _lastError = kAdmErrArgument;
1270 return -1;
1271 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001272
Max Morin787eeed2016-06-23 10:42:07 +02001273 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1274 return -1;
1275 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001276
Max Morin787eeed2016-06-23 10:42:07 +02001277 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001278 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001279 }
1280 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001281 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001282 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001283
Max Morin787eeed2016-06-23 10:42:07 +02001284 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001285}
1286
1287// ----------------------------------------------------------------------------
1288// RecordingDevices
1289// ----------------------------------------------------------------------------
1290
Max Morin787eeed2016-06-23 10:42:07 +02001291int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001292 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001293 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001294
Max Morin787eeed2016-06-23 10:42:07 +02001295 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001296
Max Morin2c332bb2016-07-04 09:03:42 +02001297 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001298 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001299}
1300
1301// ----------------------------------------------------------------------------
1302// SetRecordingDevice I (II)
1303// ----------------------------------------------------------------------------
1304
Max Morin787eeed2016-06-23 10:42:07 +02001305int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001306 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001307 CHECK_INITIALIZED();
1308 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001309}
1310
1311// ----------------------------------------------------------------------------
1312// SetRecordingDevice II (II)
1313// ----------------------------------------------------------------------------
1314
Max Morin787eeed2016-06-23 10:42:07 +02001315int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001316 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001317 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001318
Max Morin787eeed2016-06-23 10:42:07 +02001319 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001320}
1321
1322// ----------------------------------------------------------------------------
1323// InitPlayout
1324// ----------------------------------------------------------------------------
1325
Max Morin787eeed2016-06-23 10:42:07 +02001326int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001327 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001328 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001329 if (PlayoutIsInitialized()) {
1330 return 0;
1331 }
Max Morin787eeed2016-06-23 10:42:07 +02001332 _audioDeviceBuffer.InitPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001333 int32_t result = _ptrAudioDevice->InitPlayout();
1334 LOG(INFO) << "output: " << result;
1335 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1336 static_cast<int>(result == 0));
1337 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001338}
1339
1340// ----------------------------------------------------------------------------
1341// InitRecording
1342// ----------------------------------------------------------------------------
1343
Max Morin787eeed2016-06-23 10:42:07 +02001344int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001345 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001346 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001347 if (RecordingIsInitialized()) {
1348 return 0;
1349 }
Max Morin787eeed2016-06-23 10:42:07 +02001350 _audioDeviceBuffer.InitRecording();
Max Morin84cab202016-07-01 13:35:19 +02001351 int32_t result = _ptrAudioDevice->InitRecording();
1352 LOG(INFO) << "output: " << result;
1353 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1354 static_cast<int>(result == 0));
1355 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001356}
1357
1358// ----------------------------------------------------------------------------
1359// PlayoutIsInitialized
1360// ----------------------------------------------------------------------------
1361
Max Morin787eeed2016-06-23 10:42:07 +02001362bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001363 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001364 CHECK_INITIALIZED_BOOL();
1365 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001366}
1367
1368// ----------------------------------------------------------------------------
1369// RecordingIsInitialized
1370// ----------------------------------------------------------------------------
1371
Max Morin787eeed2016-06-23 10:42:07 +02001372bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001373 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001374 CHECK_INITIALIZED_BOOL();
1375 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001376}
1377
1378// ----------------------------------------------------------------------------
1379// StartPlayout
1380// ----------------------------------------------------------------------------
1381
Max Morin787eeed2016-06-23 10:42:07 +02001382int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001383 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001384 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001385 if (Playing()) {
1386 return 0;
1387 }
Max Morin84cab202016-07-01 13:35:19 +02001388 int32_t result = _ptrAudioDevice->StartPlayout();
1389 LOG(INFO) << "output: " << result;
1390 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1391 static_cast<int>(result == 0));
1392 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001393}
1394
1395// ----------------------------------------------------------------------------
1396// StopPlayout
1397// ----------------------------------------------------------------------------
1398
Max Morin787eeed2016-06-23 10:42:07 +02001399int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001400 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001401 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001402 int32_t result = _ptrAudioDevice->StopPlayout();
1403 LOG(INFO) << "output: " << result;
1404 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1405 static_cast<int>(result == 0));
1406 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001407}
1408
1409// ----------------------------------------------------------------------------
1410// Playing
1411// ----------------------------------------------------------------------------
1412
Max Morin787eeed2016-06-23 10:42:07 +02001413bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001414 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001415 CHECK_INITIALIZED_BOOL();
1416 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001417}
1418
1419// ----------------------------------------------------------------------------
1420// StartRecording
1421// ----------------------------------------------------------------------------
1422
Max Morin787eeed2016-06-23 10:42:07 +02001423int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001424 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001425 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001426 if (Recording()) {
1427 return 0;
1428 }
Max Morin84cab202016-07-01 13:35:19 +02001429 int32_t result = _ptrAudioDevice->StartRecording();
1430 LOG(INFO) << "output: " << result;
1431 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1432 static_cast<int>(result == 0));
1433 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001434}
1435// ----------------------------------------------------------------------------
1436// StopRecording
1437// ----------------------------------------------------------------------------
1438
Max Morin787eeed2016-06-23 10:42:07 +02001439int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001440 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001441 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001442 int32_t result = _ptrAudioDevice->StopRecording();
1443 LOG(INFO) << "output: " << result;
1444 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1445 static_cast<int>(result == 0));
1446 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001447}
1448
1449// ----------------------------------------------------------------------------
1450// Recording
1451// ----------------------------------------------------------------------------
1452
Max Morin787eeed2016-06-23 10:42:07 +02001453bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001454 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001455 CHECK_INITIALIZED_BOOL();
1456 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001457}
1458
1459// ----------------------------------------------------------------------------
1460// RegisterEventObserver
1461// ----------------------------------------------------------------------------
1462
Max Morin787eeed2016-06-23 10:42:07 +02001463int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1464 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001465 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001466 CriticalSectionScoped lock(&_critSectEventCb);
1467 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001468
Max Morin787eeed2016-06-23 10:42:07 +02001469 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001470}
1471
1472// ----------------------------------------------------------------------------
1473// RegisterAudioCallback
1474// ----------------------------------------------------------------------------
1475
Max Morin787eeed2016-06-23 10:42:07 +02001476int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1477 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001478 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001479 CriticalSectionScoped lock(&_critSectAudioCb);
1480 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001481
Max Morin787eeed2016-06-23 10:42:07 +02001482 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001483}
1484
1485// ----------------------------------------------------------------------------
1486// StartRawInputFileRecording
1487// ----------------------------------------------------------------------------
1488
pbos@webrtc.org25509882013-04-09 10:30:35 +00001489int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001490 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001491 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001492 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001493
Max Morin787eeed2016-06-23 10:42:07 +02001494 if (NULL == pcmFileNameUTF8) {
1495 return -1;
1496 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001497
Max Morin787eeed2016-06-23 10:42:07 +02001498 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001499}
1500
1501// ----------------------------------------------------------------------------
1502// StopRawInputFileRecording
1503// ----------------------------------------------------------------------------
1504
Max Morin787eeed2016-06-23 10:42:07 +02001505int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001506 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001507 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001508
Max Morin787eeed2016-06-23 10:42:07 +02001509 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001510}
1511
1512// ----------------------------------------------------------------------------
1513// StartRawOutputFileRecording
1514// ----------------------------------------------------------------------------
1515
pbos@webrtc.org25509882013-04-09 10:30:35 +00001516int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001517 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001518 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001519 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001520
Max Morin787eeed2016-06-23 10:42:07 +02001521 if (NULL == pcmFileNameUTF8) {
1522 return -1;
1523 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001524
Max Morin787eeed2016-06-23 10:42:07 +02001525 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001526}
1527
1528// ----------------------------------------------------------------------------
1529// StopRawOutputFileRecording
1530// ----------------------------------------------------------------------------
1531
Max Morin787eeed2016-06-23 10:42:07 +02001532int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001533 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001534 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001535
Max Morin787eeed2016-06-23 10:42:07 +02001536 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001537}
1538
1539// ----------------------------------------------------------------------------
1540// SetPlayoutBuffer
1541// ----------------------------------------------------------------------------
1542
Max Morin787eeed2016-06-23 10:42:07 +02001543int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1544 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001545 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001546 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001547 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001548 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001549 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001550 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001551 }
Max Morin787eeed2016-06-23 10:42:07 +02001552 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001553
Max Morin787eeed2016-06-23 10:42:07 +02001554 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001555 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1556 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001557 return -1;
1558 }
1559
1560 int32_t ret(0);
1561
1562 if (kFixedBufferSize == type) {
1563 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1564 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001565 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001566 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001567 }
Max Morin787eeed2016-06-23 10:42:07 +02001568 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001569
Max Morin787eeed2016-06-23 10:42:07 +02001570 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001571 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1572 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001573 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001574
Max Morin787eeed2016-06-23 10:42:07 +02001575 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001576}
1577
1578// ----------------------------------------------------------------------------
1579// PlayoutBuffer
1580// ----------------------------------------------------------------------------
1581
Max Morin787eeed2016-06-23 10:42:07 +02001582int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1583 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001584 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001585 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001586
Max Morin787eeed2016-06-23 10:42:07 +02001587 BufferType bufType;
1588 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001589
Max Morin787eeed2016-06-23 10:42:07 +02001590 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001591 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001592 return -1;
1593 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001594
Max Morin787eeed2016-06-23 10:42:07 +02001595 *type = bufType;
1596 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001597
Max Morin2c332bb2016-07-04 09:03:42 +02001598 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001599 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001600}
1601
1602// ----------------------------------------------------------------------------
1603// PlayoutDelay
1604// ----------------------------------------------------------------------------
1605
Max Morin787eeed2016-06-23 10:42:07 +02001606int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001607 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001608
Max Morin787eeed2016-06-23 10:42:07 +02001609 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001610
Max Morin787eeed2016-06-23 10:42:07 +02001611 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001612 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001613 return -1;
1614 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001615
Max Morin787eeed2016-06-23 10:42:07 +02001616 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001617 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001618}
1619
1620// ----------------------------------------------------------------------------
1621// RecordingDelay
1622// ----------------------------------------------------------------------------
1623
Max Morin787eeed2016-06-23 10:42:07 +02001624int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001625 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001626 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001627
Max Morin787eeed2016-06-23 10:42:07 +02001628 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001629
Max Morin787eeed2016-06-23 10:42:07 +02001630 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001631 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001632 return -1;
1633 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001634
Max Morin787eeed2016-06-23 10:42:07 +02001635 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001636 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001637 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001638}
1639
1640// ----------------------------------------------------------------------------
1641// CPULoad
1642// ----------------------------------------------------------------------------
1643
Max Morin787eeed2016-06-23 10:42:07 +02001644int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001645 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001646 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001647
Max Morin787eeed2016-06-23 10:42:07 +02001648 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001649
Max Morin787eeed2016-06-23 10:42:07 +02001650 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001651 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001652 return -1;
1653 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001654
Max Morin787eeed2016-06-23 10:42:07 +02001655 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001656 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001657 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001658}
1659
1660// ----------------------------------------------------------------------------
1661// SetRecordingSampleRate
1662// ----------------------------------------------------------------------------
1663
Max Morin787eeed2016-06-23 10:42:07 +02001664int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1665 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001666 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001667 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001668
Max Morin787eeed2016-06-23 10:42:07 +02001669 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1670 return -1;
1671 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001672
Max Morin787eeed2016-06-23 10:42:07 +02001673 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001674}
1675
1676// ----------------------------------------------------------------------------
1677// RecordingSampleRate
1678// ----------------------------------------------------------------------------
1679
Max Morin787eeed2016-06-23 10:42:07 +02001680int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1681 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001682 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001683 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001684
Max Morin787eeed2016-06-23 10:42:07 +02001685 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001686
Max Morin787eeed2016-06-23 10:42:07 +02001687 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001688 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001689 return -1;
1690 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001691
Max Morin787eeed2016-06-23 10:42:07 +02001692 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001693 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001694 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001695}
1696
1697// ----------------------------------------------------------------------------
1698// SetPlayoutSampleRate
1699// ----------------------------------------------------------------------------
1700
Max Morin787eeed2016-06-23 10:42:07 +02001701int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1702 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001703 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001704 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001705
Max Morin787eeed2016-06-23 10:42:07 +02001706 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1707 return -1;
1708 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001709
Max Morin787eeed2016-06-23 10:42:07 +02001710 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001711}
1712
1713// ----------------------------------------------------------------------------
1714// PlayoutSampleRate
1715// ----------------------------------------------------------------------------
1716
Max Morin787eeed2016-06-23 10:42:07 +02001717int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1718 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001719 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001720 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001721
Max Morin787eeed2016-06-23 10:42:07 +02001722 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001723
Max Morin787eeed2016-06-23 10:42:07 +02001724 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001725 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001726 return -1;
1727 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001728
Max Morin787eeed2016-06-23 10:42:07 +02001729 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001730 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001731 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001732}
1733
1734// ----------------------------------------------------------------------------
1735// ResetAudioDevice
1736// ----------------------------------------------------------------------------
1737
Max Morin787eeed2016-06-23 10:42:07 +02001738int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001739 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001740 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001741
Max Morin787eeed2016-06-23 10:42:07 +02001742 if (_ptrAudioDevice->ResetAudioDevice() == -1) {
1743 return -1;
1744 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001745
Max Morin787eeed2016-06-23 10:42:07 +02001746 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001747}
1748
1749// ----------------------------------------------------------------------------
1750// SetLoudspeakerStatus
1751// ----------------------------------------------------------------------------
1752
Max Morin787eeed2016-06-23 10:42:07 +02001753int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001754 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001755 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001756
Max Morin787eeed2016-06-23 10:42:07 +02001757 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1758 return -1;
1759 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001760
Max Morin787eeed2016-06-23 10:42:07 +02001761 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001762}
1763
1764// ----------------------------------------------------------------------------
1765// GetLoudspeakerStatus
1766// ----------------------------------------------------------------------------
1767
henrikac14f5ff2015-09-23 14:08:33 +02001768int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001769 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001770 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001771 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001772 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001773 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001774 }
Max Morin2c332bb2016-07-04 09:03:42 +02001775 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001776 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001777}
1778
henrikac14f5ff2015-09-23 14:08:33 +02001779bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
Max Morin098e6c52016-06-28 09:36:25 +02001780 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001781 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001782 bool isEnabled = _ptrAudioDevice->BuiltInAECIsEnabled();
Max Morin2c332bb2016-07-04 09:03:42 +02001783 LOG(INFO) << "output: " << isEnabled;
Max Morin098e6c52016-06-28 09:36:25 +02001784 return isEnabled;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001785}
1786
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001787bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001788 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001789 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001790 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001791 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001792 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001793}
1794
henrikac14f5ff2015-09-23 14:08:33 +02001795int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001796 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001797 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001798 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001799 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001800 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001801}
1802
1803bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001804 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001805 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001806 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001807 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001808 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001809}
1810
1811int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001812 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001813 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001814 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001815 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001816 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001817}
1818
1819bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001820 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001821 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001822 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001823 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001824 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001825}
1826
1827int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001828 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001829 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001830 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001831 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001832 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001833}
1834
henrikaba35d052015-07-14 17:04:08 +02001835int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1836 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001837 LOG(INFO) << __FUNCTION__;
1838 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001839 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001840 return r;
henrikaba35d052015-07-14 17:04:08 +02001841}
1842
1843int AudioDeviceModuleImpl::GetRecordAudioParameters(
1844 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001845 LOG(INFO) << __FUNCTION__;
1846 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001847 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001848 return r;
henrikaba35d052015-07-14 17:04:08 +02001849}
1850
niklase@google.com470e71d2011-07-07 08:21:25 +00001851// ============================================================================
1852// Private Methods
1853// ============================================================================
1854
1855// ----------------------------------------------------------------------------
1856// Platform
1857// ----------------------------------------------------------------------------
1858
Max Morin787eeed2016-06-23 10:42:07 +02001859AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001860 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001861 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001862}
1863
1864// ----------------------------------------------------------------------------
1865// PlatformAudioLayer
1866// ----------------------------------------------------------------------------
1867
Max Morin787eeed2016-06-23 10:42:07 +02001868AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1869 const {
Max Morin098e6c52016-06-28 09:36:25 +02001870 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001871 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001872}
1873
1874} // namespace webrtc