blob: 6576f5d8e92b8b50d8dd10d37017f7627b068e8f [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"
Peter Boströmdda52b92016-04-11 16:04:33 +020012#include "webrtc/base/trace_event.h"
pbos@webrtc.org811269d2013-07-11 13:24:38 +000013#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
14#include "webrtc/modules/audio_device/audio_device_config.h"
15#include "webrtc/modules/audio_device/audio_device_impl.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010016#include "webrtc/system_wrappers/include/tick_util.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +000018#include <assert.h>
xians@google.combf5d2ba2011-08-16 07:44:19 +000019#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21#if defined(_WIN32)
xians@google.com68efa212011-08-11 12:41:56 +000022 #include "audio_device_wave_win.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
xians@google.com68efa212011-08-11 12:41:56 +000024 #include "audio_device_core_win.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025 #endif
leozwang@google.com39f20512011-07-15 16:29:40 +000026#elif defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +020027#include <stdlib.h>
henrikab2619892015-05-18 16:49:16 +020028#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)
niklase@google.com470e71d2011-07-07 08:21:25 +000034 #if defined(LINUX_ALSA)
Tommi68898a22015-05-19 17:28:07 +020035 #include "audio_device_alsa_linux.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000036 #endif
Tommi68898a22015-05-19 17:28:07 +020037#if defined(LINUX_PULSE)
xians@google.com68efa212011-08-11 12:41:56 +000038 #include "audio_device_pulse_linux.h"
Tommi68898a22015-05-19 17:28:07 +020039#endif
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000040#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +000041 #include "audio_device_ios.h"
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +000042#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +000043 #include "audio_device_mac.h"
44#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000045
46#if defined(WEBRTC_DUMMY_FILE_DEVICES)
47#include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
48#endif
49
pbos@webrtc.org811269d2013-07-11 13:24:38 +000050#include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000051#include "webrtc/modules/audio_device/dummy/file_audio_device.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010052#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
53#include "webrtc/system_wrappers/include/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000054
55#define CHECK_INITIALIZED() \
56{ \
57 if (!_initialized) { \
58 return -1; \
59 }; \
60}
61
62#define CHECK_INITIALIZED_BOOL() \
63{ \
64 if (!_initialized) { \
65 return false; \
66 }; \
67}
68
Peter Boström1d194412016-03-21 16:44:31 +010069namespace webrtc {
henrike@webrtc.org70efc322012-02-23 17:45:33 +000070
niklase@google.com470e71d2011-07-07 08:21:25 +000071// ============================================================================
72// Static methods
73// ============================================================================
74
75// ----------------------------------------------------------------------------
76// AudioDeviceModule::Create()
77// ----------------------------------------------------------------------------
78
Peter Boström1d194412016-03-21 16:44:31 +010079rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModuleImpl::Create(
80 const int32_t id,
81 const AudioLayer audioLayer) {
henrika@google.com73d65512011-09-07 15:11:18 +000082 // Create the generic ref counted (platform independent) implementation.
Peter Boström1d194412016-03-21 16:44:31 +010083 rtc::scoped_refptr<AudioDeviceModuleImpl> audioDevice(
84 new rtc::RefCountedObject<AudioDeviceModuleImpl>(id, audioLayer));
niklase@google.com470e71d2011-07-07 08:21:25 +000085
henrika@google.com73d65512011-09-07 15:11:18 +000086 // Ensure that the current platform is supported.
niklase@google.com470e71d2011-07-07 08:21:25 +000087 if (audioDevice->CheckPlatform() == -1)
88 {
Peter Boström1d194412016-03-21 16:44:31 +010089 return nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +000090 }
91
henrika@google.com73d65512011-09-07 15:11:18 +000092 // Create the platform-dependent implementation.
niklase@google.com470e71d2011-07-07 08:21:25 +000093 if (audioDevice->CreatePlatformSpecificObjects() == -1)
94 {
Peter Boström1d194412016-03-21 16:44:31 +010095 return nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +000096 }
97
henrika@google.com73d65512011-09-07 15:11:18 +000098 // Ensure that the generic audio buffer can communicate with the
99 // platform-specific parts.
niklase@google.com470e71d2011-07-07 08:21:25 +0000100 if (audioDevice->AttachAudioBuffer() == -1)
101 {
Peter Boström1d194412016-03-21 16:44:31 +0100102 return nullptr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 }
104
kma@webrtc.orgac4d70d2012-10-05 00:19:01 +0000105 WebRtcSpl_Init();
106
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 return audioDevice;
108}
109
niklase@google.com470e71d2011-07-07 08:21:25 +0000110// ============================================================================
111// Construction & Destruction
112// ============================================================================
113
114// ----------------------------------------------------------------------------
115// AudioDeviceModuleImpl - ctor
116// ----------------------------------------------------------------------------
117
pbos@webrtc.org25509882013-04-09 10:30:35 +0000118AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
niklase@google.com470e71d2011-07-07 08:21:25 +0000119 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
120 _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
121 _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
122 _ptrCbAudioDeviceObserver(NULL),
xians@google.com88bd4402011-08-04 15:33:30 +0000123 _ptrAudioDevice(NULL),
niklase@google.com470e71d2011-07-07 08:21:25 +0000124 _id(id),
125 _platformAudioLayer(audioLayer),
Tommi68898a22015-05-19 17:28:07 +0200126 _lastProcessTime(TickTime::MillisecondTimestamp()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000127 _platformType(kPlatformNotSupported),
xians@google.com88bd4402011-08-04 15:33:30 +0000128 _initialized(false),
129 _lastError(kAdmErrNone)
niklase@google.com470e71d2011-07-07 08:21:25 +0000130{
131 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
132}
133
134// ----------------------------------------------------------------------------
135// CheckPlatform
136// ----------------------------------------------------------------------------
137
pbos@webrtc.org25509882013-04-09 10:30:35 +0000138int32_t AudioDeviceModuleImpl::CheckPlatform()
niklase@google.com470e71d2011-07-07 08:21:25 +0000139{
140 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
141
142 // Ensure that the current platform is supported
143 //
144 PlatformType platform(kPlatformNotSupported);
145
146#if defined(_WIN32)
147 platform = kPlatformWin32;
148 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
leozwang@google.com522f42b2011-09-19 17:39:05 +0000149#elif defined(WEBRTC_ANDROID)
150 platform = kPlatformAndroid;
151 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
niklase@google.com470e71d2011-07-07 08:21:25 +0000152#elif defined(WEBRTC_LINUX)
153 platform = kPlatformLinux;
154 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000155#elif defined(WEBRTC_IOS)
sjlee@webrtc.org4b425082012-09-10 17:58:21 +0000156 platform = kPlatformIOS;
157 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000158#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000159 platform = kPlatformMac;
160 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
161#endif
162
163 if (platform == kPlatformNotSupported)
164 {
165 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
166 return -1;
167 }
168
169 // Store valid output results
170 //
171 _platformType = platform;
172
173 return 0;
174}
175
176
177// ----------------------------------------------------------------------------
178// CreatePlatformSpecificObjects
179// ----------------------------------------------------------------------------
180
pbos@webrtc.org25509882013-04-09 10:30:35 +0000181int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
niklase@google.com470e71d2011-07-07 08:21:25 +0000182{
183 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
184
185 AudioDeviceGeneric* ptrAudioDevice(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
xians@google.combf5d2ba2011-08-16 07:44:19 +0000187#if defined(WEBRTC_DUMMY_AUDIO_BUILD)
188 ptrAudioDevice = new AudioDeviceDummy(Id());
189 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +0000190#elif defined(WEBRTC_DUMMY_FILE_DEVICES)
191 ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
192 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
193 "Will use file-playing dummy device.");
xians@google.combf5d2ba2011-08-16 07:44:19 +0000194#else
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000195 AudioLayer audioLayer(PlatformAudioLayer());
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
197 // Create the *Windows* implementation of the Audio Device
198 //
199#if defined(_WIN32)
200 if ((audioLayer == kWindowsWaveAudio)
201#if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
202 // Wave audio is default if Core audio is not supported in this build
203 || (audioLayer == kPlatformDefaultAudio)
204#endif
205 )
206 {
207 // create *Windows Wave Audio* implementation
208 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
209 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
210 }
211#if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
212 if ((audioLayer == kWindowsCoreAudio) ||
213 (audioLayer == kPlatformDefaultAudio)
214 )
215 {
216 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
217
218 if (AudioDeviceWindowsCore::CoreAudioIsSupported())
219 {
220 // create *Windows Core Audio* implementation
221 ptrAudioDevice = new AudioDeviceWindowsCore(Id());
222 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
223 }
224 else
225 {
226 // create *Windows Wave Audio* implementation
227 ptrAudioDevice = new AudioDeviceWindowsWave(Id());
228 if (ptrAudioDevice != NULL)
229 {
230 // Core Audio was not supported => revert to Windows Wave instead
231 _platformAudioLayer = kWindowsWaveAudio; // modify the state set at construction
232 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
233 }
234 }
235 }
236#endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000237#endif // #if defined(_WIN32)
238
henrike@webrtc.org9ee75e92013-12-11 21:42:44 +0000239#if defined(WEBRTC_ANDROID)
henrikab2619892015-05-18 16:49:16 +0200240 // Create an Android audio manager.
241 _audioManagerAndroid.reset(new AudioManager());
242 // Select best possible combination of audio layers.
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000243 if (audioLayer == kPlatformDefaultAudio) {
henrikab2619892015-05-18 16:49:16 +0200244 if (_audioManagerAndroid->IsLowLatencyPlayoutSupported()) {
245 // Always use OpenSL ES for output on devices that supports the
246 // low-latency output audio path.
247 audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio;
248 } else {
249 // Use Java-based audio in both directions when low-latency output
250 // is not supported.
251 audioLayer = kAndroidJavaAudio;
252 }
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +0000253 }
henrikab2619892015-05-18 16:49:16 +0200254 AudioManager* audio_manager = _audioManagerAndroid.get();
255 if (audioLayer == kAndroidJavaAudio) {
256 // Java audio for both input and output audio.
257 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(
258 audioLayer, audio_manager);
259 } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) {
260 // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
261 // This combination provides low-latency output audio and at the same
262 // time support for HW AEC using the AudioRecord Java API.
263 ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, OpenSLESPlayer>(
264 audioLayer, audio_manager);
265 } else {
266 // Invalid audio layer.
267 ptrAudioDevice = NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +0000268 }
leozwang@google.com39f20512011-07-15 16:29:40 +0000269 // END #if defined(WEBRTC_ANDROID)
niklase@google.com470e71d2011-07-07 08:21:25 +0000270
271 // Create the *Linux* implementation of the Audio Device
272 //
273#elif defined(WEBRTC_LINUX)
274 if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
275 {
276#if defined(LINUX_PULSE)
277 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
278
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000279 // create *Linux PulseAudio* implementation
280 AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
281 if (pulseDevice->Init() != -1)
niklase@google.com470e71d2011-07-07 08:21:25 +0000282 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000283 ptrAudioDevice = pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000284 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
285 }
286 else
287 {
fischman@webrtc.org7ae84952013-12-10 21:01:34 +0000288 delete pulseDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000289#endif
290#if defined(LINUX_ALSA)
291 // create *Linux ALSA Audio* implementation
292 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
293 if (ptrAudioDevice != NULL)
294 {
295 // Pulse Audio was not supported => revert to ALSA instead
296 _platformAudioLayer = kLinuxAlsaAudio; // modify the state set at construction
297 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
298 }
299#endif
300#if defined(LINUX_PULSE)
301 }
302#endif
303 }
304 else if (audioLayer == kLinuxAlsaAudio)
305 {
306#if defined(LINUX_ALSA)
307 // create *Linux ALSA Audio* implementation
308 ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
309 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
310#endif
311 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000312#endif // #if defined(WEBRTC_LINUX)
313
314 // Create the *iPhone* implementation of the Audio Device
315 //
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000316#if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000317 if (audioLayer == kPlatformDefaultAudio)
318 {
tkchin@webrtc.org122caa52014-07-15 20:20:47 +0000319 // Create iOS Audio Device implementation.
henrikaba35d052015-07-14 17:04:08 +0200320 ptrAudioDevice = new AudioDeviceIOS();
niklase@google.com470e71d2011-07-07 08:21:25 +0000321 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
322 }
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +0000323 // END #if defined(WEBRTC_IOS)
niklase@google.com470e71d2011-07-07 08:21:25 +0000324
325 // Create the *Mac* implementation of the Audio Device
326 //
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000327#elif defined(WEBRTC_MAC)
niklase@google.com470e71d2011-07-07 08:21:25 +0000328 if (audioLayer == kPlatformDefaultAudio)
329 {
330 // Create *Mac Audio* implementation
331 ptrAudioDevice = new AudioDeviceMac(Id());
332 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
333 }
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000334#endif // WEBRTC_MAC
niklase@google.com470e71d2011-07-07 08:21:25 +0000335
336 // Create the *Dummy* implementation of the Audio Device
337 // Available for all platforms
338 //
339 if (audioLayer == kDummyAudio)
340 {
341 // Create *Dummy Audio* implementation
342 assert(!ptrAudioDevice);
343 ptrAudioDevice = new AudioDeviceDummy(Id());
344 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
niklase@google.com470e71d2011-07-07 08:21:25 +0000345 }
xians@google.combf5d2ba2011-08-16 07:44:19 +0000346#endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
niklase@google.com470e71d2011-07-07 08:21:25 +0000347
348 if (ptrAudioDevice == NULL)
349 {
350 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
351 return -1;
352 }
353
niklase@google.com470e71d2011-07-07 08:21:25 +0000354 // Store valid output pointers
355 //
356 _ptrAudioDevice = ptrAudioDevice;
niklase@google.com470e71d2011-07-07 08:21:25 +0000357
358 return 0;
359}
360
361// ----------------------------------------------------------------------------
362// AttachAudioBuffer
363//
364// Install "bridge" between the platform implemetation and the generic
365// implementation. The "child" shall set the native sampling rate and the
366// number of channels in this function call.
367// ----------------------------------------------------------------------------
368
pbos@webrtc.org25509882013-04-09 10:30:35 +0000369int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
niklase@google.com470e71d2011-07-07 08:21:25 +0000370{
371 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
372
373 _audioDeviceBuffer.SetId(_id);
374 _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
375 return 0;
376}
377
378// ----------------------------------------------------------------------------
379// ~AudioDeviceModuleImpl - dtor
380// ----------------------------------------------------------------------------
381
382AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
383{
384 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
henrika@google.com73d65512011-09-07 15:11:18 +0000385
386 if (_ptrAudioDevice)
niklase@google.com470e71d2011-07-07 08:21:25 +0000387 {
henrika@google.com73d65512011-09-07 15:11:18 +0000388 delete _ptrAudioDevice;
389 _ptrAudioDevice = NULL;
390 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000391
niklase@google.com470e71d2011-07-07 08:21:25 +0000392 delete &_critSect;
393 delete &_critSectEventCb;
394 delete &_critSectAudioCb;
395}
396
397// ============================================================================
398// Module
399// ============================================================================
400
401// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000402// Module::TimeUntilNextProcess
403//
404// Returns the number of milliseconds until the module want a worker thread
405// to call Process().
406// ----------------------------------------------------------------------------
407
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000408int64_t AudioDeviceModuleImpl::TimeUntilNextProcess()
niklase@google.com470e71d2011-07-07 08:21:25 +0000409{
Tommi68898a22015-05-19 17:28:07 +0200410 int64_t now = TickTime::MillisecondTimestamp();
411 int64_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
412 return deltaProcess;
niklase@google.com470e71d2011-07-07 08:21:25 +0000413}
414
415// ----------------------------------------------------------------------------
416// Module::Process
417//
418// Check for posted error and warning reports. Generate callbacks if
419// new reports exists.
420// ----------------------------------------------------------------------------
421
pbosa26ac922016-02-25 04:50:01 -0800422void AudioDeviceModuleImpl::Process()
niklase@google.com470e71d2011-07-07 08:21:25 +0000423{
niklase@google.com470e71d2011-07-07 08:21:25 +0000424
Tommi68898a22015-05-19 17:28:07 +0200425 _lastProcessTime = TickTime::MillisecondTimestamp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000426
427 // kPlayoutWarning
428 if (_ptrAudioDevice->PlayoutWarning())
429 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000430 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000431 if (_ptrCbAudioDeviceObserver)
432 {
433 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
434 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
435 }
436 _ptrAudioDevice->ClearPlayoutWarning();
437 }
438
439 // kPlayoutError
440 if (_ptrAudioDevice->PlayoutError())
441 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000442 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000443 if (_ptrCbAudioDeviceObserver)
444 {
445 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
446 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
447 }
448 _ptrAudioDevice->ClearPlayoutError();
449 }
450
451 // kRecordingWarning
452 if (_ptrAudioDevice->RecordingWarning())
453 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000454 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000455 if (_ptrCbAudioDeviceObserver)
456 {
457 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
458 _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
459 }
460 _ptrAudioDevice->ClearRecordingWarning();
461 }
462
463 // kRecordingError
464 if (_ptrAudioDevice->RecordingError())
465 {
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +0000466 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +0000467 if (_ptrCbAudioDeviceObserver)
468 {
469 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
470 _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
471 }
472 _ptrAudioDevice->ClearRecordingError();
473 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000474}
475
476// ============================================================================
477// Public API
478// ============================================================================
479
480// ----------------------------------------------------------------------------
481// ActiveAudioLayer
482// ----------------------------------------------------------------------------
483
henrikab2619892015-05-18 16:49:16 +0200484int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const {
485 AudioLayer activeAudio;
486 if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) {
487 return -1;
488 }
489 *audioLayer = activeAudio;
490 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000491}
492
493// ----------------------------------------------------------------------------
494// LastError
495// ----------------------------------------------------------------------------
496
497AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
498{
499 return _lastError;
500}
501
502// ----------------------------------------------------------------------------
503// Init
504// ----------------------------------------------------------------------------
505
pbos@webrtc.org25509882013-04-09 10:30:35 +0000506int32_t AudioDeviceModuleImpl::Init()
niklase@google.com470e71d2011-07-07 08:21:25 +0000507{
niklase@google.com470e71d2011-07-07 08:21:25 +0000508
509 if (_initialized)
510 return 0;
511
niklase@google.com470e71d2011-07-07 08:21:25 +0000512 if (!_ptrAudioDevice)
513 return -1;
514
niklase@google.com470e71d2011-07-07 08:21:25 +0000515 if (_ptrAudioDevice->Init() == -1)
516 {
517 return -1;
518 }
519
520 _initialized = true;
521 return 0;
522}
523
524// ----------------------------------------------------------------------------
525// Terminate
526// ----------------------------------------------------------------------------
527
pbos@webrtc.org25509882013-04-09 10:30:35 +0000528int32_t AudioDeviceModuleImpl::Terminate()
niklase@google.com470e71d2011-07-07 08:21:25 +0000529{
niklase@google.com470e71d2011-07-07 08:21:25 +0000530
531 if (!_initialized)
532 return 0;
533
534 if (_ptrAudioDevice->Terminate() == -1)
535 {
536 return -1;
537 }
538
539 _initialized = false;
540 return 0;
541}
542
543// ----------------------------------------------------------------------------
544// Initialized
545// ----------------------------------------------------------------------------
546
547bool AudioDeviceModuleImpl::Initialized() const
548{
niklase@google.com470e71d2011-07-07 08:21:25 +0000549
550 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
551 return (_initialized);
552}
553
554// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000555// InitSpeaker
556// ----------------------------------------------------------------------------
557
pbos@webrtc.org25509882013-04-09 10:30:35 +0000558int32_t AudioDeviceModuleImpl::InitSpeaker()
niklase@google.com470e71d2011-07-07 08:21:25 +0000559{
niklase@google.com470e71d2011-07-07 08:21:25 +0000560 CHECK_INITIALIZED();
561 return (_ptrAudioDevice->InitSpeaker());
562}
563
564// ----------------------------------------------------------------------------
niklase@google.com470e71d2011-07-07 08:21:25 +0000565// InitMicrophone
566// ----------------------------------------------------------------------------
567
pbos@webrtc.org25509882013-04-09 10:30:35 +0000568int32_t AudioDeviceModuleImpl::InitMicrophone()
niklase@google.com470e71d2011-07-07 08:21:25 +0000569{
niklase@google.com470e71d2011-07-07 08:21:25 +0000570 CHECK_INITIALIZED();
571 return (_ptrAudioDevice->InitMicrophone());
572}
573
574// ----------------------------------------------------------------------------
575// SpeakerVolumeIsAvailable
576// ----------------------------------------------------------------------------
577
pbos@webrtc.org25509882013-04-09 10:30:35 +0000578int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000579{
niklase@google.com470e71d2011-07-07 08:21:25 +0000580 CHECK_INITIALIZED();
581
582 bool isAvailable(0);
583
584 if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
585 {
586 return -1;
587 }
588
589 *available = isAvailable;
590
591 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
592 return (0);
593}
594
595// ----------------------------------------------------------------------------
596// SetSpeakerVolume
597// ----------------------------------------------------------------------------
598
pbos@webrtc.org25509882013-04-09 10:30:35 +0000599int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000600{
niklase@google.com470e71d2011-07-07 08:21:25 +0000601 CHECK_INITIALIZED();
602 return (_ptrAudioDevice->SetSpeakerVolume(volume));
603}
604
605// ----------------------------------------------------------------------------
606// SpeakerVolume
607// ----------------------------------------------------------------------------
608
pbos@webrtc.org25509882013-04-09 10:30:35 +0000609int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000610{
niklase@google.com470e71d2011-07-07 08:21:25 +0000611 CHECK_INITIALIZED();
612
pbos@webrtc.org25509882013-04-09 10:30:35 +0000613 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000614
615 if (_ptrAudioDevice->SpeakerVolume(level) == -1)
616 {
617 return -1;
618 }
619
620 *volume = level;
621
622 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
623 return (0);
624}
625
626// ----------------------------------------------------------------------------
627// SetWaveOutVolume
628// ----------------------------------------------------------------------------
629
pbos@webrtc.org25509882013-04-09 10:30:35 +0000630int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
niklase@google.com470e71d2011-07-07 08:21:25 +0000631{
niklase@google.com470e71d2011-07-07 08:21:25 +0000632 CHECK_INITIALIZED();
633 return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
634}
635
636// ----------------------------------------------------------------------------
637// WaveOutVolume
638// ----------------------------------------------------------------------------
639
pbos@webrtc.org25509882013-04-09 10:30:35 +0000640int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000641{
niklase@google.com470e71d2011-07-07 08:21:25 +0000642 CHECK_INITIALIZED();
643
pbos@webrtc.org25509882013-04-09 10:30:35 +0000644 uint16_t volLeft(0);
645 uint16_t volRight(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000646
647 if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
648 {
649 return -1;
650 }
651
652 *volumeLeft = volLeft;
653 *volumeRight = volRight;
654
655 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
656 *volumeLeft, *volumeRight);
657
658 return (0);
659}
660
661// ----------------------------------------------------------------------------
662// SpeakerIsInitialized
663// ----------------------------------------------------------------------------
664
665bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
666{
niklase@google.com470e71d2011-07-07 08:21:25 +0000667 CHECK_INITIALIZED_BOOL();
668
669 bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
670
671 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
672 return (isInitialized);
673}
674
675// ----------------------------------------------------------------------------
676// MicrophoneIsInitialized
677// ----------------------------------------------------------------------------
678
679bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
680{
niklase@google.com470e71d2011-07-07 08:21:25 +0000681 CHECK_INITIALIZED_BOOL();
682
683 bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
684
685 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
686 return (isInitialized);
687}
688
689// ----------------------------------------------------------------------------
690// MaxSpeakerVolume
691// ----------------------------------------------------------------------------
692
pbos@webrtc.org25509882013-04-09 10:30:35 +0000693int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) 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 maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000698
699 if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
700 {
701 return -1;
702 }
703
704 *maxVolume = maxVol;
705
706 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
707 return (0);
708}
709
710// ----------------------------------------------------------------------------
711// MinSpeakerVolume
712// ----------------------------------------------------------------------------
713
pbos@webrtc.org25509882013-04-09 10:30:35 +0000714int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000715{
niklase@google.com470e71d2011-07-07 08:21:25 +0000716 CHECK_INITIALIZED();
717
pbos@webrtc.org25509882013-04-09 10:30:35 +0000718 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000719
720 if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
721 {
722 return -1;
723 }
724
725 *minVolume = minVol;
726
727 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
728 return (0);
729}
730
731// ----------------------------------------------------------------------------
732// SpeakerVolumeStepSize
733// ----------------------------------------------------------------------------
734
pbos@webrtc.org25509882013-04-09 10:30:35 +0000735int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000736{
niklase@google.com470e71d2011-07-07 08:21:25 +0000737 CHECK_INITIALIZED();
738
pbos@webrtc.org25509882013-04-09 10:30:35 +0000739 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000740
741 if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
742 {
743 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
744 return -1;
745 }
746
747 *stepSize = delta;
748
749 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
750 return (0);
751}
752
753// ----------------------------------------------------------------------------
754// SpeakerMuteIsAvailable
755// ----------------------------------------------------------------------------
756
pbos@webrtc.org25509882013-04-09 10:30:35 +0000757int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000758{
niklase@google.com470e71d2011-07-07 08:21:25 +0000759 CHECK_INITIALIZED();
760
761 bool isAvailable(0);
762
763 if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1)
764 {
765 return -1;
766 }
767
768 *available = isAvailable;
769
770 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
771 return (0);
772}
773
774// ----------------------------------------------------------------------------
775// SetSpeakerMute
776// ----------------------------------------------------------------------------
777
pbos@webrtc.org25509882013-04-09 10:30:35 +0000778int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000779{
niklase@google.com470e71d2011-07-07 08:21:25 +0000780 CHECK_INITIALIZED();
781 return (_ptrAudioDevice->SetSpeakerMute(enable));
782}
783
784// ----------------------------------------------------------------------------
785// SpeakerMute
786// ----------------------------------------------------------------------------
787
pbos@webrtc.org25509882013-04-09 10:30:35 +0000788int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000789{
niklase@google.com470e71d2011-07-07 08:21:25 +0000790 CHECK_INITIALIZED();
791
792 bool muted(false);
793
794 if (_ptrAudioDevice->SpeakerMute(muted) == -1)
795 {
796 return -1;
797 }
798
799 *enabled = muted;
800
801 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
802 return (0);
803}
804
805// ----------------------------------------------------------------------------
806// MicrophoneMuteIsAvailable
807// ----------------------------------------------------------------------------
808
pbos@webrtc.org25509882013-04-09 10:30:35 +0000809int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000810{
niklase@google.com470e71d2011-07-07 08:21:25 +0000811 CHECK_INITIALIZED();
812
813 bool isAvailable(0);
814
815 if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1)
816 {
817 return -1;
818 }
819
820 *available = isAvailable;
821
822 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
823 return (0);
824}
825
826// ----------------------------------------------------------------------------
827// SetMicrophoneMute
828// ----------------------------------------------------------------------------
829
pbos@webrtc.org25509882013-04-09 10:30:35 +0000830int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000831{
niklase@google.com470e71d2011-07-07 08:21:25 +0000832 CHECK_INITIALIZED();
833 return (_ptrAudioDevice->SetMicrophoneMute(enable));
834}
835
836// ----------------------------------------------------------------------------
837// MicrophoneMute
838// ----------------------------------------------------------------------------
839
pbos@webrtc.org25509882013-04-09 10:30:35 +0000840int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000841{
niklase@google.com470e71d2011-07-07 08:21:25 +0000842 CHECK_INITIALIZED();
843
844 bool muted(false);
845
846 if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
847 {
848 return -1;
849 }
850
851 *enabled = muted;
852
853 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
854 return (0);
855}
856
857// ----------------------------------------------------------------------------
858// MicrophoneBoostIsAvailable
859// ----------------------------------------------------------------------------
860
pbos@webrtc.org25509882013-04-09 10:30:35 +0000861int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000862{
niklase@google.com470e71d2011-07-07 08:21:25 +0000863 CHECK_INITIALIZED();
864
865 bool isAvailable(0);
866
867 if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
868 {
869 return -1;
870 }
871
872 *available = isAvailable;
873
874 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
875 return (0);
876}
877
878// ----------------------------------------------------------------------------
879// SetMicrophoneBoost
880// ----------------------------------------------------------------------------
881
pbos@webrtc.org25509882013-04-09 10:30:35 +0000882int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000883{
niklase@google.com470e71d2011-07-07 08:21:25 +0000884 CHECK_INITIALIZED();
885 return (_ptrAudioDevice->SetMicrophoneBoost(enable));
886}
887
888// ----------------------------------------------------------------------------
889// MicrophoneBoost
890// ----------------------------------------------------------------------------
891
pbos@webrtc.org25509882013-04-09 10:30:35 +0000892int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000893{
niklase@google.com470e71d2011-07-07 08:21:25 +0000894 CHECK_INITIALIZED();
895
896 bool onOff(false);
897
898 if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
899 {
900 return -1;
901 }
902
903 *enabled = onOff;
904
905 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
906 return (0);
907}
908
909// ----------------------------------------------------------------------------
910// MicrophoneVolumeIsAvailable
911// ----------------------------------------------------------------------------
912
pbos@webrtc.org25509882013-04-09 10:30:35 +0000913int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +0000914{
niklase@google.com470e71d2011-07-07 08:21:25 +0000915 CHECK_INITIALIZED();
916
917 bool isAvailable(0);
918
919 if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
920 {
921 return -1;
922 }
923
924 *available = isAvailable;
925
926 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
927 return (0);
928}
929
930// ----------------------------------------------------------------------------
931// SetMicrophoneVolume
932// ----------------------------------------------------------------------------
933
pbos@webrtc.org25509882013-04-09 10:30:35 +0000934int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
niklase@google.com470e71d2011-07-07 08:21:25 +0000935{
niklase@google.com470e71d2011-07-07 08:21:25 +0000936 CHECK_INITIALIZED();
937 return (_ptrAudioDevice->SetMicrophoneVolume(volume));
938}
939
940// ----------------------------------------------------------------------------
941// MicrophoneVolume
942// ----------------------------------------------------------------------------
943
pbos@webrtc.org25509882013-04-09 10:30:35 +0000944int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000945{
946 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
947 CHECK_INITIALIZED();
948
pbos@webrtc.org25509882013-04-09 10:30:35 +0000949 uint32_t level(0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000950
951 if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
952 {
953 return -1;
954 }
955
956 *volume = level;
957
958 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
959 return (0);
960}
961
962// ----------------------------------------------------------------------------
963// StereoRecordingIsAvailable
964// ----------------------------------------------------------------------------
965
pbos@webrtc.org25509882013-04-09 10:30:35 +0000966int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +0000967{
niklase@google.com470e71d2011-07-07 08:21:25 +0000968 CHECK_INITIALIZED();
969
970 bool isAvailable(0);
971
972 if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
973 {
974 return -1;
975 }
976
977 *available = isAvailable;
978
979 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
980 return (0);
981}
982
983// ----------------------------------------------------------------------------
984// SetStereoRecording
985// ----------------------------------------------------------------------------
986
pbos@webrtc.org25509882013-04-09 10:30:35 +0000987int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +0000988{
niklase@google.com470e71d2011-07-07 08:21:25 +0000989 CHECK_INITIALIZED();
990
991 if (_ptrAudioDevice->RecordingIsInitialized())
992 {
993 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
994 return -1;
995 }
996
997 if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
998 {
999 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1000 return -1;
1001 }
1002
pbos@webrtc.org25509882013-04-09 10:30:35 +00001003 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001004 if (enable)
1005 {
1006 nChannels = 2;
1007 }
1008 _audioDeviceBuffer.SetRecordingChannels(nChannels);
1009
1010 return 0;
1011}
1012
1013// ----------------------------------------------------------------------------
1014// StereoRecording
1015// ----------------------------------------------------------------------------
1016
pbos@webrtc.org25509882013-04-09 10:30:35 +00001017int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001018{
niklase@google.com470e71d2011-07-07 08:21:25 +00001019 CHECK_INITIALIZED();
1020
1021 bool stereo(false);
1022
1023 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1024 {
1025 return -1;
1026 }
1027
1028 *enabled = stereo;
1029
1030 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1031 return (0);
1032}
1033
1034// ----------------------------------------------------------------------------
1035// SetRecordingChannel
1036// ----------------------------------------------------------------------------
1037
pbos@webrtc.org25509882013-04-09 10:30:35 +00001038int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
niklase@google.com470e71d2011-07-07 08:21:25 +00001039{
1040 if (channel == kChannelBoth)
1041 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001042 }
1043 else if (channel == kChannelLeft)
1044 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001045 }
1046 else
1047 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001048 }
1049 CHECK_INITIALIZED();
1050
1051 bool stereo(false);
1052
1053 if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1054 {
1055 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1056 return -1;
1057 }
1058
1059 return (_audioDeviceBuffer.SetRecordingChannel(channel));
1060}
1061
1062// ----------------------------------------------------------------------------
1063// RecordingChannel
1064// ----------------------------------------------------------------------------
1065
pbos@webrtc.org25509882013-04-09 10:30:35 +00001066int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001067{
niklase@google.com470e71d2011-07-07 08:21:25 +00001068 CHECK_INITIALIZED();
1069
1070 ChannelType chType;
1071
1072 if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1073 {
1074 return -1;
1075 }
1076
1077 *channel = chType;
1078
1079 if (*channel == kChannelBoth)
1080 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001081 }
1082 else if (*channel == kChannelLeft)
1083 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001084 }
1085 else
1086 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001087 }
1088
1089 return (0);
1090}
1091
1092// ----------------------------------------------------------------------------
1093// StereoPlayoutIsAvailable
1094// ----------------------------------------------------------------------------
1095
pbos@webrtc.org25509882013-04-09 10:30:35 +00001096int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001097{
niklase@google.com470e71d2011-07-07 08:21:25 +00001098 CHECK_INITIALIZED();
1099
1100 bool isAvailable(0);
1101
1102 if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1103 {
1104 return -1;
1105 }
1106
1107 *available = isAvailable;
1108
1109 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1110 return (0);
1111}
1112
1113// ----------------------------------------------------------------------------
1114// SetStereoPlayout
1115// ----------------------------------------------------------------------------
1116
pbos@webrtc.org25509882013-04-09 10:30:35 +00001117int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001118{
niklase@google.com470e71d2011-07-07 08:21:25 +00001119 CHECK_INITIALIZED();
1120
1121 if (_ptrAudioDevice->PlayoutIsInitialized())
1122 {
1123 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1124 return -1;
1125 }
1126
1127 if (_ptrAudioDevice->SetStereoPlayout(enable))
1128 {
1129 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1130 return -1;
1131 }
1132
pbos@webrtc.org25509882013-04-09 10:30:35 +00001133 int8_t nChannels(1);
niklase@google.com470e71d2011-07-07 08:21:25 +00001134 if (enable)
1135 {
1136 nChannels = 2;
1137 }
1138 _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1139
1140 return 0;
1141}
1142
1143// ----------------------------------------------------------------------------
1144// StereoPlayout
1145// ----------------------------------------------------------------------------
1146
pbos@webrtc.org25509882013-04-09 10:30:35 +00001147int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001148{
niklase@google.com470e71d2011-07-07 08:21:25 +00001149 CHECK_INITIALIZED();
1150
1151 bool stereo(false);
1152
1153 if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1154 {
1155 return -1;
1156 }
1157
1158 *enabled = stereo;
1159
1160 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1161 return (0);
1162}
1163
1164// ----------------------------------------------------------------------------
1165// SetAGC
1166// ----------------------------------------------------------------------------
1167
pbos@webrtc.org25509882013-04-09 10:30:35 +00001168int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001169{
niklase@google.com470e71d2011-07-07 08:21:25 +00001170 CHECK_INITIALIZED();
1171 return (_ptrAudioDevice->SetAGC(enable));
1172}
1173
1174// ----------------------------------------------------------------------------
1175// AGC
1176// ----------------------------------------------------------------------------
1177
1178bool AudioDeviceModuleImpl::AGC() const
1179{
niklase@google.com470e71d2011-07-07 08:21:25 +00001180 CHECK_INITIALIZED_BOOL();
1181 return (_ptrAudioDevice->AGC());
1182}
1183
1184// ----------------------------------------------------------------------------
1185// PlayoutIsAvailable
1186// ----------------------------------------------------------------------------
1187
pbos@webrtc.org25509882013-04-09 10:30:35 +00001188int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001189{
niklase@google.com470e71d2011-07-07 08:21:25 +00001190 CHECK_INITIALIZED();
1191
1192 bool isAvailable(0);
1193
1194 if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1195 {
1196 return -1;
1197 }
1198
1199 *available = isAvailable;
1200
1201 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1202 return (0);
1203}
1204
1205// ----------------------------------------------------------------------------
1206// RecordingIsAvailable
1207// ----------------------------------------------------------------------------
1208
pbos@webrtc.org25509882013-04-09 10:30:35 +00001209int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
niklase@google.com470e71d2011-07-07 08:21:25 +00001210{
niklase@google.com470e71d2011-07-07 08:21:25 +00001211 CHECK_INITIALIZED();
1212
1213 bool isAvailable(0);
1214
1215 if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1216 {
1217 return -1;
1218 }
1219
1220 *available = isAvailable;
1221
1222 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1223 return (0);
1224}
1225
1226// ----------------------------------------------------------------------------
1227// MaxMicrophoneVolume
1228// ----------------------------------------------------------------------------
1229
pbos@webrtc.org25509882013-04-09 10:30:35 +00001230int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001231{
1232 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1233 CHECK_INITIALIZED();
1234
pbos@webrtc.org25509882013-04-09 10:30:35 +00001235 uint32_t maxVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001236
1237 if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1238 {
1239 return -1;
1240 }
1241
1242 *maxVolume = maxVol;
1243
1244 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1245 return (0);
1246}
1247
1248// ----------------------------------------------------------------------------
1249// MinMicrophoneVolume
1250// ----------------------------------------------------------------------------
1251
pbos@webrtc.org25509882013-04-09 10:30:35 +00001252int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001253{
niklase@google.com470e71d2011-07-07 08:21:25 +00001254 CHECK_INITIALIZED();
1255
pbos@webrtc.org25509882013-04-09 10:30:35 +00001256 uint32_t minVol(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001257
1258 if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1259 {
1260 return -1;
1261 }
1262
1263 *minVolume = minVol;
1264
1265 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1266 return (0);
1267}
1268
1269// ----------------------------------------------------------------------------
1270// MicrophoneVolumeStepSize
1271// ----------------------------------------------------------------------------
1272
pbos@webrtc.org25509882013-04-09 10:30:35 +00001273int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001274{
niklase@google.com470e71d2011-07-07 08:21:25 +00001275 CHECK_INITIALIZED();
1276
pbos@webrtc.org25509882013-04-09 10:30:35 +00001277 uint16_t delta(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001278
1279 if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1280 {
1281 return -1;
1282 }
1283
1284 *stepSize = delta;
1285
1286 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1287 return (0);
1288}
1289
1290// ----------------------------------------------------------------------------
1291// PlayoutDevices
1292// ----------------------------------------------------------------------------
1293
pbos@webrtc.org25509882013-04-09 10:30:35 +00001294int16_t AudioDeviceModuleImpl::PlayoutDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001295{
niklase@google.com470e71d2011-07-07 08:21:25 +00001296 CHECK_INITIALIZED();
1297
pbos@webrtc.org25509882013-04-09 10:30:35 +00001298 uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001299
1300 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001301 return ((int16_t)(nPlayoutDevices));
niklase@google.com470e71d2011-07-07 08:21:25 +00001302}
1303
1304// ----------------------------------------------------------------------------
1305// SetPlayoutDevice I (II)
1306// ----------------------------------------------------------------------------
1307
pbos@webrtc.org25509882013-04-09 10:30:35 +00001308int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001309{
niklase@google.com470e71d2011-07-07 08:21:25 +00001310 CHECK_INITIALIZED();
1311 return (_ptrAudioDevice->SetPlayoutDevice(index));
1312}
1313
1314// ----------------------------------------------------------------------------
1315// SetPlayoutDevice II (II)
1316// ----------------------------------------------------------------------------
1317
pbos@webrtc.org25509882013-04-09 10:30:35 +00001318int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001319{
1320 if (device == kDefaultDevice)
1321 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001322 }
1323 else
1324 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001325 }
1326 CHECK_INITIALIZED();
1327
1328 return (_ptrAudioDevice->SetPlayoutDevice(device));
1329}
1330
1331// ----------------------------------------------------------------------------
1332// PlayoutDeviceName
1333// ----------------------------------------------------------------------------
1334
pbos@webrtc.org25509882013-04-09 10:30:35 +00001335int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1336 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001337 char name[kAdmMaxDeviceNameSize],
1338 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001339{
niklase@google.com470e71d2011-07-07 08:21:25 +00001340 CHECK_INITIALIZED();
1341
1342 if (name == NULL)
1343 {
1344 _lastError = kAdmErrArgument;
1345 return -1;
1346 }
1347
1348 if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1349 {
1350 return -1;
1351 }
1352
1353 if (name != NULL)
1354 {
1355 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1356 }
1357 if (guid != NULL)
1358 {
1359 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1360 }
1361
1362 return (0);
1363}
1364
1365// ----------------------------------------------------------------------------
1366// RecordingDeviceName
1367// ----------------------------------------------------------------------------
1368
pbos@webrtc.org25509882013-04-09 10:30:35 +00001369int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1370 uint16_t index,
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001371 char name[kAdmMaxDeviceNameSize],
1372 char guid[kAdmMaxGuidSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001373{
niklase@google.com470e71d2011-07-07 08:21:25 +00001374 CHECK_INITIALIZED();
1375
1376 if (name == NULL)
1377 {
1378 _lastError = kAdmErrArgument;
1379 return -1;
1380 }
1381
1382 if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1383 {
1384 return -1;
1385 }
1386
1387 if (name != NULL)
1388 {
1389 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1390 }
1391 if (guid != NULL)
1392 {
1393 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1394 }
1395
1396 return (0);
1397}
1398
1399// ----------------------------------------------------------------------------
1400// RecordingDevices
1401// ----------------------------------------------------------------------------
1402
pbos@webrtc.org25509882013-04-09 10:30:35 +00001403int16_t AudioDeviceModuleImpl::RecordingDevices()
niklase@google.com470e71d2011-07-07 08:21:25 +00001404{
niklase@google.com470e71d2011-07-07 08:21:25 +00001405 CHECK_INITIALIZED();
1406
pbos@webrtc.org25509882013-04-09 10:30:35 +00001407 uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +00001408
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001409 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1410 "output: #recording devices=%d", nRecordingDevices);
pbos@webrtc.org25509882013-04-09 10:30:35 +00001411 return ((int16_t)nRecordingDevices);
niklase@google.com470e71d2011-07-07 08:21:25 +00001412}
1413
1414// ----------------------------------------------------------------------------
1415// SetRecordingDevice I (II)
1416// ----------------------------------------------------------------------------
1417
pbos@webrtc.org25509882013-04-09 10:30:35 +00001418int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
niklase@google.com470e71d2011-07-07 08:21:25 +00001419{
niklase@google.com470e71d2011-07-07 08:21:25 +00001420 CHECK_INITIALIZED();
1421 return (_ptrAudioDevice->SetRecordingDevice(index));
1422}
1423
1424// ----------------------------------------------------------------------------
1425// SetRecordingDevice II (II)
1426// ----------------------------------------------------------------------------
1427
pbos@webrtc.org25509882013-04-09 10:30:35 +00001428int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
niklase@google.com470e71d2011-07-07 08:21:25 +00001429{
1430 if (device == kDefaultDevice)
1431 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001432 }
1433 else
1434 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001435 }
1436 CHECK_INITIALIZED();
1437
1438 return (_ptrAudioDevice->SetRecordingDevice(device));
1439}
1440
1441// ----------------------------------------------------------------------------
1442// InitPlayout
1443// ----------------------------------------------------------------------------
1444
pbos@webrtc.org25509882013-04-09 10:30:35 +00001445int32_t AudioDeviceModuleImpl::InitPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001446{
niklase@google.com470e71d2011-07-07 08:21:25 +00001447 CHECK_INITIALIZED();
1448 _audioDeviceBuffer.InitPlayout();
1449 return (_ptrAudioDevice->InitPlayout());
1450}
1451
1452// ----------------------------------------------------------------------------
1453// InitRecording
1454// ----------------------------------------------------------------------------
1455
pbos@webrtc.org25509882013-04-09 10:30:35 +00001456int32_t AudioDeviceModuleImpl::InitRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001457{
Peter Boströmdda52b92016-04-11 16:04:33 +02001458 TRACE_EVENT0("webrtc", "AudioDeviceModuleImpl::InitRecording");
niklase@google.com470e71d2011-07-07 08:21:25 +00001459 CHECK_INITIALIZED();
1460 _audioDeviceBuffer.InitRecording();
1461 return (_ptrAudioDevice->InitRecording());
1462}
1463
1464// ----------------------------------------------------------------------------
1465// PlayoutIsInitialized
1466// ----------------------------------------------------------------------------
1467
1468bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1469{
niklase@google.com470e71d2011-07-07 08:21:25 +00001470 CHECK_INITIALIZED_BOOL();
1471 return (_ptrAudioDevice->PlayoutIsInitialized());
1472}
1473
1474// ----------------------------------------------------------------------------
1475// RecordingIsInitialized
1476// ----------------------------------------------------------------------------
1477
1478bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1479{
niklase@google.com470e71d2011-07-07 08:21:25 +00001480 CHECK_INITIALIZED_BOOL();
1481 return (_ptrAudioDevice->RecordingIsInitialized());
1482}
1483
1484// ----------------------------------------------------------------------------
1485// StartPlayout
1486// ----------------------------------------------------------------------------
1487
pbos@webrtc.org25509882013-04-09 10:30:35 +00001488int32_t AudioDeviceModuleImpl::StartPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001489{
niklase@google.com470e71d2011-07-07 08:21:25 +00001490 CHECK_INITIALIZED();
1491 return (_ptrAudioDevice->StartPlayout());
1492}
1493
1494// ----------------------------------------------------------------------------
1495// StopPlayout
1496// ----------------------------------------------------------------------------
1497
pbos@webrtc.org25509882013-04-09 10:30:35 +00001498int32_t AudioDeviceModuleImpl::StopPlayout()
niklase@google.com470e71d2011-07-07 08:21:25 +00001499{
niklase@google.com470e71d2011-07-07 08:21:25 +00001500 CHECK_INITIALIZED();
1501 return (_ptrAudioDevice->StopPlayout());
1502}
1503
1504// ----------------------------------------------------------------------------
1505// Playing
1506// ----------------------------------------------------------------------------
1507
1508bool AudioDeviceModuleImpl::Playing() const
1509{
niklase@google.com470e71d2011-07-07 08:21:25 +00001510 CHECK_INITIALIZED_BOOL();
1511 return (_ptrAudioDevice->Playing());
1512}
1513
1514// ----------------------------------------------------------------------------
1515// StartRecording
1516// ----------------------------------------------------------------------------
1517
pbos@webrtc.org25509882013-04-09 10:30:35 +00001518int32_t AudioDeviceModuleImpl::StartRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001519{
Peter Boströmdda52b92016-04-11 16:04:33 +02001520 TRACE_EVENT0("webrtc", "AudioDeviceModuleImpl::StartRecording");
niklase@google.com470e71d2011-07-07 08:21:25 +00001521 CHECK_INITIALIZED();
1522 return (_ptrAudioDevice->StartRecording());
1523}
1524// ----------------------------------------------------------------------------
1525// StopRecording
1526// ----------------------------------------------------------------------------
1527
pbos@webrtc.org25509882013-04-09 10:30:35 +00001528int32_t AudioDeviceModuleImpl::StopRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001529{
niklase@google.com470e71d2011-07-07 08:21:25 +00001530 CHECK_INITIALIZED();
1531 return (_ptrAudioDevice->StopRecording());
1532}
1533
1534// ----------------------------------------------------------------------------
1535// Recording
1536// ----------------------------------------------------------------------------
1537
1538bool AudioDeviceModuleImpl::Recording() const
1539{
niklase@google.com470e71d2011-07-07 08:21:25 +00001540 CHECK_INITIALIZED_BOOL();
1541 return (_ptrAudioDevice->Recording());
1542}
1543
1544// ----------------------------------------------------------------------------
1545// RegisterEventObserver
1546// ----------------------------------------------------------------------------
1547
pbos@webrtc.org25509882013-04-09 10:30:35 +00001548int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001549{
niklase@google.com470e71d2011-07-07 08:21:25 +00001550
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001551 CriticalSectionScoped lock(&_critSectEventCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001552 _ptrCbAudioDeviceObserver = eventCallback;
1553
1554 return 0;
1555}
1556
1557// ----------------------------------------------------------------------------
1558// RegisterAudioCallback
1559// ----------------------------------------------------------------------------
1560
pbos@webrtc.org25509882013-04-09 10:30:35 +00001561int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
niklase@google.com470e71d2011-07-07 08:21:25 +00001562{
niklase@google.com470e71d2011-07-07 08:21:25 +00001563
mflodman@webrtc.orga014ecc2012-04-12 12:15:51 +00001564 CriticalSectionScoped lock(&_critSectAudioCb);
niklase@google.com470e71d2011-07-07 08:21:25 +00001565 _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1566
1567 return 0;
1568}
1569
1570// ----------------------------------------------------------------------------
1571// StartRawInputFileRecording
1572// ----------------------------------------------------------------------------
1573
pbos@webrtc.org25509882013-04-09 10:30:35 +00001574int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001575 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001576{
niklase@google.com470e71d2011-07-07 08:21:25 +00001577 CHECK_INITIALIZED();
1578
1579 if (NULL == pcmFileNameUTF8)
1580 {
1581 return -1;
1582 }
1583
1584 return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1585}
1586
1587// ----------------------------------------------------------------------------
1588// StopRawInputFileRecording
1589// ----------------------------------------------------------------------------
1590
pbos@webrtc.org25509882013-04-09 10:30:35 +00001591int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001592{
niklase@google.com470e71d2011-07-07 08:21:25 +00001593 CHECK_INITIALIZED();
1594
1595 return (_audioDeviceBuffer.StopInputFileRecording());
1596}
1597
1598// ----------------------------------------------------------------------------
1599// StartRawOutputFileRecording
1600// ----------------------------------------------------------------------------
1601
pbos@webrtc.org25509882013-04-09 10:30:35 +00001602int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
leozwang@webrtc.org28f39132012-03-01 18:01:48 +00001603 const char pcmFileNameUTF8[kAdmMaxFileNameSize])
niklase@google.com470e71d2011-07-07 08:21:25 +00001604{
niklase@google.com470e71d2011-07-07 08:21:25 +00001605 CHECK_INITIALIZED();
1606
1607 if (NULL == pcmFileNameUTF8)
1608 {
1609 return -1;
1610 }
1611
1612 return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1613}
1614
1615// ----------------------------------------------------------------------------
1616// StopRawOutputFileRecording
1617// ----------------------------------------------------------------------------
1618
pbos@webrtc.org25509882013-04-09 10:30:35 +00001619int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
niklase@google.com470e71d2011-07-07 08:21:25 +00001620{
niklase@google.com470e71d2011-07-07 08:21:25 +00001621 CHECK_INITIALIZED();
1622
1623 return (_audioDeviceBuffer.StopOutputFileRecording());
niklase@google.com470e71d2011-07-07 08:21:25 +00001624}
1625
1626// ----------------------------------------------------------------------------
1627// SetPlayoutBuffer
1628// ----------------------------------------------------------------------------
1629
pbos@webrtc.org25509882013-04-09 10:30:35 +00001630int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
niklase@google.com470e71d2011-07-07 08:21:25 +00001631{
niklase@google.com470e71d2011-07-07 08:21:25 +00001632 CHECK_INITIALIZED();
1633
1634 if (_ptrAudioDevice->PlayoutIsInitialized())
1635 {
1636 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1637 return -1;
1638 }
1639
pbos@webrtc.org25509882013-04-09 10:30:35 +00001640 int32_t ret(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001641
1642 if (kFixedBufferSize == type)
1643 {
1644 if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1645 {
1646 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1647 return -1;
1648 }
1649 }
1650
1651 if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1652 {
1653 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1654 }
1655
1656 return ret;
1657}
1658
1659// ----------------------------------------------------------------------------
1660// PlayoutBuffer
1661// ----------------------------------------------------------------------------
1662
pbos@webrtc.org25509882013-04-09 10:30:35 +00001663int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001664{
niklase@google.com470e71d2011-07-07 08:21:25 +00001665 CHECK_INITIALIZED();
1666
1667 BufferType bufType;
pbos@webrtc.org25509882013-04-09 10:30:35 +00001668 uint16_t size(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001669
1670 if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1671 {
1672 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1673 return -1;
1674 }
1675
1676 *type = bufType;
1677 *sizeMS = size;
1678
1679 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1680 return (0);
1681}
1682
1683// ----------------------------------------------------------------------------
1684// PlayoutDelay
1685// ----------------------------------------------------------------------------
1686
pbos@webrtc.org25509882013-04-09 10:30:35 +00001687int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001688{
1689 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1690 CHECK_INITIALIZED();
1691
pbos@webrtc.org25509882013-04-09 10:30:35 +00001692 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001693
1694 if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1695 {
1696 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1697 return -1;
1698 }
1699
1700 *delayMS = delay;
1701
1702 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1703 return (0);
1704}
1705
1706// ----------------------------------------------------------------------------
1707// RecordingDelay
1708// ----------------------------------------------------------------------------
1709
pbos@webrtc.org25509882013-04-09 10:30:35 +00001710int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001711{
1712 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1713 CHECK_INITIALIZED();
1714
pbos@webrtc.org25509882013-04-09 10:30:35 +00001715 uint16_t delay(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001716
1717 if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1718 {
1719 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1720 return -1;
1721 }
1722
1723 *delayMS = delay;
1724
1725 WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1726 return (0);
1727}
1728
1729// ----------------------------------------------------------------------------
1730// CPULoad
1731// ----------------------------------------------------------------------------
1732
pbos@webrtc.org25509882013-04-09 10:30:35 +00001733int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001734{
niklase@google.com470e71d2011-07-07 08:21:25 +00001735 CHECK_INITIALIZED();
1736
pbos@webrtc.org25509882013-04-09 10:30:35 +00001737 uint16_t cpuLoad(0);
niklase@google.com470e71d2011-07-07 08:21:25 +00001738
1739 if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1740 {
1741 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1742 return -1;
1743 }
1744
1745 *load = cpuLoad;
1746
1747 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1748 return (0);
1749}
1750
1751// ----------------------------------------------------------------------------
1752// SetRecordingSampleRate
1753// ----------------------------------------------------------------------------
1754
pbos@webrtc.org25509882013-04-09 10:30:35 +00001755int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001756{
niklase@google.com470e71d2011-07-07 08:21:25 +00001757 CHECK_INITIALIZED();
1758
1759 if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1760 {
1761 return -1;
1762 }
1763
1764 return (0);
1765}
1766
1767// ----------------------------------------------------------------------------
1768// RecordingSampleRate
1769// ----------------------------------------------------------------------------
1770
pbos@webrtc.org25509882013-04-09 10:30:35 +00001771int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001772{
niklase@google.com470e71d2011-07-07 08:21:25 +00001773 CHECK_INITIALIZED();
1774
pbos@webrtc.org25509882013-04-09 10:30:35 +00001775 int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001776
1777 if (sampleRate == -1)
1778 {
1779 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1780 return -1;
1781 }
1782
1783 *samplesPerSec = sampleRate;
1784
1785 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1786 return (0);
1787}
1788
1789// ----------------------------------------------------------------------------
1790// SetPlayoutSampleRate
1791// ----------------------------------------------------------------------------
1792
pbos@webrtc.org25509882013-04-09 10:30:35 +00001793int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
niklase@google.com470e71d2011-07-07 08:21:25 +00001794{
niklase@google.com470e71d2011-07-07 08:21:25 +00001795 CHECK_INITIALIZED();
1796
1797 if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1798 {
1799 return -1;
1800 }
1801
1802 return (0);
1803}
1804
1805// ----------------------------------------------------------------------------
1806// PlayoutSampleRate
1807// ----------------------------------------------------------------------------
1808
pbos@webrtc.org25509882013-04-09 10:30:35 +00001809int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
niklase@google.com470e71d2011-07-07 08:21:25 +00001810{
niklase@google.com470e71d2011-07-07 08:21:25 +00001811 CHECK_INITIALIZED();
1812
pbos@webrtc.org25509882013-04-09 10:30:35 +00001813 int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
niklase@google.com470e71d2011-07-07 08:21:25 +00001814
1815 if (sampleRate == -1)
1816 {
1817 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1818 return -1;
1819 }
1820
1821 *samplesPerSec = sampleRate;
1822
1823 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1824 return (0);
1825}
1826
1827// ----------------------------------------------------------------------------
1828// ResetAudioDevice
1829// ----------------------------------------------------------------------------
1830
pbos@webrtc.org25509882013-04-09 10:30:35 +00001831int32_t AudioDeviceModuleImpl::ResetAudioDevice()
niklase@google.com470e71d2011-07-07 08:21:25 +00001832{
niklase@google.com470e71d2011-07-07 08:21:25 +00001833 CHECK_INITIALIZED();
1834
1835
1836 if (_ptrAudioDevice->ResetAudioDevice() == -1)
1837 {
1838 return -1;
1839 }
1840
1841 return (0);
1842}
1843
1844// ----------------------------------------------------------------------------
1845// SetLoudspeakerStatus
1846// ----------------------------------------------------------------------------
1847
pbos@webrtc.org25509882013-04-09 10:30:35 +00001848int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
niklase@google.com470e71d2011-07-07 08:21:25 +00001849{
niklase@google.com470e71d2011-07-07 08:21:25 +00001850 CHECK_INITIALIZED();
1851
1852 if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1853 {
1854 return -1;
1855 }
1856
1857 return 0;
1858}
1859
1860// ----------------------------------------------------------------------------
1861// GetLoudspeakerStatus
1862// ----------------------------------------------------------------------------
1863
henrikac14f5ff2015-09-23 14:08:33 +02001864int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const {
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001865 CHECK_INITIALIZED();
henrikac14f5ff2015-09-23 14:08:33 +02001866 if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) {
1867 return -1;
1868 }
1869 return 0;
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001870}
1871
henrikac14f5ff2015-09-23 14:08:33 +02001872bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const {
1873 CHECK_INITIALIZED_BOOL();
1874 return _ptrAudioDevice->BuiltInAECIsEnabled();
andrew@webrtc.orga3c6d612011-09-13 17:17:49 +00001875}
1876
henrika@webrtc.orga954c072014-12-09 16:22:09 +00001877bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const {
1878 CHECK_INITIALIZED_BOOL();
1879 return _ptrAudioDevice->BuiltInAECIsAvailable();
1880}
1881
henrikac14f5ff2015-09-23 14:08:33 +02001882int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) {
1883 CHECK_INITIALIZED();
1884 return _ptrAudioDevice->EnableBuiltInAEC(enable);
1885}
1886
1887bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const {
1888 CHECK_INITIALIZED_BOOL();
1889 return _ptrAudioDevice->BuiltInAGCIsAvailable();
1890}
1891
1892int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) {
1893 CHECK_INITIALIZED();
1894 return _ptrAudioDevice->EnableBuiltInAGC(enable);
1895}
1896
1897bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const {
1898 CHECK_INITIALIZED_BOOL();
1899 return _ptrAudioDevice->BuiltInNSIsAvailable();
1900}
1901
1902int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) {
1903 CHECK_INITIALIZED();
1904 return _ptrAudioDevice->EnableBuiltInNS(enable);
1905}
1906
henrikaba35d052015-07-14 17:04:08 +02001907int AudioDeviceModuleImpl::GetPlayoutAudioParameters(
1908 AudioParameters* params) const {
1909 return _ptrAudioDevice->GetPlayoutAudioParameters(params);
1910}
1911
1912int AudioDeviceModuleImpl::GetRecordAudioParameters(
1913 AudioParameters* params) const {
1914 return _ptrAudioDevice->GetRecordAudioParameters(params);
1915}
1916
niklase@google.com470e71d2011-07-07 08:21:25 +00001917// ============================================================================
1918// Private Methods
1919// ============================================================================
1920
1921// ----------------------------------------------------------------------------
1922// Platform
1923// ----------------------------------------------------------------------------
1924
1925AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
1926{
1927 return _platformType;
1928}
1929
1930// ----------------------------------------------------------------------------
1931// PlatformAudioLayer
1932// ----------------------------------------------------------------------------
1933
1934AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
1935{
niklase@google.com470e71d2011-07-07 08:21:25 +00001936 return _platformAudioLayer;
1937}
1938
1939} // namespace webrtc