Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/modules/audio_device/audio_device_impl.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

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