• 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 #ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
12 #define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
13 
14 #include "api/scoped_refptr.h"
15 #include "api/task_queue/task_queue_factory.h"
16 #include "modules/audio_device/include/audio_device_defines.h"
17 #include "rtc_base/ref_count.h"
18 
19 namespace webrtc {
20 
21 class AudioDeviceModuleForTest;
22 
23 class AudioDeviceModule : public rtc::RefCountInterface {
24  public:
25   enum AudioLayer {
26     kPlatformDefaultAudio = 0,
27     kWindowsCoreAudio,
28     kWindowsCoreAudio2,
29     kLinuxAlsaAudio,
30     kLinuxPulseAudio,
31     kAndroidJavaAudio,
32     kAndroidOpenSLESAudio,
33     kAndroidJavaInputAndOpenSLESOutputAudio,
34     kAndroidAAudioAudio,
35     kAndroidJavaInputAndAAudioOutputAudio,
36     kDummyAudio,
37   };
38 
39   enum WindowsDeviceType {
40     kDefaultCommunicationDevice = -1,
41     kDefaultDevice = -2
42   };
43 
44  public:
45   // Creates a default ADM for usage in production code.
46   static rtc::scoped_refptr<AudioDeviceModule> Create(
47       AudioLayer audio_layer,
48       TaskQueueFactory* task_queue_factory);
49   // Creates an ADM with support for extra test methods. Don't use this factory
50   // in production code.
51   static rtc::scoped_refptr<AudioDeviceModuleForTest> CreateForTest(
52       AudioLayer audio_layer,
53       TaskQueueFactory* task_queue_factory);
54 
55   // Retrieve the currently utilized audio layer
56   virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0;
57 
58   // Full-duplex transportation of PCM audio
59   virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0;
60 
61   // Main initialization and termination
62   virtual int32_t Init() = 0;
63   virtual int32_t Terminate() = 0;
64   virtual bool Initialized() const = 0;
65 
66   // Device enumeration
67   virtual int16_t PlayoutDevices() = 0;
68   virtual int16_t RecordingDevices() = 0;
69   virtual int32_t PlayoutDeviceName(uint16_t index,
70                                     char name[kAdmMaxDeviceNameSize],
71                                     char guid[kAdmMaxGuidSize]) = 0;
72   virtual int32_t RecordingDeviceName(uint16_t index,
73                                       char name[kAdmMaxDeviceNameSize],
74                                       char guid[kAdmMaxGuidSize]) = 0;
75 
76   // Device selection
77   virtual int32_t SetPlayoutDevice(uint16_t index) = 0;
78   virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0;
79   virtual int32_t SetRecordingDevice(uint16_t index) = 0;
80   virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0;
81 
82   // Audio transport initialization
83   virtual int32_t PlayoutIsAvailable(bool* available) = 0;
84   virtual int32_t InitPlayout() = 0;
85   virtual bool PlayoutIsInitialized() const = 0;
86   virtual int32_t RecordingIsAvailable(bool* available) = 0;
87   virtual int32_t InitRecording() = 0;
88   virtual bool RecordingIsInitialized() const = 0;
89 
90   // Audio transport control
91   virtual int32_t StartPlayout() = 0;
92   virtual int32_t StopPlayout() = 0;
93   virtual bool Playing() const = 0;
94   virtual int32_t StartRecording() = 0;
95   virtual int32_t StopRecording() = 0;
96   virtual bool Recording() const = 0;
97 
98   // Audio mixer initialization
99   virtual int32_t InitSpeaker() = 0;
100   virtual bool SpeakerIsInitialized() const = 0;
101   virtual int32_t InitMicrophone() = 0;
102   virtual bool MicrophoneIsInitialized() const = 0;
103 
104   // Speaker volume controls
105   virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0;
106   virtual int32_t SetSpeakerVolume(uint32_t volume) = 0;
107   virtual int32_t SpeakerVolume(uint32_t* volume) const = 0;
108   virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0;
109   virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0;
110 
111   // Microphone volume controls
112   virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0;
113   virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0;
114   virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0;
115   virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0;
116   virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0;
117 
118   // Speaker mute control
119   virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0;
120   virtual int32_t SetSpeakerMute(bool enable) = 0;
121   virtual int32_t SpeakerMute(bool* enabled) const = 0;
122 
123   // Microphone mute control
124   virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0;
125   virtual int32_t SetMicrophoneMute(bool enable) = 0;
126   virtual int32_t MicrophoneMute(bool* enabled) const = 0;
127 
128   // Stereo support
129   virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0;
130   virtual int32_t SetStereoPlayout(bool enable) = 0;
131   virtual int32_t StereoPlayout(bool* enabled) const = 0;
132   virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0;
133   virtual int32_t SetStereoRecording(bool enable) = 0;
134   virtual int32_t StereoRecording(bool* enabled) const = 0;
135 
136   // Playout delay
137   virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0;
138 
139   // Only supported on Android.
140   virtual bool BuiltInAECIsAvailable() const = 0;
141   virtual bool BuiltInAGCIsAvailable() const = 0;
142   virtual bool BuiltInNSIsAvailable() const = 0;
143 
144   // Enables the built-in audio effects. Only supported on Android.
145   virtual int32_t EnableBuiltInAEC(bool enable) = 0;
146   virtual int32_t EnableBuiltInAGC(bool enable) = 0;
147   virtual int32_t EnableBuiltInNS(bool enable) = 0;
148 
149   // Play underrun count. Only supported on Android.
150   // TODO(alexnarest): Make it abstract after upstream projects support it.
GetPlayoutUnderrunCount()151   virtual int32_t GetPlayoutUnderrunCount() const { return -1; }
152 
153 // Only supported on iOS.
154 #if defined(WEBRTC_IOS)
155   virtual int GetPlayoutAudioParameters(AudioParameters* params) const = 0;
156   virtual int GetRecordAudioParameters(AudioParameters* params) const = 0;
157 #endif  // WEBRTC_IOS
158 
159  protected:
~AudioDeviceModule()160   ~AudioDeviceModule() override {}
161 };
162 
163 // Extends the default ADM interface with some extra test methods.
164 // Intended for usage in tests only and requires a unique factory method.
165 class AudioDeviceModuleForTest : public AudioDeviceModule {
166  public:
167   // Triggers internal restart sequences of audio streaming. Can be used by
168   // tests to emulate events corresponding to e.g. removal of an active audio
169   // device or other actions which causes the stream to be disconnected.
170   virtual int RestartPlayoutInternally() = 0;
171   virtual int RestartRecordingInternally() = 0;
172 
173   virtual int SetPlayoutSampleRate(uint32_t sample_rate) = 0;
174   virtual int SetRecordingSampleRate(uint32_t sample_rate) = 0;
175 };
176 
177 }  // namespace webrtc
178 
179 #endif  // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_H_
180