blob: 826a89d2f1248a7a71dabe92081b44a1ed174d2a [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());
leozwang@google.com39f20512011-07-15 16:29:40 +0000281 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
282 "Android OpenSLES Audio APIs will be utilized");
braveyao@webrtc.org8a2c84f2014-08-18 03:02:42 +0000283#else
284 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(Id());
285 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
286 "Android JNI Audio APIs will be utilized");
287#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000288 }
289
290 if (ptrAudioDevice != NULL)
291 {
292 // Create the Android implementation of the Device Utility.
293 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
294 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000295 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
297 // Create the *Linux* implementation of the Audio Device
298 //
299#elif defined(WEBRTC_LINUX)
300 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
301 {
302#if defined(LINUX_PULSE)
303 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
304
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000305 // create *Linux PulseAudio* implementation
306 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
307 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000308 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000309 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000310 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
311 }
312 else
313 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000314 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000315#endif
316#if defined(LINUX_ALSA)
317 // create *Linux ALSA Audio* implementation
318 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
319 if (ptrAudioDevice != NULL)
320 {
321 // Pulse Audio was not supported => revert to ALSA instead
322 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
323 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
324 }
325#endif
326#if defined(LINUX_PULSE)
327 }
328#endif
329 }
330 else if (audioLayer == kLinuxAlsaAudio)
331 {
332#if defined(LINUX_ALSA)
333 // create *Linux ALSA Audio* implementation
334 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
335 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
336#endif
337 }
338
339 if (ptrAudioDevice != NULL)
340 {
341 // Create the Linux implementation of the Device Utility.
342 // This class is independent of the selected audio layer
343 // for Linux.
344 //
345 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
346 }
347#endif // #if defined(WEBRTC_LINUX)
348
349 // Create the *iPhone* implementation of the Audio Device
350 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000351#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000352 if (audioLayer == kPlatformDefaultAudio)
353 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000354 // Create iOS Audio Device implementation.
355 ptrAudioDevice = new AudioDeviceIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
357 }
358
359 if (ptrAudioDevice != NULL)
360 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000361 // Create iOS Device Utility implementation.
362 ptrAudioDeviceUtility = new AudioDeviceUtilityIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000363 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000364 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000365
366 // Create the *Mac* implementation of the Audio Device
367 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000368#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000369 if (audioLayer == kPlatformDefaultAudio)
370 {
371 // Create *Mac Audio* implementation
372 ptrAudioDevice = new AudioDeviceMac(Id());
373 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
374 }
375
376 if (ptrAudioDevice != NULL)
377 {
378 // Create the Mac implementation of the Device Utility.
379 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
380 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000381#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
383 // Create the *Dummy* implementation of the Audio Device
384 // Available for all platforms
385 //
386 if (audioLayer == kDummyAudio)
387 {
388 // Create *Dummy Audio* implementation
389 assert(!ptrAudioDevice);
390 ptrAudioDevice = new AudioDeviceDummy(Id());
391 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
392
393 if (ptrAudioDevice != NULL)
394 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000395 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000396 }
397 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000398#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000399
400 if (ptrAudioDevice == NULL)
401 {
402 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
403 return -1;
404 }
405
406 if (ptrAudioDeviceUtility == NULL)
407 {
408 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
409 return -1;
410 }
411
412 // Store valid output pointers
413 //
414 _ptrAudioDevice = ptrAudioDevice;
415 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
416
417 return 0;
418}
419
420// ----------------------------------------------------------------------------
421// AttachAudioBuffer
422//
423// Install "bridge" between the platform implemetation and the generic
424// implementation. The "child" shall set the native sampling rate and the
425// number of channels in this function call.
426// ----------------------------------------------------------------------------
427
pbos@webrtc.org25509882013-04-09 10:30:35 +0000428int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000429{
430 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
431
432 _audioDeviceBuffer.SetId(_id);
433 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
434 return 0;
435}
436
437// ----------------------------------------------------------------------------
438// ~AudioDeviceModuleImpl - dtor
439// ----------------------------------------------------------------------------
440
441AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
442{
443 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000444
445 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000446 {
henrika@google.com73d65512011-09-07 15:11:18 +0000447 delete _ptrAudioDevice;
448 _ptrAudioDevice = NULL;
449 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000450
henrika@google.com73d65512011-09-07 15:11:18 +0000451 if (_ptrAudioDeviceUtility)
452 {
453 delete _ptrAudioDeviceUtility;
454 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000455 }
456
457 delete &_critSect;
458 delete &_critSectEventCb;
459 delete &_critSectAudioCb;
460}
461
462// ============================================================================
463// Module
464// ============================================================================
465
466// ----------------------------------------------------------------------------
467// Module::ChangeUniqueId
468// ----------------------------------------------------------------------------
469
pbos@webrtc.org25509882013-04-09 10:30:35 +0000470int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
niklase@google.com470e71d2011-07-07 08:21:25 +0000471{
niklase@google.com470e71d2011-07-07 08:21:25 +0000472 _id = id;
473 return 0;
474}
475
476// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000477// Module::TimeUntilNextProcess
478//
479// Returns the number of milliseconds until the module want a worker thread
480// to call Process().
481// ----------------------------------------------------------------------------
482
pbos@webrtc.org25509882013-04-09 10:30:35 +0000483int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000484{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000485 uint32_t now = AudioDeviceUtility::GetTimeInMS();
486 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000487 return (deltaProcess);
488}
489
490// ----------------------------------------------------------------------------
491// Module::Process
492//
493// Check for posted error and warning reports. Generate callbacks if
494// new reports exists.
495// ----------------------------------------------------------------------------
496
pbos@webrtc.org25509882013-04-09 10:30:35 +0000497int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000498{
niklase@google.com470e71d2011-07-07 08:21:25 +0000499
500 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
501
502 // kPlayoutWarning
503 if (_ptrAudioDevice->PlayoutWarning())
504 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000505 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000506 if (_ptrCbAudioDeviceObserver)
507 {
508 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
509 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
510 }
511 _ptrAudioDevice->ClearPlayoutWarning();
512 }
513
514 // kPlayoutError
515 if (_ptrAudioDevice->PlayoutError())
516 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000517 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000518 if (_ptrCbAudioDeviceObserver)
519 {
520 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
521 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
522 }
523 _ptrAudioDevice->ClearPlayoutError();
524 }
525
526 // kRecordingWarning
527 if (_ptrAudioDevice->RecordingWarning())
528 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000529 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000530 if (_ptrCbAudioDeviceObserver)
531 {
532 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
533 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
534 }
535 _ptrAudioDevice->ClearRecordingWarning();
536 }
537
538 // kRecordingError
539 if (_ptrAudioDevice->RecordingError())
540 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000541 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000542 if (_ptrCbAudioDeviceObserver)
543 {
544 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
545 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
546 }
547 _ptrAudioDevice->ClearRecordingError();
548 }
549
550 return 0;
551}
552
553// ============================================================================
554// Public API
555// ============================================================================
556
557// ----------------------------------------------------------------------------
558// ActiveAudioLayer
559// ----------------------------------------------------------------------------
560
pbos@webrtc.org25509882013-04-09 10:30:35 +0000561int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000562{
niklase@google.com470e71d2011-07-07 08:21:25 +0000563
564 AudioLayer activeAudio;
565
566 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
567 {
568 return -1;
569 }
570
571 *audioLayer = activeAudio;
572
573 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
574 {
575 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
576 }
577 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
578 {
579 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
580 }
581 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
582 {
583 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
584 }
585 else
586 {
587 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
588 }
589
590 return 0;
591}
592
593// ----------------------------------------------------------------------------
594// LastError
595// ----------------------------------------------------------------------------
596
597AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
598{
599 return _lastError;
600}
601
602// ----------------------------------------------------------------------------
603// Init
604// ----------------------------------------------------------------------------
605
pbos@webrtc.org25509882013-04-09 10:30:35 +0000606int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000607{
niklase@google.com470e71d2011-07-07 08:21:25 +0000608
609 if (_initialized)
610 return 0;
611
612 if (!_ptrAudioDeviceUtility)
613 return -1;
614
615 if (!_ptrAudioDevice)
616 return -1;
617
618 _ptrAudioDeviceUtility->Init();
619
620 if (_ptrAudioDevice->Init() == -1)
621 {
622 return -1;
623 }
624
625 _initialized = true;
626 return 0;
627}
628
629// ----------------------------------------------------------------------------
630// Terminate
631// ----------------------------------------------------------------------------
632
pbos@webrtc.org25509882013-04-09 10:30:35 +0000633int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000634{
niklase@google.com470e71d2011-07-07 08:21:25 +0000635
636 if (!_initialized)
637 return 0;
638
639 if (_ptrAudioDevice->Terminate() == -1)
640 {
641 return -1;
642 }
643
644 _initialized = false;
645 return 0;
646}
647
648// ----------------------------------------------------------------------------
649// Initialized
650// ----------------------------------------------------------------------------
651
652bool AudioDeviceModuleImpl::Initialized() const
653{
niklase@google.com470e71d2011-07-07 08:21:25 +0000654
655 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
656 return (_initialized);
657}
658
659// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000660// InitSpeaker
661// ----------------------------------------------------------------------------
662
pbos@webrtc.org25509882013-04-09 10:30:35 +0000663int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000664{
niklase@google.com470e71d2011-07-07 08:21:25 +0000665 CHECK_INITIALIZED();
666 return (_ptrAudioDevice->InitSpeaker());
667}
668
669// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000670// InitMicrophone
671// ----------------------------------------------------------------------------
672
pbos@webrtc.org25509882013-04-09 10:30:35 +0000673int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000674{
niklase@google.com470e71d2011-07-07 08:21:25 +0000675 CHECK_INITIALIZED();
676 return (_ptrAudioDevice->InitMicrophone());
677}
678
679// ----------------------------------------------------------------------------
680// SpeakerVolumeIsAvailable
681// ----------------------------------------------------------------------------
682
pbos@webrtc.org25509882013-04-09 10:30:35 +0000683int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000684{
niklase@google.com470e71d2011-07-07 08:21:25 +0000685 CHECK_INITIALIZED();
686
687 bool isAvailable(0);
688
689 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
690 {
691 return -1;
692 }
693
694 *available = isAvailable;
695
696 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
697 return (0);
698}
699
700// ----------------------------------------------------------------------------
701// SetSpeakerVolume
702// ----------------------------------------------------------------------------
703
pbos@webrtc.org25509882013-04-09 10:30:35 +0000704int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000705{
niklase@google.com470e71d2011-07-07 08:21:25 +0000706 CHECK_INITIALIZED();
707 return (_ptrAudioDevice->SetSpeakerVolume(volume));
708}
709
710// ----------------------------------------------------------------------------
711// SpeakerVolume
712// ----------------------------------------------------------------------------
713
pbos@webrtc.org25509882013-04-09 10:30:35 +0000714int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000715{
niklase@google.com470e71d2011-07-07 08:21:25 +0000716 CHECK_INITIALIZED();
717
pbos@webrtc.org25509882013-04-09 10:30:35 +0000718 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000719
720 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
721 {
722 return -1;
723 }
724
725 *volume = level;
726
727 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
728 return (0);
729}
730
731// ----------------------------------------------------------------------------
732// SetWaveOutVolume
733// ----------------------------------------------------------------------------
734
pbos@webrtc.org25509882013-04-09 10:30:35 +0000735int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000736{
niklase@google.com470e71d2011-07-07 08:21:25 +0000737 CHECK_INITIALIZED();
738 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
739}
740
741// ----------------------------------------------------------------------------
742// WaveOutVolume
743// ----------------------------------------------------------------------------
744
pbos@webrtc.org25509882013-04-09 10:30:35 +0000745int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000746{
niklase@google.com470e71d2011-07-07 08:21:25 +0000747 CHECK_INITIALIZED();
748
pbos@webrtc.org25509882013-04-09 10:30:35 +0000749 uint16_t volLeft(0);
750 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000751
752 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
753 {
754 return -1;
755 }
756
757 *volumeLeft = volLeft;
758 *volumeRight = volRight;
759
760 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
761 *volumeLeft, *volumeRight);
762
763 return (0);
764}
765
766// ----------------------------------------------------------------------------
767// SpeakerIsInitialized
768// ----------------------------------------------------------------------------
769
770bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
771{
niklase@google.com470e71d2011-07-07 08:21:25 +0000772 CHECK_INITIALIZED_BOOL();
773
774 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
775
776 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
777 return (isInitialized);
778}
779
780// ----------------------------------------------------------------------------
781// MicrophoneIsInitialized
782// ----------------------------------------------------------------------------
783
784bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
785{
niklase@google.com470e71d2011-07-07 08:21:25 +0000786 CHECK_INITIALIZED_BOOL();
787
788 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
789
790 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
791 return (isInitialized);
792}
793
794// ----------------------------------------------------------------------------
795// MaxSpeakerVolume
796// ----------------------------------------------------------------------------
797
pbos@webrtc.org25509882013-04-09 10:30:35 +0000798int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000799{
niklase@google.com470e71d2011-07-07 08:21:25 +0000800 CHECK_INITIALIZED();
801
pbos@webrtc.org25509882013-04-09 10:30:35 +0000802 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000803
804 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
805 {
806 return -1;
807 }
808
809 *maxVolume = maxVol;
810
811 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
812 return (0);
813}
814
815// ----------------------------------------------------------------------------
816// MinSpeakerVolume
817// ----------------------------------------------------------------------------
818
pbos@webrtc.org25509882013-04-09 10:30:35 +0000819int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000820{
niklase@google.com470e71d2011-07-07 08:21:25 +0000821 CHECK_INITIALIZED();
822
pbos@webrtc.org25509882013-04-09 10:30:35 +0000823 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000824
825 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
826 {
827 return -1;
828 }
829
830 *minVolume = minVol;
831
832 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
833 return (0);
834}
835
836// ----------------------------------------------------------------------------
837// SpeakerVolumeStepSize
838// ----------------------------------------------------------------------------
839
pbos@webrtc.org25509882013-04-09 10:30:35 +0000840int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000841{
niklase@google.com470e71d2011-07-07 08:21:25 +0000842 CHECK_INITIALIZED();
843
pbos@webrtc.org25509882013-04-09 10:30:35 +0000844 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000845
846 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
847 {
848 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
849 return -1;
850 }
851
852 *stepSize = delta;
853
854 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
855 return (0);
856}
857
858// ----------------------------------------------------------------------------
859// SpeakerMuteIsAvailable
860// ----------------------------------------------------------------------------
861
pbos@webrtc.org25509882013-04-09 10:30:35 +0000862int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000863{
niklase@google.com470e71d2011-07-07 08:21:25 +0000864 CHECK_INITIALIZED();
865
866 bool isAvailable(0);
867
868 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
869 {
870 return -1;
871 }
872
873 *available = isAvailable;
874
875 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
876 return (0);
877}
878
879// ----------------------------------------------------------------------------
880// SetSpeakerMute
881// ----------------------------------------------------------------------------
882
pbos@webrtc.org25509882013-04-09 10:30:35 +0000883int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000884{
niklase@google.com470e71d2011-07-07 08:21:25 +0000885 CHECK_INITIALIZED();
886 return (_ptrAudioDevice->SetSpeakerMute(enable));
887}
888
889// ----------------------------------------------------------------------------
890// SpeakerMute
891// ----------------------------------------------------------------------------
892
pbos@webrtc.org25509882013-04-09 10:30:35 +0000893int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000894{
niklase@google.com470e71d2011-07-07 08:21:25 +0000895 CHECK_INITIALIZED();
896
897 bool muted(false);
898
899 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
900 {
901 return -1;
902 }
903
904 *enabled = muted;
905
906 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
907 return (0);
908}
909
910// ----------------------------------------------------------------------------
911// MicrophoneMuteIsAvailable
912// ----------------------------------------------------------------------------
913
pbos@webrtc.org25509882013-04-09 10:30:35 +0000914int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000915{
niklase@google.com470e71d2011-07-07 08:21:25 +0000916 CHECK_INITIALIZED();
917
918 bool isAvailable(0);
919
920 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
921 {
922 return -1;
923 }
924
925 *available = isAvailable;
926
927 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
928 return (0);
929}
930
931// ----------------------------------------------------------------------------
932// SetMicrophoneMute
933// ----------------------------------------------------------------------------
934
pbos@webrtc.org25509882013-04-09 10:30:35 +0000935int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000936{
niklase@google.com470e71d2011-07-07 08:21:25 +0000937 CHECK_INITIALIZED();
938 return (_ptrAudioDevice->SetMicrophoneMute(enable));
939}
940
941// ----------------------------------------------------------------------------
942// MicrophoneMute
943// ----------------------------------------------------------------------------
944
pbos@webrtc.org25509882013-04-09 10:30:35 +0000945int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000946{
niklase@google.com470e71d2011-07-07 08:21:25 +0000947 CHECK_INITIALIZED();
948
949 bool muted(false);
950
951 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
952 {
953 return -1;
954 }
955
956 *enabled = muted;
957
958 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
959 return (0);
960}
961
962// ----------------------------------------------------------------------------
963// MicrophoneBoostIsAvailable
964// ----------------------------------------------------------------------------
965
pbos@webrtc.org25509882013-04-09 10:30:35 +0000966int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000967{
niklase@google.com470e71d2011-07-07 08:21:25 +0000968 CHECK_INITIALIZED();
969
970 bool isAvailable(0);
971
972 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
973 {
974 return -1;
975 }
976
977 *available = isAvailable;
978
979 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
980 return (0);
981}
982
983// ----------------------------------------------------------------------------
984// SetMicrophoneBoost
985// ----------------------------------------------------------------------------
986
pbos@webrtc.org25509882013-04-09 10:30:35 +0000987int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000988{
niklase@google.com470e71d2011-07-07 08:21:25 +0000989 CHECK_INITIALIZED();
990 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
991}
992
993// ----------------------------------------------------------------------------
994// MicrophoneBoost
995// ----------------------------------------------------------------------------
996
pbos@webrtc.org25509882013-04-09 10:30:35 +0000997int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000998{
niklase@google.com470e71d2011-07-07 08:21:25 +0000999 CHECK_INITIALIZED();
1000
1001 bool onOff(false);
1002
1003 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
1004 {
1005 return -1;
1006 }
1007
1008 *enabled = onOff;
1009
1010 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1011 return (0);
1012}
1013
1014// ----------------------------------------------------------------------------
1015// MicrophoneVolumeIsAvailable
1016// ----------------------------------------------------------------------------
1017
pbos@webrtc.org25509882013-04-09 10:30:35 +00001018int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001019{
niklase@google.com470e71d2011-07-07 08:21:25 +00001020 CHECK_INITIALIZED();
1021
1022 bool isAvailable(0);
1023
1024 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1025 {
1026 return -1;
1027 }
1028
1029 *available = isAvailable;
1030
1031 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1032 return (0);
1033}
1034
1035// ----------------------------------------------------------------------------
1036// SetMicrophoneVolume
1037// ----------------------------------------------------------------------------
1038
pbos@webrtc.org25509882013-04-09 10:30:35 +00001039int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001040{
niklase@google.com470e71d2011-07-07 08:21:25 +00001041 CHECK_INITIALIZED();
1042 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1043}
1044
1045// ----------------------------------------------------------------------------
1046// MicrophoneVolume
1047// ----------------------------------------------------------------------------
1048
pbos@webrtc.org25509882013-04-09 10:30:35 +00001049int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001050{
1051 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1052 CHECK_INITIALIZED();
1053
pbos@webrtc.org25509882013-04-09 10:30:35 +00001054 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001055
1056 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1057 {
1058 return -1;
1059 }
1060
1061 *volume = level;
1062
1063 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1064 return (0);
1065}
1066
1067// ----------------------------------------------------------------------------
1068// StereoRecordingIsAvailable
1069// ----------------------------------------------------------------------------
1070
pbos@webrtc.org25509882013-04-09 10:30:35 +00001071int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001072{
niklase@google.com470e71d2011-07-07 08:21:25 +00001073 CHECK_INITIALIZED();
1074
1075 bool isAvailable(0);
1076
1077 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1078 {
1079 return -1;
1080 }
1081
1082 *available = isAvailable;
1083
1084 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1085 return (0);
1086}
1087
1088// ----------------------------------------------------------------------------
1089// SetStereoRecording
1090// ----------------------------------------------------------------------------
1091
pbos@webrtc.org25509882013-04-09 10:30:35 +00001092int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001093{
niklase@google.com470e71d2011-07-07 08:21:25 +00001094 CHECK_INITIALIZED();
1095
1096 if (_ptrAudioDevice->RecordingIsInitialized())
1097 {
1098 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1099 return -1;
1100 }
1101
1102 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1103 {
1104 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1105 return -1;
1106 }
1107
pbos@webrtc.org25509882013-04-09 10:30:35 +00001108 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001109 if (enable)
1110 {
1111 nChannels = 2;
1112 }
1113 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1114
1115 return 0;
1116}
1117
1118// ----------------------------------------------------------------------------
1119// StereoRecording
1120// ----------------------------------------------------------------------------
1121
pbos@webrtc.org25509882013-04-09 10:30:35 +00001122int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001123{
niklase@google.com470e71d2011-07-07 08:21:25 +00001124 CHECK_INITIALIZED();
1125
1126 bool stereo(false);
1127
1128 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1129 {
1130 return -1;
1131 }
1132
1133 *enabled = stereo;
1134
1135 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1136 return (0);
1137}
1138
1139// ----------------------------------------------------------------------------
1140// SetRecordingChannel
1141// ----------------------------------------------------------------------------
1142
pbos@webrtc.org25509882013-04-09 10:30:35 +00001143int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001144{
1145 if (channel == kChannelBoth)
1146 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001147 }
1148 else if (channel == kChannelLeft)
1149 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001150 }
1151 else
1152 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001153 }
1154 CHECK_INITIALIZED();
1155
1156 bool stereo(false);
1157
1158 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1159 {
1160 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1161 return -1;
1162 }
1163
1164 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1165}
1166
1167// ----------------------------------------------------------------------------
1168// RecordingChannel
1169// ----------------------------------------------------------------------------
1170
pbos@webrtc.org25509882013-04-09 10:30:35 +00001171int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001172{
niklase@google.com470e71d2011-07-07 08:21:25 +00001173 CHECK_INITIALIZED();
1174
1175 ChannelType chType;
1176
1177 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1178 {
1179 return -1;
1180 }
1181
1182 *channel = chType;
1183
1184 if (*channel == kChannelBoth)
1185 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001186 }
1187 else if (*channel == kChannelLeft)
1188 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001189 }
1190 else
1191 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001192 }
1193
1194 return (0);
1195}
1196
1197// ----------------------------------------------------------------------------
1198// StereoPlayoutIsAvailable
1199// ----------------------------------------------------------------------------
1200
pbos@webrtc.org25509882013-04-09 10:30:35 +00001201int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001202{
niklase@google.com470e71d2011-07-07 08:21:25 +00001203 CHECK_INITIALIZED();
1204
1205 bool isAvailable(0);
1206
1207 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1208 {
1209 return -1;
1210 }
1211
1212 *available = isAvailable;
1213
1214 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1215 return (0);
1216}
1217
1218// ----------------------------------------------------------------------------
1219// SetStereoPlayout
1220// ----------------------------------------------------------------------------
1221
pbos@webrtc.org25509882013-04-09 10:30:35 +00001222int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001223{
niklase@google.com470e71d2011-07-07 08:21:25 +00001224 CHECK_INITIALIZED();
1225
1226 if (_ptrAudioDevice->PlayoutIsInitialized())
1227 {
1228 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1229 return -1;
1230 }
1231
1232 if (_ptrAudioDevice->SetStereoPlayout(enable))
1233 {
1234 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1235 return -1;
1236 }
1237
pbos@webrtc.org25509882013-04-09 10:30:35 +00001238 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001239 if (enable)
1240 {
1241 nChannels = 2;
1242 }
1243 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1244
1245 return 0;
1246}
1247
1248// ----------------------------------------------------------------------------
1249// StereoPlayout
1250// ----------------------------------------------------------------------------
1251
pbos@webrtc.org25509882013-04-09 10:30:35 +00001252int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001253{
niklase@google.com470e71d2011-07-07 08:21:25 +00001254 CHECK_INITIALIZED();
1255
1256 bool stereo(false);
1257
1258 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1259 {
1260 return -1;
1261 }
1262
1263 *enabled = stereo;
1264
1265 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1266 return (0);
1267}
1268
1269// ----------------------------------------------------------------------------
1270// SetAGC
1271// ----------------------------------------------------------------------------
1272
pbos@webrtc.org25509882013-04-09 10:30:35 +00001273int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001274{
niklase@google.com470e71d2011-07-07 08:21:25 +00001275 CHECK_INITIALIZED();
1276 return (_ptrAudioDevice->SetAGC(enable));
1277}
1278
1279// ----------------------------------------------------------------------------
1280// AGC
1281// ----------------------------------------------------------------------------
1282
1283bool AudioDeviceModuleImpl::AGC() const
1284{
niklase@google.com470e71d2011-07-07 08:21:25 +00001285 CHECK_INITIALIZED_BOOL();
1286 return (_ptrAudioDevice->AGC());
1287}
1288
1289// ----------------------------------------------------------------------------
1290// PlayoutIsAvailable
1291// ----------------------------------------------------------------------------
1292
pbos@webrtc.org25509882013-04-09 10:30:35 +00001293int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001294{
niklase@google.com470e71d2011-07-07 08:21:25 +00001295 CHECK_INITIALIZED();
1296
1297 bool isAvailable(0);
1298
1299 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1300 {
1301 return -1;
1302 }
1303
1304 *available = isAvailable;
1305
1306 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1307 return (0);
1308}
1309
1310// ----------------------------------------------------------------------------
1311// RecordingIsAvailable
1312// ----------------------------------------------------------------------------
1313
pbos@webrtc.org25509882013-04-09 10:30:35 +00001314int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001315{
niklase@google.com470e71d2011-07-07 08:21:25 +00001316 CHECK_INITIALIZED();
1317
1318 bool isAvailable(0);
1319
1320 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1321 {
1322 return -1;
1323 }
1324
1325 *available = isAvailable;
1326
1327 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1328 return (0);
1329}
1330
1331// ----------------------------------------------------------------------------
1332// MaxMicrophoneVolume
1333// ----------------------------------------------------------------------------
1334
pbos@webrtc.org25509882013-04-09 10:30:35 +00001335int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001336{
1337 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1338 CHECK_INITIALIZED();
1339
pbos@webrtc.org25509882013-04-09 10:30:35 +00001340 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001341
1342 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1343 {
1344 return -1;
1345 }
1346
1347 *maxVolume = maxVol;
1348
1349 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1350 return (0);
1351}
1352
1353// ----------------------------------------------------------------------------
1354// MinMicrophoneVolume
1355// ----------------------------------------------------------------------------
1356
pbos@webrtc.org25509882013-04-09 10:30:35 +00001357int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001358{
niklase@google.com470e71d2011-07-07 08:21:25 +00001359 CHECK_INITIALIZED();
1360
pbos@webrtc.org25509882013-04-09 10:30:35 +00001361 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001362
1363 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1364 {
1365 return -1;
1366 }
1367
1368 *minVolume = minVol;
1369
1370 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1371 return (0);
1372}
1373
1374// ----------------------------------------------------------------------------
1375// MicrophoneVolumeStepSize
1376// ----------------------------------------------------------------------------
1377
pbos@webrtc.org25509882013-04-09 10:30:35 +00001378int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001379{
niklase@google.com470e71d2011-07-07 08:21:25 +00001380 CHECK_INITIALIZED();
1381
pbos@webrtc.org25509882013-04-09 10:30:35 +00001382 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001383
1384 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1385 {
1386 return -1;
1387 }
1388
1389 *stepSize = delta;
1390
1391 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1392 return (0);
1393}
1394
1395// ----------------------------------------------------------------------------
1396// PlayoutDevices
1397// ----------------------------------------------------------------------------
1398
pbos@webrtc.org25509882013-04-09 10:30:35 +00001399int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001400{
niklase@google.com470e71d2011-07-07 08:21:25 +00001401 CHECK_INITIALIZED();
1402
pbos@webrtc.org25509882013-04-09 10:30:35 +00001403 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001404
1405 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001406 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001407}
1408
1409// ----------------------------------------------------------------------------
1410// SetPlayoutDevice I (II)
1411// ----------------------------------------------------------------------------
1412
pbos@webrtc.org25509882013-04-09 10:30:35 +00001413int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001414{
niklase@google.com470e71d2011-07-07 08:21:25 +00001415 CHECK_INITIALIZED();
1416 return (_ptrAudioDevice->SetPlayoutDevice(index));
1417}
1418
1419// ----------------------------------------------------------------------------
1420// SetPlayoutDevice II (II)
1421// ----------------------------------------------------------------------------
1422
pbos@webrtc.org25509882013-04-09 10:30:35 +00001423int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001424{
1425 if (device == kDefaultDevice)
1426 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001427 }
1428 else
1429 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001430 }
1431 CHECK_INITIALIZED();
1432
1433 return (_ptrAudioDevice->SetPlayoutDevice(device));
1434}
1435
1436// ----------------------------------------------------------------------------
1437// PlayoutDeviceName
1438// ----------------------------------------------------------------------------
1439
pbos@webrtc.org25509882013-04-09 10:30:35 +00001440int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1441 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001442 char name[kAdmMaxDeviceNameSize],
1443 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001444{
niklase@google.com470e71d2011-07-07 08:21:25 +00001445 CHECK_INITIALIZED();
1446
1447 if (name == NULL)
1448 {
1449 _lastError = kAdmErrArgument;
1450 return -1;
1451 }
1452
1453 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1454 {
1455 return -1;
1456 }
1457
1458 if (name != NULL)
1459 {
1460 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1461 }
1462 if (guid != NULL)
1463 {
1464 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1465 }
1466
1467 return (0);
1468}
1469
1470// ----------------------------------------------------------------------------
1471// RecordingDeviceName
1472// ----------------------------------------------------------------------------
1473
pbos@webrtc.org25509882013-04-09 10:30:35 +00001474int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1475 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001476 char name[kAdmMaxDeviceNameSize],
1477 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001478{
niklase@google.com470e71d2011-07-07 08:21:25 +00001479 CHECK_INITIALIZED();
1480
1481 if (name == NULL)
1482 {
1483 _lastError = kAdmErrArgument;
1484 return -1;
1485 }
1486
1487 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1488 {
1489 return -1;
1490 }
1491
1492 if (name != NULL)
1493 {
1494 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1495 }
1496 if (guid != NULL)
1497 {
1498 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1499 }
1500
1501 return (0);
1502}
1503
1504// ----------------------------------------------------------------------------
1505// RecordingDevices
1506// ----------------------------------------------------------------------------
1507
pbos@webrtc.org25509882013-04-09 10:30:35 +00001508int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001509{
niklase@google.com470e71d2011-07-07 08:21:25 +00001510 CHECK_INITIALIZED();
1511
pbos@webrtc.org25509882013-04-09 10:30:35 +00001512 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001513
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001514 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1515 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001516 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001517}
1518
1519// ----------------------------------------------------------------------------
1520// SetRecordingDevice I (II)
1521// ----------------------------------------------------------------------------
1522
pbos@webrtc.org25509882013-04-09 10:30:35 +00001523int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001524{
niklase@google.com470e71d2011-07-07 08:21:25 +00001525 CHECK_INITIALIZED();
1526 return (_ptrAudioDevice->SetRecordingDevice(index));
1527}
1528
1529// ----------------------------------------------------------------------------
1530// SetRecordingDevice II (II)
1531// ----------------------------------------------------------------------------
1532
pbos@webrtc.org25509882013-04-09 10:30:35 +00001533int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001534{
1535 if (device == kDefaultDevice)
1536 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001537 }
1538 else
1539 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001540 }
1541 CHECK_INITIALIZED();
1542
1543 return (_ptrAudioDevice->SetRecordingDevice(device));
1544}
1545
1546// ----------------------------------------------------------------------------
1547// InitPlayout
1548// ----------------------------------------------------------------------------
1549
pbos@webrtc.org25509882013-04-09 10:30:35 +00001550int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001551{
niklase@google.com470e71d2011-07-07 08:21:25 +00001552 CHECK_INITIALIZED();
1553 _audioDeviceBuffer.InitPlayout();
1554 return (_ptrAudioDevice->InitPlayout());
1555}
1556
1557// ----------------------------------------------------------------------------
1558// InitRecording
1559// ----------------------------------------------------------------------------
1560
pbos@webrtc.org25509882013-04-09 10:30:35 +00001561int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001562{
niklase@google.com470e71d2011-07-07 08:21:25 +00001563 CHECK_INITIALIZED();
1564 _audioDeviceBuffer.InitRecording();
1565 return (_ptrAudioDevice->InitRecording());
1566}
1567
1568// ----------------------------------------------------------------------------
1569// PlayoutIsInitialized
1570// ----------------------------------------------------------------------------
1571
1572bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1573{
niklase@google.com470e71d2011-07-07 08:21:25 +00001574 CHECK_INITIALIZED_BOOL();
1575 return (_ptrAudioDevice->PlayoutIsInitialized());
1576}
1577
1578// ----------------------------------------------------------------------------
1579// RecordingIsInitialized
1580// ----------------------------------------------------------------------------
1581
1582bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1583{
niklase@google.com470e71d2011-07-07 08:21:25 +00001584 CHECK_INITIALIZED_BOOL();
1585 return (_ptrAudioDevice->RecordingIsInitialized());
1586}
1587
1588// ----------------------------------------------------------------------------
1589// StartPlayout
1590// ----------------------------------------------------------------------------
1591
pbos@webrtc.org25509882013-04-09 10:30:35 +00001592int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001593{
niklase@google.com470e71d2011-07-07 08:21:25 +00001594 CHECK_INITIALIZED();
1595 return (_ptrAudioDevice->StartPlayout());
1596}
1597
1598// ----------------------------------------------------------------------------
1599// StopPlayout
1600// ----------------------------------------------------------------------------
1601
pbos@webrtc.org25509882013-04-09 10:30:35 +00001602int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001603{
niklase@google.com470e71d2011-07-07 08:21:25 +00001604 CHECK_INITIALIZED();
1605 return (_ptrAudioDevice->StopPlayout());
1606}
1607
1608// ----------------------------------------------------------------------------
1609// Playing
1610// ----------------------------------------------------------------------------
1611
1612bool AudioDeviceModuleImpl::Playing() const
1613{
niklase@google.com470e71d2011-07-07 08:21:25 +00001614 CHECK_INITIALIZED_BOOL();
1615 return (_ptrAudioDevice->Playing());
1616}
1617
1618// ----------------------------------------------------------------------------
1619// StartRecording
1620// ----------------------------------------------------------------------------
1621
pbos@webrtc.org25509882013-04-09 10:30:35 +00001622int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001623{
niklase@google.com470e71d2011-07-07 08:21:25 +00001624 CHECK_INITIALIZED();
1625 return (_ptrAudioDevice->StartRecording());
1626}
1627// ----------------------------------------------------------------------------
1628// StopRecording
1629// ----------------------------------------------------------------------------
1630
pbos@webrtc.org25509882013-04-09 10:30:35 +00001631int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001632{
niklase@google.com470e71d2011-07-07 08:21:25 +00001633 CHECK_INITIALIZED();
1634 return (_ptrAudioDevice->StopRecording());
1635}
1636
1637// ----------------------------------------------------------------------------
1638// Recording
1639// ----------------------------------------------------------------------------
1640
1641bool AudioDeviceModuleImpl::Recording() const
1642{
niklase@google.com470e71d2011-07-07 08:21:25 +00001643 CHECK_INITIALIZED_BOOL();
1644 return (_ptrAudioDevice->Recording());
1645}
1646
1647// ----------------------------------------------------------------------------
1648// RegisterEventObserver
1649// ----------------------------------------------------------------------------
1650
pbos@webrtc.org25509882013-04-09 10:30:35 +00001651int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001652{
niklase@google.com470e71d2011-07-07 08:21:25 +00001653
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001654 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001655 _ptrCbAudioDeviceObserver = eventCallback;
1656
1657 return 0;
1658}
1659
1660// ----------------------------------------------------------------------------
1661// RegisterAudioCallback
1662// ----------------------------------------------------------------------------
1663
pbos@webrtc.org25509882013-04-09 10:30:35 +00001664int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001665{
niklase@google.com470e71d2011-07-07 08:21:25 +00001666
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001667 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001668 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1669
1670 return 0;
1671}
1672
1673// ----------------------------------------------------------------------------
1674// StartRawInputFileRecording
1675// ----------------------------------------------------------------------------
1676
pbos@webrtc.org25509882013-04-09 10:30:35 +00001677int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001678 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001679{
niklase@google.com470e71d2011-07-07 08:21:25 +00001680 CHECK_INITIALIZED();
1681
1682 if (NULL == pcmFileNameUTF8)
1683 {
1684 return -1;
1685 }
1686
1687 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1688}
1689
1690// ----------------------------------------------------------------------------
1691// StopRawInputFileRecording
1692// ----------------------------------------------------------------------------
1693
pbos@webrtc.org25509882013-04-09 10:30:35 +00001694int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001695{
niklase@google.com470e71d2011-07-07 08:21:25 +00001696 CHECK_INITIALIZED();
1697
1698 return (_audioDeviceBuffer.StopInputFileRecording());
1699}
1700
1701// ----------------------------------------------------------------------------
1702// StartRawOutputFileRecording
1703// ----------------------------------------------------------------------------
1704
pbos@webrtc.org25509882013-04-09 10:30:35 +00001705int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001706 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001707{
niklase@google.com470e71d2011-07-07 08:21:25 +00001708 CHECK_INITIALIZED();
1709
1710 if (NULL == pcmFileNameUTF8)
1711 {
1712 return -1;
1713 }
1714
1715 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1716}
1717
1718// ----------------------------------------------------------------------------
1719// StopRawOutputFileRecording
1720// ----------------------------------------------------------------------------
1721
pbos@webrtc.org25509882013-04-09 10:30:35 +00001722int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001723{
niklase@google.com470e71d2011-07-07 08:21:25 +00001724 CHECK_INITIALIZED();
1725
1726 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001727}
1728
1729// ----------------------------------------------------------------------------
1730// SetPlayoutBuffer
1731// ----------------------------------------------------------------------------
1732
pbos@webrtc.org25509882013-04-09 10:30:35 +00001733int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001734{
niklase@google.com470e71d2011-07-07 08:21:25 +00001735 CHECK_INITIALIZED();
1736
1737 if (_ptrAudioDevice->PlayoutIsInitialized())
1738 {
1739 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1740 return -1;
1741 }
1742
pbos@webrtc.org25509882013-04-09 10:30:35 +00001743 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001744
1745 if (kFixedBufferSize == type)
1746 {
1747 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1748 {
1749 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1750 return -1;
1751 }
1752 }
1753
1754 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1755 {
1756 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1757 }
1758
1759 return ret;
1760}
1761
1762// ----------------------------------------------------------------------------
1763// PlayoutBuffer
1764// ----------------------------------------------------------------------------
1765
pbos@webrtc.org25509882013-04-09 10:30:35 +00001766int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001767{
niklase@google.com470e71d2011-07-07 08:21:25 +00001768 CHECK_INITIALIZED();
1769
1770 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001771 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001772
1773 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1774 {
1775 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1776 return -1;
1777 }
1778
1779 *type = bufType;
1780 *sizeMS = size;
1781
1782 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1783 return (0);
1784}
1785
1786// ----------------------------------------------------------------------------
1787// PlayoutDelay
1788// ----------------------------------------------------------------------------
1789
pbos@webrtc.org25509882013-04-09 10:30:35 +00001790int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001791{
1792 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1793 CHECK_INITIALIZED();
1794
pbos@webrtc.org25509882013-04-09 10:30:35 +00001795 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001796
1797 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1798 {
1799 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1800 return -1;
1801 }
1802
1803 *delayMS = delay;
1804
1805 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1806 return (0);
1807}
1808
1809// ----------------------------------------------------------------------------
1810// RecordingDelay
1811// ----------------------------------------------------------------------------
1812
pbos@webrtc.org25509882013-04-09 10:30:35 +00001813int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001814{
1815 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1816 CHECK_INITIALIZED();
1817
pbos@webrtc.org25509882013-04-09 10:30:35 +00001818 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001819
1820 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1821 {
1822 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1823 return -1;
1824 }
1825
1826 *delayMS = delay;
1827
1828 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1829 return (0);
1830}
1831
1832// ----------------------------------------------------------------------------
1833// CPULoad
1834// ----------------------------------------------------------------------------
1835
pbos@webrtc.org25509882013-04-09 10:30:35 +00001836int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001837{
niklase@google.com470e71d2011-07-07 08:21:25 +00001838 CHECK_INITIALIZED();
1839
pbos@webrtc.org25509882013-04-09 10:30:35 +00001840 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001841
1842 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1843 {
1844 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1845 return -1;
1846 }
1847
1848 *load = cpuLoad;
1849
1850 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1851 return (0);
1852}
1853
1854// ----------------------------------------------------------------------------
1855// SetRecordingSampleRate
1856// ----------------------------------------------------------------------------
1857
pbos@webrtc.org25509882013-04-09 10:30:35 +00001858int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001859{
niklase@google.com470e71d2011-07-07 08:21:25 +00001860 CHECK_INITIALIZED();
1861
1862 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1863 {
1864 return -1;
1865 }
1866
1867 return (0);
1868}
1869
1870// ----------------------------------------------------------------------------
1871// RecordingSampleRate
1872// ----------------------------------------------------------------------------
1873
pbos@webrtc.org25509882013-04-09 10:30:35 +00001874int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001875{
niklase@google.com470e71d2011-07-07 08:21:25 +00001876 CHECK_INITIALIZED();
1877
pbos@webrtc.org25509882013-04-09 10:30:35 +00001878 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001879
1880 if (sampleRate == -1)
1881 {
1882 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1883 return -1;
1884 }
1885
1886 *samplesPerSec = sampleRate;
1887
1888 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1889 return (0);
1890}
1891
1892// ----------------------------------------------------------------------------
1893// SetPlayoutSampleRate
1894// ----------------------------------------------------------------------------
1895
pbos@webrtc.org25509882013-04-09 10:30:35 +00001896int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001897{
niklase@google.com470e71d2011-07-07 08:21:25 +00001898 CHECK_INITIALIZED();
1899
1900 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1901 {
1902 return -1;
1903 }
1904
1905 return (0);
1906}
1907
1908// ----------------------------------------------------------------------------
1909// PlayoutSampleRate
1910// ----------------------------------------------------------------------------
1911
pbos@webrtc.org25509882013-04-09 10:30:35 +00001912int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001913{
niklase@google.com470e71d2011-07-07 08:21:25 +00001914 CHECK_INITIALIZED();
1915
pbos@webrtc.org25509882013-04-09 10:30:35 +00001916 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001917
1918 if (sampleRate == -1)
1919 {
1920 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1921 return -1;
1922 }
1923
1924 *samplesPerSec = sampleRate;
1925
1926 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1927 return (0);
1928}
1929
1930// ----------------------------------------------------------------------------
1931// ResetAudioDevice
1932// ----------------------------------------------------------------------------
1933
pbos@webrtc.org25509882013-04-09 10:30:35 +00001934int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001935{
niklase@google.com470e71d2011-07-07 08:21:25 +00001936 CHECK_INITIALIZED();
1937
1938
1939 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1940 {
1941 return -1;
1942 }
1943
1944 return (0);
1945}
1946
1947// ----------------------------------------------------------------------------
1948// SetLoudspeakerStatus
1949// ----------------------------------------------------------------------------
1950
pbos@webrtc.org25509882013-04-09 10:30:35 +00001951int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001952{
niklase@google.com470e71d2011-07-07 08:21:25 +00001953 CHECK_INITIALIZED();
1954
1955 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1956 {
1957 return -1;
1958 }
1959
1960 return 0;
1961}
1962
1963// ----------------------------------------------------------------------------
1964// GetLoudspeakerStatus
1965// ----------------------------------------------------------------------------
1966
pbos@webrtc.org25509882013-04-09 10:30:35 +00001967int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001968{
niklase@google.com470e71d2011-07-07 08:21:25 +00001969 CHECK_INITIALIZED();
1970
1971 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1972 {
1973 return -1;
1974 }
1975
1976 return 0;
1977}
1978
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001979int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1980{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001981 CHECK_INITIALIZED();
1982
1983 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1984}
1985
1986bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1987{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001988 CHECK_INITIALIZED_BOOL();
1989
1990 return _ptrAudioDevice->BuiltInAECIsEnabled();
1991}
1992
niklase@google.com470e71d2011-07-07 08:21:25 +00001993// ============================================================================
1994// Private Methods
1995// ============================================================================
1996
1997// ----------------------------------------------------------------------------
1998// Platform
1999// ----------------------------------------------------------------------------
2000
2001AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
2002{
2003 return _platformType;
2004}
2005
2006// ----------------------------------------------------------------------------
2007// PlatformAudioLayer
2008// ----------------------------------------------------------------------------
2009
2010AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2011{
niklase@google.com470e71d2011-07-07 08:21:25 +00002012
2013 switch (_platformAudioLayer)
2014 {
2015 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002016 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2017 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002018 break;
2019 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002020 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2021 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002022 break;
2023 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002024 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2025 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002026 break;
2027 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002028 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2029 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002030 break;
2031 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002032 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2033 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002034 break;
2035 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002036 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2037 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002038 break;
2039 }
2040
2041 return _platformAudioLayer;
2042}
2043
2044} // namespace webrtc