blob: a8145603ab9a983330c7529a0760be2a6861bdc4 [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
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000048
49#if defined(WEBRTC_DUMMY_FILE_DEVICES)
50#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
51#endif
52
pbos@webrtc.org811269d2013-07-11 13:24:38 +000053#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
54#include "webrtc/modules/audio_device/dummy/audio_device_utility_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000055#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000056#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
57#include "webrtc/system_wrappers/interface/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000058
59#define CHECK_INITIALIZED() \
60{ \
61 if (!_initialized) { \
62 return -1; \
63 }; \
64}
65
66#define CHECK_INITIALIZED_BOOL() \
67{ \
68 if (!_initialized) { \
69 return false; \
70 }; \
71}
72
73namespace webrtc
74{
75
henrike@webrtc.org70efc322012-02-23 17:45:33 +000076AudioDeviceModule* CreateAudioDeviceModule(
pbos@webrtc.org25509882013-04-09 10:30:35 +000077 int32_t id, AudioDeviceModule::AudioLayer audioLayer) {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000078 return AudioDeviceModuleImpl::Create(id, audioLayer);
79}
80
81
niklase@google.com470e71d2011-07-07 08:21:25 +000082// ============================================================================
83// Static methods
84// ============================================================================
85
86// ----------------------------------------------------------------------------
87// AudioDeviceModule::Create()
88// ----------------------------------------------------------------------------
89
pbos@webrtc.org25509882013-04-09 10:30:35 +000090AudioDeviceModule* AudioDeviceModuleImpl::Create(const int32_t id,
henrika@google.com73d65512011-09-07 15:11:18 +000091 const AudioLayer audioLayer)
niklase@google.com470e71d2011-07-07 08:21:25 +000092{
niklase@google.com470e71d2011-07-07 08:21:25 +000093
henrika@google.com73d65512011-09-07 15:11:18 +000094 // Create the generic ref counted (platform independent) implementation.
95 RefCountImpl<AudioDeviceModuleImpl>* audioDevice =
96 new RefCountImpl<AudioDeviceModuleImpl>(id, audioLayer);
niklase@google.com470e71d2011-07-07 08:21:25 +000097
henrika@google.com73d65512011-09-07 15:11:18 +000098 // Ensure that the current platform is supported.
niklase@google.com470e71d2011-07-07 08:21:25 +000099 if (audioDevice->CheckPlatform() == -1)
100 {
101 delete audioDevice;
102 return NULL;
103 }
104
henrika@google.com73d65512011-09-07 15:11:18 +0000105 // Create the platform-dependent implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000106 if (audioDevice->CreatePlatformSpecificObjects() == -1)
107 {
108 delete audioDevice;
109 return NULL;
110 }
111
henrika@google.com73d65512011-09-07 15:11:18 +0000112 // Ensure that the generic audio buffer can communicate with the
113 // platform-specific parts.
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 if (audioDevice->AttachAudioBuffer() == -1)
115 {
116 delete audioDevice;
117 return NULL;
118 }
119
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000120 WebRtcSpl_Init();
121
niklase@google.com470e71d2011-07-07 08:21:25 +0000122 return audioDevice;
123}
124
niklase@google.com470e71d2011-07-07 08:21:25 +0000125// ============================================================================
126// Construction & Destruction
127// ============================================================================
128
129// ----------------------------------------------------------------------------
130// AudioDeviceModuleImpl - ctor
131// ----------------------------------------------------------------------------
132
pbos@webrtc.org25509882013-04-09 10:30:35 +0000133AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
135 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
136 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
137 _ptrCbAudioDeviceObserver(NULL),
xians@google.com88bd4402011-08-04 15:33:30 +0000138 _ptrAudioDeviceUtility(NULL),
139 _ptrAudioDevice(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +0000140 _id(id),
141 _platformAudioLayer(audioLayer),
142 _lastProcessTime(AudioDeviceUtility::GetTimeInMS()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000143 _platformType(kPlatformNotSupported),
xians@google.com88bd4402011-08-04 15:33:30 +0000144 _initialized(false),
145 _lastError(kAdmErrNone)
niklase@google.com470e71d2011-07-07 08:21:25 +0000146{
147 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
148}
149
150// ----------------------------------------------------------------------------
151// CheckPlatform
152// ----------------------------------------------------------------------------
153
pbos@webrtc.org25509882013-04-09 10:30:35 +0000154int32_t AudioDeviceModuleImpl::CheckPlatform()
niklase@google.com470e71d2011-07-07 08:21:25 +0000155{
156 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
157
158 // Ensure that the current platform is supported
159 //
160 PlatformType platform(kPlatformNotSupported);
161
162#if defined(_WIN32)
163 platform = kPlatformWin32;
164 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
leozwang@google.com522f42b2011-09-19 17:39:05 +0000165#elif defined(WEBRTC_ANDROID)
166 platform = kPlatformAndroid;
167 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
niklase@google.com470e71d2011-07-07 08:21:25 +0000168#elif defined(WEBRTC_LINUX)
169 platform = kPlatformLinux;
170 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000171#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000172 platform = kPlatformIOS;
173 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000174#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 platform = kPlatformMac;
176 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
177#endif
178
179 if (platform == kPlatformNotSupported)
180 {
181 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
182 return -1;
183 }
184
185 // Store valid output results
186 //
187 _platformType = platform;
188
189 return 0;
190}
191
192
193// ----------------------------------------------------------------------------
194// CreatePlatformSpecificObjects
195// ----------------------------------------------------------------------------
196
pbos@webrtc.org25509882013-04-09 10:30:35 +0000197int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
niklase@google.com470e71d2011-07-07 08:21:25 +0000198{
199 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
200
201 AudioDeviceGeneric* ptrAudioDevice(NULL);
202 AudioDeviceUtility* ptrAudioDeviceUtility(NULL);
203
xians@google.combf5d2ba2011-08-16 07:44:19 +0000204#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
205 ptrAudioDevice = new AudioDeviceDummy(Id());
206 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
207
208 if (ptrAudioDevice != NULL)
209 {
210 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
211 }
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000212#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
213 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
214 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
215 "Will use file-playing dummy device.");
216 if (ptrAudioDevice != NULL)
217 {
218 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
219 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000220#else
niklase@google.com470e71d2011-07-07 08:21:25 +0000221 const AudioLayer audioLayer(PlatformAudioLayer());
222
223 // Create the *Windows* implementation of the Audio Device
224 //
225#if defined(_WIN32)
226 if ((audioLayer == kWindowsWaveAudio)
227#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
228 // Wave audio is default if Core audio is not supported in this build
229 || (audioLayer == kPlatformDefaultAudio)
230#endif
231 )
232 {
233 // create *Windows Wave Audio* implementation
234 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
235 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
236 }
237#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
238 if ((audioLayer == kWindowsCoreAudio) ||
239 (audioLayer == kPlatformDefaultAudio)
240 )
241 {
242 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
243
244 if (AudioDeviceWindowsCore::CoreAudioIsSupported())
245 {
246 // create *Windows Core Audio* implementation
247 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
248 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
249 }
250 else
251 {
252 // create *Windows Wave Audio* implementation
253 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
254 if (ptrAudioDevice != NULL)
255 {
256 // Core Audio was not supported => revert to Windows Wave instead
257 _platformAudioLayer = kWindowsWaveAudio; // modify the state set at construction
258 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
259 }
260 }
261 }
262#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
263 if (ptrAudioDevice != NULL)
264 {
265 // Create the Windows implementation of the Device Utility.
266 // This class is independent of the selected audio layer
267 // for Windows.
268 //
269 ptrAudioDeviceUtility = new AudioDeviceUtilityWindows(Id());
270 }
271#endif // #if defined(_WIN32)
272
leozwang@google.com39f20512011-07-15 16:29:40 +0000273 // Create the *Android OpenSLES* implementation of the Audio Device
niklase@google.com470e71d2011-07-07 08:21:25 +0000274 //
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000275#if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000276 if (audioLayer == kPlatformDefaultAudio)
277 {
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000278 // AudioRecordJni provides hardware AEC and OpenSlesOutput low latency.
279#if defined(WEBRTC_ANDROID_OPENSLES)
280 ptrAudioDevice = new AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>(Id());
281#else
282 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(Id());
283#endif
leozwang@google.com39f20512011-07-15 16:29:40 +0000284 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
285 "Android OpenSLES Audio APIs will be utilized");
niklase@google.com470e71d2011-07-07 08:21:25 +0000286 }
287
288 if (ptrAudioDevice != NULL)
289 {
290 // Create the Android implementation of the Device Utility.
291 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
292 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000293 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000294
295 // Create the *Linux* implementation of the Audio Device
296 //
297#elif defined(WEBRTC_LINUX)
298 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
299 {
300#if defined(LINUX_PULSE)
301 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
302
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000303 // create *Linux PulseAudio* implementation
304 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
305 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000306 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000307 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000308 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
309 }
310 else
311 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000312 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000313#endif
314#if defined(LINUX_ALSA)
315 // create *Linux ALSA Audio* implementation
316 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
317 if (ptrAudioDevice != NULL)
318 {
319 // Pulse Audio was not supported => revert to ALSA instead
320 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
321 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
322 }
323#endif
324#if defined(LINUX_PULSE)
325 }
326#endif
327 }
328 else if (audioLayer == kLinuxAlsaAudio)
329 {
330#if defined(LINUX_ALSA)
331 // create *Linux ALSA Audio* implementation
332 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
333 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
334#endif
335 }
336
337 if (ptrAudioDevice != NULL)
338 {
339 // Create the Linux implementation of the Device Utility.
340 // This class is independent of the selected audio layer
341 // for Linux.
342 //
343 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
344 }
345#endif // #if defined(WEBRTC_LINUX)
346
347 // Create the *iPhone* implementation of the Audio Device
348 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000349#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000350 if (audioLayer == kPlatformDefaultAudio)
351 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000352 // Create iOS Audio Device implementation.
353 ptrAudioDevice = new AudioDeviceIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
355 }
356
357 if (ptrAudioDevice != NULL)
358 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000359 // Create iOS Device Utility implementation.
360 ptrAudioDeviceUtility = new AudioDeviceUtilityIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000361 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000362 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000363
364 // Create the *Mac* implementation of the Audio Device
365 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000366#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000367 if (audioLayer == kPlatformDefaultAudio)
368 {
369 // Create *Mac Audio* implementation
370 ptrAudioDevice = new AudioDeviceMac(Id());
371 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
372 }
373
374 if (ptrAudioDevice != NULL)
375 {
376 // Create the Mac implementation of the Device Utility.
377 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
378 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000379#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
381 // Create the *Dummy* implementation of the Audio Device
382 // Available for all platforms
383 //
384 if (audioLayer == kDummyAudio)
385 {
386 // Create *Dummy Audio* implementation
387 assert(!ptrAudioDevice);
388 ptrAudioDevice = new AudioDeviceDummy(Id());
389 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
390
391 if (ptrAudioDevice != NULL)
392 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000393 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000394 }
395 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000396#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000397
398 if (ptrAudioDevice == NULL)
399 {
400 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
401 return -1;
402 }
403
404 if (ptrAudioDeviceUtility == NULL)
405 {
406 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
407 return -1;
408 }
409
410 // Store valid output pointers
411 //
412 _ptrAudioDevice = ptrAudioDevice;
413 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
414
415 return 0;
416}
417
418// ----------------------------------------------------------------------------
419// AttachAudioBuffer
420//
421// Install "bridge" between the platform implemetation and the generic
422// implementation. The "child" shall set the native sampling rate and the
423// number of channels in this function call.
424// ----------------------------------------------------------------------------
425
pbos@webrtc.org25509882013-04-09 10:30:35 +0000426int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000427{
428 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
429
430 _audioDeviceBuffer.SetId(_id);
431 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
432 return 0;
433}
434
435// ----------------------------------------------------------------------------
436// ~AudioDeviceModuleImpl - dtor
437// ----------------------------------------------------------------------------
438
439AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
440{
441 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000442
443 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000444 {
henrika@google.com73d65512011-09-07 15:11:18 +0000445 delete _ptrAudioDevice;
446 _ptrAudioDevice = NULL;
447 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000448
henrika@google.com73d65512011-09-07 15:11:18 +0000449 if (_ptrAudioDeviceUtility)
450 {
451 delete _ptrAudioDeviceUtility;
452 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000453 }
454
455 delete &_critSect;
456 delete &_critSectEventCb;
457 delete &_critSectAudioCb;
458}
459
460// ============================================================================
461// Module
462// ============================================================================
463
464// ----------------------------------------------------------------------------
465// Module::ChangeUniqueId
466// ----------------------------------------------------------------------------
467
pbos@webrtc.org25509882013-04-09 10:30:35 +0000468int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
niklase@google.com470e71d2011-07-07 08:21:25 +0000469{
niklase@google.com470e71d2011-07-07 08:21:25 +0000470 _id = id;
471 return 0;
472}
473
474// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000475// Module::TimeUntilNextProcess
476//
477// Returns the number of milliseconds until the module want a worker thread
478// to call Process().
479// ----------------------------------------------------------------------------
480
pbos@webrtc.org25509882013-04-09 10:30:35 +0000481int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000482{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000483 uint32_t now = AudioDeviceUtility::GetTimeInMS();
484 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000485 return (deltaProcess);
486}
487
488// ----------------------------------------------------------------------------
489// Module::Process
490//
491// Check for posted error and warning reports. Generate callbacks if
492// new reports exists.
493// ----------------------------------------------------------------------------
494
pbos@webrtc.org25509882013-04-09 10:30:35 +0000495int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000496{
niklase@google.com470e71d2011-07-07 08:21:25 +0000497
498 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
499
500 // kPlayoutWarning
501 if (_ptrAudioDevice->PlayoutWarning())
502 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000503 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000504 if (_ptrCbAudioDeviceObserver)
505 {
506 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
507 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
508 }
509 _ptrAudioDevice->ClearPlayoutWarning();
510 }
511
512 // kPlayoutError
513 if (_ptrAudioDevice->PlayoutError())
514 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000515 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000516 if (_ptrCbAudioDeviceObserver)
517 {
518 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
519 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
520 }
521 _ptrAudioDevice->ClearPlayoutError();
522 }
523
524 // kRecordingWarning
525 if (_ptrAudioDevice->RecordingWarning())
526 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000527 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000528 if (_ptrCbAudioDeviceObserver)
529 {
530 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
531 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
532 }
533 _ptrAudioDevice->ClearRecordingWarning();
534 }
535
536 // kRecordingError
537 if (_ptrAudioDevice->RecordingError())
538 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000539 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000540 if (_ptrCbAudioDeviceObserver)
541 {
542 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
543 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
544 }
545 _ptrAudioDevice->ClearRecordingError();
546 }
547
548 return 0;
549}
550
551// ============================================================================
552// Public API
553// ============================================================================
554
555// ----------------------------------------------------------------------------
556// ActiveAudioLayer
557// ----------------------------------------------------------------------------
558
pbos@webrtc.org25509882013-04-09 10:30:35 +0000559int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000560{
niklase@google.com470e71d2011-07-07 08:21:25 +0000561
562 AudioLayer activeAudio;
563
564 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
565 {
566 return -1;
567 }
568
569 *audioLayer = activeAudio;
570
571 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
572 {
573 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
574 }
575 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
576 {
577 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
578 }
579 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
580 {
581 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
582 }
583 else
584 {
585 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
586 }
587
588 return 0;
589}
590
591// ----------------------------------------------------------------------------
592// LastError
593// ----------------------------------------------------------------------------
594
595AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
596{
597 return _lastError;
598}
599
600// ----------------------------------------------------------------------------
601// Init
602// ----------------------------------------------------------------------------
603
pbos@webrtc.org25509882013-04-09 10:30:35 +0000604int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000605{
niklase@google.com470e71d2011-07-07 08:21:25 +0000606
607 if (_initialized)
608 return 0;
609
610 if (!_ptrAudioDeviceUtility)
611 return -1;
612
613 if (!_ptrAudioDevice)
614 return -1;
615
616 _ptrAudioDeviceUtility->Init();
617
618 if (_ptrAudioDevice->Init() == -1)
619 {
620 return -1;
621 }
622
623 _initialized = true;
624 return 0;
625}
626
627// ----------------------------------------------------------------------------
628// Terminate
629// ----------------------------------------------------------------------------
630
pbos@webrtc.org25509882013-04-09 10:30:35 +0000631int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000632{
niklase@google.com470e71d2011-07-07 08:21:25 +0000633
634 if (!_initialized)
635 return 0;
636
637 if (_ptrAudioDevice->Terminate() == -1)
638 {
639 return -1;
640 }
641
642 _initialized = false;
643 return 0;
644}
645
646// ----------------------------------------------------------------------------
647// Initialized
648// ----------------------------------------------------------------------------
649
650bool AudioDeviceModuleImpl::Initialized() const
651{
niklase@google.com470e71d2011-07-07 08:21:25 +0000652
653 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
654 return (_initialized);
655}
656
657// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000658// InitSpeaker
659// ----------------------------------------------------------------------------
660
pbos@webrtc.org25509882013-04-09 10:30:35 +0000661int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000662{
niklase@google.com470e71d2011-07-07 08:21:25 +0000663 CHECK_INITIALIZED();
664 return (_ptrAudioDevice->InitSpeaker());
665}
666
667// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000668// InitMicrophone
669// ----------------------------------------------------------------------------
670
pbos@webrtc.org25509882013-04-09 10:30:35 +0000671int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000672{
niklase@google.com470e71d2011-07-07 08:21:25 +0000673 CHECK_INITIALIZED();
674 return (_ptrAudioDevice->InitMicrophone());
675}
676
677// ----------------------------------------------------------------------------
678// SpeakerVolumeIsAvailable
679// ----------------------------------------------------------------------------
680
pbos@webrtc.org25509882013-04-09 10:30:35 +0000681int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000682{
niklase@google.com470e71d2011-07-07 08:21:25 +0000683 CHECK_INITIALIZED();
684
685 bool isAvailable(0);
686
687 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
688 {
689 return -1;
690 }
691
692 *available = isAvailable;
693
694 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
695 return (0);
696}
697
698// ----------------------------------------------------------------------------
699// SetSpeakerVolume
700// ----------------------------------------------------------------------------
701
pbos@webrtc.org25509882013-04-09 10:30:35 +0000702int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000703{
niklase@google.com470e71d2011-07-07 08:21:25 +0000704 CHECK_INITIALIZED();
705 return (_ptrAudioDevice->SetSpeakerVolume(volume));
706}
707
708// ----------------------------------------------------------------------------
709// SpeakerVolume
710// ----------------------------------------------------------------------------
711
pbos@webrtc.org25509882013-04-09 10:30:35 +0000712int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000713{
niklase@google.com470e71d2011-07-07 08:21:25 +0000714 CHECK_INITIALIZED();
715
pbos@webrtc.org25509882013-04-09 10:30:35 +0000716 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000717
718 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
719 {
720 return -1;
721 }
722
723 *volume = level;
724
725 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
726 return (0);
727}
728
729// ----------------------------------------------------------------------------
730// SetWaveOutVolume
731// ----------------------------------------------------------------------------
732
pbos@webrtc.org25509882013-04-09 10:30:35 +0000733int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000734{
niklase@google.com470e71d2011-07-07 08:21:25 +0000735 CHECK_INITIALIZED();
736 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
737}
738
739// ----------------------------------------------------------------------------
740// WaveOutVolume
741// ----------------------------------------------------------------------------
742
pbos@webrtc.org25509882013-04-09 10:30:35 +0000743int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000744{
niklase@google.com470e71d2011-07-07 08:21:25 +0000745 CHECK_INITIALIZED();
746
pbos@webrtc.org25509882013-04-09 10:30:35 +0000747 uint16_t volLeft(0);
748 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000749
750 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
751 {
752 return -1;
753 }
754
755 *volumeLeft = volLeft;
756 *volumeRight = volRight;
757
758 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
759 *volumeLeft, *volumeRight);
760
761 return (0);
762}
763
764// ----------------------------------------------------------------------------
765// SpeakerIsInitialized
766// ----------------------------------------------------------------------------
767
768bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
769{
niklase@google.com470e71d2011-07-07 08:21:25 +0000770 CHECK_INITIALIZED_BOOL();
771
772 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
773
774 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
775 return (isInitialized);
776}
777
778// ----------------------------------------------------------------------------
779// MicrophoneIsInitialized
780// ----------------------------------------------------------------------------
781
782bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
783{
niklase@google.com470e71d2011-07-07 08:21:25 +0000784 CHECK_INITIALIZED_BOOL();
785
786 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
787
788 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
789 return (isInitialized);
790}
791
792// ----------------------------------------------------------------------------
793// MaxSpeakerVolume
794// ----------------------------------------------------------------------------
795
pbos@webrtc.org25509882013-04-09 10:30:35 +0000796int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000797{
niklase@google.com470e71d2011-07-07 08:21:25 +0000798 CHECK_INITIALIZED();
799
pbos@webrtc.org25509882013-04-09 10:30:35 +0000800 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000801
802 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
803 {
804 return -1;
805 }
806
807 *maxVolume = maxVol;
808
809 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
810 return (0);
811}
812
813// ----------------------------------------------------------------------------
814// MinSpeakerVolume
815// ----------------------------------------------------------------------------
816
pbos@webrtc.org25509882013-04-09 10:30:35 +0000817int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000818{
niklase@google.com470e71d2011-07-07 08:21:25 +0000819 CHECK_INITIALIZED();
820
pbos@webrtc.org25509882013-04-09 10:30:35 +0000821 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000822
823 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
824 {
825 return -1;
826 }
827
828 *minVolume = minVol;
829
830 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
831 return (0);
832}
833
834// ----------------------------------------------------------------------------
835// SpeakerVolumeStepSize
836// ----------------------------------------------------------------------------
837
pbos@webrtc.org25509882013-04-09 10:30:35 +0000838int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000839{
niklase@google.com470e71d2011-07-07 08:21:25 +0000840 CHECK_INITIALIZED();
841
pbos@webrtc.org25509882013-04-09 10:30:35 +0000842 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000843
844 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
845 {
846 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
847 return -1;
848 }
849
850 *stepSize = delta;
851
852 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
853 return (0);
854}
855
856// ----------------------------------------------------------------------------
857// SpeakerMuteIsAvailable
858// ----------------------------------------------------------------------------
859
pbos@webrtc.org25509882013-04-09 10:30:35 +0000860int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000861{
niklase@google.com470e71d2011-07-07 08:21:25 +0000862 CHECK_INITIALIZED();
863
864 bool isAvailable(0);
865
866 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
867 {
868 return -1;
869 }
870
871 *available = isAvailable;
872
873 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
874 return (0);
875}
876
877// ----------------------------------------------------------------------------
878// SetSpeakerMute
879// ----------------------------------------------------------------------------
880
pbos@webrtc.org25509882013-04-09 10:30:35 +0000881int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000882{
niklase@google.com470e71d2011-07-07 08:21:25 +0000883 CHECK_INITIALIZED();
884 return (_ptrAudioDevice->SetSpeakerMute(enable));
885}
886
887// ----------------------------------------------------------------------------
888// SpeakerMute
889// ----------------------------------------------------------------------------
890
pbos@webrtc.org25509882013-04-09 10:30:35 +0000891int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000892{
niklase@google.com470e71d2011-07-07 08:21:25 +0000893 CHECK_INITIALIZED();
894
895 bool muted(false);
896
897 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
898 {
899 return -1;
900 }
901
902 *enabled = muted;
903
904 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
905 return (0);
906}
907
908// ----------------------------------------------------------------------------
909// MicrophoneMuteIsAvailable
910// ----------------------------------------------------------------------------
911
pbos@webrtc.org25509882013-04-09 10:30:35 +0000912int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000913{
niklase@google.com470e71d2011-07-07 08:21:25 +0000914 CHECK_INITIALIZED();
915
916 bool isAvailable(0);
917
918 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
919 {
920 return -1;
921 }
922
923 *available = isAvailable;
924
925 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
926 return (0);
927}
928
929// ----------------------------------------------------------------------------
930// SetMicrophoneMute
931// ----------------------------------------------------------------------------
932
pbos@webrtc.org25509882013-04-09 10:30:35 +0000933int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000934{
niklase@google.com470e71d2011-07-07 08:21:25 +0000935 CHECK_INITIALIZED();
936 return (_ptrAudioDevice->SetMicrophoneMute(enable));
937}
938
939// ----------------------------------------------------------------------------
940// MicrophoneMute
941// ----------------------------------------------------------------------------
942
pbos@webrtc.org25509882013-04-09 10:30:35 +0000943int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000944{
niklase@google.com470e71d2011-07-07 08:21:25 +0000945 CHECK_INITIALIZED();
946
947 bool muted(false);
948
949 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
950 {
951 return -1;
952 }
953
954 *enabled = muted;
955
956 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
957 return (0);
958}
959
960// ----------------------------------------------------------------------------
961// MicrophoneBoostIsAvailable
962// ----------------------------------------------------------------------------
963
pbos@webrtc.org25509882013-04-09 10:30:35 +0000964int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000965{
niklase@google.com470e71d2011-07-07 08:21:25 +0000966 CHECK_INITIALIZED();
967
968 bool isAvailable(0);
969
970 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
971 {
972 return -1;
973 }
974
975 *available = isAvailable;
976
977 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
978 return (0);
979}
980
981// ----------------------------------------------------------------------------
982// SetMicrophoneBoost
983// ----------------------------------------------------------------------------
984
pbos@webrtc.org25509882013-04-09 10:30:35 +0000985int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000986{
niklase@google.com470e71d2011-07-07 08:21:25 +0000987 CHECK_INITIALIZED();
988 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
989}
990
991// ----------------------------------------------------------------------------
992// MicrophoneBoost
993// ----------------------------------------------------------------------------
994
pbos@webrtc.org25509882013-04-09 10:30:35 +0000995int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000996{
niklase@google.com470e71d2011-07-07 08:21:25 +0000997 CHECK_INITIALIZED();
998
999 bool onOff(false);
1000
1001 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
1002 {
1003 return -1;
1004 }
1005
1006 *enabled = onOff;
1007
1008 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1009 return (0);
1010}
1011
1012// ----------------------------------------------------------------------------
1013// MicrophoneVolumeIsAvailable
1014// ----------------------------------------------------------------------------
1015
pbos@webrtc.org25509882013-04-09 10:30:35 +00001016int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001017{
niklase@google.com470e71d2011-07-07 08:21:25 +00001018 CHECK_INITIALIZED();
1019
1020 bool isAvailable(0);
1021
1022 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1023 {
1024 return -1;
1025 }
1026
1027 *available = isAvailable;
1028
1029 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1030 return (0);
1031}
1032
1033// ----------------------------------------------------------------------------
1034// SetMicrophoneVolume
1035// ----------------------------------------------------------------------------
1036
pbos@webrtc.org25509882013-04-09 10:30:35 +00001037int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001038{
niklase@google.com470e71d2011-07-07 08:21:25 +00001039 CHECK_INITIALIZED();
1040 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1041}
1042
1043// ----------------------------------------------------------------------------
1044// MicrophoneVolume
1045// ----------------------------------------------------------------------------
1046
pbos@webrtc.org25509882013-04-09 10:30:35 +00001047int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001048{
1049 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1050 CHECK_INITIALIZED();
1051
pbos@webrtc.org25509882013-04-09 10:30:35 +00001052 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001053
1054 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1055 {
1056 return -1;
1057 }
1058
1059 *volume = level;
1060
1061 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1062 return (0);
1063}
1064
1065// ----------------------------------------------------------------------------
1066// StereoRecordingIsAvailable
1067// ----------------------------------------------------------------------------
1068
pbos@webrtc.org25509882013-04-09 10:30:35 +00001069int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001070{
niklase@google.com470e71d2011-07-07 08:21:25 +00001071 CHECK_INITIALIZED();
1072
1073 bool isAvailable(0);
1074
1075 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1076 {
1077 return -1;
1078 }
1079
1080 *available = isAvailable;
1081
1082 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1083 return (0);
1084}
1085
1086// ----------------------------------------------------------------------------
1087// SetStereoRecording
1088// ----------------------------------------------------------------------------
1089
pbos@webrtc.org25509882013-04-09 10:30:35 +00001090int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001091{
niklase@google.com470e71d2011-07-07 08:21:25 +00001092 CHECK_INITIALIZED();
1093
1094 if (_ptrAudioDevice->RecordingIsInitialized())
1095 {
1096 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1097 return -1;
1098 }
1099
1100 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1101 {
1102 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1103 return -1;
1104 }
1105
pbos@webrtc.org25509882013-04-09 10:30:35 +00001106 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001107 if (enable)
1108 {
1109 nChannels = 2;
1110 }
1111 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1112
1113 return 0;
1114}
1115
1116// ----------------------------------------------------------------------------
1117// StereoRecording
1118// ----------------------------------------------------------------------------
1119
pbos@webrtc.org25509882013-04-09 10:30:35 +00001120int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001121{
niklase@google.com470e71d2011-07-07 08:21:25 +00001122 CHECK_INITIALIZED();
1123
1124 bool stereo(false);
1125
1126 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1127 {
1128 return -1;
1129 }
1130
1131 *enabled = stereo;
1132
1133 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1134 return (0);
1135}
1136
1137// ----------------------------------------------------------------------------
1138// SetRecordingChannel
1139// ----------------------------------------------------------------------------
1140
pbos@webrtc.org25509882013-04-09 10:30:35 +00001141int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001142{
1143 if (channel == kChannelBoth)
1144 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001145 }
1146 else if (channel == kChannelLeft)
1147 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001148 }
1149 else
1150 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001151 }
1152 CHECK_INITIALIZED();
1153
1154 bool stereo(false);
1155
1156 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1157 {
1158 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1159 return -1;
1160 }
1161
1162 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1163}
1164
1165// ----------------------------------------------------------------------------
1166// RecordingChannel
1167// ----------------------------------------------------------------------------
1168
pbos@webrtc.org25509882013-04-09 10:30:35 +00001169int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001170{
niklase@google.com470e71d2011-07-07 08:21:25 +00001171 CHECK_INITIALIZED();
1172
1173 ChannelType chType;
1174
1175 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1176 {
1177 return -1;
1178 }
1179
1180 *channel = chType;
1181
1182 if (*channel == kChannelBoth)
1183 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001184 }
1185 else if (*channel == kChannelLeft)
1186 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001187 }
1188 else
1189 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001190 }
1191
1192 return (0);
1193}
1194
1195// ----------------------------------------------------------------------------
1196// StereoPlayoutIsAvailable
1197// ----------------------------------------------------------------------------
1198
pbos@webrtc.org25509882013-04-09 10:30:35 +00001199int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001200{
niklase@google.com470e71d2011-07-07 08:21:25 +00001201 CHECK_INITIALIZED();
1202
1203 bool isAvailable(0);
1204
1205 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1206 {
1207 return -1;
1208 }
1209
1210 *available = isAvailable;
1211
1212 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1213 return (0);
1214}
1215
1216// ----------------------------------------------------------------------------
1217// SetStereoPlayout
1218// ----------------------------------------------------------------------------
1219
pbos@webrtc.org25509882013-04-09 10:30:35 +00001220int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001221{
niklase@google.com470e71d2011-07-07 08:21:25 +00001222 CHECK_INITIALIZED();
1223
1224 if (_ptrAudioDevice->PlayoutIsInitialized())
1225 {
1226 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1227 return -1;
1228 }
1229
1230 if (_ptrAudioDevice->SetStereoPlayout(enable))
1231 {
1232 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1233 return -1;
1234 }
1235
pbos@webrtc.org25509882013-04-09 10:30:35 +00001236 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001237 if (enable)
1238 {
1239 nChannels = 2;
1240 }
1241 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1242
1243 return 0;
1244}
1245
1246// ----------------------------------------------------------------------------
1247// StereoPlayout
1248// ----------------------------------------------------------------------------
1249
pbos@webrtc.org25509882013-04-09 10:30:35 +00001250int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001251{
niklase@google.com470e71d2011-07-07 08:21:25 +00001252 CHECK_INITIALIZED();
1253
1254 bool stereo(false);
1255
1256 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1257 {
1258 return -1;
1259 }
1260
1261 *enabled = stereo;
1262
1263 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1264 return (0);
1265}
1266
1267// ----------------------------------------------------------------------------
1268// SetAGC
1269// ----------------------------------------------------------------------------
1270
pbos@webrtc.org25509882013-04-09 10:30:35 +00001271int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001272{
niklase@google.com470e71d2011-07-07 08:21:25 +00001273 CHECK_INITIALIZED();
1274 return (_ptrAudioDevice->SetAGC(enable));
1275}
1276
1277// ----------------------------------------------------------------------------
1278// AGC
1279// ----------------------------------------------------------------------------
1280
1281bool AudioDeviceModuleImpl::AGC() const
1282{
niklase@google.com470e71d2011-07-07 08:21:25 +00001283 CHECK_INITIALIZED_BOOL();
1284 return (_ptrAudioDevice->AGC());
1285}
1286
1287// ----------------------------------------------------------------------------
1288// PlayoutIsAvailable
1289// ----------------------------------------------------------------------------
1290
pbos@webrtc.org25509882013-04-09 10:30:35 +00001291int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001292{
niklase@google.com470e71d2011-07-07 08:21:25 +00001293 CHECK_INITIALIZED();
1294
1295 bool isAvailable(0);
1296
1297 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1298 {
1299 return -1;
1300 }
1301
1302 *available = isAvailable;
1303
1304 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1305 return (0);
1306}
1307
1308// ----------------------------------------------------------------------------
1309// RecordingIsAvailable
1310// ----------------------------------------------------------------------------
1311
pbos@webrtc.org25509882013-04-09 10:30:35 +00001312int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001313{
niklase@google.com470e71d2011-07-07 08:21:25 +00001314 CHECK_INITIALIZED();
1315
1316 bool isAvailable(0);
1317
1318 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1319 {
1320 return -1;
1321 }
1322
1323 *available = isAvailable;
1324
1325 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1326 return (0);
1327}
1328
1329// ----------------------------------------------------------------------------
1330// MaxMicrophoneVolume
1331// ----------------------------------------------------------------------------
1332
pbos@webrtc.org25509882013-04-09 10:30:35 +00001333int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001334{
1335 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1336 CHECK_INITIALIZED();
1337
pbos@webrtc.org25509882013-04-09 10:30:35 +00001338 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001339
1340 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1341 {
1342 return -1;
1343 }
1344
1345 *maxVolume = maxVol;
1346
1347 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1348 return (0);
1349}
1350
1351// ----------------------------------------------------------------------------
1352// MinMicrophoneVolume
1353// ----------------------------------------------------------------------------
1354
pbos@webrtc.org25509882013-04-09 10:30:35 +00001355int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001356{
niklase@google.com470e71d2011-07-07 08:21:25 +00001357 CHECK_INITIALIZED();
1358
pbos@webrtc.org25509882013-04-09 10:30:35 +00001359 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001360
1361 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1362 {
1363 return -1;
1364 }
1365
1366 *minVolume = minVol;
1367
1368 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1369 return (0);
1370}
1371
1372// ----------------------------------------------------------------------------
1373// MicrophoneVolumeStepSize
1374// ----------------------------------------------------------------------------
1375
pbos@webrtc.org25509882013-04-09 10:30:35 +00001376int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001377{
niklase@google.com470e71d2011-07-07 08:21:25 +00001378 CHECK_INITIALIZED();
1379
pbos@webrtc.org25509882013-04-09 10:30:35 +00001380 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001381
1382 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1383 {
1384 return -1;
1385 }
1386
1387 *stepSize = delta;
1388
1389 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1390 return (0);
1391}
1392
1393// ----------------------------------------------------------------------------
1394// PlayoutDevices
1395// ----------------------------------------------------------------------------
1396
pbos@webrtc.org25509882013-04-09 10:30:35 +00001397int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001398{
niklase@google.com470e71d2011-07-07 08:21:25 +00001399 CHECK_INITIALIZED();
1400
pbos@webrtc.org25509882013-04-09 10:30:35 +00001401 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001402
1403 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001404 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001405}
1406
1407// ----------------------------------------------------------------------------
1408// SetPlayoutDevice I (II)
1409// ----------------------------------------------------------------------------
1410
pbos@webrtc.org25509882013-04-09 10:30:35 +00001411int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001412{
niklase@google.com470e71d2011-07-07 08:21:25 +00001413 CHECK_INITIALIZED();
1414 return (_ptrAudioDevice->SetPlayoutDevice(index));
1415}
1416
1417// ----------------------------------------------------------------------------
1418// SetPlayoutDevice II (II)
1419// ----------------------------------------------------------------------------
1420
pbos@webrtc.org25509882013-04-09 10:30:35 +00001421int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001422{
1423 if (device == kDefaultDevice)
1424 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001425 }
1426 else
1427 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001428 }
1429 CHECK_INITIALIZED();
1430
1431 return (_ptrAudioDevice->SetPlayoutDevice(device));
1432}
1433
1434// ----------------------------------------------------------------------------
1435// PlayoutDeviceName
1436// ----------------------------------------------------------------------------
1437
pbos@webrtc.org25509882013-04-09 10:30:35 +00001438int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1439 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001440 char name[kAdmMaxDeviceNameSize],
1441 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001442{
niklase@google.com470e71d2011-07-07 08:21:25 +00001443 CHECK_INITIALIZED();
1444
1445 if (name == NULL)
1446 {
1447 _lastError = kAdmErrArgument;
1448 return -1;
1449 }
1450
1451 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1452 {
1453 return -1;
1454 }
1455
1456 if (name != NULL)
1457 {
1458 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1459 }
1460 if (guid != NULL)
1461 {
1462 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1463 }
1464
1465 return (0);
1466}
1467
1468// ----------------------------------------------------------------------------
1469// RecordingDeviceName
1470// ----------------------------------------------------------------------------
1471
pbos@webrtc.org25509882013-04-09 10:30:35 +00001472int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1473 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001474 char name[kAdmMaxDeviceNameSize],
1475 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001476{
niklase@google.com470e71d2011-07-07 08:21:25 +00001477 CHECK_INITIALIZED();
1478
1479 if (name == NULL)
1480 {
1481 _lastError = kAdmErrArgument;
1482 return -1;
1483 }
1484
1485 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1486 {
1487 return -1;
1488 }
1489
1490 if (name != NULL)
1491 {
1492 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1493 }
1494 if (guid != NULL)
1495 {
1496 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1497 }
1498
1499 return (0);
1500}
1501
1502// ----------------------------------------------------------------------------
1503// RecordingDevices
1504// ----------------------------------------------------------------------------
1505
pbos@webrtc.org25509882013-04-09 10:30:35 +00001506int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001507{
niklase@google.com470e71d2011-07-07 08:21:25 +00001508 CHECK_INITIALIZED();
1509
pbos@webrtc.org25509882013-04-09 10:30:35 +00001510 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001511
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001512 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1513 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001514 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001515}
1516
1517// ----------------------------------------------------------------------------
1518// SetRecordingDevice I (II)
1519// ----------------------------------------------------------------------------
1520
pbos@webrtc.org25509882013-04-09 10:30:35 +00001521int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001522{
niklase@google.com470e71d2011-07-07 08:21:25 +00001523 CHECK_INITIALIZED();
1524 return (_ptrAudioDevice->SetRecordingDevice(index));
1525}
1526
1527// ----------------------------------------------------------------------------
1528// SetRecordingDevice II (II)
1529// ----------------------------------------------------------------------------
1530
pbos@webrtc.org25509882013-04-09 10:30:35 +00001531int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001532{
1533 if (device == kDefaultDevice)
1534 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001535 }
1536 else
1537 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001538 }
1539 CHECK_INITIALIZED();
1540
1541 return (_ptrAudioDevice->SetRecordingDevice(device));
1542}
1543
1544// ----------------------------------------------------------------------------
1545// InitPlayout
1546// ----------------------------------------------------------------------------
1547
pbos@webrtc.org25509882013-04-09 10:30:35 +00001548int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001549{
niklase@google.com470e71d2011-07-07 08:21:25 +00001550 CHECK_INITIALIZED();
1551 _audioDeviceBuffer.InitPlayout();
1552 return (_ptrAudioDevice->InitPlayout());
1553}
1554
1555// ----------------------------------------------------------------------------
1556// InitRecording
1557// ----------------------------------------------------------------------------
1558
pbos@webrtc.org25509882013-04-09 10:30:35 +00001559int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001560{
niklase@google.com470e71d2011-07-07 08:21:25 +00001561 CHECK_INITIALIZED();
1562 _audioDeviceBuffer.InitRecording();
1563 return (_ptrAudioDevice->InitRecording());
1564}
1565
1566// ----------------------------------------------------------------------------
1567// PlayoutIsInitialized
1568// ----------------------------------------------------------------------------
1569
1570bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1571{
niklase@google.com470e71d2011-07-07 08:21:25 +00001572 CHECK_INITIALIZED_BOOL();
1573 return (_ptrAudioDevice->PlayoutIsInitialized());
1574}
1575
1576// ----------------------------------------------------------------------------
1577// RecordingIsInitialized
1578// ----------------------------------------------------------------------------
1579
1580bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1581{
niklase@google.com470e71d2011-07-07 08:21:25 +00001582 CHECK_INITIALIZED_BOOL();
1583 return (_ptrAudioDevice->RecordingIsInitialized());
1584}
1585
1586// ----------------------------------------------------------------------------
1587// StartPlayout
1588// ----------------------------------------------------------------------------
1589
pbos@webrtc.org25509882013-04-09 10:30:35 +00001590int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001591{
niklase@google.com470e71d2011-07-07 08:21:25 +00001592 CHECK_INITIALIZED();
1593 return (_ptrAudioDevice->StartPlayout());
1594}
1595
1596// ----------------------------------------------------------------------------
1597// StopPlayout
1598// ----------------------------------------------------------------------------
1599
pbos@webrtc.org25509882013-04-09 10:30:35 +00001600int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001601{
niklase@google.com470e71d2011-07-07 08:21:25 +00001602 CHECK_INITIALIZED();
1603 return (_ptrAudioDevice->StopPlayout());
1604}
1605
1606// ----------------------------------------------------------------------------
1607// Playing
1608// ----------------------------------------------------------------------------
1609
1610bool AudioDeviceModuleImpl::Playing() const
1611{
niklase@google.com470e71d2011-07-07 08:21:25 +00001612 CHECK_INITIALIZED_BOOL();
1613 return (_ptrAudioDevice->Playing());
1614}
1615
1616// ----------------------------------------------------------------------------
1617// StartRecording
1618// ----------------------------------------------------------------------------
1619
pbos@webrtc.org25509882013-04-09 10:30:35 +00001620int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001621{
niklase@google.com470e71d2011-07-07 08:21:25 +00001622 CHECK_INITIALIZED();
1623 return (_ptrAudioDevice->StartRecording());
1624}
1625// ----------------------------------------------------------------------------
1626// StopRecording
1627// ----------------------------------------------------------------------------
1628
pbos@webrtc.org25509882013-04-09 10:30:35 +00001629int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001630{
niklase@google.com470e71d2011-07-07 08:21:25 +00001631 CHECK_INITIALIZED();
1632 return (_ptrAudioDevice->StopRecording());
1633}
1634
1635// ----------------------------------------------------------------------------
1636// Recording
1637// ----------------------------------------------------------------------------
1638
1639bool AudioDeviceModuleImpl::Recording() const
1640{
niklase@google.com470e71d2011-07-07 08:21:25 +00001641 CHECK_INITIALIZED_BOOL();
1642 return (_ptrAudioDevice->Recording());
1643}
1644
1645// ----------------------------------------------------------------------------
1646// RegisterEventObserver
1647// ----------------------------------------------------------------------------
1648
pbos@webrtc.org25509882013-04-09 10:30:35 +00001649int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001650{
niklase@google.com470e71d2011-07-07 08:21:25 +00001651
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001652 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001653 _ptrCbAudioDeviceObserver = eventCallback;
1654
1655 return 0;
1656}
1657
1658// ----------------------------------------------------------------------------
1659// RegisterAudioCallback
1660// ----------------------------------------------------------------------------
1661
pbos@webrtc.org25509882013-04-09 10:30:35 +00001662int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001663{
niklase@google.com470e71d2011-07-07 08:21:25 +00001664
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001665 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001666 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1667
1668 return 0;
1669}
1670
1671// ----------------------------------------------------------------------------
1672// StartRawInputFileRecording
1673// ----------------------------------------------------------------------------
1674
pbos@webrtc.org25509882013-04-09 10:30:35 +00001675int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001676 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001677{
niklase@google.com470e71d2011-07-07 08:21:25 +00001678 CHECK_INITIALIZED();
1679
1680 if (NULL == pcmFileNameUTF8)
1681 {
1682 return -1;
1683 }
1684
1685 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1686}
1687
1688// ----------------------------------------------------------------------------
1689// StopRawInputFileRecording
1690// ----------------------------------------------------------------------------
1691
pbos@webrtc.org25509882013-04-09 10:30:35 +00001692int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001693{
niklase@google.com470e71d2011-07-07 08:21:25 +00001694 CHECK_INITIALIZED();
1695
1696 return (_audioDeviceBuffer.StopInputFileRecording());
1697}
1698
1699// ----------------------------------------------------------------------------
1700// StartRawOutputFileRecording
1701// ----------------------------------------------------------------------------
1702
pbos@webrtc.org25509882013-04-09 10:30:35 +00001703int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001704 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001705{
niklase@google.com470e71d2011-07-07 08:21:25 +00001706 CHECK_INITIALIZED();
1707
1708 if (NULL == pcmFileNameUTF8)
1709 {
1710 return -1;
1711 }
1712
1713 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1714}
1715
1716// ----------------------------------------------------------------------------
1717// StopRawOutputFileRecording
1718// ----------------------------------------------------------------------------
1719
pbos@webrtc.org25509882013-04-09 10:30:35 +00001720int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001721{
niklase@google.com470e71d2011-07-07 08:21:25 +00001722 CHECK_INITIALIZED();
1723
1724 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001725}
1726
1727// ----------------------------------------------------------------------------
1728// SetPlayoutBuffer
1729// ----------------------------------------------------------------------------
1730
pbos@webrtc.org25509882013-04-09 10:30:35 +00001731int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001732{
niklase@google.com470e71d2011-07-07 08:21:25 +00001733 CHECK_INITIALIZED();
1734
1735 if (_ptrAudioDevice->PlayoutIsInitialized())
1736 {
1737 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1738 return -1;
1739 }
1740
pbos@webrtc.org25509882013-04-09 10:30:35 +00001741 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001742
1743 if (kFixedBufferSize == type)
1744 {
1745 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1746 {
1747 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1748 return -1;
1749 }
1750 }
1751
1752 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1753 {
1754 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1755 }
1756
1757 return ret;
1758}
1759
1760// ----------------------------------------------------------------------------
1761// PlayoutBuffer
1762// ----------------------------------------------------------------------------
1763
pbos@webrtc.org25509882013-04-09 10:30:35 +00001764int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001765{
niklase@google.com470e71d2011-07-07 08:21:25 +00001766 CHECK_INITIALIZED();
1767
1768 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001769 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001770
1771 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1772 {
1773 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1774 return -1;
1775 }
1776
1777 *type = bufType;
1778 *sizeMS = size;
1779
1780 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1781 return (0);
1782}
1783
1784// ----------------------------------------------------------------------------
1785// PlayoutDelay
1786// ----------------------------------------------------------------------------
1787
pbos@webrtc.org25509882013-04-09 10:30:35 +00001788int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001789{
1790 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1791 CHECK_INITIALIZED();
1792
pbos@webrtc.org25509882013-04-09 10:30:35 +00001793 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001794
1795 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1796 {
1797 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1798 return -1;
1799 }
1800
1801 *delayMS = delay;
1802
1803 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1804 return (0);
1805}
1806
1807// ----------------------------------------------------------------------------
1808// RecordingDelay
1809// ----------------------------------------------------------------------------
1810
pbos@webrtc.org25509882013-04-09 10:30:35 +00001811int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001812{
1813 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1814 CHECK_INITIALIZED();
1815
pbos@webrtc.org25509882013-04-09 10:30:35 +00001816 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001817
1818 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1819 {
1820 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1821 return -1;
1822 }
1823
1824 *delayMS = delay;
1825
1826 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1827 return (0);
1828}
1829
1830// ----------------------------------------------------------------------------
1831// CPULoad
1832// ----------------------------------------------------------------------------
1833
pbos@webrtc.org25509882013-04-09 10:30:35 +00001834int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001835{
niklase@google.com470e71d2011-07-07 08:21:25 +00001836 CHECK_INITIALIZED();
1837
pbos@webrtc.org25509882013-04-09 10:30:35 +00001838 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001839
1840 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1841 {
1842 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1843 return -1;
1844 }
1845
1846 *load = cpuLoad;
1847
1848 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1849 return (0);
1850}
1851
1852// ----------------------------------------------------------------------------
1853// SetRecordingSampleRate
1854// ----------------------------------------------------------------------------
1855
pbos@webrtc.org25509882013-04-09 10:30:35 +00001856int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001857{
niklase@google.com470e71d2011-07-07 08:21:25 +00001858 CHECK_INITIALIZED();
1859
1860 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1861 {
1862 return -1;
1863 }
1864
1865 return (0);
1866}
1867
1868// ----------------------------------------------------------------------------
1869// RecordingSampleRate
1870// ----------------------------------------------------------------------------
1871
pbos@webrtc.org25509882013-04-09 10:30:35 +00001872int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001873{
niklase@google.com470e71d2011-07-07 08:21:25 +00001874 CHECK_INITIALIZED();
1875
pbos@webrtc.org25509882013-04-09 10:30:35 +00001876 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001877
1878 if (sampleRate == -1)
1879 {
1880 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1881 return -1;
1882 }
1883
1884 *samplesPerSec = sampleRate;
1885
1886 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1887 return (0);
1888}
1889
1890// ----------------------------------------------------------------------------
1891// SetPlayoutSampleRate
1892// ----------------------------------------------------------------------------
1893
pbos@webrtc.org25509882013-04-09 10:30:35 +00001894int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001895{
niklase@google.com470e71d2011-07-07 08:21:25 +00001896 CHECK_INITIALIZED();
1897
1898 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1899 {
1900 return -1;
1901 }
1902
1903 return (0);
1904}
1905
1906// ----------------------------------------------------------------------------
1907// PlayoutSampleRate
1908// ----------------------------------------------------------------------------
1909
pbos@webrtc.org25509882013-04-09 10:30:35 +00001910int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001911{
niklase@google.com470e71d2011-07-07 08:21:25 +00001912 CHECK_INITIALIZED();
1913
pbos@webrtc.org25509882013-04-09 10:30:35 +00001914 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001915
1916 if (sampleRate == -1)
1917 {
1918 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1919 return -1;
1920 }
1921
1922 *samplesPerSec = sampleRate;
1923
1924 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1925 return (0);
1926}
1927
1928// ----------------------------------------------------------------------------
1929// ResetAudioDevice
1930// ----------------------------------------------------------------------------
1931
pbos@webrtc.org25509882013-04-09 10:30:35 +00001932int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001933{
niklase@google.com470e71d2011-07-07 08:21:25 +00001934 CHECK_INITIALIZED();
1935
1936
1937 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1938 {
1939 return -1;
1940 }
1941
1942 return (0);
1943}
1944
1945// ----------------------------------------------------------------------------
1946// SetLoudspeakerStatus
1947// ----------------------------------------------------------------------------
1948
pbos@webrtc.org25509882013-04-09 10:30:35 +00001949int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001950{
niklase@google.com470e71d2011-07-07 08:21:25 +00001951 CHECK_INITIALIZED();
1952
1953 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1954 {
1955 return -1;
1956 }
1957
1958 return 0;
1959}
1960
1961// ----------------------------------------------------------------------------
1962// GetLoudspeakerStatus
1963// ----------------------------------------------------------------------------
1964
pbos@webrtc.org25509882013-04-09 10:30:35 +00001965int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001966{
niklase@google.com470e71d2011-07-07 08:21:25 +00001967 CHECK_INITIALIZED();
1968
1969 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1970 {
1971 return -1;
1972 }
1973
1974 return 0;
1975}
1976
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001977int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1978{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001979 CHECK_INITIALIZED();
1980
1981 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1982}
1983
1984bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1985{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001986 CHECK_INITIALIZED_BOOL();
1987
1988 return _ptrAudioDevice->BuiltInAECIsEnabled();
1989}
1990
niklase@google.com470e71d2011-07-07 08:21:25 +00001991// ============================================================================
1992// Private Methods
1993// ============================================================================
1994
1995// ----------------------------------------------------------------------------
1996// Platform
1997// ----------------------------------------------------------------------------
1998
1999AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
2000{
2001 return _platformType;
2002}
2003
2004// ----------------------------------------------------------------------------
2005// PlatformAudioLayer
2006// ----------------------------------------------------------------------------
2007
2008AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2009{
niklase@google.com470e71d2011-07-07 08:21:25 +00002010
2011 switch (_platformAudioLayer)
2012 {
2013 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002014 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2015 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002016 break;
2017 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002018 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2019 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002020 break;
2021 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002022 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2023 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002024 break;
2025 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002026 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2027 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002028 break;
2029 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002030 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2031 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002032 break;
2033 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002034 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2035 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002036 break;
2037 }
2038
2039 return _platformAudioLayer;
2040}
2041
2042} // namespace webrtc