blob: ad643e9684688a5ae9cf641364bdd3425f31a817 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
xians@webrtc.org20aabbb2012-02-20 09:17:41 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Max Morin84cab202016-07-01 13:35:19 +020011#include "webrtc/base/checks.h"
Max Morin098e6c52016-06-28 09:36:25 +020012#include "webrtc/base/logging.h"
henrika918b5542016-09-19 15:44:09 +020013#include "webrtc/base/checks.h"
Peter Boström1d194412016-03-21 16:44:31 +010014#include "webrtc/base/refcount.h"
Niels Möllerd28db7f2016-05-10 16:31:47 +020015#include "webrtc/base/timeutils.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000016#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
17#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020018#include "webrtc/modules/audio_device/audio_device_generic.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000019#include "webrtc/modules/audio_device/audio_device_impl.h"
Max Morin84cab202016-07-01 13:35:19 +020020#include "webrtc/system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000022#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000023#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020026#include "audio_device_wave_win.h"
27#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
28#include "audio_device_core_win.h"
29#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000030#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020031#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020032#include "webrtc/modules/audio_device/android/audio_device_template.h"
33#include "webrtc/modules/audio_device/android/audio_manager.h"
34#include "webrtc/modules/audio_device/android/audio_record_jni.h"
35#include "webrtc/modules/audio_device/android/audio_track_jni.h"
36#include "webrtc/modules/audio_device/android/opensles_player.h"
henrika918b5542016-09-19 15:44:09 +020037#include "webrtc/modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020039#if defined(LINUX_ALSA)
40#include "audio_device_alsa_linux.h"
41#endif
Tommi68898a22015-05-19 17:28:07 +020042#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020043#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020044#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000045#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020046#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000047#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020048#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000049#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000050
51#if defined(WEBRTC_DUMMY_FILE_DEVICES)
52#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
53#endif
54
pbos@webrtc.org811269d2013-07-11 13:24:38 +000055#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000056#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010057#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000058
Max Morin787eeed2016-06-23 10:42:07 +020059#define CHECK_INITIALIZED() \
60 { \
61 if (!_initialized) { \
62 return -1; \
63 }; \
64 }
niklase@google.com470e71d2011-07-07 08:21:25 +000065
Max Morin787eeed2016-06-23 10:42:07 +020066#define CHECK_INITIALIZED_BOOL() \
67 { \
68 if (!_initialized) { \
69 return false; \
70 }; \
71 }
niklase@google.com470e71d2011-07-07 08:21:25 +000072
Peter Boström1d194412016-03-21 16:44:31 +010073namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000074
niklase@google.com470e71d2011-07-07 08:21:25 +000075// ============================================================================
76// Static methods
77// ============================================================================
78
79// ----------------------------------------------------------------------------
80// AudioDeviceModule::Create()
81// ----------------------------------------------------------------------------
82
Peter Boström4adbbcf2016-05-03 15:51:26 -040083rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010084 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040085 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020086 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020087 // Create the generic ref counted (platform independent) implementation.
88 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
89 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000090
Max Morin787eeed2016-06-23 10:42:07 +020091 // Ensure that the current platform is supported.
92 if (audioDevice->CheckPlatform() == -1) {
93 return nullptr;
94 }
niklase@google.com470e71d2011-07-07 08:21:25 +000095
Max Morin787eeed2016-06-23 10:42:07 +020096 // Create the platform-dependent implementation.
97 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
98 return nullptr;
99 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
Max Morin787eeed2016-06-23 10:42:07 +0200101 // Ensure that the generic audio buffer can communicate with the
102 // platform-specific parts.
103 if (audioDevice->AttachAudioBuffer() == -1) {
104 return nullptr;
105 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
Max Morin787eeed2016-06-23 10:42:07 +0200107 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000108
Max Morin787eeed2016-06-23 10:42:07 +0200109 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110}
111
niklase@google.com470e71d2011-07-07 08:21:25 +0000112// ============================================================================
113// Construction & Destruction
114// ============================================================================
115
116// ----------------------------------------------------------------------------
117// AudioDeviceModuleImpl - ctor
118// ----------------------------------------------------------------------------
119
Max Morin787eeed2016-06-23 10:42:07 +0200120AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
121 const AudioLayer audioLayer)
122 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
123 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
124 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
125 _ptrCbAudioDeviceObserver(NULL),
126 _ptrAudioDevice(NULL),
127 _id(id),
128 _platformAudioLayer(audioLayer),
129 _lastProcessTime(rtc::TimeMillis()),
130 _platformType(kPlatformNotSupported),
131 _initialized(false),
132 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200133 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134}
135
136// ----------------------------------------------------------------------------
137// CheckPlatform
138// ----------------------------------------------------------------------------
139
Max Morin787eeed2016-06-23 10:42:07 +0200140int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200141 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
Max Morin787eeed2016-06-23 10:42:07 +0200143 // Ensure that the current platform is supported
144 //
145 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
147#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200148 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200149 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000150#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200151 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200152 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000153#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200154 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200155 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000156#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200157 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200158 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000159#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200160 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200161 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000162#endif
163
Max Morin787eeed2016-06-23 10:42:07 +0200164 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200165 LOG(LERROR) << "current platform is not supported => this module will self "
166 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200167 return -1;
168 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
Max Morin787eeed2016-06-23 10:42:07 +0200170 // Store valid output results
171 //
172 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
Max Morin787eeed2016-06-23 10:42:07 +0200174 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000175}
176
niklase@google.com470e71d2011-07-07 08:21:25 +0000177// ----------------------------------------------------------------------------
178// CreatePlatformSpecificObjects
179// ----------------------------------------------------------------------------
180
Max Morin787eeed2016-06-23 10:42:07 +0200181int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200182 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
Max Morin787eeed2016-06-23 10:42:07 +0200184 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
xians@google.combf5d2ba2011-08-16 07:44:19 +0000186#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200187 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200188 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000189#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200190 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
noahric6a355902016-08-17 15:19:50 -0700191 if (ptrAudioDevice) {
192 LOG(INFO) << "Will use file-playing dummy device.";
193 } else {
194 // Create a dummy device instead.
195 ptrAudioDevice = new AudioDeviceDummy(Id());
196 LOG(INFO) << "Dummy Audio APIs will be utilized";
197 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000198#else
Max Morin787eeed2016-06-23 10:42:07 +0200199 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
Max Morin787eeed2016-06-23 10:42:07 +0200201// Create the *Windows* implementation of the Audio Device
202//
niklase@google.com470e71d2011-07-07 08:21:25 +0000203#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200204 if ((audioLayer == kWindowsWaveAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000205#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200206 // Wave audio is default if Core audio is not supported in this build
207 || (audioLayer == kPlatformDefaultAudio)
niklase@google.com470e71d2011-07-07 08:21:25 +0000208#endif
Max Morin787eeed2016-06-23 10:42:07 +0200209 ) {
210 // create *Windows Wave Audio* implementation
211 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200212 LOG(INFO) << "Windows Wave APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200213 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000214#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200215 if ((audioLayer == kWindowsCoreAudio) ||
216 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200217 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000218
Max Morin787eeed2016-06-23 10:42:07 +0200219 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
220 // create *Windows Core Audio* implementation
221 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200222 LOG(INFO) << "Windows Core Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200223 } else {
224 // create *Windows Wave Audio* implementation
225 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
226 if (ptrAudioDevice != NULL) {
227 // Core Audio was not supported => revert to Windows Wave instead
228 _platformAudioLayer =
229 kWindowsWaveAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200230 LOG(WARNING) << "Windows Core Audio is *not* supported => Wave APIs "
231 "will be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200232 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000233 }
Max Morin787eeed2016-06-23 10:42:07 +0200234 }
235#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000236#endif // #if defined(_WIN32)
237
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000238#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200239 // Create an Android audio manager.
240 _audioManagerAndroid.reset(new AudioManager());
241 // Select best possible combination of audio layers.
242 if (audioLayer == kPlatformDefaultAudio) {
henrika918b5542016-09-19 15:44:09 +0200243 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
244 _audioManagerAndroid->IsLowLatencyRecordSupported()) {
245 // Use OpenSL ES for both playout and recording.
246 audioLayer = kAndroidOpenSLESAudio;
247 } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
248 !_audioManagerAndroid->IsLowLatencyRecordSupported()) {
249 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200250 // low-latency output audio path.
251 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200252 } else {
henrika918b5542016-09-19 15:44:09 +0200253 // Use Java-based audio in both directions when low-latency output is
254 // not supported.
Max Morin787eeed2016-06-23 10:42:07 +0200255 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000256 }
Max Morin787eeed2016-06-23 10:42:07 +0200257 }
258 AudioManager* audio_manager = _audioManagerAndroid.get();
259 if (audioLayer == kAndroidJavaAudio) {
260 // Java audio for both input and output audio.
261 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
262 audioLayer, audio_manager);
henrika918b5542016-09-19 15:44:09 +0200263 } else if (audioLayer == kAndroidOpenSLESAudio) {
264 // OpenSL ES based audio for both input and output audio.
265 ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
266 audioLayer, audio_manager);
Max Morin787eeed2016-06-23 10:42:07 +0200267 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
268 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
269 // This combination provides low-latency output audio and at the same
270 // time support for HW AEC using the AudioRecord Java API.
271 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
272 audioLayer, audio_manager);
273 } else {
274 // Invalid audio layer.
henrika918b5542016-09-19 15:44:09 +0200275 ptrAudioDevice = nullptr;
Max Morin787eeed2016-06-23 10:42:07 +0200276 }
277// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
Max Morin787eeed2016-06-23 10:42:07 +0200279// Create the *Linux* implementation of the Audio Device
280//
niklase@google.com470e71d2011-07-07 08:21:25 +0000281#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200282 if ((audioLayer == kLinuxPulseAudio) ||
283 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000284#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200285 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000286
Max Morin787eeed2016-06-23 10:42:07 +0200287 // create *Linux PulseAudio* implementation
288 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
Max Morin84cab202016-07-01 13:35:19 +0200289 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200290 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200291 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200292 } else {
293 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000294#endif
295#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200296 // create *Linux ALSA Audio* implementation
297 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
298 if (ptrAudioDevice != NULL) {
299 // Pulse Audio was not supported => revert to ALSA instead
300 _platformAudioLayer =
301 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200302 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
303 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200304 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000305#endif
306#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000307 }
Max Morin787eeed2016-06-23 10:42:07 +0200308#endif
309 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000310#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200311 // create *Linux ALSA Audio* implementation
312 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200313 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000314#endif
Max Morin787eeed2016-06-23 10:42:07 +0200315 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000316#endif // #if defined(WEBRTC_LINUX)
317
Max Morin787eeed2016-06-23 10:42:07 +0200318// Create the *iPhone* implementation of the Audio Device
319//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000320#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200321 if (audioLayer == kPlatformDefaultAudio) {
322 // Create iOS Audio Device implementation.
323 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200324 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200325 }
326// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000327
Max Morin787eeed2016-06-23 10:42:07 +0200328// Create the *Mac* implementation of the Audio Device
329//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000330#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200331 if (audioLayer == kPlatformDefaultAudio) {
332 // Create *Mac Audio* implementation
333 ptrAudioDevice = new AudioDeviceMac(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200334 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200335 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000336#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
Max Morin787eeed2016-06-23 10:42:07 +0200338 // Create the *Dummy* implementation of the Audio Device
339 // Available for all platforms
340 //
341 if (audioLayer == kDummyAudio) {
342 // Create *Dummy Audio* implementation
343 assert(!ptrAudioDevice);
344 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200345 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200346 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000347#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
Max Morin787eeed2016-06-23 10:42:07 +0200349 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200350 LOG(LERROR)
351 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200352 return -1;
353 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000354
Max Morin787eeed2016-06-23 10:42:07 +0200355 // Store valid output pointers
356 //
357 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
Max Morin787eeed2016-06-23 10:42:07 +0200359 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000360}
361
362// ----------------------------------------------------------------------------
363// AttachAudioBuffer
364//
365// Install "bridge" between the platform implemetation and the generic
366// implementation. The "child" shall set the native sampling rate and the
367// number of channels in this function call.
368// ----------------------------------------------------------------------------
369
Max Morin787eeed2016-06-23 10:42:07 +0200370int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200371 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000372
Max Morin787eeed2016-06-23 10:42:07 +0200373 _audioDeviceBuffer.SetId(_id);
374 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
375 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000376}
377
378// ----------------------------------------------------------------------------
379// ~AudioDeviceModuleImpl - dtor
380// ----------------------------------------------------------------------------
381
Max Morin787eeed2016-06-23 10:42:07 +0200382AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200383 LOG(INFO) << __FUNCTION__;
henrika@google.com73d65512011-09-07 15:11:18 +0000384
Max Morin787eeed2016-06-23 10:42:07 +0200385 if (_ptrAudioDevice) {
386 delete _ptrAudioDevice;
387 _ptrAudioDevice = NULL;
388 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000389
Max Morin787eeed2016-06-23 10:42:07 +0200390 delete &_critSect;
391 delete &_critSectEventCb;
392 delete &_critSectAudioCb;
niklase@google.com470e71d2011-07-07 08:21:25 +0000393}
394
395// ============================================================================
396// Module
397// ============================================================================
398
399// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000400// Module::TimeUntilNextProcess
401//
402// Returns the number of milliseconds until the module want a worker thread
403// to call Process().
404// ----------------------------------------------------------------------------
405
Max Morin787eeed2016-06-23 10:42:07 +0200406int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
407 int64_t now = rtc::TimeMillis();
408 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
409 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000410}
411
412// ----------------------------------------------------------------------------
413// Module::Process
414//
415// Check for posted error and warning reports. Generate callbacks if
416// new reports exists.
417// ----------------------------------------------------------------------------
418
Max Morin787eeed2016-06-23 10:42:07 +0200419void AudioDeviceModuleImpl::Process() {
420 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
Max Morin787eeed2016-06-23 10:42:07 +0200422 // kPlayoutWarning
423 if (_ptrAudioDevice->PlayoutWarning()) {
424 CriticalSectionScoped lock(&_critSectEventCb);
425 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200426 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200427 _ptrCbAudioDeviceObserver->OnWarningIsReported(
428 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429 }
Max Morin787eeed2016-06-23 10:42:07 +0200430 _ptrAudioDevice->ClearPlayoutWarning();
431 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000432
Max Morin787eeed2016-06-23 10:42:07 +0200433 // kPlayoutError
434 if (_ptrAudioDevice->PlayoutError()) {
435 CriticalSectionScoped lock(&_critSectEventCb);
436 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200437 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200438 _ptrCbAudioDeviceObserver->OnErrorIsReported(
439 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000440 }
Max Morin787eeed2016-06-23 10:42:07 +0200441 _ptrAudioDevice->ClearPlayoutError();
442 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000443
Max Morin787eeed2016-06-23 10:42:07 +0200444 // kRecordingWarning
445 if (_ptrAudioDevice->RecordingWarning()) {
446 CriticalSectionScoped lock(&_critSectEventCb);
447 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200448 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200449 _ptrCbAudioDeviceObserver->OnWarningIsReported(
450 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000451 }
Max Morin787eeed2016-06-23 10:42:07 +0200452 _ptrAudioDevice->ClearRecordingWarning();
453 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000454
Max Morin787eeed2016-06-23 10:42:07 +0200455 // kRecordingError
456 if (_ptrAudioDevice->RecordingError()) {
457 CriticalSectionScoped lock(&_critSectEventCb);
458 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200459 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200460 _ptrCbAudioDeviceObserver->OnErrorIsReported(
461 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000462 }
Max Morin787eeed2016-06-23 10:42:07 +0200463 _ptrAudioDevice->ClearRecordingError();
464 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000465}
466
467// ============================================================================
468// Public API
469// ============================================================================
470
471// ----------------------------------------------------------------------------
472// ActiveAudioLayer
473// ----------------------------------------------------------------------------
474
henrikab2619892015-05-18 16:49:16 +0200475int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200476 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200477 AudioLayer activeAudio;
478 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
479 return -1;
480 }
481 *audioLayer = activeAudio;
482 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000483}
484
485// ----------------------------------------------------------------------------
486// LastError
487// ----------------------------------------------------------------------------
488
Max Morin787eeed2016-06-23 10:42:07 +0200489AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200490 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200491 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000492}
493
494// ----------------------------------------------------------------------------
495// Init
496// ----------------------------------------------------------------------------
497
Max Morin787eeed2016-06-23 10:42:07 +0200498int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200499 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200500 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000501 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200502 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200503
Max Morin84cab202016-07-01 13:35:19 +0200504 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
505 RTC_HISTOGRAM_ENUMERATION(
506 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
507 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
508 if (status != AudioDeviceGeneric::InitStatus::OK) {
509 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200510 return -1;
511 }
512
513 _initialized = true;
514 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000515}
516
517// ----------------------------------------------------------------------------
518// Terminate
519// ----------------------------------------------------------------------------
520
Max Morin787eeed2016-06-23 10:42:07 +0200521int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200522 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200523 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000524 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200525
526 if (_ptrAudioDevice->Terminate() == -1) {
527 return -1;
528 }
529
530 _initialized = false;
531 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000532}
533
534// ----------------------------------------------------------------------------
535// Initialized
536// ----------------------------------------------------------------------------
537
Max Morin787eeed2016-06-23 10:42:07 +0200538bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200539 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200540 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000541}
542
543// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000544// InitSpeaker
545// ----------------------------------------------------------------------------
546
Max Morin787eeed2016-06-23 10:42:07 +0200547int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200548 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200549 CHECK_INITIALIZED();
550 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000551}
552
553// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000554// InitMicrophone
555// ----------------------------------------------------------------------------
556
Max Morin787eeed2016-06-23 10:42:07 +0200557int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200558 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200559 CHECK_INITIALIZED();
560 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000561}
562
563// ----------------------------------------------------------------------------
564// SpeakerVolumeIsAvailable
565// ----------------------------------------------------------------------------
566
Max Morin787eeed2016-06-23 10:42:07 +0200567int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200568 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200569 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000570
Max Morin787eeed2016-06-23 10:42:07 +0200571 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000572
Max Morin787eeed2016-06-23 10:42:07 +0200573 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
574 return -1;
575 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000576
Max Morin787eeed2016-06-23 10:42:07 +0200577 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200578 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200579 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000580}
581
582// ----------------------------------------------------------------------------
583// SetSpeakerVolume
584// ----------------------------------------------------------------------------
585
Max Morin787eeed2016-06-23 10:42:07 +0200586int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200587 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200588 CHECK_INITIALIZED();
589 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000590}
591
592// ----------------------------------------------------------------------------
593// SpeakerVolume
594// ----------------------------------------------------------------------------
595
Max Morin787eeed2016-06-23 10:42:07 +0200596int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200597 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200598 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000599
Max Morin787eeed2016-06-23 10:42:07 +0200600 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000601
Max Morin787eeed2016-06-23 10:42:07 +0200602 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
603 return -1;
604 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000605
Max Morin787eeed2016-06-23 10:42:07 +0200606 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200607 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200608 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000609}
610
611// ----------------------------------------------------------------------------
612// SetWaveOutVolume
613// ----------------------------------------------------------------------------
614
Max Morin787eeed2016-06-23 10:42:07 +0200615int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft,
616 uint16_t volumeRight) {
Max Morin098e6c52016-06-28 09:36:25 +0200617 LOG(INFO) << __FUNCTION__ << "(" << volumeLeft << ", " << volumeRight << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200618 CHECK_INITIALIZED();
619 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
niklase@google.com470e71d2011-07-07 08:21:25 +0000620}
621
622// ----------------------------------------------------------------------------
623// WaveOutVolume
624// ----------------------------------------------------------------------------
625
Max Morin787eeed2016-06-23 10:42:07 +0200626int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft,
627 uint16_t* volumeRight) const {
Max Morin098e6c52016-06-28 09:36:25 +0200628 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200629 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000630
Max Morin787eeed2016-06-23 10:42:07 +0200631 uint16_t volLeft(0);
632 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000633
Max Morin787eeed2016-06-23 10:42:07 +0200634 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1) {
635 return -1;
636 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000637
Max Morin787eeed2016-06-23 10:42:07 +0200638 *volumeLeft = volLeft;
639 *volumeRight = volRight;
Max Morin2c332bb2016-07-04 09:03:42 +0200640 LOG(INFO) << "output: " << *volumeLeft << ", " << *volumeRight;
niklase@google.com470e71d2011-07-07 08:21:25 +0000641
Max Morin787eeed2016-06-23 10:42:07 +0200642 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000643}
644
645// ----------------------------------------------------------------------------
646// SpeakerIsInitialized
647// ----------------------------------------------------------------------------
648
Max Morin787eeed2016-06-23 10:42:07 +0200649bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200650 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200651 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000652
Max Morin787eeed2016-06-23 10:42:07 +0200653 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200654 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200655 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000656}
657
658// ----------------------------------------------------------------------------
659// MicrophoneIsInitialized
660// ----------------------------------------------------------------------------
661
Max Morin787eeed2016-06-23 10:42:07 +0200662bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200663 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200664 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000665
Max Morin787eeed2016-06-23 10:42:07 +0200666 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200667 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200668 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000669}
670
671// ----------------------------------------------------------------------------
672// MaxSpeakerVolume
673// ----------------------------------------------------------------------------
674
Max Morin787eeed2016-06-23 10:42:07 +0200675int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
676 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000677
Max Morin787eeed2016-06-23 10:42:07 +0200678 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000679
Max Morin787eeed2016-06-23 10:42:07 +0200680 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
681 return -1;
682 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000683
Max Morin787eeed2016-06-23 10:42:07 +0200684 *maxVolume = maxVol;
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 {
693 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000694
Max Morin787eeed2016-06-23 10:42:07 +0200695 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000696
Max Morin787eeed2016-06-23 10:42:07 +0200697 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
698 return -1;
699 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000700
Max Morin787eeed2016-06-23 10:42:07 +0200701 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200702 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000703}
704
705// ----------------------------------------------------------------------------
706// SpeakerVolumeStepSize
707// ----------------------------------------------------------------------------
708
Max Morin787eeed2016-06-23 10:42:07 +0200709int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +0200710 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200711 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000712
Max Morin787eeed2016-06-23 10:42:07 +0200713 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000714
Max Morin787eeed2016-06-23 10:42:07 +0200715 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200716 LOG(LERROR) << "failed to retrieve the speaker-volume step size";
Max Morin787eeed2016-06-23 10:42:07 +0200717 return -1;
718 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000719
Max Morin787eeed2016-06-23 10:42:07 +0200720 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +0200721 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +0200722 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723}
724
725// ----------------------------------------------------------------------------
726// SpeakerMuteIsAvailable
727// ----------------------------------------------------------------------------
728
Max Morin787eeed2016-06-23 10:42:07 +0200729int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200730 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200731 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000732
Max Morin787eeed2016-06-23 10:42:07 +0200733 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000734
Max Morin787eeed2016-06-23 10:42:07 +0200735 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
736 return -1;
737 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000738
Max Morin787eeed2016-06-23 10:42:07 +0200739 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200740 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200741 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000742}
743
744// ----------------------------------------------------------------------------
745// SetSpeakerMute
746// ----------------------------------------------------------------------------
747
Max Morin787eeed2016-06-23 10:42:07 +0200748int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200749 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200750 CHECK_INITIALIZED();
751 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000752}
753
754// ----------------------------------------------------------------------------
755// SpeakerMute
756// ----------------------------------------------------------------------------
757
Max Morin787eeed2016-06-23 10:42:07 +0200758int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200759 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200760 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000761
Max Morin787eeed2016-06-23 10:42:07 +0200762 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000763
Max Morin787eeed2016-06-23 10:42:07 +0200764 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
765 return -1;
766 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000767
Max Morin787eeed2016-06-23 10:42:07 +0200768 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200769 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200770 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000771}
772
773// ----------------------------------------------------------------------------
774// MicrophoneMuteIsAvailable
775// ----------------------------------------------------------------------------
776
Max Morin787eeed2016-06-23 10:42:07 +0200777int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200778 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200779 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000780
Max Morin787eeed2016-06-23 10:42:07 +0200781 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000782
Max Morin787eeed2016-06-23 10:42:07 +0200783 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
784 return -1;
785 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000786
Max Morin787eeed2016-06-23 10:42:07 +0200787 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200788 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200789 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000790}
791
792// ----------------------------------------------------------------------------
793// SetMicrophoneMute
794// ----------------------------------------------------------------------------
795
Max Morin787eeed2016-06-23 10:42:07 +0200796int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200797 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200798 CHECK_INITIALIZED();
799 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000800}
801
802// ----------------------------------------------------------------------------
803// MicrophoneMute
804// ----------------------------------------------------------------------------
805
Max Morin787eeed2016-06-23 10:42:07 +0200806int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200807 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200808 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000809
Max Morin787eeed2016-06-23 10:42:07 +0200810 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000811
Max Morin787eeed2016-06-23 10:42:07 +0200812 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
813 return -1;
814 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000815
Max Morin787eeed2016-06-23 10:42:07 +0200816 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200817 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200818 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000819}
820
821// ----------------------------------------------------------------------------
822// MicrophoneBoostIsAvailable
823// ----------------------------------------------------------------------------
824
Max Morin787eeed2016-06-23 10:42:07 +0200825int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available) {
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 isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000830
Max Morin787eeed2016-06-23 10:42:07 +0200831 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1) {
832 return -1;
833 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000834
Max Morin787eeed2016-06-23 10:42:07 +0200835 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200836 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200837 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000838}
839
840// ----------------------------------------------------------------------------
841// SetMicrophoneBoost
842// ----------------------------------------------------------------------------
843
Max Morin787eeed2016-06-23 10:42:07 +0200844int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200845 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200846 CHECK_INITIALIZED();
847 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000848}
849
850// ----------------------------------------------------------------------------
851// MicrophoneBoost
852// ----------------------------------------------------------------------------
853
Max Morin787eeed2016-06-23 10:42:07 +0200854int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200855 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200856 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000857
Max Morin787eeed2016-06-23 10:42:07 +0200858 bool onOff(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000859
Max Morin787eeed2016-06-23 10:42:07 +0200860 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1) {
861 return -1;
862 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000863
Max Morin787eeed2016-06-23 10:42:07 +0200864 *enabled = onOff;
Max Morin2c332bb2016-07-04 09:03:42 +0200865 LOG(INFO) << "output: " << onOff;
Max Morin787eeed2016-06-23 10:42:07 +0200866 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000867}
868
869// ----------------------------------------------------------------------------
870// MicrophoneVolumeIsAvailable
871// ----------------------------------------------------------------------------
872
Max Morin787eeed2016-06-23 10:42:07 +0200873int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200874 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200875 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000876
Max Morin787eeed2016-06-23 10:42:07 +0200877 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000878
Max Morin787eeed2016-06-23 10:42:07 +0200879 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
880 return -1;
881 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000882
Max Morin787eeed2016-06-23 10:42:07 +0200883 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200884 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200885 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000886}
887
888// ----------------------------------------------------------------------------
889// SetMicrophoneVolume
890// ----------------------------------------------------------------------------
891
Max Morin787eeed2016-06-23 10:42:07 +0200892int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200893 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200894 CHECK_INITIALIZED();
895 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000896}
897
898// ----------------------------------------------------------------------------
899// MicrophoneVolume
900// ----------------------------------------------------------------------------
901
Max Morin787eeed2016-06-23 10:42:07 +0200902int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200903 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200904 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000905
Max Morin787eeed2016-06-23 10:42:07 +0200906 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000907
Max Morin787eeed2016-06-23 10:42:07 +0200908 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
909 return -1;
910 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000911
Max Morin787eeed2016-06-23 10:42:07 +0200912 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200913 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200914 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000915}
916
917// ----------------------------------------------------------------------------
918// StereoRecordingIsAvailable
919// ----------------------------------------------------------------------------
920
Max Morin787eeed2016-06-23 10:42:07 +0200921int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
922 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200923 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200924 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000925
Max Morin787eeed2016-06-23 10:42:07 +0200926 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000927
Max Morin787eeed2016-06-23 10:42:07 +0200928 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
929 return -1;
930 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000931
Max Morin787eeed2016-06-23 10:42:07 +0200932 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200933 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200934 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000935}
936
937// ----------------------------------------------------------------------------
938// SetStereoRecording
939// ----------------------------------------------------------------------------
940
Max Morin787eeed2016-06-23 10:42:07 +0200941int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200942 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
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 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200946 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200947 return -1;
948 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000949
Max Morin787eeed2016-06-23 10:42:07 +0200950 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200951 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200952 return -1;
953 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000954
Max Morin787eeed2016-06-23 10:42:07 +0200955 int8_t nChannels(1);
956 if (enable) {
957 nChannels = 2;
958 }
959 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000960
Max Morin787eeed2016-06-23 10:42:07 +0200961 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000962}
963
964// ----------------------------------------------------------------------------
965// StereoRecording
966// ----------------------------------------------------------------------------
967
Max Morin787eeed2016-06-23 10:42:07 +0200968int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200969 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200970 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000971
Max Morin787eeed2016-06-23 10:42:07 +0200972 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000973
Max Morin787eeed2016-06-23 10:42:07 +0200974 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
975 return -1;
976 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000977
Max Morin787eeed2016-06-23 10:42:07 +0200978 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200979 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200980 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000981}
982
983// ----------------------------------------------------------------------------
984// SetRecordingChannel
985// ----------------------------------------------------------------------------
986
Max Morin787eeed2016-06-23 10:42:07 +0200987int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
988 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200989 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200990 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200991 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200992 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200993 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200994 }
995 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000996
Max Morin787eeed2016-06-23 10:42:07 +0200997 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000998
Max Morin787eeed2016-06-23 10:42:07 +0200999 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001000 LOG(WARNING) << "recording in stereo is not supported";
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 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +00001005}
1006
1007// ----------------------------------------------------------------------------
1008// RecordingChannel
1009// ----------------------------------------------------------------------------
1010
Max Morin787eeed2016-06-23 10:42:07 +02001011int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +02001012 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001013 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001014
Max Morin787eeed2016-06-23 10:42:07 +02001015 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001016
Max Morin787eeed2016-06-23 10:42:07 +02001017 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
1018 return -1;
1019 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001020
Max Morin787eeed2016-06-23 10:42:07 +02001021 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +02001022 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +02001023 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +02001024 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +02001025 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +02001026 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001027 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +02001028 }
Max Morin787eeed2016-06-23 10:42:07 +02001029 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001030}
1031
1032// ----------------------------------------------------------------------------
1033// StereoPlayoutIsAvailable
1034// ----------------------------------------------------------------------------
1035
Max Morin787eeed2016-06-23 10:42:07 +02001036int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +02001037 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001038 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001039
Max Morin787eeed2016-06-23 10:42:07 +02001040 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001041
Max Morin787eeed2016-06-23 10:42:07 +02001042 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
1043 return -1;
1044 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001045
Max Morin787eeed2016-06-23 10:42:07 +02001046 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001047 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001048 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001049}
1050
1051// ----------------------------------------------------------------------------
1052// SetStereoPlayout
1053// ----------------------------------------------------------------------------
1054
Max Morin787eeed2016-06-23 10:42:07 +02001055int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001056 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001057 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001058
Max Morin787eeed2016-06-23 10:42:07 +02001059 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001060 LOG(LERROR)
1061 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001062 return -1;
1063 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001064
Max Morin787eeed2016-06-23 10:42:07 +02001065 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +02001066 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +02001067 return -1;
1068 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001069
Max Morin787eeed2016-06-23 10:42:07 +02001070 int8_t nChannels(1);
1071 if (enable) {
1072 nChannels = 2;
1073 }
1074 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +00001075
Max Morin787eeed2016-06-23 10:42:07 +02001076 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001077}
1078
1079// ----------------------------------------------------------------------------
1080// StereoPlayout
1081// ----------------------------------------------------------------------------
1082
Max Morin787eeed2016-06-23 10:42:07 +02001083int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001084 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001085 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001086
Max Morin787eeed2016-06-23 10:42:07 +02001087 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +00001088
Max Morin787eeed2016-06-23 10:42:07 +02001089 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
1090 return -1;
1091 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001092
Max Morin787eeed2016-06-23 10:42:07 +02001093 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +02001094 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +02001095 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001096}
1097
1098// ----------------------------------------------------------------------------
1099// SetAGC
1100// ----------------------------------------------------------------------------
1101
Max Morin787eeed2016-06-23 10:42:07 +02001102int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001103 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001104 CHECK_INITIALIZED();
1105 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +00001106}
1107
1108// ----------------------------------------------------------------------------
1109// AGC
1110// ----------------------------------------------------------------------------
1111
Max Morin787eeed2016-06-23 10:42:07 +02001112bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +02001113 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001114 CHECK_INITIALIZED_BOOL();
1115 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +00001116}
1117
1118// ----------------------------------------------------------------------------
1119// PlayoutIsAvailable
1120// ----------------------------------------------------------------------------
1121
Max Morin787eeed2016-06-23 10:42:07 +02001122int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001123 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001124 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001125
Max Morin787eeed2016-06-23 10:42:07 +02001126 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001127
Max Morin787eeed2016-06-23 10:42:07 +02001128 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
1129 return -1;
1130 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001131
Max Morin787eeed2016-06-23 10:42:07 +02001132 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001133 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001134 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001135}
1136
1137// ----------------------------------------------------------------------------
1138// RecordingIsAvailable
1139// ----------------------------------------------------------------------------
1140
Max Morin787eeed2016-06-23 10:42:07 +02001141int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001142 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001143 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001144
Max Morin787eeed2016-06-23 10:42:07 +02001145 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001146
Max Morin787eeed2016-06-23 10:42:07 +02001147 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1148 return -1;
1149 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001150
Max Morin787eeed2016-06-23 10:42:07 +02001151 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001152 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001153 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001154}
1155
1156// ----------------------------------------------------------------------------
1157// MaxMicrophoneVolume
1158// ----------------------------------------------------------------------------
1159
Max Morin787eeed2016-06-23 10:42:07 +02001160int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001161 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001162
Max Morin787eeed2016-06-23 10:42:07 +02001163 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001164
Max Morin787eeed2016-06-23 10:42:07 +02001165 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1166 return -1;
1167 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001168
Max Morin787eeed2016-06-23 10:42:07 +02001169 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001170 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001171}
1172
1173// ----------------------------------------------------------------------------
1174// MinMicrophoneVolume
1175// ----------------------------------------------------------------------------
1176
Max Morin787eeed2016-06-23 10:42:07 +02001177int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1178 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001179
Max Morin787eeed2016-06-23 10:42:07 +02001180 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001181
Max Morin787eeed2016-06-23 10:42:07 +02001182 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1183 return -1;
1184 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001185
Max Morin787eeed2016-06-23 10:42:07 +02001186 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001187 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001188}
1189
1190// ----------------------------------------------------------------------------
1191// MicrophoneVolumeStepSize
1192// ----------------------------------------------------------------------------
1193
Max Morin787eeed2016-06-23 10:42:07 +02001194int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(
1195 uint16_t* stepSize) const {
Max Morin098e6c52016-06-28 09:36:25 +02001196 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001197 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001198
Max Morin787eeed2016-06-23 10:42:07 +02001199 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001200
Max Morin787eeed2016-06-23 10:42:07 +02001201 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1) {
1202 return -1;
1203 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001204
Max Morin787eeed2016-06-23 10:42:07 +02001205 *stepSize = delta;
Max Morin2c332bb2016-07-04 09:03:42 +02001206 LOG(INFO) << "output: " << *stepSize;
Max Morin787eeed2016-06-23 10:42:07 +02001207 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001208}
1209
1210// ----------------------------------------------------------------------------
1211// PlayoutDevices
1212// ----------------------------------------------------------------------------
1213
Max Morin787eeed2016-06-23 10:42:07 +02001214int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001215 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001216 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001217
Max Morin787eeed2016-06-23 10:42:07 +02001218 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001219 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001220 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001221}
1222
1223// ----------------------------------------------------------------------------
1224// SetPlayoutDevice I (II)
1225// ----------------------------------------------------------------------------
1226
Max Morin787eeed2016-06-23 10:42:07 +02001227int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001228 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001229 CHECK_INITIALIZED();
1230 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001231}
1232
1233// ----------------------------------------------------------------------------
1234// SetPlayoutDevice II (II)
1235// ----------------------------------------------------------------------------
1236
Max Morin787eeed2016-06-23 10:42:07 +02001237int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001238 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001239 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001240
Max Morin787eeed2016-06-23 10:42:07 +02001241 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001242}
1243
1244// ----------------------------------------------------------------------------
1245// PlayoutDeviceName
1246// ----------------------------------------------------------------------------
1247
pbos@webrtc.org25509882013-04-09 10:30:35 +00001248int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1249 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001250 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001251 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001252 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001253 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001254
Max Morin787eeed2016-06-23 10:42:07 +02001255 if (name == NULL) {
1256 _lastError = kAdmErrArgument;
1257 return -1;
1258 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001259
Max Morin787eeed2016-06-23 10:42:07 +02001260 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1261 return -1;
1262 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001263
Max Morin787eeed2016-06-23 10:42:07 +02001264 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001265 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001266 }
1267 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001268 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001269 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001270
Max Morin787eeed2016-06-23 10:42:07 +02001271 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001272}
1273
1274// ----------------------------------------------------------------------------
1275// RecordingDeviceName
1276// ----------------------------------------------------------------------------
1277
pbos@webrtc.org25509882013-04-09 10:30:35 +00001278int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1279 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001280 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001281 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001282 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001283 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001284
Max Morin787eeed2016-06-23 10:42:07 +02001285 if (name == NULL) {
1286 _lastError = kAdmErrArgument;
1287 return -1;
1288 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001289
Max Morin787eeed2016-06-23 10:42:07 +02001290 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1291 return -1;
1292 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001293
Max Morin787eeed2016-06-23 10:42:07 +02001294 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001295 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001296 }
1297 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001298 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001299 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001300
Max Morin787eeed2016-06-23 10:42:07 +02001301 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001302}
1303
1304// ----------------------------------------------------------------------------
1305// RecordingDevices
1306// ----------------------------------------------------------------------------
1307
Max Morin787eeed2016-06-23 10:42:07 +02001308int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001309 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001310 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001311
Max Morin787eeed2016-06-23 10:42:07 +02001312 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001313
Max Morin2c332bb2016-07-04 09:03:42 +02001314 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001315 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001316}
1317
1318// ----------------------------------------------------------------------------
1319// SetRecordingDevice I (II)
1320// ----------------------------------------------------------------------------
1321
Max Morin787eeed2016-06-23 10:42:07 +02001322int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001323 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001324 CHECK_INITIALIZED();
1325 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001326}
1327
1328// ----------------------------------------------------------------------------
1329// SetRecordingDevice II (II)
1330// ----------------------------------------------------------------------------
1331
Max Morin787eeed2016-06-23 10:42:07 +02001332int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001333 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001334 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001335
Max Morin787eeed2016-06-23 10:42:07 +02001336 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001337}
1338
1339// ----------------------------------------------------------------------------
1340// InitPlayout
1341// ----------------------------------------------------------------------------
1342
Max Morin787eeed2016-06-23 10:42:07 +02001343int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001344 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001345 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001346 if (PlayoutIsInitialized()) {
1347 return 0;
1348 }
Max Morin84cab202016-07-01 13:35:19 +02001349 int32_t result = _ptrAudioDevice->InitPlayout();
1350 LOG(INFO) << "output: " << result;
1351 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1352 static_cast<int>(result == 0));
1353 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001354}
1355
1356// ----------------------------------------------------------------------------
1357// InitRecording
1358// ----------------------------------------------------------------------------
1359
Max Morin787eeed2016-06-23 10:42:07 +02001360int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001361 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001362 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001363 if (RecordingIsInitialized()) {
1364 return 0;
1365 }
Max Morin84cab202016-07-01 13:35:19 +02001366 int32_t result = _ptrAudioDevice->InitRecording();
1367 LOG(INFO) << "output: " << result;
1368 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1369 static_cast<int>(result == 0));
1370 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001371}
1372
1373// ----------------------------------------------------------------------------
1374// PlayoutIsInitialized
1375// ----------------------------------------------------------------------------
1376
Max Morin787eeed2016-06-23 10:42:07 +02001377bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001378 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001379 CHECK_INITIALIZED_BOOL();
1380 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001381}
1382
1383// ----------------------------------------------------------------------------
1384// RecordingIsInitialized
1385// ----------------------------------------------------------------------------
1386
Max Morin787eeed2016-06-23 10:42:07 +02001387bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001388 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001389 CHECK_INITIALIZED_BOOL();
1390 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001391}
1392
1393// ----------------------------------------------------------------------------
1394// StartPlayout
1395// ----------------------------------------------------------------------------
1396
Max Morin787eeed2016-06-23 10:42:07 +02001397int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001398 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001399 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001400 if (Playing()) {
1401 return 0;
1402 }
henrikaba156cf2016-10-31 08:18:50 -07001403 _audioDeviceBuffer.StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001404 int32_t result = _ptrAudioDevice->StartPlayout();
1405 LOG(INFO) << "output: " << result;
1406 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1407 static_cast<int>(result == 0));
1408 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001409}
1410
1411// ----------------------------------------------------------------------------
1412// StopPlayout
1413// ----------------------------------------------------------------------------
1414
Max Morin787eeed2016-06-23 10:42:07 +02001415int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001416 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001417 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001418 int32_t result = _ptrAudioDevice->StopPlayout();
henrikaba156cf2016-10-31 08:18:50 -07001419 _audioDeviceBuffer.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001420 LOG(INFO) << "output: " << result;
1421 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1422 static_cast<int>(result == 0));
1423 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001424}
1425
1426// ----------------------------------------------------------------------------
1427// Playing
1428// ----------------------------------------------------------------------------
1429
Max Morin787eeed2016-06-23 10:42:07 +02001430bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001431 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001432 CHECK_INITIALIZED_BOOL();
1433 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001434}
1435
1436// ----------------------------------------------------------------------------
1437// StartRecording
1438// ----------------------------------------------------------------------------
1439
Max Morin787eeed2016-06-23 10:42:07 +02001440int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001441 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001442 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001443 if (Recording()) {
1444 return 0;
1445 }
henrikaba156cf2016-10-31 08:18:50 -07001446 _audioDeviceBuffer.StartRecording();
Max Morin84cab202016-07-01 13:35:19 +02001447 int32_t result = _ptrAudioDevice->StartRecording();
1448 LOG(INFO) << "output: " << result;
1449 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1450 static_cast<int>(result == 0));
1451 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001452}
1453// ----------------------------------------------------------------------------
1454// StopRecording
1455// ----------------------------------------------------------------------------
1456
Max Morin787eeed2016-06-23 10:42:07 +02001457int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001458 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001459 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001460 int32_t result = _ptrAudioDevice->StopRecording();
henrikaba156cf2016-10-31 08:18:50 -07001461 _audioDeviceBuffer.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +02001462 LOG(INFO) << "output: " << result;
1463 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1464 static_cast<int>(result == 0));
1465 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001466}
1467
1468// ----------------------------------------------------------------------------
1469// Recording
1470// ----------------------------------------------------------------------------
1471
Max Morin787eeed2016-06-23 10:42:07 +02001472bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001473 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001474 CHECK_INITIALIZED_BOOL();
1475 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001476}
1477
1478// ----------------------------------------------------------------------------
1479// RegisterEventObserver
1480// ----------------------------------------------------------------------------
1481
Max Morin787eeed2016-06-23 10:42:07 +02001482int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1483 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001484 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001485 CriticalSectionScoped lock(&_critSectEventCb);
1486 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001487
Max Morin787eeed2016-06-23 10:42:07 +02001488 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001489}
1490
1491// ----------------------------------------------------------------------------
1492// RegisterAudioCallback
1493// ----------------------------------------------------------------------------
1494
Max Morin787eeed2016-06-23 10:42:07 +02001495int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1496 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001497 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001498 CriticalSectionScoped lock(&_critSectAudioCb);
henrikaf5022222016-11-07 15:56:59 +01001499 return _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001500}
1501
1502// ----------------------------------------------------------------------------
1503// StartRawInputFileRecording
1504// ----------------------------------------------------------------------------
1505
pbos@webrtc.org25509882013-04-09 10:30:35 +00001506int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001507 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001508 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001509 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001510
Max Morin787eeed2016-06-23 10:42:07 +02001511 if (NULL == pcmFileNameUTF8) {
1512 return -1;
1513 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001514
Max Morin787eeed2016-06-23 10:42:07 +02001515 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001516}
1517
1518// ----------------------------------------------------------------------------
1519// StopRawInputFileRecording
1520// ----------------------------------------------------------------------------
1521
Max Morin787eeed2016-06-23 10:42:07 +02001522int32_t AudioDeviceModuleImpl::StopRawInputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001523 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001524 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001525
Max Morin787eeed2016-06-23 10:42:07 +02001526 return (_audioDeviceBuffer.StopInputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001527}
1528
1529// ----------------------------------------------------------------------------
1530// StartRawOutputFileRecording
1531// ----------------------------------------------------------------------------
1532
pbos@webrtc.org25509882013-04-09 10:30:35 +00001533int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
Max Morin787eeed2016-06-23 10:42:07 +02001534 const char pcmFileNameUTF8[kAdmMaxFileNameSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001535 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001536 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001537
Max Morin787eeed2016-06-23 10:42:07 +02001538 if (NULL == pcmFileNameUTF8) {
1539 return -1;
1540 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001541
Max Morin787eeed2016-06-23 10:42:07 +02001542 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
niklase@google.com470e71d2011-07-07 08:21:25 +00001543}
1544
1545// ----------------------------------------------------------------------------
1546// StopRawOutputFileRecording
1547// ----------------------------------------------------------------------------
1548
Max Morin787eeed2016-06-23 10:42:07 +02001549int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001550 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001551 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001552
Max Morin787eeed2016-06-23 10:42:07 +02001553 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001554}
1555
1556// ----------------------------------------------------------------------------
1557// SetPlayoutBuffer
1558// ----------------------------------------------------------------------------
1559
Max Morin787eeed2016-06-23 10:42:07 +02001560int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type,
1561 uint16_t sizeMS) {
Max Morin098e6c52016-06-28 09:36:25 +02001562 if (type == kFixedBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001563 LOG(INFO) << __FUNCTION__ << "(fixed buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001564 } else if (type == kAdaptiveBufferSize) {
Max Morin2c332bb2016-07-04 09:03:42 +02001565 LOG(INFO) << __FUNCTION__ << "(adaptive buffer, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001566 } else {
Max Morin2c332bb2016-07-04 09:03:42 +02001567 LOG(INFO) << __FUNCTION__ << "(?, " << sizeMS << "ms)";
Max Morin098e6c52016-06-28 09:36:25 +02001568 }
Max Morin787eeed2016-06-23 10:42:07 +02001569 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001570
Max Morin787eeed2016-06-23 10:42:07 +02001571 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +02001572 LOG(LERROR) << "unable to modify the playout buffer while playing side is "
1573 "initialized";
Max Morin787eeed2016-06-23 10:42:07 +02001574 return -1;
1575 }
1576
1577 int32_t ret(0);
1578
1579 if (kFixedBufferSize == type) {
1580 if (sizeMS < kAdmMinPlayoutBufferSizeMs ||
1581 sizeMS > kAdmMaxPlayoutBufferSizeMs) {
Max Morin098e6c52016-06-28 09:36:25 +02001582 LOG(LERROR) << "size parameter is out of range";
Max Morin787eeed2016-06-23 10:42:07 +02001583 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001584 }
Max Morin787eeed2016-06-23 10:42:07 +02001585 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001586
Max Morin787eeed2016-06-23 10:42:07 +02001587 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001588 LOG(LERROR) << "failed to set the playout buffer (error: " << LastError()
1589 << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001590 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001591
Max Morin787eeed2016-06-23 10:42:07 +02001592 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +00001593}
1594
1595// ----------------------------------------------------------------------------
1596// PlayoutBuffer
1597// ----------------------------------------------------------------------------
1598
Max Morin787eeed2016-06-23 10:42:07 +02001599int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type,
1600 uint16_t* sizeMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001601 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001602 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001603
Max Morin787eeed2016-06-23 10:42:07 +02001604 BufferType bufType;
1605 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001606
Max Morin787eeed2016-06-23 10:42:07 +02001607 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001608 LOG(LERROR) << "failed to retrieve the buffer type and size";
Max Morin787eeed2016-06-23 10:42:07 +02001609 return -1;
1610 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001611
Max Morin787eeed2016-06-23 10:42:07 +02001612 *type = bufType;
1613 *sizeMS = size;
niklase@google.com470e71d2011-07-07 08:21:25 +00001614
Max Morin2c332bb2016-07-04 09:03:42 +02001615 LOG(INFO) << "output: type = " << *type << ", sizeMS = " << *sizeMS;
Max Morin787eeed2016-06-23 10:42:07 +02001616 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001617}
1618
1619// ----------------------------------------------------------------------------
1620// PlayoutDelay
1621// ----------------------------------------------------------------------------
1622
Max Morin787eeed2016-06-23 10:42:07 +02001623int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001624 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001625
Max Morin787eeed2016-06-23 10:42:07 +02001626 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001627
Max Morin787eeed2016-06-23 10:42:07 +02001628 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001629 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001630 return -1;
1631 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001632
Max Morin787eeed2016-06-23 10:42:07 +02001633 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001634 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001635}
1636
1637// ----------------------------------------------------------------------------
1638// RecordingDelay
1639// ----------------------------------------------------------------------------
1640
Max Morin787eeed2016-06-23 10:42:07 +02001641int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001642 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001643 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001644
Max Morin787eeed2016-06-23 10:42:07 +02001645 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001646
Max Morin787eeed2016-06-23 10:42:07 +02001647 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001648 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001649 return -1;
1650 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001651
Max Morin787eeed2016-06-23 10:42:07 +02001652 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001653 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001654 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001655}
1656
1657// ----------------------------------------------------------------------------
1658// CPULoad
1659// ----------------------------------------------------------------------------
1660
Max Morin787eeed2016-06-23 10:42:07 +02001661int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const {
Max Morin098e6c52016-06-28 09:36:25 +02001662 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001663 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001664
Max Morin787eeed2016-06-23 10:42:07 +02001665 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001666
Max Morin787eeed2016-06-23 10:42:07 +02001667 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001668 LOG(LERROR) << "failed to retrieve the CPU load";
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 *load = cpuLoad;
Max Morin2c332bb2016-07-04 09:03:42 +02001673 LOG(INFO) << "output: " << *load;
Max Morin787eeed2016-06-23 10:42:07 +02001674 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001675}
1676
1677// ----------------------------------------------------------------------------
1678// SetRecordingSampleRate
1679// ----------------------------------------------------------------------------
1680
Max Morin787eeed2016-06-23 10:42:07 +02001681int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1682 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001683 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001684 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001685
Max Morin787eeed2016-06-23 10:42:07 +02001686 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1687 return -1;
1688 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001689
Max Morin787eeed2016-06-23 10:42:07 +02001690 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001691}
1692
1693// ----------------------------------------------------------------------------
1694// RecordingSampleRate
1695// ----------------------------------------------------------------------------
1696
Max Morin787eeed2016-06-23 10:42:07 +02001697int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1698 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001699 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001700 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001701
Max Morin787eeed2016-06-23 10:42:07 +02001702 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001703
Max Morin787eeed2016-06-23 10:42:07 +02001704 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001705 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001706 return -1;
1707 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001708
Max Morin787eeed2016-06-23 10:42:07 +02001709 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001710 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001711 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001712}
1713
1714// ----------------------------------------------------------------------------
1715// SetPlayoutSampleRate
1716// ----------------------------------------------------------------------------
1717
Max Morin787eeed2016-06-23 10:42:07 +02001718int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1719 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001720 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001721 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001722
Max Morin787eeed2016-06-23 10:42:07 +02001723 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1724 return -1;
1725 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001726
Max Morin787eeed2016-06-23 10:42:07 +02001727 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001728}
1729
1730// ----------------------------------------------------------------------------
1731// PlayoutSampleRate
1732// ----------------------------------------------------------------------------
1733
Max Morin787eeed2016-06-23 10:42:07 +02001734int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1735 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001736 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001737 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001738
Max Morin787eeed2016-06-23 10:42:07 +02001739 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001740
Max Morin787eeed2016-06-23 10:42:07 +02001741 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001742 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001743 return -1;
1744 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001745
Max Morin787eeed2016-06-23 10:42:07 +02001746 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001747 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001748 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001749}
1750
1751// ----------------------------------------------------------------------------
1752// ResetAudioDevice
1753// ----------------------------------------------------------------------------
1754
Max Morin787eeed2016-06-23 10:42:07 +02001755int32_t AudioDeviceModuleImpl::ResetAudioDevice() {
Max Morin098e6c52016-06-28 09:36:25 +02001756 LOG(INFO) << __FUNCTION__;
henrikaf5022222016-11-07 15:56:59 +01001757 FATAL() << "Should never be called";
1758 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +00001759}
1760
1761// ----------------------------------------------------------------------------
1762// SetLoudspeakerStatus
1763// ----------------------------------------------------------------------------
1764
Max Morin787eeed2016-06-23 10:42:07 +02001765int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001766 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001767 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001768
Max Morin787eeed2016-06-23 10:42:07 +02001769 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1770 return -1;
1771 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001772
Max Morin787eeed2016-06-23 10:42:07 +02001773 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001774}
1775
1776// ----------------------------------------------------------------------------
1777// GetLoudspeakerStatus
1778// ----------------------------------------------------------------------------
1779
henrikac14f5ff2015-09-23 14:08:33 +02001780int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001781 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001782 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001783 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001784 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001785 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001786 }
Max Morin2c332bb2016-07-04 09:03:42 +02001787 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001788 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001789}
1790
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001791bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001792 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001793 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001794 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001795 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001796 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001797}
1798
henrikac14f5ff2015-09-23 14:08:33 +02001799int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001800 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001801 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001802 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001803 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001804 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001805}
1806
1807bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001808 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001809 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001810 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001811 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001812 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001813}
1814
1815int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001816 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001817 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001818 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001819 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001820 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001821}
1822
1823bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001824 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001825 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001826 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001827 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001828 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001829}
1830
1831int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001832 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001833 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001834 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001835 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001836 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001837}
1838
maxmorin88e31a32016-08-16 00:56:09 -07001839#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001840int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1841 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001842 LOG(INFO) << __FUNCTION__;
1843 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001844 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001845 return r;
henrikaba35d052015-07-14 17:04:08 +02001846}
1847
1848int AudioDeviceModuleImpl::GetRecordAudioParameters(
1849 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001850 LOG(INFO) << __FUNCTION__;
1851 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001852 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001853 return r;
henrikaba35d052015-07-14 17:04:08 +02001854}
maxmorin88e31a32016-08-16 00:56:09 -07001855#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001856
niklase@google.com470e71d2011-07-07 08:21:25 +00001857// ============================================================================
1858// Private Methods
1859// ============================================================================
1860
1861// ----------------------------------------------------------------------------
1862// Platform
1863// ----------------------------------------------------------------------------
1864
Max Morin787eeed2016-06-23 10:42:07 +02001865AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001866 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001867 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001868}
1869
1870// ----------------------------------------------------------------------------
1871// PlatformAudioLayer
1872// ----------------------------------------------------------------------------
1873
Max Morin787eeed2016-06-23 10:42:07 +02001874AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1875 const {
Max Morin098e6c52016-06-28 09:36:25 +02001876 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001877 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001878}
1879
1880} // namespace webrtc