blob: a2e5cba7813000441eefda01e7504724a0e5c353 [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)
niklase@google.com470e71d2011-07-07 08:21:25 +000026 #include <stdlib.h>
27 #include "audio_device_utility_android.h"
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +000028 #include "webrtc/modules/audio_device/android/audio_device_template.h"
29 #include "webrtc/modules/audio_device/android/audio_record_jni.h"
30 #include "webrtc/modules/audio_device/android/audio_track_jni.h"
31 #include "webrtc/modules/audio_device/android/opensles_input.h"
32 #include "webrtc/modules/audio_device/android/opensles_output.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 //
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000261#if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000262 if (audioLayer == kPlatformDefaultAudio)
263 {
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000264 // AudioRecordJni provides hardware AEC and OpenSlesOutput low latency.
265#if defined(WEBRTC_ANDROID_OPENSLES)
266 ptrAudioDevice = new AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>(Id());
267#else
268 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(Id());
269#endif
leozwang@google.com39f20512011-07-15 16:29:40 +0000270 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
271 "Android OpenSLES Audio APIs will be utilized");
niklase@google.com470e71d2011-07-07 08:21:25 +0000272 }
273
274 if (ptrAudioDevice != NULL)
275 {
276 // Create the Android implementation of the Device Utility.
277 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
278 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000279 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
281 // Create the *Linux* implementation of the Audio Device
282 //
283#elif defined(WEBRTC_LINUX)
284 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
285 {
286#if defined(LINUX_PULSE)
287 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
288
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000289 // create *Linux PulseAudio* implementation
290 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
291 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000292 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000293 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000294 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
295 }
296 else
297 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000298 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000299#endif
300#if defined(LINUX_ALSA)
301 // create *Linux ALSA Audio* implementation
302 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
303 if (ptrAudioDevice != NULL)
304 {
305 // Pulse Audio was not supported => revert to ALSA instead
306 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
307 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
308 }
309#endif
310#if defined(LINUX_PULSE)
311 }
312#endif
313 }
314 else if (audioLayer == kLinuxAlsaAudio)
315 {
316#if defined(LINUX_ALSA)
317 // create *Linux ALSA Audio* implementation
318 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
319 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
320#endif
321 }
322
323 if (ptrAudioDevice != NULL)
324 {
325 // Create the Linux implementation of the Device Utility.
326 // This class is independent of the selected audio layer
327 // for Linux.
328 //
329 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
330 }
331#endif // #if defined(WEBRTC_LINUX)
332
333 // Create the *iPhone* implementation of the Audio Device
334 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000335#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000336 if (audioLayer == kPlatformDefaultAudio)
337 {
338 // Create *iPhone Audio* implementation
339 ptrAudioDevice = new AudioDeviceIPhone(Id());
340 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
341 }
342
343 if (ptrAudioDevice != NULL)
344 {
345 // Create the Mac implementation of the Device Utility.
346 ptrAudioDeviceUtility = new AudioDeviceUtilityIPhone(Id());
347 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000348 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000349
350 // Create the *Mac* implementation of the Audio Device
351 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000352#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 if (audioLayer == kPlatformDefaultAudio)
354 {
355 // Create *Mac Audio* implementation
356 ptrAudioDevice = new AudioDeviceMac(Id());
357 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
358 }
359
360 if (ptrAudioDevice != NULL)
361 {
362 // Create the Mac implementation of the Device Utility.
363 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
364 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000365#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
367 // Create the *Dummy* implementation of the Audio Device
368 // Available for all platforms
369 //
370 if (audioLayer == kDummyAudio)
371 {
372 // Create *Dummy Audio* implementation
373 assert(!ptrAudioDevice);
374 ptrAudioDevice = new AudioDeviceDummy(Id());
375 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
376
377 if (ptrAudioDevice != NULL)
378 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000379 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000380 }
381 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000382#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
384 if (ptrAudioDevice == NULL)
385 {
386 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
387 return -1;
388 }
389
390 if (ptrAudioDeviceUtility == NULL)
391 {
392 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
393 return -1;
394 }
395
396 // Store valid output pointers
397 //
398 _ptrAudioDevice = ptrAudioDevice;
399 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
400
401 return 0;
402}
403
404// ----------------------------------------------------------------------------
405// AttachAudioBuffer
406//
407// Install "bridge" between the platform implemetation and the generic
408// implementation. The "child" shall set the native sampling rate and the
409// number of channels in this function call.
410// ----------------------------------------------------------------------------
411
pbos@webrtc.org25509882013-04-09 10:30:35 +0000412int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000413{
414 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
415
416 _audioDeviceBuffer.SetId(_id);
417 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
418 return 0;
419}
420
421// ----------------------------------------------------------------------------
422// ~AudioDeviceModuleImpl - dtor
423// ----------------------------------------------------------------------------
424
425AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
426{
427 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000428
429 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 {
henrika@google.com73d65512011-09-07 15:11:18 +0000431 delete _ptrAudioDevice;
432 _ptrAudioDevice = NULL;
433 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000434
henrika@google.com73d65512011-09-07 15:11:18 +0000435 if (_ptrAudioDeviceUtility)
436 {
437 delete _ptrAudioDeviceUtility;
438 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 }
440
441 delete &_critSect;
442 delete &_critSectEventCb;
443 delete &_critSectAudioCb;
444}
445
446// ============================================================================
447// Module
448// ============================================================================
449
450// ----------------------------------------------------------------------------
451// Module::ChangeUniqueId
452// ----------------------------------------------------------------------------
453
pbos@webrtc.org25509882013-04-09 10:30:35 +0000454int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
niklase@google.com470e71d2011-07-07 08:21:25 +0000455{
niklase@google.com470e71d2011-07-07 08:21:25 +0000456 _id = id;
457 return 0;
458}
459
460// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000461// Module::TimeUntilNextProcess
462//
463// Returns the number of milliseconds until the module want a worker thread
464// to call Process().
465// ----------------------------------------------------------------------------
466
pbos@webrtc.org25509882013-04-09 10:30:35 +0000467int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000468{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000469 uint32_t now = AudioDeviceUtility::GetTimeInMS();
470 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000471 return (deltaProcess);
472}
473
474// ----------------------------------------------------------------------------
475// Module::Process
476//
477// Check for posted error and warning reports. Generate callbacks if
478// new reports exists.
479// ----------------------------------------------------------------------------
480
pbos@webrtc.org25509882013-04-09 10:30:35 +0000481int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000482{
niklase@google.com470e71d2011-07-07 08:21:25 +0000483
484 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
485
486 // kPlayoutWarning
487 if (_ptrAudioDevice->PlayoutWarning())
488 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000489 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000490 if (_ptrCbAudioDeviceObserver)
491 {
492 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
493 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
494 }
495 _ptrAudioDevice->ClearPlayoutWarning();
496 }
497
498 // kPlayoutError
499 if (_ptrAudioDevice->PlayoutError())
500 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000501 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000502 if (_ptrCbAudioDeviceObserver)
503 {
504 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
505 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
506 }
507 _ptrAudioDevice->ClearPlayoutError();
508 }
509
510 // kRecordingWarning
511 if (_ptrAudioDevice->RecordingWarning())
512 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000513 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000514 if (_ptrCbAudioDeviceObserver)
515 {
516 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
517 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
518 }
519 _ptrAudioDevice->ClearRecordingWarning();
520 }
521
522 // kRecordingError
523 if (_ptrAudioDevice->RecordingError())
524 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000525 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000526 if (_ptrCbAudioDeviceObserver)
527 {
528 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
529 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
530 }
531 _ptrAudioDevice->ClearRecordingError();
532 }
533
534 return 0;
535}
536
537// ============================================================================
538// Public API
539// ============================================================================
540
541// ----------------------------------------------------------------------------
542// ActiveAudioLayer
543// ----------------------------------------------------------------------------
544
pbos@webrtc.org25509882013-04-09 10:30:35 +0000545int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000546{
niklase@google.com470e71d2011-07-07 08:21:25 +0000547
548 AudioLayer activeAudio;
549
550 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
551 {
552 return -1;
553 }
554
555 *audioLayer = activeAudio;
556
557 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
558 {
559 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
560 }
561 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
562 {
563 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
564 }
565 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
566 {
567 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
568 }
569 else
570 {
571 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
572 }
573
574 return 0;
575}
576
577// ----------------------------------------------------------------------------
578// LastError
579// ----------------------------------------------------------------------------
580
581AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
582{
583 return _lastError;
584}
585
586// ----------------------------------------------------------------------------
587// Init
588// ----------------------------------------------------------------------------
589
pbos@webrtc.org25509882013-04-09 10:30:35 +0000590int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000591{
niklase@google.com470e71d2011-07-07 08:21:25 +0000592
593 if (_initialized)
594 return 0;
595
596 if (!_ptrAudioDeviceUtility)
597 return -1;
598
599 if (!_ptrAudioDevice)
600 return -1;
601
602 _ptrAudioDeviceUtility->Init();
603
604 if (_ptrAudioDevice->Init() == -1)
605 {
606 return -1;
607 }
608
609 _initialized = true;
610 return 0;
611}
612
613// ----------------------------------------------------------------------------
614// Terminate
615// ----------------------------------------------------------------------------
616
pbos@webrtc.org25509882013-04-09 10:30:35 +0000617int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000618{
niklase@google.com470e71d2011-07-07 08:21:25 +0000619
620 if (!_initialized)
621 return 0;
622
623 if (_ptrAudioDevice->Terminate() == -1)
624 {
625 return -1;
626 }
627
628 _initialized = false;
629 return 0;
630}
631
632// ----------------------------------------------------------------------------
633// Initialized
634// ----------------------------------------------------------------------------
635
636bool AudioDeviceModuleImpl::Initialized() const
637{
niklase@google.com470e71d2011-07-07 08:21:25 +0000638
639 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
640 return (_initialized);
641}
642
643// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000644// InitSpeaker
645// ----------------------------------------------------------------------------
646
pbos@webrtc.org25509882013-04-09 10:30:35 +0000647int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000648{
niklase@google.com470e71d2011-07-07 08:21:25 +0000649 CHECK_INITIALIZED();
650 return (_ptrAudioDevice->InitSpeaker());
651}
652
653// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000654// InitMicrophone
655// ----------------------------------------------------------------------------
656
pbos@webrtc.org25509882013-04-09 10:30:35 +0000657int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000658{
niklase@google.com470e71d2011-07-07 08:21:25 +0000659 CHECK_INITIALIZED();
660 return (_ptrAudioDevice->InitMicrophone());
661}
662
663// ----------------------------------------------------------------------------
664// SpeakerVolumeIsAvailable
665// ----------------------------------------------------------------------------
666
pbos@webrtc.org25509882013-04-09 10:30:35 +0000667int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000668{
niklase@google.com470e71d2011-07-07 08:21:25 +0000669 CHECK_INITIALIZED();
670
671 bool isAvailable(0);
672
673 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
674 {
675 return -1;
676 }
677
678 *available = isAvailable;
679
680 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
681 return (0);
682}
683
684// ----------------------------------------------------------------------------
685// SetSpeakerVolume
686// ----------------------------------------------------------------------------
687
pbos@webrtc.org25509882013-04-09 10:30:35 +0000688int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000689{
niklase@google.com470e71d2011-07-07 08:21:25 +0000690 CHECK_INITIALIZED();
691 return (_ptrAudioDevice->SetSpeakerVolume(volume));
692}
693
694// ----------------------------------------------------------------------------
695// SpeakerVolume
696// ----------------------------------------------------------------------------
697
pbos@webrtc.org25509882013-04-09 10:30:35 +0000698int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000699{
niklase@google.com470e71d2011-07-07 08:21:25 +0000700 CHECK_INITIALIZED();
701
pbos@webrtc.org25509882013-04-09 10:30:35 +0000702 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000703
704 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
705 {
706 return -1;
707 }
708
709 *volume = level;
710
711 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
712 return (0);
713}
714
715// ----------------------------------------------------------------------------
716// SetWaveOutVolume
717// ----------------------------------------------------------------------------
718
pbos@webrtc.org25509882013-04-09 10:30:35 +0000719int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000720{
niklase@google.com470e71d2011-07-07 08:21:25 +0000721 CHECK_INITIALIZED();
722 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
723}
724
725// ----------------------------------------------------------------------------
726// WaveOutVolume
727// ----------------------------------------------------------------------------
728
pbos@webrtc.org25509882013-04-09 10:30:35 +0000729int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000730{
niklase@google.com470e71d2011-07-07 08:21:25 +0000731 CHECK_INITIALIZED();
732
pbos@webrtc.org25509882013-04-09 10:30:35 +0000733 uint16_t volLeft(0);
734 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000735
736 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
737 {
738 return -1;
739 }
740
741 *volumeLeft = volLeft;
742 *volumeRight = volRight;
743
744 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
745 *volumeLeft, *volumeRight);
746
747 return (0);
748}
749
750// ----------------------------------------------------------------------------
751// SpeakerIsInitialized
752// ----------------------------------------------------------------------------
753
754bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
755{
niklase@google.com470e71d2011-07-07 08:21:25 +0000756 CHECK_INITIALIZED_BOOL();
757
758 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
759
760 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
761 return (isInitialized);
762}
763
764// ----------------------------------------------------------------------------
765// MicrophoneIsInitialized
766// ----------------------------------------------------------------------------
767
768bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
769{
niklase@google.com470e71d2011-07-07 08:21:25 +0000770 CHECK_INITIALIZED_BOOL();
771
772 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
773
774 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
775 return (isInitialized);
776}
777
778// ----------------------------------------------------------------------------
779// MaxSpeakerVolume
780// ----------------------------------------------------------------------------
781
pbos@webrtc.org25509882013-04-09 10:30:35 +0000782int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) 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 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000787
788 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
789 {
790 return -1;
791 }
792
793 *maxVolume = maxVol;
794
795 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
796 return (0);
797}
798
799// ----------------------------------------------------------------------------
800// MinSpeakerVolume
801// ----------------------------------------------------------------------------
802
pbos@webrtc.org25509882013-04-09 10:30:35 +0000803int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000804{
niklase@google.com470e71d2011-07-07 08:21:25 +0000805 CHECK_INITIALIZED();
806
pbos@webrtc.org25509882013-04-09 10:30:35 +0000807 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000808
809 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
810 {
811 return -1;
812 }
813
814 *minVolume = minVol;
815
816 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
817 return (0);
818}
819
820// ----------------------------------------------------------------------------
821// SpeakerVolumeStepSize
822// ----------------------------------------------------------------------------
823
pbos@webrtc.org25509882013-04-09 10:30:35 +0000824int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000825{
niklase@google.com470e71d2011-07-07 08:21:25 +0000826 CHECK_INITIALIZED();
827
pbos@webrtc.org25509882013-04-09 10:30:35 +0000828 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000829
830 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
831 {
832 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
833 return -1;
834 }
835
836 *stepSize = delta;
837
838 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
839 return (0);
840}
841
842// ----------------------------------------------------------------------------
843// SpeakerMuteIsAvailable
844// ----------------------------------------------------------------------------
845
pbos@webrtc.org25509882013-04-09 10:30:35 +0000846int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000847{
niklase@google.com470e71d2011-07-07 08:21:25 +0000848 CHECK_INITIALIZED();
849
850 bool isAvailable(0);
851
852 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
853 {
854 return -1;
855 }
856
857 *available = isAvailable;
858
859 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
860 return (0);
861}
862
863// ----------------------------------------------------------------------------
864// SetSpeakerMute
865// ----------------------------------------------------------------------------
866
pbos@webrtc.org25509882013-04-09 10:30:35 +0000867int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000868{
niklase@google.com470e71d2011-07-07 08:21:25 +0000869 CHECK_INITIALIZED();
870 return (_ptrAudioDevice->SetSpeakerMute(enable));
871}
872
873// ----------------------------------------------------------------------------
874// SpeakerMute
875// ----------------------------------------------------------------------------
876
pbos@webrtc.org25509882013-04-09 10:30:35 +0000877int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000878{
niklase@google.com470e71d2011-07-07 08:21:25 +0000879 CHECK_INITIALIZED();
880
881 bool muted(false);
882
883 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
884 {
885 return -1;
886 }
887
888 *enabled = muted;
889
890 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
891 return (0);
892}
893
894// ----------------------------------------------------------------------------
895// MicrophoneMuteIsAvailable
896// ----------------------------------------------------------------------------
897
pbos@webrtc.org25509882013-04-09 10:30:35 +0000898int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000899{
niklase@google.com470e71d2011-07-07 08:21:25 +0000900 CHECK_INITIALIZED();
901
902 bool isAvailable(0);
903
904 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
905 {
906 return -1;
907 }
908
909 *available = isAvailable;
910
911 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
912 return (0);
913}
914
915// ----------------------------------------------------------------------------
916// SetMicrophoneMute
917// ----------------------------------------------------------------------------
918
pbos@webrtc.org25509882013-04-09 10:30:35 +0000919int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000920{
niklase@google.com470e71d2011-07-07 08:21:25 +0000921 CHECK_INITIALIZED();
922 return (_ptrAudioDevice->SetMicrophoneMute(enable));
923}
924
925// ----------------------------------------------------------------------------
926// MicrophoneMute
927// ----------------------------------------------------------------------------
928
pbos@webrtc.org25509882013-04-09 10:30:35 +0000929int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000930{
niklase@google.com470e71d2011-07-07 08:21:25 +0000931 CHECK_INITIALIZED();
932
933 bool muted(false);
934
935 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
936 {
937 return -1;
938 }
939
940 *enabled = muted;
941
942 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
943 return (0);
944}
945
946// ----------------------------------------------------------------------------
947// MicrophoneBoostIsAvailable
948// ----------------------------------------------------------------------------
949
pbos@webrtc.org25509882013-04-09 10:30:35 +0000950int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000951{
niklase@google.com470e71d2011-07-07 08:21:25 +0000952 CHECK_INITIALIZED();
953
954 bool isAvailable(0);
955
956 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
957 {
958 return -1;
959 }
960
961 *available = isAvailable;
962
963 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
964 return (0);
965}
966
967// ----------------------------------------------------------------------------
968// SetMicrophoneBoost
969// ----------------------------------------------------------------------------
970
pbos@webrtc.org25509882013-04-09 10:30:35 +0000971int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000972{
niklase@google.com470e71d2011-07-07 08:21:25 +0000973 CHECK_INITIALIZED();
974 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
975}
976
977// ----------------------------------------------------------------------------
978// MicrophoneBoost
979// ----------------------------------------------------------------------------
980
pbos@webrtc.org25509882013-04-09 10:30:35 +0000981int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000982{
niklase@google.com470e71d2011-07-07 08:21:25 +0000983 CHECK_INITIALIZED();
984
985 bool onOff(false);
986
987 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
988 {
989 return -1;
990 }
991
992 *enabled = onOff;
993
994 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
995 return (0);
996}
997
998// ----------------------------------------------------------------------------
999// MicrophoneVolumeIsAvailable
1000// ----------------------------------------------------------------------------
1001
pbos@webrtc.org25509882013-04-09 10:30:35 +00001002int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001003{
niklase@google.com470e71d2011-07-07 08:21:25 +00001004 CHECK_INITIALIZED();
1005
1006 bool isAvailable(0);
1007
1008 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1009 {
1010 return -1;
1011 }
1012
1013 *available = isAvailable;
1014
1015 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1016 return (0);
1017}
1018
1019// ----------------------------------------------------------------------------
1020// SetMicrophoneVolume
1021// ----------------------------------------------------------------------------
1022
pbos@webrtc.org25509882013-04-09 10:30:35 +00001023int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001024{
niklase@google.com470e71d2011-07-07 08:21:25 +00001025 CHECK_INITIALIZED();
1026 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1027}
1028
1029// ----------------------------------------------------------------------------
1030// MicrophoneVolume
1031// ----------------------------------------------------------------------------
1032
pbos@webrtc.org25509882013-04-09 10:30:35 +00001033int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001034{
1035 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1036 CHECK_INITIALIZED();
1037
pbos@webrtc.org25509882013-04-09 10:30:35 +00001038 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001039
1040 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1041 {
1042 return -1;
1043 }
1044
1045 *volume = level;
1046
1047 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1048 return (0);
1049}
1050
1051// ----------------------------------------------------------------------------
1052// StereoRecordingIsAvailable
1053// ----------------------------------------------------------------------------
1054
pbos@webrtc.org25509882013-04-09 10:30:35 +00001055int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
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->StereoRecordingIsAvailable(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// SetStereoRecording
1074// ----------------------------------------------------------------------------
1075
pbos@webrtc.org25509882013-04-09 10:30:35 +00001076int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001077{
niklase@google.com470e71d2011-07-07 08:21:25 +00001078 CHECK_INITIALIZED();
1079
1080 if (_ptrAudioDevice->RecordingIsInitialized())
1081 {
1082 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1083 return -1;
1084 }
1085
1086 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1087 {
1088 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1089 return -1;
1090 }
1091
pbos@webrtc.org25509882013-04-09 10:30:35 +00001092 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001093 if (enable)
1094 {
1095 nChannels = 2;
1096 }
1097 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1098
1099 return 0;
1100}
1101
1102// ----------------------------------------------------------------------------
1103// StereoRecording
1104// ----------------------------------------------------------------------------
1105
pbos@webrtc.org25509882013-04-09 10:30:35 +00001106int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001107{
niklase@google.com470e71d2011-07-07 08:21:25 +00001108 CHECK_INITIALIZED();
1109
1110 bool stereo(false);
1111
1112 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1113 {
1114 return -1;
1115 }
1116
1117 *enabled = stereo;
1118
1119 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1120 return (0);
1121}
1122
1123// ----------------------------------------------------------------------------
1124// SetRecordingChannel
1125// ----------------------------------------------------------------------------
1126
pbos@webrtc.org25509882013-04-09 10:30:35 +00001127int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001128{
1129 if (channel == kChannelBoth)
1130 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001131 }
1132 else if (channel == kChannelLeft)
1133 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001134 }
1135 else
1136 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001137 }
1138 CHECK_INITIALIZED();
1139
1140 bool stereo(false);
1141
1142 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1143 {
1144 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1145 return -1;
1146 }
1147
1148 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1149}
1150
1151// ----------------------------------------------------------------------------
1152// RecordingChannel
1153// ----------------------------------------------------------------------------
1154
pbos@webrtc.org25509882013-04-09 10:30:35 +00001155int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001156{
niklase@google.com470e71d2011-07-07 08:21:25 +00001157 CHECK_INITIALIZED();
1158
1159 ChannelType chType;
1160
1161 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1162 {
1163 return -1;
1164 }
1165
1166 *channel = chType;
1167
1168 if (*channel == kChannelBoth)
1169 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001170 }
1171 else if (*channel == kChannelLeft)
1172 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001173 }
1174 else
1175 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001176 }
1177
1178 return (0);
1179}
1180
1181// ----------------------------------------------------------------------------
1182// StereoPlayoutIsAvailable
1183// ----------------------------------------------------------------------------
1184
pbos@webrtc.org25509882013-04-09 10:30:35 +00001185int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001186{
niklase@google.com470e71d2011-07-07 08:21:25 +00001187 CHECK_INITIALIZED();
1188
1189 bool isAvailable(0);
1190
1191 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1192 {
1193 return -1;
1194 }
1195
1196 *available = isAvailable;
1197
1198 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1199 return (0);
1200}
1201
1202// ----------------------------------------------------------------------------
1203// SetStereoPlayout
1204// ----------------------------------------------------------------------------
1205
pbos@webrtc.org25509882013-04-09 10:30:35 +00001206int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001207{
niklase@google.com470e71d2011-07-07 08:21:25 +00001208 CHECK_INITIALIZED();
1209
1210 if (_ptrAudioDevice->PlayoutIsInitialized())
1211 {
1212 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1213 return -1;
1214 }
1215
1216 if (_ptrAudioDevice->SetStereoPlayout(enable))
1217 {
1218 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1219 return -1;
1220 }
1221
pbos@webrtc.org25509882013-04-09 10:30:35 +00001222 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001223 if (enable)
1224 {
1225 nChannels = 2;
1226 }
1227 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1228
1229 return 0;
1230}
1231
1232// ----------------------------------------------------------------------------
1233// StereoPlayout
1234// ----------------------------------------------------------------------------
1235
pbos@webrtc.org25509882013-04-09 10:30:35 +00001236int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001237{
niklase@google.com470e71d2011-07-07 08:21:25 +00001238 CHECK_INITIALIZED();
1239
1240 bool stereo(false);
1241
1242 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1243 {
1244 return -1;
1245 }
1246
1247 *enabled = stereo;
1248
1249 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1250 return (0);
1251}
1252
1253// ----------------------------------------------------------------------------
1254// SetAGC
1255// ----------------------------------------------------------------------------
1256
pbos@webrtc.org25509882013-04-09 10:30:35 +00001257int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001258{
niklase@google.com470e71d2011-07-07 08:21:25 +00001259 CHECK_INITIALIZED();
1260 return (_ptrAudioDevice->SetAGC(enable));
1261}
1262
1263// ----------------------------------------------------------------------------
1264// AGC
1265// ----------------------------------------------------------------------------
1266
1267bool AudioDeviceModuleImpl::AGC() const
1268{
niklase@google.com470e71d2011-07-07 08:21:25 +00001269 CHECK_INITIALIZED_BOOL();
1270 return (_ptrAudioDevice->AGC());
1271}
1272
1273// ----------------------------------------------------------------------------
1274// PlayoutIsAvailable
1275// ----------------------------------------------------------------------------
1276
pbos@webrtc.org25509882013-04-09 10:30:35 +00001277int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001278{
niklase@google.com470e71d2011-07-07 08:21:25 +00001279 CHECK_INITIALIZED();
1280
1281 bool isAvailable(0);
1282
1283 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1284 {
1285 return -1;
1286 }
1287
1288 *available = isAvailable;
1289
1290 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1291 return (0);
1292}
1293
1294// ----------------------------------------------------------------------------
1295// RecordingIsAvailable
1296// ----------------------------------------------------------------------------
1297
pbos@webrtc.org25509882013-04-09 10:30:35 +00001298int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001299{
niklase@google.com470e71d2011-07-07 08:21:25 +00001300 CHECK_INITIALIZED();
1301
1302 bool isAvailable(0);
1303
1304 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1305 {
1306 return -1;
1307 }
1308
1309 *available = isAvailable;
1310
1311 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1312 return (0);
1313}
1314
1315// ----------------------------------------------------------------------------
1316// MaxMicrophoneVolume
1317// ----------------------------------------------------------------------------
1318
pbos@webrtc.org25509882013-04-09 10:30:35 +00001319int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001320{
1321 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1322 CHECK_INITIALIZED();
1323
pbos@webrtc.org25509882013-04-09 10:30:35 +00001324 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001325
1326 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1327 {
1328 return -1;
1329 }
1330
1331 *maxVolume = maxVol;
1332
1333 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1334 return (0);
1335}
1336
1337// ----------------------------------------------------------------------------
1338// MinMicrophoneVolume
1339// ----------------------------------------------------------------------------
1340
pbos@webrtc.org25509882013-04-09 10:30:35 +00001341int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001342{
niklase@google.com470e71d2011-07-07 08:21:25 +00001343 CHECK_INITIALIZED();
1344
pbos@webrtc.org25509882013-04-09 10:30:35 +00001345 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001346
1347 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1348 {
1349 return -1;
1350 }
1351
1352 *minVolume = minVol;
1353
1354 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1355 return (0);
1356}
1357
1358// ----------------------------------------------------------------------------
1359// MicrophoneVolumeStepSize
1360// ----------------------------------------------------------------------------
1361
pbos@webrtc.org25509882013-04-09 10:30:35 +00001362int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001363{
niklase@google.com470e71d2011-07-07 08:21:25 +00001364 CHECK_INITIALIZED();
1365
pbos@webrtc.org25509882013-04-09 10:30:35 +00001366 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001367
1368 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1369 {
1370 return -1;
1371 }
1372
1373 *stepSize = delta;
1374
1375 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1376 return (0);
1377}
1378
1379// ----------------------------------------------------------------------------
1380// PlayoutDevices
1381// ----------------------------------------------------------------------------
1382
pbos@webrtc.org25509882013-04-09 10:30:35 +00001383int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001384{
niklase@google.com470e71d2011-07-07 08:21:25 +00001385 CHECK_INITIALIZED();
1386
pbos@webrtc.org25509882013-04-09 10:30:35 +00001387 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001388
1389 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001390 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001391}
1392
1393// ----------------------------------------------------------------------------
1394// SetPlayoutDevice I (II)
1395// ----------------------------------------------------------------------------
1396
pbos@webrtc.org25509882013-04-09 10:30:35 +00001397int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001398{
niklase@google.com470e71d2011-07-07 08:21:25 +00001399 CHECK_INITIALIZED();
1400 return (_ptrAudioDevice->SetPlayoutDevice(index));
1401}
1402
1403// ----------------------------------------------------------------------------
1404// SetPlayoutDevice II (II)
1405// ----------------------------------------------------------------------------
1406
pbos@webrtc.org25509882013-04-09 10:30:35 +00001407int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001408{
1409 if (device == kDefaultDevice)
1410 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001411 }
1412 else
1413 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001414 }
1415 CHECK_INITIALIZED();
1416
1417 return (_ptrAudioDevice->SetPlayoutDevice(device));
1418}
1419
1420// ----------------------------------------------------------------------------
1421// PlayoutDeviceName
1422// ----------------------------------------------------------------------------
1423
pbos@webrtc.org25509882013-04-09 10:30:35 +00001424int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1425 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001426 char name[kAdmMaxDeviceNameSize],
1427 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001428{
niklase@google.com470e71d2011-07-07 08:21:25 +00001429 CHECK_INITIALIZED();
1430
1431 if (name == NULL)
1432 {
1433 _lastError = kAdmErrArgument;
1434 return -1;
1435 }
1436
1437 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1438 {
1439 return -1;
1440 }
1441
1442 if (name != NULL)
1443 {
1444 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1445 }
1446 if (guid != NULL)
1447 {
1448 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1449 }
1450
1451 return (0);
1452}
1453
1454// ----------------------------------------------------------------------------
1455// RecordingDeviceName
1456// ----------------------------------------------------------------------------
1457
pbos@webrtc.org25509882013-04-09 10:30:35 +00001458int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1459 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001460 char name[kAdmMaxDeviceNameSize],
1461 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001462{
niklase@google.com470e71d2011-07-07 08:21:25 +00001463 CHECK_INITIALIZED();
1464
1465 if (name == NULL)
1466 {
1467 _lastError = kAdmErrArgument;
1468 return -1;
1469 }
1470
1471 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1472 {
1473 return -1;
1474 }
1475
1476 if (name != NULL)
1477 {
1478 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1479 }
1480 if (guid != NULL)
1481 {
1482 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1483 }
1484
1485 return (0);
1486}
1487
1488// ----------------------------------------------------------------------------
1489// RecordingDevices
1490// ----------------------------------------------------------------------------
1491
pbos@webrtc.org25509882013-04-09 10:30:35 +00001492int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001493{
niklase@google.com470e71d2011-07-07 08:21:25 +00001494 CHECK_INITIALIZED();
1495
pbos@webrtc.org25509882013-04-09 10:30:35 +00001496 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001497
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001498 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1499 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001500 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001501}
1502
1503// ----------------------------------------------------------------------------
1504// SetRecordingDevice I (II)
1505// ----------------------------------------------------------------------------
1506
pbos@webrtc.org25509882013-04-09 10:30:35 +00001507int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001508{
niklase@google.com470e71d2011-07-07 08:21:25 +00001509 CHECK_INITIALIZED();
1510 return (_ptrAudioDevice->SetRecordingDevice(index));
1511}
1512
1513// ----------------------------------------------------------------------------
1514// SetRecordingDevice II (II)
1515// ----------------------------------------------------------------------------
1516
pbos@webrtc.org25509882013-04-09 10:30:35 +00001517int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001518{
1519 if (device == kDefaultDevice)
1520 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001521 }
1522 else
1523 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001524 }
1525 CHECK_INITIALIZED();
1526
1527 return (_ptrAudioDevice->SetRecordingDevice(device));
1528}
1529
1530// ----------------------------------------------------------------------------
1531// InitPlayout
1532// ----------------------------------------------------------------------------
1533
pbos@webrtc.org25509882013-04-09 10:30:35 +00001534int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001535{
niklase@google.com470e71d2011-07-07 08:21:25 +00001536 CHECK_INITIALIZED();
1537 _audioDeviceBuffer.InitPlayout();
1538 return (_ptrAudioDevice->InitPlayout());
1539}
1540
1541// ----------------------------------------------------------------------------
1542// InitRecording
1543// ----------------------------------------------------------------------------
1544
pbos@webrtc.org25509882013-04-09 10:30:35 +00001545int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001546{
niklase@google.com470e71d2011-07-07 08:21:25 +00001547 CHECK_INITIALIZED();
1548 _audioDeviceBuffer.InitRecording();
1549 return (_ptrAudioDevice->InitRecording());
1550}
1551
1552// ----------------------------------------------------------------------------
1553// PlayoutIsInitialized
1554// ----------------------------------------------------------------------------
1555
1556bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1557{
niklase@google.com470e71d2011-07-07 08:21:25 +00001558 CHECK_INITIALIZED_BOOL();
1559 return (_ptrAudioDevice->PlayoutIsInitialized());
1560}
1561
1562// ----------------------------------------------------------------------------
1563// RecordingIsInitialized
1564// ----------------------------------------------------------------------------
1565
1566bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1567{
niklase@google.com470e71d2011-07-07 08:21:25 +00001568 CHECK_INITIALIZED_BOOL();
1569 return (_ptrAudioDevice->RecordingIsInitialized());
1570}
1571
1572// ----------------------------------------------------------------------------
1573// StartPlayout
1574// ----------------------------------------------------------------------------
1575
pbos@webrtc.org25509882013-04-09 10:30:35 +00001576int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001577{
niklase@google.com470e71d2011-07-07 08:21:25 +00001578 CHECK_INITIALIZED();
1579 return (_ptrAudioDevice->StartPlayout());
1580}
1581
1582// ----------------------------------------------------------------------------
1583// StopPlayout
1584// ----------------------------------------------------------------------------
1585
pbos@webrtc.org25509882013-04-09 10:30:35 +00001586int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001587{
niklase@google.com470e71d2011-07-07 08:21:25 +00001588 CHECK_INITIALIZED();
1589 return (_ptrAudioDevice->StopPlayout());
1590}
1591
1592// ----------------------------------------------------------------------------
1593// Playing
1594// ----------------------------------------------------------------------------
1595
1596bool AudioDeviceModuleImpl::Playing() const
1597{
niklase@google.com470e71d2011-07-07 08:21:25 +00001598 CHECK_INITIALIZED_BOOL();
1599 return (_ptrAudioDevice->Playing());
1600}
1601
1602// ----------------------------------------------------------------------------
1603// StartRecording
1604// ----------------------------------------------------------------------------
1605
pbos@webrtc.org25509882013-04-09 10:30:35 +00001606int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001607{
niklase@google.com470e71d2011-07-07 08:21:25 +00001608 CHECK_INITIALIZED();
1609 return (_ptrAudioDevice->StartRecording());
1610}
1611// ----------------------------------------------------------------------------
1612// StopRecording
1613// ----------------------------------------------------------------------------
1614
pbos@webrtc.org25509882013-04-09 10:30:35 +00001615int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001616{
niklase@google.com470e71d2011-07-07 08:21:25 +00001617 CHECK_INITIALIZED();
1618 return (_ptrAudioDevice->StopRecording());
1619}
1620
1621// ----------------------------------------------------------------------------
1622// Recording
1623// ----------------------------------------------------------------------------
1624
1625bool AudioDeviceModuleImpl::Recording() const
1626{
niklase@google.com470e71d2011-07-07 08:21:25 +00001627 CHECK_INITIALIZED_BOOL();
1628 return (_ptrAudioDevice->Recording());
1629}
1630
1631// ----------------------------------------------------------------------------
1632// RegisterEventObserver
1633// ----------------------------------------------------------------------------
1634
pbos@webrtc.org25509882013-04-09 10:30:35 +00001635int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001636{
niklase@google.com470e71d2011-07-07 08:21:25 +00001637
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001638 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001639 _ptrCbAudioDeviceObserver = eventCallback;
1640
1641 return 0;
1642}
1643
1644// ----------------------------------------------------------------------------
1645// RegisterAudioCallback
1646// ----------------------------------------------------------------------------
1647
pbos@webrtc.org25509882013-04-09 10:30:35 +00001648int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001649{
niklase@google.com470e71d2011-07-07 08:21:25 +00001650
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001651 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001652 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1653
1654 return 0;
1655}
1656
1657// ----------------------------------------------------------------------------
1658// StartRawInputFileRecording
1659// ----------------------------------------------------------------------------
1660
pbos@webrtc.org25509882013-04-09 10:30:35 +00001661int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001662 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001663{
niklase@google.com470e71d2011-07-07 08:21:25 +00001664 CHECK_INITIALIZED();
1665
1666 if (NULL == pcmFileNameUTF8)
1667 {
1668 return -1;
1669 }
1670
1671 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1672}
1673
1674// ----------------------------------------------------------------------------
1675// StopRawInputFileRecording
1676// ----------------------------------------------------------------------------
1677
pbos@webrtc.org25509882013-04-09 10:30:35 +00001678int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001679{
niklase@google.com470e71d2011-07-07 08:21:25 +00001680 CHECK_INITIALIZED();
1681
1682 return (_audioDeviceBuffer.StopInputFileRecording());
1683}
1684
1685// ----------------------------------------------------------------------------
1686// StartRawOutputFileRecording
1687// ----------------------------------------------------------------------------
1688
pbos@webrtc.org25509882013-04-09 10:30:35 +00001689int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001690 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001691{
niklase@google.com470e71d2011-07-07 08:21:25 +00001692 CHECK_INITIALIZED();
1693
1694 if (NULL == pcmFileNameUTF8)
1695 {
1696 return -1;
1697 }
1698
1699 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1700}
1701
1702// ----------------------------------------------------------------------------
1703// StopRawOutputFileRecording
1704// ----------------------------------------------------------------------------
1705
pbos@webrtc.org25509882013-04-09 10:30:35 +00001706int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001707{
niklase@google.com470e71d2011-07-07 08:21:25 +00001708 CHECK_INITIALIZED();
1709
1710 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001711}
1712
1713// ----------------------------------------------------------------------------
1714// SetPlayoutBuffer
1715// ----------------------------------------------------------------------------
1716
pbos@webrtc.org25509882013-04-09 10:30:35 +00001717int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001718{
niklase@google.com470e71d2011-07-07 08:21:25 +00001719 CHECK_INITIALIZED();
1720
1721 if (_ptrAudioDevice->PlayoutIsInitialized())
1722 {
1723 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1724 return -1;
1725 }
1726
pbos@webrtc.org25509882013-04-09 10:30:35 +00001727 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001728
1729 if (kFixedBufferSize == type)
1730 {
1731 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1732 {
1733 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1734 return -1;
1735 }
1736 }
1737
1738 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1739 {
1740 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1741 }
1742
1743 return ret;
1744}
1745
1746// ----------------------------------------------------------------------------
1747// PlayoutBuffer
1748// ----------------------------------------------------------------------------
1749
pbos@webrtc.org25509882013-04-09 10:30:35 +00001750int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001751{
niklase@google.com470e71d2011-07-07 08:21:25 +00001752 CHECK_INITIALIZED();
1753
1754 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001755 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001756
1757 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1758 {
1759 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1760 return -1;
1761 }
1762
1763 *type = bufType;
1764 *sizeMS = size;
1765
1766 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1767 return (0);
1768}
1769
1770// ----------------------------------------------------------------------------
1771// PlayoutDelay
1772// ----------------------------------------------------------------------------
1773
pbos@webrtc.org25509882013-04-09 10:30:35 +00001774int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001775{
1776 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1777 CHECK_INITIALIZED();
1778
pbos@webrtc.org25509882013-04-09 10:30:35 +00001779 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001780
1781 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1782 {
1783 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1784 return -1;
1785 }
1786
1787 *delayMS = delay;
1788
1789 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1790 return (0);
1791}
1792
1793// ----------------------------------------------------------------------------
1794// RecordingDelay
1795// ----------------------------------------------------------------------------
1796
pbos@webrtc.org25509882013-04-09 10:30:35 +00001797int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001798{
1799 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1800 CHECK_INITIALIZED();
1801
pbos@webrtc.org25509882013-04-09 10:30:35 +00001802 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001803
1804 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1805 {
1806 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1807 return -1;
1808 }
1809
1810 *delayMS = delay;
1811
1812 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1813 return (0);
1814}
1815
1816// ----------------------------------------------------------------------------
1817// CPULoad
1818// ----------------------------------------------------------------------------
1819
pbos@webrtc.org25509882013-04-09 10:30:35 +00001820int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001821{
niklase@google.com470e71d2011-07-07 08:21:25 +00001822 CHECK_INITIALIZED();
1823
pbos@webrtc.org25509882013-04-09 10:30:35 +00001824 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001825
1826 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1827 {
1828 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1829 return -1;
1830 }
1831
1832 *load = cpuLoad;
1833
1834 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1835 return (0);
1836}
1837
1838// ----------------------------------------------------------------------------
1839// SetRecordingSampleRate
1840// ----------------------------------------------------------------------------
1841
pbos@webrtc.org25509882013-04-09 10:30:35 +00001842int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001843{
niklase@google.com470e71d2011-07-07 08:21:25 +00001844 CHECK_INITIALIZED();
1845
1846 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1847 {
1848 return -1;
1849 }
1850
1851 return (0);
1852}
1853
1854// ----------------------------------------------------------------------------
1855// RecordingSampleRate
1856// ----------------------------------------------------------------------------
1857
pbos@webrtc.org25509882013-04-09 10:30:35 +00001858int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001859{
niklase@google.com470e71d2011-07-07 08:21:25 +00001860 CHECK_INITIALIZED();
1861
pbos@webrtc.org25509882013-04-09 10:30:35 +00001862 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001863
1864 if (sampleRate == -1)
1865 {
1866 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1867 return -1;
1868 }
1869
1870 *samplesPerSec = sampleRate;
1871
1872 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1873 return (0);
1874}
1875
1876// ----------------------------------------------------------------------------
1877// SetPlayoutSampleRate
1878// ----------------------------------------------------------------------------
1879
pbos@webrtc.org25509882013-04-09 10:30:35 +00001880int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001881{
niklase@google.com470e71d2011-07-07 08:21:25 +00001882 CHECK_INITIALIZED();
1883
1884 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1885 {
1886 return -1;
1887 }
1888
1889 return (0);
1890}
1891
1892// ----------------------------------------------------------------------------
1893// PlayoutSampleRate
1894// ----------------------------------------------------------------------------
1895
pbos@webrtc.org25509882013-04-09 10:30:35 +00001896int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001897{
niklase@google.com470e71d2011-07-07 08:21:25 +00001898 CHECK_INITIALIZED();
1899
pbos@webrtc.org25509882013-04-09 10:30:35 +00001900 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001901
1902 if (sampleRate == -1)
1903 {
1904 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1905 return -1;
1906 }
1907
1908 *samplesPerSec = sampleRate;
1909
1910 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1911 return (0);
1912}
1913
1914// ----------------------------------------------------------------------------
1915// ResetAudioDevice
1916// ----------------------------------------------------------------------------
1917
pbos@webrtc.org25509882013-04-09 10:30:35 +00001918int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001919{
niklase@google.com470e71d2011-07-07 08:21:25 +00001920 CHECK_INITIALIZED();
1921
1922
1923 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1924 {
1925 return -1;
1926 }
1927
1928 return (0);
1929}
1930
1931// ----------------------------------------------------------------------------
1932// SetLoudspeakerStatus
1933// ----------------------------------------------------------------------------
1934
pbos@webrtc.org25509882013-04-09 10:30:35 +00001935int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001936{
niklase@google.com470e71d2011-07-07 08:21:25 +00001937 CHECK_INITIALIZED();
1938
1939 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1940 {
1941 return -1;
1942 }
1943
1944 return 0;
1945}
1946
1947// ----------------------------------------------------------------------------
1948// GetLoudspeakerStatus
1949// ----------------------------------------------------------------------------
1950
pbos@webrtc.org25509882013-04-09 10:30:35 +00001951int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001952{
niklase@google.com470e71d2011-07-07 08:21:25 +00001953 CHECK_INITIALIZED();
1954
1955 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1956 {
1957 return -1;
1958 }
1959
1960 return 0;
1961}
1962
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001963int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1964{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001965 CHECK_INITIALIZED();
1966
1967 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1968}
1969
1970bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1971{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001972 CHECK_INITIALIZED_BOOL();
1973
1974 return _ptrAudioDevice->BuiltInAECIsEnabled();
1975}
1976
niklase@google.com470e71d2011-07-07 08:21:25 +00001977// ============================================================================
1978// Private Methods
1979// ============================================================================
1980
1981// ----------------------------------------------------------------------------
1982// Platform
1983// ----------------------------------------------------------------------------
1984
1985AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1986{
1987 return _platformType;
1988}
1989
1990// ----------------------------------------------------------------------------
1991// PlatformAudioLayer
1992// ----------------------------------------------------------------------------
1993
1994AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
1995{
niklase@google.com470e71d2011-07-07 08:21:25 +00001996
1997 switch (_platformAudioLayer)
1998 {
1999 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002000 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2001 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002002 break;
2003 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002004 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2005 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002006 break;
2007 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002008 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2009 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002010 break;
2011 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002012 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2013 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002014 break;
2015 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002016 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2017 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002018 break;
2019 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002020 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2021 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002022 break;
2023 }
2024
2025 return _platformAudioLayer;
2026}
2027
2028} // namespace webrtc