blob: b2a33ef72f7894e2fd7dc849027e7cb806eb4cb5 [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 Morin098e6c52016-06-28 09:36:25 +020011#include "webrtc/base/logging.h"
Peter Boström1d194412016-03-21 16:44:31 +010012#include "webrtc/base/refcount.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020013#include "webrtc/base/timeutils.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000014#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
15#include "webrtc/modules/audio_device/audio_device_config.h"
16#include "webrtc/modules/audio_device/audio_device_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000018#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000019#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020022#include "audio_device_wave_win.h"
23#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
24#include "audio_device_core_win.h"
25#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000026#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020027#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020028#include "webrtc/modules/audio_device/android/audio_device_template.h"
29#include "webrtc/modules/audio_device/android/audio_manager.h"
30#include "webrtc/modules/audio_device/android/audio_record_jni.h"
31#include "webrtc/modules/audio_device/android/audio_track_jni.h"
32#include "webrtc/modules/audio_device/android/opensles_player.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020034#if defined(LINUX_ALSA)
35#include "audio_device_alsa_linux.h"
36#endif
Tommi68898a22015-05-19 17:28:07 +020037#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020038#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020039#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000040#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000042#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020043#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000044#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000045
46#if defined(WEBRTC_DUMMY_FILE_DEVICES)
47#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
48#endif
49
pbos@webrtc.org811269d2013-07-11 13:24:38 +000050#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000051#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010052#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000053
Max Morin787eeed2016-06-23 10:42:07 +020054#define CHECK_INITIALIZED() \
55 { \
56 if (!_initialized) { \
57 return -1; \
58 }; \
59 }
niklase@google.com470e71d2011-07-07 08:21:25 +000060
Max Morin787eeed2016-06-23 10:42:07 +020061#define CHECK_INITIALIZED_BOOL() \
62 { \
63 if (!_initialized) { \
64 return false; \
65 }; \
66 }
niklase@google.com470e71d2011-07-07 08:21:25 +000067
Peter Boström1d194412016-03-21 16:44:31 +010068namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000069
niklase@google.com470e71d2011-07-07 08:21:25 +000070// ============================================================================
71// Static methods
72// ============================================================================
73
74// ----------------------------------------------------------------------------
75// AudioDeviceModule::Create()
76// ----------------------------------------------------------------------------
77
Peter Boström4adbbcf2016-05-03 15:51:26 -040078rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010079 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040080 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020081 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020082 // Create the generic ref counted (platform independent) implementation.
83 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
84 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000085
Max Morin787eeed2016-06-23 10:42:07 +020086 // Ensure that the current platform is supported.
87 if (audioDevice->CheckPlatform() == -1) {
88 return nullptr;
89 }
niklase@google.com470e71d2011-07-07 08:21:25 +000090
Max Morin787eeed2016-06-23 10:42:07 +020091 // Create the platform-dependent implementation.
92 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
93 return nullptr;
94 }
niklase@google.com470e71d2011-07-07 08:21:25 +000095
Max Morin787eeed2016-06-23 10:42:07 +020096 // Ensure that the generic audio buffer can communicate with the
97 // platform-specific parts.
98 if (audioDevice->AttachAudioBuffer() == -1) {
99 return nullptr;
100 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
Max Morin787eeed2016-06-23 10:42:07 +0200102 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000103
Max Morin787eeed2016-06-23 10:42:07 +0200104 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105}
106
niklase@google.com470e71d2011-07-07 08:21:25 +0000107// ============================================================================
108// Construction & Destruction
109// ============================================================================
110
111// ----------------------------------------------------------------------------
112// AudioDeviceModuleImpl - ctor
113// ----------------------------------------------------------------------------
114
Max Morin787eeed2016-06-23 10:42:07 +0200115AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
116 const AudioLayer audioLayer)
117 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
118 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
119 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
120 _ptrCbAudioDeviceObserver(NULL),
121 _ptrAudioDevice(NULL),
122 _id(id),
123 _platformAudioLayer(audioLayer),
124 _lastProcessTime(rtc::TimeMillis()),
125 _platformType(kPlatformNotSupported),
126 _initialized(false),
127 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200128 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129}
130
131// ----------------------------------------------------------------------------
132// CheckPlatform
133// ----------------------------------------------------------------------------
134
Max Morin787eeed2016-06-23 10:42:07 +0200135int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200136 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
Max Morin787eeed2016-06-23 10:42:07 +0200138 // Ensure that the current platform is supported
139 //
140 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
142#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200143 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200144 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000145#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200146 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200147 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000148#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200149 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200150 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000151#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200152 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200153 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000154#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200155 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200156 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000157#endif
158
Max Morin787eeed2016-06-23 10:42:07 +0200159 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200160 LOG(LERROR) << "current platform is not supported => this module will self "
161 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200162 return -1;
163 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
Max Morin787eeed2016-06-23 10:42:07 +0200165 // Store valid output results
166 //
167 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
Max Morin787eeed2016-06-23 10:42:07 +0200169 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000170}
171
niklase@google.com470e71d2011-07-07 08:21:25 +0000172// ----------------------------------------------------------------------------
173// CreatePlatformSpecificObjects
174// ----------------------------------------------------------------------------
175
Max Morin787eeed2016-06-23 10:42:07 +0200176int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200177 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
Max Morin787eeed2016-06-23 10:42:07 +0200179 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
xians@google.combf5d2ba2011-08-16 07:44:19 +0000181#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200182 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200183 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000184#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200185 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200186 LOG(INFO) << "Will use file-playing dummy device.";
xians@google.combf5d2ba2011-08-16 07:44:19 +0000187#else
Max Morin787eeed2016-06-23 10:42:07 +0200188 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
Max Morin787eeed2016-06-23 10:42:07 +0200190// Create the *Windows* implementation of the Audio Device
191//
niklase@google.com470e71d2011-07-07 08:21:25 +0000192#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200193 if ((audioLayer == kWindowsWaveAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000194#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200195 // Wave audio is default if Core audio is not supported in this build
196 || (audioLayer == kPlatformDefaultAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000197#endif
Max Morin787eeed2016-06-23 10:42:07 +0200198 ) {
199 // create *Windows Wave Audio* implementation
200 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200201 LOG(INFO) << "Windows Wave APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200202 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000203#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200204 if ((audioLayer == kWindowsCoreAudio) ||
205 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200206 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
Max Morin787eeed2016-06-23 10:42:07 +0200208 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
209 // create *Windows Core Audio* implementation
210 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200211 LOG(INFO) << "Windows Core Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200212 } else {
213 // create *Windows Wave Audio* implementation
214 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
215 if (ptrAudioDevice != NULL) {
216 // Core Audio was not supported => revert to Windows Wave instead
217 _platformAudioLayer =
218 kWindowsWaveAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200219 LOG(WARNING) << "Windows Core Audio is *not* supported => Wave APIs "
220 "will be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200221 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000222 }
Max Morin787eeed2016-06-23 10:42:07 +0200223 }
224#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000225#endif // #if defined(_WIN32)
226
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000227#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200228 // Create an Android audio manager.
229 _audioManagerAndroid.reset(new AudioManager());
230 // Select best possible combination of audio layers.
231 if (audioLayer == kPlatformDefaultAudio) {
232 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
233 // Always use OpenSL ES for output on devices that supports the
234 // low-latency output audio path.
235 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200236 } else {
Max Morin787eeed2016-06-23 10:42:07 +0200237 // Use Java-based audio in both directions when low-latency output
238 // is not supported.
239 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000240 }
Max Morin787eeed2016-06-23 10:42:07 +0200241 }
242 AudioManager* audio_manager = _audioManagerAndroid.get();
243 if (audioLayer == kAndroidJavaAudio) {
244 // Java audio for both input and output audio.
245 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
246 audioLayer, audio_manager);
247 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
248 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
249 // This combination provides low-latency output audio and at the same
250 // time support for HW AEC using the AudioRecord Java API.
251 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
252 audioLayer, audio_manager);
253 } else {
254 // Invalid audio layer.
255 ptrAudioDevice = NULL;
256 }
257// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
Max Morin787eeed2016-06-23 10:42:07 +0200259// Create the *Linux* implementation of the Audio Device
260//
niklase@google.com470e71d2011-07-07 08:21:25 +0000261#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200262 if ((audioLayer == kLinuxPulseAudio) ||
263 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000264#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200265 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000266
Max Morin787eeed2016-06-23 10:42:07 +0200267 // create *Linux PulseAudio* implementation
268 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
269 if (pulseDevice->Init() != -1) {
270 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200271 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200272 } else {
273 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274#endif
275#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200276 // create *Linux ALSA Audio* implementation
277 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
278 if (ptrAudioDevice != NULL) {
279 // Pulse Audio was not supported => revert to ALSA instead
280 _platformAudioLayer =
281 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200282 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
283 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200284 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000285#endif
286#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000287 }
Max Morin787eeed2016-06-23 10:42:07 +0200288#endif
289 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000290#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200291 // create *Linux ALSA Audio* implementation
292 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200293 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000294#endif
Max Morin787eeed2016-06-23 10:42:07 +0200295 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000296#endif // #if defined(WEBRTC_LINUX)
297
Max Morin787eeed2016-06-23 10:42:07 +0200298// Create the *iPhone* implementation of the Audio Device
299//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000300#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200301 if (audioLayer == kPlatformDefaultAudio) {
302 // Create iOS Audio Device implementation.
303 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200304 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200305 }
306// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
Max Morin787eeed2016-06-23 10:42:07 +0200308// Create the *Mac* implementation of the Audio Device
309//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000310#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200311 if (audioLayer == kPlatformDefaultAudio) {
312 // Create *Mac Audio* implementation
313 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200314 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200315 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000316#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
Max Morin787eeed2016-06-23 10:42:07 +0200318 // Create the *Dummy* implementation of the Audio Device
319 // Available for all platforms
320 //
321 if (audioLayer == kDummyAudio) {
322 // Create *Dummy Audio* implementation
323 assert(!ptrAudioDevice);
324 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200325 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200326 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000327#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000328
Max Morin787eeed2016-06-23 10:42:07 +0200329 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200330 LOG(LERROR)
331 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200332 return -1;
333 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000334
Max Morin787eeed2016-06-23 10:42:07 +0200335 // Store valid output pointers
336 //
337 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000338
Max Morin787eeed2016-06-23 10:42:07 +0200339 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000340}
341
342// ----------------------------------------------------------------------------
343// AttachAudioBuffer
344//
345// Install "bridge" between the platform implemetation and the generic
346// implementation. The "child" shall set the native sampling rate and the
347// number of channels in this function call.
348// ----------------------------------------------------------------------------
349
Max Morin787eeed2016-06-23 10:42:07 +0200350int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200351 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
Max Morin787eeed2016-06-23 10:42:07 +0200353 _audioDeviceBuffer.SetId(_id);
354 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
355 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000356}
357
358// ----------------------------------------------------------------------------
359// ~AudioDeviceModuleImpl - dtor
360// ----------------------------------------------------------------------------
361
Max Morin787eeed2016-06-23 10:42:07 +0200362AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200363 LOG(INFO) << __FUNCTION__;
henrika@google.com73d65512011-09-07 15:11:18 +0000364
Max Morin787eeed2016-06-23 10:42:07 +0200365 if (_ptrAudioDevice) {
366 delete _ptrAudioDevice;
367 _ptrAudioDevice = NULL;
368 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
Max Morin787eeed2016-06-23 10:42:07 +0200370 delete &_critSect;
371 delete &_critSectEventCb;
372 delete &_critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000373}
374
375// ============================================================================
376// Module
377// ============================================================================
378
379// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000380// Module::TimeUntilNextProcess
381//
382// Returns the number of milliseconds until the module want a worker thread
383// to call Process().
384// ----------------------------------------------------------------------------
385
Max Morin787eeed2016-06-23 10:42:07 +0200386int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
Max Morin098e6c52016-06-28 09:36:25 +0200387 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200388 int64_t now = rtc::TimeMillis();
389 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
390 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000391}
392
393// ----------------------------------------------------------------------------
394// Module::Process
395//
396// Check for posted error and warning reports. Generate callbacks if
397// new reports exists.
398// ----------------------------------------------------------------------------
399
Max Morin787eeed2016-06-23 10:42:07 +0200400void AudioDeviceModuleImpl::Process() {
Max Morin098e6c52016-06-28 09:36:25 +0200401 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200402 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000403
Max Morin787eeed2016-06-23 10:42:07 +0200404 // kPlayoutWarning
405 if (_ptrAudioDevice->PlayoutWarning()) {
406 CriticalSectionScoped lock(&_critSectEventCb);
407 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200408 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200409 _ptrCbAudioDeviceObserver->OnWarningIsReported(
410 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000411 }
Max Morin787eeed2016-06-23 10:42:07 +0200412 _ptrAudioDevice->ClearPlayoutWarning();
413 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000414
Max Morin787eeed2016-06-23 10:42:07 +0200415 // kPlayoutError
416 if (_ptrAudioDevice->PlayoutError()) {
417 CriticalSectionScoped lock(&_critSectEventCb);
418 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200419 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200420 _ptrCbAudioDeviceObserver->OnErrorIsReported(
421 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000422 }
Max Morin787eeed2016-06-23 10:42:07 +0200423 _ptrAudioDevice->ClearPlayoutError();
424 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000425
Max Morin787eeed2016-06-23 10:42:07 +0200426 // kRecordingWarning
427 if (_ptrAudioDevice->RecordingWarning()) {
428 CriticalSectionScoped lock(&_critSectEventCb);
429 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200430 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200431 _ptrCbAudioDeviceObserver->OnWarningIsReported(
432 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000433 }
Max Morin787eeed2016-06-23 10:42:07 +0200434 _ptrAudioDevice->ClearRecordingWarning();
435 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000436
Max Morin787eeed2016-06-23 10:42:07 +0200437 // kRecordingError
438 if (_ptrAudioDevice->RecordingError()) {
439 CriticalSectionScoped lock(&_critSectEventCb);
440 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200441 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200442 _ptrCbAudioDeviceObserver->OnErrorIsReported(
443 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000444 }
Max Morin787eeed2016-06-23 10:42:07 +0200445 _ptrAudioDevice->ClearRecordingError();
446 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000447}
448
449// ============================================================================
450// Public API
451// ============================================================================
452
453// ----------------------------------------------------------------------------
454// ActiveAudioLayer
455// ----------------------------------------------------------------------------
456
henrikab2619892015-05-18 16:49:16 +0200457int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200458 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200459 AudioLayer activeAudio;
460 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
461 return -1;
462 }
463 *audioLayer = activeAudio;
464 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000465}
466
467// ----------------------------------------------------------------------------
468// LastError
469// ----------------------------------------------------------------------------
470
Max Morin787eeed2016-06-23 10:42:07 +0200471AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200472 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200473 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000474}
475
476// ----------------------------------------------------------------------------
477// Init
478// ----------------------------------------------------------------------------
479
Max Morin787eeed2016-06-23 10:42:07 +0200480int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200481 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200482 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000483 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200484
485 if (!_ptrAudioDevice)
486 return -1;
487
488 if (_ptrAudioDevice->Init() == -1) {
489 return -1;
490 }
491
492 _initialized = true;
493 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000494}
495
496// ----------------------------------------------------------------------------
497// Terminate
498// ----------------------------------------------------------------------------
499
Max Morin787eeed2016-06-23 10:42:07 +0200500int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200501 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200502 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000503 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200504
505 if (_ptrAudioDevice->Terminate() == -1) {
506 return -1;
507 }
508
509 _initialized = false;
510 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000511}
512
513// ----------------------------------------------------------------------------
514// Initialized
515// ----------------------------------------------------------------------------
516
Max Morin787eeed2016-06-23 10:42:07 +0200517bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200518 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200519 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000520}
521
522// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000523// InitSpeaker
524// ----------------------------------------------------------------------------
525
Max Morin787eeed2016-06-23 10:42:07 +0200526int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200527 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200528 CHECK_INITIALIZED();
529 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000530}
531
532// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000533// InitMicrophone
534// ----------------------------------------------------------------------------
535
Max Morin787eeed2016-06-23 10:42:07 +0200536int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200537 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200538 CHECK_INITIALIZED();
539 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000540}
541
542// ----------------------------------------------------------------------------
543// SpeakerVolumeIsAvailable
544// ----------------------------------------------------------------------------
545
Max Morin787eeed2016-06-23 10:42:07 +0200546int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200547 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200548 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000549
Max Morin787eeed2016-06-23 10:42:07 +0200550 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000551
Max Morin787eeed2016-06-23 10:42:07 +0200552 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
553 return -1;
554 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000555
Max Morin787eeed2016-06-23 10:42:07 +0200556 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000557
Max Morin098e6c52016-06-28 09:36:25 +0200558 if (isAvailable) {
559 LOG(INFO) << __FUNCTION__ << " output: available";
560 } else {
561 LOG(INFO) << __FUNCTION__ << " output: not available";
562 }
Max Morin787eeed2016-06-23 10:42:07 +0200563 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000564}
565
566// ----------------------------------------------------------------------------
567// SetSpeakerVolume
568// ----------------------------------------------------------------------------
569
Max Morin787eeed2016-06-23 10:42:07 +0200570int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200571 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200572 CHECK_INITIALIZED();
573 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000574}
575
576// ----------------------------------------------------------------------------
577// SpeakerVolume
578// ----------------------------------------------------------------------------
579
Max Morin787eeed2016-06-23 10:42:07 +0200580int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200581 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200582 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000583
Max Morin787eeed2016-06-23 10:42:07 +0200584 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000585
Max Morin787eeed2016-06-23 10:42:07 +0200586 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
587 return -1;
588 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000589
Max Morin787eeed2016-06-23 10:42:07 +0200590 *volume = level;
niklase@google.com470e71d2011-07-07 08:21:25 +0000591
Max Morin098e6c52016-06-28 09:36:25 +0200592 LOG(INFO) << __FUNCTION__ << " output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200593 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000594}
595
596// ----------------------------------------------------------------------------
597// SetWaveOutVolume
598// ----------------------------------------------------------------------------
599
Max Morin787eeed2016-06-23 10:42:07 +0200600int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
601 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200602 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200603 CHECK_INITIALIZED();
604 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000605}
606
607// ----------------------------------------------------------------------------
608// WaveOutVolume
609// ----------------------------------------------------------------------------
610
Max Morin787eeed2016-06-23 10:42:07 +0200611int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
612 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200613 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200614 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000615
Max Morin787eeed2016-06-23 10:42:07 +0200616 uint16_t volLeft(0);
617 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000618
Max Morin787eeed2016-06-23 10:42:07 +0200619 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
620 return -1;
621 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000622
Max Morin787eeed2016-06-23 10:42:07 +0200623 *volumeLeft = volLeft;
624 *volumeRight = volRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000625
Max Morin098e6c52016-06-28 09:36:25 +0200626 LOG(INFO) << __FUNCTION__ << " output: volumeLeft = " << *volumeLeft
627 << ", volumeRight = " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000628
Max Morin787eeed2016-06-23 10:42:07 +0200629 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000630}
631
632// ----------------------------------------------------------------------------
633// SpeakerIsInitialized
634// ----------------------------------------------------------------------------
635
Max Morin787eeed2016-06-23 10:42:07 +0200636bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200637 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200638 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000639
Max Morin787eeed2016-06-23 10:42:07 +0200640 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000641
Max Morin098e6c52016-06-28 09:36:25 +0200642 if (isInitialized) {
643 LOG(INFO) << __FUNCTION__ << " output: initialized";
644 } else {
645 LOG(INFO) << __FUNCTION__ << " output: not initialized";
646 }
Max Morin787eeed2016-06-23 10:42:07 +0200647 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000648}
649
650// ----------------------------------------------------------------------------
651// MicrophoneIsInitialized
652// ----------------------------------------------------------------------------
653
Max Morin787eeed2016-06-23 10:42:07 +0200654bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200655 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200656 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000657
Max Morin787eeed2016-06-23 10:42:07 +0200658 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
niklase@google.com470e71d2011-07-07 08:21:25 +0000659
Max Morin098e6c52016-06-28 09:36:25 +0200660 if (isInitialized) {
661 LOG(INFO) << __FUNCTION__ << " output: initialized";
662 } else {
663 LOG(INFO) << __FUNCTION__ << " output: not initialized";
664 }
Max Morin787eeed2016-06-23 10:42:07 +0200665 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000666}
667
668// ----------------------------------------------------------------------------
669// MaxSpeakerVolume
670// ----------------------------------------------------------------------------
671
Max Morin787eeed2016-06-23 10:42:07 +0200672int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200673 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200674 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000675
Max Morin787eeed2016-06-23 10:42:07 +0200676 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000677
Max Morin787eeed2016-06-23 10:42:07 +0200678 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
679 return -1;
680 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000681
Max Morin787eeed2016-06-23 10:42:07 +0200682 *maxVolume = maxVol;
niklase@google.com470e71d2011-07-07 08:21:25 +0000683
Max Morin098e6c52016-06-28 09:36:25 +0200684 LOG(INFO) << __FUNCTION__ << " output: maxVolume = " << *maxVolume;
Max Morin787eeed2016-06-23 10:42:07 +0200685 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000686}
687
688// ----------------------------------------------------------------------------
689// MinSpeakerVolume
690// ----------------------------------------------------------------------------
691
Max Morin787eeed2016-06-23 10:42:07 +0200692int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200693 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200694 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000695
Max Morin787eeed2016-06-23 10:42:07 +0200696 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000697
Max Morin787eeed2016-06-23 10:42:07 +0200698 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
699 return -1;
700 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000701
Max Morin787eeed2016-06-23 10:42:07 +0200702 *minVolume = minVol;
niklase@google.com470e71d2011-07-07 08:21:25 +0000703
Max Morin098e6c52016-06-28 09:36:25 +0200704 LOG(INFO) << __FUNCTION__ << " output: " << *minVolume;
Max Morin787eeed2016-06-23 10:42:07 +0200705 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000706}
707
708// ----------------------------------------------------------------------------
709// SpeakerVolumeStepSize
710// ----------------------------------------------------------------------------
711
Max Morin787eeed2016-06-23 10:42:07 +0200712int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200713 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200714 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000715
Max Morin787eeed2016-06-23 10:42:07 +0200716 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000717
Max Morin787eeed2016-06-23 10:42:07 +0200718 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200719 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200720 return -1;
721 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000722
Max Morin787eeed2016-06-23 10:42:07 +0200723 *stepSize = delta;
niklase@google.com470e71d2011-07-07 08:21:25 +0000724
Max Morin098e6c52016-06-28 09:36:25 +0200725 LOG(INFO) << __FUNCTION__ << " output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200726 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000727}
728
729// ----------------------------------------------------------------------------
730// SpeakerMuteIsAvailable
731// ----------------------------------------------------------------------------
732
Max Morin787eeed2016-06-23 10:42:07 +0200733int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200734 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200735 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000736
Max Morin787eeed2016-06-23 10:42:07 +0200737 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000738
Max Morin787eeed2016-06-23 10:42:07 +0200739 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
740 return -1;
741 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000742
Max Morin787eeed2016-06-23 10:42:07 +0200743 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000744
Max Morin098e6c52016-06-28 09:36:25 +0200745 if (isAvailable) {
746 LOG(INFO) << __FUNCTION__ << " output: available";
747 } else {
748 LOG(INFO) << __FUNCTION__ << " output: not available";
749 }
Max Morin787eeed2016-06-23 10:42:07 +0200750 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000751}
752
753// ----------------------------------------------------------------------------
754// SetSpeakerMute
755// ----------------------------------------------------------------------------
756
Max Morin787eeed2016-06-23 10:42:07 +0200757int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200758 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200759 CHECK_INITIALIZED();
760 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000761}
762
763// ----------------------------------------------------------------------------
764// SpeakerMute
765// ----------------------------------------------------------------------------
766
Max Morin787eeed2016-06-23 10:42:07 +0200767int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200768 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200769 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000770
Max Morin787eeed2016-06-23 10:42:07 +0200771 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000772
Max Morin787eeed2016-06-23 10:42:07 +0200773 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
774 return -1;
775 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000776
Max Morin787eeed2016-06-23 10:42:07 +0200777 *enabled = muted;
niklase@google.com470e71d2011-07-07 08:21:25 +0000778
Max Morin098e6c52016-06-28 09:36:25 +0200779 if (muted) {
780 LOG(INFO) << __FUNCTION__ << " output: muted";
781 } else {
782 LOG(INFO) << __FUNCTION__ << " output: not muted";
783 }
Max Morin787eeed2016-06-23 10:42:07 +0200784 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000785}
786
787// ----------------------------------------------------------------------------
788// MicrophoneMuteIsAvailable
789// ----------------------------------------------------------------------------
790
Max Morin787eeed2016-06-23 10:42:07 +0200791int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200792 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200793 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000794
Max Morin787eeed2016-06-23 10:42:07 +0200795 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000796
Max Morin787eeed2016-06-23 10:42:07 +0200797 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
798 return -1;
799 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000800
Max Morin787eeed2016-06-23 10:42:07 +0200801 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000802
Max Morin098e6c52016-06-28 09:36:25 +0200803 if (isAvailable) {
804 LOG(INFO) << __FUNCTION__ << " output: available";
805 } else {
806 LOG(INFO) << __FUNCTION__ << " output: not available";
807 }
Max Morin787eeed2016-06-23 10:42:07 +0200808 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000809}
810
811// ----------------------------------------------------------------------------
812// SetMicrophoneMute
813// ----------------------------------------------------------------------------
814
Max Morin787eeed2016-06-23 10:42:07 +0200815int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200816 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200817 CHECK_INITIALIZED();
818 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000819}
820
821// ----------------------------------------------------------------------------
822// MicrophoneMute
823// ----------------------------------------------------------------------------
824
Max Morin787eeed2016-06-23 10:42:07 +0200825int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200826 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200827 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000828
Max Morin787eeed2016-06-23 10:42:07 +0200829 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000830
Max Morin787eeed2016-06-23 10:42:07 +0200831 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
832 return -1;
833 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000834
Max Morin787eeed2016-06-23 10:42:07 +0200835 *enabled = muted;
niklase@google.com470e71d2011-07-07 08:21:25 +0000836
Max Morin098e6c52016-06-28 09:36:25 +0200837 if (muted) {
838 LOG(INFO) << __FUNCTION__ << " output: muted";
839 } else {
840 LOG(INFO) << __FUNCTION__ << " output: not muted";
841 }
Max Morin787eeed2016-06-23 10:42:07 +0200842 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000843}
844
845// ----------------------------------------------------------------------------
846// MicrophoneBoostIsAvailable
847// ----------------------------------------------------------------------------
848
Max Morin787eeed2016-06-23 10:42:07 +0200849int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200850 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200851 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000852
Max Morin787eeed2016-06-23 10:42:07 +0200853 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000854
Max Morin787eeed2016-06-23 10:42:07 +0200855 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
856 return -1;
857 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000858
Max Morin787eeed2016-06-23 10:42:07 +0200859 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000860
Max Morin098e6c52016-06-28 09:36:25 +0200861 if (isAvailable) {
862 LOG(INFO) << __FUNCTION__ << " output: available";
863 } else {
864 LOG(INFO) << __FUNCTION__ << " output: not available";
865 }
Max Morin787eeed2016-06-23 10:42:07 +0200866 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000867}
868
869// ----------------------------------------------------------------------------
870// SetMicrophoneBoost
871// ----------------------------------------------------------------------------
872
Max Morin787eeed2016-06-23 10:42:07 +0200873int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200874 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200875 CHECK_INITIALIZED();
876 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000877}
878
879// ----------------------------------------------------------------------------
880// MicrophoneBoost
881// ----------------------------------------------------------------------------
882
Max Morin787eeed2016-06-23 10:42:07 +0200883int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200884 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200885 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000886
Max Morin787eeed2016-06-23 10:42:07 +0200887 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000888
Max Morin787eeed2016-06-23 10:42:07 +0200889 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
890 return -1;
891 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000892
Max Morin787eeed2016-06-23 10:42:07 +0200893 *enabled = onOff;
niklase@google.com470e71d2011-07-07 08:21:25 +0000894
Max Morin098e6c52016-06-28 09:36:25 +0200895 if (onOff) {
896 LOG(INFO) << __FUNCTION__ << " output: enabled";
897 } else {
898 LOG(INFO) << __FUNCTION__ << " output: not enabled";
899 }
Max Morin787eeed2016-06-23 10:42:07 +0200900 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000901}
902
903// ----------------------------------------------------------------------------
904// MicrophoneVolumeIsAvailable
905// ----------------------------------------------------------------------------
906
Max Morin787eeed2016-06-23 10:42:07 +0200907int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200908 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200909 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000910
Max Morin787eeed2016-06-23 10:42:07 +0200911 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000912
Max Morin787eeed2016-06-23 10:42:07 +0200913 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
914 return -1;
915 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000916
Max Morin787eeed2016-06-23 10:42:07 +0200917 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000918
Max Morin098e6c52016-06-28 09:36:25 +0200919 if (isAvailable) {
920 LOG(INFO) << __FUNCTION__ << " output: available";
921 } else {
922 LOG(INFO) << __FUNCTION__ << " output: not available";
923 }
Max Morin787eeed2016-06-23 10:42:07 +0200924 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000925}
926
927// ----------------------------------------------------------------------------
928// SetMicrophoneVolume
929// ----------------------------------------------------------------------------
930
Max Morin787eeed2016-06-23 10:42:07 +0200931int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200932 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200933 CHECK_INITIALIZED();
934 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000935}
936
937// ----------------------------------------------------------------------------
938// MicrophoneVolume
939// ----------------------------------------------------------------------------
940
Max Morin787eeed2016-06-23 10:42:07 +0200941int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200942 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200943 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000944
Max Morin787eeed2016-06-23 10:42:07 +0200945 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000946
Max Morin787eeed2016-06-23 10:42:07 +0200947 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
948 return -1;
949 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000950
Max Morin787eeed2016-06-23 10:42:07 +0200951 *volume = level;
niklase@google.com470e71d2011-07-07 08:21:25 +0000952
Max Morin098e6c52016-06-28 09:36:25 +0200953 LOG(INFO) << __FUNCTION__ << " output: volume = " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200954 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000955}
956
957// ----------------------------------------------------------------------------
958// StereoRecordingIsAvailable
959// ----------------------------------------------------------------------------
960
Max Morin787eeed2016-06-23 10:42:07 +0200961int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
962 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200963 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200964 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000965
Max Morin787eeed2016-06-23 10:42:07 +0200966 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000967
Max Morin787eeed2016-06-23 10:42:07 +0200968 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
969 return -1;
970 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000971
Max Morin787eeed2016-06-23 10:42:07 +0200972 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +0000973
Max Morin098e6c52016-06-28 09:36:25 +0200974 if (isAvailable) {
975 LOG(INFO) << __FUNCTION__ << " output: available";
976 } else {
977 LOG(INFO) << __FUNCTION__ << " output: not available";
978 }
Max Morin787eeed2016-06-23 10:42:07 +0200979 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000980}
981
982// ----------------------------------------------------------------------------
983// SetStereoRecording
984// ----------------------------------------------------------------------------
985
Max Morin787eeed2016-06-23 10:42:07 +0200986int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200987 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200988 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000989
Max Morin787eeed2016-06-23 10:42:07 +0200990 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200991 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200992 return -1;
993 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000994
Max Morin787eeed2016-06-23 10:42:07 +0200995 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200996 if (enable) {
997 LOG(WARNING) << "failed to enable stereo recording";
998 } else {
999 LOG(WARNING) << "failed to disable stereo recording";
1000 }
Max Morin787eeed2016-06-23 10:42:07 +02001001 return -1;
1002 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001003
Max Morin787eeed2016-06-23 10:42:07 +02001004 int8_t nChannels(1);
1005 if (enable) {
1006 nChannels = 2;
1007 }
1008 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001009
Max Morin787eeed2016-06-23 10:42:07 +02001010 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001011}
1012
1013// ----------------------------------------------------------------------------
1014// StereoRecording
1015// ----------------------------------------------------------------------------
1016
Max Morin787eeed2016-06-23 10:42:07 +02001017int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001018 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001019 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001020
Max Morin787eeed2016-06-23 10:42:07 +02001021 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001022
Max Morin787eeed2016-06-23 10:42:07 +02001023 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
1024 return -1;
1025 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001026
Max Morin787eeed2016-06-23 10:42:07 +02001027 *enabled = stereo;
niklase@google.com470e71d2011-07-07 08:21:25 +00001028
Max Morin098e6c52016-06-28 09:36:25 +02001029 if (stereo) {
1030 LOG(INFO) << __FUNCTION__ << " output: enabled";
1031 } else {
1032 LOG(INFO) << __FUNCTION__ << " output: not enabled";
1033 }
Max Morin787eeed2016-06-23 10:42:07 +02001034 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001035}
1036
1037// ----------------------------------------------------------------------------
1038// SetRecordingChannel
1039// ----------------------------------------------------------------------------
1040
Max Morin787eeed2016-06-23 10:42:07 +02001041int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
1042 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +02001043 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +02001044 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +02001045 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +02001046 } else {
Max Morin098e6c52016-06-28 09:36:25 +02001047 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +02001048 }
1049 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001050
Max Morin787eeed2016-06-23 10:42:07 +02001051 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001052
Max Morin787eeed2016-06-23 10:42:07 +02001053 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001054 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001055 return -1;
1056 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001057
Max Morin787eeed2016-06-23 10:42:07 +02001058 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +00001059}
1060
1061// ----------------------------------------------------------------------------
1062// RecordingChannel
1063// ----------------------------------------------------------------------------
1064
Max Morin787eeed2016-06-23 10:42:07 +02001065int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +02001066 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001067 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001068
Max Morin787eeed2016-06-23 10:42:07 +02001069 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001070
Max Morin787eeed2016-06-23 10:42:07 +02001071 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
1072 return -1;
1073 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001074
Max Morin787eeed2016-06-23 10:42:07 +02001075 *channel = chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001076
Max Morin787eeed2016-06-23 10:42:07 +02001077 if (*channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +02001078 LOG(INFO) << __FUNCTION__ << " output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001079 } else if (*channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +02001080 LOG(INFO) << __FUNCTION__ << " output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001081 } else {
Max Morin098e6c52016-06-28 09:36:25 +02001082 LOG(INFO) << __FUNCTION__ << " output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001083 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001084
Max Morin787eeed2016-06-23 10:42:07 +02001085 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001086}
1087
1088// ----------------------------------------------------------------------------
1089// StereoPlayoutIsAvailable
1090// ----------------------------------------------------------------------------
1091
Max Morin787eeed2016-06-23 10:42:07 +02001092int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001093 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001094 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001095
Max Morin787eeed2016-06-23 10:42:07 +02001096 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001097
Max Morin787eeed2016-06-23 10:42:07 +02001098 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1099 return -1;
1100 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001101
Max Morin787eeed2016-06-23 10:42:07 +02001102 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001103
Max Morin098e6c52016-06-28 09:36:25 +02001104 if (isAvailable) {
1105 LOG(INFO) << __FUNCTION__ << " output: available";
1106 } else {
1107 LOG(INFO) << __FUNCTION__ << " output: not available";
1108 }
Max Morin787eeed2016-06-23 10:42:07 +02001109 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001110}
1111
1112// ----------------------------------------------------------------------------
1113// SetStereoPlayout
1114// ----------------------------------------------------------------------------
1115
Max Morin787eeed2016-06-23 10:42:07 +02001116int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001117 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001118 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001119
Max Morin787eeed2016-06-23 10:42:07 +02001120 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001121 LOG(LERROR)
1122 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001123 return -1;
1124 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001125
Max Morin787eeed2016-06-23 10:42:07 +02001126 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001127 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001128 return -1;
1129 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001130
Max Morin787eeed2016-06-23 10:42:07 +02001131 int8_t nChannels(1);
1132 if (enable) {
1133 nChannels = 2;
1134 }
1135 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001136
Max Morin787eeed2016-06-23 10:42:07 +02001137 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001138}
1139
1140// ----------------------------------------------------------------------------
1141// StereoPlayout
1142// ----------------------------------------------------------------------------
1143
Max Morin787eeed2016-06-23 10:42:07 +02001144int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001145 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001146 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001147
Max Morin787eeed2016-06-23 10:42:07 +02001148 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001149
Max Morin787eeed2016-06-23 10:42:07 +02001150 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1151 return -1;
1152 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001153
Max Morin787eeed2016-06-23 10:42:07 +02001154 *enabled = stereo;
niklase@google.com470e71d2011-07-07 08:21:25 +00001155
Max Morin098e6c52016-06-28 09:36:25 +02001156 if (stereo) {
1157 LOG(INFO) << __FUNCTION__ << " output: enabled";
1158 } else {
1159 LOG(INFO) << __FUNCTION__ << " output: not enabled";
1160 }
Max Morin787eeed2016-06-23 10:42:07 +02001161 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001162}
1163
1164// ----------------------------------------------------------------------------
1165// SetAGC
1166// ----------------------------------------------------------------------------
1167
Max Morin787eeed2016-06-23 10:42:07 +02001168int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001169 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001170 CHECK_INITIALIZED();
1171 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001172}
1173
1174// ----------------------------------------------------------------------------
1175// AGC
1176// ----------------------------------------------------------------------------
1177
Max Morin787eeed2016-06-23 10:42:07 +02001178bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001179 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001180 CHECK_INITIALIZED_BOOL();
1181 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001182}
1183
1184// ----------------------------------------------------------------------------
1185// PlayoutIsAvailable
1186// ----------------------------------------------------------------------------
1187
Max Morin787eeed2016-06-23 10:42:07 +02001188int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001189 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001190 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001191
Max Morin787eeed2016-06-23 10:42:07 +02001192 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001193
Max Morin787eeed2016-06-23 10:42:07 +02001194 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1195 return -1;
1196 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001197
Max Morin787eeed2016-06-23 10:42:07 +02001198 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001199
Max Morin098e6c52016-06-28 09:36:25 +02001200 if (isAvailable) {
1201 LOG(INFO) << __FUNCTION__ << " output: available";
1202 } else {
1203 LOG(INFO) << __FUNCTION__ << " output: not available";
1204 }
Max Morin787eeed2016-06-23 10:42:07 +02001205 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001206}
1207
1208// ----------------------------------------------------------------------------
1209// RecordingIsAvailable
1210// ----------------------------------------------------------------------------
1211
Max Morin787eeed2016-06-23 10:42:07 +02001212int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001213 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001214 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001215
Max Morin787eeed2016-06-23 10:42:07 +02001216 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001217
Max Morin787eeed2016-06-23 10:42:07 +02001218 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1219 return -1;
1220 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001221
Max Morin787eeed2016-06-23 10:42:07 +02001222 *available = isAvailable;
niklase@google.com470e71d2011-07-07 08:21:25 +00001223
Max Morin098e6c52016-06-28 09:36:25 +02001224 if (isAvailable) {
1225 LOG(INFO) << __FUNCTION__ << " output: available";
1226 } else {
1227 LOG(INFO) << __FUNCTION__ << " output: not available";
1228 }
Max Morin787eeed2016-06-23 10:42:07 +02001229 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001230}
1231
1232// ----------------------------------------------------------------------------
1233// MaxMicrophoneVolume
1234// ----------------------------------------------------------------------------
1235
Max Morin787eeed2016-06-23 10:42:07 +02001236int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +02001237 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001238 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001239
Max Morin787eeed2016-06-23 10:42:07 +02001240 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001241
Max Morin787eeed2016-06-23 10:42:07 +02001242 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1243 return -1;
1244 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001245
Max Morin787eeed2016-06-23 10:42:07 +02001246 *maxVolume = maxVol;
niklase@google.com470e71d2011-07-07 08:21:25 +00001247
Max Morin098e6c52016-06-28 09:36:25 +02001248 LOG(INFO) << __FUNCTION__ << " output: = " << *maxVolume;
Max Morin787eeed2016-06-23 10:42:07 +02001249 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001250}
1251
1252// ----------------------------------------------------------------------------
1253// MinMicrophoneVolume
1254// ----------------------------------------------------------------------------
1255
Max Morin787eeed2016-06-23 10:42:07 +02001256int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
Max Morin098e6c52016-06-28 09:36:25 +02001257 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001258 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001259
Max Morin787eeed2016-06-23 10:42:07 +02001260 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001261
Max Morin787eeed2016-06-23 10:42:07 +02001262 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1263 return -1;
1264 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001265
Max Morin787eeed2016-06-23 10:42:07 +02001266 *minVolume = minVol;
niklase@google.com470e71d2011-07-07 08:21:25 +00001267
Max Morin098e6c52016-06-28 09:36:25 +02001268 LOG(INFO) << __FUNCTION__ << " output: = " << *minVolume;
Max Morin787eeed2016-06-23 10:42:07 +02001269 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001270}
1271
1272// ----------------------------------------------------------------------------
1273// MicrophoneVolumeStepSize
1274// ----------------------------------------------------------------------------
1275
Max Morin787eeed2016-06-23 10:42:07 +02001276int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1277 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001278 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001279 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001280
Max Morin787eeed2016-06-23 10:42:07 +02001281 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001282
Max Morin787eeed2016-06-23 10:42:07 +02001283 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1284 return -1;
1285 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001286
Max Morin787eeed2016-06-23 10:42:07 +02001287 *stepSize = delta;
niklase@google.com470e71d2011-07-07 08:21:25 +00001288
Max Morin098e6c52016-06-28 09:36:25 +02001289 LOG(INFO) << __FUNCTION__ << " output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001290 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001291}
1292
1293// ----------------------------------------------------------------------------
1294// PlayoutDevices
1295// ----------------------------------------------------------------------------
1296
Max Morin787eeed2016-06-23 10:42:07 +02001297int16_t AudioDeviceModuleImpl::PlayoutDevices() {
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 nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001302
Max Morin098e6c52016-06-28 09:36:25 +02001303 LOG(INFO) << __FUNCTION__ << " output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001304 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001305}
1306
1307// ----------------------------------------------------------------------------
1308// SetPlayoutDevice I (II)
1309// ----------------------------------------------------------------------------
1310
Max Morin787eeed2016-06-23 10:42:07 +02001311int32_t AudioDeviceModuleImpl::SetPlayoutDevice(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->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001315}
1316
1317// ----------------------------------------------------------------------------
1318// SetPlayoutDevice II (II)
1319// ----------------------------------------------------------------------------
1320
Max Morin787eeed2016-06-23 10:42:07 +02001321int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
1322 if (device == kDefaultDevice) {
1323 } else {
1324 }
Max Morin098e6c52016-06-28 09:36:25 +02001325 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001326 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001327
Max Morin787eeed2016-06-23 10:42:07 +02001328 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001329}
1330
1331// ----------------------------------------------------------------------------
1332// PlayoutDeviceName
1333// ----------------------------------------------------------------------------
1334
pbos@webrtc.org25509882013-04-09 10:30:35 +00001335int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1336 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001337 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001338 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001339 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001340 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001341
Max Morin787eeed2016-06-23 10:42:07 +02001342 if (name == NULL) {
1343 _lastError = kAdmErrArgument;
1344 return -1;
1345 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001346
Max Morin787eeed2016-06-23 10:42:07 +02001347 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1348 return -1;
1349 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001350
Max Morin787eeed2016-06-23 10:42:07 +02001351 if (name != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001352 LOG(INFO) << __FUNCTION__ << " output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001353 }
1354 if (guid != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001355 LOG(INFO) << __FUNCTION__ << " output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001356 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001357
Max Morin787eeed2016-06-23 10:42:07 +02001358 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001359}
1360
1361// ----------------------------------------------------------------------------
1362// RecordingDeviceName
1363// ----------------------------------------------------------------------------
1364
pbos@webrtc.org25509882013-04-09 10:30:35 +00001365int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1366 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001367 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001368 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001369 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001370 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001371
Max Morin787eeed2016-06-23 10:42:07 +02001372 if (name == NULL) {
1373 _lastError = kAdmErrArgument;
1374 return -1;
1375 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001376
Max Morin787eeed2016-06-23 10:42:07 +02001377 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1378 return -1;
1379 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001380
Max Morin787eeed2016-06-23 10:42:07 +02001381 if (name != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001382 LOG(INFO) << __FUNCTION__ << " output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001383 }
1384 if (guid != NULL) {
Max Morin098e6c52016-06-28 09:36:25 +02001385 LOG(INFO) << __FUNCTION__ << " output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001386 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001387
Max Morin787eeed2016-06-23 10:42:07 +02001388 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001389}
1390
1391// ----------------------------------------------------------------------------
1392// RecordingDevices
1393// ----------------------------------------------------------------------------
1394
Max Morin787eeed2016-06-23 10:42:07 +02001395int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001396 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001397 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001398
Max Morin787eeed2016-06-23 10:42:07 +02001399 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001400
Max Morin098e6c52016-06-28 09:36:25 +02001401 LOG(INFO) << __FUNCTION__ << " output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001402 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001403}
1404
1405// ----------------------------------------------------------------------------
1406// SetRecordingDevice I (II)
1407// ----------------------------------------------------------------------------
1408
Max Morin787eeed2016-06-23 10:42:07 +02001409int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001410 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001411 CHECK_INITIALIZED();
1412 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001413}
1414
1415// ----------------------------------------------------------------------------
1416// SetRecordingDevice II (II)
1417// ----------------------------------------------------------------------------
1418
Max Morin787eeed2016-06-23 10:42:07 +02001419int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
1420 if (device == kDefaultDevice) {
1421 } else {
1422 }
Max Morin098e6c52016-06-28 09:36:25 +02001423 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001424 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001425
Max Morin787eeed2016-06-23 10:42:07 +02001426 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001427}
1428
1429// ----------------------------------------------------------------------------
1430// InitPlayout
1431// ----------------------------------------------------------------------------
1432
Max Morin787eeed2016-06-23 10:42:07 +02001433int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001434 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001435 CHECK_INITIALIZED();
1436 _audioDeviceBuffer.InitPlayout();
1437 return (_ptrAudioDevice->InitPlayout());
niklase@google.com470e71d2011-07-07 08:21:25 +00001438}
1439
1440// ----------------------------------------------------------------------------
1441// InitRecording
1442// ----------------------------------------------------------------------------
1443
Max Morin787eeed2016-06-23 10:42:07 +02001444int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001445 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001446 CHECK_INITIALIZED();
1447 _audioDeviceBuffer.InitRecording();
1448 return (_ptrAudioDevice->InitRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001449}
1450
1451// ----------------------------------------------------------------------------
1452// PlayoutIsInitialized
1453// ----------------------------------------------------------------------------
1454
Max Morin787eeed2016-06-23 10:42:07 +02001455bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001456 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001457 CHECK_INITIALIZED_BOOL();
1458 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001459}
1460
1461// ----------------------------------------------------------------------------
1462// RecordingIsInitialized
1463// ----------------------------------------------------------------------------
1464
Max Morin787eeed2016-06-23 10:42:07 +02001465bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001466 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001467 CHECK_INITIALIZED_BOOL();
1468 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001469}
1470
1471// ----------------------------------------------------------------------------
1472// StartPlayout
1473// ----------------------------------------------------------------------------
1474
Max Morin787eeed2016-06-23 10:42:07 +02001475int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001476 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001477 CHECK_INITIALIZED();
1478 return (_ptrAudioDevice->StartPlayout());
niklase@google.com470e71d2011-07-07 08:21:25 +00001479}
1480
1481// ----------------------------------------------------------------------------
1482// StopPlayout
1483// ----------------------------------------------------------------------------
1484
Max Morin787eeed2016-06-23 10:42:07 +02001485int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001486 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001487 CHECK_INITIALIZED();
1488 return (_ptrAudioDevice->StopPlayout());
niklase@google.com470e71d2011-07-07 08:21:25 +00001489}
1490
1491// ----------------------------------------------------------------------------
1492// Playing
1493// ----------------------------------------------------------------------------
1494
Max Morin787eeed2016-06-23 10:42:07 +02001495bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001496 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001497 CHECK_INITIALIZED_BOOL();
1498 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001499}
1500
1501// ----------------------------------------------------------------------------
1502// StartRecording
1503// ----------------------------------------------------------------------------
1504
Max Morin787eeed2016-06-23 10:42:07 +02001505int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001506 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001507 CHECK_INITIALIZED();
1508 return (_ptrAudioDevice->StartRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001509}
1510// ----------------------------------------------------------------------------
1511// StopRecording
1512// ----------------------------------------------------------------------------
1513
Max Morin787eeed2016-06-23 10:42:07 +02001514int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001515 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001516 CHECK_INITIALIZED();
1517 return (_ptrAudioDevice->StopRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001518}
1519
1520// ----------------------------------------------------------------------------
1521// Recording
1522// ----------------------------------------------------------------------------
1523
Max Morin787eeed2016-06-23 10:42:07 +02001524bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001525 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001526 CHECK_INITIALIZED_BOOL();
1527 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001528}
1529
1530// ----------------------------------------------------------------------------
1531// RegisterEventObserver
1532// ----------------------------------------------------------------------------
1533
Max Morin787eeed2016-06-23 10:42:07 +02001534int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1535 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001536 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001537 CriticalSectionScoped lock(&_critSectEventCb);
1538 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001539
Max Morin787eeed2016-06-23 10:42:07 +02001540 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001541}
1542
1543// ----------------------------------------------------------------------------
1544// RegisterAudioCallback
1545// ----------------------------------------------------------------------------
1546
Max Morin787eeed2016-06-23 10:42:07 +02001547int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1548 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001549 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001550 CriticalSectionScoped lock(&_critSectAudioCb);
1551 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001552
Max Morin787eeed2016-06-23 10:42:07 +02001553 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001554}
1555
1556// ----------------------------------------------------------------------------
1557// StartRawInputFileRecording
1558// ----------------------------------------------------------------------------
1559
pbos@webrtc.org25509882013-04-09 10:30:35 +00001560int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001561 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001562 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001563 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001564
Max Morin787eeed2016-06-23 10:42:07 +02001565 if (NULL == pcmFileNameUTF8) {
1566 return -1;
1567 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001568
Max Morin787eeed2016-06-23 10:42:07 +02001569 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001570}
1571
1572// ----------------------------------------------------------------------------
1573// StopRawInputFileRecording
1574// ----------------------------------------------------------------------------
1575
Max Morin787eeed2016-06-23 10:42:07 +02001576int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001577 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001578 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001579
Max Morin787eeed2016-06-23 10:42:07 +02001580 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001581}
1582
1583// ----------------------------------------------------------------------------
1584// StartRawOutputFileRecording
1585// ----------------------------------------------------------------------------
1586
pbos@webrtc.org25509882013-04-09 10:30:35 +00001587int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001588 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001589 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001590 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001591
Max Morin787eeed2016-06-23 10:42:07 +02001592 if (NULL == pcmFileNameUTF8) {
1593 return -1;
1594 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001595
Max Morin787eeed2016-06-23 10:42:07 +02001596 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001597}
1598
1599// ----------------------------------------------------------------------------
1600// StopRawOutputFileRecording
1601// ----------------------------------------------------------------------------
1602
Max Morin787eeed2016-06-23 10:42:07 +02001603int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001604 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001605 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001606
Max Morin787eeed2016-06-23 10:42:07 +02001607 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001608}
1609
1610// ----------------------------------------------------------------------------
1611// SetPlayoutBuffer
1612// ----------------------------------------------------------------------------
1613
Max Morin787eeed2016-06-23 10:42:07 +02001614int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1615 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001616 if (type == kFixedBufferSize) {
1617 LOG(INFO) << __FUNCTION__ << "("
1618 << "fixed buffer, " << sizeMS << "ms"
1619 << ")";
1620 } else if (type == kAdaptiveBufferSize) {
1621 LOG(INFO) << __FUNCTION__ << "("
1622 << "adaptive buffer, " << sizeMS << "ms"
1623 << ")";
1624 } else {
1625 LOG(INFO) << __FUNCTION__ << "("
1626 << "?, " << sizeMS << "ms"
1627 << ")";
1628 }
Max Morin787eeed2016-06-23 10:42:07 +02001629 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001630
Max Morin787eeed2016-06-23 10:42:07 +02001631 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001632 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1633 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001634 return -1;
1635 }
1636
1637 int32_t ret(0);
1638
1639 if (kFixedBufferSize == type) {
1640 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1641 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001642 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001643 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001644 }
Max Morin787eeed2016-06-23 10:42:07 +02001645 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001646
Max Morin787eeed2016-06-23 10:42:07 +02001647 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001648 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1649 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001650 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001651
Max Morin787eeed2016-06-23 10:42:07 +02001652 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001653}
1654
1655// ----------------------------------------------------------------------------
1656// PlayoutBuffer
1657// ----------------------------------------------------------------------------
1658
Max Morin787eeed2016-06-23 10:42:07 +02001659int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1660 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001661 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001662 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001663
Max Morin787eeed2016-06-23 10:42:07 +02001664 BufferType bufType;
1665 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001666
Max Morin787eeed2016-06-23 10:42:07 +02001667 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001668 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001669 return -1;
1670 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001671
Max Morin787eeed2016-06-23 10:42:07 +02001672 *type = bufType;
1673 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001674
Max Morin098e6c52016-06-28 09:36:25 +02001675 LOG(INFO) << __FUNCTION__ << " output: type = " << *type
1676 << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001677 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001678}
1679
1680// ----------------------------------------------------------------------------
1681// PlayoutDelay
1682// ----------------------------------------------------------------------------
1683
Max Morin787eeed2016-06-23 10:42:07 +02001684int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001685 LOG(LS_VERBOSE) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001686 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001687
Max Morin787eeed2016-06-23 10:42:07 +02001688 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001689
Max Morin787eeed2016-06-23 10:42:07 +02001690 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001691 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001692 return -1;
1693 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001694
Max Morin787eeed2016-06-23 10:42:07 +02001695 *delayMS = delay;
niklase@google.com470e71d2011-07-07 08:21:25 +00001696
Max Morin098e6c52016-06-28 09:36:25 +02001697 LOG(LS_VERBOSE) << __FUNCTION__ << " output: delayMS = " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001698 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001699}
1700
1701// ----------------------------------------------------------------------------
1702// RecordingDelay
1703// ----------------------------------------------------------------------------
1704
Max Morin787eeed2016-06-23 10:42:07 +02001705int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001706 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001707 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001708
Max Morin787eeed2016-06-23 10:42:07 +02001709 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001710
Max Morin787eeed2016-06-23 10:42:07 +02001711 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001712 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001713 return -1;
1714 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001715
Max Morin787eeed2016-06-23 10:42:07 +02001716 *delayMS = delay;
niklase@google.com470e71d2011-07-07 08:21:25 +00001717
Max Morin098e6c52016-06-28 09:36:25 +02001718 LOG(INFO) << __FUNCTION__ << " output: delayMS = " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001719 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001720}
1721
1722// ----------------------------------------------------------------------------
1723// CPULoad
1724// ----------------------------------------------------------------------------
1725
Max Morin787eeed2016-06-23 10:42:07 +02001726int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001727 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001728 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001729
Max Morin787eeed2016-06-23 10:42:07 +02001730 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001731
Max Morin787eeed2016-06-23 10:42:07 +02001732 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001733 LOG(LERROR) << "failed to retrieve the CPU load";
Max Morin787eeed2016-06-23 10:42:07 +02001734 return -1;
1735 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001736
Max Morin787eeed2016-06-23 10:42:07 +02001737 *load = cpuLoad;
niklase@google.com470e71d2011-07-07 08:21:25 +00001738
Max Morin098e6c52016-06-28 09:36:25 +02001739 LOG(INFO) << __FUNCTION__ << " output: load = " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001740 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001741}
1742
1743// ----------------------------------------------------------------------------
1744// SetRecordingSampleRate
1745// ----------------------------------------------------------------------------
1746
Max Morin787eeed2016-06-23 10:42:07 +02001747int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1748 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001749 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001750 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001751
Max Morin787eeed2016-06-23 10:42:07 +02001752 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1753 return -1;
1754 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001755
Max Morin787eeed2016-06-23 10:42:07 +02001756 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001757}
1758
1759// ----------------------------------------------------------------------------
1760// RecordingSampleRate
1761// ----------------------------------------------------------------------------
1762
Max Morin787eeed2016-06-23 10:42:07 +02001763int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1764 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001765 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001766 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001767
Max Morin787eeed2016-06-23 10:42:07 +02001768 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001769
Max Morin787eeed2016-06-23 10:42:07 +02001770 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001771 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001772 return -1;
1773 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001774
Max Morin787eeed2016-06-23 10:42:07 +02001775 *samplesPerSec = sampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +00001776
Max Morin098e6c52016-06-28 09:36:25 +02001777 LOG(INFO) << __FUNCTION__ << " output: samplesPerSec = " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001778 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001779}
1780
1781// ----------------------------------------------------------------------------
1782// SetPlayoutSampleRate
1783// ----------------------------------------------------------------------------
1784
Max Morin787eeed2016-06-23 10:42:07 +02001785int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1786 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001787 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001788 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001789
Max Morin787eeed2016-06-23 10:42:07 +02001790 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1791 return -1;
1792 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001793
Max Morin787eeed2016-06-23 10:42:07 +02001794 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001795}
1796
1797// ----------------------------------------------------------------------------
1798// PlayoutSampleRate
1799// ----------------------------------------------------------------------------
1800
Max Morin787eeed2016-06-23 10:42:07 +02001801int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1802 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001803 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001804 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001805
Max Morin787eeed2016-06-23 10:42:07 +02001806 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001807
Max Morin787eeed2016-06-23 10:42:07 +02001808 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001809 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001810 return -1;
1811 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001812
Max Morin787eeed2016-06-23 10:42:07 +02001813 *samplesPerSec = sampleRate;
niklase@google.com470e71d2011-07-07 08:21:25 +00001814
Max Morin098e6c52016-06-28 09:36:25 +02001815 LOG(INFO) << __FUNCTION__ << " output: samplesPerSec = " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001816 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001817}
1818
1819// ----------------------------------------------------------------------------
1820// ResetAudioDevice
1821// ----------------------------------------------------------------------------
1822
Max Morin787eeed2016-06-23 10:42:07 +02001823int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001824 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001825 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001826
Max Morin787eeed2016-06-23 10:42:07 +02001827 if (_ptrAudioDevice->ResetAudioDevice() == -1) {
1828 return -1;
1829 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001830
Max Morin787eeed2016-06-23 10:42:07 +02001831 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001832}
1833
1834// ----------------------------------------------------------------------------
1835// SetLoudspeakerStatus
1836// ----------------------------------------------------------------------------
1837
Max Morin787eeed2016-06-23 10:42:07 +02001838int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001839 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001840 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001841
Max Morin787eeed2016-06-23 10:42:07 +02001842 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1843 return -1;
1844 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001845
Max Morin787eeed2016-06-23 10:42:07 +02001846 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001847}
1848
1849// ----------------------------------------------------------------------------
1850// GetLoudspeakerStatus
1851// ----------------------------------------------------------------------------
1852
henrikac14f5ff2015-09-23 14:08:33 +02001853int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001854 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001855 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001856 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001857 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001858 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001859 }
Max Morin098e6c52016-06-28 09:36:25 +02001860 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1861 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001862}
1863
henrikac14f5ff2015-09-23 14:08:33 +02001864bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
Max Morin098e6c52016-06-28 09:36:25 +02001865 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001866 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001867 bool isEnabled = _ptrAudioDevice->BuiltInAECIsEnabled();
1868 if (isEnabled) {
1869 LOG(INFO) << __FUNCTION__ << " output: enabled";
1870 } else {
1871 LOG(INFO) << __FUNCTION__ << " output: not enabled";
1872 }
1873 return isEnabled;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001874}
1875
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001876bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001877 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001878 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001879 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
1880 if (isAvailable) {
1881 LOG(INFO) << __FUNCTION__ << " output: available";
1882 } else {
1883 LOG(INFO) << __FUNCTION__ << " output: not available";
1884 }
1885 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001886}
1887
henrikac14f5ff2015-09-23 14:08:33 +02001888int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001889 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001890 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001891 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
1892 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1893 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001894}
1895
1896bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001897 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001898 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001899 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
1900 if (isAvailable) {
1901 LOG(INFO) << __FUNCTION__ << " output: available";
1902 } else {
1903 LOG(INFO) << __FUNCTION__ << " output: not available";
1904 }
1905 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001906}
1907
1908int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001909 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001910 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001911 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
1912 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1913 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001914}
1915
1916bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001917 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001918 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001919 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
1920 if (isAvailable) {
1921 LOG(INFO) << __FUNCTION__ << " output: available";
1922 } else {
1923 LOG(INFO) << __FUNCTION__ << " output: not available";
1924 }
1925 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001926}
1927
1928int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001929 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001930 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001931 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
1932 LOG(INFO) << __FUNCTION__ << " output: " << ok;
1933 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001934}
1935
henrikaba35d052015-07-14 17:04:08 +02001936int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1937 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001938 LOG(INFO) << __FUNCTION__;
1939 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
1940 LOG(INFO) << __FUNCTION__ << " output: " << r;
1941 return r;
henrikaba35d052015-07-14 17:04:08 +02001942}
1943
1944int AudioDeviceModuleImpl::GetRecordAudioParameters(
1945 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001946 LOG(INFO) << __FUNCTION__;
1947 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
1948 LOG(INFO) << __FUNCTION__ << " output: " << r;
1949 return r;
henrikaba35d052015-07-14 17:04:08 +02001950}
1951
niklase@google.com470e71d2011-07-07 08:21:25 +00001952// ============================================================================
1953// Private Methods
1954// ============================================================================
1955
1956// ----------------------------------------------------------------------------
1957// Platform
1958// ----------------------------------------------------------------------------
1959
Max Morin787eeed2016-06-23 10:42:07 +02001960AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001961 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001962 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001963}
1964
1965// ----------------------------------------------------------------------------
1966// PlatformAudioLayer
1967// ----------------------------------------------------------------------------
1968
Max Morin787eeed2016-06-23 10:42:07 +02001969AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1970 const {
Max Morin098e6c52016-06-28 09:36:25 +02001971 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001972 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001973}
1974
1975} // namespace webrtc