fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
a1b926e
livekit/livekit-ffi@0.13.0
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#include "livekit/audio_device.h" 18 19const int kSampleRate = 48000 ; 20const int kChannels = 2 ; 21const int kBytesPerSample = kChannels * sizeof (int16_t ); 22const int kSamplesPer10Ms = kSampleRate /100 ; 23 24namespace livekit { 25 26AudioDevice ::AudioDevice (webrtc::TaskQueueFactory * task_queue_factory ) 27 :task_queue_factory_ (task_queue_factory ), 28data_ (kSamplesPer10Ms * kChannels ) {} 29 30AudioDevice ::~AudioDevice () { 31Terminate (); 32} 33 34int32_t AudioDevice ::ActiveAudioLayer (AudioLayer * audioLayer )const { 35* audioLayer = AudioLayer ::kDummyAudio ; 36return 0 ; 37} 38 39int32_t AudioDevice ::RegisterAudioCallback (webrtc::AudioTransport * transport ) { 40 webrtc::MutexLock lock (& mutex_ ); 41audio_transport_ = transport ; 42return 0 ; 43} 44 45int32_t AudioDevice ::Init () { 46 webrtc::MutexLock lock (& mutex_ ); 47if (initialized_ ) 48return 0 ; 49 50audio_queue_ = 51task_queue_factory_ -> CreateTaskQueue ( 52"AudioDevice" , webrtc::TaskQueueFactory ::Priority ::NORMAL ); 53 54audio_task_ = 55 webrtc::RepeatingTaskHandle ::Start (audio_queue_ .get (), [this ]() { 56 webrtc::MutexLock lock (& mutex_ ); 57 58if (playing_ ) { 59int64_t elapsed_time_ms = -1 ; 60int64_t ntp_time_ms = -1 ; 61size_t n_samples_out = 0 ; 62void * data = data_ .data (); 63 64// Request the AudioData, otherwise WebRTC will ignore the packets. 65// 10ms of audio data. 66audio_transport_ -> NeedMorePlayData ( 67kSamplesPer10Ms ,kBytesPerSample ,kChannels ,kSampleRate ,data , 68n_samples_out ,& elapsed_time_ms ,& ntp_time_ms ); 69 } 70 71return webrtc::TimeDelta ::Millis (10 ); 72 }); 73 74initialized_ = true; 75return 0 ; 76} 77 78int32_t AudioDevice ::Terminate () { 79 { 80 webrtc::MutexLock lock (& mutex_ ); 81if (!initialized_ ) 82return 0 ; 83 84initialized_ = false; 85 } 86audio_queue_ = nullptr ; 87return 0 ; 88} 89 90bool AudioDevice ::Initialized ()const { 91 webrtc::MutexLock lock (& mutex_ ); 92return initialized_ ; 93} 94 95int16_t AudioDevice ::PlayoutDevices () { 96return 0 ; 97} 98 99int16_t AudioDevice ::RecordingDevices () { 100return 0 ; 101} 102 103int32_t AudioDevice ::PlayoutDeviceName (uint16_t index , 104char name [webrtc::kAdmMaxDeviceNameSize ], 105char guid [webrtc::kAdmMaxGuidSize ]) { 106return 0 ; 107} 108 109int32_t AudioDevice ::RecordingDeviceName ( 110uint16_t index , 111char name [webrtc::kAdmMaxDeviceNameSize ], 112char guid [webrtc::kAdmMaxGuidSize ]) { 113return 0 ; 114} 115 116int32_t AudioDevice ::SetPlayoutDevice (uint16_t index ) { 117return 0 ; 118} 119 120int32_t AudioDevice ::SetPlayoutDevice (WindowsDeviceType device ) { 121return 0 ; 122} 123 124int32_t AudioDevice ::SetRecordingDevice (uint16_t index ) { 125return 0 ; 126} 127 128int32_t AudioDevice ::SetRecordingDevice (WindowsDeviceType device ) { 129return 0 ; 130} 131 132int32_t AudioDevice ::PlayoutIsAvailable (bool * available ) { 133return 0 ; 134} 135 136int32_t AudioDevice ::InitPlayout () { 137return 0 ; 138} 139 140bool AudioDevice ::PlayoutIsInitialized ()const { 141return false; 142} 143 144int32_t AudioDevice ::RecordingIsAvailable (bool * available ) { 145return 0 ; 146} 147 148int32_t AudioDevice ::InitRecording () { 149return 0 ; 150} 151 152bool AudioDevice ::RecordingIsInitialized ()const { 153return false; 154} 155 156int32_t AudioDevice ::StartPlayout () { 157 webrtc::MutexLock lock (& mutex_ ); 158playing_ = true; 159return 0 ; 160} 161 162int32_t AudioDevice ::StopPlayout () { 163 webrtc::MutexLock lock (& mutex_ ); 164playing_ = false; 165return 0 ; 166} 167 168bool AudioDevice ::Playing ()const { 169 webrtc::MutexLock lock (& mutex_ ); 170return playing_ ; 171} 172 173int32_t AudioDevice ::StartRecording () { 174return 0 ; 175} 176 177int32_t AudioDevice ::StopRecording () { 178return 0 ; 179} 180 181bool AudioDevice ::Recording ()const { 182return false; 183} 184 185int32_t AudioDevice ::InitSpeaker () { 186return 0 ; 187} 188 189bool AudioDevice ::SpeakerIsInitialized ()const { 190return false; 191} 192 193int32_t AudioDevice ::InitMicrophone () { 194return 0 ; 195} 196 197bool AudioDevice ::MicrophoneIsInitialized ()const { 198return false; 199} 200 201int32_t AudioDevice ::SpeakerVolumeIsAvailable (bool * available ) { 202return 0 ; 203} 204 205int32_t AudioDevice ::SetSpeakerVolume (uint32_t volume ) { 206return 0 ; 207} 208 209int32_t AudioDevice ::SpeakerVolume (uint32_t * volume )const { 210return 0 ; 211} 212 213int32_t AudioDevice ::MaxSpeakerVolume (uint32_t * maxVolume )const { 214return 0 ; 215} 216 217int32_t AudioDevice ::MinSpeakerVolume (uint32_t * minVolume )const { 218return 0 ; 219} 220 221int32_t AudioDevice ::MicrophoneVolumeIsAvailable (bool * available ) { 222return 0 ; 223} 224 225int32_t AudioDevice ::SetMicrophoneVolume (uint32_t volume ) { 226return 0 ; 227} 228 229int32_t AudioDevice ::MicrophoneVolume (uint32_t * volume )const { 230return 0 ; 231} 232 233int32_t AudioDevice ::MaxMicrophoneVolume (uint32_t * maxVolume )const { 234return 0 ; 235} 236 237int32_t AudioDevice ::MinMicrophoneVolume (uint32_t * minVolume )const { 238return 0 ; 239} 240 241int32_t AudioDevice ::SpeakerMuteIsAvailable (bool * available ) { 242return 0 ; 243} 244 245int32_t AudioDevice ::SetSpeakerMute (bool enable ) { 246return 0 ; 247} 248 249int32_t AudioDevice ::SpeakerMute (bool * enabled )const { 250return 0 ; 251} 252 253int32_t AudioDevice ::MicrophoneMuteIsAvailable (bool * available ) { 254return 0 ; 255} 256 257int32_t AudioDevice ::SetMicrophoneMute (bool enable ) { 258return 0 ; 259} 260 261int32_t AudioDevice ::MicrophoneMute (bool * enabled )const { 262return 0 ; 263} 264 265int32_t AudioDevice ::StereoPlayoutIsAvailable (bool * available )const { 266* available = true; 267return 0 ; 268} 269 270int32_t AudioDevice ::SetStereoPlayout (bool enable ) { 271return 0 ; 272} 273 274int32_t AudioDevice ::StereoPlayout (bool * enabled )const { 275return 0 ; 276} 277 278int32_t AudioDevice ::StereoRecordingIsAvailable (bool * available )const { 279return 0 ; 280} 281 282int32_t AudioDevice ::SetStereoRecording (bool enable ) { 283return 0 ; 284} 285 286int32_t AudioDevice ::StereoRecording (bool * enabled )const { 287* enabled = true; 288return 0 ; 289} 290 291int32_t AudioDevice ::PlayoutDelay (uint16_t * delayMS )const { 292return 0 ; 293} 294 295bool AudioDevice ::BuiltInAECIsAvailable ()const { 296return false; 297} 298 299bool AudioDevice ::BuiltInAGCIsAvailable ()const { 300return false; 301} 302 303bool AudioDevice ::BuiltInNSIsAvailable ()const { 304return false; 305} 306 307int32_t AudioDevice ::EnableBuiltInAEC (bool enable ) { 308return 0 ; 309} 310 311int32_t AudioDevice ::EnableBuiltInAGC (bool enable ) { 312return 0 ; 313} 314 315int32_t AudioDevice ::EnableBuiltInNS (bool enable ) { 316return 0 ; 317} 318 319#if defined(WEBRTC_IOS ) 320int AudioDevice ::GetPlayoutAudioParameters ( 321 webrtc::AudioParameters * params )const { 322return 0 ; 323} 324 325int AudioDevice ::GetRecordAudioParameters ( 326 webrtc::AudioParameters * params )const { 327return 0 ; 328} 329#endif // WEBRTC_IOS 330 331int32_t AudioDevice ::SetAudioDeviceSink (webrtc::AudioDeviceSink * sink )const { 332return 0 ; 333} 334 335}// namespace livekit