• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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 
11 #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
12 #include "webrtc/modules/audio_device/audio_device_config.h"
13 #include "webrtc/modules/audio_device/audio_device_impl.h"
14 #include "webrtc/system_wrappers/interface/ref_count.h"
15 
16 #include <assert.h>
17 #include <string.h>
18 
19 #if defined(_WIN32)
20     #include "audio_device_utility_win.h"
21     #include "audio_device_wave_win.h"
22  #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
23     #include "audio_device_core_win.h"
24  #endif
25 #elif defined(WEBRTC_ANDROID)
26     #include <stdlib.h>
27     #include "audio_device_utility_android.h"
28     #include "webrtc/modules/audio_device/android/audio_device_template.h"
29     #include "webrtc/modules/audio_device/android/audio_record_jni.h"
30     #include "webrtc/modules/audio_device/android/audio_track_jni.h"
31     #include "webrtc/modules/audio_device/android/opensles_input.h"
32     #include "webrtc/modules/audio_device/android/opensles_output.h"
33 #elif defined(WEBRTC_LINUX)
34     #include "audio_device_utility_linux.h"
35  #if defined(LINUX_ALSA)
36     #include "audio_device_alsa_linux.h"
37  #endif
38  #if defined(LINUX_PULSE)
39     #include "audio_device_pulse_linux.h"
40  #endif
41 #elif defined(WEBRTC_IOS)
42     #include "audio_device_utility_ios.h"
43     #include "audio_device_ios.h"
44 #elif defined(WEBRTC_MAC)
45     #include "audio_device_utility_mac.h"
46     #include "audio_device_mac.h"
47 #endif
48 
49 #if defined(WEBRTC_DUMMY_FILE_DEVICES)
50 #include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
51 #endif
52 
53 #include "webrtc/modules/audio_device/dummy/audio_device_dummy.h"
54 #include "webrtc/modules/audio_device/dummy/audio_device_utility_dummy.h"
55 #include "webrtc/modules/audio_device/dummy/file_audio_device.h"
56 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
57 #include "webrtc/system_wrappers/interface/trace.h"
58 
59 #define CHECK_INITIALIZED()         \
60 {                                   \
61     if (!_initialized) {            \
62         return -1;                  \
63     };                              \
64 }
65 
66 #define CHECK_INITIALIZED_BOOL()    \
67 {                                   \
68     if (!_initialized) {            \
69         return false;               \
70     };                              \
71 }
72 
73 namespace webrtc
74 {
75 
CreateAudioDeviceModule(int32_t id,AudioDeviceModule::AudioLayer audioLayer)76 AudioDeviceModule* CreateAudioDeviceModule(
77     int32_t id, AudioDeviceModule::AudioLayer audioLayer) {
78   return AudioDeviceModuleImpl::Create(id, audioLayer);
79 }
80 
81 
82 // ============================================================================
83 //                                   Static methods
84 // ============================================================================
85 
86 // ----------------------------------------------------------------------------
87 //  AudioDeviceModule::Create()
88 // ----------------------------------------------------------------------------
89 
Create(const int32_t id,const AudioLayer audioLayer)90 AudioDeviceModule* AudioDeviceModuleImpl::Create(const int32_t id,
91                                                  const AudioLayer audioLayer)
92 {
93 
94     // Create the generic ref counted (platform independent) implementation.
95     RefCountImpl<AudioDeviceModuleImpl>* audioDevice =
96         new RefCountImpl<AudioDeviceModuleImpl>(id, audioLayer);
97 
98     // Ensure that the current platform is supported.
99     if (audioDevice->CheckPlatform() == -1)
100     {
101         delete audioDevice;
102         return NULL;
103     }
104 
105     // Create the platform-dependent implementation.
106     if (audioDevice->CreatePlatformSpecificObjects() == -1)
107     {
108         delete audioDevice;
109         return NULL;
110     }
111 
112     // Ensure that the generic audio buffer can communicate with the
113     // platform-specific parts.
114     if (audioDevice->AttachAudioBuffer() == -1)
115     {
116         delete audioDevice;
117         return NULL;
118     }
119 
120     WebRtcSpl_Init();
121 
122     return audioDevice;
123 }
124 
125 // ============================================================================
126 //                            Construction & Destruction
127 // ============================================================================
128 
129 // ----------------------------------------------------------------------------
130 //  AudioDeviceModuleImpl - ctor
131 // ----------------------------------------------------------------------------
132 
AudioDeviceModuleImpl(const int32_t id,const AudioLayer audioLayer)133 AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) :
134     _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
135     _critSectEventCb(*CriticalSectionWrapper::CreateCriticalSection()),
136     _critSectAudioCb(*CriticalSectionWrapper::CreateCriticalSection()),
137     _ptrCbAudioDeviceObserver(NULL),
138     _ptrAudioDeviceUtility(NULL),
139     _ptrAudioDevice(NULL),
140     _id(id),
141     _platformAudioLayer(audioLayer),
142     _lastProcessTime(AudioDeviceUtility::GetTimeInMS()),
143     _platformType(kPlatformNotSupported),
144     _initialized(false),
145     _lastError(kAdmErrNone)
146 {
147     WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
148 }
149 
150 // ----------------------------------------------------------------------------
151 //  CheckPlatform
152 // ----------------------------------------------------------------------------
153 
CheckPlatform()154 int32_t AudioDeviceModuleImpl::CheckPlatform()
155 {
156     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
157 
158     // Ensure that the current platform is supported
159     //
160     PlatformType platform(kPlatformNotSupported);
161 
162 #if defined(_WIN32)
163     platform = kPlatformWin32;
164     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is WIN32");
165 #elif defined(WEBRTC_ANDROID)
166     platform = kPlatformAndroid;
167     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is ANDROID");
168 #elif defined(WEBRTC_LINUX)
169     platform = kPlatformLinux;
170     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is LINUX");
171 #elif defined(WEBRTC_IOS)
172     platform = kPlatformIOS;
173     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is IOS");
174 #elif defined(WEBRTC_MAC)
175     platform = kPlatformMac;
176     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "current platform is MAC");
177 #endif
178 
179     if (platform == kPlatformNotSupported)
180     {
181         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "current platform is not supported => this module will self destruct!");
182         return -1;
183     }
184 
185     // Store valid output results
186     //
187     _platformType = platform;
188 
189     return 0;
190 }
191 
192 
193 // ----------------------------------------------------------------------------
194 //  CreatePlatformSpecificObjects
195 // ----------------------------------------------------------------------------
196 
CreatePlatformSpecificObjects()197 int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()
198 {
199     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
200 
201     AudioDeviceGeneric* ptrAudioDevice(NULL);
202     AudioDeviceUtility* ptrAudioDeviceUtility(NULL);
203 
204 #if defined(WEBRTC_DUMMY_AUDIO_BUILD)
205     ptrAudioDevice = new AudioDeviceDummy(Id());
206     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
207 
208     if (ptrAudioDevice != NULL)
209     {
210         ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
211     }
212 #elif defined(WEBRTC_DUMMY_FILE_DEVICES)
213     ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id());
214     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
215                  "Will use file-playing dummy device.");
216     if (ptrAudioDevice != NULL)
217     {
218         ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
219     }
220 #else
221     const AudioLayer audioLayer(PlatformAudioLayer());
222 
223     // Create the *Windows* implementation of the Audio Device
224     //
225 #if defined(_WIN32)
226     if ((audioLayer == kWindowsWaveAudio)
227 #if !defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
228         // Wave audio is default if Core audio is not supported in this build
229         || (audioLayer == kPlatformDefaultAudio)
230 #endif
231         )
232     {
233         // create *Windows Wave Audio* implementation
234         ptrAudioDevice = new AudioDeviceWindowsWave(Id());
235         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Wave APIs will be utilized");
236     }
237 #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
238     if ((audioLayer == kWindowsCoreAudio) ||
239         (audioLayer == kPlatformDefaultAudio)
240         )
241     {
242         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Windows Core Audio APIs...");
243 
244         if (AudioDeviceWindowsCore::CoreAudioIsSupported())
245         {
246             // create *Windows Core Audio* implementation
247             ptrAudioDevice = new AudioDeviceWindowsCore(Id());
248             WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Windows Core Audio APIs will be utilized");
249         }
250         else
251         {
252             // create *Windows Wave Audio* implementation
253             ptrAudioDevice = new AudioDeviceWindowsWave(Id());
254             if (ptrAudioDevice != NULL)
255             {
256                 // Core Audio was not supported => revert to Windows Wave instead
257                 _platformAudioLayer = kWindowsWaveAudio;  // modify the state set at construction
258                 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Windows Core Audio is *not* supported => Wave APIs will be utilized instead");
259             }
260         }
261     }
262 #endif // defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD)
263     if (ptrAudioDevice != NULL)
264     {
265         // Create the Windows implementation of the Device Utility.
266         // This class is independent of the selected audio layer
267         // for Windows.
268         //
269         ptrAudioDeviceUtility = new AudioDeviceUtilityWindows(Id());
270     }
271 #endif  // #if defined(_WIN32)
272 
273     // Create the *Android OpenSLES* implementation of the Audio Device
274     //
275 #if defined(WEBRTC_ANDROID)
276     if (audioLayer == kPlatformDefaultAudio)
277     {
278         // AudioRecordJni provides hardware AEC and OpenSlesOutput low latency.
279 #if defined(WEBRTC_ANDROID_OPENSLES)
280         ptrAudioDevice = new AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>(Id());
281 #else
282         ptrAudioDevice = new AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>(Id());
283 #endif
284         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
285                      "Android OpenSLES Audio APIs will be utilized");
286     }
287 
288     if (ptrAudioDevice != NULL)
289     {
290         // Create the Android implementation of the Device Utility.
291         ptrAudioDeviceUtility = new AudioDeviceUtilityAndroid(Id());
292     }
293     // END #if defined(WEBRTC_ANDROID)
294 
295     // Create the *Linux* implementation of the Audio Device
296     //
297 #elif defined(WEBRTC_LINUX)
298     if ((audioLayer == kLinuxPulseAudio) || (audioLayer == kPlatformDefaultAudio))
299     {
300 #if defined(LINUX_PULSE)
301         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "attempting to use the Linux PulseAudio APIs...");
302 
303         // create *Linux PulseAudio* implementation
304         AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(Id());
305         if (pulseDevice->Init() != -1)
306         {
307             ptrAudioDevice = pulseDevice;
308             WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux PulseAudio APIs will be utilized");
309         }
310         else
311         {
312             delete pulseDevice;
313 #endif
314 #if defined(LINUX_ALSA)
315             // create *Linux ALSA Audio* implementation
316             ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
317             if (ptrAudioDevice != NULL)
318             {
319                 // Pulse Audio was not supported => revert to ALSA instead
320                 _platformAudioLayer = kLinuxAlsaAudio;  // modify the state set at construction
321                 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "Linux PulseAudio is *not* supported => ALSA APIs will be utilized instead");
322             }
323 #endif
324 #if defined(LINUX_PULSE)
325         }
326 #endif
327     }
328     else if (audioLayer == kLinuxAlsaAudio)
329     {
330 #if defined(LINUX_ALSA)
331         // create *Linux ALSA Audio* implementation
332         ptrAudioDevice = new AudioDeviceLinuxALSA(Id());
333         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Linux ALSA APIs will be utilized");
334 #endif
335     }
336 
337     if (ptrAudioDevice != NULL)
338     {
339         // Create the Linux implementation of the Device Utility.
340         // This class is independent of the selected audio layer
341         // for Linux.
342         //
343         ptrAudioDeviceUtility = new AudioDeviceUtilityLinux(Id());
344     }
345 #endif  // #if defined(WEBRTC_LINUX)
346 
347     // Create the *iPhone* implementation of the Audio Device
348     //
349 #if defined(WEBRTC_IOS)
350     if (audioLayer == kPlatformDefaultAudio)
351     {
352         // Create *iPhone Audio* implementation
353         ptrAudioDevice = new AudioDeviceIPhone(Id());
354         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "iPhone Audio APIs will be utilized");
355     }
356 
357     if (ptrAudioDevice != NULL)
358     {
359         // Create the Mac implementation of the Device Utility.
360         ptrAudioDeviceUtility = new AudioDeviceUtilityIPhone(Id());
361     }
362     // END #if defined(WEBRTC_IOS)
363 
364     // Create the *Mac* implementation of the Audio Device
365     //
366 #elif defined(WEBRTC_MAC)
367     if (audioLayer == kPlatformDefaultAudio)
368     {
369         // Create *Mac Audio* implementation
370         ptrAudioDevice = new AudioDeviceMac(Id());
371         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Mac OS X Audio APIs will be utilized");
372     }
373 
374     if (ptrAudioDevice != NULL)
375     {
376         // Create the Mac implementation of the Device Utility.
377         ptrAudioDeviceUtility = new AudioDeviceUtilityMac(Id());
378     }
379 #endif  // WEBRTC_MAC
380 
381     // Create the *Dummy* implementation of the Audio Device
382     // Available for all platforms
383     //
384     if (audioLayer == kDummyAudio)
385     {
386         // Create *Dummy Audio* implementation
387         assert(!ptrAudioDevice);
388         ptrAudioDevice = new AudioDeviceDummy(Id());
389         WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "Dummy Audio APIs will be utilized");
390 
391         if (ptrAudioDevice != NULL)
392         {
393             ptrAudioDeviceUtility = new AudioDeviceUtilityDummy(Id());
394         }
395     }
396 #endif  // if defined(WEBRTC_DUMMY_AUDIO_BUILD)
397 
398     if (ptrAudioDevice == NULL)
399     {
400         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device implementation");
401         return -1;
402     }
403 
404     if (ptrAudioDeviceUtility == NULL)
405     {
406         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, "unable to create the platform specific audio device utility");
407         return -1;
408     }
409 
410     // Store valid output pointers
411     //
412     _ptrAudioDevice = ptrAudioDevice;
413     _ptrAudioDeviceUtility = ptrAudioDeviceUtility;
414 
415     return 0;
416 }
417 
418 // ----------------------------------------------------------------------------
419 //  AttachAudioBuffer
420 //
421 //  Install "bridge" between the platform implemetation and the generic
422 //  implementation. The "child" shall set the native sampling rate and the
423 //  number of channels in this function call.
424 // ----------------------------------------------------------------------------
425 
AttachAudioBuffer()426 int32_t AudioDeviceModuleImpl::AttachAudioBuffer()
427 {
428     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__);
429 
430     _audioDeviceBuffer.SetId(_id);
431     _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer);
432     return 0;
433 }
434 
435 // ----------------------------------------------------------------------------
436 //  ~AudioDeviceModuleImpl - dtor
437 // ----------------------------------------------------------------------------
438 
~AudioDeviceModuleImpl()439 AudioDeviceModuleImpl::~AudioDeviceModuleImpl()
440 {
441     WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
442 
443     if (_ptrAudioDevice)
444     {
445         delete _ptrAudioDevice;
446         _ptrAudioDevice = NULL;
447     }
448 
449     if (_ptrAudioDeviceUtility)
450     {
451         delete _ptrAudioDeviceUtility;
452         _ptrAudioDeviceUtility = NULL;
453     }
454 
455     delete &_critSect;
456     delete &_critSectEventCb;
457     delete &_critSectAudioCb;
458 }
459 
460 // ============================================================================
461 //                                  Module
462 // ============================================================================
463 
464 // ----------------------------------------------------------------------------
465 //  Module::ChangeUniqueId
466 // ----------------------------------------------------------------------------
467 
ChangeUniqueId(const int32_t id)468 int32_t AudioDeviceModuleImpl::ChangeUniqueId(const int32_t id)
469 {
470     _id = id;
471     return 0;
472 }
473 
474 // ----------------------------------------------------------------------------
475 //  Module::TimeUntilNextProcess
476 //
477 //  Returns the number of milliseconds until the module want a worker thread
478 //  to call Process().
479 // ----------------------------------------------------------------------------
480 
TimeUntilNextProcess()481 int32_t AudioDeviceModuleImpl::TimeUntilNextProcess()
482 {
483     uint32_t now = AudioDeviceUtility::GetTimeInMS();
484     int32_t deltaProcess = kAdmMaxIdleTimeProcess - (now - _lastProcessTime);
485     return (deltaProcess);
486 }
487 
488 // ----------------------------------------------------------------------------
489 //  Module::Process
490 //
491 //  Check for posted error and warning reports. Generate callbacks if
492 //  new reports exists.
493 // ----------------------------------------------------------------------------
494 
Process()495 int32_t AudioDeviceModuleImpl::Process()
496 {
497 
498     _lastProcessTime = AudioDeviceUtility::GetTimeInMS();
499 
500     // kPlayoutWarning
501     if (_ptrAudioDevice->PlayoutWarning())
502     {
503         CriticalSectionScoped lock(&_critSectEventCb);
504         if (_ptrCbAudioDeviceObserver)
505         {
506             WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kPlayoutWarning)");
507             _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kPlayoutWarning);
508         }
509         _ptrAudioDevice->ClearPlayoutWarning();
510     }
511 
512     // kPlayoutError
513     if (_ptrAudioDevice->PlayoutError())
514     {
515         CriticalSectionScoped lock(&_critSectEventCb);
516         if (_ptrCbAudioDeviceObserver)
517         {
518             WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kPlayoutError)");
519             _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kPlayoutError);
520         }
521         _ptrAudioDevice->ClearPlayoutError();
522     }
523 
524     // kRecordingWarning
525     if (_ptrAudioDevice->RecordingWarning())
526     {
527         CriticalSectionScoped lock(&_critSectEventCb);
528         if (_ptrCbAudioDeviceObserver)
529         {
530             WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "=> OnWarningIsReported(kRecordingWarning)");
531             _ptrCbAudioDeviceObserver->OnWarningIsReported(AudioDeviceObserver::kRecordingWarning);
532         }
533         _ptrAudioDevice->ClearRecordingWarning();
534     }
535 
536     // kRecordingError
537     if (_ptrAudioDevice->RecordingError())
538     {
539         CriticalSectionScoped lock(&_critSectEventCb);
540         if (_ptrCbAudioDeviceObserver)
541         {
542             WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "=> OnErrorIsReported(kRecordingError)");
543             _ptrCbAudioDeviceObserver->OnErrorIsReported(AudioDeviceObserver::kRecordingError);
544         }
545         _ptrAudioDevice->ClearRecordingError();
546     }
547 
548     return 0;
549 }
550 
551 // ============================================================================
552 //                                    Public API
553 // ============================================================================
554 
555 // ----------------------------------------------------------------------------
556 //  ActiveAudioLayer
557 // ----------------------------------------------------------------------------
558 
ActiveAudioLayer(AudioLayer * audioLayer) const559 int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const
560 {
561 
562     AudioLayer activeAudio;
563 
564     if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1)
565     {
566         return -1;
567     }
568 
569     *audioLayer = activeAudio;
570 
571     if (*audioLayer == AudioDeviceModule::kWindowsWaveAudio)
572     {
573         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsWaveAudio");
574     }
575     else if (*audioLayer == AudioDeviceModule::kWindowsCoreAudio)
576     {
577         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kWindowsCoreAudio");
578     }
579     else if (*audioLayer == AudioDeviceModule::kLinuxAlsaAudio)
580     {
581         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: kLinuxAlsaAudio");
582     }
583     else
584     {
585         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: NOT_SUPPORTED");
586     }
587 
588     return 0;
589 }
590 
591 // ----------------------------------------------------------------------------
592 //  LastError
593 // ----------------------------------------------------------------------------
594 
LastError() const595 AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const
596 {
597     return _lastError;
598 }
599 
600 // ----------------------------------------------------------------------------
601 //  Init
602 // ----------------------------------------------------------------------------
603 
Init()604 int32_t AudioDeviceModuleImpl::Init()
605 {
606 
607     if (_initialized)
608         return 0;
609 
610     if (!_ptrAudioDeviceUtility)
611         return -1;
612 
613     if (!_ptrAudioDevice)
614         return -1;
615 
616     _ptrAudioDeviceUtility->Init();
617 
618     if (_ptrAudioDevice->Init() == -1)
619     {
620         return -1;
621     }
622 
623     _initialized = true;
624     return 0;
625 }
626 
627 // ----------------------------------------------------------------------------
628 //  Terminate
629 // ----------------------------------------------------------------------------
630 
Terminate()631 int32_t AudioDeviceModuleImpl::Terminate()
632 {
633 
634     if (!_initialized)
635         return 0;
636 
637     if (_ptrAudioDevice->Terminate() == -1)
638     {
639         return -1;
640     }
641 
642     _initialized = false;
643     return 0;
644 }
645 
646 // ----------------------------------------------------------------------------
647 //  Initialized
648 // ----------------------------------------------------------------------------
649 
Initialized() const650 bool AudioDeviceModuleImpl::Initialized() const
651 {
652 
653     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", _initialized);
654     return (_initialized);
655 }
656 
657 // ----------------------------------------------------------------------------
658 //  InitSpeaker
659 // ----------------------------------------------------------------------------
660 
InitSpeaker()661 int32_t AudioDeviceModuleImpl::InitSpeaker()
662 {
663     CHECK_INITIALIZED();
664     return (_ptrAudioDevice->InitSpeaker());
665 }
666 
667 // ----------------------------------------------------------------------------
668 //  InitMicrophone
669 // ----------------------------------------------------------------------------
670 
InitMicrophone()671 int32_t AudioDeviceModuleImpl::InitMicrophone()
672 {
673     CHECK_INITIALIZED();
674     return (_ptrAudioDevice->InitMicrophone());
675 }
676 
677 // ----------------------------------------------------------------------------
678 //  SpeakerVolumeIsAvailable
679 // ----------------------------------------------------------------------------
680 
SpeakerVolumeIsAvailable(bool * available)681 int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available)
682 {
683     CHECK_INITIALIZED();
684 
685     bool isAvailable(0);
686 
687     if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1)
688     {
689         return -1;
690     }
691 
692     *available = isAvailable;
693 
694     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
695     return (0);
696 }
697 
698 // ----------------------------------------------------------------------------
699 //  SetSpeakerVolume
700 // ----------------------------------------------------------------------------
701 
SetSpeakerVolume(uint32_t volume)702 int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume)
703 {
704     CHECK_INITIALIZED();
705     return (_ptrAudioDevice->SetSpeakerVolume(volume));
706 }
707 
708 // ----------------------------------------------------------------------------
709 //  SpeakerVolume
710 // ----------------------------------------------------------------------------
711 
SpeakerVolume(uint32_t * volume) const712 int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const
713 {
714     CHECK_INITIALIZED();
715 
716     uint32_t level(0);
717 
718     if (_ptrAudioDevice->SpeakerVolume(level) == -1)
719     {
720         return -1;
721     }
722 
723     *volume = level;
724 
725     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: volume=%u", *volume);
726     return (0);
727 }
728 
729 // ----------------------------------------------------------------------------
730 //  SetWaveOutVolume
731 // ----------------------------------------------------------------------------
732 
SetWaveOutVolume(uint16_t volumeLeft,uint16_t volumeRight)733 int32_t AudioDeviceModuleImpl::SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight)
734 {
735     CHECK_INITIALIZED();
736     return (_ptrAudioDevice->SetWaveOutVolume(volumeLeft, volumeRight));
737 }
738 
739 // ----------------------------------------------------------------------------
740 //  WaveOutVolume
741 // ----------------------------------------------------------------------------
742 
WaveOutVolume(uint16_t * volumeLeft,uint16_t * volumeRight) const743 int32_t AudioDeviceModuleImpl::WaveOutVolume(uint16_t* volumeLeft, uint16_t* volumeRight) const
744 {
745     CHECK_INITIALIZED();
746 
747     uint16_t volLeft(0);
748     uint16_t volRight(0);
749 
750     if (_ptrAudioDevice->WaveOutVolume(volLeft, volRight) == -1)
751     {
752         return -1;
753     }
754 
755     *volumeLeft = volLeft;
756     *volumeRight = volRight;
757 
758     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "outputs: volumeLeft=%u, volumeRight=%u",
759         *volumeLeft, *volumeRight);
760 
761     return (0);
762 }
763 
764 // ----------------------------------------------------------------------------
765 //  SpeakerIsInitialized
766 // ----------------------------------------------------------------------------
767 
SpeakerIsInitialized() const768 bool AudioDeviceModuleImpl::SpeakerIsInitialized() const
769 {
770     CHECK_INITIALIZED_BOOL();
771 
772     bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized();
773 
774     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
775     return (isInitialized);
776 }
777 
778 // ----------------------------------------------------------------------------
779 //  MicrophoneIsInitialized
780 // ----------------------------------------------------------------------------
781 
MicrophoneIsInitialized() const782 bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const
783 {
784     CHECK_INITIALIZED_BOOL();
785 
786     bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized();
787 
788     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: %d", isInitialized);
789     return (isInitialized);
790 }
791 
792 // ----------------------------------------------------------------------------
793 //  MaxSpeakerVolume
794 // ----------------------------------------------------------------------------
795 
MaxSpeakerVolume(uint32_t * maxVolume) const796 int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const
797 {
798     CHECK_INITIALIZED();
799 
800     uint32_t maxVol(0);
801 
802     if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1)
803     {
804         return -1;
805     }
806 
807     *maxVolume = maxVol;
808 
809     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
810     return (0);
811 }
812 
813 // ----------------------------------------------------------------------------
814 //  MinSpeakerVolume
815 // ----------------------------------------------------------------------------
816 
MinSpeakerVolume(uint32_t * minVolume) const817 int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const
818 {
819     CHECK_INITIALIZED();
820 
821     uint32_t minVol(0);
822 
823     if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1)
824     {
825         return -1;
826     }
827 
828     *minVolume = minVol;
829 
830     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
831     return (0);
832 }
833 
834 // ----------------------------------------------------------------------------
835 //  SpeakerVolumeStepSize
836 // ----------------------------------------------------------------------------
837 
SpeakerVolumeStepSize(uint16_t * stepSize) const838 int32_t AudioDeviceModuleImpl::SpeakerVolumeStepSize(uint16_t* stepSize) const
839 {
840     CHECK_INITIALIZED();
841 
842     uint16_t delta(0);
843 
844     if (_ptrAudioDevice->SpeakerVolumeStepSize(delta) == -1)
845     {
846         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the speaker-volume step size");
847         return -1;
848     }
849 
850     *stepSize = delta;
851 
852     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
853     return (0);
854 }
855 
856 // ----------------------------------------------------------------------------
857 //  SpeakerMuteIsAvailable
858 // ----------------------------------------------------------------------------
859 
SpeakerMuteIsAvailable(bool * available)860 int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available)
861 {
862     CHECK_INITIALIZED();
863 
864     bool isAvailable(0);
865 
866     if (_ptrAudioDevice->SpeakerMuteIsAvailable(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 //  SetSpeakerMute
879 // ----------------------------------------------------------------------------
880 
SetSpeakerMute(bool enable)881 int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable)
882 {
883     CHECK_INITIALIZED();
884     return (_ptrAudioDevice->SetSpeakerMute(enable));
885 }
886 
887 // ----------------------------------------------------------------------------
888 //  SpeakerMute
889 // ----------------------------------------------------------------------------
890 
SpeakerMute(bool * enabled) const891 int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const
892 {
893     CHECK_INITIALIZED();
894 
895     bool muted(false);
896 
897     if (_ptrAudioDevice->SpeakerMute(muted) == -1)
898     {
899         return -1;
900     }
901 
902     *enabled = muted;
903 
904     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
905     return (0);
906 }
907 
908 // ----------------------------------------------------------------------------
909 //  MicrophoneMuteIsAvailable
910 // ----------------------------------------------------------------------------
911 
MicrophoneMuteIsAvailable(bool * available)912 int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available)
913 {
914     CHECK_INITIALIZED();
915 
916     bool isAvailable(0);
917 
918     if (_ptrAudioDevice->MicrophoneMuteIsAvailable(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 //  SetMicrophoneMute
931 // ----------------------------------------------------------------------------
932 
SetMicrophoneMute(bool enable)933 int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable)
934 {
935     CHECK_INITIALIZED();
936     return (_ptrAudioDevice->SetMicrophoneMute(enable));
937 }
938 
939 // ----------------------------------------------------------------------------
940 //  MicrophoneMute
941 // ----------------------------------------------------------------------------
942 
MicrophoneMute(bool * enabled) const943 int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const
944 {
945     CHECK_INITIALIZED();
946 
947     bool muted(false);
948 
949     if (_ptrAudioDevice->MicrophoneMute(muted) == -1)
950     {
951         return -1;
952     }
953 
954     *enabled = muted;
955 
956     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
957     return (0);
958 }
959 
960 // ----------------------------------------------------------------------------
961 //  MicrophoneBoostIsAvailable
962 // ----------------------------------------------------------------------------
963 
MicrophoneBoostIsAvailable(bool * available)964 int32_t AudioDeviceModuleImpl::MicrophoneBoostIsAvailable(bool* available)
965 {
966     CHECK_INITIALIZED();
967 
968     bool isAvailable(0);
969 
970     if (_ptrAudioDevice->MicrophoneBoostIsAvailable(isAvailable) == -1)
971     {
972         return -1;
973     }
974 
975     *available = isAvailable;
976 
977     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
978     return (0);
979 }
980 
981 // ----------------------------------------------------------------------------
982 //  SetMicrophoneBoost
983 // ----------------------------------------------------------------------------
984 
SetMicrophoneBoost(bool enable)985 int32_t AudioDeviceModuleImpl::SetMicrophoneBoost(bool enable)
986 {
987     CHECK_INITIALIZED();
988     return (_ptrAudioDevice->SetMicrophoneBoost(enable));
989 }
990 
991 // ----------------------------------------------------------------------------
992 //  MicrophoneBoost
993 // ----------------------------------------------------------------------------
994 
MicrophoneBoost(bool * enabled) const995 int32_t AudioDeviceModuleImpl::MicrophoneBoost(bool* enabled) const
996 {
997     CHECK_INITIALIZED();
998 
999     bool onOff(false);
1000 
1001     if (_ptrAudioDevice->MicrophoneBoost(onOff) == -1)
1002     {
1003         return -1;
1004     }
1005 
1006     *enabled = onOff;
1007 
1008     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1009     return (0);
1010 }
1011 
1012 // ----------------------------------------------------------------------------
1013 //  MicrophoneVolumeIsAvailable
1014 // ----------------------------------------------------------------------------
1015 
MicrophoneVolumeIsAvailable(bool * available)1016 int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available)
1017 {
1018     CHECK_INITIALIZED();
1019 
1020     bool isAvailable(0);
1021 
1022     if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1)
1023     {
1024         return -1;
1025     }
1026 
1027     *available = isAvailable;
1028 
1029     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1030     return (0);
1031 }
1032 
1033 // ----------------------------------------------------------------------------
1034 //  SetMicrophoneVolume
1035 // ----------------------------------------------------------------------------
1036 
SetMicrophoneVolume(uint32_t volume)1037 int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume)
1038 {
1039     CHECK_INITIALIZED();
1040     return (_ptrAudioDevice->SetMicrophoneVolume(volume));
1041 }
1042 
1043 // ----------------------------------------------------------------------------
1044 //  MicrophoneVolume
1045 // ----------------------------------------------------------------------------
1046 
MicrophoneVolume(uint32_t * volume) const1047 int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const
1048 {
1049     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1050     CHECK_INITIALIZED();
1051 
1052     uint32_t level(0);
1053 
1054     if (_ptrAudioDevice->MicrophoneVolume(level) == -1)
1055     {
1056         return -1;
1057     }
1058 
1059     *volume = level;
1060 
1061     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: volume=%u", *volume);
1062     return (0);
1063 }
1064 
1065 // ----------------------------------------------------------------------------
1066 //  StereoRecordingIsAvailable
1067 // ----------------------------------------------------------------------------
1068 
StereoRecordingIsAvailable(bool * available) const1069 int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable(bool* available) const
1070 {
1071     CHECK_INITIALIZED();
1072 
1073     bool isAvailable(0);
1074 
1075     if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1)
1076     {
1077         return -1;
1078     }
1079 
1080     *available = isAvailable;
1081 
1082     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1083     return (0);
1084 }
1085 
1086 // ----------------------------------------------------------------------------
1087 //  SetStereoRecording
1088 // ----------------------------------------------------------------------------
1089 
SetStereoRecording(bool enable)1090 int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable)
1091 {
1092     CHECK_INITIALIZED();
1093 
1094     if (_ptrAudioDevice->RecordingIsInitialized())
1095     {
1096         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1097         return -1;
1098     }
1099 
1100     if (_ptrAudioDevice->SetStereoRecording(enable) == -1)
1101     {
1102         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to enable stereo recording");
1103         return -1;
1104     }
1105 
1106     int8_t nChannels(1);
1107     if (enable)
1108     {
1109         nChannels = 2;
1110     }
1111     _audioDeviceBuffer.SetRecordingChannels(nChannels);
1112 
1113     return 0;
1114 }
1115 
1116 // ----------------------------------------------------------------------------
1117 //  StereoRecording
1118 // ----------------------------------------------------------------------------
1119 
StereoRecording(bool * enabled) const1120 int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const
1121 {
1122     CHECK_INITIALIZED();
1123 
1124     bool stereo(false);
1125 
1126     if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1127     {
1128         return -1;
1129     }
1130 
1131     *enabled = stereo;
1132 
1133     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1134     return (0);
1135 }
1136 
1137 // ----------------------------------------------------------------------------
1138 //  SetRecordingChannel
1139 // ----------------------------------------------------------------------------
1140 
SetRecordingChannel(const ChannelType channel)1141 int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel)
1142 {
1143     if (channel == kChannelBoth)
1144     {
1145     }
1146     else if (channel == kChannelLeft)
1147     {
1148     }
1149     else
1150     {
1151     }
1152     CHECK_INITIALIZED();
1153 
1154     bool stereo(false);
1155 
1156     if (_ptrAudioDevice->StereoRecording(stereo) == -1)
1157     {
1158         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "recording in stereo is not supported");
1159         return -1;
1160     }
1161 
1162     return (_audioDeviceBuffer.SetRecordingChannel(channel));
1163 }
1164 
1165 // ----------------------------------------------------------------------------
1166 //  RecordingChannel
1167 // ----------------------------------------------------------------------------
1168 
RecordingChannel(ChannelType * channel) const1169 int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const
1170 {
1171     CHECK_INITIALIZED();
1172 
1173     ChannelType chType;
1174 
1175     if (_audioDeviceBuffer.RecordingChannel(chType) == -1)
1176     {
1177         return -1;
1178     }
1179 
1180     *channel = chType;
1181 
1182     if (*channel == kChannelBoth)
1183     {
1184     }
1185     else if (*channel == kChannelLeft)
1186     {
1187     }
1188     else
1189     {
1190     }
1191 
1192     return (0);
1193 }
1194 
1195 // ----------------------------------------------------------------------------
1196 //  StereoPlayoutIsAvailable
1197 // ----------------------------------------------------------------------------
1198 
StereoPlayoutIsAvailable(bool * available) const1199 int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const
1200 {
1201     CHECK_INITIALIZED();
1202 
1203     bool isAvailable(0);
1204 
1205     if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1)
1206     {
1207         return -1;
1208     }
1209 
1210     *available = isAvailable;
1211 
1212     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1213     return (0);
1214 }
1215 
1216 // ----------------------------------------------------------------------------
1217 //  SetStereoPlayout
1218 // ----------------------------------------------------------------------------
1219 
SetStereoPlayout(bool enable)1220 int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable)
1221 {
1222     CHECK_INITIALIZED();
1223 
1224     if (_ptrAudioDevice->PlayoutIsInitialized())
1225     {
1226         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to set stereo mode while playing side is initialized");
1227         return -1;
1228     }
1229 
1230     if (_ptrAudioDevice->SetStereoPlayout(enable))
1231     {
1232         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "stereo playout is not supported");
1233         return -1;
1234     }
1235 
1236     int8_t nChannels(1);
1237     if (enable)
1238     {
1239         nChannels = 2;
1240     }
1241     _audioDeviceBuffer.SetPlayoutChannels(nChannels);
1242 
1243     return 0;
1244 }
1245 
1246 // ----------------------------------------------------------------------------
1247 //  StereoPlayout
1248 // ----------------------------------------------------------------------------
1249 
StereoPlayout(bool * enabled) const1250 int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const
1251 {
1252     CHECK_INITIALIZED();
1253 
1254     bool stereo(false);
1255 
1256     if (_ptrAudioDevice->StereoPlayout(stereo) == -1)
1257     {
1258         return -1;
1259     }
1260 
1261    *enabled = stereo;
1262 
1263    WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: enabled=%u", *enabled);
1264    return (0);
1265 }
1266 
1267 // ----------------------------------------------------------------------------
1268 //  SetAGC
1269 // ----------------------------------------------------------------------------
1270 
SetAGC(bool enable)1271 int32_t AudioDeviceModuleImpl::SetAGC(bool enable)
1272 {
1273     CHECK_INITIALIZED();
1274     return (_ptrAudioDevice->SetAGC(enable));
1275 }
1276 
1277 // ----------------------------------------------------------------------------
1278 //  AGC
1279 // ----------------------------------------------------------------------------
1280 
AGC() const1281 bool AudioDeviceModuleImpl::AGC() const
1282 {
1283     CHECK_INITIALIZED_BOOL();
1284     return (_ptrAudioDevice->AGC());
1285 }
1286 
1287 // ----------------------------------------------------------------------------
1288 //  PlayoutIsAvailable
1289 // ----------------------------------------------------------------------------
1290 
PlayoutIsAvailable(bool * available)1291 int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available)
1292 {
1293     CHECK_INITIALIZED();
1294 
1295     bool isAvailable(0);
1296 
1297     if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1)
1298     {
1299         return -1;
1300     }
1301 
1302     *available = isAvailable;
1303 
1304     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1305     return (0);
1306 }
1307 
1308 // ----------------------------------------------------------------------------
1309 //  RecordingIsAvailable
1310 // ----------------------------------------------------------------------------
1311 
RecordingIsAvailable(bool * available)1312 int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available)
1313 {
1314     CHECK_INITIALIZED();
1315 
1316     bool isAvailable(0);
1317 
1318     if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1)
1319     {
1320         return -1;
1321     }
1322 
1323     *available = isAvailable;
1324 
1325     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: available=%d", *available);
1326     return (0);
1327 }
1328 
1329 // ----------------------------------------------------------------------------
1330 //  MaxMicrophoneVolume
1331 // ----------------------------------------------------------------------------
1332 
MaxMicrophoneVolume(uint32_t * maxVolume) const1333 int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const
1334 {
1335     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1336     CHECK_INITIALIZED();
1337 
1338     uint32_t maxVol(0);
1339 
1340     if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1)
1341     {
1342         return -1;
1343     }
1344 
1345     *maxVolume = maxVol;
1346 
1347     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: maxVolume=%d", *maxVolume);
1348     return (0);
1349 }
1350 
1351 // ----------------------------------------------------------------------------
1352 //  MinMicrophoneVolume
1353 // ----------------------------------------------------------------------------
1354 
MinMicrophoneVolume(uint32_t * minVolume) const1355 int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const
1356 {
1357     CHECK_INITIALIZED();
1358 
1359     uint32_t minVol(0);
1360 
1361     if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1)
1362     {
1363         return -1;
1364     }
1365 
1366     *minVolume = minVol;
1367 
1368     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: minVolume=%u", *minVolume);
1369     return (0);
1370 }
1371 
1372 // ----------------------------------------------------------------------------
1373 //  MicrophoneVolumeStepSize
1374 // ----------------------------------------------------------------------------
1375 
MicrophoneVolumeStepSize(uint16_t * stepSize) const1376 int32_t AudioDeviceModuleImpl::MicrophoneVolumeStepSize(uint16_t* stepSize) const
1377 {
1378     CHECK_INITIALIZED();
1379 
1380     uint16_t delta(0);
1381 
1382     if (_ptrAudioDevice->MicrophoneVolumeStepSize(delta) == -1)
1383     {
1384         return -1;
1385     }
1386 
1387     *stepSize = delta;
1388 
1389     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: stepSize=%u", *stepSize);
1390     return (0);
1391 }
1392 
1393 // ----------------------------------------------------------------------------
1394 //  PlayoutDevices
1395 // ----------------------------------------------------------------------------
1396 
PlayoutDevices()1397 int16_t AudioDeviceModuleImpl::PlayoutDevices()
1398 {
1399     CHECK_INITIALIZED();
1400 
1401     uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices();
1402 
1403     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: #playout devices=%d", nPlayoutDevices);
1404     return ((int16_t)(nPlayoutDevices));
1405 }
1406 
1407 // ----------------------------------------------------------------------------
1408 //  SetPlayoutDevice I (II)
1409 // ----------------------------------------------------------------------------
1410 
SetPlayoutDevice(uint16_t index)1411 int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index)
1412 {
1413     CHECK_INITIALIZED();
1414     return (_ptrAudioDevice->SetPlayoutDevice(index));
1415 }
1416 
1417 // ----------------------------------------------------------------------------
1418 //  SetPlayoutDevice II (II)
1419 // ----------------------------------------------------------------------------
1420 
SetPlayoutDevice(WindowsDeviceType device)1421 int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device)
1422 {
1423     if (device == kDefaultDevice)
1424     {
1425     }
1426     else
1427     {
1428     }
1429     CHECK_INITIALIZED();
1430 
1431     return (_ptrAudioDevice->SetPlayoutDevice(device));
1432 }
1433 
1434 // ----------------------------------------------------------------------------
1435 //  PlayoutDeviceName
1436 // ----------------------------------------------------------------------------
1437 
PlayoutDeviceName(uint16_t index,char name[kAdmMaxDeviceNameSize],char guid[kAdmMaxGuidSize])1438 int32_t AudioDeviceModuleImpl::PlayoutDeviceName(
1439     uint16_t index,
1440     char name[kAdmMaxDeviceNameSize],
1441     char guid[kAdmMaxGuidSize])
1442 {
1443     CHECK_INITIALIZED();
1444 
1445     if (name == NULL)
1446     {
1447         _lastError = kAdmErrArgument;
1448         return -1;
1449     }
1450 
1451     if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1)
1452     {
1453         return -1;
1454     }
1455 
1456     if (name != NULL)
1457     {
1458         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1459     }
1460     if (guid != NULL)
1461     {
1462         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1463     }
1464 
1465     return (0);
1466 }
1467 
1468 // ----------------------------------------------------------------------------
1469 //  RecordingDeviceName
1470 // ----------------------------------------------------------------------------
1471 
RecordingDeviceName(uint16_t index,char name[kAdmMaxDeviceNameSize],char guid[kAdmMaxGuidSize])1472 int32_t AudioDeviceModuleImpl::RecordingDeviceName(
1473     uint16_t index,
1474     char name[kAdmMaxDeviceNameSize],
1475     char guid[kAdmMaxGuidSize])
1476 {
1477     CHECK_INITIALIZED();
1478 
1479     if (name == NULL)
1480     {
1481         _lastError = kAdmErrArgument;
1482         return -1;
1483     }
1484 
1485     if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1)
1486     {
1487         return -1;
1488     }
1489 
1490     if (name != NULL)
1491     {
1492         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: name=%s", name);
1493     }
1494     if (guid != NULL)
1495     {
1496         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: guid=%s", guid);
1497     }
1498 
1499     return (0);
1500 }
1501 
1502 // ----------------------------------------------------------------------------
1503 //  RecordingDevices
1504 // ----------------------------------------------------------------------------
1505 
RecordingDevices()1506 int16_t AudioDeviceModuleImpl::RecordingDevices()
1507 {
1508     CHECK_INITIALIZED();
1509 
1510     uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices();
1511 
1512     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
1513                  "output: #recording devices=%d", nRecordingDevices);
1514     return ((int16_t)nRecordingDevices);
1515 }
1516 
1517 // ----------------------------------------------------------------------------
1518 //  SetRecordingDevice I (II)
1519 // ----------------------------------------------------------------------------
1520 
SetRecordingDevice(uint16_t index)1521 int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index)
1522 {
1523     CHECK_INITIALIZED();
1524     return (_ptrAudioDevice->SetRecordingDevice(index));
1525 }
1526 
1527 // ----------------------------------------------------------------------------
1528 //  SetRecordingDevice II (II)
1529 // ----------------------------------------------------------------------------
1530 
SetRecordingDevice(WindowsDeviceType device)1531 int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device)
1532 {
1533     if (device == kDefaultDevice)
1534     {
1535     }
1536     else
1537     {
1538     }
1539     CHECK_INITIALIZED();
1540 
1541     return (_ptrAudioDevice->SetRecordingDevice(device));
1542 }
1543 
1544 // ----------------------------------------------------------------------------
1545 //  InitPlayout
1546 // ----------------------------------------------------------------------------
1547 
InitPlayout()1548 int32_t AudioDeviceModuleImpl::InitPlayout()
1549 {
1550     CHECK_INITIALIZED();
1551     _audioDeviceBuffer.InitPlayout();
1552     return (_ptrAudioDevice->InitPlayout());
1553 }
1554 
1555 // ----------------------------------------------------------------------------
1556 //  InitRecording
1557 // ----------------------------------------------------------------------------
1558 
InitRecording()1559 int32_t AudioDeviceModuleImpl::InitRecording()
1560 {
1561     CHECK_INITIALIZED();
1562     _audioDeviceBuffer.InitRecording();
1563     return (_ptrAudioDevice->InitRecording());
1564 }
1565 
1566 // ----------------------------------------------------------------------------
1567 //  PlayoutIsInitialized
1568 // ----------------------------------------------------------------------------
1569 
PlayoutIsInitialized() const1570 bool AudioDeviceModuleImpl::PlayoutIsInitialized() const
1571 {
1572     CHECK_INITIALIZED_BOOL();
1573     return (_ptrAudioDevice->PlayoutIsInitialized());
1574 }
1575 
1576 // ----------------------------------------------------------------------------
1577 //  RecordingIsInitialized
1578 // ----------------------------------------------------------------------------
1579 
RecordingIsInitialized() const1580 bool AudioDeviceModuleImpl::RecordingIsInitialized() const
1581 {
1582     CHECK_INITIALIZED_BOOL();
1583     return (_ptrAudioDevice->RecordingIsInitialized());
1584 }
1585 
1586 // ----------------------------------------------------------------------------
1587 //  StartPlayout
1588 // ----------------------------------------------------------------------------
1589 
StartPlayout()1590 int32_t AudioDeviceModuleImpl::StartPlayout()
1591 {
1592     CHECK_INITIALIZED();
1593     return (_ptrAudioDevice->StartPlayout());
1594 }
1595 
1596 // ----------------------------------------------------------------------------
1597 //  StopPlayout
1598 // ----------------------------------------------------------------------------
1599 
StopPlayout()1600 int32_t AudioDeviceModuleImpl::StopPlayout()
1601 {
1602     CHECK_INITIALIZED();
1603     return (_ptrAudioDevice->StopPlayout());
1604 }
1605 
1606 // ----------------------------------------------------------------------------
1607 //  Playing
1608 // ----------------------------------------------------------------------------
1609 
Playing() const1610 bool AudioDeviceModuleImpl::Playing() const
1611 {
1612     CHECK_INITIALIZED_BOOL();
1613     return (_ptrAudioDevice->Playing());
1614 }
1615 
1616 // ----------------------------------------------------------------------------
1617 //  StartRecording
1618 // ----------------------------------------------------------------------------
1619 
StartRecording()1620 int32_t AudioDeviceModuleImpl::StartRecording()
1621 {
1622     CHECK_INITIALIZED();
1623     return (_ptrAudioDevice->StartRecording());
1624 }
1625 // ----------------------------------------------------------------------------
1626 //  StopRecording
1627 // ----------------------------------------------------------------------------
1628 
StopRecording()1629 int32_t AudioDeviceModuleImpl::StopRecording()
1630 {
1631     CHECK_INITIALIZED();
1632     return (_ptrAudioDevice->StopRecording());
1633 }
1634 
1635 // ----------------------------------------------------------------------------
1636 //  Recording
1637 // ----------------------------------------------------------------------------
1638 
Recording() const1639 bool AudioDeviceModuleImpl::Recording() const
1640 {
1641     CHECK_INITIALIZED_BOOL();
1642     return (_ptrAudioDevice->Recording());
1643 }
1644 
1645 // ----------------------------------------------------------------------------
1646 //  RegisterEventObserver
1647 // ----------------------------------------------------------------------------
1648 
RegisterEventObserver(AudioDeviceObserver * eventCallback)1649 int32_t AudioDeviceModuleImpl::RegisterEventObserver(AudioDeviceObserver* eventCallback)
1650 {
1651 
1652     CriticalSectionScoped lock(&_critSectEventCb);
1653     _ptrCbAudioDeviceObserver = eventCallback;
1654 
1655     return 0;
1656 }
1657 
1658 // ----------------------------------------------------------------------------
1659 //  RegisterAudioCallback
1660 // ----------------------------------------------------------------------------
1661 
RegisterAudioCallback(AudioTransport * audioCallback)1662 int32_t AudioDeviceModuleImpl::RegisterAudioCallback(AudioTransport* audioCallback)
1663 {
1664 
1665     CriticalSectionScoped lock(&_critSectAudioCb);
1666     _audioDeviceBuffer.RegisterAudioCallback(audioCallback);
1667 
1668     return 0;
1669 }
1670 
1671 // ----------------------------------------------------------------------------
1672 //  StartRawInputFileRecording
1673 // ----------------------------------------------------------------------------
1674 
StartRawInputFileRecording(const char pcmFileNameUTF8[kAdmMaxFileNameSize])1675 int32_t AudioDeviceModuleImpl::StartRawInputFileRecording(
1676     const char pcmFileNameUTF8[kAdmMaxFileNameSize])
1677 {
1678     CHECK_INITIALIZED();
1679 
1680     if (NULL == pcmFileNameUTF8)
1681     {
1682         return -1;
1683     }
1684 
1685     return (_audioDeviceBuffer.StartInputFileRecording(pcmFileNameUTF8));
1686 }
1687 
1688 // ----------------------------------------------------------------------------
1689 //  StopRawInputFileRecording
1690 // ----------------------------------------------------------------------------
1691 
StopRawInputFileRecording()1692 int32_t AudioDeviceModuleImpl::StopRawInputFileRecording()
1693 {
1694     CHECK_INITIALIZED();
1695 
1696     return (_audioDeviceBuffer.StopInputFileRecording());
1697 }
1698 
1699 // ----------------------------------------------------------------------------
1700 //  StartRawOutputFileRecording
1701 // ----------------------------------------------------------------------------
1702 
StartRawOutputFileRecording(const char pcmFileNameUTF8[kAdmMaxFileNameSize])1703 int32_t AudioDeviceModuleImpl::StartRawOutputFileRecording(
1704     const char pcmFileNameUTF8[kAdmMaxFileNameSize])
1705 {
1706     CHECK_INITIALIZED();
1707 
1708     if (NULL == pcmFileNameUTF8)
1709     {
1710         return -1;
1711     }
1712 
1713     return (_audioDeviceBuffer.StartOutputFileRecording(pcmFileNameUTF8));
1714 }
1715 
1716 // ----------------------------------------------------------------------------
1717 //  StopRawOutputFileRecording
1718 // ----------------------------------------------------------------------------
1719 
StopRawOutputFileRecording()1720 int32_t AudioDeviceModuleImpl::StopRawOutputFileRecording()
1721 {
1722     CHECK_INITIALIZED();
1723 
1724     return (_audioDeviceBuffer.StopOutputFileRecording());
1725 }
1726 
1727 // ----------------------------------------------------------------------------
1728 //  SetPlayoutBuffer
1729 // ----------------------------------------------------------------------------
1730 
SetPlayoutBuffer(const BufferType type,uint16_t sizeMS)1731 int32_t AudioDeviceModuleImpl::SetPlayoutBuffer(const BufferType type, uint16_t sizeMS)
1732 {
1733     CHECK_INITIALIZED();
1734 
1735     if (_ptrAudioDevice->PlayoutIsInitialized())
1736     {
1737         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "unable to modify the playout buffer while playing side is initialized");
1738         return -1;
1739     }
1740 
1741     int32_t ret(0);
1742 
1743     if (kFixedBufferSize == type)
1744     {
1745         if (sizeMS < kAdmMinPlayoutBufferSizeMs || sizeMS > kAdmMaxPlayoutBufferSizeMs)
1746         {
1747             WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "size parameter is out of range");
1748             return -1;
1749         }
1750     }
1751 
1752     if ((ret = _ptrAudioDevice->SetPlayoutBuffer(type, sizeMS)) == -1)
1753     {
1754         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to set the playout buffer (error: %d)", LastError());
1755     }
1756 
1757     return ret;
1758 }
1759 
1760 // ----------------------------------------------------------------------------
1761 //  PlayoutBuffer
1762 // ----------------------------------------------------------------------------
1763 
PlayoutBuffer(BufferType * type,uint16_t * sizeMS) const1764 int32_t AudioDeviceModuleImpl::PlayoutBuffer(BufferType* type, uint16_t* sizeMS) const
1765 {
1766     CHECK_INITIALIZED();
1767 
1768     BufferType bufType;
1769     uint16_t size(0);
1770 
1771     if (_ptrAudioDevice->PlayoutBuffer(bufType, size) == -1)
1772     {
1773         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the buffer type and size");
1774         return -1;
1775     }
1776 
1777     *type = bufType;
1778     *sizeMS = size;
1779 
1780     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: type=%u, sizeMS=%u", *type, *sizeMS);
1781     return (0);
1782 }
1783 
1784 // ----------------------------------------------------------------------------
1785 //  PlayoutDelay
1786 // ----------------------------------------------------------------------------
1787 
PlayoutDelay(uint16_t * delayMS) const1788 int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const
1789 {
1790     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1791     CHECK_INITIALIZED();
1792 
1793     uint16_t delay(0);
1794 
1795     if (_ptrAudioDevice->PlayoutDelay(delay) == -1)
1796     {
1797         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the playout delay");
1798         return -1;
1799     }
1800 
1801     *delayMS = delay;
1802 
1803     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1804     return (0);
1805 }
1806 
1807 // ----------------------------------------------------------------------------
1808 //  RecordingDelay
1809 // ----------------------------------------------------------------------------
1810 
RecordingDelay(uint16_t * delayMS) const1811 int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const
1812 {
1813     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "%s", __FUNCTION__);
1814     CHECK_INITIALIZED();
1815 
1816     uint16_t delay(0);
1817 
1818     if (_ptrAudioDevice->RecordingDelay(delay) == -1)
1819     {
1820         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the recording delay");
1821         return -1;
1822     }
1823 
1824     *delayMS = delay;
1825 
1826     WEBRTC_TRACE(kTraceStream, kTraceAudioDevice, _id, "output: delayMS=%u", *delayMS);
1827     return (0);
1828 }
1829 
1830 // ----------------------------------------------------------------------------
1831 //  CPULoad
1832 // ----------------------------------------------------------------------------
1833 
CPULoad(uint16_t * load) const1834 int32_t AudioDeviceModuleImpl::CPULoad(uint16_t* load) const
1835 {
1836     CHECK_INITIALIZED();
1837 
1838     uint16_t cpuLoad(0);
1839 
1840     if (_ptrAudioDevice->CPULoad(cpuLoad) == -1)
1841     {
1842         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the CPU load");
1843         return -1;
1844     }
1845 
1846     *load = cpuLoad;
1847 
1848     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: load=%u", *load);
1849     return (0);
1850 }
1851 
1852 // ----------------------------------------------------------------------------
1853 //  SetRecordingSampleRate
1854 // ----------------------------------------------------------------------------
1855 
SetRecordingSampleRate(const uint32_t samplesPerSec)1856 int32_t AudioDeviceModuleImpl::SetRecordingSampleRate(const uint32_t samplesPerSec)
1857 {
1858     CHECK_INITIALIZED();
1859 
1860     if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0)
1861     {
1862         return -1;
1863     }
1864 
1865     return (0);
1866 }
1867 
1868 // ----------------------------------------------------------------------------
1869 //  RecordingSampleRate
1870 // ----------------------------------------------------------------------------
1871 
RecordingSampleRate(uint32_t * samplesPerSec) const1872 int32_t AudioDeviceModuleImpl::RecordingSampleRate(uint32_t* samplesPerSec) const
1873 {
1874     CHECK_INITIALIZED();
1875 
1876     int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate();
1877 
1878     if (sampleRate == -1)
1879     {
1880         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1881         return -1;
1882     }
1883 
1884     *samplesPerSec = sampleRate;
1885 
1886     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1887     return (0);
1888 }
1889 
1890 // ----------------------------------------------------------------------------
1891 //  SetPlayoutSampleRate
1892 // ----------------------------------------------------------------------------
1893 
SetPlayoutSampleRate(const uint32_t samplesPerSec)1894 int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate(const uint32_t samplesPerSec)
1895 {
1896     CHECK_INITIALIZED();
1897 
1898     if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0)
1899     {
1900         return -1;
1901     }
1902 
1903     return (0);
1904 }
1905 
1906 // ----------------------------------------------------------------------------
1907 //  PlayoutSampleRate
1908 // ----------------------------------------------------------------------------
1909 
PlayoutSampleRate(uint32_t * samplesPerSec) const1910 int32_t AudioDeviceModuleImpl::PlayoutSampleRate(uint32_t* samplesPerSec) const
1911 {
1912     CHECK_INITIALIZED();
1913 
1914     int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate();
1915 
1916     if (sampleRate == -1)
1917     {
1918         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "failed to retrieve the sample rate");
1919         return -1;
1920     }
1921 
1922     *samplesPerSec = sampleRate;
1923 
1924     WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "output: samplesPerSec=%u", *samplesPerSec);
1925     return (0);
1926 }
1927 
1928 // ----------------------------------------------------------------------------
1929 //  ResetAudioDevice
1930 // ----------------------------------------------------------------------------
1931 
ResetAudioDevice()1932 int32_t AudioDeviceModuleImpl::ResetAudioDevice()
1933 {
1934     CHECK_INITIALIZED();
1935 
1936 
1937     if (_ptrAudioDevice->ResetAudioDevice() == -1)
1938     {
1939         return -1;
1940     }
1941 
1942     return (0);
1943 }
1944 
1945 // ----------------------------------------------------------------------------
1946 //  SetLoudspeakerStatus
1947 // ----------------------------------------------------------------------------
1948 
SetLoudspeakerStatus(bool enable)1949 int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable)
1950 {
1951     CHECK_INITIALIZED();
1952 
1953     if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0)
1954     {
1955         return -1;
1956     }
1957 
1958     return 0;
1959 }
1960 
1961 // ----------------------------------------------------------------------------
1962 //  GetLoudspeakerStatus
1963 // ----------------------------------------------------------------------------
1964 
GetLoudspeakerStatus(bool * enabled) const1965 int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const
1966 {
1967     CHECK_INITIALIZED();
1968 
1969     if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0)
1970     {
1971         return -1;
1972     }
1973 
1974     return 0;
1975 }
1976 
EnableBuiltInAEC(bool enable)1977 int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable)
1978 {
1979     CHECK_INITIALIZED();
1980 
1981     return _ptrAudioDevice->EnableBuiltInAEC(enable);
1982 }
1983 
BuiltInAECIsEnabled() const1984 bool AudioDeviceModuleImpl::BuiltInAECIsEnabled() const
1985 {
1986     CHECK_INITIALIZED_BOOL();
1987 
1988     return _ptrAudioDevice->BuiltInAECIsEnabled();
1989 }
1990 
1991 // ============================================================================
1992 //                                 Private Methods
1993 // ============================================================================
1994 
1995 // ----------------------------------------------------------------------------
1996 //  Platform
1997 // ----------------------------------------------------------------------------
1998 
Platform() const1999 AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const
2000 {
2001     return _platformType;
2002 }
2003 
2004 // ----------------------------------------------------------------------------
2005 //  PlatformAudioLayer
2006 // ----------------------------------------------------------------------------
2007 
PlatformAudioLayer() const2008 AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const
2009 {
2010 
2011     switch (_platformAudioLayer)
2012     {
2013     case kPlatformDefaultAudio:
2014         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2015                      "output: kPlatformDefaultAudio");
2016         break;
2017     case kWindowsWaveAudio:
2018         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2019                      "output: kWindowsWaveAudio");
2020         break;
2021     case kWindowsCoreAudio:
2022         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2023                      "output: kWindowsCoreAudio");
2024         break;
2025     case kLinuxAlsaAudio:
2026         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2027                      "output: kLinuxAlsaAudio");
2028         break;
2029     case kDummyAudio:
2030         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id,
2031                      "output: kDummyAudio");
2032         break;
2033     default:
2034         WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
2035                      "output: INVALID");
2036         break;
2037     }
2038 
2039     return _platformAudioLayer;
2040 }
2041 
2042 }  // namespace webrtc
2043