blob: 86bd848b39d25beb7658dbb496040b052e6ea8c5 [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// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000467// Module::TimeUntilNextProcess
468//
469// Returns the number of milliseconds until the module want a worker thread
470// to call Process().
471// ----------------------------------------------------------------------------
472
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000473int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000474{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000475 uint32_t now = AudioDeviceUtility::GetTimeInMS();
476 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000477 return (deltaProcess);
478}
479
480// ----------------------------------------------------------------------------
481// Module::Process
482//
483// Check for posted error and warning reports. Generate callbacks if
484// new reports exists.
485// ----------------------------------------------------------------------------
486
pbos@webrtc.org25509882013-04-09 10:30:35 +0000487int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000488{
niklase@google.com470e71d2011-07-07 08:21:25 +0000489
490 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
491
492 // kPlayoutWarning
493 if (_ptrAudioDevice->PlayoutWarning())
494 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000495 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000496 if (_ptrCbAudioDeviceObserver)
497 {
498 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
499 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
500 }
501 _ptrAudioDevice->ClearPlayoutWarning();
502 }
503
504 // kPlayoutError
505 if (_ptrAudioDevice->PlayoutError())
506 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000507 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000508 if (_ptrCbAudioDeviceObserver)
509 {
510 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
511 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
512 }
513 _ptrAudioDevice->ClearPlayoutError();
514 }
515
516 // kRecordingWarning
517 if (_ptrAudioDevice->RecordingWarning())
518 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000519 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000520 if (_ptrCbAudioDeviceObserver)
521 {
522 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
523 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
524 }
525 _ptrAudioDevice->ClearRecordingWarning();
526 }
527
528 // kRecordingError
529 if (_ptrAudioDevice->RecordingError())
530 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000531 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000532 if (_ptrCbAudioDeviceObserver)
533 {
534 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
535 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
536 }
537 _ptrAudioDevice->ClearRecordingError();
538 }
539
540 return 0;
541}
542
543// ============================================================================
544// Public API
545// ============================================================================
546
547// ----------------------------------------------------------------------------
548// ActiveAudioLayer
549// ----------------------------------------------------------------------------
550
pbos@webrtc.org25509882013-04-09 10:30:35 +0000551int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000552{
niklase@google.com470e71d2011-07-07 08:21:25 +0000553
554 AudioLayer activeAudio;
555
556 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
557 {
558 return -1;
559 }
560
561 *audioLayer = activeAudio;
562
563 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
564 {
565 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
566 }
567 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
568 {
569 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
570 }
571 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
572 {
573 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
574 }
575 else
576 {
577 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
578 }
579
580 return 0;
581}
582
583// ----------------------------------------------------------------------------
584// LastError
585// ----------------------------------------------------------------------------
586
587AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
588{
589 return _lastError;
590}
591
592// ----------------------------------------------------------------------------
593// Init
594// ----------------------------------------------------------------------------
595
pbos@webrtc.org25509882013-04-09 10:30:35 +0000596int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000597{
niklase@google.com470e71d2011-07-07 08:21:25 +0000598
599 if (_initialized)
600 return 0;
601
602 if (!_ptrAudioDeviceUtility)
603 return -1;
604
605 if (!_ptrAudioDevice)
606 return -1;
607
608 _ptrAudioDeviceUtility->Init();
609
610 if (_ptrAudioDevice->Init() == -1)
611 {
612 return -1;
613 }
614
615 _initialized = true;
616 return 0;
617}
618
619// ----------------------------------------------------------------------------
620// Terminate
621// ----------------------------------------------------------------------------
622
pbos@webrtc.org25509882013-04-09 10:30:35 +0000623int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000624{
niklase@google.com470e71d2011-07-07 08:21:25 +0000625
626 if (!_initialized)
627 return 0;
628
629 if (_ptrAudioDevice->Terminate() == -1)
630 {
631 return -1;
632 }
633
634 _initialized = false;
635 return 0;
636}
637
638// ----------------------------------------------------------------------------
639// Initialized
640// ----------------------------------------------------------------------------
641
642bool AudioDeviceModuleImpl::Initialized() const
643{
niklase@google.com470e71d2011-07-07 08:21:25 +0000644
645 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
646 return (_initialized);
647}
648
649// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000650// InitSpeaker
651// ----------------------------------------------------------------------------
652
pbos@webrtc.org25509882013-04-09 10:30:35 +0000653int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000654{
niklase@google.com470e71d2011-07-07 08:21:25 +0000655 CHECK_INITIALIZED();
656 return (_ptrAudioDevice->InitSpeaker());
657}
658
659// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000660// InitMicrophone
661// ----------------------------------------------------------------------------
662
pbos@webrtc.org25509882013-04-09 10:30:35 +0000663int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000664{
niklase@google.com470e71d2011-07-07 08:21:25 +0000665 CHECK_INITIALIZED();
666 return (_ptrAudioDevice->InitMicrophone());
667}
668
669// ----------------------------------------------------------------------------
670// SpeakerVolumeIsAvailable
671// ----------------------------------------------------------------------------
672
pbos@webrtc.org25509882013-04-09 10:30:35 +0000673int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000674{
niklase@google.com470e71d2011-07-07 08:21:25 +0000675 CHECK_INITIALIZED();
676
677 bool isAvailable(0);
678
679 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
680 {
681 return -1;
682 }
683
684 *available = isAvailable;
685
686 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
687 return (0);
688}
689
690// ----------------------------------------------------------------------------
691// SetSpeakerVolume
692// ----------------------------------------------------------------------------
693
pbos@webrtc.org25509882013-04-09 10:30:35 +0000694int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000695{
niklase@google.com470e71d2011-07-07 08:21:25 +0000696 CHECK_INITIALIZED();
697 return (_ptrAudioDevice->SetSpeakerVolume(volume));
698}
699
700// ----------------------------------------------------------------------------
701// SpeakerVolume
702// ----------------------------------------------------------------------------
703
pbos@webrtc.org25509882013-04-09 10:30:35 +0000704int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000705{
niklase@google.com470e71d2011-07-07 08:21:25 +0000706 CHECK_INITIALIZED();
707
pbos@webrtc.org25509882013-04-09 10:30:35 +0000708 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000709
710 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
711 {
712 return -1;
713 }
714
715 *volume = level;
716
717 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
718 return (0);
719}
720
721// ----------------------------------------------------------------------------
722// SetWaveOutVolume
723// ----------------------------------------------------------------------------
724
pbos@webrtc.org25509882013-04-09 10:30:35 +0000725int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000726{
niklase@google.com470e71d2011-07-07 08:21:25 +0000727 CHECK_INITIALIZED();
728 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
729}
730
731// ----------------------------------------------------------------------------
732// WaveOutVolume
733// ----------------------------------------------------------------------------
734
pbos@webrtc.org25509882013-04-09 10:30:35 +0000735int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000736{
niklase@google.com470e71d2011-07-07 08:21:25 +0000737 CHECK_INITIALIZED();
738
pbos@webrtc.org25509882013-04-09 10:30:35 +0000739 uint16_t volLeft(0);
740 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000741
742 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
743 {
744 return -1;
745 }
746
747 *volumeLeft = volLeft;
748 *volumeRight = volRight;
749
750 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
751 *volumeLeft, *volumeRight);
752
753 return (0);
754}
755
756// ----------------------------------------------------------------------------
757// SpeakerIsInitialized
758// ----------------------------------------------------------------------------
759
760bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
761{
niklase@google.com470e71d2011-07-07 08:21:25 +0000762 CHECK_INITIALIZED_BOOL();
763
764 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
765
766 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
767 return (isInitialized);
768}
769
770// ----------------------------------------------------------------------------
771// MicrophoneIsInitialized
772// ----------------------------------------------------------------------------
773
774bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
775{
niklase@google.com470e71d2011-07-07 08:21:25 +0000776 CHECK_INITIALIZED_BOOL();
777
778 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
779
780 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
781 return (isInitialized);
782}
783
784// ----------------------------------------------------------------------------
785// MaxSpeakerVolume
786// ----------------------------------------------------------------------------
787
pbos@webrtc.org25509882013-04-09 10:30:35 +0000788int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000789{
niklase@google.com470e71d2011-07-07 08:21:25 +0000790 CHECK_INITIALIZED();
791
pbos@webrtc.org25509882013-04-09 10:30:35 +0000792 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000793
794 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
795 {
796 return -1;
797 }
798
799 *maxVolume = maxVol;
800
801 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
802 return (0);
803}
804
805// ----------------------------------------------------------------------------
806// MinSpeakerVolume
807// ----------------------------------------------------------------------------
808
pbos@webrtc.org25509882013-04-09 10:30:35 +0000809int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000810{
niklase@google.com470e71d2011-07-07 08:21:25 +0000811 CHECK_INITIALIZED();
812
pbos@webrtc.org25509882013-04-09 10:30:35 +0000813 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000814
815 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
816 {
817 return -1;
818 }
819
820 *minVolume = minVol;
821
822 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
823 return (0);
824}
825
826// ----------------------------------------------------------------------------
827// SpeakerVolumeStepSize
828// ----------------------------------------------------------------------------
829
pbos@webrtc.org25509882013-04-09 10:30:35 +0000830int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000831{
niklase@google.com470e71d2011-07-07 08:21:25 +0000832 CHECK_INITIALIZED();
833
pbos@webrtc.org25509882013-04-09 10:30:35 +0000834 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000835
836 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
837 {
838 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
839 return -1;
840 }
841
842 *stepSize = delta;
843
844 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
845 return (0);
846}
847
848// ----------------------------------------------------------------------------
849// SpeakerMuteIsAvailable
850// ----------------------------------------------------------------------------
851
pbos@webrtc.org25509882013-04-09 10:30:35 +0000852int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000853{
niklase@google.com470e71d2011-07-07 08:21:25 +0000854 CHECK_INITIALIZED();
855
856 bool isAvailable(0);
857
858 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
859 {
860 return -1;
861 }
862
863 *available = isAvailable;
864
865 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
866 return (0);
867}
868
869// ----------------------------------------------------------------------------
870// SetSpeakerMute
871// ----------------------------------------------------------------------------
872
pbos@webrtc.org25509882013-04-09 10:30:35 +0000873int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000874{
niklase@google.com470e71d2011-07-07 08:21:25 +0000875 CHECK_INITIALIZED();
876 return (_ptrAudioDevice->SetSpeakerMute(enable));
877}
878
879// ----------------------------------------------------------------------------
880// SpeakerMute
881// ----------------------------------------------------------------------------
882
pbos@webrtc.org25509882013-04-09 10:30:35 +0000883int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000884{
niklase@google.com470e71d2011-07-07 08:21:25 +0000885 CHECK_INITIALIZED();
886
887 bool muted(false);
888
889 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
890 {
891 return -1;
892 }
893
894 *enabled = muted;
895
896 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
897 return (0);
898}
899
900// ----------------------------------------------------------------------------
901// MicrophoneMuteIsAvailable
902// ----------------------------------------------------------------------------
903
pbos@webrtc.org25509882013-04-09 10:30:35 +0000904int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000905{
niklase@google.com470e71d2011-07-07 08:21:25 +0000906 CHECK_INITIALIZED();
907
908 bool isAvailable(0);
909
910 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
911 {
912 return -1;
913 }
914
915 *available = isAvailable;
916
917 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
918 return (0);
919}
920
921// ----------------------------------------------------------------------------
922// SetMicrophoneMute
923// ----------------------------------------------------------------------------
924
pbos@webrtc.org25509882013-04-09 10:30:35 +0000925int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000926{
niklase@google.com470e71d2011-07-07 08:21:25 +0000927 CHECK_INITIALIZED();
928 return (_ptrAudioDevice->SetMicrophoneMute(enable));
929}
930
931// ----------------------------------------------------------------------------
932// MicrophoneMute
933// ----------------------------------------------------------------------------
934
pbos@webrtc.org25509882013-04-09 10:30:35 +0000935int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000936{
niklase@google.com470e71d2011-07-07 08:21:25 +0000937 CHECK_INITIALIZED();
938
939 bool muted(false);
940
941 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
942 {
943 return -1;
944 }
945
946 *enabled = muted;
947
948 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
949 return (0);
950}
951
952// ----------------------------------------------------------------------------
953// MicrophoneBoostIsAvailable
954// ----------------------------------------------------------------------------
955
pbos@webrtc.org25509882013-04-09 10:30:35 +0000956int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000957{
niklase@google.com470e71d2011-07-07 08:21:25 +0000958 CHECK_INITIALIZED();
959
960 bool isAvailable(0);
961
962 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
963 {
964 return -1;
965 }
966
967 *available = isAvailable;
968
969 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
970 return (0);
971}
972
973// ----------------------------------------------------------------------------
974// SetMicrophoneBoost
975// ----------------------------------------------------------------------------
976
pbos@webrtc.org25509882013-04-09 10:30:35 +0000977int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000978{
niklase@google.com470e71d2011-07-07 08:21:25 +0000979 CHECK_INITIALIZED();
980 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
981}
982
983// ----------------------------------------------------------------------------
984// MicrophoneBoost
985// ----------------------------------------------------------------------------
986
pbos@webrtc.org25509882013-04-09 10:30:35 +0000987int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000988{
niklase@google.com470e71d2011-07-07 08:21:25 +0000989 CHECK_INITIALIZED();
990
991 bool onOff(false);
992
993 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
994 {
995 return -1;
996 }
997
998 *enabled = onOff;
999
1000 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1001 return (0);
1002}
1003
1004// ----------------------------------------------------------------------------
1005// MicrophoneVolumeIsAvailable
1006// ----------------------------------------------------------------------------
1007
pbos@webrtc.org25509882013-04-09 10:30:35 +00001008int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001009{
niklase@google.com470e71d2011-07-07 08:21:25 +00001010 CHECK_INITIALIZED();
1011
1012 bool isAvailable(0);
1013
1014 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1015 {
1016 return -1;
1017 }
1018
1019 *available = isAvailable;
1020
1021 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1022 return (0);
1023}
1024
1025// ----------------------------------------------------------------------------
1026// SetMicrophoneVolume
1027// ----------------------------------------------------------------------------
1028
pbos@webrtc.org25509882013-04-09 10:30:35 +00001029int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001030{
niklase@google.com470e71d2011-07-07 08:21:25 +00001031 CHECK_INITIALIZED();
1032 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1033}
1034
1035// ----------------------------------------------------------------------------
1036// MicrophoneVolume
1037// ----------------------------------------------------------------------------
1038
pbos@webrtc.org25509882013-04-09 10:30:35 +00001039int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001040{
1041 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1042 CHECK_INITIALIZED();
1043
pbos@webrtc.org25509882013-04-09 10:30:35 +00001044 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001045
1046 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1047 {
1048 return -1;
1049 }
1050
1051 *volume = level;
1052
1053 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1054 return (0);
1055}
1056
1057// ----------------------------------------------------------------------------
1058// StereoRecordingIsAvailable
1059// ----------------------------------------------------------------------------
1060
pbos@webrtc.org25509882013-04-09 10:30:35 +00001061int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001062{
niklase@google.com470e71d2011-07-07 08:21:25 +00001063 CHECK_INITIALIZED();
1064
1065 bool isAvailable(0);
1066
1067 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1068 {
1069 return -1;
1070 }
1071
1072 *available = isAvailable;
1073
1074 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1075 return (0);
1076}
1077
1078// ----------------------------------------------------------------------------
1079// SetStereoRecording
1080// ----------------------------------------------------------------------------
1081
pbos@webrtc.org25509882013-04-09 10:30:35 +00001082int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001083{
niklase@google.com470e71d2011-07-07 08:21:25 +00001084 CHECK_INITIALIZED();
1085
1086 if (_ptrAudioDevice->RecordingIsInitialized())
1087 {
1088 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1089 return -1;
1090 }
1091
1092 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1093 {
1094 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1095 return -1;
1096 }
1097
pbos@webrtc.org25509882013-04-09 10:30:35 +00001098 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001099 if (enable)
1100 {
1101 nChannels = 2;
1102 }
1103 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1104
1105 return 0;
1106}
1107
1108// ----------------------------------------------------------------------------
1109// StereoRecording
1110// ----------------------------------------------------------------------------
1111
pbos@webrtc.org25509882013-04-09 10:30:35 +00001112int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001113{
niklase@google.com470e71d2011-07-07 08:21:25 +00001114 CHECK_INITIALIZED();
1115
1116 bool stereo(false);
1117
1118 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1119 {
1120 return -1;
1121 }
1122
1123 *enabled = stereo;
1124
1125 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1126 return (0);
1127}
1128
1129// ----------------------------------------------------------------------------
1130// SetRecordingChannel
1131// ----------------------------------------------------------------------------
1132
pbos@webrtc.org25509882013-04-09 10:30:35 +00001133int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001134{
1135 if (channel == kChannelBoth)
1136 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001137 }
1138 else if (channel == kChannelLeft)
1139 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001140 }
1141 else
1142 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001143 }
1144 CHECK_INITIALIZED();
1145
1146 bool stereo(false);
1147
1148 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1149 {
1150 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1151 return -1;
1152 }
1153
1154 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1155}
1156
1157// ----------------------------------------------------------------------------
1158// RecordingChannel
1159// ----------------------------------------------------------------------------
1160
pbos@webrtc.org25509882013-04-09 10:30:35 +00001161int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001162{
niklase@google.com470e71d2011-07-07 08:21:25 +00001163 CHECK_INITIALIZED();
1164
1165 ChannelType chType;
1166
1167 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1168 {
1169 return -1;
1170 }
1171
1172 *channel = chType;
1173
1174 if (*channel == kChannelBoth)
1175 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001176 }
1177 else if (*channel == kChannelLeft)
1178 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001179 }
1180 else
1181 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001182 }
1183
1184 return (0);
1185}
1186
1187// ----------------------------------------------------------------------------
1188// StereoPlayoutIsAvailable
1189// ----------------------------------------------------------------------------
1190
pbos@webrtc.org25509882013-04-09 10:30:35 +00001191int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001192{
niklase@google.com470e71d2011-07-07 08:21:25 +00001193 CHECK_INITIALIZED();
1194
1195 bool isAvailable(0);
1196
1197 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1198 {
1199 return -1;
1200 }
1201
1202 *available = isAvailable;
1203
1204 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1205 return (0);
1206}
1207
1208// ----------------------------------------------------------------------------
1209// SetStereoPlayout
1210// ----------------------------------------------------------------------------
1211
pbos@webrtc.org25509882013-04-09 10:30:35 +00001212int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001213{
niklase@google.com470e71d2011-07-07 08:21:25 +00001214 CHECK_INITIALIZED();
1215
1216 if (_ptrAudioDevice->PlayoutIsInitialized())
1217 {
1218 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1219 return -1;
1220 }
1221
1222 if (_ptrAudioDevice->SetStereoPlayout(enable))
1223 {
1224 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1225 return -1;
1226 }
1227
pbos@webrtc.org25509882013-04-09 10:30:35 +00001228 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001229 if (enable)
1230 {
1231 nChannels = 2;
1232 }
1233 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1234
1235 return 0;
1236}
1237
1238// ----------------------------------------------------------------------------
1239// StereoPlayout
1240// ----------------------------------------------------------------------------
1241
pbos@webrtc.org25509882013-04-09 10:30:35 +00001242int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001243{
niklase@google.com470e71d2011-07-07 08:21:25 +00001244 CHECK_INITIALIZED();
1245
1246 bool stereo(false);
1247
1248 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1249 {
1250 return -1;
1251 }
1252
1253 *enabled = stereo;
1254
1255 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1256 return (0);
1257}
1258
1259// ----------------------------------------------------------------------------
1260// SetAGC
1261// ----------------------------------------------------------------------------
1262
pbos@webrtc.org25509882013-04-09 10:30:35 +00001263int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001264{
niklase@google.com470e71d2011-07-07 08:21:25 +00001265 CHECK_INITIALIZED();
1266 return (_ptrAudioDevice->SetAGC(enable));
1267}
1268
1269// ----------------------------------------------------------------------------
1270// AGC
1271// ----------------------------------------------------------------------------
1272
1273bool AudioDeviceModuleImpl::AGC() const
1274{
niklase@google.com470e71d2011-07-07 08:21:25 +00001275 CHECK_INITIALIZED_BOOL();
1276 return (_ptrAudioDevice->AGC());
1277}
1278
1279// ----------------------------------------------------------------------------
1280// PlayoutIsAvailable
1281// ----------------------------------------------------------------------------
1282
pbos@webrtc.org25509882013-04-09 10:30:35 +00001283int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001284{
niklase@google.com470e71d2011-07-07 08:21:25 +00001285 CHECK_INITIALIZED();
1286
1287 bool isAvailable(0);
1288
1289 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1290 {
1291 return -1;
1292 }
1293
1294 *available = isAvailable;
1295
1296 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1297 return (0);
1298}
1299
1300// ----------------------------------------------------------------------------
1301// RecordingIsAvailable
1302// ----------------------------------------------------------------------------
1303
pbos@webrtc.org25509882013-04-09 10:30:35 +00001304int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001305{
niklase@google.com470e71d2011-07-07 08:21:25 +00001306 CHECK_INITIALIZED();
1307
1308 bool isAvailable(0);
1309
1310 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1311 {
1312 return -1;
1313 }
1314
1315 *available = isAvailable;
1316
1317 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1318 return (0);
1319}
1320
1321// ----------------------------------------------------------------------------
1322// MaxMicrophoneVolume
1323// ----------------------------------------------------------------------------
1324
pbos@webrtc.org25509882013-04-09 10:30:35 +00001325int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001326{
1327 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1328 CHECK_INITIALIZED();
1329
pbos@webrtc.org25509882013-04-09 10:30:35 +00001330 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001331
1332 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1333 {
1334 return -1;
1335 }
1336
1337 *maxVolume = maxVol;
1338
1339 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1340 return (0);
1341}
1342
1343// ----------------------------------------------------------------------------
1344// MinMicrophoneVolume
1345// ----------------------------------------------------------------------------
1346
pbos@webrtc.org25509882013-04-09 10:30:35 +00001347int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001348{
niklase@google.com470e71d2011-07-07 08:21:25 +00001349 CHECK_INITIALIZED();
1350
pbos@webrtc.org25509882013-04-09 10:30:35 +00001351 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001352
1353 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1354 {
1355 return -1;
1356 }
1357
1358 *minVolume = minVol;
1359
1360 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1361 return (0);
1362}
1363
1364// ----------------------------------------------------------------------------
1365// MicrophoneVolumeStepSize
1366// ----------------------------------------------------------------------------
1367
pbos@webrtc.org25509882013-04-09 10:30:35 +00001368int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001369{
niklase@google.com470e71d2011-07-07 08:21:25 +00001370 CHECK_INITIALIZED();
1371
pbos@webrtc.org25509882013-04-09 10:30:35 +00001372 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001373
1374 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1375 {
1376 return -1;
1377 }
1378
1379 *stepSize = delta;
1380
1381 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1382 return (0);
1383}
1384
1385// ----------------------------------------------------------------------------
1386// PlayoutDevices
1387// ----------------------------------------------------------------------------
1388
pbos@webrtc.org25509882013-04-09 10:30:35 +00001389int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001390{
niklase@google.com470e71d2011-07-07 08:21:25 +00001391 CHECK_INITIALIZED();
1392
pbos@webrtc.org25509882013-04-09 10:30:35 +00001393 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001394
1395 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001396 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001397}
1398
1399// ----------------------------------------------------------------------------
1400// SetPlayoutDevice I (II)
1401// ----------------------------------------------------------------------------
1402
pbos@webrtc.org25509882013-04-09 10:30:35 +00001403int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001404{
niklase@google.com470e71d2011-07-07 08:21:25 +00001405 CHECK_INITIALIZED();
1406 return (_ptrAudioDevice->SetPlayoutDevice(index));
1407}
1408
1409// ----------------------------------------------------------------------------
1410// SetPlayoutDevice II (II)
1411// ----------------------------------------------------------------------------
1412
pbos@webrtc.org25509882013-04-09 10:30:35 +00001413int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001414{
1415 if (device == kDefaultDevice)
1416 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001417 }
1418 else
1419 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001420 }
1421 CHECK_INITIALIZED();
1422
1423 return (_ptrAudioDevice->SetPlayoutDevice(device));
1424}
1425
1426// ----------------------------------------------------------------------------
1427// PlayoutDeviceName
1428// ----------------------------------------------------------------------------
1429
pbos@webrtc.org25509882013-04-09 10:30:35 +00001430int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1431 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001432 char name[kAdmMaxDeviceNameSize],
1433 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001434{
niklase@google.com470e71d2011-07-07 08:21:25 +00001435 CHECK_INITIALIZED();
1436
1437 if (name == NULL)
1438 {
1439 _lastError = kAdmErrArgument;
1440 return -1;
1441 }
1442
1443 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1444 {
1445 return -1;
1446 }
1447
1448 if (name != NULL)
1449 {
1450 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1451 }
1452 if (guid != NULL)
1453 {
1454 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1455 }
1456
1457 return (0);
1458}
1459
1460// ----------------------------------------------------------------------------
1461// RecordingDeviceName
1462// ----------------------------------------------------------------------------
1463
pbos@webrtc.org25509882013-04-09 10:30:35 +00001464int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1465 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001466 char name[kAdmMaxDeviceNameSize],
1467 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001468{
niklase@google.com470e71d2011-07-07 08:21:25 +00001469 CHECK_INITIALIZED();
1470
1471 if (name == NULL)
1472 {
1473 _lastError = kAdmErrArgument;
1474 return -1;
1475 }
1476
1477 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1478 {
1479 return -1;
1480 }
1481
1482 if (name != NULL)
1483 {
1484 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1485 }
1486 if (guid != NULL)
1487 {
1488 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1489 }
1490
1491 return (0);
1492}
1493
1494// ----------------------------------------------------------------------------
1495// RecordingDevices
1496// ----------------------------------------------------------------------------
1497
pbos@webrtc.org25509882013-04-09 10:30:35 +00001498int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001499{
niklase@google.com470e71d2011-07-07 08:21:25 +00001500 CHECK_INITIALIZED();
1501
pbos@webrtc.org25509882013-04-09 10:30:35 +00001502 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001503
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001504 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1505 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001506 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001507}
1508
1509// ----------------------------------------------------------------------------
1510// SetRecordingDevice I (II)
1511// ----------------------------------------------------------------------------
1512
pbos@webrtc.org25509882013-04-09 10:30:35 +00001513int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001514{
niklase@google.com470e71d2011-07-07 08:21:25 +00001515 CHECK_INITIALIZED();
1516 return (_ptrAudioDevice->SetRecordingDevice(index));
1517}
1518
1519// ----------------------------------------------------------------------------
1520// SetRecordingDevice II (II)
1521// ----------------------------------------------------------------------------
1522
pbos@webrtc.org25509882013-04-09 10:30:35 +00001523int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001524{
1525 if (device == kDefaultDevice)
1526 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001527 }
1528 else
1529 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001530 }
1531 CHECK_INITIALIZED();
1532
1533 return (_ptrAudioDevice->SetRecordingDevice(device));
1534}
1535
1536// ----------------------------------------------------------------------------
1537// InitPlayout
1538// ----------------------------------------------------------------------------
1539
pbos@webrtc.org25509882013-04-09 10:30:35 +00001540int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001541{
niklase@google.com470e71d2011-07-07 08:21:25 +00001542 CHECK_INITIALIZED();
1543 _audioDeviceBuffer.InitPlayout();
1544 return (_ptrAudioDevice->InitPlayout());
1545}
1546
1547// ----------------------------------------------------------------------------
1548// InitRecording
1549// ----------------------------------------------------------------------------
1550
pbos@webrtc.org25509882013-04-09 10:30:35 +00001551int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001552{
niklase@google.com470e71d2011-07-07 08:21:25 +00001553 CHECK_INITIALIZED();
1554 _audioDeviceBuffer.InitRecording();
1555 return (_ptrAudioDevice->InitRecording());
1556}
1557
1558// ----------------------------------------------------------------------------
1559// PlayoutIsInitialized
1560// ----------------------------------------------------------------------------
1561
1562bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1563{
niklase@google.com470e71d2011-07-07 08:21:25 +00001564 CHECK_INITIALIZED_BOOL();
1565 return (_ptrAudioDevice->PlayoutIsInitialized());
1566}
1567
1568// ----------------------------------------------------------------------------
1569// RecordingIsInitialized
1570// ----------------------------------------------------------------------------
1571
1572bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1573{
niklase@google.com470e71d2011-07-07 08:21:25 +00001574 CHECK_INITIALIZED_BOOL();
1575 return (_ptrAudioDevice->RecordingIsInitialized());
1576}
1577
1578// ----------------------------------------------------------------------------
1579// StartPlayout
1580// ----------------------------------------------------------------------------
1581
pbos@webrtc.org25509882013-04-09 10:30:35 +00001582int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001583{
niklase@google.com470e71d2011-07-07 08:21:25 +00001584 CHECK_INITIALIZED();
1585 return (_ptrAudioDevice->StartPlayout());
1586}
1587
1588// ----------------------------------------------------------------------------
1589// StopPlayout
1590// ----------------------------------------------------------------------------
1591
pbos@webrtc.org25509882013-04-09 10:30:35 +00001592int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001593{
niklase@google.com470e71d2011-07-07 08:21:25 +00001594 CHECK_INITIALIZED();
1595 return (_ptrAudioDevice->StopPlayout());
1596}
1597
1598// ----------------------------------------------------------------------------
1599// Playing
1600// ----------------------------------------------------------------------------
1601
1602bool AudioDeviceModuleImpl::Playing() const
1603{
niklase@google.com470e71d2011-07-07 08:21:25 +00001604 CHECK_INITIALIZED_BOOL();
1605 return (_ptrAudioDevice->Playing());
1606}
1607
1608// ----------------------------------------------------------------------------
1609// StartRecording
1610// ----------------------------------------------------------------------------
1611
pbos@webrtc.org25509882013-04-09 10:30:35 +00001612int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001613{
niklase@google.com470e71d2011-07-07 08:21:25 +00001614 CHECK_INITIALIZED();
1615 return (_ptrAudioDevice->StartRecording());
1616}
1617// ----------------------------------------------------------------------------
1618// StopRecording
1619// ----------------------------------------------------------------------------
1620
pbos@webrtc.org25509882013-04-09 10:30:35 +00001621int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001622{
niklase@google.com470e71d2011-07-07 08:21:25 +00001623 CHECK_INITIALIZED();
1624 return (_ptrAudioDevice->StopRecording());
1625}
1626
1627// ----------------------------------------------------------------------------
1628// Recording
1629// ----------------------------------------------------------------------------
1630
1631bool AudioDeviceModuleImpl::Recording() const
1632{
niklase@google.com470e71d2011-07-07 08:21:25 +00001633 CHECK_INITIALIZED_BOOL();
1634 return (_ptrAudioDevice->Recording());
1635}
1636
1637// ----------------------------------------------------------------------------
1638// RegisterEventObserver
1639// ----------------------------------------------------------------------------
1640
pbos@webrtc.org25509882013-04-09 10:30:35 +00001641int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001642{
niklase@google.com470e71d2011-07-07 08:21:25 +00001643
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001644 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001645 _ptrCbAudioDeviceObserver = eventCallback;
1646
1647 return 0;
1648}
1649
1650// ----------------------------------------------------------------------------
1651// RegisterAudioCallback
1652// ----------------------------------------------------------------------------
1653
pbos@webrtc.org25509882013-04-09 10:30:35 +00001654int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001655{
niklase@google.com470e71d2011-07-07 08:21:25 +00001656
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001657 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001658 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1659
1660 return 0;
1661}
1662
1663// ----------------------------------------------------------------------------
1664// StartRawInputFileRecording
1665// ----------------------------------------------------------------------------
1666
pbos@webrtc.org25509882013-04-09 10:30:35 +00001667int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001668 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001669{
niklase@google.com470e71d2011-07-07 08:21:25 +00001670 CHECK_INITIALIZED();
1671
1672 if (NULL == pcmFileNameUTF8)
1673 {
1674 return -1;
1675 }
1676
1677 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1678}
1679
1680// ----------------------------------------------------------------------------
1681// StopRawInputFileRecording
1682// ----------------------------------------------------------------------------
1683
pbos@webrtc.org25509882013-04-09 10:30:35 +00001684int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001685{
niklase@google.com470e71d2011-07-07 08:21:25 +00001686 CHECK_INITIALIZED();
1687
1688 return (_audioDeviceBuffer.StopInputFileRecording());
1689}
1690
1691// ----------------------------------------------------------------------------
1692// StartRawOutputFileRecording
1693// ----------------------------------------------------------------------------
1694
pbos@webrtc.org25509882013-04-09 10:30:35 +00001695int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001696 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001697{
niklase@google.com470e71d2011-07-07 08:21:25 +00001698 CHECK_INITIALIZED();
1699
1700 if (NULL == pcmFileNameUTF8)
1701 {
1702 return -1;
1703 }
1704
1705 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1706}
1707
1708// ----------------------------------------------------------------------------
1709// StopRawOutputFileRecording
1710// ----------------------------------------------------------------------------
1711
pbos@webrtc.org25509882013-04-09 10:30:35 +00001712int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001713{
niklase@google.com470e71d2011-07-07 08:21:25 +00001714 CHECK_INITIALIZED();
1715
1716 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001717}
1718
1719// ----------------------------------------------------------------------------
1720// SetPlayoutBuffer
1721// ----------------------------------------------------------------------------
1722
pbos@webrtc.org25509882013-04-09 10:30:35 +00001723int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001724{
niklase@google.com470e71d2011-07-07 08:21:25 +00001725 CHECK_INITIALIZED();
1726
1727 if (_ptrAudioDevice->PlayoutIsInitialized())
1728 {
1729 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1730 return -1;
1731 }
1732
pbos@webrtc.org25509882013-04-09 10:30:35 +00001733 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001734
1735 if (kFixedBufferSize == type)
1736 {
1737 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1738 {
1739 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1740 return -1;
1741 }
1742 }
1743
1744 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1745 {
1746 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1747 }
1748
1749 return ret;
1750}
1751
1752// ----------------------------------------------------------------------------
1753// PlayoutBuffer
1754// ----------------------------------------------------------------------------
1755
pbos@webrtc.org25509882013-04-09 10:30:35 +00001756int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001757{
niklase@google.com470e71d2011-07-07 08:21:25 +00001758 CHECK_INITIALIZED();
1759
1760 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001761 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001762
1763 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1764 {
1765 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1766 return -1;
1767 }
1768
1769 *type = bufType;
1770 *sizeMS = size;
1771
1772 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1773 return (0);
1774}
1775
1776// ----------------------------------------------------------------------------
1777// PlayoutDelay
1778// ----------------------------------------------------------------------------
1779
pbos@webrtc.org25509882013-04-09 10:30:35 +00001780int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001781{
1782 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1783 CHECK_INITIALIZED();
1784
pbos@webrtc.org25509882013-04-09 10:30:35 +00001785 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001786
1787 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1788 {
1789 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1790 return -1;
1791 }
1792
1793 *delayMS = delay;
1794
1795 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1796 return (0);
1797}
1798
1799// ----------------------------------------------------------------------------
1800// RecordingDelay
1801// ----------------------------------------------------------------------------
1802
pbos@webrtc.org25509882013-04-09 10:30:35 +00001803int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001804{
1805 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1806 CHECK_INITIALIZED();
1807
pbos@webrtc.org25509882013-04-09 10:30:35 +00001808 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001809
1810 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1811 {
1812 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1813 return -1;
1814 }
1815
1816 *delayMS = delay;
1817
1818 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1819 return (0);
1820}
1821
1822// ----------------------------------------------------------------------------
1823// CPULoad
1824// ----------------------------------------------------------------------------
1825
pbos@webrtc.org25509882013-04-09 10:30:35 +00001826int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001827{
niklase@google.com470e71d2011-07-07 08:21:25 +00001828 CHECK_INITIALIZED();
1829
pbos@webrtc.org25509882013-04-09 10:30:35 +00001830 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001831
1832 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1833 {
1834 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1835 return -1;
1836 }
1837
1838 *load = cpuLoad;
1839
1840 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1841 return (0);
1842}
1843
1844// ----------------------------------------------------------------------------
1845// SetRecordingSampleRate
1846// ----------------------------------------------------------------------------
1847
pbos@webrtc.org25509882013-04-09 10:30:35 +00001848int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001849{
niklase@google.com470e71d2011-07-07 08:21:25 +00001850 CHECK_INITIALIZED();
1851
1852 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1853 {
1854 return -1;
1855 }
1856
1857 return (0);
1858}
1859
1860// ----------------------------------------------------------------------------
1861// RecordingSampleRate
1862// ----------------------------------------------------------------------------
1863
pbos@webrtc.org25509882013-04-09 10:30:35 +00001864int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001865{
niklase@google.com470e71d2011-07-07 08:21:25 +00001866 CHECK_INITIALIZED();
1867
pbos@webrtc.org25509882013-04-09 10:30:35 +00001868 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001869
1870 if (sampleRate == -1)
1871 {
1872 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1873 return -1;
1874 }
1875
1876 *samplesPerSec = sampleRate;
1877
1878 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1879 return (0);
1880}
1881
1882// ----------------------------------------------------------------------------
1883// SetPlayoutSampleRate
1884// ----------------------------------------------------------------------------
1885
pbos@webrtc.org25509882013-04-09 10:30:35 +00001886int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001887{
niklase@google.com470e71d2011-07-07 08:21:25 +00001888 CHECK_INITIALIZED();
1889
1890 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1891 {
1892 return -1;
1893 }
1894
1895 return (0);
1896}
1897
1898// ----------------------------------------------------------------------------
1899// PlayoutSampleRate
1900// ----------------------------------------------------------------------------
1901
pbos@webrtc.org25509882013-04-09 10:30:35 +00001902int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001903{
niklase@google.com470e71d2011-07-07 08:21:25 +00001904 CHECK_INITIALIZED();
1905
pbos@webrtc.org25509882013-04-09 10:30:35 +00001906 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001907
1908 if (sampleRate == -1)
1909 {
1910 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1911 return -1;
1912 }
1913
1914 *samplesPerSec = sampleRate;
1915
1916 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1917 return (0);
1918}
1919
1920// ----------------------------------------------------------------------------
1921// ResetAudioDevice
1922// ----------------------------------------------------------------------------
1923
pbos@webrtc.org25509882013-04-09 10:30:35 +00001924int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001925{
niklase@google.com470e71d2011-07-07 08:21:25 +00001926 CHECK_INITIALIZED();
1927
1928
1929 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1930 {
1931 return -1;
1932 }
1933
1934 return (0);
1935}
1936
1937// ----------------------------------------------------------------------------
1938// SetLoudspeakerStatus
1939// ----------------------------------------------------------------------------
1940
pbos@webrtc.org25509882013-04-09 10:30:35 +00001941int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001942{
niklase@google.com470e71d2011-07-07 08:21:25 +00001943 CHECK_INITIALIZED();
1944
1945 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1946 {
1947 return -1;
1948 }
1949
1950 return 0;
1951}
1952
1953// ----------------------------------------------------------------------------
1954// GetLoudspeakerStatus
1955// ----------------------------------------------------------------------------
1956
pbos@webrtc.org25509882013-04-09 10:30:35 +00001957int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001958{
niklase@google.com470e71d2011-07-07 08:21:25 +00001959 CHECK_INITIALIZED();
1960
1961 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1962 {
1963 return -1;
1964 }
1965
1966 return 0;
1967}
1968
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001969int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1970{
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001971 CHECK_INITIALIZED();
1972 return _ptrAudioDevice->EnableBuiltInAEC(enable);
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001973}
1974
1975bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1976{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001977 CHECK_INITIALIZED_BOOL();
1978
1979 return _ptrAudioDevice->BuiltInAECIsEnabled();
1980}
1981
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001982bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1983 CHECK_INITIALIZED_BOOL();
1984 return _ptrAudioDevice->BuiltInAECIsAvailable();
1985}
1986
niklase@google.com470e71d2011-07-07 08:21:25 +00001987// ============================================================================
1988// Private Methods
1989// ============================================================================
1990
1991// ----------------------------------------------------------------------------
1992// Platform
1993// ----------------------------------------------------------------------------
1994
1995AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1996{
1997 return _platformType;
1998}
1999
2000// ----------------------------------------------------------------------------
2001// PlatformAudioLayer
2002// ----------------------------------------------------------------------------
2003
2004AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2005{
niklase@google.com470e71d2011-07-07 08:21:25 +00002006
2007 switch (_platformAudioLayer)
2008 {
2009 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002010 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2011 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002012 break;
2013 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002014 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2015 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002016 break;
2017 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002018 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2019 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002020 break;
2021 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002022 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2023 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002024 break;
2025 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002026 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2027 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002028 break;
2029 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002030 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2031 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002032 break;
2033 }
2034
2035 return _platformAudioLayer;
2036}
2037
2038} // namespace webrtc