blob: 0bcba9825ada50f78b6b49125133eb5a00339e71 [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{
henrika@google.com73d65512011-09-07 15:11:18 +000093 // Create the generic ref counted (platform independent) implementation.
94 RefCountImpl<AudioDeviceModuleImpl>* audioDevice =
95 new RefCountImpl<AudioDeviceModuleImpl>(id, audioLayer);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
henrika@google.com73d65512011-09-07 15:11:18 +000097 // Ensure that the current platform is supported.
niklase@google.com470e71d2011-07-07 08:21:25 +000098 if (audioDevice->CheckPlatform() == -1)
99 {
100 delete audioDevice;
101 return NULL;
102 }
103
henrika@google.com73d65512011-09-07 15:11:18 +0000104 // Create the platform-dependent implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 if (audioDevice->CreatePlatformSpecificObjects() == -1)
106 {
107 delete audioDevice;
108 return NULL;
109 }
110
henrika@google.com73d65512011-09-07 15:11:18 +0000111 // Ensure that the generic audio buffer can communicate with the
112 // platform-specific parts.
niklase@google.com470e71d2011-07-07 08:21:25 +0000113 if (audioDevice->AttachAudioBuffer() == -1)
114 {
115 delete audioDevice;
116 return NULL;
117 }
118
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000119 WebRtcSpl_Init();
120
niklase@google.com470e71d2011-07-07 08:21:25 +0000121 return audioDevice;
122}
123
niklase@google.com470e71d2011-07-07 08:21:25 +0000124// ============================================================================
125// Construction & Destruction
126// ============================================================================
127
128// ----------------------------------------------------------------------------
129// AudioDeviceModuleImpl - ctor
130// ----------------------------------------------------------------------------
131
pbos@webrtc.org25509882013-04-09 10:30:35 +0000132AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
niklase@google.com470e71d2011-07-07 08:21:25 +0000133 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
134 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
135 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
136 _ptrCbAudioDeviceObserver(NULL),
xians@google.com88bd4402011-08-04 15:33:30 +0000137 _ptrAudioDeviceUtility(NULL),
138 _ptrAudioDevice(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +0000139 _id(id),
140 _platformAudioLayer(audioLayer),
141 _lastProcessTime(AudioDeviceUtility::GetTimeInMS()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000142 _platformType(kPlatformNotSupported),
xians@google.com88bd4402011-08-04 15:33:30 +0000143 _initialized(false),
144 _lastError(kAdmErrNone)
niklase@google.com470e71d2011-07-07 08:21:25 +0000145{
146 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
147}
148
149// ----------------------------------------------------------------------------
150// CheckPlatform
151// ----------------------------------------------------------------------------
152
pbos@webrtc.org25509882013-04-09 10:30:35 +0000153int32_t AudioDeviceModuleImpl::CheckPlatform()
niklase@google.com470e71d2011-07-07 08:21:25 +0000154{
155 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
156
157 // Ensure that the current platform is supported
158 //
159 PlatformType platform(kPlatformNotSupported);
160
161#if defined(_WIN32)
162 platform = kPlatformWin32;
163 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
leozwang@google.com522f42b2011-09-19 17:39:05 +0000164#elif defined(WEBRTC_ANDROID)
165 platform = kPlatformAndroid;
166 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
niklase@google.com470e71d2011-07-07 08:21:25 +0000167#elif defined(WEBRTC_LINUX)
168 platform = kPlatformLinux;
169 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000170#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000171 platform = kPlatformIOS;
172 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000173#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000174 platform = kPlatformMac;
175 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
176#endif
177
178 if (platform == kPlatformNotSupported)
179 {
180 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
181 return -1;
182 }
183
184 // Store valid output results
185 //
186 _platformType = platform;
187
188 return 0;
189}
190
191
192// ----------------------------------------------------------------------------
193// CreatePlatformSpecificObjects
194// ----------------------------------------------------------------------------
195
pbos@webrtc.org25509882013-04-09 10:30:35 +0000196int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
niklase@google.com470e71d2011-07-07 08:21:25 +0000197{
198 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
199
200 AudioDeviceGeneric* ptrAudioDevice(NULL);
201 AudioDeviceUtility* ptrAudioDeviceUtility(NULL);
202
xians@google.combf5d2ba2011-08-16 07:44:19 +0000203#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
204 ptrAudioDevice = new AudioDeviceDummy(Id());
205 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
206
207 if (ptrAudioDevice != NULL)
208 {
209 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
210 }
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000211#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
212 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
213 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
214 "Will use file-playing dummy device.");
215 if (ptrAudioDevice != NULL)
216 {
217 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
218 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000219#else
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000220 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
222 // Create the *Windows* implementation of the Audio Device
223 //
224#if defined(_WIN32)
225 if ((audioLayer == kWindowsWaveAudio)
226#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
227 // Wave audio is default if Core audio is not supported in this build
228 || (audioLayer == kPlatformDefaultAudio)
229#endif
230 )
231 {
232 // create *Windows Wave Audio* implementation
233 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
234 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
235 }
236#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
237 if ((audioLayer == kWindowsCoreAudio) ||
238 (audioLayer == kPlatformDefaultAudio)
239 )
240 {
241 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
242
243 if (AudioDeviceWindowsCore::CoreAudioIsSupported())
244 {
245 // create *Windows Core Audio* implementation
246 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
247 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
248 }
249 else
250 {
251 // create *Windows Wave Audio* implementation
252 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
253 if (ptrAudioDevice != NULL)
254 {
255 // Core Audio was not supported => revert to Windows Wave instead
256 _platformAudioLayer = kWindowsWaveAudio; // modify the state set at construction
257 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
258 }
259 }
260 }
261#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
262 if (ptrAudioDevice != NULL)
263 {
264 // Create the Windows implementation of the Device Utility.
265 // This class is independent of the selected audio layer
266 // for Windows.
267 //
268 ptrAudioDeviceUtility = new AudioDeviceUtilityWindows(Id());
269 }
270#endif // #if defined(_WIN32)
271
leozwang@google.com39f20512011-07-15 16:29:40 +0000272 // Create the *Android OpenSLES* implementation of the Audio Device
niklase@google.com470e71d2011-07-07 08:21:25 +0000273 //
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000274#if defined(WEBRTC_ANDROID)
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000275#ifdef WEBRTC_ANDROID_OPENSLES
276 // Force default audio layer to OpenSL ES if the special compiler flag
277 // (enable_android_opensl) has been set to one.
278 if (audioLayer == kPlatformDefaultAudio) {
279 audioLayer = kAndroidOpenSLESAudio;
280 }
braveyao@webrtc.org8a2c84f2014-08-18 03:02:42 +0000281#endif
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000282 if (audioLayer == kPlatformDefaultAudio ||
283 audioLayer == kAndroidJavaAudio) {
284 ptrAudioDevice =
285 new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(Id());
286 } else if (audioLayer == kAndroidOpenSLESAudio) {
287 // AudioRecordJni provides hardware AEC and OpenSlesOutput low latency.
288 ptrAudioDevice =
289 new AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000290 }
291
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000292 if (ptrAudioDevice != NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000293 // Create the Android implementation of the Device Utility.
294 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
295 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000296 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
298 // Create the *Linux* implementation of the Audio Device
299 //
300#elif defined(WEBRTC_LINUX)
301 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
302 {
303#if defined(LINUX_PULSE)
304 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
305
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000306 // create *Linux PulseAudio* implementation
307 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
308 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000309 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000310 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000311 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
312 }
313 else
314 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000315 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000316#endif
317#if defined(LINUX_ALSA)
318 // create *Linux ALSA Audio* implementation
319 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
320 if (ptrAudioDevice != NULL)
321 {
322 // Pulse Audio was not supported => revert to ALSA instead
323 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
324 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
325 }
326#endif
327#if defined(LINUX_PULSE)
328 }
329#endif
330 }
331 else if (audioLayer == kLinuxAlsaAudio)
332 {
333#if defined(LINUX_ALSA)
334 // create *Linux ALSA Audio* implementation
335 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
336 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
337#endif
338 }
339
340 if (ptrAudioDevice != NULL)
341 {
342 // Create the Linux implementation of the Device Utility.
343 // This class is independent of the selected audio layer
344 // for Linux.
345 //
346 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
347 }
348#endif // #if defined(WEBRTC_LINUX)
349
350 // Create the *iPhone* implementation of the Audio Device
351 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000352#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 if (audioLayer == kPlatformDefaultAudio)
354 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000355 // Create iOS Audio Device implementation.
356 ptrAudioDevice = new AudioDeviceIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000357 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
358 }
359
360 if (ptrAudioDevice != NULL)
361 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000362 // Create iOS Device Utility implementation.
363 ptrAudioDeviceUtility = new AudioDeviceUtilityIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000364 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000365 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000366
367 // Create the *Mac* implementation of the Audio Device
368 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000369#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000370 if (audioLayer == kPlatformDefaultAudio)
371 {
372 // Create *Mac Audio* implementation
373 ptrAudioDevice = new AudioDeviceMac(Id());
374 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
375 }
376
377 if (ptrAudioDevice != NULL)
378 {
379 // Create the Mac implementation of the Device Utility.
380 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
381 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000382#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
384 // Create the *Dummy* implementation of the Audio Device
385 // Available for all platforms
386 //
387 if (audioLayer == kDummyAudio)
388 {
389 // Create *Dummy Audio* implementation
390 assert(!ptrAudioDevice);
391 ptrAudioDevice = new AudioDeviceDummy(Id());
392 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
393
394 if (ptrAudioDevice != NULL)
395 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000396 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000397 }
398 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000399#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000400
401 if (ptrAudioDevice == NULL)
402 {
403 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
404 return -1;
405 }
406
407 if (ptrAudioDeviceUtility == NULL)
408 {
409 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
410 return -1;
411 }
412
413 // Store valid output pointers
414 //
415 _ptrAudioDevice = ptrAudioDevice;
416 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
417
418 return 0;
419}
420
421// ----------------------------------------------------------------------------
422// AttachAudioBuffer
423//
424// Install "bridge" between the platform implemetation and the generic
425// implementation. The "child" shall set the native sampling rate and the
426// number of channels in this function call.
427// ----------------------------------------------------------------------------
428
pbos@webrtc.org25509882013-04-09 10:30:35 +0000429int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000430{
431 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
432
433 _audioDeviceBuffer.SetId(_id);
434 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
435 return 0;
436}
437
438// ----------------------------------------------------------------------------
439// ~AudioDeviceModuleImpl - dtor
440// ----------------------------------------------------------------------------
441
442AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
443{
444 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000445
446 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000447 {
henrika@google.com73d65512011-09-07 15:11:18 +0000448 delete _ptrAudioDevice;
449 _ptrAudioDevice = NULL;
450 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000451
henrika@google.com73d65512011-09-07 15:11:18 +0000452 if (_ptrAudioDeviceUtility)
453 {
454 delete _ptrAudioDeviceUtility;
455 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000456 }
457
458 delete &_critSect;
459 delete &_critSectEventCb;
460 delete &_critSectAudioCb;
461}
462
463// ============================================================================
464// Module
465// ============================================================================
466
467// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000468// Module::TimeUntilNextProcess
469//
470// Returns the number of milliseconds until the module want a worker thread
471// to call Process().
472// ----------------------------------------------------------------------------
473
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000474int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000475{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000476 uint32_t now = AudioDeviceUtility::GetTimeInMS();
477 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000478 return (deltaProcess);
479}
480
481// ----------------------------------------------------------------------------
482// Module::Process
483//
484// Check for posted error and warning reports. Generate callbacks if
485// new reports exists.
486// ----------------------------------------------------------------------------
487
pbos@webrtc.org25509882013-04-09 10:30:35 +0000488int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000489{
niklase@google.com470e71d2011-07-07 08:21:25 +0000490
491 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
492
493 // kPlayoutWarning
494 if (_ptrAudioDevice->PlayoutWarning())
495 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000496 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000497 if (_ptrCbAudioDeviceObserver)
498 {
499 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
500 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
501 }
502 _ptrAudioDevice->ClearPlayoutWarning();
503 }
504
505 // kPlayoutError
506 if (_ptrAudioDevice->PlayoutError())
507 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000508 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000509 if (_ptrCbAudioDeviceObserver)
510 {
511 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
512 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
513 }
514 _ptrAudioDevice->ClearPlayoutError();
515 }
516
517 // kRecordingWarning
518 if (_ptrAudioDevice->RecordingWarning())
519 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000520 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000521 if (_ptrCbAudioDeviceObserver)
522 {
523 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
524 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
525 }
526 _ptrAudioDevice->ClearRecordingWarning();
527 }
528
529 // kRecordingError
530 if (_ptrAudioDevice->RecordingError())
531 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000532 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000533 if (_ptrCbAudioDeviceObserver)
534 {
535 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
536 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
537 }
538 _ptrAudioDevice->ClearRecordingError();
539 }
540
541 return 0;
542}
543
544// ============================================================================
545// Public API
546// ============================================================================
547
548// ----------------------------------------------------------------------------
549// ActiveAudioLayer
550// ----------------------------------------------------------------------------
551
pbos@webrtc.org25509882013-04-09 10:30:35 +0000552int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000553{
niklase@google.com470e71d2011-07-07 08:21:25 +0000554
555 AudioLayer activeAudio;
556
557 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
558 {
559 return -1;
560 }
561
562 *audioLayer = activeAudio;
563
564 if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
565 {
566 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
567 }
568 else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
569 {
570 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
571 }
572 else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
573 {
574 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
575 }
576 else
577 {
578 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
579 }
580
581 return 0;
582}
583
584// ----------------------------------------------------------------------------
585// LastError
586// ----------------------------------------------------------------------------
587
588AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
589{
590 return _lastError;
591}
592
593// ----------------------------------------------------------------------------
594// Init
595// ----------------------------------------------------------------------------
596
pbos@webrtc.org25509882013-04-09 10:30:35 +0000597int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000598{
niklase@google.com470e71d2011-07-07 08:21:25 +0000599
600 if (_initialized)
601 return 0;
602
603 if (!_ptrAudioDeviceUtility)
604 return -1;
605
606 if (!_ptrAudioDevice)
607 return -1;
608
609 _ptrAudioDeviceUtility->Init();
610
611 if (_ptrAudioDevice->Init() == -1)
612 {
613 return -1;
614 }
615
616 _initialized = true;
617 return 0;
618}
619
620// ----------------------------------------------------------------------------
621// Terminate
622// ----------------------------------------------------------------------------
623
pbos@webrtc.org25509882013-04-09 10:30:35 +0000624int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000625{
niklase@google.com470e71d2011-07-07 08:21:25 +0000626
627 if (!_initialized)
628 return 0;
629
630 if (_ptrAudioDevice->Terminate() == -1)
631 {
632 return -1;
633 }
634
635 _initialized = false;
636 return 0;
637}
638
639// ----------------------------------------------------------------------------
640// Initialized
641// ----------------------------------------------------------------------------
642
643bool AudioDeviceModuleImpl::Initialized() const
644{
niklase@google.com470e71d2011-07-07 08:21:25 +0000645
646 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
647 return (_initialized);
648}
649
650// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000651// InitSpeaker
652// ----------------------------------------------------------------------------
653
pbos@webrtc.org25509882013-04-09 10:30:35 +0000654int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000655{
niklase@google.com470e71d2011-07-07 08:21:25 +0000656 CHECK_INITIALIZED();
657 return (_ptrAudioDevice->InitSpeaker());
658}
659
660// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000661// InitMicrophone
662// ----------------------------------------------------------------------------
663
pbos@webrtc.org25509882013-04-09 10:30:35 +0000664int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000665{
niklase@google.com470e71d2011-07-07 08:21:25 +0000666 CHECK_INITIALIZED();
667 return (_ptrAudioDevice->InitMicrophone());
668}
669
670// ----------------------------------------------------------------------------
671// SpeakerVolumeIsAvailable
672// ----------------------------------------------------------------------------
673
pbos@webrtc.org25509882013-04-09 10:30:35 +0000674int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000675{
niklase@google.com470e71d2011-07-07 08:21:25 +0000676 CHECK_INITIALIZED();
677
678 bool isAvailable(0);
679
680 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
681 {
682 return -1;
683 }
684
685 *available = isAvailable;
686
687 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
688 return (0);
689}
690
691// ----------------------------------------------------------------------------
692// SetSpeakerVolume
693// ----------------------------------------------------------------------------
694
pbos@webrtc.org25509882013-04-09 10:30:35 +0000695int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000696{
niklase@google.com470e71d2011-07-07 08:21:25 +0000697 CHECK_INITIALIZED();
698 return (_ptrAudioDevice->SetSpeakerVolume(volume));
699}
700
701// ----------------------------------------------------------------------------
702// SpeakerVolume
703// ----------------------------------------------------------------------------
704
pbos@webrtc.org25509882013-04-09 10:30:35 +0000705int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000706{
niklase@google.com470e71d2011-07-07 08:21:25 +0000707 CHECK_INITIALIZED();
708
pbos@webrtc.org25509882013-04-09 10:30:35 +0000709 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000710
711 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
712 {
713 return -1;
714 }
715
716 *volume = level;
717
718 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
719 return (0);
720}
721
722// ----------------------------------------------------------------------------
723// SetWaveOutVolume
724// ----------------------------------------------------------------------------
725
pbos@webrtc.org25509882013-04-09 10:30:35 +0000726int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000727{
niklase@google.com470e71d2011-07-07 08:21:25 +0000728 CHECK_INITIALIZED();
729 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
730}
731
732// ----------------------------------------------------------------------------
733// WaveOutVolume
734// ----------------------------------------------------------------------------
735
pbos@webrtc.org25509882013-04-09 10:30:35 +0000736int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000737{
niklase@google.com470e71d2011-07-07 08:21:25 +0000738 CHECK_INITIALIZED();
739
pbos@webrtc.org25509882013-04-09 10:30:35 +0000740 uint16_t volLeft(0);
741 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000742
743 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
744 {
745 return -1;
746 }
747
748 *volumeLeft = volLeft;
749 *volumeRight = volRight;
750
751 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
752 *volumeLeft, *volumeRight);
753
754 return (0);
755}
756
757// ----------------------------------------------------------------------------
758// SpeakerIsInitialized
759// ----------------------------------------------------------------------------
760
761bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
762{
niklase@google.com470e71d2011-07-07 08:21:25 +0000763 CHECK_INITIALIZED_BOOL();
764
765 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
766
767 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
768 return (isInitialized);
769}
770
771// ----------------------------------------------------------------------------
772// MicrophoneIsInitialized
773// ----------------------------------------------------------------------------
774
775bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
776{
niklase@google.com470e71d2011-07-07 08:21:25 +0000777 CHECK_INITIALIZED_BOOL();
778
779 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
780
781 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
782 return (isInitialized);
783}
784
785// ----------------------------------------------------------------------------
786// MaxSpeakerVolume
787// ----------------------------------------------------------------------------
788
pbos@webrtc.org25509882013-04-09 10:30:35 +0000789int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000790{
niklase@google.com470e71d2011-07-07 08:21:25 +0000791 CHECK_INITIALIZED();
792
pbos@webrtc.org25509882013-04-09 10:30:35 +0000793 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000794
795 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
796 {
797 return -1;
798 }
799
800 *maxVolume = maxVol;
801
802 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
803 return (0);
804}
805
806// ----------------------------------------------------------------------------
807// MinSpeakerVolume
808// ----------------------------------------------------------------------------
809
pbos@webrtc.org25509882013-04-09 10:30:35 +0000810int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000811{
niklase@google.com470e71d2011-07-07 08:21:25 +0000812 CHECK_INITIALIZED();
813
pbos@webrtc.org25509882013-04-09 10:30:35 +0000814 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000815
816 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
817 {
818 return -1;
819 }
820
821 *minVolume = minVol;
822
823 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
824 return (0);
825}
826
827// ----------------------------------------------------------------------------
828// SpeakerVolumeStepSize
829// ----------------------------------------------------------------------------
830
pbos@webrtc.org25509882013-04-09 10:30:35 +0000831int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000832{
niklase@google.com470e71d2011-07-07 08:21:25 +0000833 CHECK_INITIALIZED();
834
pbos@webrtc.org25509882013-04-09 10:30:35 +0000835 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000836
837 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
838 {
839 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
840 return -1;
841 }
842
843 *stepSize = delta;
844
845 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
846 return (0);
847}
848
849// ----------------------------------------------------------------------------
850// SpeakerMuteIsAvailable
851// ----------------------------------------------------------------------------
852
pbos@webrtc.org25509882013-04-09 10:30:35 +0000853int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000854{
niklase@google.com470e71d2011-07-07 08:21:25 +0000855 CHECK_INITIALIZED();
856
857 bool isAvailable(0);
858
859 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
860 {
861 return -1;
862 }
863
864 *available = isAvailable;
865
866 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
867 return (0);
868}
869
870// ----------------------------------------------------------------------------
871// SetSpeakerMute
872// ----------------------------------------------------------------------------
873
pbos@webrtc.org25509882013-04-09 10:30:35 +0000874int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000875{
niklase@google.com470e71d2011-07-07 08:21:25 +0000876 CHECK_INITIALIZED();
877 return (_ptrAudioDevice->SetSpeakerMute(enable));
878}
879
880// ----------------------------------------------------------------------------
881// SpeakerMute
882// ----------------------------------------------------------------------------
883
pbos@webrtc.org25509882013-04-09 10:30:35 +0000884int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000885{
niklase@google.com470e71d2011-07-07 08:21:25 +0000886 CHECK_INITIALIZED();
887
888 bool muted(false);
889
890 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
891 {
892 return -1;
893 }
894
895 *enabled = muted;
896
897 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
898 return (0);
899}
900
901// ----------------------------------------------------------------------------
902// MicrophoneMuteIsAvailable
903// ----------------------------------------------------------------------------
904
pbos@webrtc.org25509882013-04-09 10:30:35 +0000905int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000906{
niklase@google.com470e71d2011-07-07 08:21:25 +0000907 CHECK_INITIALIZED();
908
909 bool isAvailable(0);
910
911 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
912 {
913 return -1;
914 }
915
916 *available = isAvailable;
917
918 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
919 return (0);
920}
921
922// ----------------------------------------------------------------------------
923// SetMicrophoneMute
924// ----------------------------------------------------------------------------
925
pbos@webrtc.org25509882013-04-09 10:30:35 +0000926int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000927{
niklase@google.com470e71d2011-07-07 08:21:25 +0000928 CHECK_INITIALIZED();
929 return (_ptrAudioDevice->SetMicrophoneMute(enable));
930}
931
932// ----------------------------------------------------------------------------
933// MicrophoneMute
934// ----------------------------------------------------------------------------
935
pbos@webrtc.org25509882013-04-09 10:30:35 +0000936int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000937{
niklase@google.com470e71d2011-07-07 08:21:25 +0000938 CHECK_INITIALIZED();
939
940 bool muted(false);
941
942 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
943 {
944 return -1;
945 }
946
947 *enabled = muted;
948
949 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
950 return (0);
951}
952
953// ----------------------------------------------------------------------------
954// MicrophoneBoostIsAvailable
955// ----------------------------------------------------------------------------
956
pbos@webrtc.org25509882013-04-09 10:30:35 +0000957int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000958{
niklase@google.com470e71d2011-07-07 08:21:25 +0000959 CHECK_INITIALIZED();
960
961 bool isAvailable(0);
962
963 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
964 {
965 return -1;
966 }
967
968 *available = isAvailable;
969
970 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
971 return (0);
972}
973
974// ----------------------------------------------------------------------------
975// SetMicrophoneBoost
976// ----------------------------------------------------------------------------
977
pbos@webrtc.org25509882013-04-09 10:30:35 +0000978int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000979{
niklase@google.com470e71d2011-07-07 08:21:25 +0000980 CHECK_INITIALIZED();
981 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
982}
983
984// ----------------------------------------------------------------------------
985// MicrophoneBoost
986// ----------------------------------------------------------------------------
987
pbos@webrtc.org25509882013-04-09 10:30:35 +0000988int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000989{
niklase@google.com470e71d2011-07-07 08:21:25 +0000990 CHECK_INITIALIZED();
991
992 bool onOff(false);
993
994 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
995 {
996 return -1;
997 }
998
999 *enabled = onOff;
1000
1001 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1002 return (0);
1003}
1004
1005// ----------------------------------------------------------------------------
1006// MicrophoneVolumeIsAvailable
1007// ----------------------------------------------------------------------------
1008
pbos@webrtc.org25509882013-04-09 10:30:35 +00001009int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001010{
niklase@google.com470e71d2011-07-07 08:21:25 +00001011 CHECK_INITIALIZED();
1012
1013 bool isAvailable(0);
1014
1015 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1016 {
1017 return -1;
1018 }
1019
1020 *available = isAvailable;
1021
1022 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1023 return (0);
1024}
1025
1026// ----------------------------------------------------------------------------
1027// SetMicrophoneVolume
1028// ----------------------------------------------------------------------------
1029
pbos@webrtc.org25509882013-04-09 10:30:35 +00001030int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001031{
niklase@google.com470e71d2011-07-07 08:21:25 +00001032 CHECK_INITIALIZED();
1033 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1034}
1035
1036// ----------------------------------------------------------------------------
1037// MicrophoneVolume
1038// ----------------------------------------------------------------------------
1039
pbos@webrtc.org25509882013-04-09 10:30:35 +00001040int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001041{
1042 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1043 CHECK_INITIALIZED();
1044
pbos@webrtc.org25509882013-04-09 10:30:35 +00001045 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001046
1047 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1048 {
1049 return -1;
1050 }
1051
1052 *volume = level;
1053
1054 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1055 return (0);
1056}
1057
1058// ----------------------------------------------------------------------------
1059// StereoRecordingIsAvailable
1060// ----------------------------------------------------------------------------
1061
pbos@webrtc.org25509882013-04-09 10:30:35 +00001062int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001063{
niklase@google.com470e71d2011-07-07 08:21:25 +00001064 CHECK_INITIALIZED();
1065
1066 bool isAvailable(0);
1067
1068 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1069 {
1070 return -1;
1071 }
1072
1073 *available = isAvailable;
1074
1075 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1076 return (0);
1077}
1078
1079// ----------------------------------------------------------------------------
1080// SetStereoRecording
1081// ----------------------------------------------------------------------------
1082
pbos@webrtc.org25509882013-04-09 10:30:35 +00001083int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001084{
niklase@google.com470e71d2011-07-07 08:21:25 +00001085 CHECK_INITIALIZED();
1086
1087 if (_ptrAudioDevice->RecordingIsInitialized())
1088 {
1089 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1090 return -1;
1091 }
1092
1093 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1094 {
1095 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1096 return -1;
1097 }
1098
pbos@webrtc.org25509882013-04-09 10:30:35 +00001099 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001100 if (enable)
1101 {
1102 nChannels = 2;
1103 }
1104 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1105
1106 return 0;
1107}
1108
1109// ----------------------------------------------------------------------------
1110// StereoRecording
1111// ----------------------------------------------------------------------------
1112
pbos@webrtc.org25509882013-04-09 10:30:35 +00001113int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001114{
niklase@google.com470e71d2011-07-07 08:21:25 +00001115 CHECK_INITIALIZED();
1116
1117 bool stereo(false);
1118
1119 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1120 {
1121 return -1;
1122 }
1123
1124 *enabled = stereo;
1125
1126 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1127 return (0);
1128}
1129
1130// ----------------------------------------------------------------------------
1131// SetRecordingChannel
1132// ----------------------------------------------------------------------------
1133
pbos@webrtc.org25509882013-04-09 10:30:35 +00001134int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001135{
1136 if (channel == kChannelBoth)
1137 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001138 }
1139 else if (channel == kChannelLeft)
1140 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001141 }
1142 else
1143 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001144 }
1145 CHECK_INITIALIZED();
1146
1147 bool stereo(false);
1148
1149 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1150 {
1151 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1152 return -1;
1153 }
1154
1155 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1156}
1157
1158// ----------------------------------------------------------------------------
1159// RecordingChannel
1160// ----------------------------------------------------------------------------
1161
pbos@webrtc.org25509882013-04-09 10:30:35 +00001162int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001163{
niklase@google.com470e71d2011-07-07 08:21:25 +00001164 CHECK_INITIALIZED();
1165
1166 ChannelType chType;
1167
1168 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1169 {
1170 return -1;
1171 }
1172
1173 *channel = chType;
1174
1175 if (*channel == kChannelBoth)
1176 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001177 }
1178 else if (*channel == kChannelLeft)
1179 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001180 }
1181 else
1182 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001183 }
1184
1185 return (0);
1186}
1187
1188// ----------------------------------------------------------------------------
1189// StereoPlayoutIsAvailable
1190// ----------------------------------------------------------------------------
1191
pbos@webrtc.org25509882013-04-09 10:30:35 +00001192int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001193{
niklase@google.com470e71d2011-07-07 08:21:25 +00001194 CHECK_INITIALIZED();
1195
1196 bool isAvailable(0);
1197
1198 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1199 {
1200 return -1;
1201 }
1202
1203 *available = isAvailable;
1204
1205 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1206 return (0);
1207}
1208
1209// ----------------------------------------------------------------------------
1210// SetStereoPlayout
1211// ----------------------------------------------------------------------------
1212
pbos@webrtc.org25509882013-04-09 10:30:35 +00001213int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001214{
niklase@google.com470e71d2011-07-07 08:21:25 +00001215 CHECK_INITIALIZED();
1216
1217 if (_ptrAudioDevice->PlayoutIsInitialized())
1218 {
1219 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1220 return -1;
1221 }
1222
1223 if (_ptrAudioDevice->SetStereoPlayout(enable))
1224 {
1225 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1226 return -1;
1227 }
1228
pbos@webrtc.org25509882013-04-09 10:30:35 +00001229 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001230 if (enable)
1231 {
1232 nChannels = 2;
1233 }
1234 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1235
1236 return 0;
1237}
1238
1239// ----------------------------------------------------------------------------
1240// StereoPlayout
1241// ----------------------------------------------------------------------------
1242
pbos@webrtc.org25509882013-04-09 10:30:35 +00001243int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001244{
niklase@google.com470e71d2011-07-07 08:21:25 +00001245 CHECK_INITIALIZED();
1246
1247 bool stereo(false);
1248
1249 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1250 {
1251 return -1;
1252 }
1253
1254 *enabled = stereo;
1255
1256 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1257 return (0);
1258}
1259
1260// ----------------------------------------------------------------------------
1261// SetAGC
1262// ----------------------------------------------------------------------------
1263
pbos@webrtc.org25509882013-04-09 10:30:35 +00001264int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001265{
niklase@google.com470e71d2011-07-07 08:21:25 +00001266 CHECK_INITIALIZED();
1267 return (_ptrAudioDevice->SetAGC(enable));
1268}
1269
1270// ----------------------------------------------------------------------------
1271// AGC
1272// ----------------------------------------------------------------------------
1273
1274bool AudioDeviceModuleImpl::AGC() const
1275{
niklase@google.com470e71d2011-07-07 08:21:25 +00001276 CHECK_INITIALIZED_BOOL();
1277 return (_ptrAudioDevice->AGC());
1278}
1279
1280// ----------------------------------------------------------------------------
1281// PlayoutIsAvailable
1282// ----------------------------------------------------------------------------
1283
pbos@webrtc.org25509882013-04-09 10:30:35 +00001284int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001285{
niklase@google.com470e71d2011-07-07 08:21:25 +00001286 CHECK_INITIALIZED();
1287
1288 bool isAvailable(0);
1289
1290 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1291 {
1292 return -1;
1293 }
1294
1295 *available = isAvailable;
1296
1297 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1298 return (0);
1299}
1300
1301// ----------------------------------------------------------------------------
1302// RecordingIsAvailable
1303// ----------------------------------------------------------------------------
1304
pbos@webrtc.org25509882013-04-09 10:30:35 +00001305int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001306{
niklase@google.com470e71d2011-07-07 08:21:25 +00001307 CHECK_INITIALIZED();
1308
1309 bool isAvailable(0);
1310
1311 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1312 {
1313 return -1;
1314 }
1315
1316 *available = isAvailable;
1317
1318 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1319 return (0);
1320}
1321
1322// ----------------------------------------------------------------------------
1323// MaxMicrophoneVolume
1324// ----------------------------------------------------------------------------
1325
pbos@webrtc.org25509882013-04-09 10:30:35 +00001326int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001327{
1328 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1329 CHECK_INITIALIZED();
1330
pbos@webrtc.org25509882013-04-09 10:30:35 +00001331 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001332
1333 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1334 {
1335 return -1;
1336 }
1337
1338 *maxVolume = maxVol;
1339
1340 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1341 return (0);
1342}
1343
1344// ----------------------------------------------------------------------------
1345// MinMicrophoneVolume
1346// ----------------------------------------------------------------------------
1347
pbos@webrtc.org25509882013-04-09 10:30:35 +00001348int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001349{
niklase@google.com470e71d2011-07-07 08:21:25 +00001350 CHECK_INITIALIZED();
1351
pbos@webrtc.org25509882013-04-09 10:30:35 +00001352 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001353
1354 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1355 {
1356 return -1;
1357 }
1358
1359 *minVolume = minVol;
1360
1361 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1362 return (0);
1363}
1364
1365// ----------------------------------------------------------------------------
1366// MicrophoneVolumeStepSize
1367// ----------------------------------------------------------------------------
1368
pbos@webrtc.org25509882013-04-09 10:30:35 +00001369int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001370{
niklase@google.com470e71d2011-07-07 08:21:25 +00001371 CHECK_INITIALIZED();
1372
pbos@webrtc.org25509882013-04-09 10:30:35 +00001373 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001374
1375 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1376 {
1377 return -1;
1378 }
1379
1380 *stepSize = delta;
1381
1382 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1383 return (0);
1384}
1385
1386// ----------------------------------------------------------------------------
1387// PlayoutDevices
1388// ----------------------------------------------------------------------------
1389
pbos@webrtc.org25509882013-04-09 10:30:35 +00001390int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001391{
niklase@google.com470e71d2011-07-07 08:21:25 +00001392 CHECK_INITIALIZED();
1393
pbos@webrtc.org25509882013-04-09 10:30:35 +00001394 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001395
1396 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001397 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001398}
1399
1400// ----------------------------------------------------------------------------
1401// SetPlayoutDevice I (II)
1402// ----------------------------------------------------------------------------
1403
pbos@webrtc.org25509882013-04-09 10:30:35 +00001404int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001405{
niklase@google.com470e71d2011-07-07 08:21:25 +00001406 CHECK_INITIALIZED();
1407 return (_ptrAudioDevice->SetPlayoutDevice(index));
1408}
1409
1410// ----------------------------------------------------------------------------
1411// SetPlayoutDevice II (II)
1412// ----------------------------------------------------------------------------
1413
pbos@webrtc.org25509882013-04-09 10:30:35 +00001414int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001415{
1416 if (device == kDefaultDevice)
1417 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001418 }
1419 else
1420 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001421 }
1422 CHECK_INITIALIZED();
1423
1424 return (_ptrAudioDevice->SetPlayoutDevice(device));
1425}
1426
1427// ----------------------------------------------------------------------------
1428// PlayoutDeviceName
1429// ----------------------------------------------------------------------------
1430
pbos@webrtc.org25509882013-04-09 10:30:35 +00001431int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1432 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001433 char name[kAdmMaxDeviceNameSize],
1434 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001435{
niklase@google.com470e71d2011-07-07 08:21:25 +00001436 CHECK_INITIALIZED();
1437
1438 if (name == NULL)
1439 {
1440 _lastError = kAdmErrArgument;
1441 return -1;
1442 }
1443
1444 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1445 {
1446 return -1;
1447 }
1448
1449 if (name != NULL)
1450 {
1451 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1452 }
1453 if (guid != NULL)
1454 {
1455 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1456 }
1457
1458 return (0);
1459}
1460
1461// ----------------------------------------------------------------------------
1462// RecordingDeviceName
1463// ----------------------------------------------------------------------------
1464
pbos@webrtc.org25509882013-04-09 10:30:35 +00001465int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1466 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001467 char name[kAdmMaxDeviceNameSize],
1468 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001469{
niklase@google.com470e71d2011-07-07 08:21:25 +00001470 CHECK_INITIALIZED();
1471
1472 if (name == NULL)
1473 {
1474 _lastError = kAdmErrArgument;
1475 return -1;
1476 }
1477
1478 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1479 {
1480 return -1;
1481 }
1482
1483 if (name != NULL)
1484 {
1485 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1486 }
1487 if (guid != NULL)
1488 {
1489 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1490 }
1491
1492 return (0);
1493}
1494
1495// ----------------------------------------------------------------------------
1496// RecordingDevices
1497// ----------------------------------------------------------------------------
1498
pbos@webrtc.org25509882013-04-09 10:30:35 +00001499int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001500{
niklase@google.com470e71d2011-07-07 08:21:25 +00001501 CHECK_INITIALIZED();
1502
pbos@webrtc.org25509882013-04-09 10:30:35 +00001503 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001504
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001505 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1506 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001507 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001508}
1509
1510// ----------------------------------------------------------------------------
1511// SetRecordingDevice I (II)
1512// ----------------------------------------------------------------------------
1513
pbos@webrtc.org25509882013-04-09 10:30:35 +00001514int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001515{
niklase@google.com470e71d2011-07-07 08:21:25 +00001516 CHECK_INITIALIZED();
1517 return (_ptrAudioDevice->SetRecordingDevice(index));
1518}
1519
1520// ----------------------------------------------------------------------------
1521// SetRecordingDevice II (II)
1522// ----------------------------------------------------------------------------
1523
pbos@webrtc.org25509882013-04-09 10:30:35 +00001524int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001525{
1526 if (device == kDefaultDevice)
1527 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001528 }
1529 else
1530 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001531 }
1532 CHECK_INITIALIZED();
1533
1534 return (_ptrAudioDevice->SetRecordingDevice(device));
1535}
1536
1537// ----------------------------------------------------------------------------
1538// InitPlayout
1539// ----------------------------------------------------------------------------
1540
pbos@webrtc.org25509882013-04-09 10:30:35 +00001541int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001542{
niklase@google.com470e71d2011-07-07 08:21:25 +00001543 CHECK_INITIALIZED();
1544 _audioDeviceBuffer.InitPlayout();
1545 return (_ptrAudioDevice->InitPlayout());
1546}
1547
1548// ----------------------------------------------------------------------------
1549// InitRecording
1550// ----------------------------------------------------------------------------
1551
pbos@webrtc.org25509882013-04-09 10:30:35 +00001552int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001553{
niklase@google.com470e71d2011-07-07 08:21:25 +00001554 CHECK_INITIALIZED();
1555 _audioDeviceBuffer.InitRecording();
1556 return (_ptrAudioDevice->InitRecording());
1557}
1558
1559// ----------------------------------------------------------------------------
1560// PlayoutIsInitialized
1561// ----------------------------------------------------------------------------
1562
1563bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1564{
niklase@google.com470e71d2011-07-07 08:21:25 +00001565 CHECK_INITIALIZED_BOOL();
1566 return (_ptrAudioDevice->PlayoutIsInitialized());
1567}
1568
1569// ----------------------------------------------------------------------------
1570// RecordingIsInitialized
1571// ----------------------------------------------------------------------------
1572
1573bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1574{
niklase@google.com470e71d2011-07-07 08:21:25 +00001575 CHECK_INITIALIZED_BOOL();
1576 return (_ptrAudioDevice->RecordingIsInitialized());
1577}
1578
1579// ----------------------------------------------------------------------------
1580// StartPlayout
1581// ----------------------------------------------------------------------------
1582
pbos@webrtc.org25509882013-04-09 10:30:35 +00001583int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001584{
niklase@google.com470e71d2011-07-07 08:21:25 +00001585 CHECK_INITIALIZED();
1586 return (_ptrAudioDevice->StartPlayout());
1587}
1588
1589// ----------------------------------------------------------------------------
1590// StopPlayout
1591// ----------------------------------------------------------------------------
1592
pbos@webrtc.org25509882013-04-09 10:30:35 +00001593int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001594{
niklase@google.com470e71d2011-07-07 08:21:25 +00001595 CHECK_INITIALIZED();
1596 return (_ptrAudioDevice->StopPlayout());
1597}
1598
1599// ----------------------------------------------------------------------------
1600// Playing
1601// ----------------------------------------------------------------------------
1602
1603bool AudioDeviceModuleImpl::Playing() const
1604{
niklase@google.com470e71d2011-07-07 08:21:25 +00001605 CHECK_INITIALIZED_BOOL();
1606 return (_ptrAudioDevice->Playing());
1607}
1608
1609// ----------------------------------------------------------------------------
1610// StartRecording
1611// ----------------------------------------------------------------------------
1612
pbos@webrtc.org25509882013-04-09 10:30:35 +00001613int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001614{
niklase@google.com470e71d2011-07-07 08:21:25 +00001615 CHECK_INITIALIZED();
1616 return (_ptrAudioDevice->StartRecording());
1617}
1618// ----------------------------------------------------------------------------
1619// StopRecording
1620// ----------------------------------------------------------------------------
1621
pbos@webrtc.org25509882013-04-09 10:30:35 +00001622int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001623{
niklase@google.com470e71d2011-07-07 08:21:25 +00001624 CHECK_INITIALIZED();
1625 return (_ptrAudioDevice->StopRecording());
1626}
1627
1628// ----------------------------------------------------------------------------
1629// Recording
1630// ----------------------------------------------------------------------------
1631
1632bool AudioDeviceModuleImpl::Recording() const
1633{
niklase@google.com470e71d2011-07-07 08:21:25 +00001634 CHECK_INITIALIZED_BOOL();
1635 return (_ptrAudioDevice->Recording());
1636}
1637
1638// ----------------------------------------------------------------------------
1639// RegisterEventObserver
1640// ----------------------------------------------------------------------------
1641
pbos@webrtc.org25509882013-04-09 10:30:35 +00001642int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001643{
niklase@google.com470e71d2011-07-07 08:21:25 +00001644
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001645 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001646 _ptrCbAudioDeviceObserver = eventCallback;
1647
1648 return 0;
1649}
1650
1651// ----------------------------------------------------------------------------
1652// RegisterAudioCallback
1653// ----------------------------------------------------------------------------
1654
pbos@webrtc.org25509882013-04-09 10:30:35 +00001655int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001656{
niklase@google.com470e71d2011-07-07 08:21:25 +00001657
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001658 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001659 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1660
1661 return 0;
1662}
1663
1664// ----------------------------------------------------------------------------
1665// StartRawInputFileRecording
1666// ----------------------------------------------------------------------------
1667
pbos@webrtc.org25509882013-04-09 10:30:35 +00001668int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001669 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001670{
niklase@google.com470e71d2011-07-07 08:21:25 +00001671 CHECK_INITIALIZED();
1672
1673 if (NULL == pcmFileNameUTF8)
1674 {
1675 return -1;
1676 }
1677
1678 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1679}
1680
1681// ----------------------------------------------------------------------------
1682// StopRawInputFileRecording
1683// ----------------------------------------------------------------------------
1684
pbos@webrtc.org25509882013-04-09 10:30:35 +00001685int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001686{
niklase@google.com470e71d2011-07-07 08:21:25 +00001687 CHECK_INITIALIZED();
1688
1689 return (_audioDeviceBuffer.StopInputFileRecording());
1690}
1691
1692// ----------------------------------------------------------------------------
1693// StartRawOutputFileRecording
1694// ----------------------------------------------------------------------------
1695
pbos@webrtc.org25509882013-04-09 10:30:35 +00001696int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001697 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001698{
niklase@google.com470e71d2011-07-07 08:21:25 +00001699 CHECK_INITIALIZED();
1700
1701 if (NULL == pcmFileNameUTF8)
1702 {
1703 return -1;
1704 }
1705
1706 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1707}
1708
1709// ----------------------------------------------------------------------------
1710// StopRawOutputFileRecording
1711// ----------------------------------------------------------------------------
1712
pbos@webrtc.org25509882013-04-09 10:30:35 +00001713int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001714{
niklase@google.com470e71d2011-07-07 08:21:25 +00001715 CHECK_INITIALIZED();
1716
1717 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001718}
1719
1720// ----------------------------------------------------------------------------
1721// SetPlayoutBuffer
1722// ----------------------------------------------------------------------------
1723
pbos@webrtc.org25509882013-04-09 10:30:35 +00001724int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001725{
niklase@google.com470e71d2011-07-07 08:21:25 +00001726 CHECK_INITIALIZED();
1727
1728 if (_ptrAudioDevice->PlayoutIsInitialized())
1729 {
1730 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1731 return -1;
1732 }
1733
pbos@webrtc.org25509882013-04-09 10:30:35 +00001734 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001735
1736 if (kFixedBufferSize == type)
1737 {
1738 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1739 {
1740 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1741 return -1;
1742 }
1743 }
1744
1745 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1746 {
1747 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1748 }
1749
1750 return ret;
1751}
1752
1753// ----------------------------------------------------------------------------
1754// PlayoutBuffer
1755// ----------------------------------------------------------------------------
1756
pbos@webrtc.org25509882013-04-09 10:30:35 +00001757int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001758{
niklase@google.com470e71d2011-07-07 08:21:25 +00001759 CHECK_INITIALIZED();
1760
1761 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001762 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001763
1764 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1765 {
1766 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1767 return -1;
1768 }
1769
1770 *type = bufType;
1771 *sizeMS = size;
1772
1773 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1774 return (0);
1775}
1776
1777// ----------------------------------------------------------------------------
1778// PlayoutDelay
1779// ----------------------------------------------------------------------------
1780
pbos@webrtc.org25509882013-04-09 10:30:35 +00001781int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001782{
1783 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1784 CHECK_INITIALIZED();
1785
pbos@webrtc.org25509882013-04-09 10:30:35 +00001786 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001787
1788 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1789 {
1790 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1791 return -1;
1792 }
1793
1794 *delayMS = delay;
1795
1796 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1797 return (0);
1798}
1799
1800// ----------------------------------------------------------------------------
1801// RecordingDelay
1802// ----------------------------------------------------------------------------
1803
pbos@webrtc.org25509882013-04-09 10:30:35 +00001804int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001805{
1806 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1807 CHECK_INITIALIZED();
1808
pbos@webrtc.org25509882013-04-09 10:30:35 +00001809 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001810
1811 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1812 {
1813 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1814 return -1;
1815 }
1816
1817 *delayMS = delay;
1818
1819 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1820 return (0);
1821}
1822
1823// ----------------------------------------------------------------------------
1824// CPULoad
1825// ----------------------------------------------------------------------------
1826
pbos@webrtc.org25509882013-04-09 10:30:35 +00001827int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001828{
niklase@google.com470e71d2011-07-07 08:21:25 +00001829 CHECK_INITIALIZED();
1830
pbos@webrtc.org25509882013-04-09 10:30:35 +00001831 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001832
1833 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1834 {
1835 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1836 return -1;
1837 }
1838
1839 *load = cpuLoad;
1840
1841 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1842 return (0);
1843}
1844
1845// ----------------------------------------------------------------------------
1846// SetRecordingSampleRate
1847// ----------------------------------------------------------------------------
1848
pbos@webrtc.org25509882013-04-09 10:30:35 +00001849int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001850{
niklase@google.com470e71d2011-07-07 08:21:25 +00001851 CHECK_INITIALIZED();
1852
1853 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1854 {
1855 return -1;
1856 }
1857
1858 return (0);
1859}
1860
1861// ----------------------------------------------------------------------------
1862// RecordingSampleRate
1863// ----------------------------------------------------------------------------
1864
pbos@webrtc.org25509882013-04-09 10:30:35 +00001865int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001866{
niklase@google.com470e71d2011-07-07 08:21:25 +00001867 CHECK_INITIALIZED();
1868
pbos@webrtc.org25509882013-04-09 10:30:35 +00001869 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001870
1871 if (sampleRate == -1)
1872 {
1873 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1874 return -1;
1875 }
1876
1877 *samplesPerSec = sampleRate;
1878
1879 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1880 return (0);
1881}
1882
1883// ----------------------------------------------------------------------------
1884// SetPlayoutSampleRate
1885// ----------------------------------------------------------------------------
1886
pbos@webrtc.org25509882013-04-09 10:30:35 +00001887int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001888{
niklase@google.com470e71d2011-07-07 08:21:25 +00001889 CHECK_INITIALIZED();
1890
1891 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1892 {
1893 return -1;
1894 }
1895
1896 return (0);
1897}
1898
1899// ----------------------------------------------------------------------------
1900// PlayoutSampleRate
1901// ----------------------------------------------------------------------------
1902
pbos@webrtc.org25509882013-04-09 10:30:35 +00001903int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001904{
niklase@google.com470e71d2011-07-07 08:21:25 +00001905 CHECK_INITIALIZED();
1906
pbos@webrtc.org25509882013-04-09 10:30:35 +00001907 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001908
1909 if (sampleRate == -1)
1910 {
1911 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1912 return -1;
1913 }
1914
1915 *samplesPerSec = sampleRate;
1916
1917 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1918 return (0);
1919}
1920
1921// ----------------------------------------------------------------------------
1922// ResetAudioDevice
1923// ----------------------------------------------------------------------------
1924
pbos@webrtc.org25509882013-04-09 10:30:35 +00001925int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001926{
niklase@google.com470e71d2011-07-07 08:21:25 +00001927 CHECK_INITIALIZED();
1928
1929
1930 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1931 {
1932 return -1;
1933 }
1934
1935 return (0);
1936}
1937
1938// ----------------------------------------------------------------------------
1939// SetLoudspeakerStatus
1940// ----------------------------------------------------------------------------
1941
pbos@webrtc.org25509882013-04-09 10:30:35 +00001942int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001943{
niklase@google.com470e71d2011-07-07 08:21:25 +00001944 CHECK_INITIALIZED();
1945
1946 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1947 {
1948 return -1;
1949 }
1950
1951 return 0;
1952}
1953
1954// ----------------------------------------------------------------------------
1955// GetLoudspeakerStatus
1956// ----------------------------------------------------------------------------
1957
pbos@webrtc.org25509882013-04-09 10:30:35 +00001958int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001959{
niklase@google.com470e71d2011-07-07 08:21:25 +00001960 CHECK_INITIALIZED();
1961
1962 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1963 {
1964 return -1;
1965 }
1966
1967 return 0;
1968}
1969
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001970int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1971{
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001972 CHECK_INITIALIZED();
1973 return _ptrAudioDevice->EnableBuiltInAEC(enable);
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001974}
1975
1976bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1977{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001978 CHECK_INITIALIZED_BOOL();
1979
1980 return _ptrAudioDevice->BuiltInAECIsEnabled();
1981}
1982
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001983bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1984 CHECK_INITIALIZED_BOOL();
1985 return _ptrAudioDevice->BuiltInAECIsAvailable();
1986}
1987
niklase@google.com470e71d2011-07-07 08:21:25 +00001988// ============================================================================
1989// Private Methods
1990// ============================================================================
1991
1992// ----------------------------------------------------------------------------
1993// Platform
1994// ----------------------------------------------------------------------------
1995
1996AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1997{
1998 return _platformType;
1999}
2000
2001// ----------------------------------------------------------------------------
2002// PlatformAudioLayer
2003// ----------------------------------------------------------------------------
2004
2005AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2006{
niklase@google.com470e71d2011-07-07 08:21:25 +00002007
2008 switch (_platformAudioLayer)
2009 {
2010 case kPlatformDefaultAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002011 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2012 "output: kPlatformDefaultAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002013 break;
2014 case kWindowsWaveAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002015 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2016 "output: kWindowsWaveAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002017 break;
2018 case kWindowsCoreAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002019 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2020 "output: kWindowsCoreAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002021 break;
2022 case kLinuxAlsaAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002023 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2024 "output: kLinuxAlsaAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002025 break;
2026 case kDummyAudio:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002027 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2028 "output: kDummyAudio");
niklase@google.com470e71d2011-07-07 08:21:25 +00002029 break;
2030 default:
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00002031 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2032 "output: INVALID");
niklase@google.com470e71d2011-07-07 08:21:25 +00002033 break;
2034 }
2035
2036 return _platformAudioLayer;
2037}
2038
2039} // namespace webrtc