blob: d881bcd40c9293358b6ac8f1b5a21c3e8cc78982 [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
Peter Boström1d194412016-03-21 16:44:31 +010011#include "webrtc/base/refcount.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000012#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
13#include "webrtc/modules/audio_device/audio_device_config.h"
14#include "webrtc/modules/audio_device/audio_device_impl.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010015#include "webrtc/system_wrappers/include/tick_util.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000017#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000018#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000019
20#if defined(_WIN32)
xians@google.com68efa212011-08-11 12:41:56 +000021 #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>
henrikab2619892015-05-18 16:49:16 +020027#include "webrtc/modules/audio_device/android/audio_device_template.h"
28#include "webrtc/modules/audio_device/android/audio_manager.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_player.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000032#elif defined(WEBRTC_LINUX)
niklase@google.com470e71d2011-07-07 08:21:25 +000033 #if defined(LINUX_ALSA)
Tommi68898a22015-05-19 17:28:07 +020034 #include "audio_device_alsa_linux.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000035 #endif
Tommi68898a22015-05-19 17:28:07 +020036#if defined(LINUX_PULSE)
xians@google.com68efa212011-08-11 12:41:56 +000037 #include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020038#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000039#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000040 #include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000041#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +000042 #include "audio_device_mac.h"
43#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000044
45#if defined(WEBRTC_DUMMY_FILE_DEVICES)
46#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
47#endif
48
pbos@webrtc.org811269d2013-07-11 13:24:38 +000049#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000050#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010051#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
52#include "webrtc/system_wrappers/include/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000053
54#define CHECK_INITIALIZED() \
55{ \
56 if (!_initialized) { \
57 return -1; \
58 }; \
59}
60
61#define CHECK_INITIALIZED_BOOL() \
62{ \
63 if (!_initialized) { \
64 return false; \
65 }; \
66}
67
Peter Boström1d194412016-03-21 16:44:31 +010068namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000069
niklase@google.com470e71d2011-07-07 08:21:25 +000070// ============================================================================
71// Static methods
72// ============================================================================
73
74// ----------------------------------------------------------------------------
75// AudioDeviceModule::Create()
76// ----------------------------------------------------------------------------
77
Peter Boström1d194412016-03-21 16:44:31 +010078rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModuleImpl::Create(
79 const int32_t id,
80 const AudioLayer audioLayer) {
henrika@google.com73d65512011-09-07 15:11:18 +000081 // Create the generic ref counted (platform independent) implementation.
Peter Boström1d194412016-03-21 16:44:31 +010082 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
83 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audioLayer));
niklase@google.com470e71d2011-07-07 08:21:25 +000084
henrika@google.com73d65512011-09-07 15:11:18 +000085 // Ensure that the current platform is supported.
niklase@google.com470e71d2011-07-07 08:21:25 +000086 if (audioDevice->CheckPlatform() == -1)
87 {
Peter Boström1d194412016-03-21 16:44:31 +010088 return nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +000089 }
90
henrika@google.com73d65512011-09-07 15:11:18 +000091 // Create the platform-dependent implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +000092 if (audioDevice->CreatePlatformSpecificObjects() == -1)
93 {
Peter Boström1d194412016-03-21 16:44:31 +010094 return nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +000095 }
96
henrika@google.com73d65512011-09-07 15:11:18 +000097 // Ensure that the generic audio buffer can communicate with the
98 // platform-specific parts.
niklase@google.com470e71d2011-07-07 08:21:25 +000099 if (audioDevice->AttachAudioBuffer() == -1)
100 {
Peter Boström1d194412016-03-21 16:44:31 +0100101 return nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 }
103
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000104 WebRtcSpl_Init();
105
niklase@google.com470e71d2011-07-07 08:21:25 +0000106 return audioDevice;
107}
108
niklase@google.com470e71d2011-07-07 08:21:25 +0000109// ============================================================================
110// Construction & Destruction
111// ============================================================================
112
113// ----------------------------------------------------------------------------
114// AudioDeviceModuleImpl - ctor
115// ----------------------------------------------------------------------------
116
pbos@webrtc.org25509882013-04-09 10:30:35 +0000117AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
119 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
120 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
121 _ptrCbAudioDeviceObserver(NULL),
xians@google.com88bd4402011-08-04 15:33:30 +0000122 _ptrAudioDevice(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +0000123 _id(id),
124 _platformAudioLayer(audioLayer),
Tommi68898a22015-05-19 17:28:07 +0200125 _lastProcessTime(TickTime::MillisecondTimestamp()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000126 _platformType(kPlatformNotSupported),
xians@google.com88bd4402011-08-04 15:33:30 +0000127 _initialized(false),
128 _lastError(kAdmErrNone)
niklase@google.com470e71d2011-07-07 08:21:25 +0000129{
130 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
131}
132
133// ----------------------------------------------------------------------------
134// CheckPlatform
135// ----------------------------------------------------------------------------
136
pbos@webrtc.org25509882013-04-09 10:30:35 +0000137int32_t AudioDeviceModuleImpl::CheckPlatform()
niklase@google.com470e71d2011-07-07 08:21:25 +0000138{
139 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
140
141 // Ensure that the current platform is supported
142 //
143 PlatformType platform(kPlatformNotSupported);
144
145#if defined(_WIN32)
146 platform = kPlatformWin32;
147 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
leozwang@google.com522f42b2011-09-19 17:39:05 +0000148#elif defined(WEBRTC_ANDROID)
149 platform = kPlatformAndroid;
150 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
niklase@google.com470e71d2011-07-07 08:21:25 +0000151#elif defined(WEBRTC_LINUX)
152 platform = kPlatformLinux;
153 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000154#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000155 platform = kPlatformIOS;
156 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000157#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 platform = kPlatformMac;
159 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
160#endif
161
162 if (platform == kPlatformNotSupported)
163 {
164 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
165 return -1;
166 }
167
168 // Store valid output results
169 //
170 _platformType = platform;
171
172 return 0;
173}
174
175
176// ----------------------------------------------------------------------------
177// CreatePlatformSpecificObjects
178// ----------------------------------------------------------------------------
179
pbos@webrtc.org25509882013-04-09 10:30:35 +0000180int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
niklase@google.com470e71d2011-07-07 08:21:25 +0000181{
182 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
183
184 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
xians@google.combf5d2ba2011-08-16 07:44:19 +0000186#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
187 ptrAudioDevice = new AudioDeviceDummy(Id());
188 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000189#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
190 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
191 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
192 "Will use file-playing dummy device.");
xians@google.combf5d2ba2011-08-16 07:44:19 +0000193#else
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000194 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
196 // Create the *Windows* implementation of the Audio Device
197 //
198#if defined(_WIN32)
199 if ((audioLayer == kWindowsWaveAudio)
200#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
201 // Wave audio is default if Core audio is not supported in this build
202 || (audioLayer == kPlatformDefaultAudio)
203#endif
204 )
205 {
206 // create *Windows Wave Audio* implementation
207 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
208 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
209 }
210#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
211 if ((audioLayer == kWindowsCoreAudio) ||
212 (audioLayer == kPlatformDefaultAudio)
213 )
214 {
215 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
216
217 if (AudioDeviceWindowsCore::CoreAudioIsSupported())
218 {
219 // create *Windows Core Audio* implementation
220 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
221 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
222 }
223 else
224 {
225 // create *Windows Wave Audio* implementation
226 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
227 if (ptrAudioDevice != NULL)
228 {
229 // Core Audio was not supported => revert to Windows Wave instead
230 _platformAudioLayer = kWindowsWaveAudio; // modify the state set at construction
231 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
232 }
233 }
234 }
235#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000236#endif // #if defined(_WIN32)
237
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000238#if defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +0200239 // Create an Android audio manager.
240 _audioManagerAndroid.reset(new AudioManager());
241 // Select best possible combination of audio layers.
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000242 if (audioLayer == kPlatformDefaultAudio) {
henrikab2619892015-05-18 16:49:16 +0200243 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
244 // Always use OpenSL ES for output on devices that supports the
245 // low-latency output audio path.
246 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
247 } else {
248 // Use Java-based audio in both directions when low-latency output
249 // is not supported.
250 audioLayer = kAndroidJavaAudio;
251 }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000252 }
henrikab2619892015-05-18 16:49:16 +0200253 AudioManager* audio_manager = _audioManagerAndroid.get();
254 if (audioLayer == kAndroidJavaAudio) {
255 // Java audio for both input and output audio.
256 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
257 audioLayer, audio_manager);
258 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
259 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
260 // This combination provides low-latency output audio and at the same
261 // time support for HW AEC using the AudioRecord Java API.
262 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
263 audioLayer, audio_manager);
264 } else {
265 // Invalid audio layer.
266 ptrAudioDevice = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000267 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000268 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
270 // Create the *Linux* implementation of the Audio Device
271 //
272#elif defined(WEBRTC_LINUX)
273 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
274 {
275#if defined(LINUX_PULSE)
276 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
277
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000278 // create *Linux PulseAudio* implementation
279 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
280 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000281 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000282 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000283 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
284 }
285 else
286 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000287 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000288#endif
289#if defined(LINUX_ALSA)
290 // create *Linux ALSA Audio* implementation
291 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
292 if (ptrAudioDevice != NULL)
293 {
294 // Pulse Audio was not supported => revert to ALSA instead
295 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
296 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
297 }
298#endif
299#if defined(LINUX_PULSE)
300 }
301#endif
302 }
303 else if (audioLayer == kLinuxAlsaAudio)
304 {
305#if defined(LINUX_ALSA)
306 // create *Linux ALSA Audio* implementation
307 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
308 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
309#endif
310 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000311#endif // #if defined(WEBRTC_LINUX)
312
313 // Create the *iPhone* implementation of the Audio Device
314 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000315#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000316 if (audioLayer == kPlatformDefaultAudio)
317 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000318 // Create iOS Audio Device implementation.
henrikaba35d052015-07-14 17:04:08 +0200319 ptrAudioDevice = new AudioDeviceIOS();
niklase@google.com470e71d2011-07-07 08:21:25 +0000320 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
321 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000322 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000323
324 // Create the *Mac* implementation of the Audio Device
325 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000326#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000327 if (audioLayer == kPlatformDefaultAudio)
328 {
329 // Create *Mac Audio* implementation
330 ptrAudioDevice = new AudioDeviceMac(Id());
331 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
332 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000333#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000334
335 // Create the *Dummy* implementation of the Audio Device
336 // Available for all platforms
337 //
338 if (audioLayer == kDummyAudio)
339 {
340 // Create *Dummy Audio* implementation
341 assert(!ptrAudioDevice);
342 ptrAudioDevice = new AudioDeviceDummy(Id());
343 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
niklase@google.com470e71d2011-07-07 08:21:25 +0000344 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000345#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000346
347 if (ptrAudioDevice == NULL)
348 {
349 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
350 return -1;
351 }
352
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 // Store valid output pointers
354 //
355 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000356
357 return 0;
358}
359
360// ----------------------------------------------------------------------------
361// AttachAudioBuffer
362//
363// Install "bridge" between the platform implemetation and the generic
364// implementation. The "child" shall set the native sampling rate and the
365// number of channels in this function call.
366// ----------------------------------------------------------------------------
367
pbos@webrtc.org25509882013-04-09 10:30:35 +0000368int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000369{
370 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
371
372 _audioDeviceBuffer.SetId(_id);
373 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
374 return 0;
375}
376
377// ----------------------------------------------------------------------------
378// ~AudioDeviceModuleImpl - dtor
379// ----------------------------------------------------------------------------
380
381AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
382{
383 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000384
385 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000386 {
henrika@google.com73d65512011-09-07 15:11:18 +0000387 delete _ptrAudioDevice;
388 _ptrAudioDevice = NULL;
389 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000390
niklase@google.com470e71d2011-07-07 08:21:25 +0000391 delete &_critSect;
392 delete &_critSectEventCb;
393 delete &_critSectAudioCb;
394}
395
396// ============================================================================
397// Module
398// ============================================================================
399
400// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000401// Module::TimeUntilNextProcess
402//
403// Returns the number of milliseconds until the module want a worker thread
404// to call Process().
405// ----------------------------------------------------------------------------
406
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000407int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000408{
Tommi68898a22015-05-19 17:28:07 +0200409 int64_t now = TickTime::MillisecondTimestamp();
410 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
411 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000412}
413
414// ----------------------------------------------------------------------------
415// Module::Process
416//
417// Check for posted error and warning reports. Generate callbacks if
418// new reports exists.
419// ----------------------------------------------------------------------------
420
pbosa26ac922016-02-25 04:50:01 -0800421void AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000422{
niklase@google.com470e71d2011-07-07 08:21:25 +0000423
Tommi68898a22015-05-19 17:28:07 +0200424 _lastProcessTime = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000425
426 // kPlayoutWarning
427 if (_ptrAudioDevice->PlayoutWarning())
428 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000429 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000430 if (_ptrCbAudioDeviceObserver)
431 {
432 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
433 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
434 }
435 _ptrAudioDevice->ClearPlayoutWarning();
436 }
437
438 // kPlayoutError
439 if (_ptrAudioDevice->PlayoutError())
440 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000441 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000442 if (_ptrCbAudioDeviceObserver)
443 {
444 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
445 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
446 }
447 _ptrAudioDevice->ClearPlayoutError();
448 }
449
450 // kRecordingWarning
451 if (_ptrAudioDevice->RecordingWarning())
452 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000453 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000454 if (_ptrCbAudioDeviceObserver)
455 {
456 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
457 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
458 }
459 _ptrAudioDevice->ClearRecordingWarning();
460 }
461
462 // kRecordingError
463 if (_ptrAudioDevice->RecordingError())
464 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000465 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000466 if (_ptrCbAudioDeviceObserver)
467 {
468 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
469 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
470 }
471 _ptrAudioDevice->ClearRecordingError();
472 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000473}
474
475// ============================================================================
476// Public API
477// ============================================================================
478
479// ----------------------------------------------------------------------------
480// ActiveAudioLayer
481// ----------------------------------------------------------------------------
482
henrikab2619892015-05-18 16:49:16 +0200483int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
484 AudioLayer activeAudio;
485 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
486 return -1;
487 }
488 *audioLayer = activeAudio;
489 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000490}
491
492// ----------------------------------------------------------------------------
493// LastError
494// ----------------------------------------------------------------------------
495
496AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
497{
498 return _lastError;
499}
500
501// ----------------------------------------------------------------------------
502// Init
503// ----------------------------------------------------------------------------
504
pbos@webrtc.org25509882013-04-09 10:30:35 +0000505int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000506{
niklase@google.com470e71d2011-07-07 08:21:25 +0000507
508 if (_initialized)
509 return 0;
510
niklase@google.com470e71d2011-07-07 08:21:25 +0000511 if (!_ptrAudioDevice)
512 return -1;
513
niklase@google.com470e71d2011-07-07 08:21:25 +0000514 if (_ptrAudioDevice->Init() == -1)
515 {
516 return -1;
517 }
518
519 _initialized = true;
520 return 0;
521}
522
523// ----------------------------------------------------------------------------
524// Terminate
525// ----------------------------------------------------------------------------
526
pbos@webrtc.org25509882013-04-09 10:30:35 +0000527int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000528{
niklase@google.com470e71d2011-07-07 08:21:25 +0000529
530 if (!_initialized)
531 return 0;
532
533 if (_ptrAudioDevice->Terminate() == -1)
534 {
535 return -1;
536 }
537
538 _initialized = false;
539 return 0;
540}
541
542// ----------------------------------------------------------------------------
543// Initialized
544// ----------------------------------------------------------------------------
545
546bool AudioDeviceModuleImpl::Initialized() const
547{
niklase@google.com470e71d2011-07-07 08:21:25 +0000548
549 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
550 return (_initialized);
551}
552
553// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000554// InitSpeaker
555// ----------------------------------------------------------------------------
556
pbos@webrtc.org25509882013-04-09 10:30:35 +0000557int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000558{
niklase@google.com470e71d2011-07-07 08:21:25 +0000559 CHECK_INITIALIZED();
560 return (_ptrAudioDevice->InitSpeaker());
561}
562
563// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000564// InitMicrophone
565// ----------------------------------------------------------------------------
566
pbos@webrtc.org25509882013-04-09 10:30:35 +0000567int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000568{
niklase@google.com470e71d2011-07-07 08:21:25 +0000569 CHECK_INITIALIZED();
570 return (_ptrAudioDevice->InitMicrophone());
571}
572
573// ----------------------------------------------------------------------------
574// SpeakerVolumeIsAvailable
575// ----------------------------------------------------------------------------
576
pbos@webrtc.org25509882013-04-09 10:30:35 +0000577int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000578{
niklase@google.com470e71d2011-07-07 08:21:25 +0000579 CHECK_INITIALIZED();
580
581 bool isAvailable(0);
582
583 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
584 {
585 return -1;
586 }
587
588 *available = isAvailable;
589
590 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
591 return (0);
592}
593
594// ----------------------------------------------------------------------------
595// SetSpeakerVolume
596// ----------------------------------------------------------------------------
597
pbos@webrtc.org25509882013-04-09 10:30:35 +0000598int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000599{
niklase@google.com470e71d2011-07-07 08:21:25 +0000600 CHECK_INITIALIZED();
601 return (_ptrAudioDevice->SetSpeakerVolume(volume));
602}
603
604// ----------------------------------------------------------------------------
605// SpeakerVolume
606// ----------------------------------------------------------------------------
607
pbos@webrtc.org25509882013-04-09 10:30:35 +0000608int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000609{
niklase@google.com470e71d2011-07-07 08:21:25 +0000610 CHECK_INITIALIZED();
611
pbos@webrtc.org25509882013-04-09 10:30:35 +0000612 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000613
614 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
615 {
616 return -1;
617 }
618
619 *volume = level;
620
621 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
622 return (0);
623}
624
625// ----------------------------------------------------------------------------
626// SetWaveOutVolume
627// ----------------------------------------------------------------------------
628
pbos@webrtc.org25509882013-04-09 10:30:35 +0000629int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000630{
niklase@google.com470e71d2011-07-07 08:21:25 +0000631 CHECK_INITIALIZED();
632 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
633}
634
635// ----------------------------------------------------------------------------
636// WaveOutVolume
637// ----------------------------------------------------------------------------
638
pbos@webrtc.org25509882013-04-09 10:30:35 +0000639int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000640{
niklase@google.com470e71d2011-07-07 08:21:25 +0000641 CHECK_INITIALIZED();
642
pbos@webrtc.org25509882013-04-09 10:30:35 +0000643 uint16_t volLeft(0);
644 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000645
646 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
647 {
648 return -1;
649 }
650
651 *volumeLeft = volLeft;
652 *volumeRight = volRight;
653
654 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
655 *volumeLeft, *volumeRight);
656
657 return (0);
658}
659
660// ----------------------------------------------------------------------------
661// SpeakerIsInitialized
662// ----------------------------------------------------------------------------
663
664bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
665{
niklase@google.com470e71d2011-07-07 08:21:25 +0000666 CHECK_INITIALIZED_BOOL();
667
668 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
669
670 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
671 return (isInitialized);
672}
673
674// ----------------------------------------------------------------------------
675// MicrophoneIsInitialized
676// ----------------------------------------------------------------------------
677
678bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
679{
niklase@google.com470e71d2011-07-07 08:21:25 +0000680 CHECK_INITIALIZED_BOOL();
681
682 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
683
684 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
685 return (isInitialized);
686}
687
688// ----------------------------------------------------------------------------
689// MaxSpeakerVolume
690// ----------------------------------------------------------------------------
691
pbos@webrtc.org25509882013-04-09 10:30:35 +0000692int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000693{
niklase@google.com470e71d2011-07-07 08:21:25 +0000694 CHECK_INITIALIZED();
695
pbos@webrtc.org25509882013-04-09 10:30:35 +0000696 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000697
698 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
699 {
700 return -1;
701 }
702
703 *maxVolume = maxVol;
704
705 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
706 return (0);
707}
708
709// ----------------------------------------------------------------------------
710// MinSpeakerVolume
711// ----------------------------------------------------------------------------
712
pbos@webrtc.org25509882013-04-09 10:30:35 +0000713int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000714{
niklase@google.com470e71d2011-07-07 08:21:25 +0000715 CHECK_INITIALIZED();
716
pbos@webrtc.org25509882013-04-09 10:30:35 +0000717 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000718
719 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
720 {
721 return -1;
722 }
723
724 *minVolume = minVol;
725
726 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
727 return (0);
728}
729
730// ----------------------------------------------------------------------------
731// SpeakerVolumeStepSize
732// ----------------------------------------------------------------------------
733
pbos@webrtc.org25509882013-04-09 10:30:35 +0000734int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000735{
niklase@google.com470e71d2011-07-07 08:21:25 +0000736 CHECK_INITIALIZED();
737
pbos@webrtc.org25509882013-04-09 10:30:35 +0000738 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000739
740 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
741 {
742 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
743 return -1;
744 }
745
746 *stepSize = delta;
747
748 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
749 return (0);
750}
751
752// ----------------------------------------------------------------------------
753// SpeakerMuteIsAvailable
754// ----------------------------------------------------------------------------
755
pbos@webrtc.org25509882013-04-09 10:30:35 +0000756int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000757{
niklase@google.com470e71d2011-07-07 08:21:25 +0000758 CHECK_INITIALIZED();
759
760 bool isAvailable(0);
761
762 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
763 {
764 return -1;
765 }
766
767 *available = isAvailable;
768
769 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
770 return (0);
771}
772
773// ----------------------------------------------------------------------------
774// SetSpeakerMute
775// ----------------------------------------------------------------------------
776
pbos@webrtc.org25509882013-04-09 10:30:35 +0000777int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000778{
niklase@google.com470e71d2011-07-07 08:21:25 +0000779 CHECK_INITIALIZED();
780 return (_ptrAudioDevice->SetSpeakerMute(enable));
781}
782
783// ----------------------------------------------------------------------------
784// SpeakerMute
785// ----------------------------------------------------------------------------
786
pbos@webrtc.org25509882013-04-09 10:30:35 +0000787int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000788{
niklase@google.com470e71d2011-07-07 08:21:25 +0000789 CHECK_INITIALIZED();
790
791 bool muted(false);
792
793 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
794 {
795 return -1;
796 }
797
798 *enabled = muted;
799
800 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
801 return (0);
802}
803
804// ----------------------------------------------------------------------------
805// MicrophoneMuteIsAvailable
806// ----------------------------------------------------------------------------
807
pbos@webrtc.org25509882013-04-09 10:30:35 +0000808int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000809{
niklase@google.com470e71d2011-07-07 08:21:25 +0000810 CHECK_INITIALIZED();
811
812 bool isAvailable(0);
813
814 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
815 {
816 return -1;
817 }
818
819 *available = isAvailable;
820
821 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
822 return (0);
823}
824
825// ----------------------------------------------------------------------------
826// SetMicrophoneMute
827// ----------------------------------------------------------------------------
828
pbos@webrtc.org25509882013-04-09 10:30:35 +0000829int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000830{
niklase@google.com470e71d2011-07-07 08:21:25 +0000831 CHECK_INITIALIZED();
832 return (_ptrAudioDevice->SetMicrophoneMute(enable));
833}
834
835// ----------------------------------------------------------------------------
836// MicrophoneMute
837// ----------------------------------------------------------------------------
838
pbos@webrtc.org25509882013-04-09 10:30:35 +0000839int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000840{
niklase@google.com470e71d2011-07-07 08:21:25 +0000841 CHECK_INITIALIZED();
842
843 bool muted(false);
844
845 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
846 {
847 return -1;
848 }
849
850 *enabled = muted;
851
852 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
853 return (0);
854}
855
856// ----------------------------------------------------------------------------
857// MicrophoneBoostIsAvailable
858// ----------------------------------------------------------------------------
859
pbos@webrtc.org25509882013-04-09 10:30:35 +0000860int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000861{
niklase@google.com470e71d2011-07-07 08:21:25 +0000862 CHECK_INITIALIZED();
863
864 bool isAvailable(0);
865
866 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
867 {
868 return -1;
869 }
870
871 *available = isAvailable;
872
873 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
874 return (0);
875}
876
877// ----------------------------------------------------------------------------
878// SetMicrophoneBoost
879// ----------------------------------------------------------------------------
880
pbos@webrtc.org25509882013-04-09 10:30:35 +0000881int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000882{
niklase@google.com470e71d2011-07-07 08:21:25 +0000883 CHECK_INITIALIZED();
884 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
885}
886
887// ----------------------------------------------------------------------------
888// MicrophoneBoost
889// ----------------------------------------------------------------------------
890
pbos@webrtc.org25509882013-04-09 10:30:35 +0000891int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000892{
niklase@google.com470e71d2011-07-07 08:21:25 +0000893 CHECK_INITIALIZED();
894
895 bool onOff(false);
896
897 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
898 {
899 return -1;
900 }
901
902 *enabled = onOff;
903
904 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
905 return (0);
906}
907
908// ----------------------------------------------------------------------------
909// MicrophoneVolumeIsAvailable
910// ----------------------------------------------------------------------------
911
pbos@webrtc.org25509882013-04-09 10:30:35 +0000912int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000913{
niklase@google.com470e71d2011-07-07 08:21:25 +0000914 CHECK_INITIALIZED();
915
916 bool isAvailable(0);
917
918 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
919 {
920 return -1;
921 }
922
923 *available = isAvailable;
924
925 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
926 return (0);
927}
928
929// ----------------------------------------------------------------------------
930// SetMicrophoneVolume
931// ----------------------------------------------------------------------------
932
pbos@webrtc.org25509882013-04-09 10:30:35 +0000933int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000934{
niklase@google.com470e71d2011-07-07 08:21:25 +0000935 CHECK_INITIALIZED();
936 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
937}
938
939// ----------------------------------------------------------------------------
940// MicrophoneVolume
941// ----------------------------------------------------------------------------
942
pbos@webrtc.org25509882013-04-09 10:30:35 +0000943int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000944{
945 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
946 CHECK_INITIALIZED();
947
pbos@webrtc.org25509882013-04-09 10:30:35 +0000948 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000949
950 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
951 {
952 return -1;
953 }
954
955 *volume = level;
956
957 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
958 return (0);
959}
960
961// ----------------------------------------------------------------------------
962// StereoRecordingIsAvailable
963// ----------------------------------------------------------------------------
964
pbos@webrtc.org25509882013-04-09 10:30:35 +0000965int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000966{
niklase@google.com470e71d2011-07-07 08:21:25 +0000967 CHECK_INITIALIZED();
968
969 bool isAvailable(0);
970
971 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
972 {
973 return -1;
974 }
975
976 *available = isAvailable;
977
978 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
979 return (0);
980}
981
982// ----------------------------------------------------------------------------
983// SetStereoRecording
984// ----------------------------------------------------------------------------
985
pbos@webrtc.org25509882013-04-09 10:30:35 +0000986int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000987{
niklase@google.com470e71d2011-07-07 08:21:25 +0000988 CHECK_INITIALIZED();
989
990 if (_ptrAudioDevice->RecordingIsInitialized())
991 {
992 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
993 return -1;
994 }
995
996 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
997 {
998 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
999 return -1;
1000 }
1001
pbos@webrtc.org25509882013-04-09 10:30:35 +00001002 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001003 if (enable)
1004 {
1005 nChannels = 2;
1006 }
1007 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1008
1009 return 0;
1010}
1011
1012// ----------------------------------------------------------------------------
1013// StereoRecording
1014// ----------------------------------------------------------------------------
1015
pbos@webrtc.org25509882013-04-09 10:30:35 +00001016int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001017{
niklase@google.com470e71d2011-07-07 08:21:25 +00001018 CHECK_INITIALIZED();
1019
1020 bool stereo(false);
1021
1022 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1023 {
1024 return -1;
1025 }
1026
1027 *enabled = stereo;
1028
1029 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1030 return (0);
1031}
1032
1033// ----------------------------------------------------------------------------
1034// SetRecordingChannel
1035// ----------------------------------------------------------------------------
1036
pbos@webrtc.org25509882013-04-09 10:30:35 +00001037int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001038{
1039 if (channel == kChannelBoth)
1040 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001041 }
1042 else if (channel == kChannelLeft)
1043 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001044 }
1045 else
1046 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001047 }
1048 CHECK_INITIALIZED();
1049
1050 bool stereo(false);
1051
1052 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1053 {
1054 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1055 return -1;
1056 }
1057
1058 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1059}
1060
1061// ----------------------------------------------------------------------------
1062// RecordingChannel
1063// ----------------------------------------------------------------------------
1064
pbos@webrtc.org25509882013-04-09 10:30:35 +00001065int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001066{
niklase@google.com470e71d2011-07-07 08:21:25 +00001067 CHECK_INITIALIZED();
1068
1069 ChannelType chType;
1070
1071 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1072 {
1073 return -1;
1074 }
1075
1076 *channel = chType;
1077
1078 if (*channel == kChannelBoth)
1079 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001080 }
1081 else if (*channel == kChannelLeft)
1082 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001083 }
1084 else
1085 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001086 }
1087
1088 return (0);
1089}
1090
1091// ----------------------------------------------------------------------------
1092// StereoPlayoutIsAvailable
1093// ----------------------------------------------------------------------------
1094
pbos@webrtc.org25509882013-04-09 10:30:35 +00001095int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001096{
niklase@google.com470e71d2011-07-07 08:21:25 +00001097 CHECK_INITIALIZED();
1098
1099 bool isAvailable(0);
1100
1101 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1102 {
1103 return -1;
1104 }
1105
1106 *available = isAvailable;
1107
1108 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1109 return (0);
1110}
1111
1112// ----------------------------------------------------------------------------
1113// SetStereoPlayout
1114// ----------------------------------------------------------------------------
1115
pbos@webrtc.org25509882013-04-09 10:30:35 +00001116int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001117{
niklase@google.com470e71d2011-07-07 08:21:25 +00001118 CHECK_INITIALIZED();
1119
1120 if (_ptrAudioDevice->PlayoutIsInitialized())
1121 {
1122 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1123 return -1;
1124 }
1125
1126 if (_ptrAudioDevice->SetStereoPlayout(enable))
1127 {
1128 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1129 return -1;
1130 }
1131
pbos@webrtc.org25509882013-04-09 10:30:35 +00001132 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001133 if (enable)
1134 {
1135 nChannels = 2;
1136 }
1137 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1138
1139 return 0;
1140}
1141
1142// ----------------------------------------------------------------------------
1143// StereoPlayout
1144// ----------------------------------------------------------------------------
1145
pbos@webrtc.org25509882013-04-09 10:30:35 +00001146int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001147{
niklase@google.com470e71d2011-07-07 08:21:25 +00001148 CHECK_INITIALIZED();
1149
1150 bool stereo(false);
1151
1152 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1153 {
1154 return -1;
1155 }
1156
1157 *enabled = stereo;
1158
1159 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1160 return (0);
1161}
1162
1163// ----------------------------------------------------------------------------
1164// SetAGC
1165// ----------------------------------------------------------------------------
1166
pbos@webrtc.org25509882013-04-09 10:30:35 +00001167int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001168{
niklase@google.com470e71d2011-07-07 08:21:25 +00001169 CHECK_INITIALIZED();
1170 return (_ptrAudioDevice->SetAGC(enable));
1171}
1172
1173// ----------------------------------------------------------------------------
1174// AGC
1175// ----------------------------------------------------------------------------
1176
1177bool AudioDeviceModuleImpl::AGC() const
1178{
niklase@google.com470e71d2011-07-07 08:21:25 +00001179 CHECK_INITIALIZED_BOOL();
1180 return (_ptrAudioDevice->AGC());
1181}
1182
1183// ----------------------------------------------------------------------------
1184// PlayoutIsAvailable
1185// ----------------------------------------------------------------------------
1186
pbos@webrtc.org25509882013-04-09 10:30:35 +00001187int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001188{
niklase@google.com470e71d2011-07-07 08:21:25 +00001189 CHECK_INITIALIZED();
1190
1191 bool isAvailable(0);
1192
1193 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1194 {
1195 return -1;
1196 }
1197
1198 *available = isAvailable;
1199
1200 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1201 return (0);
1202}
1203
1204// ----------------------------------------------------------------------------
1205// RecordingIsAvailable
1206// ----------------------------------------------------------------------------
1207
pbos@webrtc.org25509882013-04-09 10:30:35 +00001208int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001209{
niklase@google.com470e71d2011-07-07 08:21:25 +00001210 CHECK_INITIALIZED();
1211
1212 bool isAvailable(0);
1213
1214 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1215 {
1216 return -1;
1217 }
1218
1219 *available = isAvailable;
1220
1221 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1222 return (0);
1223}
1224
1225// ----------------------------------------------------------------------------
1226// MaxMicrophoneVolume
1227// ----------------------------------------------------------------------------
1228
pbos@webrtc.org25509882013-04-09 10:30:35 +00001229int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001230{
1231 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1232 CHECK_INITIALIZED();
1233
pbos@webrtc.org25509882013-04-09 10:30:35 +00001234 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001235
1236 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1237 {
1238 return -1;
1239 }
1240
1241 *maxVolume = maxVol;
1242
1243 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1244 return (0);
1245}
1246
1247// ----------------------------------------------------------------------------
1248// MinMicrophoneVolume
1249// ----------------------------------------------------------------------------
1250
pbos@webrtc.org25509882013-04-09 10:30:35 +00001251int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001252{
niklase@google.com470e71d2011-07-07 08:21:25 +00001253 CHECK_INITIALIZED();
1254
pbos@webrtc.org25509882013-04-09 10:30:35 +00001255 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001256
1257 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1258 {
1259 return -1;
1260 }
1261
1262 *minVolume = minVol;
1263
1264 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1265 return (0);
1266}
1267
1268// ----------------------------------------------------------------------------
1269// MicrophoneVolumeStepSize
1270// ----------------------------------------------------------------------------
1271
pbos@webrtc.org25509882013-04-09 10:30:35 +00001272int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001273{
niklase@google.com470e71d2011-07-07 08:21:25 +00001274 CHECK_INITIALIZED();
1275
pbos@webrtc.org25509882013-04-09 10:30:35 +00001276 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001277
1278 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1279 {
1280 return -1;
1281 }
1282
1283 *stepSize = delta;
1284
1285 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1286 return (0);
1287}
1288
1289// ----------------------------------------------------------------------------
1290// PlayoutDevices
1291// ----------------------------------------------------------------------------
1292
pbos@webrtc.org25509882013-04-09 10:30:35 +00001293int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001294{
niklase@google.com470e71d2011-07-07 08:21:25 +00001295 CHECK_INITIALIZED();
1296
pbos@webrtc.org25509882013-04-09 10:30:35 +00001297 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001298
1299 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001300 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001301}
1302
1303// ----------------------------------------------------------------------------
1304// SetPlayoutDevice I (II)
1305// ----------------------------------------------------------------------------
1306
pbos@webrtc.org25509882013-04-09 10:30:35 +00001307int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001308{
niklase@google.com470e71d2011-07-07 08:21:25 +00001309 CHECK_INITIALIZED();
1310 return (_ptrAudioDevice->SetPlayoutDevice(index));
1311}
1312
1313// ----------------------------------------------------------------------------
1314// SetPlayoutDevice II (II)
1315// ----------------------------------------------------------------------------
1316
pbos@webrtc.org25509882013-04-09 10:30:35 +00001317int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001318{
1319 if (device == kDefaultDevice)
1320 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001321 }
1322 else
1323 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001324 }
1325 CHECK_INITIALIZED();
1326
1327 return (_ptrAudioDevice->SetPlayoutDevice(device));
1328}
1329
1330// ----------------------------------------------------------------------------
1331// PlayoutDeviceName
1332// ----------------------------------------------------------------------------
1333
pbos@webrtc.org25509882013-04-09 10:30:35 +00001334int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1335 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001336 char name[kAdmMaxDeviceNameSize],
1337 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001338{
niklase@google.com470e71d2011-07-07 08:21:25 +00001339 CHECK_INITIALIZED();
1340
1341 if (name == NULL)
1342 {
1343 _lastError = kAdmErrArgument;
1344 return -1;
1345 }
1346
1347 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1348 {
1349 return -1;
1350 }
1351
1352 if (name != NULL)
1353 {
1354 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1355 }
1356 if (guid != NULL)
1357 {
1358 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1359 }
1360
1361 return (0);
1362}
1363
1364// ----------------------------------------------------------------------------
1365// RecordingDeviceName
1366// ----------------------------------------------------------------------------
1367
pbos@webrtc.org25509882013-04-09 10:30:35 +00001368int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1369 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001370 char name[kAdmMaxDeviceNameSize],
1371 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001372{
niklase@google.com470e71d2011-07-07 08:21:25 +00001373 CHECK_INITIALIZED();
1374
1375 if (name == NULL)
1376 {
1377 _lastError = kAdmErrArgument;
1378 return -1;
1379 }
1380
1381 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1382 {
1383 return -1;
1384 }
1385
1386 if (name != NULL)
1387 {
1388 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1389 }
1390 if (guid != NULL)
1391 {
1392 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1393 }
1394
1395 return (0);
1396}
1397
1398// ----------------------------------------------------------------------------
1399// RecordingDevices
1400// ----------------------------------------------------------------------------
1401
pbos@webrtc.org25509882013-04-09 10:30:35 +00001402int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001403{
niklase@google.com470e71d2011-07-07 08:21:25 +00001404 CHECK_INITIALIZED();
1405
pbos@webrtc.org25509882013-04-09 10:30:35 +00001406 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001407
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001408 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1409 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001410 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001411}
1412
1413// ----------------------------------------------------------------------------
1414// SetRecordingDevice I (II)
1415// ----------------------------------------------------------------------------
1416
pbos@webrtc.org25509882013-04-09 10:30:35 +00001417int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001418{
niklase@google.com470e71d2011-07-07 08:21:25 +00001419 CHECK_INITIALIZED();
1420 return (_ptrAudioDevice->SetRecordingDevice(index));
1421}
1422
1423// ----------------------------------------------------------------------------
1424// SetRecordingDevice II (II)
1425// ----------------------------------------------------------------------------
1426
pbos@webrtc.org25509882013-04-09 10:30:35 +00001427int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001428{
1429 if (device == kDefaultDevice)
1430 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001431 }
1432 else
1433 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001434 }
1435 CHECK_INITIALIZED();
1436
1437 return (_ptrAudioDevice->SetRecordingDevice(device));
1438}
1439
1440// ----------------------------------------------------------------------------
1441// InitPlayout
1442// ----------------------------------------------------------------------------
1443
pbos@webrtc.org25509882013-04-09 10:30:35 +00001444int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001445{
niklase@google.com470e71d2011-07-07 08:21:25 +00001446 CHECK_INITIALIZED();
1447 _audioDeviceBuffer.InitPlayout();
1448 return (_ptrAudioDevice->InitPlayout());
1449}
1450
1451// ----------------------------------------------------------------------------
1452// InitRecording
1453// ----------------------------------------------------------------------------
1454
pbos@webrtc.org25509882013-04-09 10:30:35 +00001455int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001456{
niklase@google.com470e71d2011-07-07 08:21:25 +00001457 CHECK_INITIALIZED();
1458 _audioDeviceBuffer.InitRecording();
1459 return (_ptrAudioDevice->InitRecording());
1460}
1461
1462// ----------------------------------------------------------------------------
1463// PlayoutIsInitialized
1464// ----------------------------------------------------------------------------
1465
1466bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1467{
niklase@google.com470e71d2011-07-07 08:21:25 +00001468 CHECK_INITIALIZED_BOOL();
1469 return (_ptrAudioDevice->PlayoutIsInitialized());
1470}
1471
1472// ----------------------------------------------------------------------------
1473// RecordingIsInitialized
1474// ----------------------------------------------------------------------------
1475
1476bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1477{
niklase@google.com470e71d2011-07-07 08:21:25 +00001478 CHECK_INITIALIZED_BOOL();
1479 return (_ptrAudioDevice->RecordingIsInitialized());
1480}
1481
1482// ----------------------------------------------------------------------------
1483// StartPlayout
1484// ----------------------------------------------------------------------------
1485
pbos@webrtc.org25509882013-04-09 10:30:35 +00001486int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001487{
niklase@google.com470e71d2011-07-07 08:21:25 +00001488 CHECK_INITIALIZED();
1489 return (_ptrAudioDevice->StartPlayout());
1490}
1491
1492// ----------------------------------------------------------------------------
1493// StopPlayout
1494// ----------------------------------------------------------------------------
1495
pbos@webrtc.org25509882013-04-09 10:30:35 +00001496int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001497{
niklase@google.com470e71d2011-07-07 08:21:25 +00001498 CHECK_INITIALIZED();
1499 return (_ptrAudioDevice->StopPlayout());
1500}
1501
1502// ----------------------------------------------------------------------------
1503// Playing
1504// ----------------------------------------------------------------------------
1505
1506bool AudioDeviceModuleImpl::Playing() const
1507{
niklase@google.com470e71d2011-07-07 08:21:25 +00001508 CHECK_INITIALIZED_BOOL();
1509 return (_ptrAudioDevice->Playing());
1510}
1511
1512// ----------------------------------------------------------------------------
1513// StartRecording
1514// ----------------------------------------------------------------------------
1515
pbos@webrtc.org25509882013-04-09 10:30:35 +00001516int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001517{
niklase@google.com470e71d2011-07-07 08:21:25 +00001518 CHECK_INITIALIZED();
1519 return (_ptrAudioDevice->StartRecording());
1520}
1521// ----------------------------------------------------------------------------
1522// StopRecording
1523// ----------------------------------------------------------------------------
1524
pbos@webrtc.org25509882013-04-09 10:30:35 +00001525int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001526{
niklase@google.com470e71d2011-07-07 08:21:25 +00001527 CHECK_INITIALIZED();
1528 return (_ptrAudioDevice->StopRecording());
1529}
1530
1531// ----------------------------------------------------------------------------
1532// Recording
1533// ----------------------------------------------------------------------------
1534
1535bool AudioDeviceModuleImpl::Recording() const
1536{
niklase@google.com470e71d2011-07-07 08:21:25 +00001537 CHECK_INITIALIZED_BOOL();
1538 return (_ptrAudioDevice->Recording());
1539}
1540
1541// ----------------------------------------------------------------------------
1542// RegisterEventObserver
1543// ----------------------------------------------------------------------------
1544
pbos@webrtc.org25509882013-04-09 10:30:35 +00001545int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001546{
niklase@google.com470e71d2011-07-07 08:21:25 +00001547
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001548 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001549 _ptrCbAudioDeviceObserver = eventCallback;
1550
1551 return 0;
1552}
1553
1554// ----------------------------------------------------------------------------
1555// RegisterAudioCallback
1556// ----------------------------------------------------------------------------
1557
pbos@webrtc.org25509882013-04-09 10:30:35 +00001558int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001559{
niklase@google.com470e71d2011-07-07 08:21:25 +00001560
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001561 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001562 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1563
1564 return 0;
1565}
1566
1567// ----------------------------------------------------------------------------
1568// StartRawInputFileRecording
1569// ----------------------------------------------------------------------------
1570
pbos@webrtc.org25509882013-04-09 10:30:35 +00001571int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001572 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001573{
niklase@google.com470e71d2011-07-07 08:21:25 +00001574 CHECK_INITIALIZED();
1575
1576 if (NULL == pcmFileNameUTF8)
1577 {
1578 return -1;
1579 }
1580
1581 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1582}
1583
1584// ----------------------------------------------------------------------------
1585// StopRawInputFileRecording
1586// ----------------------------------------------------------------------------
1587
pbos@webrtc.org25509882013-04-09 10:30:35 +00001588int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001589{
niklase@google.com470e71d2011-07-07 08:21:25 +00001590 CHECK_INITIALIZED();
1591
1592 return (_audioDeviceBuffer.StopInputFileRecording());
1593}
1594
1595// ----------------------------------------------------------------------------
1596// StartRawOutputFileRecording
1597// ----------------------------------------------------------------------------
1598
pbos@webrtc.org25509882013-04-09 10:30:35 +00001599int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001600 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001601{
niklase@google.com470e71d2011-07-07 08:21:25 +00001602 CHECK_INITIALIZED();
1603
1604 if (NULL == pcmFileNameUTF8)
1605 {
1606 return -1;
1607 }
1608
1609 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1610}
1611
1612// ----------------------------------------------------------------------------
1613// StopRawOutputFileRecording
1614// ----------------------------------------------------------------------------
1615
pbos@webrtc.org25509882013-04-09 10:30:35 +00001616int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001617{
niklase@google.com470e71d2011-07-07 08:21:25 +00001618 CHECK_INITIALIZED();
1619
1620 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001621}
1622
1623// ----------------------------------------------------------------------------
1624// SetPlayoutBuffer
1625// ----------------------------------------------------------------------------
1626
pbos@webrtc.org25509882013-04-09 10:30:35 +00001627int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001628{
niklase@google.com470e71d2011-07-07 08:21:25 +00001629 CHECK_INITIALIZED();
1630
1631 if (_ptrAudioDevice->PlayoutIsInitialized())
1632 {
1633 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1634 return -1;
1635 }
1636
pbos@webrtc.org25509882013-04-09 10:30:35 +00001637 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001638
1639 if (kFixedBufferSize == type)
1640 {
1641 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1642 {
1643 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1644 return -1;
1645 }
1646 }
1647
1648 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1649 {
1650 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1651 }
1652
1653 return ret;
1654}
1655
1656// ----------------------------------------------------------------------------
1657// PlayoutBuffer
1658// ----------------------------------------------------------------------------
1659
pbos@webrtc.org25509882013-04-09 10:30:35 +00001660int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001661{
niklase@google.com470e71d2011-07-07 08:21:25 +00001662 CHECK_INITIALIZED();
1663
1664 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001665 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001666
1667 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1668 {
1669 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1670 return -1;
1671 }
1672
1673 *type = bufType;
1674 *sizeMS = size;
1675
1676 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1677 return (0);
1678}
1679
1680// ----------------------------------------------------------------------------
1681// PlayoutDelay
1682// ----------------------------------------------------------------------------
1683
pbos@webrtc.org25509882013-04-09 10:30:35 +00001684int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001685{
1686 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1687 CHECK_INITIALIZED();
1688
pbos@webrtc.org25509882013-04-09 10:30:35 +00001689 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001690
1691 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1692 {
1693 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1694 return -1;
1695 }
1696
1697 *delayMS = delay;
1698
1699 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1700 return (0);
1701}
1702
1703// ----------------------------------------------------------------------------
1704// RecordingDelay
1705// ----------------------------------------------------------------------------
1706
pbos@webrtc.org25509882013-04-09 10:30:35 +00001707int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001708{
1709 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1710 CHECK_INITIALIZED();
1711
pbos@webrtc.org25509882013-04-09 10:30:35 +00001712 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001713
1714 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1715 {
1716 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1717 return -1;
1718 }
1719
1720 *delayMS = delay;
1721
1722 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1723 return (0);
1724}
1725
1726// ----------------------------------------------------------------------------
1727// CPULoad
1728// ----------------------------------------------------------------------------
1729
pbos@webrtc.org25509882013-04-09 10:30:35 +00001730int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001731{
niklase@google.com470e71d2011-07-07 08:21:25 +00001732 CHECK_INITIALIZED();
1733
pbos@webrtc.org25509882013-04-09 10:30:35 +00001734 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001735
1736 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1737 {
1738 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1739 return -1;
1740 }
1741
1742 *load = cpuLoad;
1743
1744 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1745 return (0);
1746}
1747
1748// ----------------------------------------------------------------------------
1749// SetRecordingSampleRate
1750// ----------------------------------------------------------------------------
1751
pbos@webrtc.org25509882013-04-09 10:30:35 +00001752int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001753{
niklase@google.com470e71d2011-07-07 08:21:25 +00001754 CHECK_INITIALIZED();
1755
1756 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1757 {
1758 return -1;
1759 }
1760
1761 return (0);
1762}
1763
1764// ----------------------------------------------------------------------------
1765// RecordingSampleRate
1766// ----------------------------------------------------------------------------
1767
pbos@webrtc.org25509882013-04-09 10:30:35 +00001768int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001769{
niklase@google.com470e71d2011-07-07 08:21:25 +00001770 CHECK_INITIALIZED();
1771
pbos@webrtc.org25509882013-04-09 10:30:35 +00001772 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001773
1774 if (sampleRate == -1)
1775 {
1776 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1777 return -1;
1778 }
1779
1780 *samplesPerSec = sampleRate;
1781
1782 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1783 return (0);
1784}
1785
1786// ----------------------------------------------------------------------------
1787// SetPlayoutSampleRate
1788// ----------------------------------------------------------------------------
1789
pbos@webrtc.org25509882013-04-09 10:30:35 +00001790int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001791{
niklase@google.com470e71d2011-07-07 08:21:25 +00001792 CHECK_INITIALIZED();
1793
1794 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1795 {
1796 return -1;
1797 }
1798
1799 return (0);
1800}
1801
1802// ----------------------------------------------------------------------------
1803// PlayoutSampleRate
1804// ----------------------------------------------------------------------------
1805
pbos@webrtc.org25509882013-04-09 10:30:35 +00001806int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001807{
niklase@google.com470e71d2011-07-07 08:21:25 +00001808 CHECK_INITIALIZED();
1809
pbos@webrtc.org25509882013-04-09 10:30:35 +00001810 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001811
1812 if (sampleRate == -1)
1813 {
1814 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1815 return -1;
1816 }
1817
1818 *samplesPerSec = sampleRate;
1819
1820 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1821 return (0);
1822}
1823
1824// ----------------------------------------------------------------------------
1825// ResetAudioDevice
1826// ----------------------------------------------------------------------------
1827
pbos@webrtc.org25509882013-04-09 10:30:35 +00001828int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001829{
niklase@google.com470e71d2011-07-07 08:21:25 +00001830 CHECK_INITIALIZED();
1831
1832
1833 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1834 {
1835 return -1;
1836 }
1837
1838 return (0);
1839}
1840
1841// ----------------------------------------------------------------------------
1842// SetLoudspeakerStatus
1843// ----------------------------------------------------------------------------
1844
pbos@webrtc.org25509882013-04-09 10:30:35 +00001845int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001846{
niklase@google.com470e71d2011-07-07 08:21:25 +00001847 CHECK_INITIALIZED();
1848
1849 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1850 {
1851 return -1;
1852 }
1853
1854 return 0;
1855}
1856
1857// ----------------------------------------------------------------------------
1858// GetLoudspeakerStatus
1859// ----------------------------------------------------------------------------
1860
henrikac14f5ff2015-09-23 14:08:33 +02001861int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001862 CHECK_INITIALIZED();
henrikac14f5ff2015-09-23 14:08:33 +02001863 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
1864 return -1;
1865 }
1866 return 0;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001867}
1868
henrikac14f5ff2015-09-23 14:08:33 +02001869bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
1870 CHECK_INITIALIZED_BOOL();
1871 return _ptrAudioDevice->BuiltInAECIsEnabled();
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001872}
1873
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001874bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1875 CHECK_INITIALIZED_BOOL();
1876 return _ptrAudioDevice->BuiltInAECIsAvailable();
1877}
1878
henrikac14f5ff2015-09-23 14:08:33 +02001879int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
1880 CHECK_INITIALIZED();
1881 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1882}
1883
1884bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
1885 CHECK_INITIALIZED_BOOL();
1886 return _ptrAudioDevice->BuiltInAGCIsAvailable();
1887}
1888
1889int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
1890 CHECK_INITIALIZED();
1891 return _ptrAudioDevice->EnableBuiltInAGC(enable);
1892}
1893
1894bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
1895 CHECK_INITIALIZED_BOOL();
1896 return _ptrAudioDevice->BuiltInNSIsAvailable();
1897}
1898
1899int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
1900 CHECK_INITIALIZED();
1901 return _ptrAudioDevice->EnableBuiltInNS(enable);
1902}
1903
henrikaba35d052015-07-14 17:04:08 +02001904int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1905 AudioParameters* params) const {
1906 return _ptrAudioDevice->GetPlayoutAudioParameters(params);
1907}
1908
1909int AudioDeviceModuleImpl::GetRecordAudioParameters(
1910 AudioParameters* params) const {
1911 return _ptrAudioDevice->GetRecordAudioParameters(params);
1912}
1913
niklase@google.com470e71d2011-07-07 08:21:25 +00001914// ============================================================================
1915// Private Methods
1916// ============================================================================
1917
1918// ----------------------------------------------------------------------------
1919// Platform
1920// ----------------------------------------------------------------------------
1921
1922AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1923{
1924 return _platformType;
1925}
1926
1927// ----------------------------------------------------------------------------
1928// PlatformAudioLayer
1929// ----------------------------------------------------------------------------
1930
1931AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
1932{
niklase@google.com470e71d2011-07-07 08:21:25 +00001933 return _platformAudioLayer;
1934}
1935
1936} // namespace webrtc