blob: 6e31fc3fd17b81f8f6f0840e315c79ea8cd24f98 [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)
henrikab2619892015-05-18 16:49:16 +020026#include <stdlib.h>
27#include "audio_device_utility_android.h"
28#include "webrtc/modules/audio_device/android/audio_device_template.h"
29#include "webrtc/modules/audio_device/android/audio_manager.h"
30#include "webrtc/modules/audio_device/android/audio_record_jni.h"
31#include "webrtc/modules/audio_device/android/audio_track_jni.h"
32#include "webrtc/modules/audio_device/android/opensles_player.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
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000272#if defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +0200273 // Create an Android audio manager.
274 _audioManagerAndroid.reset(new AudioManager());
275 // Select best possible combination of audio layers.
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000276 if (audioLayer == kPlatformDefaultAudio) {
henrikab2619892015-05-18 16:49:16 +0200277 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
278 // Always use OpenSL ES for output on devices that supports the
279 // low-latency output audio path.
280 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
281 } else {
282 // Use Java-based audio in both directions when low-latency output
283 // is not supported.
284 audioLayer = kAndroidJavaAudio;
285 }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000286 }
henrikab2619892015-05-18 16:49:16 +0200287 AudioManager* audio_manager = _audioManagerAndroid.get();
288 if (audioLayer == kAndroidJavaAudio) {
289 // Java audio for both input and output audio.
290 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
291 audioLayer, audio_manager);
292 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
293 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
294 // This combination provides low-latency output audio and at the same
295 // time support for HW AEC using the AudioRecord Java API.
296 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
297 audioLayer, audio_manager);
298 } else {
299 // Invalid audio layer.
300 ptrAudioDevice = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000301 }
302
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000303 if (ptrAudioDevice != NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000304 // Create the Android implementation of the Device Utility.
305 ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
306 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000307 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000308
309 // Create the *Linux* implementation of the Audio Device
310 //
311#elif defined(WEBRTC_LINUX)
312 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
313 {
314#if defined(LINUX_PULSE)
315 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
316
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000317 // create *Linux PulseAudio* implementation
318 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
319 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000320 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000321 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000322 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
323 }
324 else
325 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000326 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000327#endif
328#if defined(LINUX_ALSA)
329 // create *Linux ALSA Audio* implementation
330 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
331 if (ptrAudioDevice != NULL)
332 {
333 // Pulse Audio was not supported => revert to ALSA instead
334 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
335 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
336 }
337#endif
338#if defined(LINUX_PULSE)
339 }
340#endif
341 }
342 else if (audioLayer == kLinuxAlsaAudio)
343 {
344#if defined(LINUX_ALSA)
345 // create *Linux ALSA Audio* implementation
346 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
347 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
348#endif
349 }
350
351 if (ptrAudioDevice != NULL)
352 {
353 // Create the Linux implementation of the Device Utility.
354 // This class is independent of the selected audio layer
355 // for Linux.
356 //
357 ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
358 }
359#endif // #if defined(WEBRTC_LINUX)
360
361 // Create the *iPhone* implementation of the Audio Device
362 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000363#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000364 if (audioLayer == kPlatformDefaultAudio)
365 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000366 // Create iOS Audio Device implementation.
367 ptrAudioDevice = new AudioDeviceIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000368 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
369 }
370
371 if (ptrAudioDevice != NULL)
372 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000373 // Create iOS Device Utility implementation.
374 ptrAudioDeviceUtility = new AudioDeviceUtilityIOS(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000375 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000376 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
378 // Create the *Mac* implementation of the Audio Device
379 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000380#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000381 if (audioLayer == kPlatformDefaultAudio)
382 {
383 // Create *Mac Audio* implementation
384 ptrAudioDevice = new AudioDeviceMac(Id());
385 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
386 }
387
388 if (ptrAudioDevice != NULL)
389 {
390 // Create the Mac implementation of the Device Utility.
391 ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
392 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000393#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
395 // Create the *Dummy* implementation of the Audio Device
396 // Available for all platforms
397 //
398 if (audioLayer == kDummyAudio)
399 {
400 // Create *Dummy Audio* implementation
401 assert(!ptrAudioDevice);
402 ptrAudioDevice = new AudioDeviceDummy(Id());
403 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
404
405 if (ptrAudioDevice != NULL)
406 {
ajm@google.come89f6b52011-07-29 18:03:57 +0000407 ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
niklase@google.com470e71d2011-07-07 08:21:25 +0000408 }
409 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000410#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000411
412 if (ptrAudioDevice == NULL)
413 {
414 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
415 return -1;
416 }
417
418 if (ptrAudioDeviceUtility == NULL)
419 {
420 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
421 return -1;
422 }
423
424 // Store valid output pointers
425 //
426 _ptrAudioDevice = ptrAudioDevice;
427 _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
428
429 return 0;
430}
431
432// ----------------------------------------------------------------------------
433// AttachAudioBuffer
434//
435// Install "bridge" between the platform implemetation and the generic
436// implementation. The "child" shall set the native sampling rate and the
437// number of channels in this function call.
438// ----------------------------------------------------------------------------
439
pbos@webrtc.org25509882013-04-09 10:30:35 +0000440int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000441{
442 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
443
444 _audioDeviceBuffer.SetId(_id);
445 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
446 return 0;
447}
448
449// ----------------------------------------------------------------------------
450// ~AudioDeviceModuleImpl - dtor
451// ----------------------------------------------------------------------------
452
453AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
454{
455 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000456
457 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000458 {
henrika@google.com73d65512011-09-07 15:11:18 +0000459 delete _ptrAudioDevice;
460 _ptrAudioDevice = NULL;
461 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000462
henrika@google.com73d65512011-09-07 15:11:18 +0000463 if (_ptrAudioDeviceUtility)
464 {
465 delete _ptrAudioDeviceUtility;
466 _ptrAudioDeviceUtility = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000467 }
468
469 delete &_critSect;
470 delete &_critSectEventCb;
471 delete &_critSectAudioCb;
472}
473
474// ============================================================================
475// Module
476// ============================================================================
477
478// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000479// Module::TimeUntilNextProcess
480//
481// Returns the number of milliseconds until the module want a worker thread
482// to call Process().
483// ----------------------------------------------------------------------------
484
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000485int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000486{
pbos@webrtc.org25509882013-04-09 10:30:35 +0000487 uint32_t now = AudioDeviceUtility::GetTimeInMS();
488 int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000489 return (deltaProcess);
490}
491
492// ----------------------------------------------------------------------------
493// Module::Process
494//
495// Check for posted error and warning reports. Generate callbacks if
496// new reports exists.
497// ----------------------------------------------------------------------------
498
pbos@webrtc.org25509882013-04-09 10:30:35 +0000499int32_t AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000500{
niklase@google.com470e71d2011-07-07 08:21:25 +0000501
502 _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
503
504 // kPlayoutWarning
505 if (_ptrAudioDevice->PlayoutWarning())
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(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
511 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
512 }
513 _ptrAudioDevice->ClearPlayoutWarning();
514 }
515
516 // kPlayoutError
517 if (_ptrAudioDevice->PlayoutError())
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(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
523 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
524 }
525 _ptrAudioDevice->ClearPlayoutError();
526 }
527
528 // kRecordingWarning
529 if (_ptrAudioDevice->RecordingWarning())
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(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
535 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
536 }
537 _ptrAudioDevice->ClearRecordingWarning();
538 }
539
540 // kRecordingError
541 if (_ptrAudioDevice->RecordingError())
542 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000543 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000544 if (_ptrCbAudioDeviceObserver)
545 {
546 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
547 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
548 }
549 _ptrAudioDevice->ClearRecordingError();
550 }
551
552 return 0;
553}
554
555// ============================================================================
556// Public API
557// ============================================================================
558
559// ----------------------------------------------------------------------------
560// ActiveAudioLayer
561// ----------------------------------------------------------------------------
562
henrikab2619892015-05-18 16:49:16 +0200563int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
564 AudioLayer activeAudio;
565 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
566 return -1;
567 }
568 *audioLayer = activeAudio;
569 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000570}
571
572// ----------------------------------------------------------------------------
573// LastError
574// ----------------------------------------------------------------------------
575
576AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
577{
578 return _lastError;
579}
580
581// ----------------------------------------------------------------------------
582// Init
583// ----------------------------------------------------------------------------
584
pbos@webrtc.org25509882013-04-09 10:30:35 +0000585int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000586{
niklase@google.com470e71d2011-07-07 08:21:25 +0000587
588 if (_initialized)
589 return 0;
590
591 if (!_ptrAudioDeviceUtility)
592 return -1;
593
594 if (!_ptrAudioDevice)
595 return -1;
596
597 _ptrAudioDeviceUtility->Init();
598
599 if (_ptrAudioDevice->Init() == -1)
600 {
601 return -1;
602 }
603
604 _initialized = true;
605 return 0;
606}
607
608// ----------------------------------------------------------------------------
609// Terminate
610// ----------------------------------------------------------------------------
611
pbos@webrtc.org25509882013-04-09 10:30:35 +0000612int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000613{
niklase@google.com470e71d2011-07-07 08:21:25 +0000614
615 if (!_initialized)
616 return 0;
617
618 if (_ptrAudioDevice->Terminate() == -1)
619 {
620 return -1;
621 }
622
623 _initialized = false;
624 return 0;
625}
626
627// ----------------------------------------------------------------------------
628// Initialized
629// ----------------------------------------------------------------------------
630
631bool AudioDeviceModuleImpl::Initialized() const
632{
niklase@google.com470e71d2011-07-07 08:21:25 +0000633
634 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
635 return (_initialized);
636}
637
638// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000639// InitSpeaker
640// ----------------------------------------------------------------------------
641
pbos@webrtc.org25509882013-04-09 10:30:35 +0000642int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000643{
niklase@google.com470e71d2011-07-07 08:21:25 +0000644 CHECK_INITIALIZED();
645 return (_ptrAudioDevice->InitSpeaker());
646}
647
648// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000649// InitMicrophone
650// ----------------------------------------------------------------------------
651
pbos@webrtc.org25509882013-04-09 10:30:35 +0000652int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000653{
niklase@google.com470e71d2011-07-07 08:21:25 +0000654 CHECK_INITIALIZED();
655 return (_ptrAudioDevice->InitMicrophone());
656}
657
658// ----------------------------------------------------------------------------
659// SpeakerVolumeIsAvailable
660// ----------------------------------------------------------------------------
661
pbos@webrtc.org25509882013-04-09 10:30:35 +0000662int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000663{
niklase@google.com470e71d2011-07-07 08:21:25 +0000664 CHECK_INITIALIZED();
665
666 bool isAvailable(0);
667
668 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
669 {
670 return -1;
671 }
672
673 *available = isAvailable;
674
675 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
676 return (0);
677}
678
679// ----------------------------------------------------------------------------
680// SetSpeakerVolume
681// ----------------------------------------------------------------------------
682
pbos@webrtc.org25509882013-04-09 10:30:35 +0000683int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000684{
niklase@google.com470e71d2011-07-07 08:21:25 +0000685 CHECK_INITIALIZED();
686 return (_ptrAudioDevice->SetSpeakerVolume(volume));
687}
688
689// ----------------------------------------------------------------------------
690// SpeakerVolume
691// ----------------------------------------------------------------------------
692
pbos@webrtc.org25509882013-04-09 10:30:35 +0000693int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000694{
niklase@google.com470e71d2011-07-07 08:21:25 +0000695 CHECK_INITIALIZED();
696
pbos@webrtc.org25509882013-04-09 10:30:35 +0000697 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000698
699 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
700 {
701 return -1;
702 }
703
704 *volume = level;
705
706 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
707 return (0);
708}
709
710// ----------------------------------------------------------------------------
711// SetWaveOutVolume
712// ----------------------------------------------------------------------------
713
pbos@webrtc.org25509882013-04-09 10:30:35 +0000714int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000715{
niklase@google.com470e71d2011-07-07 08:21:25 +0000716 CHECK_INITIALIZED();
717 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
718}
719
720// ----------------------------------------------------------------------------
721// WaveOutVolume
722// ----------------------------------------------------------------------------
723
pbos@webrtc.org25509882013-04-09 10:30:35 +0000724int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000725{
niklase@google.com470e71d2011-07-07 08:21:25 +0000726 CHECK_INITIALIZED();
727
pbos@webrtc.org25509882013-04-09 10:30:35 +0000728 uint16_t volLeft(0);
729 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000730
731 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
732 {
733 return -1;
734 }
735
736 *volumeLeft = volLeft;
737 *volumeRight = volRight;
738
739 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
740 *volumeLeft, *volumeRight);
741
742 return (0);
743}
744
745// ----------------------------------------------------------------------------
746// SpeakerIsInitialized
747// ----------------------------------------------------------------------------
748
749bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
750{
niklase@google.com470e71d2011-07-07 08:21:25 +0000751 CHECK_INITIALIZED_BOOL();
752
753 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
754
755 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
756 return (isInitialized);
757}
758
759// ----------------------------------------------------------------------------
760// MicrophoneIsInitialized
761// ----------------------------------------------------------------------------
762
763bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
764{
niklase@google.com470e71d2011-07-07 08:21:25 +0000765 CHECK_INITIALIZED_BOOL();
766
767 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
768
769 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
770 return (isInitialized);
771}
772
773// ----------------------------------------------------------------------------
774// MaxSpeakerVolume
775// ----------------------------------------------------------------------------
776
pbos@webrtc.org25509882013-04-09 10:30:35 +0000777int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000778{
niklase@google.com470e71d2011-07-07 08:21:25 +0000779 CHECK_INITIALIZED();
780
pbos@webrtc.org25509882013-04-09 10:30:35 +0000781 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000782
783 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
784 {
785 return -1;
786 }
787
788 *maxVolume = maxVol;
789
790 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
791 return (0);
792}
793
794// ----------------------------------------------------------------------------
795// MinSpeakerVolume
796// ----------------------------------------------------------------------------
797
pbos@webrtc.org25509882013-04-09 10:30:35 +0000798int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000799{
niklase@google.com470e71d2011-07-07 08:21:25 +0000800 CHECK_INITIALIZED();
801
pbos@webrtc.org25509882013-04-09 10:30:35 +0000802 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000803
804 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
805 {
806 return -1;
807 }
808
809 *minVolume = minVol;
810
811 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
812 return (0);
813}
814
815// ----------------------------------------------------------------------------
816// SpeakerVolumeStepSize
817// ----------------------------------------------------------------------------
818
pbos@webrtc.org25509882013-04-09 10:30:35 +0000819int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000820{
niklase@google.com470e71d2011-07-07 08:21:25 +0000821 CHECK_INITIALIZED();
822
pbos@webrtc.org25509882013-04-09 10:30:35 +0000823 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000824
825 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
826 {
827 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
828 return -1;
829 }
830
831 *stepSize = delta;
832
833 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
834 return (0);
835}
836
837// ----------------------------------------------------------------------------
838// SpeakerMuteIsAvailable
839// ----------------------------------------------------------------------------
840
pbos@webrtc.org25509882013-04-09 10:30:35 +0000841int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000842{
niklase@google.com470e71d2011-07-07 08:21:25 +0000843 CHECK_INITIALIZED();
844
845 bool isAvailable(0);
846
847 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
848 {
849 return -1;
850 }
851
852 *available = isAvailable;
853
854 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
855 return (0);
856}
857
858// ----------------------------------------------------------------------------
859// SetSpeakerMute
860// ----------------------------------------------------------------------------
861
pbos@webrtc.org25509882013-04-09 10:30:35 +0000862int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000863{
niklase@google.com470e71d2011-07-07 08:21:25 +0000864 CHECK_INITIALIZED();
865 return (_ptrAudioDevice->SetSpeakerMute(enable));
866}
867
868// ----------------------------------------------------------------------------
869// SpeakerMute
870// ----------------------------------------------------------------------------
871
pbos@webrtc.org25509882013-04-09 10:30:35 +0000872int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000873{
niklase@google.com470e71d2011-07-07 08:21:25 +0000874 CHECK_INITIALIZED();
875
876 bool muted(false);
877
878 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
879 {
880 return -1;
881 }
882
883 *enabled = muted;
884
885 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
886 return (0);
887}
888
889// ----------------------------------------------------------------------------
890// MicrophoneMuteIsAvailable
891// ----------------------------------------------------------------------------
892
pbos@webrtc.org25509882013-04-09 10:30:35 +0000893int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000894{
niklase@google.com470e71d2011-07-07 08:21:25 +0000895 CHECK_INITIALIZED();
896
897 bool isAvailable(0);
898
899 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
900 {
901 return -1;
902 }
903
904 *available = isAvailable;
905
906 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
907 return (0);
908}
909
910// ----------------------------------------------------------------------------
911// SetMicrophoneMute
912// ----------------------------------------------------------------------------
913
pbos@webrtc.org25509882013-04-09 10:30:35 +0000914int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000915{
niklase@google.com470e71d2011-07-07 08:21:25 +0000916 CHECK_INITIALIZED();
917 return (_ptrAudioDevice->SetMicrophoneMute(enable));
918}
919
920// ----------------------------------------------------------------------------
921// MicrophoneMute
922// ----------------------------------------------------------------------------
923
pbos@webrtc.org25509882013-04-09 10:30:35 +0000924int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000925{
niklase@google.com470e71d2011-07-07 08:21:25 +0000926 CHECK_INITIALIZED();
927
928 bool muted(false);
929
930 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
931 {
932 return -1;
933 }
934
935 *enabled = muted;
936
937 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
938 return (0);
939}
940
941// ----------------------------------------------------------------------------
942// MicrophoneBoostIsAvailable
943// ----------------------------------------------------------------------------
944
pbos@webrtc.org25509882013-04-09 10:30:35 +0000945int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000946{
niklase@google.com470e71d2011-07-07 08:21:25 +0000947 CHECK_INITIALIZED();
948
949 bool isAvailable(0);
950
951 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
952 {
953 return -1;
954 }
955
956 *available = isAvailable;
957
958 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
959 return (0);
960}
961
962// ----------------------------------------------------------------------------
963// SetMicrophoneBoost
964// ----------------------------------------------------------------------------
965
pbos@webrtc.org25509882013-04-09 10:30:35 +0000966int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000967{
niklase@google.com470e71d2011-07-07 08:21:25 +0000968 CHECK_INITIALIZED();
969 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
970}
971
972// ----------------------------------------------------------------------------
973// MicrophoneBoost
974// ----------------------------------------------------------------------------
975
pbos@webrtc.org25509882013-04-09 10:30:35 +0000976int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000977{
niklase@google.com470e71d2011-07-07 08:21:25 +0000978 CHECK_INITIALIZED();
979
980 bool onOff(false);
981
982 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
983 {
984 return -1;
985 }
986
987 *enabled = onOff;
988
989 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
990 return (0);
991}
992
993// ----------------------------------------------------------------------------
994// MicrophoneVolumeIsAvailable
995// ----------------------------------------------------------------------------
996
pbos@webrtc.org25509882013-04-09 10:30:35 +0000997int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000998{
niklase@google.com470e71d2011-07-07 08:21:25 +0000999 CHECK_INITIALIZED();
1000
1001 bool isAvailable(0);
1002
1003 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1004 {
1005 return -1;
1006 }
1007
1008 *available = isAvailable;
1009
1010 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1011 return (0);
1012}
1013
1014// ----------------------------------------------------------------------------
1015// SetMicrophoneVolume
1016// ----------------------------------------------------------------------------
1017
pbos@webrtc.org25509882013-04-09 10:30:35 +00001018int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +00001019{
niklase@google.com470e71d2011-07-07 08:21:25 +00001020 CHECK_INITIALIZED();
1021 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1022}
1023
1024// ----------------------------------------------------------------------------
1025// MicrophoneVolume
1026// ----------------------------------------------------------------------------
1027
pbos@webrtc.org25509882013-04-09 10:30:35 +00001028int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001029{
1030 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1031 CHECK_INITIALIZED();
1032
pbos@webrtc.org25509882013-04-09 10:30:35 +00001033 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001034
1035 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1036 {
1037 return -1;
1038 }
1039
1040 *volume = level;
1041
1042 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1043 return (0);
1044}
1045
1046// ----------------------------------------------------------------------------
1047// StereoRecordingIsAvailable
1048// ----------------------------------------------------------------------------
1049
pbos@webrtc.org25509882013-04-09 10:30:35 +00001050int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001051{
niklase@google.com470e71d2011-07-07 08:21:25 +00001052 CHECK_INITIALIZED();
1053
1054 bool isAvailable(0);
1055
1056 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1057 {
1058 return -1;
1059 }
1060
1061 *available = isAvailable;
1062
1063 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1064 return (0);
1065}
1066
1067// ----------------------------------------------------------------------------
1068// SetStereoRecording
1069// ----------------------------------------------------------------------------
1070
pbos@webrtc.org25509882013-04-09 10:30:35 +00001071int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001072{
niklase@google.com470e71d2011-07-07 08:21:25 +00001073 CHECK_INITIALIZED();
1074
1075 if (_ptrAudioDevice->RecordingIsInitialized())
1076 {
1077 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1078 return -1;
1079 }
1080
1081 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1082 {
1083 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1084 return -1;
1085 }
1086
pbos@webrtc.org25509882013-04-09 10:30:35 +00001087 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001088 if (enable)
1089 {
1090 nChannels = 2;
1091 }
1092 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1093
1094 return 0;
1095}
1096
1097// ----------------------------------------------------------------------------
1098// StereoRecording
1099// ----------------------------------------------------------------------------
1100
pbos@webrtc.org25509882013-04-09 10:30:35 +00001101int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001102{
niklase@google.com470e71d2011-07-07 08:21:25 +00001103 CHECK_INITIALIZED();
1104
1105 bool stereo(false);
1106
1107 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1108 {
1109 return -1;
1110 }
1111
1112 *enabled = stereo;
1113
1114 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1115 return (0);
1116}
1117
1118// ----------------------------------------------------------------------------
1119// SetRecordingChannel
1120// ----------------------------------------------------------------------------
1121
pbos@webrtc.org25509882013-04-09 10:30:35 +00001122int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001123{
1124 if (channel == kChannelBoth)
1125 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001126 }
1127 else if (channel == kChannelLeft)
1128 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001129 }
1130 else
1131 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001132 }
1133 CHECK_INITIALIZED();
1134
1135 bool stereo(false);
1136
1137 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1138 {
1139 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1140 return -1;
1141 }
1142
1143 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1144}
1145
1146// ----------------------------------------------------------------------------
1147// RecordingChannel
1148// ----------------------------------------------------------------------------
1149
pbos@webrtc.org25509882013-04-09 10:30:35 +00001150int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001151{
niklase@google.com470e71d2011-07-07 08:21:25 +00001152 CHECK_INITIALIZED();
1153
1154 ChannelType chType;
1155
1156 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1157 {
1158 return -1;
1159 }
1160
1161 *channel = chType;
1162
1163 if (*channel == kChannelBoth)
1164 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001165 }
1166 else if (*channel == kChannelLeft)
1167 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001168 }
1169 else
1170 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001171 }
1172
1173 return (0);
1174}
1175
1176// ----------------------------------------------------------------------------
1177// StereoPlayoutIsAvailable
1178// ----------------------------------------------------------------------------
1179
pbos@webrtc.org25509882013-04-09 10:30:35 +00001180int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001181{
niklase@google.com470e71d2011-07-07 08:21:25 +00001182 CHECK_INITIALIZED();
1183
1184 bool isAvailable(0);
1185
1186 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1187 {
1188 return -1;
1189 }
1190
1191 *available = isAvailable;
1192
1193 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1194 return (0);
1195}
1196
1197// ----------------------------------------------------------------------------
1198// SetStereoPlayout
1199// ----------------------------------------------------------------------------
1200
pbos@webrtc.org25509882013-04-09 10:30:35 +00001201int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001202{
niklase@google.com470e71d2011-07-07 08:21:25 +00001203 CHECK_INITIALIZED();
1204
1205 if (_ptrAudioDevice->PlayoutIsInitialized())
1206 {
1207 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1208 return -1;
1209 }
1210
1211 if (_ptrAudioDevice->SetStereoPlayout(enable))
1212 {
1213 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1214 return -1;
1215 }
1216
pbos@webrtc.org25509882013-04-09 10:30:35 +00001217 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001218 if (enable)
1219 {
1220 nChannels = 2;
1221 }
1222 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1223
1224 return 0;
1225}
1226
1227// ----------------------------------------------------------------------------
1228// StereoPlayout
1229// ----------------------------------------------------------------------------
1230
pbos@webrtc.org25509882013-04-09 10:30:35 +00001231int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001232{
niklase@google.com470e71d2011-07-07 08:21:25 +00001233 CHECK_INITIALIZED();
1234
1235 bool stereo(false);
1236
1237 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1238 {
1239 return -1;
1240 }
1241
1242 *enabled = stereo;
1243
1244 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1245 return (0);
1246}
1247
1248// ----------------------------------------------------------------------------
1249// SetAGC
1250// ----------------------------------------------------------------------------
1251
pbos@webrtc.org25509882013-04-09 10:30:35 +00001252int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001253{
niklase@google.com470e71d2011-07-07 08:21:25 +00001254 CHECK_INITIALIZED();
1255 return (_ptrAudioDevice->SetAGC(enable));
1256}
1257
1258// ----------------------------------------------------------------------------
1259// AGC
1260// ----------------------------------------------------------------------------
1261
1262bool AudioDeviceModuleImpl::AGC() const
1263{
niklase@google.com470e71d2011-07-07 08:21:25 +00001264 CHECK_INITIALIZED_BOOL();
1265 return (_ptrAudioDevice->AGC());
1266}
1267
1268// ----------------------------------------------------------------------------
1269// PlayoutIsAvailable
1270// ----------------------------------------------------------------------------
1271
pbos@webrtc.org25509882013-04-09 10:30:35 +00001272int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001273{
niklase@google.com470e71d2011-07-07 08:21:25 +00001274 CHECK_INITIALIZED();
1275
1276 bool isAvailable(0);
1277
1278 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1279 {
1280 return -1;
1281 }
1282
1283 *available = isAvailable;
1284
1285 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1286 return (0);
1287}
1288
1289// ----------------------------------------------------------------------------
1290// RecordingIsAvailable
1291// ----------------------------------------------------------------------------
1292
pbos@webrtc.org25509882013-04-09 10:30:35 +00001293int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001294{
niklase@google.com470e71d2011-07-07 08:21:25 +00001295 CHECK_INITIALIZED();
1296
1297 bool isAvailable(0);
1298
1299 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1300 {
1301 return -1;
1302 }
1303
1304 *available = isAvailable;
1305
1306 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1307 return (0);
1308}
1309
1310// ----------------------------------------------------------------------------
1311// MaxMicrophoneVolume
1312// ----------------------------------------------------------------------------
1313
pbos@webrtc.org25509882013-04-09 10:30:35 +00001314int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001315{
1316 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1317 CHECK_INITIALIZED();
1318
pbos@webrtc.org25509882013-04-09 10:30:35 +00001319 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001320
1321 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1322 {
1323 return -1;
1324 }
1325
1326 *maxVolume = maxVol;
1327
1328 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1329 return (0);
1330}
1331
1332// ----------------------------------------------------------------------------
1333// MinMicrophoneVolume
1334// ----------------------------------------------------------------------------
1335
pbos@webrtc.org25509882013-04-09 10:30:35 +00001336int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001337{
niklase@google.com470e71d2011-07-07 08:21:25 +00001338 CHECK_INITIALIZED();
1339
pbos@webrtc.org25509882013-04-09 10:30:35 +00001340 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001341
1342 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1343 {
1344 return -1;
1345 }
1346
1347 *minVolume = minVol;
1348
1349 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1350 return (0);
1351}
1352
1353// ----------------------------------------------------------------------------
1354// MicrophoneVolumeStepSize
1355// ----------------------------------------------------------------------------
1356
pbos@webrtc.org25509882013-04-09 10:30:35 +00001357int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001358{
niklase@google.com470e71d2011-07-07 08:21:25 +00001359 CHECK_INITIALIZED();
1360
pbos@webrtc.org25509882013-04-09 10:30:35 +00001361 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001362
1363 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1364 {
1365 return -1;
1366 }
1367
1368 *stepSize = delta;
1369
1370 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1371 return (0);
1372}
1373
1374// ----------------------------------------------------------------------------
1375// PlayoutDevices
1376// ----------------------------------------------------------------------------
1377
pbos@webrtc.org25509882013-04-09 10:30:35 +00001378int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001379{
niklase@google.com470e71d2011-07-07 08:21:25 +00001380 CHECK_INITIALIZED();
1381
pbos@webrtc.org25509882013-04-09 10:30:35 +00001382 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001383
1384 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001385 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001386}
1387
1388// ----------------------------------------------------------------------------
1389// SetPlayoutDevice I (II)
1390// ----------------------------------------------------------------------------
1391
pbos@webrtc.org25509882013-04-09 10:30:35 +00001392int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001393{
niklase@google.com470e71d2011-07-07 08:21:25 +00001394 CHECK_INITIALIZED();
1395 return (_ptrAudioDevice->SetPlayoutDevice(index));
1396}
1397
1398// ----------------------------------------------------------------------------
1399// SetPlayoutDevice II (II)
1400// ----------------------------------------------------------------------------
1401
pbos@webrtc.org25509882013-04-09 10:30:35 +00001402int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001403{
1404 if (device == kDefaultDevice)
1405 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001406 }
1407 else
1408 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001409 }
1410 CHECK_INITIALIZED();
1411
1412 return (_ptrAudioDevice->SetPlayoutDevice(device));
1413}
1414
1415// ----------------------------------------------------------------------------
1416// PlayoutDeviceName
1417// ----------------------------------------------------------------------------
1418
pbos@webrtc.org25509882013-04-09 10:30:35 +00001419int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1420 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001421 char name[kAdmMaxDeviceNameSize],
1422 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001423{
niklase@google.com470e71d2011-07-07 08:21:25 +00001424 CHECK_INITIALIZED();
1425
1426 if (name == NULL)
1427 {
1428 _lastError = kAdmErrArgument;
1429 return -1;
1430 }
1431
1432 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1433 {
1434 return -1;
1435 }
1436
1437 if (name != NULL)
1438 {
1439 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1440 }
1441 if (guid != NULL)
1442 {
1443 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1444 }
1445
1446 return (0);
1447}
1448
1449// ----------------------------------------------------------------------------
1450// RecordingDeviceName
1451// ----------------------------------------------------------------------------
1452
pbos@webrtc.org25509882013-04-09 10:30:35 +00001453int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1454 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001455 char name[kAdmMaxDeviceNameSize],
1456 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001457{
niklase@google.com470e71d2011-07-07 08:21:25 +00001458 CHECK_INITIALIZED();
1459
1460 if (name == NULL)
1461 {
1462 _lastError = kAdmErrArgument;
1463 return -1;
1464 }
1465
1466 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1467 {
1468 return -1;
1469 }
1470
1471 if (name != NULL)
1472 {
1473 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1474 }
1475 if (guid != NULL)
1476 {
1477 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1478 }
1479
1480 return (0);
1481}
1482
1483// ----------------------------------------------------------------------------
1484// RecordingDevices
1485// ----------------------------------------------------------------------------
1486
pbos@webrtc.org25509882013-04-09 10:30:35 +00001487int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001488{
niklase@google.com470e71d2011-07-07 08:21:25 +00001489 CHECK_INITIALIZED();
1490
pbos@webrtc.org25509882013-04-09 10:30:35 +00001491 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001492
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001493 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1494 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001495 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001496}
1497
1498// ----------------------------------------------------------------------------
1499// SetRecordingDevice I (II)
1500// ----------------------------------------------------------------------------
1501
pbos@webrtc.org25509882013-04-09 10:30:35 +00001502int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001503{
niklase@google.com470e71d2011-07-07 08:21:25 +00001504 CHECK_INITIALIZED();
1505 return (_ptrAudioDevice->SetRecordingDevice(index));
1506}
1507
1508// ----------------------------------------------------------------------------
1509// SetRecordingDevice II (II)
1510// ----------------------------------------------------------------------------
1511
pbos@webrtc.org25509882013-04-09 10:30:35 +00001512int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001513{
1514 if (device == kDefaultDevice)
1515 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001516 }
1517 else
1518 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001519 }
1520 CHECK_INITIALIZED();
1521
1522 return (_ptrAudioDevice->SetRecordingDevice(device));
1523}
1524
1525// ----------------------------------------------------------------------------
1526// InitPlayout
1527// ----------------------------------------------------------------------------
1528
pbos@webrtc.org25509882013-04-09 10:30:35 +00001529int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001530{
niklase@google.com470e71d2011-07-07 08:21:25 +00001531 CHECK_INITIALIZED();
1532 _audioDeviceBuffer.InitPlayout();
1533 return (_ptrAudioDevice->InitPlayout());
1534}
1535
1536// ----------------------------------------------------------------------------
1537// InitRecording
1538// ----------------------------------------------------------------------------
1539
pbos@webrtc.org25509882013-04-09 10:30:35 +00001540int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001541{
niklase@google.com470e71d2011-07-07 08:21:25 +00001542 CHECK_INITIALIZED();
1543 _audioDeviceBuffer.InitRecording();
1544 return (_ptrAudioDevice->InitRecording());
1545}
1546
1547// ----------------------------------------------------------------------------
1548// PlayoutIsInitialized
1549// ----------------------------------------------------------------------------
1550
1551bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1552{
niklase@google.com470e71d2011-07-07 08:21:25 +00001553 CHECK_INITIALIZED_BOOL();
1554 return (_ptrAudioDevice->PlayoutIsInitialized());
1555}
1556
1557// ----------------------------------------------------------------------------
1558// RecordingIsInitialized
1559// ----------------------------------------------------------------------------
1560
1561bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1562{
niklase@google.com470e71d2011-07-07 08:21:25 +00001563 CHECK_INITIALIZED_BOOL();
1564 return (_ptrAudioDevice->RecordingIsInitialized());
1565}
1566
1567// ----------------------------------------------------------------------------
1568// StartPlayout
1569// ----------------------------------------------------------------------------
1570
pbos@webrtc.org25509882013-04-09 10:30:35 +00001571int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001572{
niklase@google.com470e71d2011-07-07 08:21:25 +00001573 CHECK_INITIALIZED();
1574 return (_ptrAudioDevice->StartPlayout());
1575}
1576
1577// ----------------------------------------------------------------------------
1578// StopPlayout
1579// ----------------------------------------------------------------------------
1580
pbos@webrtc.org25509882013-04-09 10:30:35 +00001581int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001582{
niklase@google.com470e71d2011-07-07 08:21:25 +00001583 CHECK_INITIALIZED();
1584 return (_ptrAudioDevice->StopPlayout());
1585}
1586
1587// ----------------------------------------------------------------------------
1588// Playing
1589// ----------------------------------------------------------------------------
1590
1591bool AudioDeviceModuleImpl::Playing() const
1592{
niklase@google.com470e71d2011-07-07 08:21:25 +00001593 CHECK_INITIALIZED_BOOL();
1594 return (_ptrAudioDevice->Playing());
1595}
1596
1597// ----------------------------------------------------------------------------
1598// StartRecording
1599// ----------------------------------------------------------------------------
1600
pbos@webrtc.org25509882013-04-09 10:30:35 +00001601int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001602{
niklase@google.com470e71d2011-07-07 08:21:25 +00001603 CHECK_INITIALIZED();
1604 return (_ptrAudioDevice->StartRecording());
1605}
1606// ----------------------------------------------------------------------------
1607// StopRecording
1608// ----------------------------------------------------------------------------
1609
pbos@webrtc.org25509882013-04-09 10:30:35 +00001610int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001611{
niklase@google.com470e71d2011-07-07 08:21:25 +00001612 CHECK_INITIALIZED();
1613 return (_ptrAudioDevice->StopRecording());
1614}
1615
1616// ----------------------------------------------------------------------------
1617// Recording
1618// ----------------------------------------------------------------------------
1619
1620bool AudioDeviceModuleImpl::Recording() const
1621{
niklase@google.com470e71d2011-07-07 08:21:25 +00001622 CHECK_INITIALIZED_BOOL();
1623 return (_ptrAudioDevice->Recording());
1624}
1625
1626// ----------------------------------------------------------------------------
1627// RegisterEventObserver
1628// ----------------------------------------------------------------------------
1629
pbos@webrtc.org25509882013-04-09 10:30:35 +00001630int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001631{
niklase@google.com470e71d2011-07-07 08:21:25 +00001632
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001633 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001634 _ptrCbAudioDeviceObserver = eventCallback;
1635
1636 return 0;
1637}
1638
1639// ----------------------------------------------------------------------------
1640// RegisterAudioCallback
1641// ----------------------------------------------------------------------------
1642
pbos@webrtc.org25509882013-04-09 10:30:35 +00001643int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001644{
niklase@google.com470e71d2011-07-07 08:21:25 +00001645
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001646 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001647 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1648
1649 return 0;
1650}
1651
1652// ----------------------------------------------------------------------------
1653// StartRawInputFileRecording
1654// ----------------------------------------------------------------------------
1655
pbos@webrtc.org25509882013-04-09 10:30:35 +00001656int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001657 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001658{
niklase@google.com470e71d2011-07-07 08:21:25 +00001659 CHECK_INITIALIZED();
1660
1661 if (NULL == pcmFileNameUTF8)
1662 {
1663 return -1;
1664 }
1665
1666 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1667}
1668
1669// ----------------------------------------------------------------------------
1670// StopRawInputFileRecording
1671// ----------------------------------------------------------------------------
1672
pbos@webrtc.org25509882013-04-09 10:30:35 +00001673int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001674{
niklase@google.com470e71d2011-07-07 08:21:25 +00001675 CHECK_INITIALIZED();
1676
1677 return (_audioDeviceBuffer.StopInputFileRecording());
1678}
1679
1680// ----------------------------------------------------------------------------
1681// StartRawOutputFileRecording
1682// ----------------------------------------------------------------------------
1683
pbos@webrtc.org25509882013-04-09 10:30:35 +00001684int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001685 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001686{
niklase@google.com470e71d2011-07-07 08:21:25 +00001687 CHECK_INITIALIZED();
1688
1689 if (NULL == pcmFileNameUTF8)
1690 {
1691 return -1;
1692 }
1693
1694 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1695}
1696
1697// ----------------------------------------------------------------------------
1698// StopRawOutputFileRecording
1699// ----------------------------------------------------------------------------
1700
pbos@webrtc.org25509882013-04-09 10:30:35 +00001701int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001702{
niklase@google.com470e71d2011-07-07 08:21:25 +00001703 CHECK_INITIALIZED();
1704
1705 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001706}
1707
1708// ----------------------------------------------------------------------------
1709// SetPlayoutBuffer
1710// ----------------------------------------------------------------------------
1711
pbos@webrtc.org25509882013-04-09 10:30:35 +00001712int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001713{
niklase@google.com470e71d2011-07-07 08:21:25 +00001714 CHECK_INITIALIZED();
1715
1716 if (_ptrAudioDevice->PlayoutIsInitialized())
1717 {
1718 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1719 return -1;
1720 }
1721
pbos@webrtc.org25509882013-04-09 10:30:35 +00001722 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001723
1724 if (kFixedBufferSize == type)
1725 {
1726 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1727 {
1728 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1729 return -1;
1730 }
1731 }
1732
1733 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1734 {
1735 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1736 }
1737
1738 return ret;
1739}
1740
1741// ----------------------------------------------------------------------------
1742// PlayoutBuffer
1743// ----------------------------------------------------------------------------
1744
pbos@webrtc.org25509882013-04-09 10:30:35 +00001745int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001746{
niklase@google.com470e71d2011-07-07 08:21:25 +00001747 CHECK_INITIALIZED();
1748
1749 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001750 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001751
1752 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1753 {
1754 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1755 return -1;
1756 }
1757
1758 *type = bufType;
1759 *sizeMS = size;
1760
1761 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1762 return (0);
1763}
1764
1765// ----------------------------------------------------------------------------
1766// PlayoutDelay
1767// ----------------------------------------------------------------------------
1768
pbos@webrtc.org25509882013-04-09 10:30:35 +00001769int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001770{
1771 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1772 CHECK_INITIALIZED();
1773
pbos@webrtc.org25509882013-04-09 10:30:35 +00001774 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001775
1776 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1777 {
1778 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1779 return -1;
1780 }
1781
1782 *delayMS = delay;
1783
1784 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1785 return (0);
1786}
1787
1788// ----------------------------------------------------------------------------
1789// RecordingDelay
1790// ----------------------------------------------------------------------------
1791
pbos@webrtc.org25509882013-04-09 10:30:35 +00001792int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001793{
1794 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1795 CHECK_INITIALIZED();
1796
pbos@webrtc.org25509882013-04-09 10:30:35 +00001797 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001798
1799 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1800 {
1801 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1802 return -1;
1803 }
1804
1805 *delayMS = delay;
1806
1807 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1808 return (0);
1809}
1810
1811// ----------------------------------------------------------------------------
1812// CPULoad
1813// ----------------------------------------------------------------------------
1814
pbos@webrtc.org25509882013-04-09 10:30:35 +00001815int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001816{
niklase@google.com470e71d2011-07-07 08:21:25 +00001817 CHECK_INITIALIZED();
1818
pbos@webrtc.org25509882013-04-09 10:30:35 +00001819 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001820
1821 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1822 {
1823 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1824 return -1;
1825 }
1826
1827 *load = cpuLoad;
1828
1829 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1830 return (0);
1831}
1832
1833// ----------------------------------------------------------------------------
1834// SetRecordingSampleRate
1835// ----------------------------------------------------------------------------
1836
pbos@webrtc.org25509882013-04-09 10:30:35 +00001837int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001838{
niklase@google.com470e71d2011-07-07 08:21:25 +00001839 CHECK_INITIALIZED();
1840
1841 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1842 {
1843 return -1;
1844 }
1845
1846 return (0);
1847}
1848
1849// ----------------------------------------------------------------------------
1850// RecordingSampleRate
1851// ----------------------------------------------------------------------------
1852
pbos@webrtc.org25509882013-04-09 10:30:35 +00001853int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001854{
niklase@google.com470e71d2011-07-07 08:21:25 +00001855 CHECK_INITIALIZED();
1856
pbos@webrtc.org25509882013-04-09 10:30:35 +00001857 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001858
1859 if (sampleRate == -1)
1860 {
1861 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1862 return -1;
1863 }
1864
1865 *samplesPerSec = sampleRate;
1866
1867 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1868 return (0);
1869}
1870
1871// ----------------------------------------------------------------------------
1872// SetPlayoutSampleRate
1873// ----------------------------------------------------------------------------
1874
pbos@webrtc.org25509882013-04-09 10:30:35 +00001875int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001876{
niklase@google.com470e71d2011-07-07 08:21:25 +00001877 CHECK_INITIALIZED();
1878
1879 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1880 {
1881 return -1;
1882 }
1883
1884 return (0);
1885}
1886
1887// ----------------------------------------------------------------------------
1888// PlayoutSampleRate
1889// ----------------------------------------------------------------------------
1890
pbos@webrtc.org25509882013-04-09 10:30:35 +00001891int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001892{
niklase@google.com470e71d2011-07-07 08:21:25 +00001893 CHECK_INITIALIZED();
1894
pbos@webrtc.org25509882013-04-09 10:30:35 +00001895 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001896
1897 if (sampleRate == -1)
1898 {
1899 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1900 return -1;
1901 }
1902
1903 *samplesPerSec = sampleRate;
1904
1905 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1906 return (0);
1907}
1908
1909// ----------------------------------------------------------------------------
1910// ResetAudioDevice
1911// ----------------------------------------------------------------------------
1912
pbos@webrtc.org25509882013-04-09 10:30:35 +00001913int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001914{
niklase@google.com470e71d2011-07-07 08:21:25 +00001915 CHECK_INITIALIZED();
1916
1917
1918 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1919 {
1920 return -1;
1921 }
1922
1923 return (0);
1924}
1925
1926// ----------------------------------------------------------------------------
1927// SetLoudspeakerStatus
1928// ----------------------------------------------------------------------------
1929
pbos@webrtc.org25509882013-04-09 10:30:35 +00001930int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001931{
niklase@google.com470e71d2011-07-07 08:21:25 +00001932 CHECK_INITIALIZED();
1933
1934 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1935 {
1936 return -1;
1937 }
1938
1939 return 0;
1940}
1941
1942// ----------------------------------------------------------------------------
1943// GetLoudspeakerStatus
1944// ----------------------------------------------------------------------------
1945
pbos@webrtc.org25509882013-04-09 10:30:35 +00001946int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001947{
niklase@google.com470e71d2011-07-07 08:21:25 +00001948 CHECK_INITIALIZED();
1949
1950 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1951 {
1952 return -1;
1953 }
1954
1955 return 0;
1956}
1957
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001958int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1959{
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001960 CHECK_INITIALIZED();
1961 return _ptrAudioDevice->EnableBuiltInAEC(enable);
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001962}
1963
1964bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1965{
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001966 CHECK_INITIALIZED_BOOL();
1967
1968 return _ptrAudioDevice->BuiltInAECIsEnabled();
1969}
1970
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001971bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1972 CHECK_INITIALIZED_BOOL();
1973 return _ptrAudioDevice->BuiltInAECIsAvailable();
1974}
1975
niklase@google.com470e71d2011-07-07 08:21:25 +00001976// ============================================================================
1977// Private Methods
1978// ============================================================================
1979
1980// ----------------------------------------------------------------------------
1981// Platform
1982// ----------------------------------------------------------------------------
1983
1984AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1985{
1986 return _platformType;
1987}
1988
1989// ----------------------------------------------------------------------------
1990// PlatformAudioLayer
1991// ----------------------------------------------------------------------------
1992
1993AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
1994{
niklase@google.com470e71d2011-07-07 08:21:25 +00001995 return _platformAudioLayer;
1996}
1997
1998} // namespace webrtc