blob: 6496f5efc43d800ee0f4da37e2c909a05000e9ab [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
Peter Boströmf14c47a2016-02-24 16:51:18 +0100430void 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 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000482}
483
484// ============================================================================
485// Public API
486// ============================================================================
487
488// ----------------------------------------------------------------------------
489// ActiveAudioLayer
490// ----------------------------------------------------------------------------
491
henrikab2619892015-05-18 16:49:16 +0200492int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
493 AudioLayer activeAudio;
494 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
495 return -1;
496 }
497 *audioLayer = activeAudio;
498 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000499}
500
501// ----------------------------------------------------------------------------
502// LastError
503// ----------------------------------------------------------------------------
504
505AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
506{
507 return _lastError;
508}
509
510// ----------------------------------------------------------------------------
511// Init
512// ----------------------------------------------------------------------------
513
pbos@webrtc.org25509882013-04-09 10:30:35 +0000514int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000515{
niklase@google.com470e71d2011-07-07 08:21:25 +0000516
517 if (_initialized)
518 return 0;
519
niklase@google.com470e71d2011-07-07 08:21:25 +0000520 if (!_ptrAudioDevice)
521 return -1;
522
niklase@google.com470e71d2011-07-07 08:21:25 +0000523 if (_ptrAudioDevice->Init() == -1)
524 {
525 return -1;
526 }
527
528 _initialized = true;
529 return 0;
530}
531
532// ----------------------------------------------------------------------------
533// Terminate
534// ----------------------------------------------------------------------------
535
pbos@webrtc.org25509882013-04-09 10:30:35 +0000536int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000537{
niklase@google.com470e71d2011-07-07 08:21:25 +0000538
539 if (!_initialized)
540 return 0;
541
542 if (_ptrAudioDevice->Terminate() == -1)
543 {
544 return -1;
545 }
546
547 _initialized = false;
548 return 0;
549}
550
551// ----------------------------------------------------------------------------
552// Initialized
553// ----------------------------------------------------------------------------
554
555bool AudioDeviceModuleImpl::Initialized() const
556{
niklase@google.com470e71d2011-07-07 08:21:25 +0000557
558 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
559 return (_initialized);
560}
561
562// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000563// InitSpeaker
564// ----------------------------------------------------------------------------
565
pbos@webrtc.org25509882013-04-09 10:30:35 +0000566int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000567{
niklase@google.com470e71d2011-07-07 08:21:25 +0000568 CHECK_INITIALIZED();
569 return (_ptrAudioDevice->InitSpeaker());
570}
571
572// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000573// InitMicrophone
574// ----------------------------------------------------------------------------
575
pbos@webrtc.org25509882013-04-09 10:30:35 +0000576int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000577{
niklase@google.com470e71d2011-07-07 08:21:25 +0000578 CHECK_INITIALIZED();
579 return (_ptrAudioDevice->InitMicrophone());
580}
581
582// ----------------------------------------------------------------------------
583// SpeakerVolumeIsAvailable
584// ----------------------------------------------------------------------------
585
pbos@webrtc.org25509882013-04-09 10:30:35 +0000586int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000587{
niklase@google.com470e71d2011-07-07 08:21:25 +0000588 CHECK_INITIALIZED();
589
590 bool isAvailable(0);
591
592 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
593 {
594 return -1;
595 }
596
597 *available = isAvailable;
598
599 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
600 return (0);
601}
602
603// ----------------------------------------------------------------------------
604// SetSpeakerVolume
605// ----------------------------------------------------------------------------
606
pbos@webrtc.org25509882013-04-09 10:30:35 +0000607int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000608{
niklase@google.com470e71d2011-07-07 08:21:25 +0000609 CHECK_INITIALIZED();
610 return (_ptrAudioDevice->SetSpeakerVolume(volume));
611}
612
613// ----------------------------------------------------------------------------
614// SpeakerVolume
615// ----------------------------------------------------------------------------
616
pbos@webrtc.org25509882013-04-09 10:30:35 +0000617int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000618{
niklase@google.com470e71d2011-07-07 08:21:25 +0000619 CHECK_INITIALIZED();
620
pbos@webrtc.org25509882013-04-09 10:30:35 +0000621 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000622
623 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
624 {
625 return -1;
626 }
627
628 *volume = level;
629
630 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
631 return (0);
632}
633
634// ----------------------------------------------------------------------------
635// SetWaveOutVolume
636// ----------------------------------------------------------------------------
637
pbos@webrtc.org25509882013-04-09 10:30:35 +0000638int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000639{
niklase@google.com470e71d2011-07-07 08:21:25 +0000640 CHECK_INITIALIZED();
641 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
642}
643
644// ----------------------------------------------------------------------------
645// WaveOutVolume
646// ----------------------------------------------------------------------------
647
pbos@webrtc.org25509882013-04-09 10:30:35 +0000648int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000649{
niklase@google.com470e71d2011-07-07 08:21:25 +0000650 CHECK_INITIALIZED();
651
pbos@webrtc.org25509882013-04-09 10:30:35 +0000652 uint16_t volLeft(0);
653 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000654
655 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
656 {
657 return -1;
658 }
659
660 *volumeLeft = volLeft;
661 *volumeRight = volRight;
662
663 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
664 *volumeLeft, *volumeRight);
665
666 return (0);
667}
668
669// ----------------------------------------------------------------------------
670// SpeakerIsInitialized
671// ----------------------------------------------------------------------------
672
673bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
674{
niklase@google.com470e71d2011-07-07 08:21:25 +0000675 CHECK_INITIALIZED_BOOL();
676
677 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
678
679 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
680 return (isInitialized);
681}
682
683// ----------------------------------------------------------------------------
684// MicrophoneIsInitialized
685// ----------------------------------------------------------------------------
686
687bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
688{
niklase@google.com470e71d2011-07-07 08:21:25 +0000689 CHECK_INITIALIZED_BOOL();
690
691 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
692
693 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
694 return (isInitialized);
695}
696
697// ----------------------------------------------------------------------------
698// MaxSpeakerVolume
699// ----------------------------------------------------------------------------
700
pbos@webrtc.org25509882013-04-09 10:30:35 +0000701int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000702{
niklase@google.com470e71d2011-07-07 08:21:25 +0000703 CHECK_INITIALIZED();
704
pbos@webrtc.org25509882013-04-09 10:30:35 +0000705 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000706
707 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
708 {
709 return -1;
710 }
711
712 *maxVolume = maxVol;
713
714 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
715 return (0);
716}
717
718// ----------------------------------------------------------------------------
719// MinSpeakerVolume
720// ----------------------------------------------------------------------------
721
pbos@webrtc.org25509882013-04-09 10:30:35 +0000722int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000723{
niklase@google.com470e71d2011-07-07 08:21:25 +0000724 CHECK_INITIALIZED();
725
pbos@webrtc.org25509882013-04-09 10:30:35 +0000726 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000727
728 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
729 {
730 return -1;
731 }
732
733 *minVolume = minVol;
734
735 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
736 return (0);
737}
738
739// ----------------------------------------------------------------------------
740// SpeakerVolumeStepSize
741// ----------------------------------------------------------------------------
742
pbos@webrtc.org25509882013-04-09 10:30:35 +0000743int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000744{
niklase@google.com470e71d2011-07-07 08:21:25 +0000745 CHECK_INITIALIZED();
746
pbos@webrtc.org25509882013-04-09 10:30:35 +0000747 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000748
749 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
750 {
751 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
752 return -1;
753 }
754
755 *stepSize = delta;
756
757 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
758 return (0);
759}
760
761// ----------------------------------------------------------------------------
762// SpeakerMuteIsAvailable
763// ----------------------------------------------------------------------------
764
pbos@webrtc.org25509882013-04-09 10:30:35 +0000765int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000766{
niklase@google.com470e71d2011-07-07 08:21:25 +0000767 CHECK_INITIALIZED();
768
769 bool isAvailable(0);
770
771 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
772 {
773 return -1;
774 }
775
776 *available = isAvailable;
777
778 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
779 return (0);
780}
781
782// ----------------------------------------------------------------------------
783// SetSpeakerMute
784// ----------------------------------------------------------------------------
785
pbos@webrtc.org25509882013-04-09 10:30:35 +0000786int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000787{
niklase@google.com470e71d2011-07-07 08:21:25 +0000788 CHECK_INITIALIZED();
789 return (_ptrAudioDevice->SetSpeakerMute(enable));
790}
791
792// ----------------------------------------------------------------------------
793// SpeakerMute
794// ----------------------------------------------------------------------------
795
pbos@webrtc.org25509882013-04-09 10:30:35 +0000796int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000797{
niklase@google.com470e71d2011-07-07 08:21:25 +0000798 CHECK_INITIALIZED();
799
800 bool muted(false);
801
802 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
803 {
804 return -1;
805 }
806
807 *enabled = muted;
808
809 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
810 return (0);
811}
812
813// ----------------------------------------------------------------------------
814// MicrophoneMuteIsAvailable
815// ----------------------------------------------------------------------------
816
pbos@webrtc.org25509882013-04-09 10:30:35 +0000817int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000818{
niklase@google.com470e71d2011-07-07 08:21:25 +0000819 CHECK_INITIALIZED();
820
821 bool isAvailable(0);
822
823 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
824 {
825 return -1;
826 }
827
828 *available = isAvailable;
829
830 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
831 return (0);
832}
833
834// ----------------------------------------------------------------------------
835// SetMicrophoneMute
836// ----------------------------------------------------------------------------
837
pbos@webrtc.org25509882013-04-09 10:30:35 +0000838int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000839{
niklase@google.com470e71d2011-07-07 08:21:25 +0000840 CHECK_INITIALIZED();
841 return (_ptrAudioDevice->SetMicrophoneMute(enable));
842}
843
844// ----------------------------------------------------------------------------
845// MicrophoneMute
846// ----------------------------------------------------------------------------
847
pbos@webrtc.org25509882013-04-09 10:30:35 +0000848int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000849{
niklase@google.com470e71d2011-07-07 08:21:25 +0000850 CHECK_INITIALIZED();
851
852 bool muted(false);
853
854 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
855 {
856 return -1;
857 }
858
859 *enabled = muted;
860
861 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
862 return (0);
863}
864
865// ----------------------------------------------------------------------------
866// MicrophoneBoostIsAvailable
867// ----------------------------------------------------------------------------
868
pbos@webrtc.org25509882013-04-09 10:30:35 +0000869int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000870{
niklase@google.com470e71d2011-07-07 08:21:25 +0000871 CHECK_INITIALIZED();
872
873 bool isAvailable(0);
874
875 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
876 {
877 return -1;
878 }
879
880 *available = isAvailable;
881
882 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
883 return (0);
884}
885
886// ----------------------------------------------------------------------------
887// SetMicrophoneBoost
888// ----------------------------------------------------------------------------
889
pbos@webrtc.org25509882013-04-09 10:30:35 +0000890int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000891{
niklase@google.com470e71d2011-07-07 08:21:25 +0000892 CHECK_INITIALIZED();
893 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
894}
895
896// ----------------------------------------------------------------------------
897// MicrophoneBoost
898// ----------------------------------------------------------------------------
899
pbos@webrtc.org25509882013-04-09 10:30:35 +0000900int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000901{
niklase@google.com470e71d2011-07-07 08:21:25 +0000902 CHECK_INITIALIZED();
903
904 bool onOff(false);
905
906 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
907 {
908 return -1;
909 }
910
911 *enabled = onOff;
912
913 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
914 return (0);
915}
916
917// ----------------------------------------------------------------------------
918// MicrophoneVolumeIsAvailable
919// ----------------------------------------------------------------------------
920
pbos@webrtc.org25509882013-04-09 10:30:35 +0000921int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000922{
niklase@google.com470e71d2011-07-07 08:21:25 +0000923 CHECK_INITIALIZED();
924
925 bool isAvailable(0);
926
927 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
928 {
929 return -1;
930 }
931
932 *available = isAvailable;
933
934 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
935 return (0);
936}
937
938// ----------------------------------------------------------------------------
939// SetMicrophoneVolume
940// ----------------------------------------------------------------------------
941
pbos@webrtc.org25509882013-04-09 10:30:35 +0000942int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000943{
niklase@google.com470e71d2011-07-07 08:21:25 +0000944 CHECK_INITIALIZED();
945 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
946}
947
948// ----------------------------------------------------------------------------
949// MicrophoneVolume
950// ----------------------------------------------------------------------------
951
pbos@webrtc.org25509882013-04-09 10:30:35 +0000952int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000953{
954 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
955 CHECK_INITIALIZED();
956
pbos@webrtc.org25509882013-04-09 10:30:35 +0000957 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000958
959 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
960 {
961 return -1;
962 }
963
964 *volume = level;
965
966 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
967 return (0);
968}
969
970// ----------------------------------------------------------------------------
971// StereoRecordingIsAvailable
972// ----------------------------------------------------------------------------
973
pbos@webrtc.org25509882013-04-09 10:30:35 +0000974int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000975{
niklase@google.com470e71d2011-07-07 08:21:25 +0000976 CHECK_INITIALIZED();
977
978 bool isAvailable(0);
979
980 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
981 {
982 return -1;
983 }
984
985 *available = isAvailable;
986
987 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
988 return (0);
989}
990
991// ----------------------------------------------------------------------------
992// SetStereoRecording
993// ----------------------------------------------------------------------------
994
pbos@webrtc.org25509882013-04-09 10:30:35 +0000995int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000996{
niklase@google.com470e71d2011-07-07 08:21:25 +0000997 CHECK_INITIALIZED();
998
999 if (_ptrAudioDevice->RecordingIsInitialized())
1000 {
1001 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1002 return -1;
1003 }
1004
1005 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1006 {
1007 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1008 return -1;
1009 }
1010
pbos@webrtc.org25509882013-04-09 10:30:35 +00001011 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001012 if (enable)
1013 {
1014 nChannels = 2;
1015 }
1016 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1017
1018 return 0;
1019}
1020
1021// ----------------------------------------------------------------------------
1022// StereoRecording
1023// ----------------------------------------------------------------------------
1024
pbos@webrtc.org25509882013-04-09 10:30:35 +00001025int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001026{
niklase@google.com470e71d2011-07-07 08:21:25 +00001027 CHECK_INITIALIZED();
1028
1029 bool stereo(false);
1030
1031 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1032 {
1033 return -1;
1034 }
1035
1036 *enabled = stereo;
1037
1038 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1039 return (0);
1040}
1041
1042// ----------------------------------------------------------------------------
1043// SetRecordingChannel
1044// ----------------------------------------------------------------------------
1045
pbos@webrtc.org25509882013-04-09 10:30:35 +00001046int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001047{
1048 if (channel == kChannelBoth)
1049 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001050 }
1051 else if (channel == kChannelLeft)
1052 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001053 }
1054 else
1055 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001056 }
1057 CHECK_INITIALIZED();
1058
1059 bool stereo(false);
1060
1061 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1062 {
1063 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1064 return -1;
1065 }
1066
1067 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1068}
1069
1070// ----------------------------------------------------------------------------
1071// RecordingChannel
1072// ----------------------------------------------------------------------------
1073
pbos@webrtc.org25509882013-04-09 10:30:35 +00001074int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001075{
niklase@google.com470e71d2011-07-07 08:21:25 +00001076 CHECK_INITIALIZED();
1077
1078 ChannelType chType;
1079
1080 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1081 {
1082 return -1;
1083 }
1084
1085 *channel = chType;
1086
1087 if (*channel == kChannelBoth)
1088 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001089 }
1090 else if (*channel == kChannelLeft)
1091 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001092 }
1093 else
1094 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001095 }
1096
1097 return (0);
1098}
1099
1100// ----------------------------------------------------------------------------
1101// StereoPlayoutIsAvailable
1102// ----------------------------------------------------------------------------
1103
pbos@webrtc.org25509882013-04-09 10:30:35 +00001104int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001105{
niklase@google.com470e71d2011-07-07 08:21:25 +00001106 CHECK_INITIALIZED();
1107
1108 bool isAvailable(0);
1109
1110 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1111 {
1112 return -1;
1113 }
1114
1115 *available = isAvailable;
1116
1117 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1118 return (0);
1119}
1120
1121// ----------------------------------------------------------------------------
1122// SetStereoPlayout
1123// ----------------------------------------------------------------------------
1124
pbos@webrtc.org25509882013-04-09 10:30:35 +00001125int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001126{
niklase@google.com470e71d2011-07-07 08:21:25 +00001127 CHECK_INITIALIZED();
1128
1129 if (_ptrAudioDevice->PlayoutIsInitialized())
1130 {
1131 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1132 return -1;
1133 }
1134
1135 if (_ptrAudioDevice->SetStereoPlayout(enable))
1136 {
1137 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1138 return -1;
1139 }
1140
pbos@webrtc.org25509882013-04-09 10:30:35 +00001141 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001142 if (enable)
1143 {
1144 nChannels = 2;
1145 }
1146 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1147
1148 return 0;
1149}
1150
1151// ----------------------------------------------------------------------------
1152// StereoPlayout
1153// ----------------------------------------------------------------------------
1154
pbos@webrtc.org25509882013-04-09 10:30:35 +00001155int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001156{
niklase@google.com470e71d2011-07-07 08:21:25 +00001157 CHECK_INITIALIZED();
1158
1159 bool stereo(false);
1160
1161 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1162 {
1163 return -1;
1164 }
1165
1166 *enabled = stereo;
1167
1168 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1169 return (0);
1170}
1171
1172// ----------------------------------------------------------------------------
1173// SetAGC
1174// ----------------------------------------------------------------------------
1175
pbos@webrtc.org25509882013-04-09 10:30:35 +00001176int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001177{
niklase@google.com470e71d2011-07-07 08:21:25 +00001178 CHECK_INITIALIZED();
1179 return (_ptrAudioDevice->SetAGC(enable));
1180}
1181
1182// ----------------------------------------------------------------------------
1183// AGC
1184// ----------------------------------------------------------------------------
1185
1186bool AudioDeviceModuleImpl::AGC() const
1187{
niklase@google.com470e71d2011-07-07 08:21:25 +00001188 CHECK_INITIALIZED_BOOL();
1189 return (_ptrAudioDevice->AGC());
1190}
1191
1192// ----------------------------------------------------------------------------
1193// PlayoutIsAvailable
1194// ----------------------------------------------------------------------------
1195
pbos@webrtc.org25509882013-04-09 10:30:35 +00001196int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001197{
niklase@google.com470e71d2011-07-07 08:21:25 +00001198 CHECK_INITIALIZED();
1199
1200 bool isAvailable(0);
1201
1202 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1203 {
1204 return -1;
1205 }
1206
1207 *available = isAvailable;
1208
1209 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1210 return (0);
1211}
1212
1213// ----------------------------------------------------------------------------
1214// RecordingIsAvailable
1215// ----------------------------------------------------------------------------
1216
pbos@webrtc.org25509882013-04-09 10:30:35 +00001217int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001218{
niklase@google.com470e71d2011-07-07 08:21:25 +00001219 CHECK_INITIALIZED();
1220
1221 bool isAvailable(0);
1222
1223 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1224 {
1225 return -1;
1226 }
1227
1228 *available = isAvailable;
1229
1230 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1231 return (0);
1232}
1233
1234// ----------------------------------------------------------------------------
1235// MaxMicrophoneVolume
1236// ----------------------------------------------------------------------------
1237
pbos@webrtc.org25509882013-04-09 10:30:35 +00001238int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001239{
1240 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1241 CHECK_INITIALIZED();
1242
pbos@webrtc.org25509882013-04-09 10:30:35 +00001243 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001244
1245 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1246 {
1247 return -1;
1248 }
1249
1250 *maxVolume = maxVol;
1251
1252 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1253 return (0);
1254}
1255
1256// ----------------------------------------------------------------------------
1257// MinMicrophoneVolume
1258// ----------------------------------------------------------------------------
1259
pbos@webrtc.org25509882013-04-09 10:30:35 +00001260int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001261{
niklase@google.com470e71d2011-07-07 08:21:25 +00001262 CHECK_INITIALIZED();
1263
pbos@webrtc.org25509882013-04-09 10:30:35 +00001264 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001265
1266 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1267 {
1268 return -1;
1269 }
1270
1271 *minVolume = minVol;
1272
1273 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1274 return (0);
1275}
1276
1277// ----------------------------------------------------------------------------
1278// MicrophoneVolumeStepSize
1279// ----------------------------------------------------------------------------
1280
pbos@webrtc.org25509882013-04-09 10:30:35 +00001281int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001282{
niklase@google.com470e71d2011-07-07 08:21:25 +00001283 CHECK_INITIALIZED();
1284
pbos@webrtc.org25509882013-04-09 10:30:35 +00001285 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001286
1287 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1288 {
1289 return -1;
1290 }
1291
1292 *stepSize = delta;
1293
1294 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1295 return (0);
1296}
1297
1298// ----------------------------------------------------------------------------
1299// PlayoutDevices
1300// ----------------------------------------------------------------------------
1301
pbos@webrtc.org25509882013-04-09 10:30:35 +00001302int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001303{
niklase@google.com470e71d2011-07-07 08:21:25 +00001304 CHECK_INITIALIZED();
1305
pbos@webrtc.org25509882013-04-09 10:30:35 +00001306 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001307
1308 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001309 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001310}
1311
1312// ----------------------------------------------------------------------------
1313// SetPlayoutDevice I (II)
1314// ----------------------------------------------------------------------------
1315
pbos@webrtc.org25509882013-04-09 10:30:35 +00001316int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001317{
niklase@google.com470e71d2011-07-07 08:21:25 +00001318 CHECK_INITIALIZED();
1319 return (_ptrAudioDevice->SetPlayoutDevice(index));
1320}
1321
1322// ----------------------------------------------------------------------------
1323// SetPlayoutDevice II (II)
1324// ----------------------------------------------------------------------------
1325
pbos@webrtc.org25509882013-04-09 10:30:35 +00001326int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001327{
1328 if (device == kDefaultDevice)
1329 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001330 }
1331 else
1332 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001333 }
1334 CHECK_INITIALIZED();
1335
1336 return (_ptrAudioDevice->SetPlayoutDevice(device));
1337}
1338
1339// ----------------------------------------------------------------------------
1340// PlayoutDeviceName
1341// ----------------------------------------------------------------------------
1342
pbos@webrtc.org25509882013-04-09 10:30:35 +00001343int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1344 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001345 char name[kAdmMaxDeviceNameSize],
1346 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001347{
niklase@google.com470e71d2011-07-07 08:21:25 +00001348 CHECK_INITIALIZED();
1349
1350 if (name == NULL)
1351 {
1352 _lastError = kAdmErrArgument;
1353 return -1;
1354 }
1355
1356 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1357 {
1358 return -1;
1359 }
1360
1361 if (name != NULL)
1362 {
1363 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1364 }
1365 if (guid != NULL)
1366 {
1367 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1368 }
1369
1370 return (0);
1371}
1372
1373// ----------------------------------------------------------------------------
1374// RecordingDeviceName
1375// ----------------------------------------------------------------------------
1376
pbos@webrtc.org25509882013-04-09 10:30:35 +00001377int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1378 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001379 char name[kAdmMaxDeviceNameSize],
1380 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001381{
niklase@google.com470e71d2011-07-07 08:21:25 +00001382 CHECK_INITIALIZED();
1383
1384 if (name == NULL)
1385 {
1386 _lastError = kAdmErrArgument;
1387 return -1;
1388 }
1389
1390 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1391 {
1392 return -1;
1393 }
1394
1395 if (name != NULL)
1396 {
1397 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1398 }
1399 if (guid != NULL)
1400 {
1401 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1402 }
1403
1404 return (0);
1405}
1406
1407// ----------------------------------------------------------------------------
1408// RecordingDevices
1409// ----------------------------------------------------------------------------
1410
pbos@webrtc.org25509882013-04-09 10:30:35 +00001411int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001412{
niklase@google.com470e71d2011-07-07 08:21:25 +00001413 CHECK_INITIALIZED();
1414
pbos@webrtc.org25509882013-04-09 10:30:35 +00001415 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001416
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001417 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1418 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001419 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001420}
1421
1422// ----------------------------------------------------------------------------
1423// SetRecordingDevice I (II)
1424// ----------------------------------------------------------------------------
1425
pbos@webrtc.org25509882013-04-09 10:30:35 +00001426int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001427{
niklase@google.com470e71d2011-07-07 08:21:25 +00001428 CHECK_INITIALIZED();
1429 return (_ptrAudioDevice->SetRecordingDevice(index));
1430}
1431
1432// ----------------------------------------------------------------------------
1433// SetRecordingDevice II (II)
1434// ----------------------------------------------------------------------------
1435
pbos@webrtc.org25509882013-04-09 10:30:35 +00001436int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001437{
1438 if (device == kDefaultDevice)
1439 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001440 }
1441 else
1442 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001443 }
1444 CHECK_INITIALIZED();
1445
1446 return (_ptrAudioDevice->SetRecordingDevice(device));
1447}
1448
1449// ----------------------------------------------------------------------------
1450// InitPlayout
1451// ----------------------------------------------------------------------------
1452
pbos@webrtc.org25509882013-04-09 10:30:35 +00001453int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001454{
niklase@google.com470e71d2011-07-07 08:21:25 +00001455 CHECK_INITIALIZED();
1456 _audioDeviceBuffer.InitPlayout();
1457 return (_ptrAudioDevice->InitPlayout());
1458}
1459
1460// ----------------------------------------------------------------------------
1461// InitRecording
1462// ----------------------------------------------------------------------------
1463
pbos@webrtc.org25509882013-04-09 10:30:35 +00001464int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001465{
niklase@google.com470e71d2011-07-07 08:21:25 +00001466 CHECK_INITIALIZED();
1467 _audioDeviceBuffer.InitRecording();
1468 return (_ptrAudioDevice->InitRecording());
1469}
1470
1471// ----------------------------------------------------------------------------
1472// PlayoutIsInitialized
1473// ----------------------------------------------------------------------------
1474
1475bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1476{
niklase@google.com470e71d2011-07-07 08:21:25 +00001477 CHECK_INITIALIZED_BOOL();
1478 return (_ptrAudioDevice->PlayoutIsInitialized());
1479}
1480
1481// ----------------------------------------------------------------------------
1482// RecordingIsInitialized
1483// ----------------------------------------------------------------------------
1484
1485bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1486{
niklase@google.com470e71d2011-07-07 08:21:25 +00001487 CHECK_INITIALIZED_BOOL();
1488 return (_ptrAudioDevice->RecordingIsInitialized());
1489}
1490
1491// ----------------------------------------------------------------------------
1492// StartPlayout
1493// ----------------------------------------------------------------------------
1494
pbos@webrtc.org25509882013-04-09 10:30:35 +00001495int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001496{
niklase@google.com470e71d2011-07-07 08:21:25 +00001497 CHECK_INITIALIZED();
1498 return (_ptrAudioDevice->StartPlayout());
1499}
1500
1501// ----------------------------------------------------------------------------
1502// StopPlayout
1503// ----------------------------------------------------------------------------
1504
pbos@webrtc.org25509882013-04-09 10:30:35 +00001505int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001506{
niklase@google.com470e71d2011-07-07 08:21:25 +00001507 CHECK_INITIALIZED();
1508 return (_ptrAudioDevice->StopPlayout());
1509}
1510
1511// ----------------------------------------------------------------------------
1512// Playing
1513// ----------------------------------------------------------------------------
1514
1515bool AudioDeviceModuleImpl::Playing() const
1516{
niklase@google.com470e71d2011-07-07 08:21:25 +00001517 CHECK_INITIALIZED_BOOL();
1518 return (_ptrAudioDevice->Playing());
1519}
1520
1521// ----------------------------------------------------------------------------
1522// StartRecording
1523// ----------------------------------------------------------------------------
1524
pbos@webrtc.org25509882013-04-09 10:30:35 +00001525int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001526{
niklase@google.com470e71d2011-07-07 08:21:25 +00001527 CHECK_INITIALIZED();
1528 return (_ptrAudioDevice->StartRecording());
1529}
1530// ----------------------------------------------------------------------------
1531// StopRecording
1532// ----------------------------------------------------------------------------
1533
pbos@webrtc.org25509882013-04-09 10:30:35 +00001534int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001535{
niklase@google.com470e71d2011-07-07 08:21:25 +00001536 CHECK_INITIALIZED();
1537 return (_ptrAudioDevice->StopRecording());
1538}
1539
1540// ----------------------------------------------------------------------------
1541// Recording
1542// ----------------------------------------------------------------------------
1543
1544bool AudioDeviceModuleImpl::Recording() const
1545{
niklase@google.com470e71d2011-07-07 08:21:25 +00001546 CHECK_INITIALIZED_BOOL();
1547 return (_ptrAudioDevice->Recording());
1548}
1549
1550// ----------------------------------------------------------------------------
1551// RegisterEventObserver
1552// ----------------------------------------------------------------------------
1553
pbos@webrtc.org25509882013-04-09 10:30:35 +00001554int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001555{
niklase@google.com470e71d2011-07-07 08:21:25 +00001556
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001557 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001558 _ptrCbAudioDeviceObserver = eventCallback;
1559
1560 return 0;
1561}
1562
1563// ----------------------------------------------------------------------------
1564// RegisterAudioCallback
1565// ----------------------------------------------------------------------------
1566
pbos@webrtc.org25509882013-04-09 10:30:35 +00001567int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001568{
niklase@google.com470e71d2011-07-07 08:21:25 +00001569
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001570 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001571 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1572
1573 return 0;
1574}
1575
1576// ----------------------------------------------------------------------------
1577// StartRawInputFileRecording
1578// ----------------------------------------------------------------------------
1579
pbos@webrtc.org25509882013-04-09 10:30:35 +00001580int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001581 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001582{
niklase@google.com470e71d2011-07-07 08:21:25 +00001583 CHECK_INITIALIZED();
1584
1585 if (NULL == pcmFileNameUTF8)
1586 {
1587 return -1;
1588 }
1589
1590 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1591}
1592
1593// ----------------------------------------------------------------------------
1594// StopRawInputFileRecording
1595// ----------------------------------------------------------------------------
1596
pbos@webrtc.org25509882013-04-09 10:30:35 +00001597int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001598{
niklase@google.com470e71d2011-07-07 08:21:25 +00001599 CHECK_INITIALIZED();
1600
1601 return (_audioDeviceBuffer.StopInputFileRecording());
1602}
1603
1604// ----------------------------------------------------------------------------
1605// StartRawOutputFileRecording
1606// ----------------------------------------------------------------------------
1607
pbos@webrtc.org25509882013-04-09 10:30:35 +00001608int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001609 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001610{
niklase@google.com470e71d2011-07-07 08:21:25 +00001611 CHECK_INITIALIZED();
1612
1613 if (NULL == pcmFileNameUTF8)
1614 {
1615 return -1;
1616 }
1617
1618 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1619}
1620
1621// ----------------------------------------------------------------------------
1622// StopRawOutputFileRecording
1623// ----------------------------------------------------------------------------
1624
pbos@webrtc.org25509882013-04-09 10:30:35 +00001625int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001626{
niklase@google.com470e71d2011-07-07 08:21:25 +00001627 CHECK_INITIALIZED();
1628
1629 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001630}
1631
1632// ----------------------------------------------------------------------------
1633// SetPlayoutBuffer
1634// ----------------------------------------------------------------------------
1635
pbos@webrtc.org25509882013-04-09 10:30:35 +00001636int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001637{
niklase@google.com470e71d2011-07-07 08:21:25 +00001638 CHECK_INITIALIZED();
1639
1640 if (_ptrAudioDevice->PlayoutIsInitialized())
1641 {
1642 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1643 return -1;
1644 }
1645
pbos@webrtc.org25509882013-04-09 10:30:35 +00001646 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001647
1648 if (kFixedBufferSize == type)
1649 {
1650 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1651 {
1652 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1653 return -1;
1654 }
1655 }
1656
1657 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1658 {
1659 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1660 }
1661
1662 return ret;
1663}
1664
1665// ----------------------------------------------------------------------------
1666// PlayoutBuffer
1667// ----------------------------------------------------------------------------
1668
pbos@webrtc.org25509882013-04-09 10:30:35 +00001669int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001670{
niklase@google.com470e71d2011-07-07 08:21:25 +00001671 CHECK_INITIALIZED();
1672
1673 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001674 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001675
1676 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1677 {
1678 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1679 return -1;
1680 }
1681
1682 *type = bufType;
1683 *sizeMS = size;
1684
1685 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1686 return (0);
1687}
1688
1689// ----------------------------------------------------------------------------
1690// PlayoutDelay
1691// ----------------------------------------------------------------------------
1692
pbos@webrtc.org25509882013-04-09 10:30:35 +00001693int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001694{
1695 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1696 CHECK_INITIALIZED();
1697
pbos@webrtc.org25509882013-04-09 10:30:35 +00001698 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001699
1700 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1701 {
1702 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1703 return -1;
1704 }
1705
1706 *delayMS = delay;
1707
1708 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1709 return (0);
1710}
1711
1712// ----------------------------------------------------------------------------
1713// RecordingDelay
1714// ----------------------------------------------------------------------------
1715
pbos@webrtc.org25509882013-04-09 10:30:35 +00001716int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001717{
1718 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1719 CHECK_INITIALIZED();
1720
pbos@webrtc.org25509882013-04-09 10:30:35 +00001721 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001722
1723 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1724 {
1725 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1726 return -1;
1727 }
1728
1729 *delayMS = delay;
1730
1731 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1732 return (0);
1733}
1734
1735// ----------------------------------------------------------------------------
1736// CPULoad
1737// ----------------------------------------------------------------------------
1738
pbos@webrtc.org25509882013-04-09 10:30:35 +00001739int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001740{
niklase@google.com470e71d2011-07-07 08:21:25 +00001741 CHECK_INITIALIZED();
1742
pbos@webrtc.org25509882013-04-09 10:30:35 +00001743 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001744
1745 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1746 {
1747 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1748 return -1;
1749 }
1750
1751 *load = cpuLoad;
1752
1753 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1754 return (0);
1755}
1756
1757// ----------------------------------------------------------------------------
1758// SetRecordingSampleRate
1759// ----------------------------------------------------------------------------
1760
pbos@webrtc.org25509882013-04-09 10:30:35 +00001761int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001762{
niklase@google.com470e71d2011-07-07 08:21:25 +00001763 CHECK_INITIALIZED();
1764
1765 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1766 {
1767 return -1;
1768 }
1769
1770 return (0);
1771}
1772
1773// ----------------------------------------------------------------------------
1774// RecordingSampleRate
1775// ----------------------------------------------------------------------------
1776
pbos@webrtc.org25509882013-04-09 10:30:35 +00001777int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001778{
niklase@google.com470e71d2011-07-07 08:21:25 +00001779 CHECK_INITIALIZED();
1780
pbos@webrtc.org25509882013-04-09 10:30:35 +00001781 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001782
1783 if (sampleRate == -1)
1784 {
1785 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1786 return -1;
1787 }
1788
1789 *samplesPerSec = sampleRate;
1790
1791 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1792 return (0);
1793}
1794
1795// ----------------------------------------------------------------------------
1796// SetPlayoutSampleRate
1797// ----------------------------------------------------------------------------
1798
pbos@webrtc.org25509882013-04-09 10:30:35 +00001799int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001800{
niklase@google.com470e71d2011-07-07 08:21:25 +00001801 CHECK_INITIALIZED();
1802
1803 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1804 {
1805 return -1;
1806 }
1807
1808 return (0);
1809}
1810
1811// ----------------------------------------------------------------------------
1812// PlayoutSampleRate
1813// ----------------------------------------------------------------------------
1814
pbos@webrtc.org25509882013-04-09 10:30:35 +00001815int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001816{
niklase@google.com470e71d2011-07-07 08:21:25 +00001817 CHECK_INITIALIZED();
1818
pbos@webrtc.org25509882013-04-09 10:30:35 +00001819 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001820
1821 if (sampleRate == -1)
1822 {
1823 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1824 return -1;
1825 }
1826
1827 *samplesPerSec = sampleRate;
1828
1829 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1830 return (0);
1831}
1832
1833// ----------------------------------------------------------------------------
1834// ResetAudioDevice
1835// ----------------------------------------------------------------------------
1836
pbos@webrtc.org25509882013-04-09 10:30:35 +00001837int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001838{
niklase@google.com470e71d2011-07-07 08:21:25 +00001839 CHECK_INITIALIZED();
1840
1841
1842 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1843 {
1844 return -1;
1845 }
1846
1847 return (0);
1848}
1849
1850// ----------------------------------------------------------------------------
1851// SetLoudspeakerStatus
1852// ----------------------------------------------------------------------------
1853
pbos@webrtc.org25509882013-04-09 10:30:35 +00001854int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001855{
niklase@google.com470e71d2011-07-07 08:21:25 +00001856 CHECK_INITIALIZED();
1857
1858 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1859 {
1860 return -1;
1861 }
1862
1863 return 0;
1864}
1865
1866// ----------------------------------------------------------------------------
1867// GetLoudspeakerStatus
1868// ----------------------------------------------------------------------------
1869
henrikac14f5ff2015-09-23 14:08:33 +02001870int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001871 CHECK_INITIALIZED();
henrikac14f5ff2015-09-23 14:08:33 +02001872 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
1873 return -1;
1874 }
1875 return 0;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001876}
1877
henrikac14f5ff2015-09-23 14:08:33 +02001878bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
1879 CHECK_INITIALIZED_BOOL();
1880 return _ptrAudioDevice->BuiltInAECIsEnabled();
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001881}
1882
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001883bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1884 CHECK_INITIALIZED_BOOL();
1885 return _ptrAudioDevice->BuiltInAECIsAvailable();
1886}
1887
henrikac14f5ff2015-09-23 14:08:33 +02001888int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
1889 CHECK_INITIALIZED();
1890 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1891}
1892
1893bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
1894 CHECK_INITIALIZED_BOOL();
1895 return _ptrAudioDevice->BuiltInAGCIsAvailable();
1896}
1897
1898int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
1899 CHECK_INITIALIZED();
1900 return _ptrAudioDevice->EnableBuiltInAGC(enable);
1901}
1902
1903bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
1904 CHECK_INITIALIZED_BOOL();
1905 return _ptrAudioDevice->BuiltInNSIsAvailable();
1906}
1907
1908int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
1909 CHECK_INITIALIZED();
1910 return _ptrAudioDevice->EnableBuiltInNS(enable);
1911}
1912
henrikaba35d052015-07-14 17:04:08 +02001913int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1914 AudioParameters* params) const {
1915 return _ptrAudioDevice->GetPlayoutAudioParameters(params);
1916}
1917
1918int AudioDeviceModuleImpl::GetRecordAudioParameters(
1919 AudioParameters* params) const {
1920 return _ptrAudioDevice->GetRecordAudioParameters(params);
1921}
1922
niklase@google.com470e71d2011-07-07 08:21:25 +00001923// ============================================================================
1924// Private Methods
1925// ============================================================================
1926
1927// ----------------------------------------------------------------------------
1928// Platform
1929// ----------------------------------------------------------------------------
1930
1931AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1932{
1933 return _platformType;
1934}
1935
1936// ----------------------------------------------------------------------------
1937// PlatformAudioLayer
1938// ----------------------------------------------------------------------------
1939
1940AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
1941{
niklase@google.com470e71d2011-07-07 08:21:25 +00001942 return _platformAudioLayer;
1943}
1944
1945} // namespace webrtc