blob: 978a7b657316d53f383b7e4927d9222d2be4da34 [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
11#include "audio_device_impl.h"
12#include "audio_device_config.h"
kma@webrtc.org0221b782012-09-08 00:09:26 +000013#include "common_audio/signal_processing/include/signal_processing_library.h"
henrika@google.com73d65512011-09-07 15:11:18 +000014#include "system_wrappers/interface/ref_count.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000016#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000017#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19#if defined(_WIN32)
xians@google.com68efa212011-08-11 12:41:56 +000020 #include "audio_device_utility_win.h"
21 #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_OPENSLES)
niklase@google.com470e71d2011-07-07 08:21:25 +000026 #include <stdlib.h>
27 #include "audio_device_utility_android.h"
leozwang@webrtc.org2a84f632012-10-03 21:40:06 +000028 #include "audio_device_opensles_android.h"
leozwang@google.com39f20512011-07-15 16:29:40 +000029#elif defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +000030 #include <stdlib.h>
31 #include "audio_device_utility_android.h"
leozwang@webrtc.org2a84f632012-10-03 21:40:06 +000032 #include "audio_device_jni_android.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033#elif defined(WEBRTC_LINUX)
34 #include "audio_device_utility_linux.h"
35 #if defined(LINUX_ALSA)
xians@google.com68efa212011-08-11 12:41:56 +000036 #include "audio_device_alsa_linux.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000037 #endif
38 #if defined(LINUX_PULSE)
xians@google.com68efa212011-08-11 12:41:56 +000039 #include "audio_device_pulse_linux.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000040 #endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000041#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000042 #include "audio_device_utility_ios.h"
43 #include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000044#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +000045 #include "audio_device_utility_mac.h"
46 #include "audio_device_mac.h"
47#endif
48#include "audio_device_dummy.h"
ajm@google.come89f6b52011-07-29 18:03:57 +000049#include "audio_device_utility_dummy.h"
xians@google.combf5d2ba2011-08-16 07:44:19 +000050#include "critical_section_wrapper.h"
51#include "trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000052
53#define CHECK_INITIALIZED() \
54{ \
55 if (!_initialized) { \
56 return -1; \
57 }; \
58}
59
60#define CHECK_INITIALIZED_BOOL() \
61{ \
62 if (!_initialized) { \
63 return false; \
64 }; \
65}
66
67namespace webrtc
68{
69
henrike@webrtc.org70efc322012-02-23 17:45:33 +000070AudioDeviceModule* CreateAudioDeviceModule(
pbos@webrtc.org25509882013-04-09 10:30:35 +000071 int32_t id, AudioDeviceModule::AudioLayer audioLayer) {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000072 return AudioDeviceModuleImpl::Create(id, audioLayer);
73}
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{
niklase@google.com470e71d2011-07-07 08:21:25 +000087
henrika@google.com73d65512011-09-07 15:11:18 +000088 // Create the generic ref counted (platform independent) implementation.
89 RefCountImpl<AudioDeviceModuleImpl>* audioDevice =
90 new RefCountImpl<AudioDeviceModuleImpl>(id, audioLayer);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
henrika@google.com73d65512011-09-07 15:11:18 +000092 // Ensure that the current platform is supported.
niklase@google.com470e71d2011-07-07 08:21:25 +000093 if (audioDevice->CheckPlatform() == -1)
94 {
95 delete audioDevice;
96 return NULL;
97 }
98
henrika@google.com73d65512011-09-07 15:11:18 +000099 // Create the platform-dependent implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000100 if (audioDevice->CreatePlatformSpecificObjects() == -1)
101 {
102 delete audioDevice;
103 return NULL;
104 }
105
henrika@google.com73d65512011-09-07 15:11:18 +0000106 // Ensure that the generic audio buffer can communicate with the
107 // platform-specific parts.
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 if (audioDevice->AttachAudioBuffer() == -1)
109 {
110 delete audioDevice;
111 return NULL;
112 }
113
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000114 WebRtcSpl_Init();
115
niklase@google.com470e71d2011-07-07 08:21:25 +0000116 return audioDevice;
117}
118
niklase@google.com470e71d2011-07-07 08:21:25 +0000119// ============================================================================
120// Construction & Destruction
121// ============================================================================
122
123// ----------------------------------------------------------------------------
124// AudioDeviceModuleImpl - ctor
125// ----------------------------------------------------------------------------
126
pbos@webrtc.org25509882013-04-09 10:30:35 +0000127AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
129 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
130 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
131 _ptrCbAudioDeviceObserver(NULL),
xians@google.com88bd4402011-08-04 15:33:30 +0000132 _ptrAudioDeviceUtility(NULL),
133 _ptrAudioDevice(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 _id(id),
135 _platformAudioLayer(audioLayer),
136 _lastProcessTime(AudioDeviceUtility::GetTimeInMS()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000137 _platformType(kPlatformNotSupported),
xians@google.com88bd4402011-08-04 15:33:30 +0000138 _initialized(false),
139 _lastError(kAdmErrNone)
niklase@google.com470e71d2011-07-07 08:21:25 +0000140{
141 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
142}
143
144// ----------------------------------------------------------------------------
145// CheckPlatform
146// ----------------------------------------------------------------------------
147
pbos@webrtc.org25509882013-04-09 10:30:35 +0000148int32_t AudioDeviceModuleImpl::CheckPlatform()
niklase@google.com470e71d2011-07-07 08:21:25 +0000149{
150 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
151
152 // Ensure that the current platform is supported
153 //
154 PlatformType platform(kPlatformNotSupported);
155
156#if defined(_WIN32)
157 platform = kPlatformWin32;
158 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
leozwang@google.com522f42b2011-09-19 17:39:05 +0000159#elif defined(WEBRTC_ANDROID)
160 platform = kPlatformAndroid;
161 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
niklase@google.com470e71d2011-07-07 08:21:25 +0000162#elif defined(WEBRTC_LINUX)
163 platform = kPlatformLinux;
164 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000165#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000166 platform = kPlatformIOS;
167 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000168#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000169 platform = kPlatformMac;
170 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
171#endif
172
173 if (platform == kPlatformNotSupported)
174 {
175 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
176 return -1;
177 }
178
179 // Store valid output results
180 //
181 _platformType = platform;
182
183 return 0;
184}
185
186
187// ----------------------------------------------------------------------------
188// CreatePlatformSpecificObjects
189// ----------------------------------------------------------------------------
190
pbos@webrtc.org25509882013-04-09 10:30:35 +0000191int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
niklase@google.com470e71d2011-07-07 08:21:25 +0000192{
193 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
194
195 AudioDeviceGeneric* ptrAudioDevice(NULL);
196 AudioDeviceUtility* ptrAudioDeviceUtility(NULL);
197
xians@google.combf5d2ba2011-08-16 07:44:19 +0000198#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
199 ptrAudioDevice = new AudioDeviceDummy(Id());
200 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
201
202 if (ptrAudioDevice != NULL)
203 {
204 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
205 }
206#else
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 const AudioLayer audioLayer(PlatformAudioLayer());
208
209 // Create the *Windows* implementation of the Audio Device
210 //
211#if defined(_WIN32)
212 if ((audioLayer == kWindowsWaveAudio)
213#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
214 // Wave audio is default if Core audio is not supported in this build
215 || (audioLayer == kPlatformDefaultAudio)
216#endif
217 )
218 {
219 // create *Windows Wave Audio* implementation
220 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
221 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
222 }
223#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
224 if ((audioLayer == kWindowsCoreAudio) ||
225 (audioLayer == kPlatformDefaultAudio)
226 )
227 {
228 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
229
230 if (AudioDeviceWindowsCore::CoreAudioIsSupported())
231 {
232 // create *Windows Core Audio* implementation
233 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
234 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
235 }
236 else
237 {
238 // create *Windows Wave Audio* implementation
239 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
240 if (ptrAudioDevice != NULL)
241 {
242 // Core Audio was not supported => revert to Windows Wave instead
243 _platformAudioLayer = kWindowsWaveAudio; // modify the state set at construction
244 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
245 }
246 }
247 }
248#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
249 if (ptrAudioDevice != NULL)
250 {
251 // Create the Windows implementation of the Device Utility.
252 // This class is independent of the selected audio layer
253 // for Windows.
254 //
255 ptrAudioDeviceUtility = new AudioDeviceUtilityWindows(Id());
256 }
257#endif // #if defined(_WIN32)
258
leozwang@google.com39f20512011-07-15 16:29:40 +0000259 // Create the *Android OpenSLES* implementation of the Audio Device
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 //
leozwang@google.com39f20512011-07-15 16:29:40 +0000261#if defined(WEBRTC_ANDROID_OPENSLES)
niklase@google.com470e71d2011-07-07 08:21:25 +0000262 if (audioLayer == kPlatformDefaultAudio)
263 {
leozwang@google.com39f20512011-07-15 16:29:40 +0000264 // Create *Android OpenELSE Audio* implementation
265 ptrAudioDevice = new AudioDeviceAndroidOpenSLES(Id());
266 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
267 "Android OpenSLES Audio APIs will be utilized");
niklase@google.com470e71d2011-07-07 08:21:25 +0000268 }
269
270 if (ptrAudioDevice != NULL)
271 {
272 // Create the Android implementation of the Device Utility.
273 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
274 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000275 // END #if defined(WEBRTC_ANDROID_OPENSLES)
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
277 // Create the *Android Java* implementation of the Audio Device
278 //
leozwang@google.com39f20512011-07-15 16:29:40 +0000279#elif defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000280 if (audioLayer == kPlatformDefaultAudio)
281 {
282 // Create *Android JNI Audio* implementation
283 ptrAudioDevice = new AudioDeviceAndroidJni(Id());
284 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Android JNI Audio APIs will be utilized");
285 }
286
287 if (ptrAudioDevice != NULL)
288 {
289 // Create the Android implementation of the Device Utility.
290 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
291 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000292 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000293
294 // Create the *Linux* implementation of the Audio Device
295 //
296#elif defined(WEBRTC_LINUX)
297 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
298 {
299#if defined(LINUX_PULSE)
300 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
301
302 if (AudioDeviceLinuxPulse::PulseAudioIsSupported())
303 {
304 // create *Linux PulseAudio* implementation
305 ptrAudioDevice = new AudioDeviceLinuxPulse(Id());
306 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
307 }
308 else
309 {
310#endif
311#if defined(LINUX_ALSA)
312 // create *Linux ALSA Audio* implementation
313 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
314 if (ptrAudioDevice != NULL)
315 {
316 // Pulse Audio was not supported => revert to ALSA instead
317 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
318 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
319 }
320#endif
321#if defined(LINUX_PULSE)
322 }
323#endif
324 }
325 else if (audioLayer == kLinuxAlsaAudio)
326 {
327#if defined(LINUX_ALSA)
328 // create *Linux ALSA Audio* implementation
329 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
330 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
331#endif
332 }
333
334 if (ptrAudioDevice != NULL)
335 {
336 // Create the Linux implementation of the Device Utility.
337 // This class is independent of the selected audio layer
338 // for Linux.
339 //
340 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
341 }
342#endif // #if defined(WEBRTC_LINUX)
343
344 // Create the *iPhone* implementation of the Audio Device
345 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000346#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000347 if (audioLayer == kPlatformDefaultAudio)
348 {
349 // Create *iPhone Audio* implementation
350 ptrAudioDevice = new AudioDeviceIPhone(Id());
351 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
352 }
353
354 if (ptrAudioDevice != NULL)
355 {
356 // Create the Mac implementation of the Device Utility.
357 ptrAudioDeviceUtility = new AudioDeviceUtilityIPhone(Id());
358 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000359 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000360
361 // Create the *Mac* implementation of the Audio Device
362 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000363#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000364 if (audioLayer == kPlatformDefaultAudio)
365 {
366 // Create *Mac Audio* implementation
367 ptrAudioDevice = new AudioDeviceMac(Id());
368 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
369 }
370
371 if (ptrAudioDevice != NULL)
372 {
373 // Create the Mac implementation of the Device Utility.
374 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
375 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000376#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
378 // Create the *Dummy* implementation of the Audio Device
379 // Available for all platforms
380 //
381 if (audioLayer == kDummyAudio)
382 {
383 // Create *Dummy Audio* implementation
384 assert(!ptrAudioDevice);
385 ptrAudioDevice = new AudioDeviceDummy(Id());
386 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
387
388 if (ptrAudioDevice != NULL)
389 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000390 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000391 }
392 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000393#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
395 if (ptrAudioDevice == NULL)
396 {
397 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
398 return -1;
399 }
400
401 if (ptrAudioDeviceUtility == NULL)
402 {
403 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
404 return -1;
405 }
406
407 // Store valid output pointers
408 //
409 _ptrAudioDevice = ptrAudioDevice;
410 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
411
412 return 0;
413}
414
415// ----------------------------------------------------------------------------
416// AttachAudioBuffer
417//
418// Install "bridge" between the platform implemetation and the generic
419// implementation. The "child" shall set the native sampling rate and the
420// number of channels in this function call.
421// ----------------------------------------------------------------------------
422
pbos@webrtc.org25509882013-04-09 10:30:35 +0000423int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000424{
425 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
426
427 _audioDeviceBuffer.SetId(_id);
428 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
429 return 0;
430}
431
432// ----------------------------------------------------------------------------
433// ~AudioDeviceModuleImpl - dtor
434// ----------------------------------------------------------------------------
435
436AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
437{
438 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000439
440 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000441 {
henrika@google.com73d65512011-09-07 15:11:18 +0000442 delete _ptrAudioDevice;
443 _ptrAudioDevice = NULL;
444 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000445
henrika@google.com73d65512011-09-07 15:11:18 +0000446 if (_ptrAudioDeviceUtility)
447 {
448 delete _ptrAudioDeviceUtility;
449 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000450 }
451
452 delete &_critSect;
453 delete &_critSectEventCb;
454 delete &_critSectAudioCb;
455}
456
457// ============================================================================
458// Module
459// ============================================================================
460
461// ----------------------------------------------------------------------------
462// Module::ChangeUniqueId
463// ----------------------------------------------------------------------------
464
pbos@webrtc.org25509882013-04-09 10:30:35 +0000465int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
niklase@google.com470e71d2011-07-07 08:21:25 +0000466{
niklase@google.com470e71d2011-07-07 08:21:25 +0000467 _id = id;
468 return 0;
469}
470
471// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000472// Module::TimeUntilNextProcess
473//
474// Returns the number of milliseconds until the module want a worker thread
475// to call Process().
476// ----------------------------------------------------------------------------
477
pbos@webrtc.org25509882013-04-09 10:30:35 +0000478int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000479{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000480 uint32_t now = AudioDeviceUtility::GetTimeInMS();
481 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000482 return (deltaProcess);
483}
484
485// ----------------------------------------------------------------------------
486// Module::Process
487//
488// Check for posted error and warning reports. Generate callbacks if
489// new reports exists.
490// ----------------------------------------------------------------------------
491
pbos@webrtc.org25509882013-04-09 10:30:35 +0000492int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000493{
niklase@google.com470e71d2011-07-07 08:21:25 +0000494
495 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
496
497 // kPlayoutWarning
498 if (_ptrAudioDevice->PlayoutWarning())
499 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000500 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000501 if (_ptrCbAudioDeviceObserver)
502 {
503 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
504 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
505 }
506 _ptrAudioDevice->ClearPlayoutWarning();
507 }
508
509 // kPlayoutError
510 if (_ptrAudioDevice->PlayoutError())
511 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000512 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000513 if (_ptrCbAudioDeviceObserver)
514 {
515 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
516 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
517 }
518 _ptrAudioDevice->ClearPlayoutError();
519 }
520
521 // kRecordingWarning
522 if (_ptrAudioDevice->RecordingWarning())
523 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000524 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000525 if (_ptrCbAudioDeviceObserver)
526 {
527 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
528 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
529 }
530 _ptrAudioDevice->ClearRecordingWarning();
531 }
532
533 // kRecordingError
534 if (_ptrAudioDevice->RecordingError())
535 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000536 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000537 if (_ptrCbAudioDeviceObserver)
538 {
539 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
540 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
541 }
542 _ptrAudioDevice->ClearRecordingError();
543 }
544
545 return 0;
546}
547
548// ============================================================================
549// Public API
550// ============================================================================
551
552// ----------------------------------------------------------------------------
553// ActiveAudioLayer
554// ----------------------------------------------------------------------------
555
pbos@webrtc.org25509882013-04-09 10:30:35 +0000556int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000557{
niklase@google.com470e71d2011-07-07 08:21:25 +0000558
559 AudioLayer activeAudio;
560
561 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
562 {
563 return -1;
564 }
565
566 *audioLayer = activeAudio;
567
568 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
569 {
570 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
571 }
572 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
573 {
574 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
575 }
576 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
577 {
578 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
579 }
580 else
581 {
582 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
583 }
584
585 return 0;
586}
587
588// ----------------------------------------------------------------------------
589// LastError
590// ----------------------------------------------------------------------------
591
592AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
593{
594 return _lastError;
595}
596
597// ----------------------------------------------------------------------------
598// Init
599// ----------------------------------------------------------------------------
600
pbos@webrtc.org25509882013-04-09 10:30:35 +0000601int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000602{
niklase@google.com470e71d2011-07-07 08:21:25 +0000603
604 if (_initialized)
605 return 0;
606
607 if (!_ptrAudioDeviceUtility)
608 return -1;
609
610 if (!_ptrAudioDevice)
611 return -1;
612
613 _ptrAudioDeviceUtility->Init();
614
615 if (_ptrAudioDevice->Init() == -1)
616 {
617 return -1;
618 }
619
620 _initialized = true;
621 return 0;
622}
623
624// ----------------------------------------------------------------------------
625// Terminate
626// ----------------------------------------------------------------------------
627
pbos@webrtc.org25509882013-04-09 10:30:35 +0000628int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000629{
niklase@google.com470e71d2011-07-07 08:21:25 +0000630
631 if (!_initialized)
632 return 0;
633
634 if (_ptrAudioDevice->Terminate() == -1)
635 {
636 return -1;
637 }
638
639 _initialized = false;
640 return 0;
641}
642
643// ----------------------------------------------------------------------------
644// Initialized
645// ----------------------------------------------------------------------------
646
647bool AudioDeviceModuleImpl::Initialized() const
648{
niklase@google.com470e71d2011-07-07 08:21:25 +0000649
650 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
651 return (_initialized);
652}
653
654// ----------------------------------------------------------------------------
655// SpeakerIsAvailable
656// ----------------------------------------------------------------------------
657
pbos@webrtc.org25509882013-04-09 10:30:35 +0000658int32_t AudioDeviceModuleImpl::SpeakerIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000659{
niklase@google.com470e71d2011-07-07 08:21:25 +0000660 CHECK_INITIALIZED();
661
662 bool isAvailable(0);
663
664 if (_ptrAudioDevice->SpeakerIsAvailable(isAvailable) == -1)
665 {
666 return -1;
667 }
668
669 *available = isAvailable;
670
671 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", available);
672 return (0);
673}
674
675// ----------------------------------------------------------------------------
676// InitSpeaker
677// ----------------------------------------------------------------------------
678
pbos@webrtc.org25509882013-04-09 10:30:35 +0000679int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000680{
niklase@google.com470e71d2011-07-07 08:21:25 +0000681 CHECK_INITIALIZED();
682 return (_ptrAudioDevice->InitSpeaker());
683}
684
685// ----------------------------------------------------------------------------
686// MicrophoneIsAvailable
687// ----------------------------------------------------------------------------
688
pbos@webrtc.org25509882013-04-09 10:30:35 +0000689int32_t AudioDeviceModuleImpl::MicrophoneIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000690{
niklase@google.com470e71d2011-07-07 08:21:25 +0000691 CHECK_INITIALIZED();
692
693 bool isAvailable(0);
694
695 if (_ptrAudioDevice->MicrophoneIsAvailable(isAvailable) == -1)
696 {
697 return -1;
698 }
699
700 *available = isAvailable;
701
702 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
703 return (0);
704}
705
706// ----------------------------------------------------------------------------
707// InitMicrophone
708// ----------------------------------------------------------------------------
709
pbos@webrtc.org25509882013-04-09 10:30:35 +0000710int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000711{
niklase@google.com470e71d2011-07-07 08:21:25 +0000712 CHECK_INITIALIZED();
713 return (_ptrAudioDevice->InitMicrophone());
714}
715
716// ----------------------------------------------------------------------------
717// SpeakerVolumeIsAvailable
718// ----------------------------------------------------------------------------
719
pbos@webrtc.org25509882013-04-09 10:30:35 +0000720int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000721{
niklase@google.com470e71d2011-07-07 08:21:25 +0000722 CHECK_INITIALIZED();
723
724 bool isAvailable(0);
725
726 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
727 {
728 return -1;
729 }
730
731 *available = isAvailable;
732
733 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
734 return (0);
735}
736
737// ----------------------------------------------------------------------------
738// SetSpeakerVolume
739// ----------------------------------------------------------------------------
740
pbos@webrtc.org25509882013-04-09 10:30:35 +0000741int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000742{
niklase@google.com470e71d2011-07-07 08:21:25 +0000743 CHECK_INITIALIZED();
744 return (_ptrAudioDevice->SetSpeakerVolume(volume));
745}
746
747// ----------------------------------------------------------------------------
748// SpeakerVolume
749// ----------------------------------------------------------------------------
750
pbos@webrtc.org25509882013-04-09 10:30:35 +0000751int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000752{
niklase@google.com470e71d2011-07-07 08:21:25 +0000753 CHECK_INITIALIZED();
754
pbos@webrtc.org25509882013-04-09 10:30:35 +0000755 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000756
757 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
758 {
759 return -1;
760 }
761
762 *volume = level;
763
764 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
765 return (0);
766}
767
768// ----------------------------------------------------------------------------
769// SetWaveOutVolume
770// ----------------------------------------------------------------------------
771
pbos@webrtc.org25509882013-04-09 10:30:35 +0000772int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000773{
niklase@google.com470e71d2011-07-07 08:21:25 +0000774 CHECK_INITIALIZED();
775 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
776}
777
778// ----------------------------------------------------------------------------
779// WaveOutVolume
780// ----------------------------------------------------------------------------
781
pbos@webrtc.org25509882013-04-09 10:30:35 +0000782int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000783{
niklase@google.com470e71d2011-07-07 08:21:25 +0000784 CHECK_INITIALIZED();
785
pbos@webrtc.org25509882013-04-09 10:30:35 +0000786 uint16_t volLeft(0);
787 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000788
789 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
790 {
791 return -1;
792 }
793
794 *volumeLeft = volLeft;
795 *volumeRight = volRight;
796
797 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
798 *volumeLeft, *volumeRight);
799
800 return (0);
801}
802
803// ----------------------------------------------------------------------------
804// SpeakerIsInitialized
805// ----------------------------------------------------------------------------
806
807bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
808{
niklase@google.com470e71d2011-07-07 08:21:25 +0000809 CHECK_INITIALIZED_BOOL();
810
811 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
812
813 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
814 return (isInitialized);
815}
816
817// ----------------------------------------------------------------------------
818// MicrophoneIsInitialized
819// ----------------------------------------------------------------------------
820
821bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
822{
niklase@google.com470e71d2011-07-07 08:21:25 +0000823 CHECK_INITIALIZED_BOOL();
824
825 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
826
827 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
828 return (isInitialized);
829}
830
831// ----------------------------------------------------------------------------
832// MaxSpeakerVolume
833// ----------------------------------------------------------------------------
834
pbos@webrtc.org25509882013-04-09 10:30:35 +0000835int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000836{
niklase@google.com470e71d2011-07-07 08:21:25 +0000837 CHECK_INITIALIZED();
838
pbos@webrtc.org25509882013-04-09 10:30:35 +0000839 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000840
841 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
842 {
843 return -1;
844 }
845
846 *maxVolume = maxVol;
847
848 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
849 return (0);
850}
851
852// ----------------------------------------------------------------------------
853// MinSpeakerVolume
854// ----------------------------------------------------------------------------
855
pbos@webrtc.org25509882013-04-09 10:30:35 +0000856int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000857{
niklase@google.com470e71d2011-07-07 08:21:25 +0000858 CHECK_INITIALIZED();
859
pbos@webrtc.org25509882013-04-09 10:30:35 +0000860 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000861
862 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
863 {
864 return -1;
865 }
866
867 *minVolume = minVol;
868
869 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
870 return (0);
871}
872
873// ----------------------------------------------------------------------------
874// SpeakerVolumeStepSize
875// ----------------------------------------------------------------------------
876
pbos@webrtc.org25509882013-04-09 10:30:35 +0000877int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000878{
niklase@google.com470e71d2011-07-07 08:21:25 +0000879 CHECK_INITIALIZED();
880
pbos@webrtc.org25509882013-04-09 10:30:35 +0000881 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000882
883 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
884 {
885 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
886 return -1;
887 }
888
889 *stepSize = delta;
890
891 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
892 return (0);
893}
894
895// ----------------------------------------------------------------------------
896// SpeakerMuteIsAvailable
897// ----------------------------------------------------------------------------
898
pbos@webrtc.org25509882013-04-09 10:30:35 +0000899int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000900{
niklase@google.com470e71d2011-07-07 08:21:25 +0000901 CHECK_INITIALIZED();
902
903 bool isAvailable(0);
904
905 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
906 {
907 return -1;
908 }
909
910 *available = isAvailable;
911
912 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
913 return (0);
914}
915
916// ----------------------------------------------------------------------------
917// SetSpeakerMute
918// ----------------------------------------------------------------------------
919
pbos@webrtc.org25509882013-04-09 10:30:35 +0000920int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000921{
niklase@google.com470e71d2011-07-07 08:21:25 +0000922 CHECK_INITIALIZED();
923 return (_ptrAudioDevice->SetSpeakerMute(enable));
924}
925
926// ----------------------------------------------------------------------------
927// SpeakerMute
928// ----------------------------------------------------------------------------
929
pbos@webrtc.org25509882013-04-09 10:30:35 +0000930int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000931{
niklase@google.com470e71d2011-07-07 08:21:25 +0000932 CHECK_INITIALIZED();
933
934 bool muted(false);
935
936 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
937 {
938 return -1;
939 }
940
941 *enabled = muted;
942
943 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
944 return (0);
945}
946
947// ----------------------------------------------------------------------------
948// MicrophoneMuteIsAvailable
949// ----------------------------------------------------------------------------
950
pbos@webrtc.org25509882013-04-09 10:30:35 +0000951int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000952{
niklase@google.com470e71d2011-07-07 08:21:25 +0000953 CHECK_INITIALIZED();
954
955 bool isAvailable(0);
956
957 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
958 {
959 return -1;
960 }
961
962 *available = isAvailable;
963
964 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
965 return (0);
966}
967
968// ----------------------------------------------------------------------------
969// SetMicrophoneMute
970// ----------------------------------------------------------------------------
971
pbos@webrtc.org25509882013-04-09 10:30:35 +0000972int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000973{
niklase@google.com470e71d2011-07-07 08:21:25 +0000974 CHECK_INITIALIZED();
975 return (_ptrAudioDevice->SetMicrophoneMute(enable));
976}
977
978// ----------------------------------------------------------------------------
979// MicrophoneMute
980// ----------------------------------------------------------------------------
981
pbos@webrtc.org25509882013-04-09 10:30:35 +0000982int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000983{
niklase@google.com470e71d2011-07-07 08:21:25 +0000984 CHECK_INITIALIZED();
985
986 bool muted(false);
987
988 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
989 {
990 return -1;
991 }
992
993 *enabled = muted;
994
995 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
996 return (0);
997}
998
999// ----------------------------------------------------------------------------
1000// MicrophoneBoostIsAvailable
1001// ----------------------------------------------------------------------------
1002
pbos@webrtc.org25509882013-04-09 10:30:35 +00001003int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001004{
niklase@google.com470e71d2011-07-07 08:21:25 +00001005 CHECK_INITIALIZED();
1006
1007 bool isAvailable(0);
1008
1009 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
1010 {
1011 return -1;
1012 }
1013
1014 *available = isAvailable;
1015
1016 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1017 return (0);
1018}
1019
1020// ----------------------------------------------------------------------------
1021// SetMicrophoneBoost
1022// ----------------------------------------------------------------------------
1023
pbos@webrtc.org25509882013-04-09 10:30:35 +00001024int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001025{
niklase@google.com470e71d2011-07-07 08:21:25 +00001026 CHECK_INITIALIZED();
1027 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
1028}
1029
1030// ----------------------------------------------------------------------------
1031// MicrophoneBoost
1032// ----------------------------------------------------------------------------
1033
pbos@webrtc.org25509882013-04-09 10:30:35 +00001034int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001035{
niklase@google.com470e71d2011-07-07 08:21:25 +00001036 CHECK_INITIALIZED();
1037
1038 bool onOff(false);
1039
1040 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
1041 {
1042 return -1;
1043 }
1044
1045 *enabled = onOff;
1046
1047 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1048 return (0);
1049}
1050
1051// ----------------------------------------------------------------------------
1052// MicrophoneVolumeIsAvailable
1053// ----------------------------------------------------------------------------
1054
pbos@webrtc.org25509882013-04-09 10:30:35 +00001055int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001056{
niklase@google.com470e71d2011-07-07 08:21:25 +00001057 CHECK_INITIALIZED();
1058
1059 bool isAvailable(0);
1060
1061 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1062 {
1063 return -1;
1064 }
1065
1066 *available = isAvailable;
1067
1068 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1069 return (0);
1070}
1071
1072// ----------------------------------------------------------------------------
1073// SetMicrophoneVolume
1074// ----------------------------------------------------------------------------
1075
pbos@webrtc.org25509882013-04-09 10:30:35 +00001076int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001077{
niklase@google.com470e71d2011-07-07 08:21:25 +00001078 CHECK_INITIALIZED();
1079 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1080}
1081
1082// ----------------------------------------------------------------------------
1083// MicrophoneVolume
1084// ----------------------------------------------------------------------------
1085
pbos@webrtc.org25509882013-04-09 10:30:35 +00001086int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001087{
1088 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1089 CHECK_INITIALIZED();
1090
pbos@webrtc.org25509882013-04-09 10:30:35 +00001091 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001092
1093 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1094 {
1095 return -1;
1096 }
1097
1098 *volume = level;
1099
1100 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1101 return (0);
1102}
1103
1104// ----------------------------------------------------------------------------
1105// StereoRecordingIsAvailable
1106// ----------------------------------------------------------------------------
1107
pbos@webrtc.org25509882013-04-09 10:30:35 +00001108int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001109{
niklase@google.com470e71d2011-07-07 08:21:25 +00001110 CHECK_INITIALIZED();
1111
1112 bool isAvailable(0);
1113
1114 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1115 {
1116 return -1;
1117 }
1118
1119 *available = isAvailable;
1120
1121 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1122 return (0);
1123}
1124
1125// ----------------------------------------------------------------------------
1126// SetStereoRecording
1127// ----------------------------------------------------------------------------
1128
pbos@webrtc.org25509882013-04-09 10:30:35 +00001129int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001130{
niklase@google.com470e71d2011-07-07 08:21:25 +00001131 CHECK_INITIALIZED();
1132
1133 if (_ptrAudioDevice->RecordingIsInitialized())
1134 {
1135 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1136 return -1;
1137 }
1138
1139 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1140 {
1141 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1142 return -1;
1143 }
1144
pbos@webrtc.org25509882013-04-09 10:30:35 +00001145 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001146 if (enable)
1147 {
1148 nChannels = 2;
1149 }
1150 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1151
1152 return 0;
1153}
1154
1155// ----------------------------------------------------------------------------
1156// StereoRecording
1157// ----------------------------------------------------------------------------
1158
pbos@webrtc.org25509882013-04-09 10:30:35 +00001159int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001160{
niklase@google.com470e71d2011-07-07 08:21:25 +00001161 CHECK_INITIALIZED();
1162
1163 bool stereo(false);
1164
1165 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1166 {
1167 return -1;
1168 }
1169
1170 *enabled = stereo;
1171
1172 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1173 return (0);
1174}
1175
1176// ----------------------------------------------------------------------------
1177// SetRecordingChannel
1178// ----------------------------------------------------------------------------
1179
pbos@webrtc.org25509882013-04-09 10:30:35 +00001180int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001181{
1182 if (channel == kChannelBoth)
1183 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001184 }
1185 else if (channel == kChannelLeft)
1186 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001187 }
1188 else
1189 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001190 }
1191 CHECK_INITIALIZED();
1192
1193 bool stereo(false);
1194
1195 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1196 {
1197 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1198 return -1;
1199 }
1200
1201 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1202}
1203
1204// ----------------------------------------------------------------------------
1205// RecordingChannel
1206// ----------------------------------------------------------------------------
1207
pbos@webrtc.org25509882013-04-09 10:30:35 +00001208int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001209{
niklase@google.com470e71d2011-07-07 08:21:25 +00001210 CHECK_INITIALIZED();
1211
1212 ChannelType chType;
1213
1214 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1215 {
1216 return -1;
1217 }
1218
1219 *channel = chType;
1220
1221 if (*channel == kChannelBoth)
1222 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001223 }
1224 else if (*channel == kChannelLeft)
1225 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001226 }
1227 else
1228 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001229 }
1230
1231 return (0);
1232}
1233
1234// ----------------------------------------------------------------------------
1235// StereoPlayoutIsAvailable
1236// ----------------------------------------------------------------------------
1237
pbos@webrtc.org25509882013-04-09 10:30:35 +00001238int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001239{
niklase@google.com470e71d2011-07-07 08:21:25 +00001240 CHECK_INITIALIZED();
1241
1242 bool isAvailable(0);
1243
1244 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1245 {
1246 return -1;
1247 }
1248
1249 *available = isAvailable;
1250
1251 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1252 return (0);
1253}
1254
1255// ----------------------------------------------------------------------------
1256// SetStereoPlayout
1257// ----------------------------------------------------------------------------
1258
pbos@webrtc.org25509882013-04-09 10:30:35 +00001259int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001260{
niklase@google.com470e71d2011-07-07 08:21:25 +00001261 CHECK_INITIALIZED();
1262
1263 if (_ptrAudioDevice->PlayoutIsInitialized())
1264 {
1265 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1266 return -1;
1267 }
1268
1269 if (_ptrAudioDevice->SetStereoPlayout(enable))
1270 {
1271 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1272 return -1;
1273 }
1274
pbos@webrtc.org25509882013-04-09 10:30:35 +00001275 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001276 if (enable)
1277 {
1278 nChannels = 2;
1279 }
1280 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1281
1282 return 0;
1283}
1284
1285// ----------------------------------------------------------------------------
1286// StereoPlayout
1287// ----------------------------------------------------------------------------
1288
pbos@webrtc.org25509882013-04-09 10:30:35 +00001289int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001290{
niklase@google.com470e71d2011-07-07 08:21:25 +00001291 CHECK_INITIALIZED();
1292
1293 bool stereo(false);
1294
1295 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1296 {
1297 return -1;
1298 }
1299
1300 *enabled = stereo;
1301
1302 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1303 return (0);
1304}
1305
1306// ----------------------------------------------------------------------------
1307// SetAGC
1308// ----------------------------------------------------------------------------
1309
pbos@webrtc.org25509882013-04-09 10:30:35 +00001310int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001311{
niklase@google.com470e71d2011-07-07 08:21:25 +00001312 CHECK_INITIALIZED();
1313 return (_ptrAudioDevice->SetAGC(enable));
1314}
1315
1316// ----------------------------------------------------------------------------
1317// AGC
1318// ----------------------------------------------------------------------------
1319
1320bool AudioDeviceModuleImpl::AGC() const
1321{
niklase@google.com470e71d2011-07-07 08:21:25 +00001322 CHECK_INITIALIZED_BOOL();
1323 return (_ptrAudioDevice->AGC());
1324}
1325
1326// ----------------------------------------------------------------------------
1327// PlayoutIsAvailable
1328// ----------------------------------------------------------------------------
1329
pbos@webrtc.org25509882013-04-09 10:30:35 +00001330int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001331{
niklase@google.com470e71d2011-07-07 08:21:25 +00001332 CHECK_INITIALIZED();
1333
1334 bool isAvailable(0);
1335
1336 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1337 {
1338 return -1;
1339 }
1340
1341 *available = isAvailable;
1342
1343 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1344 return (0);
1345}
1346
1347// ----------------------------------------------------------------------------
1348// RecordingIsAvailable
1349// ----------------------------------------------------------------------------
1350
pbos@webrtc.org25509882013-04-09 10:30:35 +00001351int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001352{
niklase@google.com470e71d2011-07-07 08:21:25 +00001353 CHECK_INITIALIZED();
1354
1355 bool isAvailable(0);
1356
1357 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1358 {
1359 return -1;
1360 }
1361
1362 *available = isAvailable;
1363
1364 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1365 return (0);
1366}
1367
1368// ----------------------------------------------------------------------------
1369// MaxMicrophoneVolume
1370// ----------------------------------------------------------------------------
1371
pbos@webrtc.org25509882013-04-09 10:30:35 +00001372int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001373{
1374 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1375 CHECK_INITIALIZED();
1376
pbos@webrtc.org25509882013-04-09 10:30:35 +00001377 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001378
1379 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1380 {
1381 return -1;
1382 }
1383
1384 *maxVolume = maxVol;
1385
1386 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1387 return (0);
1388}
1389
1390// ----------------------------------------------------------------------------
1391// MinMicrophoneVolume
1392// ----------------------------------------------------------------------------
1393
pbos@webrtc.org25509882013-04-09 10:30:35 +00001394int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001395{
niklase@google.com470e71d2011-07-07 08:21:25 +00001396 CHECK_INITIALIZED();
1397
pbos@webrtc.org25509882013-04-09 10:30:35 +00001398 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001399
1400 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1401 {
1402 return -1;
1403 }
1404
1405 *minVolume = minVol;
1406
1407 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1408 return (0);
1409}
1410
1411// ----------------------------------------------------------------------------
1412// MicrophoneVolumeStepSize
1413// ----------------------------------------------------------------------------
1414
pbos@webrtc.org25509882013-04-09 10:30:35 +00001415int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001416{
niklase@google.com470e71d2011-07-07 08:21:25 +00001417 CHECK_INITIALIZED();
1418
pbos@webrtc.org25509882013-04-09 10:30:35 +00001419 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001420
1421 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1422 {
1423 return -1;
1424 }
1425
1426 *stepSize = delta;
1427
1428 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1429 return (0);
1430}
1431
1432// ----------------------------------------------------------------------------
1433// PlayoutDevices
1434// ----------------------------------------------------------------------------
1435
pbos@webrtc.org25509882013-04-09 10:30:35 +00001436int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001437{
niklase@google.com470e71d2011-07-07 08:21:25 +00001438 CHECK_INITIALIZED();
1439
pbos@webrtc.org25509882013-04-09 10:30:35 +00001440 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001441
1442 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001443 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001444}
1445
1446// ----------------------------------------------------------------------------
1447// SetPlayoutDevice I (II)
1448// ----------------------------------------------------------------------------
1449
pbos@webrtc.org25509882013-04-09 10:30:35 +00001450int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001451{
niklase@google.com470e71d2011-07-07 08:21:25 +00001452 CHECK_INITIALIZED();
1453 return (_ptrAudioDevice->SetPlayoutDevice(index));
1454}
1455
1456// ----------------------------------------------------------------------------
1457// SetPlayoutDevice II (II)
1458// ----------------------------------------------------------------------------
1459
pbos@webrtc.org25509882013-04-09 10:30:35 +00001460int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001461{
1462 if (device == kDefaultDevice)
1463 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001464 }
1465 else
1466 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001467 }
1468 CHECK_INITIALIZED();
1469
1470 return (_ptrAudioDevice->SetPlayoutDevice(device));
1471}
1472
1473// ----------------------------------------------------------------------------
1474// PlayoutDeviceName
1475// ----------------------------------------------------------------------------
1476
pbos@webrtc.org25509882013-04-09 10:30:35 +00001477int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1478 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001479 char name[kAdmMaxDeviceNameSize],
1480 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001481{
niklase@google.com470e71d2011-07-07 08:21:25 +00001482 CHECK_INITIALIZED();
1483
1484 if (name == NULL)
1485 {
1486 _lastError = kAdmErrArgument;
1487 return -1;
1488 }
1489
1490 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1491 {
1492 return -1;
1493 }
1494
1495 if (name != NULL)
1496 {
1497 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1498 }
1499 if (guid != NULL)
1500 {
1501 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1502 }
1503
1504 return (0);
1505}
1506
1507// ----------------------------------------------------------------------------
1508// RecordingDeviceName
1509// ----------------------------------------------------------------------------
1510
pbos@webrtc.org25509882013-04-09 10:30:35 +00001511int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1512 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001513 char name[kAdmMaxDeviceNameSize],
1514 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001515{
niklase@google.com470e71d2011-07-07 08:21:25 +00001516 CHECK_INITIALIZED();
1517
1518 if (name == NULL)
1519 {
1520 _lastError = kAdmErrArgument;
1521 return -1;
1522 }
1523
1524 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1525 {
1526 return -1;
1527 }
1528
1529 if (name != NULL)
1530 {
1531 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1532 }
1533 if (guid != NULL)
1534 {
1535 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1536 }
1537
1538 return (0);
1539}
1540
1541// ----------------------------------------------------------------------------
1542// RecordingDevices
1543// ----------------------------------------------------------------------------
1544
pbos@webrtc.org25509882013-04-09 10:30:35 +00001545int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001546{
niklase@google.com470e71d2011-07-07 08:21:25 +00001547 CHECK_INITIALIZED();
1548
pbos@webrtc.org25509882013-04-09 10:30:35 +00001549 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001550
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001551 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1552 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001553 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001554}
1555
1556// ----------------------------------------------------------------------------
1557// SetRecordingDevice I (II)
1558// ----------------------------------------------------------------------------
1559
pbos@webrtc.org25509882013-04-09 10:30:35 +00001560int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001561{
niklase@google.com470e71d2011-07-07 08:21:25 +00001562 CHECK_INITIALIZED();
1563 return (_ptrAudioDevice->SetRecordingDevice(index));
1564}
1565
1566// ----------------------------------------------------------------------------
1567// SetRecordingDevice II (II)
1568// ----------------------------------------------------------------------------
1569
pbos@webrtc.org25509882013-04-09 10:30:35 +00001570int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001571{
1572 if (device == kDefaultDevice)
1573 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001574 }
1575 else
1576 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001577 }
1578 CHECK_INITIALIZED();
1579
1580 return (_ptrAudioDevice->SetRecordingDevice(device));
1581}
1582
1583// ----------------------------------------------------------------------------
1584// InitPlayout
1585// ----------------------------------------------------------------------------
1586
pbos@webrtc.org25509882013-04-09 10:30:35 +00001587int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001588{
niklase@google.com470e71d2011-07-07 08:21:25 +00001589 CHECK_INITIALIZED();
1590 _audioDeviceBuffer.InitPlayout();
1591 return (_ptrAudioDevice->InitPlayout());
1592}
1593
1594// ----------------------------------------------------------------------------
1595// InitRecording
1596// ----------------------------------------------------------------------------
1597
pbos@webrtc.org25509882013-04-09 10:30:35 +00001598int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001599{
niklase@google.com470e71d2011-07-07 08:21:25 +00001600 CHECK_INITIALIZED();
1601 _audioDeviceBuffer.InitRecording();
1602 return (_ptrAudioDevice->InitRecording());
1603}
1604
1605// ----------------------------------------------------------------------------
1606// PlayoutIsInitialized
1607// ----------------------------------------------------------------------------
1608
1609bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1610{
niklase@google.com470e71d2011-07-07 08:21:25 +00001611 CHECK_INITIALIZED_BOOL();
1612 return (_ptrAudioDevice->PlayoutIsInitialized());
1613}
1614
1615// ----------------------------------------------------------------------------
1616// RecordingIsInitialized
1617// ----------------------------------------------------------------------------
1618
1619bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1620{
niklase@google.com470e71d2011-07-07 08:21:25 +00001621 CHECK_INITIALIZED_BOOL();
1622 return (_ptrAudioDevice->RecordingIsInitialized());
1623}
1624
1625// ----------------------------------------------------------------------------
1626// StartPlayout
1627// ----------------------------------------------------------------------------
1628
pbos@webrtc.org25509882013-04-09 10:30:35 +00001629int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001630{
niklase@google.com470e71d2011-07-07 08:21:25 +00001631 CHECK_INITIALIZED();
1632 return (_ptrAudioDevice->StartPlayout());
1633}
1634
1635// ----------------------------------------------------------------------------
1636// StopPlayout
1637// ----------------------------------------------------------------------------
1638
pbos@webrtc.org25509882013-04-09 10:30:35 +00001639int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001640{
niklase@google.com470e71d2011-07-07 08:21:25 +00001641 CHECK_INITIALIZED();
1642 return (_ptrAudioDevice->StopPlayout());
1643}
1644
1645// ----------------------------------------------------------------------------
1646// Playing
1647// ----------------------------------------------------------------------------
1648
1649bool AudioDeviceModuleImpl::Playing() const
1650{
niklase@google.com470e71d2011-07-07 08:21:25 +00001651 CHECK_INITIALIZED_BOOL();
1652 return (_ptrAudioDevice->Playing());
1653}
1654
1655// ----------------------------------------------------------------------------
1656// StartRecording
1657// ----------------------------------------------------------------------------
1658
pbos@webrtc.org25509882013-04-09 10:30:35 +00001659int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001660{
niklase@google.com470e71d2011-07-07 08:21:25 +00001661 CHECK_INITIALIZED();
1662 return (_ptrAudioDevice->StartRecording());
1663}
1664// ----------------------------------------------------------------------------
1665// StopRecording
1666// ----------------------------------------------------------------------------
1667
pbos@webrtc.org25509882013-04-09 10:30:35 +00001668int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001669{
niklase@google.com470e71d2011-07-07 08:21:25 +00001670 CHECK_INITIALIZED();
1671 return (_ptrAudioDevice->StopRecording());
1672}
1673
1674// ----------------------------------------------------------------------------
1675// Recording
1676// ----------------------------------------------------------------------------
1677
1678bool AudioDeviceModuleImpl::Recording() const
1679{
niklase@google.com470e71d2011-07-07 08:21:25 +00001680 CHECK_INITIALIZED_BOOL();
1681 return (_ptrAudioDevice->Recording());
1682}
1683
1684// ----------------------------------------------------------------------------
1685// RegisterEventObserver
1686// ----------------------------------------------------------------------------
1687
pbos@webrtc.org25509882013-04-09 10:30:35 +00001688int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001689{
niklase@google.com470e71d2011-07-07 08:21:25 +00001690
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001691 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001692 _ptrCbAudioDeviceObserver = eventCallback;
1693
1694 return 0;
1695}
1696
1697// ----------------------------------------------------------------------------
1698// RegisterAudioCallback
1699// ----------------------------------------------------------------------------
1700
pbos@webrtc.org25509882013-04-09 10:30:35 +00001701int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001702{
niklase@google.com470e71d2011-07-07 08:21:25 +00001703
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001704 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001705 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1706
1707 return 0;
1708}
1709
1710// ----------------------------------------------------------------------------
1711// StartRawInputFileRecording
1712// ----------------------------------------------------------------------------
1713
pbos@webrtc.org25509882013-04-09 10:30:35 +00001714int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001715 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001716{
niklase@google.com470e71d2011-07-07 08:21:25 +00001717 CHECK_INITIALIZED();
1718
1719 if (NULL == pcmFileNameUTF8)
1720 {
1721 return -1;
1722 }
1723
1724 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1725}
1726
1727// ----------------------------------------------------------------------------
1728// StopRawInputFileRecording
1729// ----------------------------------------------------------------------------
1730
pbos@webrtc.org25509882013-04-09 10:30:35 +00001731int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001732{
niklase@google.com470e71d2011-07-07 08:21:25 +00001733 CHECK_INITIALIZED();
1734
1735 return (_audioDeviceBuffer.StopInputFileRecording());
1736}
1737
1738// ----------------------------------------------------------------------------
1739// StartRawOutputFileRecording
1740// ----------------------------------------------------------------------------
1741
pbos@webrtc.org25509882013-04-09 10:30:35 +00001742int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001743 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001744{
niklase@google.com470e71d2011-07-07 08:21:25 +00001745 CHECK_INITIALIZED();
1746
1747 if (NULL == pcmFileNameUTF8)
1748 {
1749 return -1;
1750 }
1751
1752 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1753}
1754
1755// ----------------------------------------------------------------------------
1756// StopRawOutputFileRecording
1757// ----------------------------------------------------------------------------
1758
pbos@webrtc.org25509882013-04-09 10:30:35 +00001759int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001760{
niklase@google.com470e71d2011-07-07 08:21:25 +00001761 CHECK_INITIALIZED();
1762
1763 return (_audioDeviceBuffer.StopOutputFileRecording());
1764
1765 return 0;
1766}
1767
1768// ----------------------------------------------------------------------------
1769// SetPlayoutBuffer
1770// ----------------------------------------------------------------------------
1771
pbos@webrtc.org25509882013-04-09 10:30:35 +00001772int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001773{
niklase@google.com470e71d2011-07-07 08:21:25 +00001774 CHECK_INITIALIZED();
1775
1776 if (_ptrAudioDevice->PlayoutIsInitialized())
1777 {
1778 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1779 return -1;
1780 }
1781
pbos@webrtc.org25509882013-04-09 10:30:35 +00001782 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001783
1784 if (kFixedBufferSize == type)
1785 {
1786 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1787 {
1788 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1789 return -1;
1790 }
1791 }
1792
1793 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1794 {
1795 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1796 }
1797
1798 return ret;
1799}
1800
1801// ----------------------------------------------------------------------------
1802// PlayoutBuffer
1803// ----------------------------------------------------------------------------
1804
pbos@webrtc.org25509882013-04-09 10:30:35 +00001805int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001806{
niklase@google.com470e71d2011-07-07 08:21:25 +00001807 CHECK_INITIALIZED();
1808
1809 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001810 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001811
1812 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1813 {
1814 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1815 return -1;
1816 }
1817
1818 *type = bufType;
1819 *sizeMS = size;
1820
1821 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1822 return (0);
1823}
1824
1825// ----------------------------------------------------------------------------
1826// PlayoutDelay
1827// ----------------------------------------------------------------------------
1828
pbos@webrtc.org25509882013-04-09 10:30:35 +00001829int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001830{
1831 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1832 CHECK_INITIALIZED();
1833
pbos@webrtc.org25509882013-04-09 10:30:35 +00001834 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001835
1836 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1837 {
1838 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1839 return -1;
1840 }
1841
1842 *delayMS = delay;
1843
1844 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1845 return (0);
1846}
1847
1848// ----------------------------------------------------------------------------
1849// RecordingDelay
1850// ----------------------------------------------------------------------------
1851
pbos@webrtc.org25509882013-04-09 10:30:35 +00001852int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001853{
1854 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1855 CHECK_INITIALIZED();
1856
pbos@webrtc.org25509882013-04-09 10:30:35 +00001857 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001858
1859 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1860 {
1861 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1862 return -1;
1863 }
1864
1865 *delayMS = delay;
1866
1867 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1868 return (0);
1869}
1870
1871// ----------------------------------------------------------------------------
1872// CPULoad
1873// ----------------------------------------------------------------------------
1874
pbos@webrtc.org25509882013-04-09 10:30:35 +00001875int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001876{
niklase@google.com470e71d2011-07-07 08:21:25 +00001877 CHECK_INITIALIZED();
1878
pbos@webrtc.org25509882013-04-09 10:30:35 +00001879 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001880
1881 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1882 {
1883 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1884 return -1;
1885 }
1886
1887 *load = cpuLoad;
1888
1889 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1890 return (0);
1891}
1892
1893// ----------------------------------------------------------------------------
1894// SetRecordingSampleRate
1895// ----------------------------------------------------------------------------
1896
pbos@webrtc.org25509882013-04-09 10:30:35 +00001897int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001898{
niklase@google.com470e71d2011-07-07 08:21:25 +00001899 CHECK_INITIALIZED();
1900
1901 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1902 {
1903 return -1;
1904 }
1905
1906 return (0);
1907}
1908
1909// ----------------------------------------------------------------------------
1910// RecordingSampleRate
1911// ----------------------------------------------------------------------------
1912
pbos@webrtc.org25509882013-04-09 10:30:35 +00001913int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001914{
niklase@google.com470e71d2011-07-07 08:21:25 +00001915 CHECK_INITIALIZED();
1916
pbos@webrtc.org25509882013-04-09 10:30:35 +00001917 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001918
1919 if (sampleRate == -1)
1920 {
1921 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1922 return -1;
1923 }
1924
1925 *samplesPerSec = sampleRate;
1926
1927 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1928 return (0);
1929}
1930
1931// ----------------------------------------------------------------------------
1932// SetPlayoutSampleRate
1933// ----------------------------------------------------------------------------
1934
pbos@webrtc.org25509882013-04-09 10:30:35 +00001935int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001936{
niklase@google.com470e71d2011-07-07 08:21:25 +00001937 CHECK_INITIALIZED();
1938
1939 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1940 {
1941 return -1;
1942 }
1943
1944 return (0);
1945}
1946
1947// ----------------------------------------------------------------------------
1948// PlayoutSampleRate
1949// ----------------------------------------------------------------------------
1950
pbos@webrtc.org25509882013-04-09 10:30:35 +00001951int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001952{
niklase@google.com470e71d2011-07-07 08:21:25 +00001953 CHECK_INITIALIZED();
1954
pbos@webrtc.org25509882013-04-09 10:30:35 +00001955 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001956
1957 if (sampleRate == -1)
1958 {
1959 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1960 return -1;
1961 }
1962
1963 *samplesPerSec = sampleRate;
1964
1965 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1966 return (0);
1967}
1968
1969// ----------------------------------------------------------------------------
1970// ResetAudioDevice
1971// ----------------------------------------------------------------------------
1972
pbos@webrtc.org25509882013-04-09 10:30:35 +00001973int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001974{
niklase@google.com470e71d2011-07-07 08:21:25 +00001975 CHECK_INITIALIZED();
1976
1977
1978 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1979 {
1980 return -1;
1981 }
1982
1983 return (0);
1984}
1985
1986// ----------------------------------------------------------------------------
1987// SetLoudspeakerStatus
1988// ----------------------------------------------------------------------------
1989
pbos@webrtc.org25509882013-04-09 10:30:35 +00001990int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001991{
niklase@google.com470e71d2011-07-07 08:21:25 +00001992 CHECK_INITIALIZED();
1993
1994 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1995 {
1996 return -1;
1997 }
1998
1999 return 0;
2000}
2001
2002// ----------------------------------------------------------------------------
2003// GetLoudspeakerStatus
2004// ----------------------------------------------------------------------------
2005
pbos@webrtc.org25509882013-04-09 10:30:35 +00002006int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00002007{
niklase@google.com470e71d2011-07-07 08:21:25 +00002008 CHECK_INITIALIZED();
2009
2010 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
2011 {
2012 return -1;
2013 }
2014
2015 return 0;
2016}
2017
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00002018int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
2019{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00002020 CHECK_INITIALIZED();
2021
2022 return _ptrAudioDevice->EnableBuiltInAEC(enable);
2023}
2024
2025bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
2026{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00002027 CHECK_INITIALIZED_BOOL();
2028
2029 return _ptrAudioDevice->BuiltInAECIsEnabled();
2030}
2031
niklase@google.com470e71d2011-07-07 08:21:25 +00002032// ============================================================================
2033// Private Methods
2034// ============================================================================
2035
2036// ----------------------------------------------------------------------------
2037// Platform
2038// ----------------------------------------------------------------------------
2039
2040AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
2041{
2042 return _platformType;
2043}
2044
2045// ----------------------------------------------------------------------------
2046// PlatformAudioLayer
2047// ----------------------------------------------------------------------------
2048
2049AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2050{
niklase@google.com470e71d2011-07-07 08:21:25 +00002051
2052 switch (_platformAudioLayer)
2053 {
2054 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002055 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2056 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002057 break;
2058 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002059 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2060 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002061 break;
2062 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002063 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2064 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002065 break;
2066 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002067 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2068 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002069 break;
2070 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002071 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2072 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002073 break;
2074 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002075 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2076 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002077 break;
2078 }
2079
2080 return _platformAudioLayer;
2081}
2082
2083} // namespace webrtc