blob: e8a3a72605f22a87fbcea3dec6bdd68e30ce7976 [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
Edward Lemurc20978e2017-07-06 19:44:34 +020011#include "webrtc/modules/audio_device/audio_device_impl.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000012#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
13#include "webrtc/modules/audio_device/audio_device_config.h"
Max Morin84cab202016-07-01 13:35:19 +020014#include "webrtc/modules/audio_device/audio_device_generic.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020015#include "webrtc/rtc_base/checks.h"
16#include "webrtc/rtc_base/logging.h"
17#include "webrtc/rtc_base/refcount.h"
18#include "webrtc/rtc_base/timeutils.h"
Max Morin84cab202016-07-01 13:35:19 +020019#include "webrtc/system_wrappers/include/metrics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000021#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000022#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +020025#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
26#include "audio_device_core_win.h"
27#endif
leozwang@google.com39f20512011-07-15 16:29:40 +000028#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020029#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020030#include "webrtc/modules/audio_device/android/audio_device_template.h"
31#include "webrtc/modules/audio_device/android/audio_manager.h"
32#include "webrtc/modules/audio_device/android/audio_record_jni.h"
33#include "webrtc/modules/audio_device/android/audio_track_jni.h"
34#include "webrtc/modules/audio_device/android/opensles_player.h"
henrika918b5542016-09-19 15:44:09 +020035#include "webrtc/modules/audio_device/android/opensles_recorder.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +020037#if defined(LINUX_ALSA)
38#include "audio_device_alsa_linux.h"
39#endif
Tommi68898a22015-05-19 17:28:07 +020040#if defined(LINUX_PULSE)
Max Morin787eeed2016-06-23 10:42:07 +020041#include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020042#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000043#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +020044#include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000045#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +020046#include "audio_device_mac.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000047#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000048
49#if defined(WEBRTC_DUMMY_FILE_DEVICES)
50#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
51#endif
52
pbos@webrtc.org811269d2013-07-11 13:24:38 +000053#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000054#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000055
Max Morin787eeed2016-06-23 10:42:07 +020056#define CHECK_INITIALIZED() \
57 { \
58 if (!_initialized) { \
59 return -1; \
60 }; \
61 }
niklase@google.com470e71d2011-07-07 08:21:25 +000062
Max Morin787eeed2016-06-23 10:42:07 +020063#define CHECK_INITIALIZED_BOOL() \
64 { \
65 if (!_initialized) { \
66 return false; \
67 }; \
68 }
niklase@google.com470e71d2011-07-07 08:21:25 +000069
Peter Boström1d194412016-03-21 16:44:31 +010070namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000071
niklase@google.com470e71d2011-07-07 08:21:25 +000072// ============================================================================
73// Static methods
74// ============================================================================
75
76// ----------------------------------------------------------------------------
77// AudioDeviceModule::Create()
78// ----------------------------------------------------------------------------
79
Peter Boström4adbbcf2016-05-03 15:51:26 -040080rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
Peter Boström1d194412016-03-21 16:44:31 +010081 const int32_t id,
Peter Boström4adbbcf2016-05-03 15:51:26 -040082 const AudioLayer audio_layer) {
Max Morin098e6c52016-06-28 09:36:25 +020083 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +020084 // Create the generic ref counted (platform independent) implementation.
85 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
86 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audio_layer));
niklase@google.com470e71d2011-07-07 08:21:25 +000087
Max Morin787eeed2016-06-23 10:42:07 +020088 // Ensure that the current platform is supported.
89 if (audioDevice->CheckPlatform() == -1) {
90 return nullptr;
91 }
niklase@google.com470e71d2011-07-07 08:21:25 +000092
Max Morin787eeed2016-06-23 10:42:07 +020093 // Create the platform-dependent implementation.
94 if (audioDevice->CreatePlatformSpecificObjects() == -1) {
95 return nullptr;
96 }
niklase@google.com470e71d2011-07-07 08:21:25 +000097
Max Morin787eeed2016-06-23 10:42:07 +020098 // Ensure that the generic audio buffer can communicate with the
99 // platform-specific parts.
100 if (audioDevice->AttachAudioBuffer() == -1) {
101 return nullptr;
102 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
Max Morin787eeed2016-06-23 10:42:07 +0200104 WebRtcSpl_Init();
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000105
Max Morin787eeed2016-06-23 10:42:07 +0200106 return audioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107}
108
niklase@google.com470e71d2011-07-07 08:21:25 +0000109// ============================================================================
110// Construction & Destruction
111// ============================================================================
112
113// ----------------------------------------------------------------------------
114// AudioDeviceModuleImpl - ctor
115// ----------------------------------------------------------------------------
116
Max Morin787eeed2016-06-23 10:42:07 +0200117AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id,
118 const AudioLayer audioLayer)
kthelgason6bfe49c2017-03-30 01:14:41 -0700119 : _ptrCbAudioDeviceObserver(NULL),
Max Morin787eeed2016-06-23 10:42:07 +0200120 _ptrAudioDevice(NULL),
121 _id(id),
122 _platformAudioLayer(audioLayer),
123 _lastProcessTime(rtc::TimeMillis()),
124 _platformType(kPlatformNotSupported),
125 _initialized(false),
126 _lastError(kAdmErrNone) {
Max Morin098e6c52016-06-28 09:36:25 +0200127 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128}
129
130// ----------------------------------------------------------------------------
131// CheckPlatform
132// ----------------------------------------------------------------------------
133
Max Morin787eeed2016-06-23 10:42:07 +0200134int32_t AudioDeviceModuleImpl::CheckPlatform() {
Max Morin098e6c52016-06-28 09:36:25 +0200135 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
Max Morin787eeed2016-06-23 10:42:07 +0200137 // Ensure that the current platform is supported
138 //
139 PlatformType platform(kPlatformNotSupported);
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
141#if defined(_WIN32)
Max Morin787eeed2016-06-23 10:42:07 +0200142 platform = kPlatformWin32;
Max Morin098e6c52016-06-28 09:36:25 +0200143 LOG(INFO) << "current platform is Win32";
leozwang@google.com522f42b2011-09-19 17:39:05 +0000144#elif defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200145 platform = kPlatformAndroid;
Max Morin098e6c52016-06-28 09:36:25 +0200146 LOG(INFO) << "current platform is Android";
niklase@google.com470e71d2011-07-07 08:21:25 +0000147#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200148 platform = kPlatformLinux;
Max Morin098e6c52016-06-28 09:36:25 +0200149 LOG(INFO) << "current platform is Linux";
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000150#elif defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200151 platform = kPlatformIOS;
Max Morin098e6c52016-06-28 09:36:25 +0200152 LOG(INFO) << "current platform is IOS";
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000153#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200154 platform = kPlatformMac;
Max Morin098e6c52016-06-28 09:36:25 +0200155 LOG(INFO) << "current platform is Mac";
niklase@google.com470e71d2011-07-07 08:21:25 +0000156#endif
157
Max Morin787eeed2016-06-23 10:42:07 +0200158 if (platform == kPlatformNotSupported) {
Max Morin098e6c52016-06-28 09:36:25 +0200159 LOG(LERROR) << "current platform is not supported => this module will self "
160 "destruct!";
Max Morin787eeed2016-06-23 10:42:07 +0200161 return -1;
162 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
Max Morin787eeed2016-06-23 10:42:07 +0200164 // Store valid output results
165 //
166 _platformType = platform;
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
Max Morin787eeed2016-06-23 10:42:07 +0200168 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000169}
170
niklase@google.com470e71d2011-07-07 08:21:25 +0000171// ----------------------------------------------------------------------------
172// CreatePlatformSpecificObjects
173// ----------------------------------------------------------------------------
174
Max Morin787eeed2016-06-23 10:42:07 +0200175int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
Max Morin098e6c52016-06-28 09:36:25 +0200176 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000177
Max Morin787eeed2016-06-23 10:42:07 +0200178 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
xians@google.combf5d2ba2011-08-16 07:44:19 +0000180#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200181 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200182 LOG(INFO) << "Dummy Audio APIs will be utilized";
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000183#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
Max Morin787eeed2016-06-23 10:42:07 +0200184 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
noahric6a355902016-08-17 15:19:50 -0700185 if (ptrAudioDevice) {
186 LOG(INFO) << "Will use file-playing dummy device.";
187 } else {
188 // Create a dummy device instead.
189 ptrAudioDevice = new AudioDeviceDummy(Id());
190 LOG(INFO) << "Dummy Audio APIs will be utilized";
191 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000192#else
Max Morin787eeed2016-06-23 10:42:07 +0200193 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
Max Morin787eeed2016-06-23 10:42:07 +0200195// Create the *Windows* implementation of the Audio Device
196//
niklase@google.com470e71d2011-07-07 08:21:25 +0000197#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
Max Morin787eeed2016-06-23 10:42:07 +0200198 if ((audioLayer == kWindowsCoreAudio) ||
199 (audioLayer == kPlatformDefaultAudio)) {
Max Morin098e6c52016-06-28 09:36:25 +0200200 LOG(INFO) << "attempting to use the Windows Core Audio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
Max Morin787eeed2016-06-23 10:42:07 +0200202 if (AudioDeviceWindowsCore::CoreAudioIsSupported()) {
203 // create *Windows Core Audio* implementation
sazab4aa4eb2017-07-19 01:12:36 -0700204 ptrAudioDevice = new AudioDeviceWindowsCore();
Max Morin098e6c52016-06-28 09:36:25 +0200205 LOG(INFO) << "Windows Core Audio APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000206 }
Max Morin787eeed2016-06-23 10:42:07 +0200207 }
208#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000210#if defined(WEBRTC_ANDROID)
Max Morin787eeed2016-06-23 10:42:07 +0200211 // Create an Android audio manager.
212 _audioManagerAndroid.reset(new AudioManager());
213 // Select best possible combination of audio layers.
214 if (audioLayer == kPlatformDefaultAudio) {
henrika918b5542016-09-19 15:44:09 +0200215 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
216 _audioManagerAndroid->IsLowLatencyRecordSupported()) {
217 // Use OpenSL ES for both playout and recording.
218 audioLayer = kAndroidOpenSLESAudio;
219 } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() &&
220 !_audioManagerAndroid->IsLowLatencyRecordSupported()) {
221 // Use OpenSL ES for output on devices that only supports the
Max Morin787eeed2016-06-23 10:42:07 +0200222 // low-latency output audio path.
223 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
henrikab2619892015-05-18 16:49:16 +0200224 } else {
henrika918b5542016-09-19 15:44:09 +0200225 // Use Java-based audio in both directions when low-latency output is
226 // not supported.
Max Morin787eeed2016-06-23 10:42:07 +0200227 audioLayer = kAndroidJavaAudio;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228 }
Max Morin787eeed2016-06-23 10:42:07 +0200229 }
230 AudioManager* audio_manager = _audioManagerAndroid.get();
231 if (audioLayer == kAndroidJavaAudio) {
232 // Java audio for both input and output audio.
233 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
234 audioLayer, audio_manager);
henrika918b5542016-09-19 15:44:09 +0200235 } else if (audioLayer == kAndroidOpenSLESAudio) {
236 // OpenSL ES based audio for both input and output audio.
237 ptrAudioDevice = new AudioDeviceTemplate<OpenSLESRecorder, OpenSLESPlayer>(
238 audioLayer, audio_manager);
Max Morin787eeed2016-06-23 10:42:07 +0200239 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
240 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
241 // This combination provides low-latency output audio and at the same
242 // time support for HW AEC using the AudioRecord Java API.
243 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
244 audioLayer, audio_manager);
245 } else {
246 // Invalid audio layer.
henrika918b5542016-09-19 15:44:09 +0200247 ptrAudioDevice = nullptr;
Max Morin787eeed2016-06-23 10:42:07 +0200248 }
249// END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000250
Max Morin787eeed2016-06-23 10:42:07 +0200251// Create the *Linux* implementation of the Audio Device
252//
niklase@google.com470e71d2011-07-07 08:21:25 +0000253#elif defined(WEBRTC_LINUX)
Max Morin787eeed2016-06-23 10:42:07 +0200254 if ((audioLayer == kLinuxPulseAudio) ||
255 (audioLayer == kPlatformDefaultAudio)) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000256#if defined(LINUX_PULSE)
Max Morin098e6c52016-06-28 09:36:25 +0200257 LOG(INFO) << "attempting to use the Linux PulseAudio APIs...";
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
Max Morin787eeed2016-06-23 10:42:07 +0200259 // create *Linux PulseAudio* implementation
saza43a85f02017-07-18 04:12:29 -0700260 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse();
Max Morin84cab202016-07-01 13:35:19 +0200261 if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) {
Max Morin787eeed2016-06-23 10:42:07 +0200262 ptrAudioDevice = pulseDevice;
Max Morin098e6c52016-06-28 09:36:25 +0200263 LOG(INFO) << "Linux PulseAudio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200264 } else {
265 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000266#endif
267#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200268 // create *Linux ALSA Audio* implementation
saza43a85f02017-07-18 04:12:29 -0700269 ptrAudioDevice = new AudioDeviceLinuxALSA();
Max Morin787eeed2016-06-23 10:42:07 +0200270 if (ptrAudioDevice != NULL) {
271 // Pulse Audio was not supported => revert to ALSA instead
272 _platformAudioLayer =
273 kLinuxAlsaAudio; // modify the state set at construction
Max Morin098e6c52016-06-28 09:36:25 +0200274 LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will "
275 "be utilized instead";
Max Morin787eeed2016-06-23 10:42:07 +0200276 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000277#endif
278#if defined(LINUX_PULSE)
niklase@google.com470e71d2011-07-07 08:21:25 +0000279 }
Max Morin787eeed2016-06-23 10:42:07 +0200280#endif
281 } else if (audioLayer == kLinuxAlsaAudio) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000282#if defined(LINUX_ALSA)
Max Morin787eeed2016-06-23 10:42:07 +0200283 // create *Linux ALSA Audio* implementation
saza43a85f02017-07-18 04:12:29 -0700284 ptrAudioDevice = new AudioDeviceLinuxALSA();
Max Morin098e6c52016-06-28 09:36:25 +0200285 LOG(INFO) << "Linux ALSA APIs will be utilized";
niklase@google.com470e71d2011-07-07 08:21:25 +0000286#endif
Max Morin787eeed2016-06-23 10:42:07 +0200287 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000288#endif // #if defined(WEBRTC_LINUX)
289
Max Morin787eeed2016-06-23 10:42:07 +0200290// Create the *iPhone* implementation of the Audio Device
291//
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000292#if defined(WEBRTC_IOS)
Max Morin787eeed2016-06-23 10:42:07 +0200293 if (audioLayer == kPlatformDefaultAudio) {
294 // Create iOS Audio Device implementation.
295 ptrAudioDevice = new AudioDeviceIOS();
Max Morin098e6c52016-06-28 09:36:25 +0200296 LOG(INFO) << "iPhone Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200297 }
298// END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000299
Max Morin787eeed2016-06-23 10:42:07 +0200300// Create the *Mac* implementation of the Audio Device
301//
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000302#elif defined(WEBRTC_MAC)
Max Morin787eeed2016-06-23 10:42:07 +0200303 if (audioLayer == kPlatformDefaultAudio) {
304 // Create *Mac Audio* implementation
sazab4aa4eb2017-07-19 01:12:36 -0700305 ptrAudioDevice = new AudioDeviceMac();
Max Morin098e6c52016-06-28 09:36:25 +0200306 LOG(INFO) << "Mac OS X Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200307 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000308#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000309
Max Morin787eeed2016-06-23 10:42:07 +0200310 // Create the *Dummy* implementation of the Audio Device
311 // Available for all platforms
312 //
313 if (audioLayer == kDummyAudio) {
314 // Create *Dummy Audio* implementation
315 assert(!ptrAudioDevice);
316 ptrAudioDevice = new AudioDeviceDummy(Id());
Max Morin098e6c52016-06-28 09:36:25 +0200317 LOG(INFO) << "Dummy Audio APIs will be utilized";
Max Morin787eeed2016-06-23 10:42:07 +0200318 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000319#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
Max Morin787eeed2016-06-23 10:42:07 +0200321 if (ptrAudioDevice == NULL) {
Max Morin098e6c52016-06-28 09:36:25 +0200322 LOG(LERROR)
323 << "unable to create the platform specific audio device implementation";
Max Morin787eeed2016-06-23 10:42:07 +0200324 return -1;
325 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
Max Morin787eeed2016-06-23 10:42:07 +0200327 // Store valid output pointers
328 //
329 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000330
Max Morin787eeed2016-06-23 10:42:07 +0200331 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000332}
333
334// ----------------------------------------------------------------------------
335// AttachAudioBuffer
336//
337// Install "bridge" between the platform implemetation and the generic
338// implementation. The "child" shall set the native sampling rate and the
339// number of channels in this function call.
340// ----------------------------------------------------------------------------
341
Max Morin787eeed2016-06-23 10:42:07 +0200342int32_t AudioDeviceModuleImpl::AttachAudioBuffer() {
Max Morin098e6c52016-06-28 09:36:25 +0200343 LOG(INFO) << __FUNCTION__;
niklase@google.com470e71d2011-07-07 08:21:25 +0000344
Max Morin787eeed2016-06-23 10:42:07 +0200345 _audioDeviceBuffer.SetId(_id);
346 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
347 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000348}
349
350// ----------------------------------------------------------------------------
351// ~AudioDeviceModuleImpl - dtor
352// ----------------------------------------------------------------------------
353
Max Morin787eeed2016-06-23 10:42:07 +0200354AudioDeviceModuleImpl::~AudioDeviceModuleImpl() {
Max Morin098e6c52016-06-28 09:36:25 +0200355 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200356 if (_ptrAudioDevice) {
357 delete _ptrAudioDevice;
358 _ptrAudioDevice = NULL;
359 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000360}
361
362// ============================================================================
363// Module
364// ============================================================================
365
366// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000367// Module::TimeUntilNextProcess
368//
369// Returns the number of milliseconds until the module want a worker thread
370// to call Process().
371// ----------------------------------------------------------------------------
372
Max Morin787eeed2016-06-23 10:42:07 +0200373int64_t AudioDeviceModuleImpl::TimeUntilNextProcess() {
374 int64_t now = rtc::TimeMillis();
375 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
376 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377}
378
379// ----------------------------------------------------------------------------
380// Module::Process
381//
382// Check for posted error and warning reports. Generate callbacks if
383// new reports exists.
384// ----------------------------------------------------------------------------
385
Max Morin787eeed2016-06-23 10:42:07 +0200386void AudioDeviceModuleImpl::Process() {
387 _lastProcessTime = rtc::TimeMillis();
niklase@google.com470e71d2011-07-07 08:21:25 +0000388
Max Morin787eeed2016-06-23 10:42:07 +0200389 // kPlayoutWarning
390 if (_ptrAudioDevice->PlayoutWarning()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700391 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200392 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200393 LOG(WARNING) << "=> OnWarningIsReported(kPlayoutWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200394 _ptrCbAudioDeviceObserver->OnWarningIsReported(
395 AudioDeviceObserver::kPlayoutWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 }
Max Morin787eeed2016-06-23 10:42:07 +0200397 _ptrAudioDevice->ClearPlayoutWarning();
398 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
Max Morin787eeed2016-06-23 10:42:07 +0200400 // kPlayoutError
401 if (_ptrAudioDevice->PlayoutError()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700402 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200403 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200404 LOG(LERROR) << "=> OnErrorIsReported(kPlayoutError)";
Max Morin787eeed2016-06-23 10:42:07 +0200405 _ptrCbAudioDeviceObserver->OnErrorIsReported(
406 AudioDeviceObserver::kPlayoutError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000407 }
Max Morin787eeed2016-06-23 10:42:07 +0200408 _ptrAudioDevice->ClearPlayoutError();
409 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000410
Max Morin787eeed2016-06-23 10:42:07 +0200411 // kRecordingWarning
412 if (_ptrAudioDevice->RecordingWarning()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700413 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200414 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200415 LOG(WARNING) << "=> OnWarningIsReported(kRecordingWarning)";
Max Morin787eeed2016-06-23 10:42:07 +0200416 _ptrCbAudioDeviceObserver->OnWarningIsReported(
417 AudioDeviceObserver::kRecordingWarning);
niklase@google.com470e71d2011-07-07 08:21:25 +0000418 }
Max Morin787eeed2016-06-23 10:42:07 +0200419 _ptrAudioDevice->ClearRecordingWarning();
420 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000421
Max Morin787eeed2016-06-23 10:42:07 +0200422 // kRecordingError
423 if (_ptrAudioDevice->RecordingError()) {
kthelgason6bfe49c2017-03-30 01:14:41 -0700424 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +0200425 if (_ptrCbAudioDeviceObserver) {
Max Morin098e6c52016-06-28 09:36:25 +0200426 LOG(LERROR) << "=> OnErrorIsReported(kRecordingError)";
Max Morin787eeed2016-06-23 10:42:07 +0200427 _ptrCbAudioDeviceObserver->OnErrorIsReported(
428 AudioDeviceObserver::kRecordingError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429 }
Max Morin787eeed2016-06-23 10:42:07 +0200430 _ptrAudioDevice->ClearRecordingError();
431 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000432}
433
434// ============================================================================
435// Public API
436// ============================================================================
437
438// ----------------------------------------------------------------------------
439// ActiveAudioLayer
440// ----------------------------------------------------------------------------
441
henrikab2619892015-05-18 16:49:16 +0200442int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
Max Morin098e6c52016-06-28 09:36:25 +0200443 LOG(INFO) << __FUNCTION__;
henrikab2619892015-05-18 16:49:16 +0200444 AudioLayer activeAudio;
445 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
446 return -1;
447 }
448 *audioLayer = activeAudio;
449 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000450}
451
452// ----------------------------------------------------------------------------
453// LastError
454// ----------------------------------------------------------------------------
455
Max Morin787eeed2016-06-23 10:42:07 +0200456AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const {
Max Morin098e6c52016-06-28 09:36:25 +0200457 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200458 return _lastError;
niklase@google.com470e71d2011-07-07 08:21:25 +0000459}
460
461// ----------------------------------------------------------------------------
462// Init
463// ----------------------------------------------------------------------------
464
Max Morin787eeed2016-06-23 10:42:07 +0200465int32_t AudioDeviceModuleImpl::Init() {
Max Morin098e6c52016-06-28 09:36:25 +0200466 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200467 if (_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000468 return 0;
Max Morin84cab202016-07-01 13:35:19 +0200469 RTC_CHECK(_ptrAudioDevice);
Max Morin787eeed2016-06-23 10:42:07 +0200470
Max Morin84cab202016-07-01 13:35:19 +0200471 AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init();
472 RTC_HISTOGRAM_ENUMERATION(
473 "WebRTC.Audio.InitializationResult", static_cast<int>(status),
474 static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
475 if (status != AudioDeviceGeneric::InitStatus::OK) {
476 LOG(LS_ERROR) << "Audio device initialization failed.";
Max Morin787eeed2016-06-23 10:42:07 +0200477 return -1;
478 }
479
480 _initialized = true;
481 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000482}
483
484// ----------------------------------------------------------------------------
485// Terminate
486// ----------------------------------------------------------------------------
487
Max Morin787eeed2016-06-23 10:42:07 +0200488int32_t AudioDeviceModuleImpl::Terminate() {
Max Morin098e6c52016-06-28 09:36:25 +0200489 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200490 if (!_initialized)
niklase@google.com470e71d2011-07-07 08:21:25 +0000491 return 0;
Max Morin787eeed2016-06-23 10:42:07 +0200492
493 if (_ptrAudioDevice->Terminate() == -1) {
494 return -1;
495 }
496
497 _initialized = false;
498 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000499}
500
501// ----------------------------------------------------------------------------
502// Initialized
503// ----------------------------------------------------------------------------
504
Max Morin787eeed2016-06-23 10:42:07 +0200505bool AudioDeviceModuleImpl::Initialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200506 LOG(INFO) << __FUNCTION__ << ": " << _initialized;
Max Morin787eeed2016-06-23 10:42:07 +0200507 return (_initialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000508}
509
510// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000511// InitSpeaker
512// ----------------------------------------------------------------------------
513
Max Morin787eeed2016-06-23 10:42:07 +0200514int32_t AudioDeviceModuleImpl::InitSpeaker() {
Max Morin098e6c52016-06-28 09:36:25 +0200515 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200516 CHECK_INITIALIZED();
517 return (_ptrAudioDevice->InitSpeaker());
niklase@google.com470e71d2011-07-07 08:21:25 +0000518}
519
520// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000521// InitMicrophone
522// ----------------------------------------------------------------------------
523
Max Morin787eeed2016-06-23 10:42:07 +0200524int32_t AudioDeviceModuleImpl::InitMicrophone() {
Max Morin098e6c52016-06-28 09:36:25 +0200525 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200526 CHECK_INITIALIZED();
527 return (_ptrAudioDevice->InitMicrophone());
niklase@google.com470e71d2011-07-07 08:21:25 +0000528}
529
530// ----------------------------------------------------------------------------
531// SpeakerVolumeIsAvailable
532// ----------------------------------------------------------------------------
533
Max Morin787eeed2016-06-23 10:42:07 +0200534int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200535 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200536 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000537
Max Morin787eeed2016-06-23 10:42:07 +0200538 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000539
Max Morin787eeed2016-06-23 10:42:07 +0200540 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) {
541 return -1;
542 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000543
Max Morin787eeed2016-06-23 10:42:07 +0200544 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200545 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200546 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000547}
548
549// ----------------------------------------------------------------------------
550// SetSpeakerVolume
551// ----------------------------------------------------------------------------
552
Max Morin787eeed2016-06-23 10:42:07 +0200553int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200554 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200555 CHECK_INITIALIZED();
556 return (_ptrAudioDevice->SetSpeakerVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000557}
558
559// ----------------------------------------------------------------------------
560// SpeakerVolume
561// ----------------------------------------------------------------------------
562
Max Morin787eeed2016-06-23 10:42:07 +0200563int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200564 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200565 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000566
Max Morin787eeed2016-06-23 10:42:07 +0200567 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000568
Max Morin787eeed2016-06-23 10:42:07 +0200569 if (_ptrAudioDevice->SpeakerVolume(level) == -1) {
570 return -1;
571 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000572
Max Morin787eeed2016-06-23 10:42:07 +0200573 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200574 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200575 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000576}
577
578// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000579// SpeakerIsInitialized
580// ----------------------------------------------------------------------------
581
Max Morin787eeed2016-06-23 10:42:07 +0200582bool AudioDeviceModuleImpl::SpeakerIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200583 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200584 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000585
Max Morin787eeed2016-06-23 10:42:07 +0200586 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200587 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200588 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000589}
590
591// ----------------------------------------------------------------------------
592// MicrophoneIsInitialized
593// ----------------------------------------------------------------------------
594
Max Morin787eeed2016-06-23 10:42:07 +0200595bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +0200596 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200597 CHECK_INITIALIZED_BOOL();
niklase@google.com470e71d2011-07-07 08:21:25 +0000598
Max Morin787eeed2016-06-23 10:42:07 +0200599 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
Max Morin2c332bb2016-07-04 09:03:42 +0200600 LOG(INFO) << "output: " << isInitialized;
Max Morin787eeed2016-06-23 10:42:07 +0200601 return (isInitialized);
niklase@google.com470e71d2011-07-07 08:21:25 +0000602}
603
604// ----------------------------------------------------------------------------
605// MaxSpeakerVolume
606// ----------------------------------------------------------------------------
607
Max Morin787eeed2016-06-23 10:42:07 +0200608int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const {
609 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000610
Max Morin787eeed2016-06-23 10:42:07 +0200611 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000612
Max Morin787eeed2016-06-23 10:42:07 +0200613 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) {
614 return -1;
615 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000616
Max Morin787eeed2016-06-23 10:42:07 +0200617 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +0200618 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000619}
620
621// ----------------------------------------------------------------------------
622// MinSpeakerVolume
623// ----------------------------------------------------------------------------
624
Max Morin787eeed2016-06-23 10:42:07 +0200625int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const {
626 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000627
Max Morin787eeed2016-06-23 10:42:07 +0200628 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000629
Max Morin787eeed2016-06-23 10:42:07 +0200630 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) {
631 return -1;
632 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000633
Max Morin787eeed2016-06-23 10:42:07 +0200634 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +0200635 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000636}
637
638// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000639// SpeakerMuteIsAvailable
640// ----------------------------------------------------------------------------
641
Max Morin787eeed2016-06-23 10:42:07 +0200642int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200643 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200644 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000645
Max Morin787eeed2016-06-23 10:42:07 +0200646 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000647
Max Morin787eeed2016-06-23 10:42:07 +0200648 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) {
649 return -1;
650 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000651
Max Morin787eeed2016-06-23 10:42:07 +0200652 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200653 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200654 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000655}
656
657// ----------------------------------------------------------------------------
658// SetSpeakerMute
659// ----------------------------------------------------------------------------
660
Max Morin787eeed2016-06-23 10:42:07 +0200661int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200662 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200663 CHECK_INITIALIZED();
664 return (_ptrAudioDevice->SetSpeakerMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000665}
666
667// ----------------------------------------------------------------------------
668// SpeakerMute
669// ----------------------------------------------------------------------------
670
Max Morin787eeed2016-06-23 10:42:07 +0200671int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200672 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200673 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000674
Max Morin787eeed2016-06-23 10:42:07 +0200675 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000676
Max Morin787eeed2016-06-23 10:42:07 +0200677 if (_ptrAudioDevice->SpeakerMute(muted) == -1) {
678 return -1;
679 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000680
Max Morin787eeed2016-06-23 10:42:07 +0200681 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200682 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200683 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000684}
685
686// ----------------------------------------------------------------------------
687// MicrophoneMuteIsAvailable
688// ----------------------------------------------------------------------------
689
Max Morin787eeed2016-06-23 10:42:07 +0200690int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200691 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200692 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000693
Max Morin787eeed2016-06-23 10:42:07 +0200694 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000695
Max Morin787eeed2016-06-23 10:42:07 +0200696 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) {
697 return -1;
698 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000699
Max Morin787eeed2016-06-23 10:42:07 +0200700 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200701 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200702 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000703}
704
705// ----------------------------------------------------------------------------
706// SetMicrophoneMute
707// ----------------------------------------------------------------------------
708
Max Morin787eeed2016-06-23 10:42:07 +0200709int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200710 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200711 CHECK_INITIALIZED();
712 return (_ptrAudioDevice->SetMicrophoneMute(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000713}
714
715// ----------------------------------------------------------------------------
716// MicrophoneMute
717// ----------------------------------------------------------------------------
718
Max Morin787eeed2016-06-23 10:42:07 +0200719int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200720 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200721 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000722
Max Morin787eeed2016-06-23 10:42:07 +0200723 bool muted(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000724
Max Morin787eeed2016-06-23 10:42:07 +0200725 if (_ptrAudioDevice->MicrophoneMute(muted) == -1) {
726 return -1;
727 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000728
Max Morin787eeed2016-06-23 10:42:07 +0200729 *enabled = muted;
Max Morin2c332bb2016-07-04 09:03:42 +0200730 LOG(INFO) << "output: " << muted;
Max Morin787eeed2016-06-23 10:42:07 +0200731 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000732}
733
734// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000735// MicrophoneVolumeIsAvailable
736// ----------------------------------------------------------------------------
737
Max Morin787eeed2016-06-23 10:42:07 +0200738int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200739 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200740 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000741
Max Morin787eeed2016-06-23 10:42:07 +0200742 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000743
Max Morin787eeed2016-06-23 10:42:07 +0200744 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
745 return -1;
746 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000747
Max Morin787eeed2016-06-23 10:42:07 +0200748 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200749 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200750 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000751}
752
753// ----------------------------------------------------------------------------
754// SetMicrophoneVolume
755// ----------------------------------------------------------------------------
756
Max Morin787eeed2016-06-23 10:42:07 +0200757int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) {
Max Morin098e6c52016-06-28 09:36:25 +0200758 LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200759 CHECK_INITIALIZED();
760 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
niklase@google.com470e71d2011-07-07 08:21:25 +0000761}
762
763// ----------------------------------------------------------------------------
764// MicrophoneVolume
765// ----------------------------------------------------------------------------
766
Max Morin787eeed2016-06-23 10:42:07 +0200767int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const {
Max Morin098e6c52016-06-28 09:36:25 +0200768 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200769 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000770
Max Morin787eeed2016-06-23 10:42:07 +0200771 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000772
Max Morin787eeed2016-06-23 10:42:07 +0200773 if (_ptrAudioDevice->MicrophoneVolume(level) == -1) {
774 return -1;
775 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000776
Max Morin787eeed2016-06-23 10:42:07 +0200777 *volume = level;
Max Morin2c332bb2016-07-04 09:03:42 +0200778 LOG(INFO) << "output: " << *volume;
Max Morin787eeed2016-06-23 10:42:07 +0200779 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000780}
781
782// ----------------------------------------------------------------------------
783// StereoRecordingIsAvailable
784// ----------------------------------------------------------------------------
785
Max Morin787eeed2016-06-23 10:42:07 +0200786int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(
787 bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200788 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200789 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000790
Max Morin787eeed2016-06-23 10:42:07 +0200791 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000792
Max Morin787eeed2016-06-23 10:42:07 +0200793 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) {
794 return -1;
795 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000796
Max Morin787eeed2016-06-23 10:42:07 +0200797 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200798 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200799 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000800}
801
802// ----------------------------------------------------------------------------
803// SetStereoRecording
804// ----------------------------------------------------------------------------
805
Max Morin787eeed2016-06-23 10:42:07 +0200806int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200807 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
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 if (_ptrAudioDevice->RecordingIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200811 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200812 return -1;
813 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000814
Max Morin787eeed2016-06-23 10:42:07 +0200815 if (_ptrAudioDevice->SetStereoRecording(enable) == -1) {
Max Morin2c332bb2016-07-04 09:03:42 +0200816 LOG(WARNING) << "failed to change stereo recording";
Max Morin787eeed2016-06-23 10:42:07 +0200817 return -1;
818 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000819
Max Morin787eeed2016-06-23 10:42:07 +0200820 int8_t nChannels(1);
821 if (enable) {
822 nChannels = 2;
823 }
824 _audioDeviceBuffer.SetRecordingChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000825
Max Morin787eeed2016-06-23 10:42:07 +0200826 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000827}
828
829// ----------------------------------------------------------------------------
830// StereoRecording
831// ----------------------------------------------------------------------------
832
Max Morin787eeed2016-06-23 10:42:07 +0200833int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200834 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200835 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000836
Max Morin787eeed2016-06-23 10:42:07 +0200837 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000838
Max Morin787eeed2016-06-23 10:42:07 +0200839 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
840 return -1;
841 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000842
Max Morin787eeed2016-06-23 10:42:07 +0200843 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200844 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200845 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000846}
847
848// ----------------------------------------------------------------------------
849// SetRecordingChannel
850// ----------------------------------------------------------------------------
851
Max Morin787eeed2016-06-23 10:42:07 +0200852int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) {
853 if (channel == kChannelBoth) {
Max Morin098e6c52016-06-28 09:36:25 +0200854 LOG(INFO) << __FUNCTION__ << "(both)";
Max Morin787eeed2016-06-23 10:42:07 +0200855 } else if (channel == kChannelLeft) {
Max Morin098e6c52016-06-28 09:36:25 +0200856 LOG(INFO) << __FUNCTION__ << "(left)";
Max Morin787eeed2016-06-23 10:42:07 +0200857 } else {
Max Morin098e6c52016-06-28 09:36:25 +0200858 LOG(INFO) << __FUNCTION__ << "(right)";
Max Morin787eeed2016-06-23 10:42:07 +0200859 }
860 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000861
Max Morin787eeed2016-06-23 10:42:07 +0200862 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000863
Max Morin787eeed2016-06-23 10:42:07 +0200864 if (_ptrAudioDevice->StereoRecording(stereo) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +0200865 LOG(WARNING) << "recording in stereo is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200866 return -1;
867 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000868
Max Morin787eeed2016-06-23 10:42:07 +0200869 return (_audioDeviceBuffer.SetRecordingChannel(channel));
niklase@google.com470e71d2011-07-07 08:21:25 +0000870}
871
872// ----------------------------------------------------------------------------
873// RecordingChannel
874// ----------------------------------------------------------------------------
875
Max Morin787eeed2016-06-23 10:42:07 +0200876int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const {
Max Morin098e6c52016-06-28 09:36:25 +0200877 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200878 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000879
Max Morin787eeed2016-06-23 10:42:07 +0200880 ChannelType chType;
niklase@google.com470e71d2011-07-07 08:21:25 +0000881
Max Morin787eeed2016-06-23 10:42:07 +0200882 if (_audioDeviceBuffer.RecordingChannel(chType) == -1) {
883 return -1;
884 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000885
Max Morin787eeed2016-06-23 10:42:07 +0200886 *channel = chType;
Max Morin787eeed2016-06-23 10:42:07 +0200887 if (*channel == kChannelBoth) {
Max Morin2c332bb2016-07-04 09:03:42 +0200888 LOG(INFO) << "output: both";
Max Morin787eeed2016-06-23 10:42:07 +0200889 } else if (*channel == kChannelLeft) {
Max Morin2c332bb2016-07-04 09:03:42 +0200890 LOG(INFO) << "output: left";
Max Morin787eeed2016-06-23 10:42:07 +0200891 } else {
Max Morin2c332bb2016-07-04 09:03:42 +0200892 LOG(INFO) << "output: right";
Max Morin787eeed2016-06-23 10:42:07 +0200893 }
Max Morin787eeed2016-06-23 10:42:07 +0200894 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000895}
896
897// ----------------------------------------------------------------------------
898// StereoPlayoutIsAvailable
899// ----------------------------------------------------------------------------
900
Max Morin787eeed2016-06-23 10:42:07 +0200901int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const {
Max Morin098e6c52016-06-28 09:36:25 +0200902 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200903 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000904
Max Morin787eeed2016-06-23 10:42:07 +0200905 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000906
Max Morin787eeed2016-06-23 10:42:07 +0200907 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) {
908 return -1;
909 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000910
Max Morin787eeed2016-06-23 10:42:07 +0200911 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200912 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200913 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000914}
915
916// ----------------------------------------------------------------------------
917// SetStereoPlayout
918// ----------------------------------------------------------------------------
919
Max Morin787eeed2016-06-23 10:42:07 +0200920int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200921 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200922 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000923
Max Morin787eeed2016-06-23 10:42:07 +0200924 if (_ptrAudioDevice->PlayoutIsInitialized()) {
Max Morin098e6c52016-06-28 09:36:25 +0200925 LOG(LERROR)
926 << "unable to set stereo mode while playing side is initialized";
Max Morin787eeed2016-06-23 10:42:07 +0200927 return -1;
928 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000929
Max Morin787eeed2016-06-23 10:42:07 +0200930 if (_ptrAudioDevice->SetStereoPlayout(enable)) {
Max Morin098e6c52016-06-28 09:36:25 +0200931 LOG(WARNING) << "stereo playout is not supported";
Max Morin787eeed2016-06-23 10:42:07 +0200932 return -1;
933 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000934
Max Morin787eeed2016-06-23 10:42:07 +0200935 int8_t nChannels(1);
936 if (enable) {
937 nChannels = 2;
938 }
939 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
niklase@google.com470e71d2011-07-07 08:21:25 +0000940
Max Morin787eeed2016-06-23 10:42:07 +0200941 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000942}
943
944// ----------------------------------------------------------------------------
945// StereoPlayout
946// ----------------------------------------------------------------------------
947
Max Morin787eeed2016-06-23 10:42:07 +0200948int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +0200949 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200950 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000951
Max Morin787eeed2016-06-23 10:42:07 +0200952 bool stereo(false);
niklase@google.com470e71d2011-07-07 08:21:25 +0000953
Max Morin787eeed2016-06-23 10:42:07 +0200954 if (_ptrAudioDevice->StereoPlayout(stereo) == -1) {
955 return -1;
956 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000957
Max Morin787eeed2016-06-23 10:42:07 +0200958 *enabled = stereo;
Max Morin2c332bb2016-07-04 09:03:42 +0200959 LOG(INFO) << "output: " << stereo;
Max Morin787eeed2016-06-23 10:42:07 +0200960 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000961}
962
963// ----------------------------------------------------------------------------
964// SetAGC
965// ----------------------------------------------------------------------------
966
Max Morin787eeed2016-06-23 10:42:07 +0200967int32_t AudioDeviceModuleImpl::SetAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +0200968 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +0200969 CHECK_INITIALIZED();
970 return (_ptrAudioDevice->SetAGC(enable));
niklase@google.com470e71d2011-07-07 08:21:25 +0000971}
972
973// ----------------------------------------------------------------------------
974// AGC
975// ----------------------------------------------------------------------------
976
Max Morin787eeed2016-06-23 10:42:07 +0200977bool AudioDeviceModuleImpl::AGC() const {
Max Morin098e6c52016-06-28 09:36:25 +0200978 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200979 CHECK_INITIALIZED_BOOL();
980 return (_ptrAudioDevice->AGC());
niklase@google.com470e71d2011-07-07 08:21:25 +0000981}
982
983// ----------------------------------------------------------------------------
984// PlayoutIsAvailable
985// ----------------------------------------------------------------------------
986
Max Morin787eeed2016-06-23 10:42:07 +0200987int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +0200988 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +0200989 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +0000990
Max Morin787eeed2016-06-23 10:42:07 +0200991 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000992
Max Morin787eeed2016-06-23 10:42:07 +0200993 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) {
994 return -1;
995 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000996
Max Morin787eeed2016-06-23 10:42:07 +0200997 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +0200998 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +0200999 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001000}
1001
1002// ----------------------------------------------------------------------------
1003// RecordingIsAvailable
1004// ----------------------------------------------------------------------------
1005
Max Morin787eeed2016-06-23 10:42:07 +02001006int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) {
Max Morin098e6c52016-06-28 09:36:25 +02001007 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001008 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001009
Max Morin787eeed2016-06-23 10:42:07 +02001010 bool isAvailable(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001011
Max Morin787eeed2016-06-23 10:42:07 +02001012 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) {
1013 return -1;
1014 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001015
Max Morin787eeed2016-06-23 10:42:07 +02001016 *available = isAvailable;
Max Morin2c332bb2016-07-04 09:03:42 +02001017 LOG(INFO) << "output: " << isAvailable;
Max Morin787eeed2016-06-23 10:42:07 +02001018 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001019}
1020
1021// ----------------------------------------------------------------------------
1022// MaxMicrophoneVolume
1023// ----------------------------------------------------------------------------
1024
Max Morin787eeed2016-06-23 10:42:07 +02001025int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const {
Max Morin787eeed2016-06-23 10:42:07 +02001026 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001027
Max Morin787eeed2016-06-23 10:42:07 +02001028 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001029
Max Morin787eeed2016-06-23 10:42:07 +02001030 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) {
1031 return -1;
1032 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001033
Max Morin787eeed2016-06-23 10:42:07 +02001034 *maxVolume = maxVol;
Max Morin787eeed2016-06-23 10:42:07 +02001035 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001036}
1037
1038// ----------------------------------------------------------------------------
1039// MinMicrophoneVolume
1040// ----------------------------------------------------------------------------
1041
Max Morin787eeed2016-06-23 10:42:07 +02001042int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const {
1043 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001044
Max Morin787eeed2016-06-23 10:42:07 +02001045 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001046
Max Morin787eeed2016-06-23 10:42:07 +02001047 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) {
1048 return -1;
1049 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001050
Max Morin787eeed2016-06-23 10:42:07 +02001051 *minVolume = minVol;
Max Morin787eeed2016-06-23 10:42:07 +02001052 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001053}
1054
1055// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001056// PlayoutDevices
1057// ----------------------------------------------------------------------------
1058
Max Morin787eeed2016-06-23 10:42:07 +02001059int16_t AudioDeviceModuleImpl::PlayoutDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001060 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001061 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001062
Max Morin787eeed2016-06-23 10:42:07 +02001063 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
Max Morin2c332bb2016-07-04 09:03:42 +02001064 LOG(INFO) << "output: " << nPlayoutDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001065 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001066}
1067
1068// ----------------------------------------------------------------------------
1069// SetPlayoutDevice I (II)
1070// ----------------------------------------------------------------------------
1071
Max Morin787eeed2016-06-23 10:42:07 +02001072int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001073 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001074 CHECK_INITIALIZED();
1075 return (_ptrAudioDevice->SetPlayoutDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001076}
1077
1078// ----------------------------------------------------------------------------
1079// SetPlayoutDevice II (II)
1080// ----------------------------------------------------------------------------
1081
Max Morin787eeed2016-06-23 10:42:07 +02001082int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001083 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001084 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001085
Max Morin787eeed2016-06-23 10:42:07 +02001086 return (_ptrAudioDevice->SetPlayoutDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001087}
1088
1089// ----------------------------------------------------------------------------
1090// PlayoutDeviceName
1091// ----------------------------------------------------------------------------
1092
pbos@webrtc.org25509882013-04-09 10:30:35 +00001093int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1094 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001095 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001096 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001097 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001098 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001099
Max Morin787eeed2016-06-23 10:42:07 +02001100 if (name == NULL) {
1101 _lastError = kAdmErrArgument;
1102 return -1;
1103 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001104
Max Morin787eeed2016-06-23 10:42:07 +02001105 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) {
1106 return -1;
1107 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001108
Max Morin787eeed2016-06-23 10:42:07 +02001109 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001110 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001111 }
1112 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001113 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001114 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001115
Max Morin787eeed2016-06-23 10:42:07 +02001116 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001117}
1118
1119// ----------------------------------------------------------------------------
1120// RecordingDeviceName
1121// ----------------------------------------------------------------------------
1122
pbos@webrtc.org25509882013-04-09 10:30:35 +00001123int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1124 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001125 char name[kAdmMaxDeviceNameSize],
Max Morin787eeed2016-06-23 10:42:07 +02001126 char guid[kAdmMaxGuidSize]) {
Max Morin098e6c52016-06-28 09:36:25 +02001127 LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)";
Max Morin787eeed2016-06-23 10:42:07 +02001128 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001129
Max Morin787eeed2016-06-23 10:42:07 +02001130 if (name == NULL) {
1131 _lastError = kAdmErrArgument;
1132 return -1;
1133 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001134
Max Morin787eeed2016-06-23 10:42:07 +02001135 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) {
1136 return -1;
1137 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001138
Max Morin787eeed2016-06-23 10:42:07 +02001139 if (name != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001140 LOG(INFO) << "output: name = " << name;
Max Morin787eeed2016-06-23 10:42:07 +02001141 }
1142 if (guid != NULL) {
Max Morin2c332bb2016-07-04 09:03:42 +02001143 LOG(INFO) << "output: guid = " << guid;
Max Morin787eeed2016-06-23 10:42:07 +02001144 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001145
Max Morin787eeed2016-06-23 10:42:07 +02001146 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001147}
1148
1149// ----------------------------------------------------------------------------
1150// RecordingDevices
1151// ----------------------------------------------------------------------------
1152
Max Morin787eeed2016-06-23 10:42:07 +02001153int16_t AudioDeviceModuleImpl::RecordingDevices() {
Max Morin098e6c52016-06-28 09:36:25 +02001154 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001155 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001156
Max Morin787eeed2016-06-23 10:42:07 +02001157 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001158
Max Morin2c332bb2016-07-04 09:03:42 +02001159 LOG(INFO) << "output: " << nRecordingDevices;
Max Morin787eeed2016-06-23 10:42:07 +02001160 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001161}
1162
1163// ----------------------------------------------------------------------------
1164// SetRecordingDevice I (II)
1165// ----------------------------------------------------------------------------
1166
Max Morin787eeed2016-06-23 10:42:07 +02001167int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) {
Max Morin098e6c52016-06-28 09:36:25 +02001168 LOG(INFO) << __FUNCTION__ << "(" << index << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001169 CHECK_INITIALIZED();
1170 return (_ptrAudioDevice->SetRecordingDevice(index));
niklase@google.com470e71d2011-07-07 08:21:25 +00001171}
1172
1173// ----------------------------------------------------------------------------
1174// SetRecordingDevice II (II)
1175// ----------------------------------------------------------------------------
1176
Max Morin787eeed2016-06-23 10:42:07 +02001177int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) {
Max Morin098e6c52016-06-28 09:36:25 +02001178 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001179 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001180
Max Morin787eeed2016-06-23 10:42:07 +02001181 return (_ptrAudioDevice->SetRecordingDevice(device));
niklase@google.com470e71d2011-07-07 08:21:25 +00001182}
1183
1184// ----------------------------------------------------------------------------
1185// InitPlayout
1186// ----------------------------------------------------------------------------
1187
Max Morin787eeed2016-06-23 10:42:07 +02001188int32_t AudioDeviceModuleImpl::InitPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001189 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001190 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001191 if (PlayoutIsInitialized()) {
1192 return 0;
1193 }
Max Morin84cab202016-07-01 13:35:19 +02001194 int32_t result = _ptrAudioDevice->InitPlayout();
1195 LOG(INFO) << "output: " << result;
1196 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
1197 static_cast<int>(result == 0));
1198 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001199}
1200
1201// ----------------------------------------------------------------------------
1202// InitRecording
1203// ----------------------------------------------------------------------------
1204
Max Morin787eeed2016-06-23 10:42:07 +02001205int32_t AudioDeviceModuleImpl::InitRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001206 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001207 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001208 if (RecordingIsInitialized()) {
1209 return 0;
1210 }
Max Morin84cab202016-07-01 13:35:19 +02001211 int32_t result = _ptrAudioDevice->InitRecording();
1212 LOG(INFO) << "output: " << result;
1213 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
1214 static_cast<int>(result == 0));
1215 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001216}
1217
1218// ----------------------------------------------------------------------------
1219// PlayoutIsInitialized
1220// ----------------------------------------------------------------------------
1221
Max Morin787eeed2016-06-23 10:42:07 +02001222bool AudioDeviceModuleImpl::PlayoutIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001223 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001224 CHECK_INITIALIZED_BOOL();
1225 return (_ptrAudioDevice->PlayoutIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001226}
1227
1228// ----------------------------------------------------------------------------
1229// RecordingIsInitialized
1230// ----------------------------------------------------------------------------
1231
Max Morin787eeed2016-06-23 10:42:07 +02001232bool AudioDeviceModuleImpl::RecordingIsInitialized() const {
Max Morin098e6c52016-06-28 09:36:25 +02001233 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001234 CHECK_INITIALIZED_BOOL();
1235 return (_ptrAudioDevice->RecordingIsInitialized());
niklase@google.com470e71d2011-07-07 08:21:25 +00001236}
1237
1238// ----------------------------------------------------------------------------
1239// StartPlayout
1240// ----------------------------------------------------------------------------
1241
Max Morin787eeed2016-06-23 10:42:07 +02001242int32_t AudioDeviceModuleImpl::StartPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001243 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001244 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001245 if (Playing()) {
1246 return 0;
1247 }
henrikaba156cf2016-10-31 08:18:50 -07001248 _audioDeviceBuffer.StartPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001249 int32_t result = _ptrAudioDevice->StartPlayout();
1250 LOG(INFO) << "output: " << result;
1251 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
1252 static_cast<int>(result == 0));
1253 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001254}
1255
1256// ----------------------------------------------------------------------------
1257// StopPlayout
1258// ----------------------------------------------------------------------------
1259
Max Morin787eeed2016-06-23 10:42:07 +02001260int32_t AudioDeviceModuleImpl::StopPlayout() {
Max Morin098e6c52016-06-28 09:36:25 +02001261 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001262 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001263 int32_t result = _ptrAudioDevice->StopPlayout();
henrikaba156cf2016-10-31 08:18:50 -07001264 _audioDeviceBuffer.StopPlayout();
Max Morin84cab202016-07-01 13:35:19 +02001265 LOG(INFO) << "output: " << result;
1266 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
1267 static_cast<int>(result == 0));
1268 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001269}
1270
1271// ----------------------------------------------------------------------------
1272// Playing
1273// ----------------------------------------------------------------------------
1274
Max Morin787eeed2016-06-23 10:42:07 +02001275bool AudioDeviceModuleImpl::Playing() const {
Max Morin098e6c52016-06-28 09:36:25 +02001276 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001277 CHECK_INITIALIZED_BOOL();
1278 return (_ptrAudioDevice->Playing());
niklase@google.com470e71d2011-07-07 08:21:25 +00001279}
1280
1281// ----------------------------------------------------------------------------
1282// StartRecording
1283// ----------------------------------------------------------------------------
1284
Max Morin787eeed2016-06-23 10:42:07 +02001285int32_t AudioDeviceModuleImpl::StartRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001286 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001287 CHECK_INITIALIZED();
maxmorin8c695b42016-07-25 02:46:44 -07001288 if (Recording()) {
1289 return 0;
1290 }
henrikaba156cf2016-10-31 08:18:50 -07001291 _audioDeviceBuffer.StartRecording();
Max Morin84cab202016-07-01 13:35:19 +02001292 int32_t result = _ptrAudioDevice->StartRecording();
1293 LOG(INFO) << "output: " << result;
1294 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
1295 static_cast<int>(result == 0));
1296 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001297}
1298// ----------------------------------------------------------------------------
1299// StopRecording
1300// ----------------------------------------------------------------------------
1301
Max Morin787eeed2016-06-23 10:42:07 +02001302int32_t AudioDeviceModuleImpl::StopRecording() {
Max Morin098e6c52016-06-28 09:36:25 +02001303 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001304 CHECK_INITIALIZED();
Max Morin84cab202016-07-01 13:35:19 +02001305 int32_t result = _ptrAudioDevice->StopRecording();
henrikaba156cf2016-10-31 08:18:50 -07001306 _audioDeviceBuffer.StopRecording();
Max Morin84cab202016-07-01 13:35:19 +02001307 LOG(INFO) << "output: " << result;
1308 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
1309 static_cast<int>(result == 0));
1310 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +00001311}
1312
1313// ----------------------------------------------------------------------------
1314// Recording
1315// ----------------------------------------------------------------------------
1316
Max Morin787eeed2016-06-23 10:42:07 +02001317bool AudioDeviceModuleImpl::Recording() const {
Max Morin098e6c52016-06-28 09:36:25 +02001318 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001319 CHECK_INITIALIZED_BOOL();
1320 return (_ptrAudioDevice->Recording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001321}
1322
1323// ----------------------------------------------------------------------------
1324// RegisterEventObserver
1325// ----------------------------------------------------------------------------
1326
Max Morin787eeed2016-06-23 10:42:07 +02001327int32_t AudioDeviceModuleImpl::RegisterEventObserver(
1328 AudioDeviceObserver* eventCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001329 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001330 rtc::CritScope lock(&_critSectEventCb);
Max Morin787eeed2016-06-23 10:42:07 +02001331 _ptrCbAudioDeviceObserver = eventCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +00001332
Max Morin787eeed2016-06-23 10:42:07 +02001333 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001334}
1335
1336// ----------------------------------------------------------------------------
1337// RegisterAudioCallback
1338// ----------------------------------------------------------------------------
1339
Max Morin787eeed2016-06-23 10:42:07 +02001340int32_t AudioDeviceModuleImpl::RegisterAudioCallback(
1341 AudioTransport* audioCallback) {
Max Morin098e6c52016-06-28 09:36:25 +02001342 LOG(INFO) << __FUNCTION__;
kthelgason6bfe49c2017-03-30 01:14:41 -07001343 rtc::CritScope lock(&_critSectAudioCb);
henrikaf5022222016-11-07 15:56:59 +01001344 return _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
niklase@google.com470e71d2011-07-07 08:21:25 +00001345}
1346
1347// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001348// PlayoutDelay
1349// ----------------------------------------------------------------------------
1350
Max Morin787eeed2016-06-23 10:42:07 +02001351int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const {
Max Morin787eeed2016-06-23 10:42:07 +02001352 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001353
Max Morin787eeed2016-06-23 10:42:07 +02001354 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001355
Max Morin787eeed2016-06-23 10:42:07 +02001356 if (_ptrAudioDevice->PlayoutDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001357 LOG(LERROR) << "failed to retrieve the playout delay";
Max Morin787eeed2016-06-23 10:42:07 +02001358 return -1;
1359 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001360
Max Morin787eeed2016-06-23 10:42:07 +02001361 *delayMS = delay;
Max Morin787eeed2016-06-23 10:42:07 +02001362 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001363}
1364
1365// ----------------------------------------------------------------------------
1366// RecordingDelay
1367// ----------------------------------------------------------------------------
1368
Max Morin787eeed2016-06-23 10:42:07 +02001369int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const {
Max Morin098e6c52016-06-28 09:36:25 +02001370 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001371 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001372
Max Morin787eeed2016-06-23 10:42:07 +02001373 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001374
Max Morin787eeed2016-06-23 10:42:07 +02001375 if (_ptrAudioDevice->RecordingDelay(delay) == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001376 LOG(LERROR) << "failed to retrieve the recording delay";
Max Morin787eeed2016-06-23 10:42:07 +02001377 return -1;
1378 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001379
Max Morin787eeed2016-06-23 10:42:07 +02001380 *delayMS = delay;
Max Morin2c332bb2016-07-04 09:03:42 +02001381 LOG(INFO) << "output: " << *delayMS;
Max Morin787eeed2016-06-23 10:42:07 +02001382 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001383}
1384
1385// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001386// SetRecordingSampleRate
1387// ----------------------------------------------------------------------------
1388
Max Morin787eeed2016-06-23 10:42:07 +02001389int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(
1390 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001391 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001392 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001393
Max Morin787eeed2016-06-23 10:42:07 +02001394 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) {
1395 return -1;
1396 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001397
Max Morin787eeed2016-06-23 10:42:07 +02001398 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001399}
1400
1401// ----------------------------------------------------------------------------
1402// RecordingSampleRate
1403// ----------------------------------------------------------------------------
1404
Max Morin787eeed2016-06-23 10:42:07 +02001405int32_t AudioDeviceModuleImpl::RecordingSampleRate(
1406 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001407 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001408 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001409
Max Morin787eeed2016-06-23 10:42:07 +02001410 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001411
Max Morin787eeed2016-06-23 10:42:07 +02001412 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001413 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001414 return -1;
1415 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001416
Max Morin787eeed2016-06-23 10:42:07 +02001417 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001418 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001419 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001420}
1421
1422// ----------------------------------------------------------------------------
1423// SetPlayoutSampleRate
1424// ----------------------------------------------------------------------------
1425
Max Morin787eeed2016-06-23 10:42:07 +02001426int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(
1427 const uint32_t samplesPerSec) {
Max Morin098e6c52016-06-28 09:36:25 +02001428 LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001429 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001430
Max Morin787eeed2016-06-23 10:42:07 +02001431 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) {
1432 return -1;
1433 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001434
Max Morin787eeed2016-06-23 10:42:07 +02001435 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001436}
1437
1438// ----------------------------------------------------------------------------
1439// PlayoutSampleRate
1440// ----------------------------------------------------------------------------
1441
Max Morin787eeed2016-06-23 10:42:07 +02001442int32_t AudioDeviceModuleImpl::PlayoutSampleRate(
1443 uint32_t* samplesPerSec) const {
Max Morin098e6c52016-06-28 09:36:25 +02001444 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001445 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001446
Max Morin787eeed2016-06-23 10:42:07 +02001447 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001448
Max Morin787eeed2016-06-23 10:42:07 +02001449 if (sampleRate == -1) {
Max Morin098e6c52016-06-28 09:36:25 +02001450 LOG(LERROR) << "failed to retrieve the sample rate";
Max Morin787eeed2016-06-23 10:42:07 +02001451 return -1;
1452 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001453
Max Morin787eeed2016-06-23 10:42:07 +02001454 *samplesPerSec = sampleRate;
Max Morin2c332bb2016-07-04 09:03:42 +02001455 LOG(INFO) << "output: " << *samplesPerSec;
Max Morin787eeed2016-06-23 10:42:07 +02001456 return (0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001457}
1458
1459// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +00001460// SetLoudspeakerStatus
1461// ----------------------------------------------------------------------------
1462
Max Morin787eeed2016-06-23 10:42:07 +02001463int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001464 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
Max Morin787eeed2016-06-23 10:42:07 +02001465 CHECK_INITIALIZED();
niklase@google.com470e71d2011-07-07 08:21:25 +00001466
Max Morin787eeed2016-06-23 10:42:07 +02001467 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) {
1468 return -1;
1469 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001470
Max Morin787eeed2016-06-23 10:42:07 +02001471 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001472}
1473
1474// ----------------------------------------------------------------------------
1475// GetLoudspeakerStatus
1476// ----------------------------------------------------------------------------
1477
henrikac14f5ff2015-09-23 14:08:33 +02001478int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
Max Morin098e6c52016-06-28 09:36:25 +02001479 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001480 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001481 int32_t ok = 0;
henrikac14f5ff2015-09-23 14:08:33 +02001482 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
Max Morin098e6c52016-06-28 09:36:25 +02001483 ok = -1;
henrikac14f5ff2015-09-23 14:08:33 +02001484 }
Max Morin2c332bb2016-07-04 09:03:42 +02001485 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001486 return ok;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001487}
1488
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001489bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001490 LOG(INFO) << __FUNCTION__;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001491 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001492 bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001493 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001494 return isAvailable;
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001495}
1496
henrikac14f5ff2015-09-23 14:08:33 +02001497int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001498 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001499 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001500 int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001501 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001502 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001503}
1504
1505bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001506 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001507 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001508 bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001509 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001510 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001511}
1512
1513int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001514 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001515 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001516 int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001517 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001518 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001519}
1520
1521bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
Max Morin098e6c52016-06-28 09:36:25 +02001522 LOG(INFO) << __FUNCTION__;
henrikac14f5ff2015-09-23 14:08:33 +02001523 CHECK_INITIALIZED_BOOL();
Max Morin098e6c52016-06-28 09:36:25 +02001524 bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable();
Max Morin2c332bb2016-07-04 09:03:42 +02001525 LOG(INFO) << "output: " << isAvailable;
Max Morin098e6c52016-06-28 09:36:25 +02001526 return isAvailable;
henrikac14f5ff2015-09-23 14:08:33 +02001527}
1528
1529int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
Max Morin098e6c52016-06-28 09:36:25 +02001530 LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
henrikac14f5ff2015-09-23 14:08:33 +02001531 CHECK_INITIALIZED();
Max Morin098e6c52016-06-28 09:36:25 +02001532 int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable);
Max Morin2c332bb2016-07-04 09:03:42 +02001533 LOG(INFO) << "output: " << ok;
Max Morin098e6c52016-06-28 09:36:25 +02001534 return ok;
henrikac14f5ff2015-09-23 14:08:33 +02001535}
1536
maxmorin88e31a32016-08-16 00:56:09 -07001537#if defined(WEBRTC_IOS)
henrikaba35d052015-07-14 17:04:08 +02001538int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1539 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001540 LOG(INFO) << __FUNCTION__;
1541 int r = _ptrAudioDevice->GetPlayoutAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001542 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001543 return r;
henrikaba35d052015-07-14 17:04:08 +02001544}
1545
1546int AudioDeviceModuleImpl::GetRecordAudioParameters(
1547 AudioParameters* params) const {
Max Morin098e6c52016-06-28 09:36:25 +02001548 LOG(INFO) << __FUNCTION__;
1549 int r = _ptrAudioDevice->GetRecordAudioParameters(params);
Max Morin2c332bb2016-07-04 09:03:42 +02001550 LOG(INFO) << "output: " << r;
Max Morin098e6c52016-06-28 09:36:25 +02001551 return r;
henrikaba35d052015-07-14 17:04:08 +02001552}
maxmorin88e31a32016-08-16 00:56:09 -07001553#endif // WEBRTC_IOS
henrikaba35d052015-07-14 17:04:08 +02001554
niklase@google.com470e71d2011-07-07 08:21:25 +00001555// ============================================================================
1556// Private Methods
1557// ============================================================================
1558
1559// ----------------------------------------------------------------------------
1560// Platform
1561// ----------------------------------------------------------------------------
1562
Max Morin787eeed2016-06-23 10:42:07 +02001563AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
Max Morin098e6c52016-06-28 09:36:25 +02001564 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001565 return _platformType;
niklase@google.com470e71d2011-07-07 08:21:25 +00001566}
1567
1568// ----------------------------------------------------------------------------
1569// PlatformAudioLayer
1570// ----------------------------------------------------------------------------
1571
Max Morin787eeed2016-06-23 10:42:07 +02001572AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer()
1573 const {
Max Morin098e6c52016-06-28 09:36:25 +02001574 LOG(INFO) << __FUNCTION__;
Max Morin787eeed2016-06-23 10:42:07 +02001575 return _platformAudioLayer;
niklase@google.com470e71d2011-07-07 08:21:25 +00001576}
1577
1578} // namespace webrtc