blob: a11c496289246ec25a90e722c5590a8d7fd1d576 [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
pbos@webrtc.org811269d2013-07-11 13:24:38 +000011#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
12#include "webrtc/modules/audio_device/audio_device_config.h"
13#include "webrtc/modules/audio_device/audio_device_impl.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010014#include "webrtc/system_wrappers/include/ref_count.h"
15#include "webrtc/system_wrappers/include/tick_util.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000017#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000018#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000019
20#if defined(_WIN32)
xians@google.com68efa212011-08-11 12:41:56 +000021 #include "audio_device_wave_win.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
xians@google.com68efa212011-08-11 12:41:56 +000023 #include "audio_device_core_win.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024 #endif
leozwang@google.com39f20512011-07-15 16:29:40 +000025#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020026#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020027#include "webrtc/modules/audio_device/android/audio_device_template.h"
28#include "webrtc/modules/audio_device/android/audio_manager.h"
29#include "webrtc/modules/audio_device/android/audio_record_jni.h"
30#include "webrtc/modules/audio_device/android/audio_track_jni.h"
31#include "webrtc/modules/audio_device/android/opensles_player.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000032#elif defined(WEBRTC_LINUX)
niklase@google.com470e71d2011-07-07 08:21:25 +000033 #if defined(LINUX_ALSA)
Tommi68898a22015-05-19 17:28:07 +020034 #include "audio_device_alsa_linux.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000035 #endif
Tommi68898a22015-05-19 17:28:07 +020036#if defined(LINUX_PULSE)
xians@google.com68efa212011-08-11 12:41:56 +000037 #include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020038#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000039#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000040 #include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000041#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +000042 #include "audio_device_mac.h"
43#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000044
45#if defined(WEBRTC_DUMMY_FILE_DEVICES)
46#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
47#endif
48
pbos@webrtc.org811269d2013-07-11 13:24:38 +000049#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000050#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010051#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
52#include "webrtc/system_wrappers/include/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000053
54#define CHECK_INITIALIZED() \
55{ \
56 if (!_initialized) { \
57 return -1; \
58 }; \
59}
60
61#define CHECK_INITIALIZED_BOOL() \
62{ \
63 if (!_initialized) { \
64 return false; \
65 }; \
66}
67
68namespace webrtc
69{
70
henrike@webrtc.org70efc322012-02-23 17:45:33 +000071AudioDeviceModule* CreateAudioDeviceModule(
pbos@webrtc.org25509882013-04-09 10:30:35 +000072 int32_t id, AudioDeviceModule::AudioLayer audioLayer) {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000073 return AudioDeviceModuleImpl::Create(id, audioLayer);
74}
75
niklase@google.com470e71d2011-07-07 08:21:25 +000076// ============================================================================
77// Static methods
78// ============================================================================
79
80// ----------------------------------------------------------------------------
81// AudioDeviceModule::Create()
82// ----------------------------------------------------------------------------
83
pbos@webrtc.org25509882013-04-09 10:30:35 +000084AudioDeviceModule* AudioDeviceModuleImpl::Create(const int32_t id,
henrika@google.com73d65512011-09-07 15:11:18 +000085 const AudioLayer audioLayer)
niklase@google.com470e71d2011-07-07 08:21:25 +000086{
henrika@google.com73d65512011-09-07 15:11:18 +000087 // Create the generic ref counted (platform independent) implementation.
88 RefCountImpl<AudioDeviceModuleImpl>* audioDevice =
89 new RefCountImpl<AudioDeviceModuleImpl>(id, audioLayer);
niklase@google.com470e71d2011-07-07 08:21:25 +000090
henrika@google.com73d65512011-09-07 15:11:18 +000091 // Ensure that the current platform is supported.
niklase@google.com470e71d2011-07-07 08:21:25 +000092 if (audioDevice->CheckPlatform() == -1)
93 {
94 delete audioDevice;
95 return NULL;
96 }
97
henrika@google.com73d65512011-09-07 15:11:18 +000098 // Create the platform-dependent implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +000099 if (audioDevice->CreatePlatformSpecificObjects() == -1)
100 {
101 delete audioDevice;
102 return NULL;
103 }
104
henrika@google.com73d65512011-09-07 15:11:18 +0000105 // Ensure that the generic audio buffer can communicate with the
106 // platform-specific parts.
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 if (audioDevice->AttachAudioBuffer() == -1)
108 {
109 delete audioDevice;
110 return NULL;
111 }
112
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000113 WebRtcSpl_Init();
114
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 return audioDevice;
116}
117
niklase@google.com470e71d2011-07-07 08:21:25 +0000118// ============================================================================
119// Construction & Destruction
120// ============================================================================
121
122// ----------------------------------------------------------------------------
123// AudioDeviceModuleImpl - ctor
124// ----------------------------------------------------------------------------
125
pbos@webrtc.org25509882013-04-09 10:30:35 +0000126AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
niklase@google.com470e71d2011-07-07 08:21:25 +0000127 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
128 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
129 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
130 _ptrCbAudioDeviceObserver(NULL),
xians@google.com88bd4402011-08-04 15:33:30 +0000131 _ptrAudioDevice(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +0000132 _id(id),
133 _platformAudioLayer(audioLayer),
Tommi68898a22015-05-19 17:28:07 +0200134 _lastProcessTime(TickTime::MillisecondTimestamp()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000135 _platformType(kPlatformNotSupported),
xians@google.com88bd4402011-08-04 15:33:30 +0000136 _initialized(false),
137 _lastError(kAdmErrNone)
niklase@google.com470e71d2011-07-07 08:21:25 +0000138{
139 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
140}
141
142// ----------------------------------------------------------------------------
143// CheckPlatform
144// ----------------------------------------------------------------------------
145
pbos@webrtc.org25509882013-04-09 10:30:35 +0000146int32_t AudioDeviceModuleImpl::CheckPlatform()
niklase@google.com470e71d2011-07-07 08:21:25 +0000147{
148 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
149
150 // Ensure that the current platform is supported
151 //
152 PlatformType platform(kPlatformNotSupported);
153
154#if defined(_WIN32)
155 platform = kPlatformWin32;
156 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
leozwang@google.com522f42b2011-09-19 17:39:05 +0000157#elif defined(WEBRTC_ANDROID)
158 platform = kPlatformAndroid;
159 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
niklase@google.com470e71d2011-07-07 08:21:25 +0000160#elif defined(WEBRTC_LINUX)
161 platform = kPlatformLinux;
162 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000163#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000164 platform = kPlatformIOS;
165 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000166#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000167 platform = kPlatformMac;
168 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
169#endif
170
171 if (platform == kPlatformNotSupported)
172 {
173 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
174 return -1;
175 }
176
177 // Store valid output results
178 //
179 _platformType = platform;
180
181 return 0;
182}
183
184
185// ----------------------------------------------------------------------------
186// CreatePlatformSpecificObjects
187// ----------------------------------------------------------------------------
188
pbos@webrtc.org25509882013-04-09 10:30:35 +0000189int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
niklase@google.com470e71d2011-07-07 08:21:25 +0000190{
191 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
192
193 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
xians@google.combf5d2ba2011-08-16 07:44:19 +0000195#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
196 ptrAudioDevice = new AudioDeviceDummy(Id());
197 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000198#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
199 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
200 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
201 "Will use file-playing dummy device.");
xians@google.combf5d2ba2011-08-16 07:44:19 +0000202#else
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000203 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
205 // Create the *Windows* implementation of the Audio Device
206 //
207#if defined(_WIN32)
208 if ((audioLayer == kWindowsWaveAudio)
209#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
210 // Wave audio is default if Core audio is not supported in this build
211 || (audioLayer == kPlatformDefaultAudio)
212#endif
213 )
214 {
215 // create *Windows Wave Audio* implementation
216 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
217 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
218 }
219#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
220 if ((audioLayer == kWindowsCoreAudio) ||
221 (audioLayer == kPlatformDefaultAudio)
222 )
223 {
224 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
225
226 if (AudioDeviceWindowsCore::CoreAudioIsSupported())
227 {
228 // create *Windows Core Audio* implementation
229 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
230 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
231 }
232 else
233 {
234 // create *Windows Wave Audio* implementation
235 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
236 if (ptrAudioDevice != NULL)
237 {
238 // Core Audio was not supported => revert to Windows Wave instead
239 _platformAudioLayer = kWindowsWaveAudio; // modify the state set at construction
240 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
241 }
242 }
243 }
244#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000245#endif // #if defined(_WIN32)
246
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000247#if defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +0200248 // Create an Android audio manager.
249 _audioManagerAndroid.reset(new AudioManager());
250 // Select best possible combination of audio layers.
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000251 if (audioLayer == kPlatformDefaultAudio) {
henrikab2619892015-05-18 16:49:16 +0200252 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
253 // Always use OpenSL ES for output on devices that supports the
254 // low-latency output audio path.
255 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
256 } else {
257 // Use Java-based audio in both directions when low-latency output
258 // is not supported.
259 audioLayer = kAndroidJavaAudio;
260 }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000261 }
henrikab2619892015-05-18 16:49:16 +0200262 AudioManager* audio_manager = _audioManagerAndroid.get();
263 if (audioLayer == kAndroidJavaAudio) {
264 // Java audio for both input and output audio.
265 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
266 audioLayer, audio_manager);
267 } 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.
275 ptrAudioDevice = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000276 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000277 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
279 // Create the *Linux* implementation of the Audio Device
280 //
281#elif defined(WEBRTC_LINUX)
282 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
283 {
284#if defined(LINUX_PULSE)
285 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
286
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000287 // create *Linux PulseAudio* implementation
288 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
289 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000290 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000291 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000292 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
293 }
294 else
295 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000296 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000297#endif
298#if defined(LINUX_ALSA)
299 // create *Linux ALSA Audio* implementation
300 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
301 if (ptrAudioDevice != NULL)
302 {
303 // Pulse Audio was not supported => revert to ALSA instead
304 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
305 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
306 }
307#endif
308#if defined(LINUX_PULSE)
309 }
310#endif
311 }
312 else if (audioLayer == kLinuxAlsaAudio)
313 {
314#if defined(LINUX_ALSA)
315 // create *Linux ALSA Audio* implementation
316 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
317 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
318#endif
319 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000320#endif // #if defined(WEBRTC_LINUX)
321
322 // Create the *iPhone* implementation of the Audio Device
323 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000324#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000325 if (audioLayer == kPlatformDefaultAudio)
326 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000327 // Create iOS Audio Device implementation.
henrikaba35d052015-07-14 17:04:08 +0200328 ptrAudioDevice = new AudioDeviceIOS();
niklase@google.com470e71d2011-07-07 08:21:25 +0000329 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
330 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000331 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000332
333 // Create the *Mac* implementation of the Audio Device
334 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000335#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000336 if (audioLayer == kPlatformDefaultAudio)
337 {
338 // Create *Mac Audio* implementation
339 ptrAudioDevice = new AudioDeviceMac(Id());
340 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
341 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000342#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000343
344 // Create the *Dummy* implementation of the Audio Device
345 // Available for all platforms
346 //
347 if (audioLayer == kDummyAudio)
348 {
349 // Create *Dummy Audio* implementation
350 assert(!ptrAudioDevice);
351 ptrAudioDevice = new AudioDeviceDummy(Id());
352 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000354#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000355
356 if (ptrAudioDevice == NULL)
357 {
358 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
359 return -1;
360 }
361
niklase@google.com470e71d2011-07-07 08:21:25 +0000362 // Store valid output pointers
363 //
364 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000365
366 return 0;
367}
368
369// ----------------------------------------------------------------------------
370// AttachAudioBuffer
371//
372// Install "bridge" between the platform implemetation and the generic
373// implementation. The "child" shall set the native sampling rate and the
374// number of channels in this function call.
375// ----------------------------------------------------------------------------
376
pbos@webrtc.org25509882013-04-09 10:30:35 +0000377int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000378{
379 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
380
381 _audioDeviceBuffer.SetId(_id);
382 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
383 return 0;
384}
385
386// ----------------------------------------------------------------------------
387// ~AudioDeviceModuleImpl - dtor
388// ----------------------------------------------------------------------------
389
390AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
391{
392 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000393
394 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 {
henrika@google.com73d65512011-09-07 15:11:18 +0000396 delete _ptrAudioDevice;
397 _ptrAudioDevice = NULL;
398 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 delete &_critSect;
401 delete &_critSectEventCb;
402 delete &_critSectAudioCb;
403}
404
405// ============================================================================
406// Module
407// ============================================================================
408
409// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000410// Module::TimeUntilNextProcess
411//
412// Returns the number of milliseconds until the module want a worker thread
413// to call Process().
414// ----------------------------------------------------------------------------
415
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000416int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000417{
Tommi68898a22015-05-19 17:28:07 +0200418 int64_t now = TickTime::MillisecondTimestamp();
419 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
420 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000421}
422
423// ----------------------------------------------------------------------------
424// Module::Process
425//
426// Check for posted error and warning reports. Generate callbacks if
427// new reports exists.
428// ----------------------------------------------------------------------------
429
torbjorngda33a8a2016-02-25 04:34:03 -0800430int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000431{
niklase@google.com470e71d2011-07-07 08:21:25 +0000432
Tommi68898a22015-05-19 17:28:07 +0200433 _lastProcessTime = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000434
435 // kPlayoutWarning
436 if (_ptrAudioDevice->PlayoutWarning())
437 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000438 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 if (_ptrCbAudioDeviceObserver)
440 {
441 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
442 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
443 }
444 _ptrAudioDevice->ClearPlayoutWarning();
445 }
446
447 // kPlayoutError
448 if (_ptrAudioDevice->PlayoutError())
449 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000450 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000451 if (_ptrCbAudioDeviceObserver)
452 {
453 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
454 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
455 }
456 _ptrAudioDevice->ClearPlayoutError();
457 }
458
459 // kRecordingWarning
460 if (_ptrAudioDevice->RecordingWarning())
461 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000462 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000463 if (_ptrCbAudioDeviceObserver)
464 {
465 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
466 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
467 }
468 _ptrAudioDevice->ClearRecordingWarning();
469 }
470
471 // kRecordingError
472 if (_ptrAudioDevice->RecordingError())
473 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000474 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000475 if (_ptrCbAudioDeviceObserver)
476 {
477 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
478 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
479 }
480 _ptrAudioDevice->ClearRecordingError();
481 }
torbjorngda33a8a2016-02-25 04:34:03 -0800482
483 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484}
485
486// ============================================================================
487// Public API
488// ============================================================================
489
490// ----------------------------------------------------------------------------
491// ActiveAudioLayer
492// ----------------------------------------------------------------------------
493
henrikab2619892015-05-18 16:49:16 +0200494int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
495 AudioLayer activeAudio;
496 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
497 return -1;
498 }
499 *audioLayer = activeAudio;
500 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000501}
502
503// ----------------------------------------------------------------------------
504// LastError
505// ----------------------------------------------------------------------------
506
507AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
508{
509 return _lastError;
510}
511
512// ----------------------------------------------------------------------------
513// Init
514// ----------------------------------------------------------------------------
515
pbos@webrtc.org25509882013-04-09 10:30:35 +0000516int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000517{
niklase@google.com470e71d2011-07-07 08:21:25 +0000518
519 if (_initialized)
520 return 0;
521
niklase@google.com470e71d2011-07-07 08:21:25 +0000522 if (!_ptrAudioDevice)
523 return -1;
524
niklase@google.com470e71d2011-07-07 08:21:25 +0000525 if (_ptrAudioDevice->Init() == -1)
526 {
527 return -1;
528 }
529
530 _initialized = true;
531 return 0;
532}
533
534// ----------------------------------------------------------------------------
535// Terminate
536// ----------------------------------------------------------------------------
537
pbos@webrtc.org25509882013-04-09 10:30:35 +0000538int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000539{
niklase@google.com470e71d2011-07-07 08:21:25 +0000540
541 if (!_initialized)
542 return 0;
543
544 if (_ptrAudioDevice->Terminate() == -1)
545 {
546 return -1;
547 }
548
549 _initialized = false;
550 return 0;
551}
552
553// ----------------------------------------------------------------------------
554// Initialized
555// ----------------------------------------------------------------------------
556
557bool AudioDeviceModuleImpl::Initialized() const
558{
niklase@google.com470e71d2011-07-07 08:21:25 +0000559
560 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
561 return (_initialized);
562}
563
564// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000565// InitSpeaker
566// ----------------------------------------------------------------------------
567
pbos@webrtc.org25509882013-04-09 10:30:35 +0000568int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000569{
niklase@google.com470e71d2011-07-07 08:21:25 +0000570 CHECK_INITIALIZED();
571 return (_ptrAudioDevice->InitSpeaker());
572}
573
574// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000575// InitMicrophone
576// ----------------------------------------------------------------------------
577
pbos@webrtc.org25509882013-04-09 10:30:35 +0000578int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000579{
niklase@google.com470e71d2011-07-07 08:21:25 +0000580 CHECK_INITIALIZED();
581 return (_ptrAudioDevice->InitMicrophone());
582}
583
584// ----------------------------------------------------------------------------
585// SpeakerVolumeIsAvailable
586// ----------------------------------------------------------------------------
587
pbos@webrtc.org25509882013-04-09 10:30:35 +0000588int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000589{
niklase@google.com470e71d2011-07-07 08:21:25 +0000590 CHECK_INITIALIZED();
591
592 bool isAvailable(0);
593
594 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
595 {
596 return -1;
597 }
598
599 *available = isAvailable;
600
601 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
602 return (0);
603}
604
605// ----------------------------------------------------------------------------
606// SetSpeakerVolume
607// ----------------------------------------------------------------------------
608
pbos@webrtc.org25509882013-04-09 10:30:35 +0000609int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000610{
niklase@google.com470e71d2011-07-07 08:21:25 +0000611 CHECK_INITIALIZED();
612 return (_ptrAudioDevice->SetSpeakerVolume(volume));
613}
614
615// ----------------------------------------------------------------------------
616// SpeakerVolume
617// ----------------------------------------------------------------------------
618
pbos@webrtc.org25509882013-04-09 10:30:35 +0000619int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000620{
niklase@google.com470e71d2011-07-07 08:21:25 +0000621 CHECK_INITIALIZED();
622
pbos@webrtc.org25509882013-04-09 10:30:35 +0000623 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000624
625 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
626 {
627 return -1;
628 }
629
630 *volume = level;
631
632 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
633 return (0);
634}
635
636// ----------------------------------------------------------------------------
637// SetWaveOutVolume
638// ----------------------------------------------------------------------------
639
pbos@webrtc.org25509882013-04-09 10:30:35 +0000640int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000641{
niklase@google.com470e71d2011-07-07 08:21:25 +0000642 CHECK_INITIALIZED();
643 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
644}
645
646// ----------------------------------------------------------------------------
647// WaveOutVolume
648// ----------------------------------------------------------------------------
649
pbos@webrtc.org25509882013-04-09 10:30:35 +0000650int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000651{
niklase@google.com470e71d2011-07-07 08:21:25 +0000652 CHECK_INITIALIZED();
653
pbos@webrtc.org25509882013-04-09 10:30:35 +0000654 uint16_t volLeft(0);
655 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000656
657 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
658 {
659 return -1;
660 }
661
662 *volumeLeft = volLeft;
663 *volumeRight = volRight;
664
665 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
666 *volumeLeft, *volumeRight);
667
668 return (0);
669}
670
671// ----------------------------------------------------------------------------
672// SpeakerIsInitialized
673// ----------------------------------------------------------------------------
674
675bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
676{
niklase@google.com470e71d2011-07-07 08:21:25 +0000677 CHECK_INITIALIZED_BOOL();
678
679 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
680
681 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
682 return (isInitialized);
683}
684
685// ----------------------------------------------------------------------------
686// MicrophoneIsInitialized
687// ----------------------------------------------------------------------------
688
689bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
690{
niklase@google.com470e71d2011-07-07 08:21:25 +0000691 CHECK_INITIALIZED_BOOL();
692
693 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
694
695 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
696 return (isInitialized);
697}
698
699// ----------------------------------------------------------------------------
700// MaxSpeakerVolume
701// ----------------------------------------------------------------------------
702
pbos@webrtc.org25509882013-04-09 10:30:35 +0000703int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000704{
niklase@google.com470e71d2011-07-07 08:21:25 +0000705 CHECK_INITIALIZED();
706
pbos@webrtc.org25509882013-04-09 10:30:35 +0000707 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000708
709 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
710 {
711 return -1;
712 }
713
714 *maxVolume = maxVol;
715
716 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
717 return (0);
718}
719
720// ----------------------------------------------------------------------------
721// MinSpeakerVolume
722// ----------------------------------------------------------------------------
723
pbos@webrtc.org25509882013-04-09 10:30:35 +0000724int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000725{
niklase@google.com470e71d2011-07-07 08:21:25 +0000726 CHECK_INITIALIZED();
727
pbos@webrtc.org25509882013-04-09 10:30:35 +0000728 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000729
730 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
731 {
732 return -1;
733 }
734
735 *minVolume = minVol;
736
737 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
738 return (0);
739}
740
741// ----------------------------------------------------------------------------
742// SpeakerVolumeStepSize
743// ----------------------------------------------------------------------------
744
pbos@webrtc.org25509882013-04-09 10:30:35 +0000745int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000746{
niklase@google.com470e71d2011-07-07 08:21:25 +0000747 CHECK_INITIALIZED();
748
pbos@webrtc.org25509882013-04-09 10:30:35 +0000749 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000750
751 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
752 {
753 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
754 return -1;
755 }
756
757 *stepSize = delta;
758
759 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
760 return (0);
761}
762
763// ----------------------------------------------------------------------------
764// SpeakerMuteIsAvailable
765// ----------------------------------------------------------------------------
766
pbos@webrtc.org25509882013-04-09 10:30:35 +0000767int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000768{
niklase@google.com470e71d2011-07-07 08:21:25 +0000769 CHECK_INITIALIZED();
770
771 bool isAvailable(0);
772
773 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
774 {
775 return -1;
776 }
777
778 *available = isAvailable;
779
780 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
781 return (0);
782}
783
784// ----------------------------------------------------------------------------
785// SetSpeakerMute
786// ----------------------------------------------------------------------------
787
pbos@webrtc.org25509882013-04-09 10:30:35 +0000788int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000789{
niklase@google.com470e71d2011-07-07 08:21:25 +0000790 CHECK_INITIALIZED();
791 return (_ptrAudioDevice->SetSpeakerMute(enable));
792}
793
794// ----------------------------------------------------------------------------
795// SpeakerMute
796// ----------------------------------------------------------------------------
797
pbos@webrtc.org25509882013-04-09 10:30:35 +0000798int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000799{
niklase@google.com470e71d2011-07-07 08:21:25 +0000800 CHECK_INITIALIZED();
801
802 bool muted(false);
803
804 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
805 {
806 return -1;
807 }
808
809 *enabled = muted;
810
811 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
812 return (0);
813}
814
815// ----------------------------------------------------------------------------
816// MicrophoneMuteIsAvailable
817// ----------------------------------------------------------------------------
818
pbos@webrtc.org25509882013-04-09 10:30:35 +0000819int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000820{
niklase@google.com470e71d2011-07-07 08:21:25 +0000821 CHECK_INITIALIZED();
822
823 bool isAvailable(0);
824
825 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
826 {
827 return -1;
828 }
829
830 *available = isAvailable;
831
832 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
833 return (0);
834}
835
836// ----------------------------------------------------------------------------
837// SetMicrophoneMute
838// ----------------------------------------------------------------------------
839
pbos@webrtc.org25509882013-04-09 10:30:35 +0000840int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000841{
niklase@google.com470e71d2011-07-07 08:21:25 +0000842 CHECK_INITIALIZED();
843 return (_ptrAudioDevice->SetMicrophoneMute(enable));
844}
845
846// ----------------------------------------------------------------------------
847// MicrophoneMute
848// ----------------------------------------------------------------------------
849
pbos@webrtc.org25509882013-04-09 10:30:35 +0000850int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000851{
niklase@google.com470e71d2011-07-07 08:21:25 +0000852 CHECK_INITIALIZED();
853
854 bool muted(false);
855
856 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
857 {
858 return -1;
859 }
860
861 *enabled = muted;
862
863 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
864 return (0);
865}
866
867// ----------------------------------------------------------------------------
868// MicrophoneBoostIsAvailable
869// ----------------------------------------------------------------------------
870
pbos@webrtc.org25509882013-04-09 10:30:35 +0000871int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000872{
niklase@google.com470e71d2011-07-07 08:21:25 +0000873 CHECK_INITIALIZED();
874
875 bool isAvailable(0);
876
877 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
878 {
879 return -1;
880 }
881
882 *available = isAvailable;
883
884 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
885 return (0);
886}
887
888// ----------------------------------------------------------------------------
889// SetMicrophoneBoost
890// ----------------------------------------------------------------------------
891
pbos@webrtc.org25509882013-04-09 10:30:35 +0000892int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000893{
niklase@google.com470e71d2011-07-07 08:21:25 +0000894 CHECK_INITIALIZED();
895 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
896}
897
898// ----------------------------------------------------------------------------
899// MicrophoneBoost
900// ----------------------------------------------------------------------------
901
pbos@webrtc.org25509882013-04-09 10:30:35 +0000902int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000903{
niklase@google.com470e71d2011-07-07 08:21:25 +0000904 CHECK_INITIALIZED();
905
906 bool onOff(false);
907
908 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
909 {
910 return -1;
911 }
912
913 *enabled = onOff;
914
915 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
916 return (0);
917}
918
919// ----------------------------------------------------------------------------
920// MicrophoneVolumeIsAvailable
921// ----------------------------------------------------------------------------
922
pbos@webrtc.org25509882013-04-09 10:30:35 +0000923int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000924{
niklase@google.com470e71d2011-07-07 08:21:25 +0000925 CHECK_INITIALIZED();
926
927 bool isAvailable(0);
928
929 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
930 {
931 return -1;
932 }
933
934 *available = isAvailable;
935
936 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
937 return (0);
938}
939
940// ----------------------------------------------------------------------------
941// SetMicrophoneVolume
942// ----------------------------------------------------------------------------
943
pbos@webrtc.org25509882013-04-09 10:30:35 +0000944int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000945{
niklase@google.com470e71d2011-07-07 08:21:25 +0000946 CHECK_INITIALIZED();
947 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
948}
949
950// ----------------------------------------------------------------------------
951// MicrophoneVolume
952// ----------------------------------------------------------------------------
953
pbos@webrtc.org25509882013-04-09 10:30:35 +0000954int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000955{
956 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
957 CHECK_INITIALIZED();
958
pbos@webrtc.org25509882013-04-09 10:30:35 +0000959 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000960
961 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
962 {
963 return -1;
964 }
965
966 *volume = level;
967
968 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
969 return (0);
970}
971
972// ----------------------------------------------------------------------------
973// StereoRecordingIsAvailable
974// ----------------------------------------------------------------------------
975
pbos@webrtc.org25509882013-04-09 10:30:35 +0000976int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000977{
niklase@google.com470e71d2011-07-07 08:21:25 +0000978 CHECK_INITIALIZED();
979
980 bool isAvailable(0);
981
982 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
983 {
984 return -1;
985 }
986
987 *available = isAvailable;
988
989 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
990 return (0);
991}
992
993// ----------------------------------------------------------------------------
994// SetStereoRecording
995// ----------------------------------------------------------------------------
996
pbos@webrtc.org25509882013-04-09 10:30:35 +0000997int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000998{
niklase@google.com470e71d2011-07-07 08:21:25 +0000999 CHECK_INITIALIZED();
1000
1001 if (_ptrAudioDevice->RecordingIsInitialized())
1002 {
1003 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1004 return -1;
1005 }
1006
1007 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1008 {
1009 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1010 return -1;
1011 }
1012
pbos@webrtc.org25509882013-04-09 10:30:35 +00001013 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001014 if (enable)
1015 {
1016 nChannels = 2;
1017 }
1018 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1019
1020 return 0;
1021}
1022
1023// ----------------------------------------------------------------------------
1024// StereoRecording
1025// ----------------------------------------------------------------------------
1026
pbos@webrtc.org25509882013-04-09 10:30:35 +00001027int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001028{
niklase@google.com470e71d2011-07-07 08:21:25 +00001029 CHECK_INITIALIZED();
1030
1031 bool stereo(false);
1032
1033 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1034 {
1035 return -1;
1036 }
1037
1038 *enabled = stereo;
1039
1040 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1041 return (0);
1042}
1043
1044// ----------------------------------------------------------------------------
1045// SetRecordingChannel
1046// ----------------------------------------------------------------------------
1047
pbos@webrtc.org25509882013-04-09 10:30:35 +00001048int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001049{
1050 if (channel == kChannelBoth)
1051 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001052 }
1053 else if (channel == kChannelLeft)
1054 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001055 }
1056 else
1057 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001058 }
1059 CHECK_INITIALIZED();
1060
1061 bool stereo(false);
1062
1063 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1064 {
1065 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1066 return -1;
1067 }
1068
1069 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1070}
1071
1072// ----------------------------------------------------------------------------
1073// RecordingChannel
1074// ----------------------------------------------------------------------------
1075
pbos@webrtc.org25509882013-04-09 10:30:35 +00001076int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001077{
niklase@google.com470e71d2011-07-07 08:21:25 +00001078 CHECK_INITIALIZED();
1079
1080 ChannelType chType;
1081
1082 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1083 {
1084 return -1;
1085 }
1086
1087 *channel = chType;
1088
1089 if (*channel == kChannelBoth)
1090 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001091 }
1092 else if (*channel == kChannelLeft)
1093 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001094 }
1095 else
1096 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001097 }
1098
1099 return (0);
1100}
1101
1102// ----------------------------------------------------------------------------
1103// StereoPlayoutIsAvailable
1104// ----------------------------------------------------------------------------
1105
pbos@webrtc.org25509882013-04-09 10:30:35 +00001106int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001107{
niklase@google.com470e71d2011-07-07 08:21:25 +00001108 CHECK_INITIALIZED();
1109
1110 bool isAvailable(0);
1111
1112 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1113 {
1114 return -1;
1115 }
1116
1117 *available = isAvailable;
1118
1119 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1120 return (0);
1121}
1122
1123// ----------------------------------------------------------------------------
1124// SetStereoPlayout
1125// ----------------------------------------------------------------------------
1126
pbos@webrtc.org25509882013-04-09 10:30:35 +00001127int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001128{
niklase@google.com470e71d2011-07-07 08:21:25 +00001129 CHECK_INITIALIZED();
1130
1131 if (_ptrAudioDevice->PlayoutIsInitialized())
1132 {
1133 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1134 return -1;
1135 }
1136
1137 if (_ptrAudioDevice->SetStereoPlayout(enable))
1138 {
1139 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1140 return -1;
1141 }
1142
pbos@webrtc.org25509882013-04-09 10:30:35 +00001143 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001144 if (enable)
1145 {
1146 nChannels = 2;
1147 }
1148 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1149
1150 return 0;
1151}
1152
1153// ----------------------------------------------------------------------------
1154// StereoPlayout
1155// ----------------------------------------------------------------------------
1156
pbos@webrtc.org25509882013-04-09 10:30:35 +00001157int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001158{
niklase@google.com470e71d2011-07-07 08:21:25 +00001159 CHECK_INITIALIZED();
1160
1161 bool stereo(false);
1162
1163 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1164 {
1165 return -1;
1166 }
1167
1168 *enabled = stereo;
1169
1170 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1171 return (0);
1172}
1173
1174// ----------------------------------------------------------------------------
1175// SetAGC
1176// ----------------------------------------------------------------------------
1177
pbos@webrtc.org25509882013-04-09 10:30:35 +00001178int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001179{
niklase@google.com470e71d2011-07-07 08:21:25 +00001180 CHECK_INITIALIZED();
1181 return (_ptrAudioDevice->SetAGC(enable));
1182}
1183
1184// ----------------------------------------------------------------------------
1185// AGC
1186// ----------------------------------------------------------------------------
1187
1188bool AudioDeviceModuleImpl::AGC() const
1189{
niklase@google.com470e71d2011-07-07 08:21:25 +00001190 CHECK_INITIALIZED_BOOL();
1191 return (_ptrAudioDevice->AGC());
1192}
1193
1194// ----------------------------------------------------------------------------
1195// PlayoutIsAvailable
1196// ----------------------------------------------------------------------------
1197
pbos@webrtc.org25509882013-04-09 10:30:35 +00001198int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001199{
niklase@google.com470e71d2011-07-07 08:21:25 +00001200 CHECK_INITIALIZED();
1201
1202 bool isAvailable(0);
1203
1204 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1205 {
1206 return -1;
1207 }
1208
1209 *available = isAvailable;
1210
1211 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1212 return (0);
1213}
1214
1215// ----------------------------------------------------------------------------
1216// RecordingIsAvailable
1217// ----------------------------------------------------------------------------
1218
pbos@webrtc.org25509882013-04-09 10:30:35 +00001219int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001220{
niklase@google.com470e71d2011-07-07 08:21:25 +00001221 CHECK_INITIALIZED();
1222
1223 bool isAvailable(0);
1224
1225 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1226 {
1227 return -1;
1228 }
1229
1230 *available = isAvailable;
1231
1232 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1233 return (0);
1234}
1235
1236// ----------------------------------------------------------------------------
1237// MaxMicrophoneVolume
1238// ----------------------------------------------------------------------------
1239
pbos@webrtc.org25509882013-04-09 10:30:35 +00001240int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001241{
1242 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1243 CHECK_INITIALIZED();
1244
pbos@webrtc.org25509882013-04-09 10:30:35 +00001245 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001246
1247 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1248 {
1249 return -1;
1250 }
1251
1252 *maxVolume = maxVol;
1253
1254 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1255 return (0);
1256}
1257
1258// ----------------------------------------------------------------------------
1259// MinMicrophoneVolume
1260// ----------------------------------------------------------------------------
1261
pbos@webrtc.org25509882013-04-09 10:30:35 +00001262int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001263{
niklase@google.com470e71d2011-07-07 08:21:25 +00001264 CHECK_INITIALIZED();
1265
pbos@webrtc.org25509882013-04-09 10:30:35 +00001266 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001267
1268 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1269 {
1270 return -1;
1271 }
1272
1273 *minVolume = minVol;
1274
1275 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1276 return (0);
1277}
1278
1279// ----------------------------------------------------------------------------
1280// MicrophoneVolumeStepSize
1281// ----------------------------------------------------------------------------
1282
pbos@webrtc.org25509882013-04-09 10:30:35 +00001283int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001284{
niklase@google.com470e71d2011-07-07 08:21:25 +00001285 CHECK_INITIALIZED();
1286
pbos@webrtc.org25509882013-04-09 10:30:35 +00001287 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001288
1289 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1290 {
1291 return -1;
1292 }
1293
1294 *stepSize = delta;
1295
1296 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1297 return (0);
1298}
1299
1300// ----------------------------------------------------------------------------
1301// PlayoutDevices
1302// ----------------------------------------------------------------------------
1303
pbos@webrtc.org25509882013-04-09 10:30:35 +00001304int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001305{
niklase@google.com470e71d2011-07-07 08:21:25 +00001306 CHECK_INITIALIZED();
1307
pbos@webrtc.org25509882013-04-09 10:30:35 +00001308 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001309
1310 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001311 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001312}
1313
1314// ----------------------------------------------------------------------------
1315// SetPlayoutDevice I (II)
1316// ----------------------------------------------------------------------------
1317
pbos@webrtc.org25509882013-04-09 10:30:35 +00001318int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001319{
niklase@google.com470e71d2011-07-07 08:21:25 +00001320 CHECK_INITIALIZED();
1321 return (_ptrAudioDevice->SetPlayoutDevice(index));
1322}
1323
1324// ----------------------------------------------------------------------------
1325// SetPlayoutDevice II (II)
1326// ----------------------------------------------------------------------------
1327
pbos@webrtc.org25509882013-04-09 10:30:35 +00001328int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001329{
1330 if (device == kDefaultDevice)
1331 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001332 }
1333 else
1334 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001335 }
1336 CHECK_INITIALIZED();
1337
1338 return (_ptrAudioDevice->SetPlayoutDevice(device));
1339}
1340
1341// ----------------------------------------------------------------------------
1342// PlayoutDeviceName
1343// ----------------------------------------------------------------------------
1344
pbos@webrtc.org25509882013-04-09 10:30:35 +00001345int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1346 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001347 char name[kAdmMaxDeviceNameSize],
1348 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001349{
niklase@google.com470e71d2011-07-07 08:21:25 +00001350 CHECK_INITIALIZED();
1351
1352 if (name == NULL)
1353 {
1354 _lastError = kAdmErrArgument;
1355 return -1;
1356 }
1357
1358 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1359 {
1360 return -1;
1361 }
1362
1363 if (name != NULL)
1364 {
1365 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1366 }
1367 if (guid != NULL)
1368 {
1369 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1370 }
1371
1372 return (0);
1373}
1374
1375// ----------------------------------------------------------------------------
1376// RecordingDeviceName
1377// ----------------------------------------------------------------------------
1378
pbos@webrtc.org25509882013-04-09 10:30:35 +00001379int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1380 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001381 char name[kAdmMaxDeviceNameSize],
1382 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001383{
niklase@google.com470e71d2011-07-07 08:21:25 +00001384 CHECK_INITIALIZED();
1385
1386 if (name == NULL)
1387 {
1388 _lastError = kAdmErrArgument;
1389 return -1;
1390 }
1391
1392 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1393 {
1394 return -1;
1395 }
1396
1397 if (name != NULL)
1398 {
1399 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1400 }
1401 if (guid != NULL)
1402 {
1403 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1404 }
1405
1406 return (0);
1407}
1408
1409// ----------------------------------------------------------------------------
1410// RecordingDevices
1411// ----------------------------------------------------------------------------
1412
pbos@webrtc.org25509882013-04-09 10:30:35 +00001413int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001414{
niklase@google.com470e71d2011-07-07 08:21:25 +00001415 CHECK_INITIALIZED();
1416
pbos@webrtc.org25509882013-04-09 10:30:35 +00001417 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001418
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001419 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1420 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001421 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001422}
1423
1424// ----------------------------------------------------------------------------
1425// SetRecordingDevice I (II)
1426// ----------------------------------------------------------------------------
1427
pbos@webrtc.org25509882013-04-09 10:30:35 +00001428int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001429{
niklase@google.com470e71d2011-07-07 08:21:25 +00001430 CHECK_INITIALIZED();
1431 return (_ptrAudioDevice->SetRecordingDevice(index));
1432}
1433
1434// ----------------------------------------------------------------------------
1435// SetRecordingDevice II (II)
1436// ----------------------------------------------------------------------------
1437
pbos@webrtc.org25509882013-04-09 10:30:35 +00001438int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001439{
1440 if (device == kDefaultDevice)
1441 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001442 }
1443 else
1444 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001445 }
1446 CHECK_INITIALIZED();
1447
1448 return (_ptrAudioDevice->SetRecordingDevice(device));
1449}
1450
1451// ----------------------------------------------------------------------------
1452// InitPlayout
1453// ----------------------------------------------------------------------------
1454
pbos@webrtc.org25509882013-04-09 10:30:35 +00001455int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001456{
niklase@google.com470e71d2011-07-07 08:21:25 +00001457 CHECK_INITIALIZED();
1458 _audioDeviceBuffer.InitPlayout();
1459 return (_ptrAudioDevice->InitPlayout());
1460}
1461
1462// ----------------------------------------------------------------------------
1463// InitRecording
1464// ----------------------------------------------------------------------------
1465
pbos@webrtc.org25509882013-04-09 10:30:35 +00001466int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001467{
niklase@google.com470e71d2011-07-07 08:21:25 +00001468 CHECK_INITIALIZED();
1469 _audioDeviceBuffer.InitRecording();
1470 return (_ptrAudioDevice->InitRecording());
1471}
1472
1473// ----------------------------------------------------------------------------
1474// PlayoutIsInitialized
1475// ----------------------------------------------------------------------------
1476
1477bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1478{
niklase@google.com470e71d2011-07-07 08:21:25 +00001479 CHECK_INITIALIZED_BOOL();
1480 return (_ptrAudioDevice->PlayoutIsInitialized());
1481}
1482
1483// ----------------------------------------------------------------------------
1484// RecordingIsInitialized
1485// ----------------------------------------------------------------------------
1486
1487bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1488{
niklase@google.com470e71d2011-07-07 08:21:25 +00001489 CHECK_INITIALIZED_BOOL();
1490 return (_ptrAudioDevice->RecordingIsInitialized());
1491}
1492
1493// ----------------------------------------------------------------------------
1494// StartPlayout
1495// ----------------------------------------------------------------------------
1496
pbos@webrtc.org25509882013-04-09 10:30:35 +00001497int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001498{
niklase@google.com470e71d2011-07-07 08:21:25 +00001499 CHECK_INITIALIZED();
1500 return (_ptrAudioDevice->StartPlayout());
1501}
1502
1503// ----------------------------------------------------------------------------
1504// StopPlayout
1505// ----------------------------------------------------------------------------
1506
pbos@webrtc.org25509882013-04-09 10:30:35 +00001507int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001508{
niklase@google.com470e71d2011-07-07 08:21:25 +00001509 CHECK_INITIALIZED();
1510 return (_ptrAudioDevice->StopPlayout());
1511}
1512
1513// ----------------------------------------------------------------------------
1514// Playing
1515// ----------------------------------------------------------------------------
1516
1517bool AudioDeviceModuleImpl::Playing() const
1518{
niklase@google.com470e71d2011-07-07 08:21:25 +00001519 CHECK_INITIALIZED_BOOL();
1520 return (_ptrAudioDevice->Playing());
1521}
1522
1523// ----------------------------------------------------------------------------
1524// StartRecording
1525// ----------------------------------------------------------------------------
1526
pbos@webrtc.org25509882013-04-09 10:30:35 +00001527int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001528{
niklase@google.com470e71d2011-07-07 08:21:25 +00001529 CHECK_INITIALIZED();
1530 return (_ptrAudioDevice->StartRecording());
1531}
1532// ----------------------------------------------------------------------------
1533// StopRecording
1534// ----------------------------------------------------------------------------
1535
pbos@webrtc.org25509882013-04-09 10:30:35 +00001536int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001537{
niklase@google.com470e71d2011-07-07 08:21:25 +00001538 CHECK_INITIALIZED();
1539 return (_ptrAudioDevice->StopRecording());
1540}
1541
1542// ----------------------------------------------------------------------------
1543// Recording
1544// ----------------------------------------------------------------------------
1545
1546bool AudioDeviceModuleImpl::Recording() const
1547{
niklase@google.com470e71d2011-07-07 08:21:25 +00001548 CHECK_INITIALIZED_BOOL();
1549 return (_ptrAudioDevice->Recording());
1550}
1551
1552// ----------------------------------------------------------------------------
1553// RegisterEventObserver
1554// ----------------------------------------------------------------------------
1555
pbos@webrtc.org25509882013-04-09 10:30:35 +00001556int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001557{
niklase@google.com470e71d2011-07-07 08:21:25 +00001558
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001559 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001560 _ptrCbAudioDeviceObserver = eventCallback;
1561
1562 return 0;
1563}
1564
1565// ----------------------------------------------------------------------------
1566// RegisterAudioCallback
1567// ----------------------------------------------------------------------------
1568
pbos@webrtc.org25509882013-04-09 10:30:35 +00001569int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001570{
niklase@google.com470e71d2011-07-07 08:21:25 +00001571
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001572 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001573 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1574
1575 return 0;
1576}
1577
1578// ----------------------------------------------------------------------------
1579// StartRawInputFileRecording
1580// ----------------------------------------------------------------------------
1581
pbos@webrtc.org25509882013-04-09 10:30:35 +00001582int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001583 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001584{
niklase@google.com470e71d2011-07-07 08:21:25 +00001585 CHECK_INITIALIZED();
1586
1587 if (NULL == pcmFileNameUTF8)
1588 {
1589 return -1;
1590 }
1591
1592 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1593}
1594
1595// ----------------------------------------------------------------------------
1596// StopRawInputFileRecording
1597// ----------------------------------------------------------------------------
1598
pbos@webrtc.org25509882013-04-09 10:30:35 +00001599int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001600{
niklase@google.com470e71d2011-07-07 08:21:25 +00001601 CHECK_INITIALIZED();
1602
1603 return (_audioDeviceBuffer.StopInputFileRecording());
1604}
1605
1606// ----------------------------------------------------------------------------
1607// StartRawOutputFileRecording
1608// ----------------------------------------------------------------------------
1609
pbos@webrtc.org25509882013-04-09 10:30:35 +00001610int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001611 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001612{
niklase@google.com470e71d2011-07-07 08:21:25 +00001613 CHECK_INITIALIZED();
1614
1615 if (NULL == pcmFileNameUTF8)
1616 {
1617 return -1;
1618 }
1619
1620 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1621}
1622
1623// ----------------------------------------------------------------------------
1624// StopRawOutputFileRecording
1625// ----------------------------------------------------------------------------
1626
pbos@webrtc.org25509882013-04-09 10:30:35 +00001627int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001628{
niklase@google.com470e71d2011-07-07 08:21:25 +00001629 CHECK_INITIALIZED();
1630
1631 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001632}
1633
1634// ----------------------------------------------------------------------------
1635// SetPlayoutBuffer
1636// ----------------------------------------------------------------------------
1637
pbos@webrtc.org25509882013-04-09 10:30:35 +00001638int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001639{
niklase@google.com470e71d2011-07-07 08:21:25 +00001640 CHECK_INITIALIZED();
1641
1642 if (_ptrAudioDevice->PlayoutIsInitialized())
1643 {
1644 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1645 return -1;
1646 }
1647
pbos@webrtc.org25509882013-04-09 10:30:35 +00001648 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001649
1650 if (kFixedBufferSize == type)
1651 {
1652 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1653 {
1654 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1655 return -1;
1656 }
1657 }
1658
1659 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1660 {
1661 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1662 }
1663
1664 return ret;
1665}
1666
1667// ----------------------------------------------------------------------------
1668// PlayoutBuffer
1669// ----------------------------------------------------------------------------
1670
pbos@webrtc.org25509882013-04-09 10:30:35 +00001671int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001672{
niklase@google.com470e71d2011-07-07 08:21:25 +00001673 CHECK_INITIALIZED();
1674
1675 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001676 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001677
1678 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1679 {
1680 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1681 return -1;
1682 }
1683
1684 *type = bufType;
1685 *sizeMS = size;
1686
1687 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1688 return (0);
1689}
1690
1691// ----------------------------------------------------------------------------
1692// PlayoutDelay
1693// ----------------------------------------------------------------------------
1694
pbos@webrtc.org25509882013-04-09 10:30:35 +00001695int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001696{
1697 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1698 CHECK_INITIALIZED();
1699
pbos@webrtc.org25509882013-04-09 10:30:35 +00001700 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001701
1702 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1703 {
1704 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1705 return -1;
1706 }
1707
1708 *delayMS = delay;
1709
1710 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1711 return (0);
1712}
1713
1714// ----------------------------------------------------------------------------
1715// RecordingDelay
1716// ----------------------------------------------------------------------------
1717
pbos@webrtc.org25509882013-04-09 10:30:35 +00001718int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001719{
1720 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1721 CHECK_INITIALIZED();
1722
pbos@webrtc.org25509882013-04-09 10:30:35 +00001723 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001724
1725 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1726 {
1727 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1728 return -1;
1729 }
1730
1731 *delayMS = delay;
1732
1733 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1734 return (0);
1735}
1736
1737// ----------------------------------------------------------------------------
1738// CPULoad
1739// ----------------------------------------------------------------------------
1740
pbos@webrtc.org25509882013-04-09 10:30:35 +00001741int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001742{
niklase@google.com470e71d2011-07-07 08:21:25 +00001743 CHECK_INITIALIZED();
1744
pbos@webrtc.org25509882013-04-09 10:30:35 +00001745 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001746
1747 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1748 {
1749 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1750 return -1;
1751 }
1752
1753 *load = cpuLoad;
1754
1755 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1756 return (0);
1757}
1758
1759// ----------------------------------------------------------------------------
1760// SetRecordingSampleRate
1761// ----------------------------------------------------------------------------
1762
pbos@webrtc.org25509882013-04-09 10:30:35 +00001763int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001764{
niklase@google.com470e71d2011-07-07 08:21:25 +00001765 CHECK_INITIALIZED();
1766
1767 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1768 {
1769 return -1;
1770 }
1771
1772 return (0);
1773}
1774
1775// ----------------------------------------------------------------------------
1776// RecordingSampleRate
1777// ----------------------------------------------------------------------------
1778
pbos@webrtc.org25509882013-04-09 10:30:35 +00001779int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001780{
niklase@google.com470e71d2011-07-07 08:21:25 +00001781 CHECK_INITIALIZED();
1782
pbos@webrtc.org25509882013-04-09 10:30:35 +00001783 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001784
1785 if (sampleRate == -1)
1786 {
1787 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1788 return -1;
1789 }
1790
1791 *samplesPerSec = sampleRate;
1792
1793 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1794 return (0);
1795}
1796
1797// ----------------------------------------------------------------------------
1798// SetPlayoutSampleRate
1799// ----------------------------------------------------------------------------
1800
pbos@webrtc.org25509882013-04-09 10:30:35 +00001801int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001802{
niklase@google.com470e71d2011-07-07 08:21:25 +00001803 CHECK_INITIALIZED();
1804
1805 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1806 {
1807 return -1;
1808 }
1809
1810 return (0);
1811}
1812
1813// ----------------------------------------------------------------------------
1814// PlayoutSampleRate
1815// ----------------------------------------------------------------------------
1816
pbos@webrtc.org25509882013-04-09 10:30:35 +00001817int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001818{
niklase@google.com470e71d2011-07-07 08:21:25 +00001819 CHECK_INITIALIZED();
1820
pbos@webrtc.org25509882013-04-09 10:30:35 +00001821 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001822
1823 if (sampleRate == -1)
1824 {
1825 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1826 return -1;
1827 }
1828
1829 *samplesPerSec = sampleRate;
1830
1831 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1832 return (0);
1833}
1834
1835// ----------------------------------------------------------------------------
1836// ResetAudioDevice
1837// ----------------------------------------------------------------------------
1838
pbos@webrtc.org25509882013-04-09 10:30:35 +00001839int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001840{
niklase@google.com470e71d2011-07-07 08:21:25 +00001841 CHECK_INITIALIZED();
1842
1843
1844 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1845 {
1846 return -1;
1847 }
1848
1849 return (0);
1850}
1851
1852// ----------------------------------------------------------------------------
1853// SetLoudspeakerStatus
1854// ----------------------------------------------------------------------------
1855
pbos@webrtc.org25509882013-04-09 10:30:35 +00001856int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001857{
niklase@google.com470e71d2011-07-07 08:21:25 +00001858 CHECK_INITIALIZED();
1859
1860 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1861 {
1862 return -1;
1863 }
1864
1865 return 0;
1866}
1867
1868// ----------------------------------------------------------------------------
1869// GetLoudspeakerStatus
1870// ----------------------------------------------------------------------------
1871
henrikac14f5ff2015-09-23 14:08:33 +02001872int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001873 CHECK_INITIALIZED();
henrikac14f5ff2015-09-23 14:08:33 +02001874 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
1875 return -1;
1876 }
1877 return 0;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001878}
1879
henrikac14f5ff2015-09-23 14:08:33 +02001880bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
1881 CHECK_INITIALIZED_BOOL();
1882 return _ptrAudioDevice->BuiltInAECIsEnabled();
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001883}
1884
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001885bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1886 CHECK_INITIALIZED_BOOL();
1887 return _ptrAudioDevice->BuiltInAECIsAvailable();
1888}
1889
henrikac14f5ff2015-09-23 14:08:33 +02001890int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
1891 CHECK_INITIALIZED();
1892 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1893}
1894
1895bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
1896 CHECK_INITIALIZED_BOOL();
1897 return _ptrAudioDevice->BuiltInAGCIsAvailable();
1898}
1899
1900int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
1901 CHECK_INITIALIZED();
1902 return _ptrAudioDevice->EnableBuiltInAGC(enable);
1903}
1904
1905bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
1906 CHECK_INITIALIZED_BOOL();
1907 return _ptrAudioDevice->BuiltInNSIsAvailable();
1908}
1909
1910int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
1911 CHECK_INITIALIZED();
1912 return _ptrAudioDevice->EnableBuiltInNS(enable);
1913}
1914
henrikaba35d052015-07-14 17:04:08 +02001915int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1916 AudioParameters* params) const {
1917 return _ptrAudioDevice->GetPlayoutAudioParameters(params);
1918}
1919
1920int AudioDeviceModuleImpl::GetRecordAudioParameters(
1921 AudioParameters* params) const {
1922 return _ptrAudioDevice->GetRecordAudioParameters(params);
1923}
1924
niklase@google.com470e71d2011-07-07 08:21:25 +00001925// ============================================================================
1926// Private Methods
1927// ============================================================================
1928
1929// ----------------------------------------------------------------------------
1930// Platform
1931// ----------------------------------------------------------------------------
1932
1933AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1934{
1935 return _platformType;
1936}
1937
1938// ----------------------------------------------------------------------------
1939// PlatformAudioLayer
1940// ----------------------------------------------------------------------------
1941
1942AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
1943{
niklase@google.com470e71d2011-07-07 08:21:25 +00001944 return _platformAudioLayer;
1945}
1946
1947} // namespace webrtc