blob: 429bf62506e3e4408ed18a9f1637d2c83f3c03e0 [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"
14#include "webrtc/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
pbos@webrtc.org811269d2013-07-11 13:24:38 +000048#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
49#include "webrtc/modules/audio_device/dummy/audio_device_utility_dummy.h"
50#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
51#include "webrtc/system_wrappers/interface/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
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000302 // create *Linux PulseAudio* implementation
303 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
304 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000305 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000306 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000307 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
308 }
309 else
310 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000311 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000312#endif
313#if defined(LINUX_ALSA)
314 // create *Linux ALSA Audio* implementation
315 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
316 if (ptrAudioDevice != NULL)
317 {
318 // Pulse Audio was not supported => revert to ALSA instead
319 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
320 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
321 }
322#endif
323#if defined(LINUX_PULSE)
324 }
325#endif
326 }
327 else if (audioLayer == kLinuxAlsaAudio)
328 {
329#if defined(LINUX_ALSA)
330 // create *Linux ALSA Audio* implementation
331 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
332 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
333#endif
334 }
335
336 if (ptrAudioDevice != NULL)
337 {
338 // Create the Linux implementation of the Device Utility.
339 // This class is independent of the selected audio layer
340 // for Linux.
341 //
342 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
343 }
344#endif // #if defined(WEBRTC_LINUX)
345
346 // Create the *iPhone* implementation of the Audio Device
347 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000348#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000349 if (audioLayer == kPlatformDefaultAudio)
350 {
351 // Create *iPhone Audio* implementation
352 ptrAudioDevice = new AudioDeviceIPhone(Id());
353 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
354 }
355
356 if (ptrAudioDevice != NULL)
357 {
358 // Create the Mac implementation of the Device Utility.
359 ptrAudioDeviceUtility = new AudioDeviceUtilityIPhone(Id());
360 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000361 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
363 // Create the *Mac* implementation of the Audio Device
364 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000365#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000366 if (audioLayer == kPlatformDefaultAudio)
367 {
368 // Create *Mac Audio* implementation
369 ptrAudioDevice = new AudioDeviceMac(Id());
370 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
371 }
372
373 if (ptrAudioDevice != NULL)
374 {
375 // Create the Mac implementation of the Device Utility.
376 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
377 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000378#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
380 // Create the *Dummy* implementation of the Audio Device
381 // Available for all platforms
382 //
383 if (audioLayer == kDummyAudio)
384 {
385 // Create *Dummy Audio* implementation
386 assert(!ptrAudioDevice);
387 ptrAudioDevice = new AudioDeviceDummy(Id());
388 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
389
390 if (ptrAudioDevice != NULL)
391 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000392 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000393 }
394 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000395#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000396
397 if (ptrAudioDevice == NULL)
398 {
399 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
400 return -1;
401 }
402
403 if (ptrAudioDeviceUtility == NULL)
404 {
405 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
406 return -1;
407 }
408
409 // Store valid output pointers
410 //
411 _ptrAudioDevice = ptrAudioDevice;
412 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
413
414 return 0;
415}
416
417// ----------------------------------------------------------------------------
418// AttachAudioBuffer
419//
420// Install "bridge" between the platform implemetation and the generic
421// implementation. The "child" shall set the native sampling rate and the
422// number of channels in this function call.
423// ----------------------------------------------------------------------------
424
pbos@webrtc.org25509882013-04-09 10:30:35 +0000425int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000426{
427 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
428
429 _audioDeviceBuffer.SetId(_id);
430 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
431 return 0;
432}
433
434// ----------------------------------------------------------------------------
435// ~AudioDeviceModuleImpl - dtor
436// ----------------------------------------------------------------------------
437
438AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
439{
440 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000441
442 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000443 {
henrika@google.com73d65512011-09-07 15:11:18 +0000444 delete _ptrAudioDevice;
445 _ptrAudioDevice = NULL;
446 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000447
henrika@google.com73d65512011-09-07 15:11:18 +0000448 if (_ptrAudioDeviceUtility)
449 {
450 delete _ptrAudioDeviceUtility;
451 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000452 }
453
454 delete &_critSect;
455 delete &_critSectEventCb;
456 delete &_critSectAudioCb;
457}
458
459// ============================================================================
460// Module
461// ============================================================================
462
463// ----------------------------------------------------------------------------
464// Module::ChangeUniqueId
465// ----------------------------------------------------------------------------
466
pbos@webrtc.org25509882013-04-09 10:30:35 +0000467int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
niklase@google.com470e71d2011-07-07 08:21:25 +0000468{
niklase@google.com470e71d2011-07-07 08:21:25 +0000469 _id = id;
470 return 0;
471}
472
473// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000474// Module::TimeUntilNextProcess
475//
476// Returns the number of milliseconds until the module want a worker thread
477// to call Process().
478// ----------------------------------------------------------------------------
479
pbos@webrtc.org25509882013-04-09 10:30:35 +0000480int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000481{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000482 uint32_t now = AudioDeviceUtility::GetTimeInMS();
483 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000484 return (deltaProcess);
485}
486
487// ----------------------------------------------------------------------------
488// Module::Process
489//
490// Check for posted error and warning reports. Generate callbacks if
491// new reports exists.
492// ----------------------------------------------------------------------------
493
pbos@webrtc.org25509882013-04-09 10:30:35 +0000494int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000495{
niklase@google.com470e71d2011-07-07 08:21:25 +0000496
497 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
498
499 // kPlayoutWarning
500 if (_ptrAudioDevice->PlayoutWarning())
501 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000502 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000503 if (_ptrCbAudioDeviceObserver)
504 {
505 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
506 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
507 }
508 _ptrAudioDevice->ClearPlayoutWarning();
509 }
510
511 // kPlayoutError
512 if (_ptrAudioDevice->PlayoutError())
513 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000514 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000515 if (_ptrCbAudioDeviceObserver)
516 {
517 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
518 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
519 }
520 _ptrAudioDevice->ClearPlayoutError();
521 }
522
523 // kRecordingWarning
524 if (_ptrAudioDevice->RecordingWarning())
525 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000526 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000527 if (_ptrCbAudioDeviceObserver)
528 {
529 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
530 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
531 }
532 _ptrAudioDevice->ClearRecordingWarning();
533 }
534
535 // kRecordingError
536 if (_ptrAudioDevice->RecordingError())
537 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000538 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000539 if (_ptrCbAudioDeviceObserver)
540 {
541 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
542 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
543 }
544 _ptrAudioDevice->ClearRecordingError();
545 }
546
547 return 0;
548}
549
550// ============================================================================
551// Public API
552// ============================================================================
553
554// ----------------------------------------------------------------------------
555// ActiveAudioLayer
556// ----------------------------------------------------------------------------
557
pbos@webrtc.org25509882013-04-09 10:30:35 +0000558int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000559{
niklase@google.com470e71d2011-07-07 08:21:25 +0000560
561 AudioLayer activeAudio;
562
563 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
564 {
565 return -1;
566 }
567
568 *audioLayer = activeAudio;
569
570 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
571 {
572 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
573 }
574 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
575 {
576 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
577 }
578 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
579 {
580 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
581 }
582 else
583 {
584 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
585 }
586
587 return 0;
588}
589
590// ----------------------------------------------------------------------------
591// LastError
592// ----------------------------------------------------------------------------
593
594AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
595{
596 return _lastError;
597}
598
599// ----------------------------------------------------------------------------
600// Init
601// ----------------------------------------------------------------------------
602
pbos@webrtc.org25509882013-04-09 10:30:35 +0000603int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000604{
niklase@google.com470e71d2011-07-07 08:21:25 +0000605
606 if (_initialized)
607 return 0;
608
609 if (!_ptrAudioDeviceUtility)
610 return -1;
611
612 if (!_ptrAudioDevice)
613 return -1;
614
615 _ptrAudioDeviceUtility->Init();
616
617 if (_ptrAudioDevice->Init() == -1)
618 {
619 return -1;
620 }
621
622 _initialized = true;
623 return 0;
624}
625
626// ----------------------------------------------------------------------------
627// Terminate
628// ----------------------------------------------------------------------------
629
pbos@webrtc.org25509882013-04-09 10:30:35 +0000630int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000631{
niklase@google.com470e71d2011-07-07 08:21:25 +0000632
633 if (!_initialized)
634 return 0;
635
636 if (_ptrAudioDevice->Terminate() == -1)
637 {
638 return -1;
639 }
640
641 _initialized = false;
642 return 0;
643}
644
645// ----------------------------------------------------------------------------
646// Initialized
647// ----------------------------------------------------------------------------
648
649bool AudioDeviceModuleImpl::Initialized() const
650{
niklase@google.com470e71d2011-07-07 08:21:25 +0000651
652 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
653 return (_initialized);
654}
655
656// ----------------------------------------------------------------------------
657// SpeakerIsAvailable
658// ----------------------------------------------------------------------------
659
pbos@webrtc.org25509882013-04-09 10:30:35 +0000660int32_t AudioDeviceModuleImpl::SpeakerIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000661{
niklase@google.com470e71d2011-07-07 08:21:25 +0000662 CHECK_INITIALIZED();
663
664 bool isAvailable(0);
665
666 if (_ptrAudioDevice->SpeakerIsAvailable(isAvailable) == -1)
667 {
668 return -1;
669 }
670
671 *available = isAvailable;
672
673 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", available);
674 return (0);
675}
676
677// ----------------------------------------------------------------------------
678// InitSpeaker
679// ----------------------------------------------------------------------------
680
pbos@webrtc.org25509882013-04-09 10:30:35 +0000681int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000682{
niklase@google.com470e71d2011-07-07 08:21:25 +0000683 CHECK_INITIALIZED();
684 return (_ptrAudioDevice->InitSpeaker());
685}
686
687// ----------------------------------------------------------------------------
688// MicrophoneIsAvailable
689// ----------------------------------------------------------------------------
690
pbos@webrtc.org25509882013-04-09 10:30:35 +0000691int32_t AudioDeviceModuleImpl::MicrophoneIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000692{
niklase@google.com470e71d2011-07-07 08:21:25 +0000693 CHECK_INITIALIZED();
694
695 bool isAvailable(0);
696
697 if (_ptrAudioDevice->MicrophoneIsAvailable(isAvailable) == -1)
698 {
699 return -1;
700 }
701
702 *available = isAvailable;
703
704 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
705 return (0);
706}
707
708// ----------------------------------------------------------------------------
709// InitMicrophone
710// ----------------------------------------------------------------------------
711
pbos@webrtc.org25509882013-04-09 10:30:35 +0000712int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000713{
niklase@google.com470e71d2011-07-07 08:21:25 +0000714 CHECK_INITIALIZED();
715 return (_ptrAudioDevice->InitMicrophone());
716}
717
718// ----------------------------------------------------------------------------
719// SpeakerVolumeIsAvailable
720// ----------------------------------------------------------------------------
721
pbos@webrtc.org25509882013-04-09 10:30:35 +0000722int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000723{
niklase@google.com470e71d2011-07-07 08:21:25 +0000724 CHECK_INITIALIZED();
725
726 bool isAvailable(0);
727
728 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
729 {
730 return -1;
731 }
732
733 *available = isAvailable;
734
735 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
736 return (0);
737}
738
739// ----------------------------------------------------------------------------
740// SetSpeakerVolume
741// ----------------------------------------------------------------------------
742
pbos@webrtc.org25509882013-04-09 10:30:35 +0000743int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000744{
niklase@google.com470e71d2011-07-07 08:21:25 +0000745 CHECK_INITIALIZED();
746 return (_ptrAudioDevice->SetSpeakerVolume(volume));
747}
748
749// ----------------------------------------------------------------------------
750// SpeakerVolume
751// ----------------------------------------------------------------------------
752
pbos@webrtc.org25509882013-04-09 10:30:35 +0000753int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000754{
niklase@google.com470e71d2011-07-07 08:21:25 +0000755 CHECK_INITIALIZED();
756
pbos@webrtc.org25509882013-04-09 10:30:35 +0000757 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000758
759 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
760 {
761 return -1;
762 }
763
764 *volume = level;
765
766 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
767 return (0);
768}
769
770// ----------------------------------------------------------------------------
771// SetWaveOutVolume
772// ----------------------------------------------------------------------------
773
pbos@webrtc.org25509882013-04-09 10:30:35 +0000774int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000775{
niklase@google.com470e71d2011-07-07 08:21:25 +0000776 CHECK_INITIALIZED();
777 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
778}
779
780// ----------------------------------------------------------------------------
781// WaveOutVolume
782// ----------------------------------------------------------------------------
783
pbos@webrtc.org25509882013-04-09 10:30:35 +0000784int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000785{
niklase@google.com470e71d2011-07-07 08:21:25 +0000786 CHECK_INITIALIZED();
787
pbos@webrtc.org25509882013-04-09 10:30:35 +0000788 uint16_t volLeft(0);
789 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000790
791 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
792 {
793 return -1;
794 }
795
796 *volumeLeft = volLeft;
797 *volumeRight = volRight;
798
799 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
800 *volumeLeft, *volumeRight);
801
802 return (0);
803}
804
805// ----------------------------------------------------------------------------
806// SpeakerIsInitialized
807// ----------------------------------------------------------------------------
808
809bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
810{
niklase@google.com470e71d2011-07-07 08:21:25 +0000811 CHECK_INITIALIZED_BOOL();
812
813 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
814
815 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
816 return (isInitialized);
817}
818
819// ----------------------------------------------------------------------------
820// MicrophoneIsInitialized
821// ----------------------------------------------------------------------------
822
823bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
824{
niklase@google.com470e71d2011-07-07 08:21:25 +0000825 CHECK_INITIALIZED_BOOL();
826
827 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
828
829 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
830 return (isInitialized);
831}
832
833// ----------------------------------------------------------------------------
834// MaxSpeakerVolume
835// ----------------------------------------------------------------------------
836
pbos@webrtc.org25509882013-04-09 10:30:35 +0000837int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000838{
niklase@google.com470e71d2011-07-07 08:21:25 +0000839 CHECK_INITIALIZED();
840
pbos@webrtc.org25509882013-04-09 10:30:35 +0000841 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000842
843 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
844 {
845 return -1;
846 }
847
848 *maxVolume = maxVol;
849
850 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
851 return (0);
852}
853
854// ----------------------------------------------------------------------------
855// MinSpeakerVolume
856// ----------------------------------------------------------------------------
857
pbos@webrtc.org25509882013-04-09 10:30:35 +0000858int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000859{
niklase@google.com470e71d2011-07-07 08:21:25 +0000860 CHECK_INITIALIZED();
861
pbos@webrtc.org25509882013-04-09 10:30:35 +0000862 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000863
864 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
865 {
866 return -1;
867 }
868
869 *minVolume = minVol;
870
871 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
872 return (0);
873}
874
875// ----------------------------------------------------------------------------
876// SpeakerVolumeStepSize
877// ----------------------------------------------------------------------------
878
pbos@webrtc.org25509882013-04-09 10:30:35 +0000879int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000880{
niklase@google.com470e71d2011-07-07 08:21:25 +0000881 CHECK_INITIALIZED();
882
pbos@webrtc.org25509882013-04-09 10:30:35 +0000883 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000884
885 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
886 {
887 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
888 return -1;
889 }
890
891 *stepSize = delta;
892
893 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
894 return (0);
895}
896
897// ----------------------------------------------------------------------------
898// SpeakerMuteIsAvailable
899// ----------------------------------------------------------------------------
900
pbos@webrtc.org25509882013-04-09 10:30:35 +0000901int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000902{
niklase@google.com470e71d2011-07-07 08:21:25 +0000903 CHECK_INITIALIZED();
904
905 bool isAvailable(0);
906
907 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
908 {
909 return -1;
910 }
911
912 *available = isAvailable;
913
914 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
915 return (0);
916}
917
918// ----------------------------------------------------------------------------
919// SetSpeakerMute
920// ----------------------------------------------------------------------------
921
pbos@webrtc.org25509882013-04-09 10:30:35 +0000922int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000923{
niklase@google.com470e71d2011-07-07 08:21:25 +0000924 CHECK_INITIALIZED();
925 return (_ptrAudioDevice->SetSpeakerMute(enable));
926}
927
928// ----------------------------------------------------------------------------
929// SpeakerMute
930// ----------------------------------------------------------------------------
931
pbos@webrtc.org25509882013-04-09 10:30:35 +0000932int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000933{
niklase@google.com470e71d2011-07-07 08:21:25 +0000934 CHECK_INITIALIZED();
935
936 bool muted(false);
937
938 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
939 {
940 return -1;
941 }
942
943 *enabled = muted;
944
945 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
946 return (0);
947}
948
949// ----------------------------------------------------------------------------
950// MicrophoneMuteIsAvailable
951// ----------------------------------------------------------------------------
952
pbos@webrtc.org25509882013-04-09 10:30:35 +0000953int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000954{
niklase@google.com470e71d2011-07-07 08:21:25 +0000955 CHECK_INITIALIZED();
956
957 bool isAvailable(0);
958
959 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
960 {
961 return -1;
962 }
963
964 *available = isAvailable;
965
966 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
967 return (0);
968}
969
970// ----------------------------------------------------------------------------
971// SetMicrophoneMute
972// ----------------------------------------------------------------------------
973
pbos@webrtc.org25509882013-04-09 10:30:35 +0000974int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000975{
niklase@google.com470e71d2011-07-07 08:21:25 +0000976 CHECK_INITIALIZED();
977 return (_ptrAudioDevice->SetMicrophoneMute(enable));
978}
979
980// ----------------------------------------------------------------------------
981// MicrophoneMute
982// ----------------------------------------------------------------------------
983
pbos@webrtc.org25509882013-04-09 10:30:35 +0000984int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000985{
niklase@google.com470e71d2011-07-07 08:21:25 +0000986 CHECK_INITIALIZED();
987
988 bool muted(false);
989
990 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
991 {
992 return -1;
993 }
994
995 *enabled = muted;
996
997 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
998 return (0);
999}
1000
1001// ----------------------------------------------------------------------------
1002// MicrophoneBoostIsAvailable
1003// ----------------------------------------------------------------------------
1004
pbos@webrtc.org25509882013-04-09 10:30:35 +00001005int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001006{
niklase@google.com470e71d2011-07-07 08:21:25 +00001007 CHECK_INITIALIZED();
1008
1009 bool isAvailable(0);
1010
1011 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
1012 {
1013 return -1;
1014 }
1015
1016 *available = isAvailable;
1017
1018 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1019 return (0);
1020}
1021
1022// ----------------------------------------------------------------------------
1023// SetMicrophoneBoost
1024// ----------------------------------------------------------------------------
1025
pbos@webrtc.org25509882013-04-09 10:30:35 +00001026int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001027{
niklase@google.com470e71d2011-07-07 08:21:25 +00001028 CHECK_INITIALIZED();
1029 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
1030}
1031
1032// ----------------------------------------------------------------------------
1033// MicrophoneBoost
1034// ----------------------------------------------------------------------------
1035
pbos@webrtc.org25509882013-04-09 10:30:35 +00001036int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001037{
niklase@google.com470e71d2011-07-07 08:21:25 +00001038 CHECK_INITIALIZED();
1039
1040 bool onOff(false);
1041
1042 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
1043 {
1044 return -1;
1045 }
1046
1047 *enabled = onOff;
1048
1049 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1050 return (0);
1051}
1052
1053// ----------------------------------------------------------------------------
1054// MicrophoneVolumeIsAvailable
1055// ----------------------------------------------------------------------------
1056
pbos@webrtc.org25509882013-04-09 10:30:35 +00001057int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001058{
niklase@google.com470e71d2011-07-07 08:21:25 +00001059 CHECK_INITIALIZED();
1060
1061 bool isAvailable(0);
1062
1063 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1064 {
1065 return -1;
1066 }
1067
1068 *available = isAvailable;
1069
1070 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1071 return (0);
1072}
1073
1074// ----------------------------------------------------------------------------
1075// SetMicrophoneVolume
1076// ----------------------------------------------------------------------------
1077
pbos@webrtc.org25509882013-04-09 10:30:35 +00001078int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001079{
niklase@google.com470e71d2011-07-07 08:21:25 +00001080 CHECK_INITIALIZED();
1081 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1082}
1083
1084// ----------------------------------------------------------------------------
1085// MicrophoneVolume
1086// ----------------------------------------------------------------------------
1087
pbos@webrtc.org25509882013-04-09 10:30:35 +00001088int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001089{
1090 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1091 CHECK_INITIALIZED();
1092
pbos@webrtc.org25509882013-04-09 10:30:35 +00001093 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001094
1095 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1096 {
1097 return -1;
1098 }
1099
1100 *volume = level;
1101
1102 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1103 return (0);
1104}
1105
1106// ----------------------------------------------------------------------------
1107// StereoRecordingIsAvailable
1108// ----------------------------------------------------------------------------
1109
pbos@webrtc.org25509882013-04-09 10:30:35 +00001110int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001111{
niklase@google.com470e71d2011-07-07 08:21:25 +00001112 CHECK_INITIALIZED();
1113
1114 bool isAvailable(0);
1115
1116 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1117 {
1118 return -1;
1119 }
1120
1121 *available = isAvailable;
1122
1123 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1124 return (0);
1125}
1126
1127// ----------------------------------------------------------------------------
1128// SetStereoRecording
1129// ----------------------------------------------------------------------------
1130
pbos@webrtc.org25509882013-04-09 10:30:35 +00001131int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001132{
niklase@google.com470e71d2011-07-07 08:21:25 +00001133 CHECK_INITIALIZED();
1134
1135 if (_ptrAudioDevice->RecordingIsInitialized())
1136 {
1137 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1138 return -1;
1139 }
1140
1141 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1142 {
1143 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1144 return -1;
1145 }
1146
pbos@webrtc.org25509882013-04-09 10:30:35 +00001147 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001148 if (enable)
1149 {
1150 nChannels = 2;
1151 }
1152 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1153
1154 return 0;
1155}
1156
1157// ----------------------------------------------------------------------------
1158// StereoRecording
1159// ----------------------------------------------------------------------------
1160
pbos@webrtc.org25509882013-04-09 10:30:35 +00001161int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001162{
niklase@google.com470e71d2011-07-07 08:21:25 +00001163 CHECK_INITIALIZED();
1164
1165 bool stereo(false);
1166
1167 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1168 {
1169 return -1;
1170 }
1171
1172 *enabled = stereo;
1173
1174 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1175 return (0);
1176}
1177
1178// ----------------------------------------------------------------------------
1179// SetRecordingChannel
1180// ----------------------------------------------------------------------------
1181
pbos@webrtc.org25509882013-04-09 10:30:35 +00001182int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001183{
1184 if (channel == kChannelBoth)
1185 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001186 }
1187 else if (channel == kChannelLeft)
1188 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001189 }
1190 else
1191 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001192 }
1193 CHECK_INITIALIZED();
1194
1195 bool stereo(false);
1196
1197 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1198 {
1199 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1200 return -1;
1201 }
1202
1203 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1204}
1205
1206// ----------------------------------------------------------------------------
1207// RecordingChannel
1208// ----------------------------------------------------------------------------
1209
pbos@webrtc.org25509882013-04-09 10:30:35 +00001210int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001211{
niklase@google.com470e71d2011-07-07 08:21:25 +00001212 CHECK_INITIALIZED();
1213
1214 ChannelType chType;
1215
1216 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1217 {
1218 return -1;
1219 }
1220
1221 *channel = chType;
1222
1223 if (*channel == kChannelBoth)
1224 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001225 }
1226 else if (*channel == kChannelLeft)
1227 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001228 }
1229 else
1230 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001231 }
1232
1233 return (0);
1234}
1235
1236// ----------------------------------------------------------------------------
1237// StereoPlayoutIsAvailable
1238// ----------------------------------------------------------------------------
1239
pbos@webrtc.org25509882013-04-09 10:30:35 +00001240int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001241{
niklase@google.com470e71d2011-07-07 08:21:25 +00001242 CHECK_INITIALIZED();
1243
1244 bool isAvailable(0);
1245
1246 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1247 {
1248 return -1;
1249 }
1250
1251 *available = isAvailable;
1252
1253 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1254 return (0);
1255}
1256
1257// ----------------------------------------------------------------------------
1258// SetStereoPlayout
1259// ----------------------------------------------------------------------------
1260
pbos@webrtc.org25509882013-04-09 10:30:35 +00001261int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001262{
niklase@google.com470e71d2011-07-07 08:21:25 +00001263 CHECK_INITIALIZED();
1264
1265 if (_ptrAudioDevice->PlayoutIsInitialized())
1266 {
1267 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1268 return -1;
1269 }
1270
1271 if (_ptrAudioDevice->SetStereoPlayout(enable))
1272 {
1273 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1274 return -1;
1275 }
1276
pbos@webrtc.org25509882013-04-09 10:30:35 +00001277 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001278 if (enable)
1279 {
1280 nChannels = 2;
1281 }
1282 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1283
1284 return 0;
1285}
1286
1287// ----------------------------------------------------------------------------
1288// StereoPlayout
1289// ----------------------------------------------------------------------------
1290
pbos@webrtc.org25509882013-04-09 10:30:35 +00001291int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001292{
niklase@google.com470e71d2011-07-07 08:21:25 +00001293 CHECK_INITIALIZED();
1294
1295 bool stereo(false);
1296
1297 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1298 {
1299 return -1;
1300 }
1301
1302 *enabled = stereo;
1303
1304 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1305 return (0);
1306}
1307
1308// ----------------------------------------------------------------------------
1309// SetAGC
1310// ----------------------------------------------------------------------------
1311
pbos@webrtc.org25509882013-04-09 10:30:35 +00001312int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001313{
niklase@google.com470e71d2011-07-07 08:21:25 +00001314 CHECK_INITIALIZED();
1315 return (_ptrAudioDevice->SetAGC(enable));
1316}
1317
1318// ----------------------------------------------------------------------------
1319// AGC
1320// ----------------------------------------------------------------------------
1321
1322bool AudioDeviceModuleImpl::AGC() const
1323{
niklase@google.com470e71d2011-07-07 08:21:25 +00001324 CHECK_INITIALIZED_BOOL();
1325 return (_ptrAudioDevice->AGC());
1326}
1327
1328// ----------------------------------------------------------------------------
1329// PlayoutIsAvailable
1330// ----------------------------------------------------------------------------
1331
pbos@webrtc.org25509882013-04-09 10:30:35 +00001332int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001333{
niklase@google.com470e71d2011-07-07 08:21:25 +00001334 CHECK_INITIALIZED();
1335
1336 bool isAvailable(0);
1337
1338 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1339 {
1340 return -1;
1341 }
1342
1343 *available = isAvailable;
1344
1345 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1346 return (0);
1347}
1348
1349// ----------------------------------------------------------------------------
1350// RecordingIsAvailable
1351// ----------------------------------------------------------------------------
1352
pbos@webrtc.org25509882013-04-09 10:30:35 +00001353int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001354{
niklase@google.com470e71d2011-07-07 08:21:25 +00001355 CHECK_INITIALIZED();
1356
1357 bool isAvailable(0);
1358
1359 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1360 {
1361 return -1;
1362 }
1363
1364 *available = isAvailable;
1365
1366 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1367 return (0);
1368}
1369
1370// ----------------------------------------------------------------------------
1371// MaxMicrophoneVolume
1372// ----------------------------------------------------------------------------
1373
pbos@webrtc.org25509882013-04-09 10:30:35 +00001374int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001375{
1376 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1377 CHECK_INITIALIZED();
1378
pbos@webrtc.org25509882013-04-09 10:30:35 +00001379 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001380
1381 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1382 {
1383 return -1;
1384 }
1385
1386 *maxVolume = maxVol;
1387
1388 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1389 return (0);
1390}
1391
1392// ----------------------------------------------------------------------------
1393// MinMicrophoneVolume
1394// ----------------------------------------------------------------------------
1395
pbos@webrtc.org25509882013-04-09 10:30:35 +00001396int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001397{
niklase@google.com470e71d2011-07-07 08:21:25 +00001398 CHECK_INITIALIZED();
1399
pbos@webrtc.org25509882013-04-09 10:30:35 +00001400 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001401
1402 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1403 {
1404 return -1;
1405 }
1406
1407 *minVolume = minVol;
1408
1409 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1410 return (0);
1411}
1412
1413// ----------------------------------------------------------------------------
1414// MicrophoneVolumeStepSize
1415// ----------------------------------------------------------------------------
1416
pbos@webrtc.org25509882013-04-09 10:30:35 +00001417int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001418{
niklase@google.com470e71d2011-07-07 08:21:25 +00001419 CHECK_INITIALIZED();
1420
pbos@webrtc.org25509882013-04-09 10:30:35 +00001421 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001422
1423 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1424 {
1425 return -1;
1426 }
1427
1428 *stepSize = delta;
1429
1430 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1431 return (0);
1432}
1433
1434// ----------------------------------------------------------------------------
1435// PlayoutDevices
1436// ----------------------------------------------------------------------------
1437
pbos@webrtc.org25509882013-04-09 10:30:35 +00001438int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001439{
niklase@google.com470e71d2011-07-07 08:21:25 +00001440 CHECK_INITIALIZED();
1441
pbos@webrtc.org25509882013-04-09 10:30:35 +00001442 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001443
1444 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001445 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001446}
1447
1448// ----------------------------------------------------------------------------
1449// SetPlayoutDevice I (II)
1450// ----------------------------------------------------------------------------
1451
pbos@webrtc.org25509882013-04-09 10:30:35 +00001452int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001453{
niklase@google.com470e71d2011-07-07 08:21:25 +00001454 CHECK_INITIALIZED();
1455 return (_ptrAudioDevice->SetPlayoutDevice(index));
1456}
1457
1458// ----------------------------------------------------------------------------
1459// SetPlayoutDevice II (II)
1460// ----------------------------------------------------------------------------
1461
pbos@webrtc.org25509882013-04-09 10:30:35 +00001462int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001463{
1464 if (device == kDefaultDevice)
1465 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001466 }
1467 else
1468 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001469 }
1470 CHECK_INITIALIZED();
1471
1472 return (_ptrAudioDevice->SetPlayoutDevice(device));
1473}
1474
1475// ----------------------------------------------------------------------------
1476// PlayoutDeviceName
1477// ----------------------------------------------------------------------------
1478
pbos@webrtc.org25509882013-04-09 10:30:35 +00001479int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1480 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001481 char name[kAdmMaxDeviceNameSize],
1482 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001483{
niklase@google.com470e71d2011-07-07 08:21:25 +00001484 CHECK_INITIALIZED();
1485
1486 if (name == NULL)
1487 {
1488 _lastError = kAdmErrArgument;
1489 return -1;
1490 }
1491
1492 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1493 {
1494 return -1;
1495 }
1496
1497 if (name != NULL)
1498 {
1499 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1500 }
1501 if (guid != NULL)
1502 {
1503 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1504 }
1505
1506 return (0);
1507}
1508
1509// ----------------------------------------------------------------------------
1510// RecordingDeviceName
1511// ----------------------------------------------------------------------------
1512
pbos@webrtc.org25509882013-04-09 10:30:35 +00001513int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1514 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001515 char name[kAdmMaxDeviceNameSize],
1516 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001517{
niklase@google.com470e71d2011-07-07 08:21:25 +00001518 CHECK_INITIALIZED();
1519
1520 if (name == NULL)
1521 {
1522 _lastError = kAdmErrArgument;
1523 return -1;
1524 }
1525
1526 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1527 {
1528 return -1;
1529 }
1530
1531 if (name != NULL)
1532 {
1533 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1534 }
1535 if (guid != NULL)
1536 {
1537 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1538 }
1539
1540 return (0);
1541}
1542
1543// ----------------------------------------------------------------------------
1544// RecordingDevices
1545// ----------------------------------------------------------------------------
1546
pbos@webrtc.org25509882013-04-09 10:30:35 +00001547int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001548{
niklase@google.com470e71d2011-07-07 08:21:25 +00001549 CHECK_INITIALIZED();
1550
pbos@webrtc.org25509882013-04-09 10:30:35 +00001551 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001552
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001553 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1554 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001555 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001556}
1557
1558// ----------------------------------------------------------------------------
1559// SetRecordingDevice I (II)
1560// ----------------------------------------------------------------------------
1561
pbos@webrtc.org25509882013-04-09 10:30:35 +00001562int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001563{
niklase@google.com470e71d2011-07-07 08:21:25 +00001564 CHECK_INITIALIZED();
1565 return (_ptrAudioDevice->SetRecordingDevice(index));
1566}
1567
1568// ----------------------------------------------------------------------------
1569// SetRecordingDevice II (II)
1570// ----------------------------------------------------------------------------
1571
pbos@webrtc.org25509882013-04-09 10:30:35 +00001572int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001573{
1574 if (device == kDefaultDevice)
1575 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001576 }
1577 else
1578 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001579 }
1580 CHECK_INITIALIZED();
1581
1582 return (_ptrAudioDevice->SetRecordingDevice(device));
1583}
1584
1585// ----------------------------------------------------------------------------
1586// InitPlayout
1587// ----------------------------------------------------------------------------
1588
pbos@webrtc.org25509882013-04-09 10:30:35 +00001589int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001590{
niklase@google.com470e71d2011-07-07 08:21:25 +00001591 CHECK_INITIALIZED();
1592 _audioDeviceBuffer.InitPlayout();
1593 return (_ptrAudioDevice->InitPlayout());
1594}
1595
1596// ----------------------------------------------------------------------------
1597// InitRecording
1598// ----------------------------------------------------------------------------
1599
pbos@webrtc.org25509882013-04-09 10:30:35 +00001600int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001601{
niklase@google.com470e71d2011-07-07 08:21:25 +00001602 CHECK_INITIALIZED();
1603 _audioDeviceBuffer.InitRecording();
1604 return (_ptrAudioDevice->InitRecording());
1605}
1606
1607// ----------------------------------------------------------------------------
1608// PlayoutIsInitialized
1609// ----------------------------------------------------------------------------
1610
1611bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1612{
niklase@google.com470e71d2011-07-07 08:21:25 +00001613 CHECK_INITIALIZED_BOOL();
1614 return (_ptrAudioDevice->PlayoutIsInitialized());
1615}
1616
1617// ----------------------------------------------------------------------------
1618// RecordingIsInitialized
1619// ----------------------------------------------------------------------------
1620
1621bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1622{
niklase@google.com470e71d2011-07-07 08:21:25 +00001623 CHECK_INITIALIZED_BOOL();
1624 return (_ptrAudioDevice->RecordingIsInitialized());
1625}
1626
1627// ----------------------------------------------------------------------------
1628// StartPlayout
1629// ----------------------------------------------------------------------------
1630
pbos@webrtc.org25509882013-04-09 10:30:35 +00001631int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001632{
niklase@google.com470e71d2011-07-07 08:21:25 +00001633 CHECK_INITIALIZED();
1634 return (_ptrAudioDevice->StartPlayout());
1635}
1636
1637// ----------------------------------------------------------------------------
1638// StopPlayout
1639// ----------------------------------------------------------------------------
1640
pbos@webrtc.org25509882013-04-09 10:30:35 +00001641int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001642{
niklase@google.com470e71d2011-07-07 08:21:25 +00001643 CHECK_INITIALIZED();
1644 return (_ptrAudioDevice->StopPlayout());
1645}
1646
1647// ----------------------------------------------------------------------------
1648// Playing
1649// ----------------------------------------------------------------------------
1650
1651bool AudioDeviceModuleImpl::Playing() const
1652{
niklase@google.com470e71d2011-07-07 08:21:25 +00001653 CHECK_INITIALIZED_BOOL();
1654 return (_ptrAudioDevice->Playing());
1655}
1656
1657// ----------------------------------------------------------------------------
1658// StartRecording
1659// ----------------------------------------------------------------------------
1660
pbos@webrtc.org25509882013-04-09 10:30:35 +00001661int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001662{
niklase@google.com470e71d2011-07-07 08:21:25 +00001663 CHECK_INITIALIZED();
1664 return (_ptrAudioDevice->StartRecording());
1665}
1666// ----------------------------------------------------------------------------
1667// StopRecording
1668// ----------------------------------------------------------------------------
1669
pbos@webrtc.org25509882013-04-09 10:30:35 +00001670int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001671{
niklase@google.com470e71d2011-07-07 08:21:25 +00001672 CHECK_INITIALIZED();
1673 return (_ptrAudioDevice->StopRecording());
1674}
1675
1676// ----------------------------------------------------------------------------
1677// Recording
1678// ----------------------------------------------------------------------------
1679
1680bool AudioDeviceModuleImpl::Recording() const
1681{
niklase@google.com470e71d2011-07-07 08:21:25 +00001682 CHECK_INITIALIZED_BOOL();
1683 return (_ptrAudioDevice->Recording());
1684}
1685
1686// ----------------------------------------------------------------------------
1687// RegisterEventObserver
1688// ----------------------------------------------------------------------------
1689
pbos@webrtc.org25509882013-04-09 10:30:35 +00001690int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001691{
niklase@google.com470e71d2011-07-07 08:21:25 +00001692
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001693 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001694 _ptrCbAudioDeviceObserver = eventCallback;
1695
1696 return 0;
1697}
1698
1699// ----------------------------------------------------------------------------
1700// RegisterAudioCallback
1701// ----------------------------------------------------------------------------
1702
pbos@webrtc.org25509882013-04-09 10:30:35 +00001703int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001704{
niklase@google.com470e71d2011-07-07 08:21:25 +00001705
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001706 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001707 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1708
1709 return 0;
1710}
1711
1712// ----------------------------------------------------------------------------
1713// StartRawInputFileRecording
1714// ----------------------------------------------------------------------------
1715
pbos@webrtc.org25509882013-04-09 10:30:35 +00001716int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001717 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001718{
niklase@google.com470e71d2011-07-07 08:21:25 +00001719 CHECK_INITIALIZED();
1720
1721 if (NULL == pcmFileNameUTF8)
1722 {
1723 return -1;
1724 }
1725
1726 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1727}
1728
1729// ----------------------------------------------------------------------------
1730// StopRawInputFileRecording
1731// ----------------------------------------------------------------------------
1732
pbos@webrtc.org25509882013-04-09 10:30:35 +00001733int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001734{
niklase@google.com470e71d2011-07-07 08:21:25 +00001735 CHECK_INITIALIZED();
1736
1737 return (_audioDeviceBuffer.StopInputFileRecording());
1738}
1739
1740// ----------------------------------------------------------------------------
1741// StartRawOutputFileRecording
1742// ----------------------------------------------------------------------------
1743
pbos@webrtc.org25509882013-04-09 10:30:35 +00001744int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001745 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001746{
niklase@google.com470e71d2011-07-07 08:21:25 +00001747 CHECK_INITIALIZED();
1748
1749 if (NULL == pcmFileNameUTF8)
1750 {
1751 return -1;
1752 }
1753
1754 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1755}
1756
1757// ----------------------------------------------------------------------------
1758// StopRawOutputFileRecording
1759// ----------------------------------------------------------------------------
1760
pbos@webrtc.org25509882013-04-09 10:30:35 +00001761int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001762{
niklase@google.com470e71d2011-07-07 08:21:25 +00001763 CHECK_INITIALIZED();
1764
1765 return (_audioDeviceBuffer.StopOutputFileRecording());
1766
1767 return 0;
1768}
1769
1770// ----------------------------------------------------------------------------
1771// SetPlayoutBuffer
1772// ----------------------------------------------------------------------------
1773
pbos@webrtc.org25509882013-04-09 10:30:35 +00001774int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001775{
niklase@google.com470e71d2011-07-07 08:21:25 +00001776 CHECK_INITIALIZED();
1777
1778 if (_ptrAudioDevice->PlayoutIsInitialized())
1779 {
1780 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1781 return -1;
1782 }
1783
pbos@webrtc.org25509882013-04-09 10:30:35 +00001784 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001785
1786 if (kFixedBufferSize == type)
1787 {
1788 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1789 {
1790 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1791 return -1;
1792 }
1793 }
1794
1795 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1796 {
1797 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1798 }
1799
1800 return ret;
1801}
1802
1803// ----------------------------------------------------------------------------
1804// PlayoutBuffer
1805// ----------------------------------------------------------------------------
1806
pbos@webrtc.org25509882013-04-09 10:30:35 +00001807int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001808{
niklase@google.com470e71d2011-07-07 08:21:25 +00001809 CHECK_INITIALIZED();
1810
1811 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001812 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001813
1814 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1815 {
1816 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1817 return -1;
1818 }
1819
1820 *type = bufType;
1821 *sizeMS = size;
1822
1823 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1824 return (0);
1825}
1826
1827// ----------------------------------------------------------------------------
1828// PlayoutDelay
1829// ----------------------------------------------------------------------------
1830
pbos@webrtc.org25509882013-04-09 10:30:35 +00001831int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001832{
1833 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1834 CHECK_INITIALIZED();
1835
pbos@webrtc.org25509882013-04-09 10:30:35 +00001836 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001837
1838 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1839 {
1840 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1841 return -1;
1842 }
1843
1844 *delayMS = delay;
1845
1846 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1847 return (0);
1848}
1849
1850// ----------------------------------------------------------------------------
1851// RecordingDelay
1852// ----------------------------------------------------------------------------
1853
pbos@webrtc.org25509882013-04-09 10:30:35 +00001854int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001855{
1856 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1857 CHECK_INITIALIZED();
1858
pbos@webrtc.org25509882013-04-09 10:30:35 +00001859 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001860
1861 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1862 {
1863 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1864 return -1;
1865 }
1866
1867 *delayMS = delay;
1868
1869 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1870 return (0);
1871}
1872
1873// ----------------------------------------------------------------------------
1874// CPULoad
1875// ----------------------------------------------------------------------------
1876
pbos@webrtc.org25509882013-04-09 10:30:35 +00001877int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001878{
niklase@google.com470e71d2011-07-07 08:21:25 +00001879 CHECK_INITIALIZED();
1880
pbos@webrtc.org25509882013-04-09 10:30:35 +00001881 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001882
1883 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1884 {
1885 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1886 return -1;
1887 }
1888
1889 *load = cpuLoad;
1890
1891 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1892 return (0);
1893}
1894
1895// ----------------------------------------------------------------------------
1896// SetRecordingSampleRate
1897// ----------------------------------------------------------------------------
1898
pbos@webrtc.org25509882013-04-09 10:30:35 +00001899int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001900{
niklase@google.com470e71d2011-07-07 08:21:25 +00001901 CHECK_INITIALIZED();
1902
1903 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1904 {
1905 return -1;
1906 }
1907
1908 return (0);
1909}
1910
1911// ----------------------------------------------------------------------------
1912// RecordingSampleRate
1913// ----------------------------------------------------------------------------
1914
pbos@webrtc.org25509882013-04-09 10:30:35 +00001915int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001916{
niklase@google.com470e71d2011-07-07 08:21:25 +00001917 CHECK_INITIALIZED();
1918
pbos@webrtc.org25509882013-04-09 10:30:35 +00001919 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001920
1921 if (sampleRate == -1)
1922 {
1923 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1924 return -1;
1925 }
1926
1927 *samplesPerSec = sampleRate;
1928
1929 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1930 return (0);
1931}
1932
1933// ----------------------------------------------------------------------------
1934// SetPlayoutSampleRate
1935// ----------------------------------------------------------------------------
1936
pbos@webrtc.org25509882013-04-09 10:30:35 +00001937int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001938{
niklase@google.com470e71d2011-07-07 08:21:25 +00001939 CHECK_INITIALIZED();
1940
1941 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1942 {
1943 return -1;
1944 }
1945
1946 return (0);
1947}
1948
1949// ----------------------------------------------------------------------------
1950// PlayoutSampleRate
1951// ----------------------------------------------------------------------------
1952
pbos@webrtc.org25509882013-04-09 10:30:35 +00001953int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001954{
niklase@google.com470e71d2011-07-07 08:21:25 +00001955 CHECK_INITIALIZED();
1956
pbos@webrtc.org25509882013-04-09 10:30:35 +00001957 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001958
1959 if (sampleRate == -1)
1960 {
1961 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1962 return -1;
1963 }
1964
1965 *samplesPerSec = sampleRate;
1966
1967 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1968 return (0);
1969}
1970
1971// ----------------------------------------------------------------------------
1972// ResetAudioDevice
1973// ----------------------------------------------------------------------------
1974
pbos@webrtc.org25509882013-04-09 10:30:35 +00001975int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001976{
niklase@google.com470e71d2011-07-07 08:21:25 +00001977 CHECK_INITIALIZED();
1978
1979
1980 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1981 {
1982 return -1;
1983 }
1984
1985 return (0);
1986}
1987
1988// ----------------------------------------------------------------------------
1989// SetLoudspeakerStatus
1990// ----------------------------------------------------------------------------
1991
pbos@webrtc.org25509882013-04-09 10:30:35 +00001992int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001993{
niklase@google.com470e71d2011-07-07 08:21:25 +00001994 CHECK_INITIALIZED();
1995
1996 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1997 {
1998 return -1;
1999 }
2000
2001 return 0;
2002}
2003
2004// ----------------------------------------------------------------------------
2005// GetLoudspeakerStatus
2006// ----------------------------------------------------------------------------
2007
pbos@webrtc.org25509882013-04-09 10:30:35 +00002008int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00002009{
niklase@google.com470e71d2011-07-07 08:21:25 +00002010 CHECK_INITIALIZED();
2011
2012 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
2013 {
2014 return -1;
2015 }
2016
2017 return 0;
2018}
2019
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00002020int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
2021{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00002022 CHECK_INITIALIZED();
2023
2024 return _ptrAudioDevice->EnableBuiltInAEC(enable);
2025}
2026
2027bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
2028{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00002029 CHECK_INITIALIZED_BOOL();
2030
2031 return _ptrAudioDevice->BuiltInAECIsEnabled();
2032}
2033
niklase@google.com470e71d2011-07-07 08:21:25 +00002034// ============================================================================
2035// Private Methods
2036// ============================================================================
2037
2038// ----------------------------------------------------------------------------
2039// Platform
2040// ----------------------------------------------------------------------------
2041
2042AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
2043{
2044 return _platformType;
2045}
2046
2047// ----------------------------------------------------------------------------
2048// PlatformAudioLayer
2049// ----------------------------------------------------------------------------
2050
2051AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2052{
niklase@google.com470e71d2011-07-07 08:21:25 +00002053
2054 switch (_platformAudioLayer)
2055 {
2056 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002057 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2058 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002059 break;
2060 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002061 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2062 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002063 break;
2064 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002065 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2066 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002067 break;
2068 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002069 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2070 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002071 break;
2072 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002073 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2074 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002075 break;
2076 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002077 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2078 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002079 break;
2080 }
2081
2082 return _platformAudioLayer;
2083}
2084
2085} // namespace webrtc