niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011 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 WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_H |
| 12 | #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_H |
| 13 | |
| 14 | #include "module.h" |
| 15 | #include "audio_device_defines.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | class AudioDeviceModule : public Module |
| 20 | { |
| 21 | public: |
| 22 | enum ErrorCode |
| 23 | { |
| 24 | kAdmErrNone = 0, |
| 25 | kAdmErrArgument = 1 |
| 26 | }; |
| 27 | |
| 28 | enum AudioLayer |
| 29 | { |
| 30 | kPlatformDefaultAudio = 0, |
| 31 | kWindowsWaveAudio = 1, |
| 32 | kWindowsCoreAudio = 2, |
| 33 | kLinuxAlsaAudio = 3, |
| 34 | kLinuxPulseAudio = 4, |
| 35 | kDummyAudio = 5 |
| 36 | }; |
| 37 | |
| 38 | enum WindowsDeviceType |
| 39 | { |
| 40 | kDefaultCommunicationDevice = -1, |
| 41 | kDefaultDevice = -2 |
| 42 | }; |
| 43 | |
| 44 | enum BufferType |
| 45 | { |
| 46 | kFixedBufferSize = 0, |
| 47 | kAdaptiveBufferSize = 1 |
| 48 | }; |
| 49 | |
| 50 | enum ChannelType |
| 51 | { |
| 52 | kChannelLeft = 0, |
| 53 | kChannelRight = 1, |
| 54 | kChannelBoth = 2 |
| 55 | }; |
| 56 | |
| 57 | public: |
| 58 | // Factory methods (resource allocation/deallocation) |
| 59 | static AudioDeviceModule* Create( |
| 60 | const int32_t id, |
| 61 | const AudioLayer audioLayer = kPlatformDefaultAudio); |
| 62 | static void Destroy(AudioDeviceModule* module); |
| 63 | |
| 64 | // Retrieve the currently utilized audio layer |
| 65 | virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0; |
| 66 | |
| 67 | // Module methods |
| 68 | static int32_t GetVersion(char* version, |
| 69 | uint32_t& remainingBufferInBytes, |
| 70 | uint32_t& position); |
| 71 | virtual int32_t ChangeUniqueId(const int32_t id) = 0; |
| 72 | |
| 73 | // Error handling |
| 74 | virtual ErrorCode LastError() const = 0; |
| 75 | virtual int32_t RegisterEventObserver( |
| 76 | AudioDeviceObserver* eventCallback) = 0; |
| 77 | |
| 78 | // Full-duplex transportation of PCM audio |
| 79 | virtual int32_t RegisterAudioCallback(AudioTransport* audioCallback) = 0; |
| 80 | |
| 81 | // Main initialization and termination |
| 82 | virtual int32_t Init() = 0; |
| 83 | virtual int32_t Terminate() = 0; |
| 84 | virtual bool Initialized() const = 0; |
| 85 | |
| 86 | // Device enumeration |
| 87 | virtual int16_t PlayoutDevices() = 0; |
| 88 | virtual int16_t RecordingDevices() = 0; |
| 89 | virtual int32_t PlayoutDeviceName(uint16_t index, |
| 90 | char name[kAdmMaxDeviceNameSize], |
| 91 | char guid[kAdmMaxGuidSize]) = 0; |
| 92 | virtual int32_t RecordingDeviceName(uint16_t index, |
| 93 | char name[kAdmMaxDeviceNameSize], |
| 94 | char guid[kAdmMaxGuidSize]) = 0; |
| 95 | |
| 96 | // Device selection |
| 97 | virtual int32_t SetPlayoutDevice(uint16_t index) = 0; |
| 98 | virtual int32_t SetPlayoutDevice(WindowsDeviceType device) = 0; |
| 99 | virtual int32_t SetRecordingDevice(uint16_t index) = 0; |
| 100 | virtual int32_t SetRecordingDevice(WindowsDeviceType device) = 0; |
| 101 | |
| 102 | // Audio transport initialization |
| 103 | virtual int32_t PlayoutIsAvailable(bool* available) = 0; |
| 104 | virtual int32_t InitPlayout() = 0; |
| 105 | virtual bool PlayoutIsInitialized() const = 0; |
| 106 | virtual int32_t RecordingIsAvailable(bool* available) = 0; |
| 107 | virtual int32_t InitRecording() = 0; |
| 108 | virtual bool RecordingIsInitialized() const = 0; |
| 109 | |
| 110 | // Audio transport control |
| 111 | virtual int32_t StartPlayout() = 0; |
| 112 | virtual int32_t StopPlayout() = 0; |
| 113 | virtual bool Playing() const = 0; |
| 114 | virtual int32_t StartRecording() = 0; |
| 115 | virtual int32_t StopRecording() = 0; |
| 116 | virtual bool Recording() const = 0; |
| 117 | |
| 118 | // Microphone Automatic Gain Control (AGC) |
| 119 | virtual int32_t SetAGC(bool enable) = 0; |
| 120 | virtual bool AGC() const = 0; |
| 121 | |
| 122 | // Volume control based on the Windows Wave API (Windows only) |
| 123 | virtual int32_t SetWaveOutVolume(uint16_t volumeLeft, |
| 124 | uint16_t volumeRight) = 0; |
| 125 | virtual int32_t WaveOutVolume(uint16_t* volumeLeft, |
| 126 | uint16_t* volumeRight) const = 0; |
| 127 | |
| 128 | // Audio mixer initialization |
| 129 | virtual int32_t SpeakerIsAvailable(bool* available) = 0; |
| 130 | virtual int32_t InitSpeaker() = 0; |
| 131 | virtual bool SpeakerIsInitialized() const = 0; |
| 132 | virtual int32_t MicrophoneIsAvailable(bool* available) = 0; |
| 133 | virtual int32_t InitMicrophone() = 0; |
| 134 | virtual bool MicrophoneIsInitialized() const = 0; |
| 135 | |
| 136 | // Speaker volume controls |
| 137 | virtual int32_t SpeakerVolumeIsAvailable(bool* available) = 0; |
| 138 | virtual int32_t SetSpeakerVolume(uint32_t volume) = 0; |
| 139 | virtual int32_t SpeakerVolume(uint32_t* volume) const = 0; |
| 140 | virtual int32_t MaxSpeakerVolume(uint32_t* maxVolume) const = 0; |
| 141 | virtual int32_t MinSpeakerVolume(uint32_t* minVolume) const = 0; |
| 142 | virtual int32_t SpeakerVolumeStepSize(uint16_t* stepSize) const = 0; |
| 143 | |
| 144 | // Microphone volume controls |
| 145 | virtual int32_t MicrophoneVolumeIsAvailable(bool* available) = 0; |
| 146 | virtual int32_t SetMicrophoneVolume(uint32_t volume) = 0; |
| 147 | virtual int32_t MicrophoneVolume(uint32_t* volume) const = 0; |
| 148 | virtual int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const = 0; |
| 149 | virtual int32_t MinMicrophoneVolume(uint32_t* minVolume) const = 0; |
| 150 | virtual int32_t MicrophoneVolumeStepSize(uint16_t* stepSize) const = 0; |
| 151 | |
| 152 | // Speaker mute control |
| 153 | virtual int32_t SpeakerMuteIsAvailable(bool* available) = 0; |
| 154 | virtual int32_t SetSpeakerMute(bool enable) = 0; |
| 155 | virtual int32_t SpeakerMute(bool* enabled) const = 0; |
| 156 | |
| 157 | // Microphone mute control |
| 158 | virtual int32_t MicrophoneMuteIsAvailable(bool* available) = 0; |
| 159 | virtual int32_t SetMicrophoneMute(bool enable) = 0; |
| 160 | virtual int32_t MicrophoneMute(bool* enabled) const = 0; |
| 161 | |
| 162 | // Microphone boost control |
| 163 | virtual int32_t MicrophoneBoostIsAvailable(bool* available) = 0; |
| 164 | virtual int32_t SetMicrophoneBoost(bool enable) = 0; |
| 165 | virtual int32_t MicrophoneBoost(bool* enabled) const = 0; |
| 166 | |
| 167 | // Stereo support |
| 168 | virtual int32_t StereoPlayoutIsAvailable(bool* available) const = 0; |
| 169 | virtual int32_t SetStereoPlayout(bool enable) = 0; |
| 170 | virtual int32_t StereoPlayout(bool* enabled) const = 0; |
| 171 | virtual int32_t StereoRecordingIsAvailable(bool* available) const = 0; |
| 172 | virtual int32_t SetStereoRecording(bool enable) = 0; |
| 173 | virtual int32_t StereoRecording(bool* enabled) const = 0; |
| 174 | virtual int32_t SetRecordingChannel(const ChannelType channel) = 0; |
| 175 | virtual int32_t RecordingChannel(ChannelType* channel) const = 0; |
| 176 | |
| 177 | // Delay information and control |
| 178 | virtual int32_t SetPlayoutBuffer(const BufferType type, |
| 179 | uint16_t sizeMS = 0) = 0; |
| 180 | virtual int32_t PlayoutBuffer(BufferType* type, |
| 181 | uint16_t* sizeMS) const = 0; |
| 182 | virtual int32_t PlayoutDelay(uint16_t* delayMS) const = 0; |
| 183 | virtual int32_t RecordingDelay(uint16_t* delayMS) const = 0; |
| 184 | |
| 185 | // CPU load |
| 186 | virtual int32_t CPULoad(uint16_t* load) const = 0; |
| 187 | |
| 188 | // Recording of raw PCM data |
| 189 | virtual int32_t StartRawOutputFileRecording( |
| 190 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) = 0; |
| 191 | virtual int32_t StopRawOutputFileRecording() = 0; |
| 192 | virtual int32_t StartRawInputFileRecording( |
| 193 | const char pcmFileNameUTF8[kAdmMaxFileNameSize]) = 0; |
| 194 | virtual int32_t StopRawInputFileRecording() = 0; |
| 195 | |
| 196 | // Native sample rate controls (samples/sec) |
| 197 | virtual int32_t SetRecordingSampleRate(const uint32_t samplesPerSec) = 0; |
| 198 | virtual int32_t RecordingSampleRate(uint32_t* samplesPerSec) const = 0; |
| 199 | virtual int32_t SetPlayoutSampleRate(const uint32_t samplesPerSec) = 0; |
| 200 | virtual int32_t PlayoutSampleRate(uint32_t* samplesPerSec) const = 0; |
| 201 | |
| 202 | // Mobile device specific functions |
| 203 | virtual int32_t ResetAudioDevice() = 0; |
| 204 | virtual int32_t SetLoudspeakerStatus(bool enable) = 0; |
| 205 | virtual int32_t GetLoudspeakerStatus(bool* enabled) const = 0; |
| 206 | |
| 207 | // Android specific function |
| 208 | static int32_t SetAndroidObjects(void* javaVM, void* env, void* context); |
| 209 | |
| 210 | protected: |
| 211 | virtual ~AudioDeviceModule() {}; |
| 212 | }; |
| 213 | |
| 214 | } // namespace webrtc |
| 215 | |
| 216 | #endif // WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_H |