niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H |
| 12 | #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H |
| 13 | |
| 14 | #include "audio_device.h" |
| 15 | #include "audio_device_buffer.h" |
| 16 | |
| 17 | namespace webrtc |
| 18 | { |
| 19 | |
| 20 | class AudioDeviceGeneric; |
| 21 | class AudioDeviceUtility; |
| 22 | class CriticalSectionWrapper; |
| 23 | |
| 24 | class AudioDeviceModuleImpl : public AudioDeviceModule |
| 25 | { |
| 26 | public: |
| 27 | enum PlatformType |
| 28 | { |
| 29 | kPlatformNotSupported = 0, |
| 30 | kPlatformWin32 = 1, |
| 31 | kPlatformWinCe = 2, |
| 32 | kPlatformLinux = 3, |
leozwang@google.com | 522f42b | 2011-09-19 17:39:05 +0000 | [diff] [blame] | 33 | kPlatformMac = 4, |
| 34 | kPlatformAndroid = 5 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | WebRtc_Word32 CheckPlatform(); |
| 38 | WebRtc_Word32 CreatePlatformSpecificObjects(); |
| 39 | WebRtc_Word32 AttachAudioBuffer(); |
| 40 | |
| 41 | AudioDeviceModuleImpl(const WebRtc_Word32 id, const AudioLayer audioLayer); |
| 42 | virtual ~AudioDeviceModuleImpl(); |
| 43 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 44 | public: // RefCountedModule |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | virtual WebRtc_Word32 TimeUntilNextProcess(); |
| 47 | virtual WebRtc_Word32 Process(); |
| 48 | |
| 49 | public: |
| 50 | // Factory methods (resource allocation/deallocation) |
| 51 | static AudioDeviceModule* Create( |
| 52 | const WebRtc_Word32 id, |
| 53 | const AudioLayer audioLayer = kPlatformDefaultAudio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
| 55 | // Retrieve the currently utilized audio layer |
| 56 | virtual WebRtc_Word32 ActiveAudioLayer(AudioLayer* audioLayer) const; |
| 57 | |
| 58 | // Error handling |
| 59 | virtual ErrorCode LastError() const; |
| 60 | virtual WebRtc_Word32 RegisterEventObserver( |
| 61 | AudioDeviceObserver* eventCallback); |
| 62 | |
| 63 | // Full-duplex transportation of PCM audio |
| 64 | virtual WebRtc_Word32 RegisterAudioCallback( |
| 65 | AudioTransport* audioCallback); |
| 66 | |
| 67 | // Main initializaton and termination |
| 68 | virtual WebRtc_Word32 Init(); |
| 69 | virtual WebRtc_Word32 Terminate(); |
| 70 | virtual bool Initialized() const; |
| 71 | |
| 72 | // Device enumeration |
| 73 | virtual WebRtc_Word16 PlayoutDevices(); |
| 74 | virtual WebRtc_Word16 RecordingDevices(); |
| 75 | virtual WebRtc_Word32 PlayoutDeviceName( |
| 76 | WebRtc_UWord16 index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame^] | 77 | char name[kAdmMaxDeviceNameSize], |
| 78 | char guid[kAdmMaxGuidSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | virtual WebRtc_Word32 RecordingDeviceName( |
| 80 | WebRtc_UWord16 index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame^] | 81 | char name[kAdmMaxDeviceNameSize], |
| 82 | char guid[kAdmMaxGuidSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
| 84 | // Device selection |
| 85 | virtual WebRtc_Word32 SetPlayoutDevice(WebRtc_UWord16 index); |
| 86 | virtual WebRtc_Word32 SetPlayoutDevice(WindowsDeviceType device); |
| 87 | virtual WebRtc_Word32 SetRecordingDevice(WebRtc_UWord16 index); |
| 88 | virtual WebRtc_Word32 SetRecordingDevice(WindowsDeviceType device); |
| 89 | |
| 90 | // Audio transport initialization |
| 91 | virtual WebRtc_Word32 PlayoutIsAvailable(bool* available); |
| 92 | virtual WebRtc_Word32 InitPlayout(); |
| 93 | virtual bool PlayoutIsInitialized() const; |
| 94 | virtual WebRtc_Word32 RecordingIsAvailable(bool* available); |
| 95 | virtual WebRtc_Word32 InitRecording(); |
| 96 | virtual bool RecordingIsInitialized() const; |
| 97 | |
| 98 | // Audio transport control |
| 99 | virtual WebRtc_Word32 StartPlayout(); |
| 100 | virtual WebRtc_Word32 StopPlayout(); |
| 101 | virtual bool Playing() const; |
| 102 | virtual WebRtc_Word32 StartRecording(); |
| 103 | virtual WebRtc_Word32 StopRecording(); |
| 104 | virtual bool Recording() const; |
| 105 | |
| 106 | // Microphone Automatic Gain Control (AGC) |
| 107 | virtual WebRtc_Word32 SetAGC(bool enable); |
| 108 | virtual bool AGC() const; |
| 109 | |
| 110 | // Volume control based on the Windows Wave API (Windows only) |
| 111 | virtual WebRtc_Word32 SetWaveOutVolume(WebRtc_UWord16 volumeLeft, |
| 112 | WebRtc_UWord16 volumeRight); |
| 113 | virtual WebRtc_Word32 WaveOutVolume(WebRtc_UWord16* volumeLeft, |
| 114 | WebRtc_UWord16* volumeRight) const; |
| 115 | |
| 116 | // Audio mixer initialization |
| 117 | virtual WebRtc_Word32 SpeakerIsAvailable(bool* available); |
| 118 | virtual WebRtc_Word32 InitSpeaker(); |
| 119 | virtual bool SpeakerIsInitialized() const; |
| 120 | virtual WebRtc_Word32 MicrophoneIsAvailable(bool* available); |
| 121 | virtual WebRtc_Word32 InitMicrophone(); |
| 122 | virtual bool MicrophoneIsInitialized() const; |
| 123 | |
| 124 | // Speaker volume controls |
| 125 | virtual WebRtc_Word32 SpeakerVolumeIsAvailable(bool* available); |
| 126 | virtual WebRtc_Word32 SetSpeakerVolume(WebRtc_UWord32 volume); |
| 127 | virtual WebRtc_Word32 SpeakerVolume(WebRtc_UWord32* volume) const; |
| 128 | virtual WebRtc_Word32 MaxSpeakerVolume(WebRtc_UWord32* maxVolume) const; |
| 129 | virtual WebRtc_Word32 MinSpeakerVolume(WebRtc_UWord32* minVolume) const; |
| 130 | virtual WebRtc_Word32 SpeakerVolumeStepSize( |
| 131 | WebRtc_UWord16* stepSize) const; |
| 132 | |
| 133 | // Microphone volume controls |
| 134 | virtual WebRtc_Word32 MicrophoneVolumeIsAvailable(bool* available); |
| 135 | virtual WebRtc_Word32 SetMicrophoneVolume(WebRtc_UWord32 volume); |
| 136 | virtual WebRtc_Word32 MicrophoneVolume(WebRtc_UWord32* volume) const; |
| 137 | virtual WebRtc_Word32 MaxMicrophoneVolume( |
| 138 | WebRtc_UWord32* maxVolume) const; |
| 139 | virtual WebRtc_Word32 MinMicrophoneVolume( |
| 140 | WebRtc_UWord32* minVolume) const; |
| 141 | virtual WebRtc_Word32 MicrophoneVolumeStepSize( |
| 142 | WebRtc_UWord16* stepSize) const; |
| 143 | |
| 144 | // Speaker mute control |
| 145 | virtual WebRtc_Word32 SpeakerMuteIsAvailable(bool* available); |
| 146 | virtual WebRtc_Word32 SetSpeakerMute(bool enable); |
| 147 | virtual WebRtc_Word32 SpeakerMute(bool* enabled) const; |
| 148 | |
| 149 | // Microphone mute control |
| 150 | virtual WebRtc_Word32 MicrophoneMuteIsAvailable(bool* available); |
| 151 | virtual WebRtc_Word32 SetMicrophoneMute(bool enable); |
| 152 | virtual WebRtc_Word32 MicrophoneMute(bool* enabled) const; |
| 153 | |
| 154 | // Microphone boost control |
| 155 | virtual WebRtc_Word32 MicrophoneBoostIsAvailable(bool* available); |
| 156 | virtual WebRtc_Word32 SetMicrophoneBoost(bool enable); |
| 157 | virtual WebRtc_Word32 MicrophoneBoost(bool* enabled) const; |
| 158 | |
| 159 | // Stereo support |
| 160 | virtual WebRtc_Word32 StereoPlayoutIsAvailable(bool* available) const; |
| 161 | virtual WebRtc_Word32 SetStereoPlayout(bool enable); |
| 162 | virtual WebRtc_Word32 StereoPlayout(bool* enabled) const; |
| 163 | virtual WebRtc_Word32 StereoRecordingIsAvailable(bool* available) const; |
| 164 | virtual WebRtc_Word32 SetStereoRecording(bool enable); |
| 165 | virtual WebRtc_Word32 StereoRecording(bool* enabled) const; |
| 166 | virtual WebRtc_Word32 SetRecordingChannel(const ChannelType channel); |
| 167 | virtual WebRtc_Word32 RecordingChannel(ChannelType* channel) const; |
| 168 | |
| 169 | // Delay information and control |
| 170 | virtual WebRtc_Word32 SetPlayoutBuffer(const BufferType type, |
| 171 | WebRtc_UWord16 sizeMS = 0); |
| 172 | virtual WebRtc_Word32 PlayoutBuffer(BufferType* type, |
| 173 | WebRtc_UWord16* sizeMS) const; |
| 174 | virtual WebRtc_Word32 PlayoutDelay(WebRtc_UWord16* delayMS) const; |
| 175 | virtual WebRtc_Word32 RecordingDelay(WebRtc_UWord16* delayMS) const; |
| 176 | |
| 177 | // CPU load |
| 178 | virtual WebRtc_Word32 CPULoad(WebRtc_UWord16* load) const; |
| 179 | |
| 180 | // Recording of raw PCM data |
| 181 | virtual WebRtc_Word32 StartRawOutputFileRecording( |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame^] | 182 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | virtual WebRtc_Word32 StopRawOutputFileRecording(); |
| 184 | virtual WebRtc_Word32 StartRawInputFileRecording( |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame^] | 185 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | virtual WebRtc_Word32 StopRawInputFileRecording(); |
| 187 | |
| 188 | // Native sample rate controls (samples/sec) |
| 189 | virtual WebRtc_Word32 SetRecordingSampleRate( |
| 190 | const WebRtc_UWord32 samplesPerSec); |
| 191 | virtual WebRtc_Word32 RecordingSampleRate( |
| 192 | WebRtc_UWord32* samplesPerSec) const; |
| 193 | virtual WebRtc_Word32 SetPlayoutSampleRate( |
| 194 | const WebRtc_UWord32 samplesPerSec); |
| 195 | virtual WebRtc_Word32 PlayoutSampleRate( |
| 196 | WebRtc_UWord32* samplesPerSec) const; |
| 197 | |
| 198 | // Mobile device specific functions |
| 199 | virtual WebRtc_Word32 ResetAudioDevice(); |
| 200 | virtual WebRtc_Word32 SetLoudspeakerStatus(bool enable); |
| 201 | virtual WebRtc_Word32 GetLoudspeakerStatus(bool* enabled) const; |
| 202 | |
andrew@webrtc.org | a3c6d61 | 2011-09-13 17:17:49 +0000 | [diff] [blame] | 203 | virtual int32_t EnableBuiltInAEC(bool enable); |
| 204 | virtual bool BuiltInAECIsEnabled() const; |
| 205 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | public: |
| 207 | WebRtc_Word32 Id() {return _id;} |
| 208 | |
| 209 | private: |
| 210 | PlatformType Platform() const; |
| 211 | AudioLayer PlatformAudioLayer() const; |
| 212 | |
| 213 | private: |
| 214 | CriticalSectionWrapper& _critSect; |
| 215 | CriticalSectionWrapper& _critSectEventCb; |
| 216 | CriticalSectionWrapper& _critSectAudioCb; |
| 217 | |
| 218 | AudioDeviceObserver* _ptrCbAudioDeviceObserver; |
| 219 | |
| 220 | AudioDeviceUtility* _ptrAudioDeviceUtility; |
| 221 | AudioDeviceGeneric* _ptrAudioDevice; |
| 222 | |
| 223 | AudioDeviceBuffer _audioDeviceBuffer; |
| 224 | |
| 225 | WebRtc_Word32 _id; |
| 226 | AudioLayer _platformAudioLayer; |
| 227 | WebRtc_UWord32 _lastProcessTime; |
| 228 | PlatformType _platformType; |
| 229 | bool _initialized; |
| 230 | mutable ErrorCode _lastError; |
| 231 | }; |
| 232 | |
| 233 | } // namespace webrtc |
| 234 | |
| 235 | #endif // WEBRTC_MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_ |