fork/rust-sdks

git clone https://git.julia.blue/fork/rust-sdks

aoife cassidychore(webrtc-sys): bump to m125_release (#505)a1b926e

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