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