fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
a1b926e
main
1/* 2* Copyright 2023 LiveKit 3* 4* Licensed under the Apache License, Version 2.0 (the “License”); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an “AS IS” BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16 17#pragma once 18 19#include <atomic> 20 21#include "api/task_queue/task_queue_factory.h" 22#include "api/task_queue/task_queue_base.h" 23#include "modules/audio_device/include/audio_device.h" 24#include "rtc_base/synchronization/mutex.h" 25#include "rtc_base/task_utils/repeating_task.h" 26 27namespace livekit { 28 29class AudioDevice :public webrtc ::AudioDeviceModule { 30public : 31AudioDevice (webrtc ::TaskQueueFactory * task_queue_factory ); 32 ~AudioDevice ()override ; 33 34int32_t ActiveAudioLayer (AudioLayer * audioLayer )const override ; 35int32_t RegisterAudioCallback (webrtc ::AudioTransport * transport )override ; 36 37int32_t Init ()override ; 38int32_t Terminate () override; 39bool Initialized () const override; 40 41int16_t PlayoutDevices () override; 42int16_t RecordingDevices () override; 43int32_t PlayoutDeviceName ( uint16_t index, 44char name[webrtc::kAdmMaxDeviceNameSize], 45char guid[webrtc::kAdmMaxGuidSize]) override; 46 47int32_t RecordingDeviceName ( uint16_t index, 48char name[webrtc::kAdmMaxDeviceNameSize], 49char guid[webrtc::kAdmMaxGuidSize]) override; 50 51int32_t SetPlayoutDevice ( uint16_t index) override; 52int32_t SetPlayoutDevice ( WindowsDeviceType device) override; 53int32_t SetRecordingDevice ( uint16_t index) override; 54int32_t SetRecordingDevice ( WindowsDeviceType device) override; 55 56int32_t PlayoutIsAvailable ( bool * available) override; 57int32_t InitPlayout () override; 58bool PlayoutIsInitialized () const override; 59int32_t RecordingIsAvailable ( bool * available) override; 60int32_t InitRecording () override; 61bool RecordingIsInitialized () const override; 62 63int32_t StartPlayout () override; 64int32_t StopPlayout () override; 65bool Playing () const override; 66int32_t StartRecording () override; 67int32_t StopRecording () override; 68bool Recording () const override; 69 70int32_t InitSpeaker () override; 71bool SpeakerIsInitialized () const override; 72int32_t InitMicrophone () override; 73bool MicrophoneIsInitialized () const override; 74 75int32_t SpeakerVolumeIsAvailable ( bool * available) override; 76int32_t SetSpeakerVolume ( uint32_t volume) override; 77int32_t SpeakerVolume ( uint32_t * volume) const override; 78int32_t MaxSpeakerVolume ( uint32_t * maxVolume) const override; 79int32_t MinSpeakerVolume ( uint32_t * minVolume) const override; 80 81int32_t MicrophoneVolumeIsAvailable ( bool * available) override; 82int32_t SetMicrophoneVolume ( uint32_t volume) override; 83int32_t MicrophoneVolume ( uint32_t * volume) const override; 84int32_t MaxMicrophoneVolume ( uint32_t * maxVolume) const override; 85int32_t MinMicrophoneVolume ( uint32_t * minVolume) const override; 86 87int32_t SpeakerMuteIsAvailable ( bool * available) override; 88int32_t SetSpeakerMute ( bool enable) override; 89int32_t SpeakerMute ( bool * enabled) const override; 90 91int32_t MicrophoneMuteIsAvailable ( bool * available) override; 92int32_t SetMicrophoneMute ( bool enable) override; 93int32_t MicrophoneMute ( bool * enabled) const override; 94 95int32_t StereoPlayoutIsAvailable ( bool * available) const override; 96int32_t SetStereoPlayout ( bool enable) override; 97int32_t StereoPlayout ( bool * enabled) const override; 98int32_t StereoRecordingIsAvailable ( bool * available) const override; 99int32_t SetStereoRecording ( bool enable) override; 100int32_t StereoRecording ( bool * enabled) const override; 101 102int32_t PlayoutDelay ( uint16_t * delayMS) const override; 103 104bool BuiltInAECIsAvailable () const override; 105bool BuiltInAGCIsAvailable () const override; 106bool BuiltInNSIsAvailable () const override; 107 108int32_t EnableBuiltInAEC ( bool enable) override; 109int32_t EnableBuiltInAGC ( bool enable) override; 110int32_t EnableBuiltInNS ( bool enable) override; 111 112#if defined( WEBRTC_IOS ) 113int GetPlayoutAudioParameters ( webrtc ::AudioParameters * params) const override; 114int GetRecordAudioParameters ( webrtc ::AudioParameters * params) const override; 115#endif // WEBRTC_IOS 116 117int32_t SetAudioDeviceSink ( webrtc ::AudioDeviceSink * sink) const override; 118 119private: 120mutable webrtc::Mutex mutex_; 121std ::vector < int16_t > data_; 122std ::unique_ptr < webrtc::TaskQueueBase, webrtc::TaskQueueDeleter > audio_queue_; 123webrtc ::RepeatingTaskHandle audio_task_; 124webrtc ::AudioTransport * audio_transport_; 125webrtc ::TaskQueueFactory * task_queue_factory_; 126bool playing_{false}; 127bool initialized_{false}; 128}; 129} // namespace livekit