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 | |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame^] | 14 | #include "webrtc/modules/audio_device/audio_device_buffer.h" |
| 15 | #include "webrtc/modules/audio_device/include/audio_device.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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, |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 34 | kPlatformAndroid = 5, |
| 35 | kPlatformIOS = 6 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 38 | int32_t CheckPlatform(); |
| 39 | int32_t CreatePlatformSpecificObjects(); |
| 40 | int32_t AttachAudioBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 42 | AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | virtual ~AudioDeviceModuleImpl(); |
| 44 | |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 45 | public: // RefCountedModule |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 46 | virtual int32_t ChangeUniqueId(const int32_t id); |
| 47 | virtual int32_t TimeUntilNextProcess(); |
| 48 | virtual int32_t Process(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
| 50 | public: |
| 51 | // Factory methods (resource allocation/deallocation) |
| 52 | static AudioDeviceModule* Create( |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 53 | const int32_t id, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | const AudioLayer audioLayer = kPlatformDefaultAudio); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
| 56 | // Retrieve the currently utilized audio layer |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 57 | virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
| 59 | // Error handling |
| 60 | virtual ErrorCode LastError() const; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 61 | virtual int32_t RegisterEventObserver( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | AudioDeviceObserver* eventCallback); |
| 63 | |
| 64 | // Full-duplex transportation of PCM audio |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 65 | virtual int32_t RegisterAudioCallback( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | AudioTransport* audioCallback); |
| 67 | |
| 68 | // Main initializaton and termination |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 69 | virtual int32_t Init(); |
| 70 | virtual int32_t Terminate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | virtual bool Initialized() const; |
| 72 | |
| 73 | // Device enumeration |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 74 | virtual int16_t PlayoutDevices(); |
| 75 | virtual int16_t RecordingDevices(); |
| 76 | virtual int32_t PlayoutDeviceName( |
| 77 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 78 | char name[kAdmMaxDeviceNameSize], |
| 79 | char guid[kAdmMaxGuidSize]); |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 80 | virtual int32_t RecordingDeviceName( |
| 81 | uint16_t index, |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 82 | char name[kAdmMaxDeviceNameSize], |
| 83 | char guid[kAdmMaxGuidSize]); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
| 85 | // Device selection |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 86 | virtual int32_t SetPlayoutDevice(uint16_t index); |
| 87 | virtual int32_t SetPlayoutDevice(WindowsDeviceType device); |
| 88 | virtual int32_t SetRecordingDevice(uint16_t index); |
| 89 | virtual int32_t SetRecordingDevice(WindowsDeviceType device); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
| 91 | // Audio transport initialization |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 92 | virtual int32_t PlayoutIsAvailable(bool* available); |
| 93 | virtual int32_t InitPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | virtual bool PlayoutIsInitialized() const; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 95 | virtual int32_t RecordingIsAvailable(bool* available); |
| 96 | virtual int32_t InitRecording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | virtual bool RecordingIsInitialized() const; |
| 98 | |
| 99 | // Audio transport control |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 100 | virtual int32_t StartPlayout(); |
| 101 | virtual int32_t StopPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | virtual bool Playing() const; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 103 | virtual int32_t StartRecording(); |
| 104 | virtual int32_t StopRecording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | virtual bool Recording() const; |
| 106 | |
| 107 | // Microphone Automatic Gain Control (AGC) |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 108 | virtual int32_t SetAGC(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | virtual bool AGC() const; |
| 110 | |
| 111 | // Volume control based on the Windows Wave API (Windows only) |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 112 | virtual int32_t SetWaveOutVolume(uint16_t volumeLeft, uint16_t volumeRight); |
| 113 | virtual int32_t WaveOutVolume(uint16_t* volumeLeft, |
| 114 | uint16_t* volumeRight) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
| 116 | // Audio mixer initialization |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 117 | virtual int32_t SpeakerIsAvailable(bool* available); |
| 118 | virtual int32_t InitSpeaker(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | virtual bool SpeakerIsInitialized() const; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 120 | virtual int32_t MicrophoneIsAvailable(bool* available); |
| 121 | virtual int32_t InitMicrophone(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | virtual bool MicrophoneIsInitialized() const; |
| 123 | |
| 124 | // Speaker volume controls |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 125 | virtual int32_t SpeakerVolumeIsAvailable(bool* available); |
| 126 | virtual int32_t SetSpeakerVolume(uint32_t volume); |
| 127 | virtual int32_t SpeakerVolume(uint32_t* volume) const; |
| 128 | virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const; |
| 129 | virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const; |
| 130 | virtual int32_t SpeakerVolumeStepSize( |
| 131 | uint16_t* stepSize) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
| 133 | // Microphone volume controls |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 134 | virtual int32_t MicrophoneVolumeIsAvailable(bool* available); |
| 135 | virtual int32_t SetMicrophoneVolume(uint32_t volume); |
| 136 | virtual int32_t MicrophoneVolume(uint32_t* volume) const; |
| 137 | virtual int32_t MaxMicrophoneVolume( |
| 138 | uint32_t* maxVolume) const; |
| 139 | virtual int32_t MinMicrophoneVolume( |
| 140 | uint32_t* minVolume) const; |
| 141 | virtual int32_t MicrophoneVolumeStepSize( |
| 142 | uint16_t* stepSize) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | |
| 144 | // Speaker mute control |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 145 | virtual int32_t SpeakerMuteIsAvailable(bool* available); |
| 146 | virtual int32_t SetSpeakerMute(bool enable); |
| 147 | virtual int32_t SpeakerMute(bool* enabled) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | |
| 149 | // Microphone mute control |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 150 | virtual int32_t MicrophoneMuteIsAvailable(bool* available); |
| 151 | virtual int32_t SetMicrophoneMute(bool enable); |
| 152 | virtual int32_t MicrophoneMute(bool* enabled) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | |
| 154 | // Microphone boost control |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 155 | virtual int32_t MicrophoneBoostIsAvailable(bool* available); |
| 156 | virtual int32_t SetMicrophoneBoost(bool enable); |
| 157 | virtual int32_t MicrophoneBoost(bool* enabled) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | |
| 159 | // Stereo support |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 160 | virtual int32_t StereoPlayoutIsAvailable(bool* available) const; |
| 161 | virtual int32_t SetStereoPlayout(bool enable); |
| 162 | virtual int32_t StereoPlayout(bool* enabled) const; |
| 163 | virtual int32_t StereoRecordingIsAvailable(bool* available) const; |
| 164 | virtual int32_t SetStereoRecording(bool enable); |
| 165 | virtual int32_t StereoRecording(bool* enabled) const; |
| 166 | virtual int32_t SetRecordingChannel(const ChannelType channel); |
| 167 | virtual int32_t RecordingChannel(ChannelType* channel) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | |
| 169 | // Delay information and control |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 170 | virtual int32_t SetPlayoutBuffer(const BufferType type, |
| 171 | uint16_t sizeMS = 0); |
| 172 | virtual int32_t PlayoutBuffer(BufferType* type, |
| 173 | uint16_t* sizeMS) const; |
| 174 | virtual int32_t PlayoutDelay(uint16_t* delayMS) const; |
| 175 | virtual int32_t RecordingDelay(uint16_t* delayMS) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | |
| 177 | // CPU load |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 178 | virtual int32_t CPULoad(uint16_t* load) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
| 180 | // Recording of raw PCM data |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 181 | virtual int32_t StartRawOutputFileRecording( |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 182 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]); |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 183 | virtual int32_t StopRawOutputFileRecording(); |
| 184 | virtual int32_t StartRawInputFileRecording( |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 185 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]); |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 186 | virtual int32_t StopRawInputFileRecording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 187 | |
| 188 | // Native sample rate controls (samples/sec) |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 189 | virtual int32_t SetRecordingSampleRate( |
| 190 | const uint32_t samplesPerSec); |
| 191 | virtual int32_t RecordingSampleRate( |
| 192 | uint32_t* samplesPerSec) const; |
| 193 | virtual int32_t SetPlayoutSampleRate( |
| 194 | const uint32_t samplesPerSec); |
| 195 | virtual int32_t PlayoutSampleRate( |
| 196 | uint32_t* samplesPerSec) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | |
| 198 | // Mobile device specific functions |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 199 | virtual int32_t ResetAudioDevice(); |
| 200 | virtual int32_t SetLoudspeakerStatus(bool enable); |
| 201 | virtual int32_t GetLoudspeakerStatus(bool* enabled) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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: |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 207 | int32_t Id() {return _id;} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 225 | int32_t _id; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 226 | AudioLayer _platformAudioLayer; |
pbos@webrtc.org | 2550988 | 2013-04-09 10:30:35 +0000 | [diff] [blame] | 227 | uint32_t _lastProcessTime; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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_ |