audio_device_impl.h (6906B)
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_AUDIO_DEVICE_IMPL_H_ 12 #define MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ 13 14 #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) 15 16 #include <cstdint> 17 #include <memory> 18 19 #include "absl/base/nullability.h" 20 #include "api/audio/audio_device.h" 21 #include "api/audio/audio_device_defines.h" 22 #include "api/environment/environment.h" 23 #include "api/scoped_refptr.h" 24 #include "modules/audio_device/audio_device_buffer.h" 25 26 namespace webrtc { 27 28 class AudioDeviceGeneric; 29 30 class AudioDeviceModuleImpl : public AudioDeviceModuleForTest { 31 public: 32 enum PlatformType { 33 kPlatformNotSupported = 0, 34 kPlatformWin32 = 1, 35 kPlatformWinCe = 2, 36 kPlatformLinux = 3, 37 kPlatformMac = 4, 38 kPlatformAndroid = 5, 39 kPlatformIOS = 6, 40 // Fuchsia isn't fully supported, as there is no implementation for 41 // AudioDeviceGeneric which will be created for Fuchsia, so 42 // `CreatePlatformSpecificObjects()` call will fail unless usable 43 // implementation will be provided by the user. 44 kPlatformFuchsia = 7, 45 }; 46 47 static absl_nullable scoped_refptr<AudioDeviceModuleImpl> Create( 48 const Environment& env, 49 AudioLayer audio_layer); 50 51 AudioDeviceModuleImpl(const Environment& env, AudioLayer audio_layer); 52 // If `create_detached` is true, created ADM can be used on another thread 53 // compared to the one on which it was created. It's useful for testing. 54 AudioDeviceModuleImpl(const Environment& env, 55 AudioLayer audio_layer, 56 std::unique_ptr<AudioDeviceGeneric> audio_device, 57 bool create_detached); 58 ~AudioDeviceModuleImpl() override; 59 60 int32_t CheckPlatform(); 61 int32_t CreatePlatformSpecificObjects(const Environment& env); 62 int32_t AttachAudioBuffer(); 63 64 // Retrieve the currently utilized audio layer 65 int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override; 66 67 // Full-duplex transportation of PCM audio 68 int32_t RegisterAudioCallback(AudioTransport* audioCallback) override; 69 70 // Main initializaton and termination 71 int32_t Init() override; 72 int32_t Terminate() override; 73 bool Initialized() const override; 74 75 // Device enumeration 76 int16_t PlayoutDevices() override; 77 int16_t RecordingDevices() override; 78 int32_t PlayoutDeviceName(uint16_t index, 79 char name[kAdmMaxDeviceNameSize], 80 char guid[kAdmMaxGuidSize]) override; 81 int32_t RecordingDeviceName(uint16_t index, 82 char name[kAdmMaxDeviceNameSize], 83 char guid[kAdmMaxGuidSize]) override; 84 85 // Device selection 86 int32_t SetPlayoutDevice(uint16_t index) override; 87 int32_t SetPlayoutDevice(WindowsDeviceType device) override; 88 int32_t SetRecordingDevice(uint16_t index) override; 89 int32_t SetRecordingDevice(WindowsDeviceType device) override; 90 91 // Audio transport initialization 92 int32_t PlayoutIsAvailable(bool* available) override; 93 int32_t InitPlayout() override; 94 bool PlayoutIsInitialized() const override; 95 int32_t RecordingIsAvailable(bool* available) override; 96 int32_t InitRecording() override; 97 bool RecordingIsInitialized() const override; 98 99 // Audio transport control 100 int32_t StartPlayout() override; 101 int32_t StopPlayout() override; 102 bool Playing() const override; 103 int32_t StartRecording() override; 104 int32_t StopRecording() override; 105 bool Recording() const override; 106 107 // Audio mixer initialization 108 int32_t InitSpeaker() override; 109 bool SpeakerIsInitialized() const override; 110 int32_t InitMicrophone() override; 111 bool MicrophoneIsInitialized() const override; 112 113 // Speaker volume controls 114 int32_t SpeakerVolumeIsAvailable(bool* available) override; 115 int32_t SetSpeakerVolume(uint32_t volume) override; 116 int32_t SpeakerVolume(uint32_t* volume) const override; 117 int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override; 118 int32_t MinSpeakerVolume(uint32_t* minVolume) const override; 119 120 // Microphone volume controls 121 int32_t MicrophoneVolumeIsAvailable(bool* available) override; 122 int32_t SetMicrophoneVolume(uint32_t volume) override; 123 int32_t MicrophoneVolume(uint32_t* volume) const override; 124 int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override; 125 int32_t MinMicrophoneVolume(uint32_t* minVolume) const override; 126 127 // Speaker mute control 128 int32_t SpeakerMuteIsAvailable(bool* available) override; 129 int32_t SetSpeakerMute(bool enable) override; 130 int32_t SpeakerMute(bool* enabled) const override; 131 132 // Microphone mute control 133 int32_t MicrophoneMuteIsAvailable(bool* available) override; 134 int32_t SetMicrophoneMute(bool enable) override; 135 int32_t MicrophoneMute(bool* enabled) const override; 136 137 // Stereo support 138 int32_t StereoPlayoutIsAvailable(bool* available) const override; 139 int32_t SetStereoPlayout(bool enable) override; 140 int32_t StereoPlayout(bool* enabled) const override; 141 int32_t StereoRecordingIsAvailable(bool* available) const override; 142 int32_t SetStereoRecording(bool enable) override; 143 int32_t StereoRecording(bool* enabled) const override; 144 145 // Delay information and control 146 int32_t PlayoutDelay(uint16_t* delayMS) const override; 147 148 bool BuiltInAECIsAvailable() const override; 149 int32_t EnableBuiltInAEC(bool enable) override; 150 bool BuiltInAGCIsAvailable() const override; 151 int32_t EnableBuiltInAGC(bool enable) override; 152 bool BuiltInNSIsAvailable() const override; 153 int32_t EnableBuiltInNS(bool enable) override; 154 155 // Play underrun count. 156 int32_t GetPlayoutUnderrunCount() const override; 157 158 #if defined(WEBRTC_IOS) 159 int GetPlayoutAudioParameters(AudioParameters* params) const override; 160 int GetRecordAudioParameters(AudioParameters* params) const override; 161 #endif // WEBRTC_IOS 162 163 AudioDeviceBuffer* GetAudioDeviceBuffer() { return &audio_device_buffer_; } 164 165 int RestartPlayoutInternally() override { return -1; } 166 int RestartRecordingInternally() override { return -1; } 167 int SetPlayoutSampleRate(uint32_t /* sample_rate */) override { return -1; } 168 int SetRecordingSampleRate(uint32_t /* sample_rate */) override { return -1; } 169 170 private: 171 PlatformType Platform() const; 172 AudioLayer PlatformAudioLayer() const; 173 174 AudioLayer audio_layer_; 175 PlatformType platform_type_ = kPlatformNotSupported; 176 bool initialized_ = false; 177 AudioDeviceBuffer audio_device_buffer_; 178 std::unique_ptr<AudioDeviceGeneric> audio_device_; 179 }; 180 181 } // namespace webrtc 182 183 #endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) 184 185 #endif // MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_