blob: 850e9f3db92e20ab6103de53aade1f48ad5f85ea [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());
noahric6a355902016-08-17 15:19:50 -0700189 if (ptrAudioDevice) {
190 LOG(INFO) << "Will use file-playing dummy device.";
191 } else {
192 // Create a dummy device instead.
193 ptrAudioDevice = new AudioDeviceDummy(Id());
194 LOG(INFO) << "Dummy Audio APIs will be utilized";
195 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000196#else
Max Morin787eeed2016-06-23 10:42:07 +0200197 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
Max Morin787eeed2016-06-23 10:42:07 +0200199// Create the *Windows* implementation of the Audio Device
200//
niklase@google.com470e71d2011-07-07 08:21:25 +0000201#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200202 if ((audioLayer == kWindowsWaveAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000203#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200204 // Wave audio is default if Core audio is not supported in this build
205 || (audioLayer == kPlatformDefaultAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000206#endif
Max Morin787eeed2016-06-23 10:42:07 +0200207 ) {
208 // create *Windows Wave Audio* implementation
209 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200210 LOG(INFO) << "Windows Wave APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200211 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000212#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200213 if ((audioLayer == kWindowsCoreAudio) ||
214 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200215 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
Max Morin787eeed2016-06-23 10:42:07 +0200217 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
218 // create *Windows Core Audio* implementation
219 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200220 LOG(INFO) << "Windows Core Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200221 } else {
222 // create *Windows Wave Audio* implementation
223 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
224 if (ptrAudioDevice != NULL) {
225 // Core Audio was not supported => revert to Windows Wave instead
226 _platformAudioLayer =
227 kWindowsWaveAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200228 LOG(WARNING) << "Windows Core Audio is *not* supported => Wave APIs "
229 "will be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200230 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000231 }
Max Morin787eeed2016-06-23 10:42:07 +0200232 }
233#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000234#endif // #if defined(_WIN32)
235
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000236#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200237 // Create an Android audio manager.
238 _audioManagerAndroid.reset(new AudioManager());
239 // Select best possible combination of audio layers.
240 if (audioLayer == kPlatformDefaultAudio) {
241 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
242 // Always use OpenSL ES for output on devices that supports the
243 // low-latency output audio path.
244 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200245 } else {
Max Morin787eeed2016-06-23 10:42:07 +0200246 // Use Java-based audio in both directions when low-latency output
247 // is not supported.
248 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000249 }
Max Morin787eeed2016-06-23 10:42:07 +0200250 }
251 AudioManager* audio_manager = _audioManagerAndroid.get();
252 if (audioLayer == kAndroidJavaAudio) {
253 // Java audio for both input and output audio.
254 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
255 audioLayer, audio_manager);
256 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
257 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
258 // This combination provides low-latency output audio and at the same
259 // time support for HW AEC using the AudioRecord Java API.
260 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
261 audioLayer, audio_manager);
262 } else {
263 // Invalid audio layer.
264 ptrAudioDevice = NULL;
265 }
266// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000267
Max Morin787eeed2016-06-23 10:42:07 +0200268// Create the *Linux* implementation of the Audio Device
269//
niklase@google.com470e71d2011-07-07 08:21:25 +0000270#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200271 if ((audioLayer == kLinuxPulseAudio) ||
272 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000273#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200274 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000275
Max Morin787eeed2016-06-23 10:42:07 +0200276 // create *Linux PulseAudio* implementation
277 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200278 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200279 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200280 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200281 } else {
282 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000283#endif
284#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200285 // create *Linux ALSA Audio* implementation
286 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
287 if (ptrAudioDevice != NULL) {
288 // Pulse Audio was not supported => revert to ALSA instead
289 _platformAudioLayer =
290 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200291 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
292 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200293 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000294#endif
295#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000296 }
Max Morin787eeed2016-06-23 10:42:07 +0200297#endif
298 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000299#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200300 // create *Linux ALSA Audio* implementation
301 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200302 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000303#endif
Max Morin787eeed2016-06-23 10:42:07 +0200304 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000305#endif // #if defined(WEBRTC_LINUX)
306
Max Morin787eeed2016-06-23 10:42:07 +0200307// Create the *iPhone* implementation of the Audio Device
308//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000309#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200310 if (audioLayer == kPlatformDefaultAudio) {
311 // Create iOS Audio Device implementation.
312 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200313 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200314 }
315// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000316
Max Morin787eeed2016-06-23 10:42:07 +0200317// Create the *Mac* implementation of the Audio Device
318//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000319#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200320 if (audioLayer == kPlatformDefaultAudio) {
321 // Create *Mac Audio* implementation
322 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200323 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200324 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000325#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
Max Morin787eeed2016-06-23 10:42:07 +0200327 // Create the *Dummy* implementation of the Audio Device
328 // Available for all platforms
329 //
330 if (audioLayer == kDummyAudio) {
331 // Create *Dummy Audio* implementation
332 assert(!ptrAudioDevice);
333 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200334 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200335 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000336#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
Max Morin787eeed2016-06-23 10:42:07 +0200338 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200339 LOG(LERROR)
340 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200341 return -1;
342 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000343
Max Morin787eeed2016-06-23 10:42:07 +0200344 // Store valid output pointers
345 //
346 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000347
Max Morin787eeed2016-06-23 10:42:07 +0200348 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000349}
350
351// ----------------------------------------------------------------------------
352// AttachAudioBuffer
353//
354// Install "bridge" between the platform implemetation and the generic
355// implementation. The "child" shall set the native sampling rate and the
356// number of channels in this function call.
357// ----------------------------------------------------------------------------
358
Max Morin787eeed2016-06-23 10:42:07 +0200359int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200360 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000361
Max Morin787eeed2016-06-23 10:42:07 +0200362 _audioDeviceBuffer.SetId(_id);
363 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
364 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000365}
366
367// ----------------------------------------------------------------------------
368// ~AudioDeviceModuleImpl - dtor
369// ----------------------------------------------------------------------------
370
Max Morin787eeed2016-06-23 10:42:07 +0200371AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200372 LOG(INFO) << __FUNCTION__;
henrika@google.com73d65512011-09-07 15:11:18 +0000373
Max Morin787eeed2016-06-23 10:42:07 +0200374 if (_ptrAudioDevice) {
375 delete _ptrAudioDevice;
376 _ptrAudioDevice = NULL;
377 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000378
Max Morin787eeed2016-06-23 10:42:07 +0200379 delete &_critSect;
380 delete &_critSectEventCb;
381 delete &_critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000382}
383
384// ============================================================================
385// Module
386// ============================================================================
387
388// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000389// Module::TimeUntilNextProcess
390//
391// Returns the number of milliseconds until the module want a worker thread
392// to call Process().
393// ----------------------------------------------------------------------------
394
Max Morin787eeed2016-06-23 10:42:07 +0200395int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
396 int64_t now = rtc::TimeMillis();
397 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
398 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000399}
400
401// ----------------------------------------------------------------------------
402// Module::Process
403//
404// Check for posted error and warning reports. Generate callbacks if
405// new reports exists.
406// ----------------------------------------------------------------------------
407
Max Morin787eeed2016-06-23 10:42:07 +0200408void AudioDeviceModuleImpl::Process() {
409 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000410
Max Morin787eeed2016-06-23 10:42:07 +0200411 // kPlayoutWarning
412 if (_ptrAudioDevice->PlayoutWarning()) {
413 CriticalSectionScoped lock(&_critSectEventCb);
414 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200415 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200416 _ptrCbAudioDeviceObserver->OnWarningIsReported(
417 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000418 }
Max Morin787eeed2016-06-23 10:42:07 +0200419 _ptrAudioDevice->ClearPlayoutWarning();
420 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
Max Morin787eeed2016-06-23 10:42:07 +0200422 // kPlayoutError
423 if (_ptrAudioDevice->PlayoutError()) {
424 CriticalSectionScoped lock(&_critSectEventCb);
425 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200426 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200427 _ptrCbAudioDeviceObserver->OnErrorIsReported(
428 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429 }
Max Morin787eeed2016-06-23 10:42:07 +0200430 _ptrAudioDevice->ClearPlayoutError();
431 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000432
Max Morin787eeed2016-06-23 10:42:07 +0200433 // kRecordingWarning
434 if (_ptrAudioDevice->RecordingWarning()) {
435 CriticalSectionScoped lock(&_critSectEventCb);
436 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200437 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200438 _ptrCbAudioDeviceObserver->OnWarningIsReported(
439 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000440 }
Max Morin787eeed2016-06-23 10:42:07 +0200441 _ptrAudioDevice->ClearRecordingWarning();
442 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000443
Max Morin787eeed2016-06-23 10:42:07 +0200444 // kRecordingError
445 if (_ptrAudioDevice->RecordingError()) {
446 CriticalSectionScoped lock(&_critSectEventCb);
447 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200448 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200449 _ptrCbAudioDeviceObserver->OnErrorIsReported(
450 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000451 }
Max Morin787eeed2016-06-23 10:42:07 +0200452 _ptrAudioDevice->ClearRecordingError();
453 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000454}
455
456// ============================================================================
457// Public API
458// ============================================================================
459
460// ----------------------------------------------------------------------------
461// ActiveAudioLayer
462// ----------------------------------------------------------------------------
463
henrikab2619892015-05-18 16:49:16 +0200464int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200465 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200466 AudioLayer activeAudio;
467 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
468 return -1;
469 }
470 *audioLayer = activeAudio;
471 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000472}
473
474// ----------------------------------------------------------------------------
475// LastError
476// ----------------------------------------------------------------------------
477
Max Morin787eeed2016-06-23 10:42:07 +0200478AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200479 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200480 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000481}
482
483// ----------------------------------------------------------------------------
484// Init
485// ----------------------------------------------------------------------------
486
Max Morin787eeed2016-06-23 10:42:07 +0200487int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200488 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200489 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000490 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200491 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200492
Max Morin84cab202016-07-01 13:35:19 +0200493 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
494 RTC_HISTOGRAM_ENUMERATION(
495 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
496 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
497 if (status != AudioDeviceGeneric::InitStatus::OK) {
498 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200499 return -1;
500 }
501
502 _initialized = true;
503 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000504}
505
506// ----------------------------------------------------------------------------
507// Terminate
508// ----------------------------------------------------------------------------
509
Max Morin787eeed2016-06-23 10:42:07 +0200510int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200511 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200512 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000513 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200514
515 if (_ptrAudioDevice->Terminate() == -1) {
516 return -1;
517 }
518
519 _initialized = false;
520 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000521}
522
523// ----------------------------------------------------------------------------
524// Initialized
525// ----------------------------------------------------------------------------
526
Max Morin787eeed2016-06-23 10:42:07 +0200527bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200528 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200529 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000530}
531
532// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000533// InitSpeaker
534// ----------------------------------------------------------------------------
535
Max Morin787eeed2016-06-23 10:42:07 +0200536int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200537 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200538 CHECK_INITIALIZED();
539 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000540}
541
542// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000543// InitMicrophone
544// ----------------------------------------------------------------------------
545
Max Morin787eeed2016-06-23 10:42:07 +0200546int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200547 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200548 CHECK_INITIALIZED();
549 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000550}
551
552// ----------------------------------------------------------------------------
553// SpeakerVolumeIsAvailable
554// ----------------------------------------------------------------------------
555
Max Morin787eeed2016-06-23 10:42:07 +0200556int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200557 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200558 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000559
Max Morin787eeed2016-06-23 10:42:07 +0200560 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000561
Max Morin787eeed2016-06-23 10:42:07 +0200562 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
563 return -1;
564 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000565
Max Morin787eeed2016-06-23 10:42:07 +0200566 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200567 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200568 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000569}
570
571// ----------------------------------------------------------------------------
572// SetSpeakerVolume
573// ----------------------------------------------------------------------------
574
Max Morin787eeed2016-06-23 10:42:07 +0200575int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200576 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200577 CHECK_INITIALIZED();
578 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000579}
580
581// ----------------------------------------------------------------------------
582// SpeakerVolume
583// ----------------------------------------------------------------------------
584
Max Morin787eeed2016-06-23 10:42:07 +0200585int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200586 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200587 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000588
Max Morin787eeed2016-06-23 10:42:07 +0200589 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000590
Max Morin787eeed2016-06-23 10:42:07 +0200591 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
592 return -1;
593 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000594
Max Morin787eeed2016-06-23 10:42:07 +0200595 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200596 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200597 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000598}
599
600// ----------------------------------------------------------------------------
601// SetWaveOutVolume
602// ----------------------------------------------------------------------------
603
Max Morin787eeed2016-06-23 10:42:07 +0200604int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
605 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200606 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200607 CHECK_INITIALIZED();
608 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000609}
610
611// ----------------------------------------------------------------------------
612// WaveOutVolume
613// ----------------------------------------------------------------------------
614
Max Morin787eeed2016-06-23 10:42:07 +0200615int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
616 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200617 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200618 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000619
Max Morin787eeed2016-06-23 10:42:07 +0200620 uint16_t volLeft(0);
621 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000622
Max Morin787eeed2016-06-23 10:42:07 +0200623 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
624 return -1;
625 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000626
Max Morin787eeed2016-06-23 10:42:07 +0200627 *volumeLeft = volLeft;
628 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200629 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000630
Max Morin787eeed2016-06-23 10:42:07 +0200631 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000632}
633
634// ----------------------------------------------------------------------------
635// SpeakerIsInitialized
636// ----------------------------------------------------------------------------
637
Max Morin787eeed2016-06-23 10:42:07 +0200638bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200639 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200640 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000641
Max Morin787eeed2016-06-23 10:42:07 +0200642 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200643 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200644 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000645}
646
647// ----------------------------------------------------------------------------
648// MicrophoneIsInitialized
649// ----------------------------------------------------------------------------
650
Max Morin787eeed2016-06-23 10:42:07 +0200651bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200652 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200653 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000654
Max Morin787eeed2016-06-23 10:42:07 +0200655 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200656 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200657 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000658}
659
660// ----------------------------------------------------------------------------
661// MaxSpeakerVolume
662// ----------------------------------------------------------------------------
663
Max Morin787eeed2016-06-23 10:42:07 +0200664int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
665 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000666
Max Morin787eeed2016-06-23 10:42:07 +0200667 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000668
Max Morin787eeed2016-06-23 10:42:07 +0200669 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
670 return -1;
671 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000672
Max Morin787eeed2016-06-23 10:42:07 +0200673 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200674 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000675}
676
677// ----------------------------------------------------------------------------
678// MinSpeakerVolume
679// ----------------------------------------------------------------------------
680
Max Morin787eeed2016-06-23 10:42:07 +0200681int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
682 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000683
Max Morin787eeed2016-06-23 10:42:07 +0200684 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000685
Max Morin787eeed2016-06-23 10:42:07 +0200686 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
687 return -1;
688 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000689
Max Morin787eeed2016-06-23 10:42:07 +0200690 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200691 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000692}
693
694// ----------------------------------------------------------------------------
695// SpeakerVolumeStepSize
696// ----------------------------------------------------------------------------
697
Max Morin787eeed2016-06-23 10:42:07 +0200698int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200699 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200700 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000701
Max Morin787eeed2016-06-23 10:42:07 +0200702 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000703
Max Morin787eeed2016-06-23 10:42:07 +0200704 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200705 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200706 return -1;
707 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000708
Max Morin787eeed2016-06-23 10:42:07 +0200709 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200710 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200711 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000712}
713
714// ----------------------------------------------------------------------------
715// SpeakerMuteIsAvailable
716// ----------------------------------------------------------------------------
717
Max Morin787eeed2016-06-23 10:42:07 +0200718int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200719 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200720 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000721
Max Morin787eeed2016-06-23 10:42:07 +0200722 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723
Max Morin787eeed2016-06-23 10:42:07 +0200724 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
725 return -1;
726 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000727
Max Morin787eeed2016-06-23 10:42:07 +0200728 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200729 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200730 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000731}
732
733// ----------------------------------------------------------------------------
734// SetSpeakerMute
735// ----------------------------------------------------------------------------
736
Max Morin787eeed2016-06-23 10:42:07 +0200737int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200738 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200739 CHECK_INITIALIZED();
740 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000741}
742
743// ----------------------------------------------------------------------------
744// SpeakerMute
745// ----------------------------------------------------------------------------
746
Max Morin787eeed2016-06-23 10:42:07 +0200747int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200748 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200749 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000750
Max Morin787eeed2016-06-23 10:42:07 +0200751 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000752
Max Morin787eeed2016-06-23 10:42:07 +0200753 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
754 return -1;
755 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000756
Max Morin787eeed2016-06-23 10:42:07 +0200757 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200758 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200759 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000760}
761
762// ----------------------------------------------------------------------------
763// MicrophoneMuteIsAvailable
764// ----------------------------------------------------------------------------
765
Max Morin787eeed2016-06-23 10:42:07 +0200766int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200767 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200768 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000769
Max Morin787eeed2016-06-23 10:42:07 +0200770 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000771
Max Morin787eeed2016-06-23 10:42:07 +0200772 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
773 return -1;
774 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000775
Max Morin787eeed2016-06-23 10:42:07 +0200776 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200777 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200778 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000779}
780
781// ----------------------------------------------------------------------------
782// SetMicrophoneMute
783// ----------------------------------------------------------------------------
784
Max Morin787eeed2016-06-23 10:42:07 +0200785int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200786 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200787 CHECK_INITIALIZED();
788 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000789}
790
791// ----------------------------------------------------------------------------
792// MicrophoneMute
793// ----------------------------------------------------------------------------
794
Max Morin787eeed2016-06-23 10:42:07 +0200795int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200796 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200797 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000798
Max Morin787eeed2016-06-23 10:42:07 +0200799 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000800
Max Morin787eeed2016-06-23 10:42:07 +0200801 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
802 return -1;
803 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000804
Max Morin787eeed2016-06-23 10:42:07 +0200805 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200806 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200807 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000808}
809
810// ----------------------------------------------------------------------------
811// MicrophoneBoostIsAvailable
812// ----------------------------------------------------------------------------
813
Max Morin787eeed2016-06-23 10:42:07 +0200814int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200815 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200816 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000817
Max Morin787eeed2016-06-23 10:42:07 +0200818 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000819
Max Morin787eeed2016-06-23 10:42:07 +0200820 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
821 return -1;
822 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000823
Max Morin787eeed2016-06-23 10:42:07 +0200824 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200825 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200826 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000827}
828
829// ----------------------------------------------------------------------------
830// SetMicrophoneBoost
831// ----------------------------------------------------------------------------
832
Max Morin787eeed2016-06-23 10:42:07 +0200833int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200834 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200835 CHECK_INITIALIZED();
836 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000837}
838
839// ----------------------------------------------------------------------------
840// MicrophoneBoost
841// ----------------------------------------------------------------------------
842
Max Morin787eeed2016-06-23 10:42:07 +0200843int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200844 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200845 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000846
Max Morin787eeed2016-06-23 10:42:07 +0200847 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000848
Max Morin787eeed2016-06-23 10:42:07 +0200849 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
850 return -1;
851 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000852
Max Morin787eeed2016-06-23 10:42:07 +0200853 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200854 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200855 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000856}
857
858// ----------------------------------------------------------------------------
859// MicrophoneVolumeIsAvailable
860// ----------------------------------------------------------------------------
861
Max Morin787eeed2016-06-23 10:42:07 +0200862int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200863 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200864 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000865
Max Morin787eeed2016-06-23 10:42:07 +0200866 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000867
Max Morin787eeed2016-06-23 10:42:07 +0200868 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
869 return -1;
870 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000871
Max Morin787eeed2016-06-23 10:42:07 +0200872 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200873 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200874 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000875}
876
877// ----------------------------------------------------------------------------
878// SetMicrophoneVolume
879// ----------------------------------------------------------------------------
880
Max Morin787eeed2016-06-23 10:42:07 +0200881int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200882 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200883 CHECK_INITIALIZED();
884 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000885}
886
887// ----------------------------------------------------------------------------
888// MicrophoneVolume
889// ----------------------------------------------------------------------------
890
Max Morin787eeed2016-06-23 10:42:07 +0200891int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200892 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200893 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000894
Max Morin787eeed2016-06-23 10:42:07 +0200895 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000896
Max Morin787eeed2016-06-23 10:42:07 +0200897 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
898 return -1;
899 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000900
Max Morin787eeed2016-06-23 10:42:07 +0200901 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200902 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200903 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000904}
905
906// ----------------------------------------------------------------------------
907// StereoRecordingIsAvailable
908// ----------------------------------------------------------------------------
909
Max Morin787eeed2016-06-23 10:42:07 +0200910int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
911 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200912 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200913 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000914
Max Morin787eeed2016-06-23 10:42:07 +0200915 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000916
Max Morin787eeed2016-06-23 10:42:07 +0200917 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
918 return -1;
919 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000920
Max Morin787eeed2016-06-23 10:42:07 +0200921 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200922 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200923 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000924}
925
926// ----------------------------------------------------------------------------
927// SetStereoRecording
928// ----------------------------------------------------------------------------
929
Max Morin787eeed2016-06-23 10:42:07 +0200930int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200931 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200932 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000933
Max Morin787eeed2016-06-23 10:42:07 +0200934 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200935 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200936 return -1;
937 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000938
Max Morin787eeed2016-06-23 10:42:07 +0200939 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200940 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200941 return -1;
942 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000943
Max Morin787eeed2016-06-23 10:42:07 +0200944 int8_t nChannels(1);
945 if (enable) {
946 nChannels = 2;
947 }
948 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000949
Max Morin787eeed2016-06-23 10:42:07 +0200950 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000951}
952
953// ----------------------------------------------------------------------------
954// StereoRecording
955// ----------------------------------------------------------------------------
956
Max Morin787eeed2016-06-23 10:42:07 +0200957int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200958 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200959 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000960
Max Morin787eeed2016-06-23 10:42:07 +0200961 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000962
Max Morin787eeed2016-06-23 10:42:07 +0200963 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
964 return -1;
965 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000966
Max Morin787eeed2016-06-23 10:42:07 +0200967 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200968 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200969 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000970}
971
972// ----------------------------------------------------------------------------
973// SetRecordingChannel
974// ----------------------------------------------------------------------------
975
Max Morin787eeed2016-06-23 10:42:07 +0200976int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
977 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200978 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200979 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200980 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200981 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200982 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200983 }
984 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000985
Max Morin787eeed2016-06-23 10:42:07 +0200986 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000987
Max Morin787eeed2016-06-23 10:42:07 +0200988 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200989 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200990 return -1;
991 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000992
Max Morin787eeed2016-06-23 10:42:07 +0200993 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000994}
995
996// ----------------------------------------------------------------------------
997// RecordingChannel
998// ----------------------------------------------------------------------------
999
Max Morin787eeed2016-06-23 10:42:07 +02001000int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +02001001 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001002 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001003
Max Morin787eeed2016-06-23 10:42:07 +02001004 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001005
Max Morin787eeed2016-06-23 10:42:07 +02001006 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
1007 return -1;
1008 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001009
Max Morin787eeed2016-06-23 10:42:07 +02001010 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +02001011 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +02001012 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001013 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +02001014 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001015 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001016 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001017 }
Max Morin787eeed2016-06-23 10:42:07 +02001018 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001019}
1020
1021// ----------------------------------------------------------------------------
1022// StereoPlayoutIsAvailable
1023// ----------------------------------------------------------------------------
1024
Max Morin787eeed2016-06-23 10:42:07 +02001025int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001026 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001027 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001028
Max Morin787eeed2016-06-23 10:42:07 +02001029 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001030
Max Morin787eeed2016-06-23 10:42:07 +02001031 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1032 return -1;
1033 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001034
Max Morin787eeed2016-06-23 10:42:07 +02001035 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001036 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001037 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001038}
1039
1040// ----------------------------------------------------------------------------
1041// SetStereoPlayout
1042// ----------------------------------------------------------------------------
1043
Max Morin787eeed2016-06-23 10:42:07 +02001044int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001045 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001046 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001047
Max Morin787eeed2016-06-23 10:42:07 +02001048 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001049 LOG(LERROR)
1050 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001051 return -1;
1052 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001053
Max Morin787eeed2016-06-23 10:42:07 +02001054 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001055 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001056 return -1;
1057 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001058
Max Morin787eeed2016-06-23 10:42:07 +02001059 int8_t nChannels(1);
1060 if (enable) {
1061 nChannels = 2;
1062 }
1063 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001064
Max Morin787eeed2016-06-23 10:42:07 +02001065 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001066}
1067
1068// ----------------------------------------------------------------------------
1069// StereoPlayout
1070// ----------------------------------------------------------------------------
1071
Max Morin787eeed2016-06-23 10:42:07 +02001072int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001073 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001074 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001075
Max Morin787eeed2016-06-23 10:42:07 +02001076 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001077
Max Morin787eeed2016-06-23 10:42:07 +02001078 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1079 return -1;
1080 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001081
Max Morin787eeed2016-06-23 10:42:07 +02001082 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001083 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001084 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001085}
1086
1087// ----------------------------------------------------------------------------
1088// SetAGC
1089// ----------------------------------------------------------------------------
1090
Max Morin787eeed2016-06-23 10:42:07 +02001091int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001092 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001093 CHECK_INITIALIZED();
1094 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001095}
1096
1097// ----------------------------------------------------------------------------
1098// AGC
1099// ----------------------------------------------------------------------------
1100
Max Morin787eeed2016-06-23 10:42:07 +02001101bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001102 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001103 CHECK_INITIALIZED_BOOL();
1104 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001105}
1106
1107// ----------------------------------------------------------------------------
1108// PlayoutIsAvailable
1109// ----------------------------------------------------------------------------
1110
Max Morin787eeed2016-06-23 10:42:07 +02001111int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001112 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001113 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001114
Max Morin787eeed2016-06-23 10:42:07 +02001115 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001116
Max Morin787eeed2016-06-23 10:42:07 +02001117 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1118 return -1;
1119 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001120
Max Morin787eeed2016-06-23 10:42:07 +02001121 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001122 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001123 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001124}
1125
1126// ----------------------------------------------------------------------------
1127// RecordingIsAvailable
1128// ----------------------------------------------------------------------------
1129
Max Morin787eeed2016-06-23 10:42:07 +02001130int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001131 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001132 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001133
Max Morin787eeed2016-06-23 10:42:07 +02001134 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001135
Max Morin787eeed2016-06-23 10:42:07 +02001136 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1137 return -1;
1138 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001139
Max Morin787eeed2016-06-23 10:42:07 +02001140 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001141 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001142 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001143}
1144
1145// ----------------------------------------------------------------------------
1146// MaxMicrophoneVolume
1147// ----------------------------------------------------------------------------
1148
Max Morin787eeed2016-06-23 10:42:07 +02001149int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001150 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001151
Max Morin787eeed2016-06-23 10:42:07 +02001152 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001153
Max Morin787eeed2016-06-23 10:42:07 +02001154 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1155 return -1;
1156 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001157
Max Morin787eeed2016-06-23 10:42:07 +02001158 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001159 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001160}
1161
1162// ----------------------------------------------------------------------------
1163// MinMicrophoneVolume
1164// ----------------------------------------------------------------------------
1165
Max Morin787eeed2016-06-23 10:42:07 +02001166int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1167 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001168
Max Morin787eeed2016-06-23 10:42:07 +02001169 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001170
Max Morin787eeed2016-06-23 10:42:07 +02001171 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1172 return -1;
1173 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001174
Max Morin787eeed2016-06-23 10:42:07 +02001175 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001176 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001177}
1178
1179// ----------------------------------------------------------------------------
1180// MicrophoneVolumeStepSize
1181// ----------------------------------------------------------------------------
1182
Max Morin787eeed2016-06-23 10:42:07 +02001183int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1184 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001185 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001186 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001187
Max Morin787eeed2016-06-23 10:42:07 +02001188 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001189
Max Morin787eeed2016-06-23 10:42:07 +02001190 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1191 return -1;
1192 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001193
Max Morin787eeed2016-06-23 10:42:07 +02001194 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001195 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001196 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001197}
1198
1199// ----------------------------------------------------------------------------
1200// PlayoutDevices
1201// ----------------------------------------------------------------------------
1202
Max Morin787eeed2016-06-23 10:42:07 +02001203int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001204 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001205 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001206
Max Morin787eeed2016-06-23 10:42:07 +02001207 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001208 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001209 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001210}
1211
1212// ----------------------------------------------------------------------------
1213// SetPlayoutDevice I (II)
1214// ----------------------------------------------------------------------------
1215
Max Morin787eeed2016-06-23 10:42:07 +02001216int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001217 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001218 CHECK_INITIALIZED();
1219 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001220}
1221
1222// ----------------------------------------------------------------------------
1223// SetPlayoutDevice II (II)
1224// ----------------------------------------------------------------------------
1225
Max Morin787eeed2016-06-23 10:42:07 +02001226int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001227 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001228 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001229
Max Morin787eeed2016-06-23 10:42:07 +02001230 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001231}
1232
1233// ----------------------------------------------------------------------------
1234// PlayoutDeviceName
1235// ----------------------------------------------------------------------------
1236
pbos@webrtc.org25509882013-04-09 10:30:35 +00001237int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1238 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001239 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001240 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001241 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001242 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001243
Max Morin787eeed2016-06-23 10:42:07 +02001244 if (name == NULL) {
1245 _lastError = kAdmErrArgument;
1246 return -1;
1247 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001248
Max Morin787eeed2016-06-23 10:42:07 +02001249 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1250 return -1;
1251 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001252
Max Morin787eeed2016-06-23 10:42:07 +02001253 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001254 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001255 }
1256 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001257 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001258 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001259
Max Morin787eeed2016-06-23 10:42:07 +02001260 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001261}
1262
1263// ----------------------------------------------------------------------------
1264// RecordingDeviceName
1265// ----------------------------------------------------------------------------
1266
pbos@webrtc.org25509882013-04-09 10:30:35 +00001267int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1268 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001269 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001270 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001271 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001272 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001273
Max Morin787eeed2016-06-23 10:42:07 +02001274 if (name == NULL) {
1275 _lastError = kAdmErrArgument;
1276 return -1;
1277 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001278
Max Morin787eeed2016-06-23 10:42:07 +02001279 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1280 return -1;
1281 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001282
Max Morin787eeed2016-06-23 10:42:07 +02001283 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001284 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001285 }
1286 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001287 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001288 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001289
Max Morin787eeed2016-06-23 10:42:07 +02001290 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001291}
1292
1293// ----------------------------------------------------------------------------
1294// RecordingDevices
1295// ----------------------------------------------------------------------------
1296
Max Morin787eeed2016-06-23 10:42:07 +02001297int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001298 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001299 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001300
Max Morin787eeed2016-06-23 10:42:07 +02001301 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001302
Max Morin2c332bb2016-07-04 09:03:42 +02001303 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001304 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001305}
1306
1307// ----------------------------------------------------------------------------
1308// SetRecordingDevice I (II)
1309// ----------------------------------------------------------------------------
1310
Max Morin787eeed2016-06-23 10:42:07 +02001311int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001312 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001313 CHECK_INITIALIZED();
1314 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001315}
1316
1317// ----------------------------------------------------------------------------
1318// SetRecordingDevice II (II)
1319// ----------------------------------------------------------------------------
1320
Max Morin787eeed2016-06-23 10:42:07 +02001321int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001322 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001323 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001324
Max Morin787eeed2016-06-23 10:42:07 +02001325 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001326}
1327
1328// ----------------------------------------------------------------------------
1329// InitPlayout
1330// ----------------------------------------------------------------------------
1331
Max Morin787eeed2016-06-23 10:42:07 +02001332int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001333 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001334 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001335 if (PlayoutIsInitialized()) {
1336 return 0;
1337 }
Max Morin787eeed2016-06-23 10:42:07 +02001338 _audioDeviceBuffer.InitPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001339 int32_t result = _ptrAudioDevice->InitPlayout();
1340 LOG(INFO) << "output: " << result;
1341 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1342 static_cast<int>(result == 0));
1343 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001344}
1345
1346// ----------------------------------------------------------------------------
1347// InitRecording
1348// ----------------------------------------------------------------------------
1349
Max Morin787eeed2016-06-23 10:42:07 +02001350int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001351 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001352 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001353 if (RecordingIsInitialized()) {
1354 return 0;
1355 }
Max Morin787eeed2016-06-23 10:42:07 +02001356 _audioDeviceBuffer.InitRecording();
Max Morin84cab202016-07-01 13:35:19 +02001357 int32_t result = _ptrAudioDevice->InitRecording();
1358 LOG(INFO) << "output: " << result;
1359 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1360 static_cast<int>(result == 0));
1361 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001362}
1363
1364// ----------------------------------------------------------------------------
1365// PlayoutIsInitialized
1366// ----------------------------------------------------------------------------
1367
Max Morin787eeed2016-06-23 10:42:07 +02001368bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001369 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001370 CHECK_INITIALIZED_BOOL();
1371 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001372}
1373
1374// ----------------------------------------------------------------------------
1375// RecordingIsInitialized
1376// ----------------------------------------------------------------------------
1377
Max Morin787eeed2016-06-23 10:42:07 +02001378bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001379 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001380 CHECK_INITIALIZED_BOOL();
1381 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001382}
1383
1384// ----------------------------------------------------------------------------
1385// StartPlayout
1386// ----------------------------------------------------------------------------
1387
Max Morin787eeed2016-06-23 10:42:07 +02001388int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001389 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001390 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001391 if (Playing()) {
1392 return 0;
1393 }
Max Morin84cab202016-07-01 13:35:19 +02001394 int32_t result = _ptrAudioDevice->StartPlayout();
1395 LOG(INFO) << "output: " << result;
1396 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1397 static_cast<int>(result == 0));
1398 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001399}
1400
1401// ----------------------------------------------------------------------------
1402// StopPlayout
1403// ----------------------------------------------------------------------------
1404
Max Morin787eeed2016-06-23 10:42:07 +02001405int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001406 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001407 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001408 int32_t result = _ptrAudioDevice->StopPlayout();
1409 LOG(INFO) << "output: " << result;
1410 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1411 static_cast<int>(result == 0));
1412 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001413}
1414
1415// ----------------------------------------------------------------------------
1416// Playing
1417// ----------------------------------------------------------------------------
1418
Max Morin787eeed2016-06-23 10:42:07 +02001419bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001420 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001421 CHECK_INITIALIZED_BOOL();
1422 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001423}
1424
1425// ----------------------------------------------------------------------------
1426// StartRecording
1427// ----------------------------------------------------------------------------
1428
Max Morin787eeed2016-06-23 10:42:07 +02001429int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001430 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001431 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001432 if (Recording()) {
1433 return 0;
1434 }
Max Morin84cab202016-07-01 13:35:19 +02001435 int32_t result = _ptrAudioDevice->StartRecording();
1436 LOG(INFO) << "output: " << result;
1437 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1438 static_cast<int>(result == 0));
1439 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001440}
1441// ----------------------------------------------------------------------------
1442// StopRecording
1443// ----------------------------------------------------------------------------
1444
Max Morin787eeed2016-06-23 10:42:07 +02001445int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001446 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001447 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001448 int32_t result = _ptrAudioDevice->StopRecording();
1449 LOG(INFO) << "output: " << result;
1450 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1451 static_cast<int>(result == 0));
1452 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001453}
1454
1455// ----------------------------------------------------------------------------
1456// Recording
1457// ----------------------------------------------------------------------------
1458
Max Morin787eeed2016-06-23 10:42:07 +02001459bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001460 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001461 CHECK_INITIALIZED_BOOL();
1462 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001463}
1464
1465// ----------------------------------------------------------------------------
1466// RegisterEventObserver
1467// ----------------------------------------------------------------------------
1468
Max Morin787eeed2016-06-23 10:42:07 +02001469int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1470 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001471 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001472 CriticalSectionScoped lock(&_critSectEventCb);
1473 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001474
Max Morin787eeed2016-06-23 10:42:07 +02001475 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001476}
1477
1478// ----------------------------------------------------------------------------
1479// RegisterAudioCallback
1480// ----------------------------------------------------------------------------
1481
Max Morin787eeed2016-06-23 10:42:07 +02001482int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1483 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001484 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001485 CriticalSectionScoped lock(&_critSectAudioCb);
1486 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001487
Max Morin787eeed2016-06-23 10:42:07 +02001488 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001489}
1490
1491// ----------------------------------------------------------------------------
1492// StartRawInputFileRecording
1493// ----------------------------------------------------------------------------
1494
pbos@webrtc.org25509882013-04-09 10:30:35 +00001495int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001496 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001497 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001498 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001499
Max Morin787eeed2016-06-23 10:42:07 +02001500 if (NULL == pcmFileNameUTF8) {
1501 return -1;
1502 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001503
Max Morin787eeed2016-06-23 10:42:07 +02001504 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001505}
1506
1507// ----------------------------------------------------------------------------
1508// StopRawInputFileRecording
1509// ----------------------------------------------------------------------------
1510
Max Morin787eeed2016-06-23 10:42:07 +02001511int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001512 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001513 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001514
Max Morin787eeed2016-06-23 10:42:07 +02001515 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001516}
1517
1518// ----------------------------------------------------------------------------
1519// StartRawOutputFileRecording
1520// ----------------------------------------------------------------------------
1521
pbos@webrtc.org25509882013-04-09 10:30:35 +00001522int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001523 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001524 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001525 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001526
Max Morin787eeed2016-06-23 10:42:07 +02001527 if (NULL == pcmFileNameUTF8) {
1528 return -1;
1529 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001530
Max Morin787eeed2016-06-23 10:42:07 +02001531 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001532}
1533
1534// ----------------------------------------------------------------------------
1535// StopRawOutputFileRecording
1536// ----------------------------------------------------------------------------
1537
Max Morin787eeed2016-06-23 10:42:07 +02001538int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001539 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001540 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001541
Max Morin787eeed2016-06-23 10:42:07 +02001542 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001543}
1544
1545// ----------------------------------------------------------------------------
1546// SetPlayoutBuffer
1547// ----------------------------------------------------------------------------
1548
Max Morin787eeed2016-06-23 10:42:07 +02001549int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1550 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001551 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001552 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001553 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001554 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001555 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001556 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001557 }
Max Morin787eeed2016-06-23 10:42:07 +02001558 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001559
Max Morin787eeed2016-06-23 10:42:07 +02001560 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001561 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1562 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001563 return -1;
1564 }
1565
1566 int32_t ret(0);
1567
1568 if (kFixedBufferSize == type) {
1569 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1570 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001571 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001572 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001573 }
Max Morin787eeed2016-06-23 10:42:07 +02001574 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001575
Max Morin787eeed2016-06-23 10:42:07 +02001576 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001577 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1578 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001579 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001580
Max Morin787eeed2016-06-23 10:42:07 +02001581 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001582}
1583
1584// ----------------------------------------------------------------------------
1585// PlayoutBuffer
1586// ----------------------------------------------------------------------------
1587
Max Morin787eeed2016-06-23 10:42:07 +02001588int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1589 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001590 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001591 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001592
Max Morin787eeed2016-06-23 10:42:07 +02001593 BufferType bufType;
1594 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001595
Max Morin787eeed2016-06-23 10:42:07 +02001596 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001597 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001598 return -1;
1599 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001600
Max Morin787eeed2016-06-23 10:42:07 +02001601 *type = bufType;
1602 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001603
Max Morin2c332bb2016-07-04 09:03:42 +02001604 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001605 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001606}
1607
1608// ----------------------------------------------------------------------------
1609// PlayoutDelay
1610// ----------------------------------------------------------------------------
1611
Max Morin787eeed2016-06-23 10:42:07 +02001612int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001613 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001614
Max Morin787eeed2016-06-23 10:42:07 +02001615 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001616
Max Morin787eeed2016-06-23 10:42:07 +02001617 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001618 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001619 return -1;
1620 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001621
Max Morin787eeed2016-06-23 10:42:07 +02001622 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001623 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001624}
1625
1626// ----------------------------------------------------------------------------
1627// RecordingDelay
1628// ----------------------------------------------------------------------------
1629
Max Morin787eeed2016-06-23 10:42:07 +02001630int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001631 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001632 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001633
Max Morin787eeed2016-06-23 10:42:07 +02001634 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001635
Max Morin787eeed2016-06-23 10:42:07 +02001636 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001637 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001638 return -1;
1639 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001640
Max Morin787eeed2016-06-23 10:42:07 +02001641 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001642 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001643 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001644}
1645
1646// ----------------------------------------------------------------------------
1647// CPULoad
1648// ----------------------------------------------------------------------------
1649
Max Morin787eeed2016-06-23 10:42:07 +02001650int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001651 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001652 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001653
Max Morin787eeed2016-06-23 10:42:07 +02001654 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001655
Max Morin787eeed2016-06-23 10:42:07 +02001656 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001657 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001658 return -1;
1659 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001660
Max Morin787eeed2016-06-23 10:42:07 +02001661 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001662 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001663 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001664}
1665
1666// ----------------------------------------------------------------------------
1667// SetRecordingSampleRate
1668// ----------------------------------------------------------------------------
1669
Max Morin787eeed2016-06-23 10:42:07 +02001670int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1671 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001672 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001673 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001674
Max Morin787eeed2016-06-23 10:42:07 +02001675 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1676 return -1;
1677 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001678
Max Morin787eeed2016-06-23 10:42:07 +02001679 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001680}
1681
1682// ----------------------------------------------------------------------------
1683// RecordingSampleRate
1684// ----------------------------------------------------------------------------
1685
Max Morin787eeed2016-06-23 10:42:07 +02001686int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1687 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001688 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001689 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001690
Max Morin787eeed2016-06-23 10:42:07 +02001691 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001692
Max Morin787eeed2016-06-23 10:42:07 +02001693 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001694 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001695 return -1;
1696 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001697
Max Morin787eeed2016-06-23 10:42:07 +02001698 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001699 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001700 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001701}
1702
1703// ----------------------------------------------------------------------------
1704// SetPlayoutSampleRate
1705// ----------------------------------------------------------------------------
1706
Max Morin787eeed2016-06-23 10:42:07 +02001707int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1708 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001709 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001710 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001711
Max Morin787eeed2016-06-23 10:42:07 +02001712 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1713 return -1;
1714 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001715
Max Morin787eeed2016-06-23 10:42:07 +02001716 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001717}
1718
1719// ----------------------------------------------------------------------------
1720// PlayoutSampleRate
1721// ----------------------------------------------------------------------------
1722
Max Morin787eeed2016-06-23 10:42:07 +02001723int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1724 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001725 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001726 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001727
Max Morin787eeed2016-06-23 10:42:07 +02001728 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001729
Max Morin787eeed2016-06-23 10:42:07 +02001730 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001731 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001732 return -1;
1733 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001734
Max Morin787eeed2016-06-23 10:42:07 +02001735 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001736 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001737 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001738}
1739
1740// ----------------------------------------------------------------------------
1741// ResetAudioDevice
1742// ----------------------------------------------------------------------------
1743
Max Morin787eeed2016-06-23 10:42:07 +02001744int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001745 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001746 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001747
Max Morin787eeed2016-06-23 10:42:07 +02001748 if (_ptrAudioDevice->ResetAudioDevice() == -1) {
1749 return -1;
1750 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001751
Max Morin787eeed2016-06-23 10:42:07 +02001752 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001753}
1754
1755// ----------------------------------------------------------------------------
1756// SetLoudspeakerStatus
1757// ----------------------------------------------------------------------------
1758
Max Morin787eeed2016-06-23 10:42:07 +02001759int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001760 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001761 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001762
Max Morin787eeed2016-06-23 10:42:07 +02001763 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1764 return -1;
1765 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001766
Max Morin787eeed2016-06-23 10:42:07 +02001767 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001768}
1769
1770// ----------------------------------------------------------------------------
1771// GetLoudspeakerStatus
1772// ----------------------------------------------------------------------------
1773
henrikac14f5ff2015-09-23 14:08:33 +02001774int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001775 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001776 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001777 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001778 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001779 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001780 }
Max Morin2c332bb2016-07-04 09:03:42 +02001781 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001782 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001783}
1784
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001785bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001786 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001787 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001788 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001789 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001790 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001791}
1792
henrikac14f5ff2015-09-23 14:08:33 +02001793int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001794 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001795 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001796 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001797 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001798 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001799}
1800
1801bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001802 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001803 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001804 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001805 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001806 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001807}
1808
1809int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001810 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001811 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001812 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001813 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001814 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001815}
1816
1817bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001818 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001819 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001820 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001821 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001822 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001823}
1824
1825int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001826 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001827 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001828 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001829 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001830 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001831}
1832
maxmorin88e31a32016-08-16 00:56:09 -07001833#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001834int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1835 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001836 LOG(INFO) << __FUNCTION__;
1837 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001838 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001839 return r;
henrikaba35d052015-07-14 17:04:08 +02001840}
1841
1842int AudioDeviceModuleImpl::GetRecordAudioParameters(
1843 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001844 LOG(INFO) << __FUNCTION__;
1845 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001846 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001847 return r;
henrikaba35d052015-07-14 17:04:08 +02001848}
maxmorin88e31a32016-08-16 00:56:09 -07001849#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001850
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