summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/sdk/objc/native/src/objc_audio_device.mm
blob: d629fae20fe5177fe78a61fc5eed2a05e9454c5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/*
 *  Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "objc_audio_device.h"
#include "objc_audio_device_delegate.h"

#import "components/audio/RTCAudioDevice.h"
#include "modules/audio_device/fine_audio_buffer.h"

#include "api/task_queue/default_task_queue_factory.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/time_utils.h"

namespace {

webrtc::AudioParameters RecordParameters(id<RTC_OBJC_TYPE(RTCAudioDevice)> audio_device) {
  const double sample_rate = static_cast<int>([audio_device deviceInputSampleRate]);
  const size_t channels = static_cast<size_t>([audio_device inputNumberOfChannels]);
  const size_t frames_per_buffer =
      static_cast<size_t>(sample_rate * [audio_device inputIOBufferDuration] + .5);
  return webrtc::AudioParameters(sample_rate, channels, frames_per_buffer);
}

webrtc::AudioParameters PlayoutParameters(id<RTC_OBJC_TYPE(RTCAudioDevice)> audio_device) {
  const double sample_rate = static_cast<int>([audio_device deviceOutputSampleRate]);
  const size_t channels = static_cast<size_t>([audio_device outputNumberOfChannels]);
  const size_t frames_per_buffer =
      static_cast<size_t>(sample_rate * [audio_device outputIOBufferDuration] + .5);
  return webrtc::AudioParameters(sample_rate, channels, frames_per_buffer);
}

}  // namespace

namespace webrtc {
namespace objc_adm {

ObjCAudioDeviceModule::ObjCAudioDeviceModule(id<RTC_OBJC_TYPE(RTCAudioDevice)> audio_device)
    : audio_device_(audio_device), task_queue_factory_(CreateDefaultTaskQueueFactory()) {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK(audio_device_);
  thread_checker_.Detach();
  io_playout_thread_checker_.Detach();
  io_record_thread_checker_.Detach();
}

ObjCAudioDeviceModule::~ObjCAudioDeviceModule() {
  RTC_DLOG_F(LS_VERBOSE) << "";
}

int32_t ObjCAudioDeviceModule::RegisterAudioCallback(AudioTransport* audioCallback) {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK(audio_device_buffer_);
  return audio_device_buffer_->RegisterAudioCallback(audioCallback);
}

int32_t ObjCAudioDeviceModule::Init() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);

  if (Initialized()) {
    RTC_LOG_F(LS_INFO) << "Already initialized";
    return 0;
  }
  io_playout_thread_checker_.Detach();
  io_record_thread_checker_.Detach();

  thread_ = rtc::Thread::Current();
  audio_device_buffer_.reset(new webrtc::AudioDeviceBuffer(task_queue_factory_.get()));

  if (![audio_device_ isInitialized]) {
    if (audio_device_delegate_ == nil) {
      audio_device_delegate_ = [[ObjCAudioDeviceDelegate alloc]
          initWithAudioDeviceModule:rtc::scoped_refptr<ObjCAudioDeviceModule>(this)
                  audioDeviceThread:thread_];
    }

    if (![audio_device_ initializeWithDelegate:audio_device_delegate_]) {
      RTC_LOG_F(LS_WARNING) << "Failed to initialize audio device";
      [audio_device_delegate_ resetAudioDeviceModule];
      audio_device_delegate_ = nil;
      return -1;
    }
  }

  playout_parameters_.reset([audio_device_delegate_ preferredOutputSampleRate], 1);
  UpdateOutputAudioDeviceBuffer();

  record_parameters_.reset([audio_device_delegate_ preferredInputSampleRate], 1);
  UpdateInputAudioDeviceBuffer();

  is_initialized_ = true;

  RTC_LOG_F(LS_INFO) << "Did initialize";
  return 0;
}

int32_t ObjCAudioDeviceModule::Terminate() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);

  if (!Initialized()) {
    RTC_LOG_F(LS_INFO) << "Not initialized";
    return 0;
  }

  if ([audio_device_ isInitialized]) {
    if (![audio_device_ terminateDevice]) {
      RTC_LOG_F(LS_ERROR) << "Failed to terminate audio device";
      return -1;
    }
  }

  if (audio_device_delegate_ != nil) {
    [audio_device_delegate_ resetAudioDeviceModule];
    audio_device_delegate_ = nil;
  }

  is_initialized_ = false;
  is_playout_initialized_ = false;
  is_recording_initialized_ = false;
  thread_ = nullptr;

  RTC_LOG_F(LS_INFO) << "Did terminate";
  return 0;
}

bool ObjCAudioDeviceModule::Initialized() const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  return is_initialized_ && [audio_device_ isInitialized];
}

int32_t ObjCAudioDeviceModule::PlayoutIsAvailable(bool* available) {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  *available = Initialized();
  return 0;
}

bool ObjCAudioDeviceModule::PlayoutIsInitialized() const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  return Initialized() && is_playout_initialized_ && [audio_device_ isPlayoutInitialized];
}

int32_t ObjCAudioDeviceModule::InitPlayout() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  if (!Initialized()) {
    return -1;
  }
  if (PlayoutIsInitialized()) {
    return 0;
  }
  RTC_DCHECK(!playing_.load());

  if (![audio_device_ isPlayoutInitialized]) {
    if (![audio_device_ initializePlayout]) {
      RTC_LOG_F(LS_ERROR) << "Failed to initialize audio device playout";
      return -1;
    }
  }

  if (UpdateAudioParameters(playout_parameters_, PlayoutParameters(audio_device_))) {
    UpdateOutputAudioDeviceBuffer();
  }

  is_playout_initialized_ = true;
  RTC_LOG_F(LS_INFO) << "Did initialize playout";
  return 0;
}

bool ObjCAudioDeviceModule::Playing() const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  return playing_.load() && [audio_device_ isPlaying];
}

int32_t ObjCAudioDeviceModule::StartPlayout() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  if (!PlayoutIsInitialized()) {
    return -1;
  }
  if (Playing()) {
    return 0;
  }

  audio_device_buffer_->StartPlayout();
  if (playout_fine_audio_buffer_) {
    playout_fine_audio_buffer_->ResetPlayout();
  }
  if (![audio_device_ startPlayout]) {
    RTC_LOG_F(LS_ERROR) << "Failed to start audio device playout";
    return -1;
  }
  playing_.store(true, std::memory_order_release);
  RTC_LOG_F(LS_INFO) << "Did start playout";
  return 0;
}

int32_t ObjCAudioDeviceModule::StopPlayout() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);

  if (![audio_device_ stopPlayout]) {
    RTC_LOG_F(LS_WARNING) << "Failed to stop playout";
    return -1;
  }

  audio_device_buffer_->StopPlayout();
  playing_.store(false, std::memory_order_release);
  RTC_LOG_F(LS_INFO) << "Did stop playout";
  return 0;
}

int32_t ObjCAudioDeviceModule::PlayoutDelay(uint16_t* delayMS) const {
  RTC_DCHECK_RUN_ON(&thread_checker_);
  *delayMS = static_cast<uint16_t>(rtc::SafeClamp<int>(
      cached_playout_delay_ms_.load(), 0, std::numeric_limits<uint16_t>::max()));
  return 0;
}

int32_t ObjCAudioDeviceModule::RecordingIsAvailable(bool* available) {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  *available = Initialized();
  return 0;
}

bool ObjCAudioDeviceModule::RecordingIsInitialized() const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  return Initialized() && is_recording_initialized_ && [audio_device_ isRecordingInitialized];
}

int32_t ObjCAudioDeviceModule::InitRecording() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  if (!Initialized()) {
    return -1;
  }
  if (RecordingIsInitialized()) {
    return 0;
  }
  RTC_DCHECK(!recording_.load());

  if (![audio_device_ isRecordingInitialized]) {
    if (![audio_device_ initializeRecording]) {
      RTC_LOG_F(LS_ERROR) << "Failed to initialize audio device recording";
      return -1;
    }
  }

  if (UpdateAudioParameters(record_parameters_, RecordParameters(audio_device_))) {
    UpdateInputAudioDeviceBuffer();
  }

  is_recording_initialized_ = true;
  RTC_LOG_F(LS_INFO) << "Did initialize recording";
  return 0;
}

bool ObjCAudioDeviceModule::Recording() const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  return recording_.load() && [audio_device_ isRecording];
}

int32_t ObjCAudioDeviceModule::StartRecording() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  if (!RecordingIsInitialized()) {
    return -1;
  }
  if (Recording()) {
    return 0;
  }

  audio_device_buffer_->StartRecording();
  if (record_fine_audio_buffer_) {
    record_fine_audio_buffer_->ResetRecord();
  }

  if (![audio_device_ startRecording]) {
    RTC_LOG_F(LS_ERROR) << "Failed to start audio device recording";
    return -1;
  }
  recording_.store(true, std::memory_order_release);
  RTC_LOG_F(LS_INFO) << "Did start recording";
  return 0;
}

int32_t ObjCAudioDeviceModule::StopRecording() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);

  if (![audio_device_ stopRecording]) {
    RTC_LOG_F(LS_WARNING) << "Failed to stop recording";
    return -1;
  }
  audio_device_buffer_->StopRecording();
  recording_.store(false, std::memory_order_release);
  RTC_LOG_F(LS_INFO) << "Did stop recording";
  return 0;
}

#if defined(WEBRTC_IOS)

int ObjCAudioDeviceModule::GetPlayoutAudioParameters(AudioParameters* params) const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK(playout_parameters_.is_valid());
  RTC_DCHECK_RUN_ON(&thread_checker_);
  *params = playout_parameters_;
  return 0;
}

int ObjCAudioDeviceModule::GetRecordAudioParameters(AudioParameters* params) const {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK(record_parameters_.is_valid());
  RTC_DCHECK_RUN_ON(&thread_checker_);
  *params = record_parameters_;
  return 0;
}

#endif  // WEBRTC_IOS

void ObjCAudioDeviceModule::UpdateOutputAudioDeviceBuffer() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  RTC_DCHECK(audio_device_buffer_) << "AttachAudioBuffer must be called first";

  RTC_DCHECK_GT(playout_parameters_.sample_rate(), 0);
  RTC_DCHECK(playout_parameters_.channels() == 1 || playout_parameters_.channels() == 2);

  audio_device_buffer_->SetPlayoutSampleRate(playout_parameters_.sample_rate());
  audio_device_buffer_->SetPlayoutChannels(playout_parameters_.channels());
  playout_fine_audio_buffer_.reset(new FineAudioBuffer(audio_device_buffer_.get()));
}

void ObjCAudioDeviceModule::UpdateInputAudioDeviceBuffer() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  RTC_DCHECK(audio_device_buffer_) << "AttachAudioBuffer must be called first";

  RTC_DCHECK_GT(record_parameters_.sample_rate(), 0);
  RTC_DCHECK(record_parameters_.channels() == 1 || record_parameters_.channels() == 2);

  audio_device_buffer_->SetRecordingSampleRate(record_parameters_.sample_rate());
  audio_device_buffer_->SetRecordingChannels(record_parameters_.channels());
  record_fine_audio_buffer_.reset(new FineAudioBuffer(audio_device_buffer_.get()));
}

void ObjCAudioDeviceModule::UpdateAudioDelay(std::atomic<int>& delay_ms,
                                             const NSTimeInterval device_latency) {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  int latency_ms = static_cast<int>(rtc::kNumMillisecsPerSec * device_latency);
  if (latency_ms <= 0) {
    return;
  }
  const int old_latency_ms = delay_ms.exchange(latency_ms);
  if (old_latency_ms != latency_ms) {
    RTC_LOG_F(LS_INFO) << "Did change audio IO latency from: " << old_latency_ms
                       << " ms to: " << latency_ms << " ms";
  }
}

bool ObjCAudioDeviceModule::UpdateAudioParameters(AudioParameters& params,
                                                  const AudioParameters& device_params) {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  if (!device_params.is_complete()) {
    RTC_LOG_F(LS_INFO) << "Device params are incomplete: " << device_params.ToString();
    return false;
  }
  if (params.channels() == device_params.channels() &&
      params.frames_per_buffer() == device_params.frames_per_buffer() &&
      params.sample_rate() == device_params.sample_rate()) {
    RTC_LOG_F(LS_INFO) << "Device params: " << device_params.ToString()
                       << " are not different from: " << params.ToString();
    return false;
  }

  RTC_LOG_F(LS_INFO) << "Audio params will be changed from: " << params.ToString()
                     << " to: " << device_params.ToString();
  params.reset(
      device_params.sample_rate(), device_params.channels(), device_params.frames_per_buffer());
  return true;
}

OSStatus ObjCAudioDeviceModule::OnDeliverRecordedData(
    AudioUnitRenderActionFlags* flags,
    const AudioTimeStamp* time_stamp,
    NSInteger bus_number,
    UInt32 num_frames,
    const AudioBufferList* io_data,
    void* render_context,
    RTC_OBJC_TYPE(RTCAudioDeviceRenderRecordedDataBlock) render_block) {
  RTC_DCHECK_RUN_ON(&io_record_thread_checker_);
  OSStatus result = noErr;
  // Simply return if recording is not enabled.
  if (!recording_.load()) return result;

  if (io_data != nullptr) {
    // AudioBuffer already fullfilled with audio data
    RTC_DCHECK_EQ(1, io_data->mNumberBuffers);
    const AudioBuffer* audio_buffer = &io_data->mBuffers[0];
    RTC_DCHECK(audio_buffer->mNumberChannels == 1 || audio_buffer->mNumberChannels == 2);

    record_fine_audio_buffer_->DeliverRecordedData(
        rtc::ArrayView<const int16_t>(static_cast<int16_t*>(audio_buffer->mData), num_frames),
        cached_recording_delay_ms_.load());
    return noErr;
  }
  RTC_DCHECK(render_block != nullptr) << "Either io_data or render_block must be provided";

  // Set the size of our own audio buffer and clear it first to avoid copying
  // in combination with potential reallocations.
  // On real iOS devices, the size will only be set once (at first callback).
  const int channels_count = record_parameters_.channels();
  record_audio_buffer_.Clear();
  record_audio_buffer_.SetSize(num_frames * channels_count);

  // Allocate AudioBuffers to be used as storage for the received audio.
  // The AudioBufferList structure works as a placeholder for the
  // AudioBuffer structure, which holds a pointer to the actual data buffer
  // in `record_audio_buffer_`. Recorded audio will be rendered into this memory
  // at each input callback when calling `render_block`.
  AudioBufferList audio_buffer_list;
  audio_buffer_list.mNumberBuffers = 1;
  AudioBuffer* audio_buffer = &audio_buffer_list.mBuffers[0];
  audio_buffer->mNumberChannels = channels_count;
  audio_buffer->mDataByteSize =
      record_audio_buffer_.size() * sizeof(decltype(record_audio_buffer_)::value_type);
  audio_buffer->mData = reinterpret_cast<int8_t*>(record_audio_buffer_.data());

  // Obtain the recorded audio samples by initiating a rendering cycle into own buffer.
  result =
      render_block(flags, time_stamp, bus_number, num_frames, &audio_buffer_list, render_context);
  if (result != noErr) {
    RTC_LOG_F(LS_ERROR) << "Failed to render audio: " << result;
    return result;
  }

  // Get a pointer to the recorded audio and send it to the WebRTC ADB.
  // Use the FineAudioBuffer instance to convert between native buffer size
  // and the 10ms buffer size used by WebRTC.
  record_fine_audio_buffer_->DeliverRecordedData(record_audio_buffer_,
                                                 cached_recording_delay_ms_.load());
  return noErr;
}

OSStatus ObjCAudioDeviceModule::OnGetPlayoutData(AudioUnitRenderActionFlags* flags,
                                                 const AudioTimeStamp* time_stamp,
                                                 NSInteger bus_number,
                                                 UInt32 num_frames,
                                                 AudioBufferList* io_data) {
  RTC_DCHECK_RUN_ON(&io_playout_thread_checker_);
  // Verify 16-bit, noninterleaved mono or stereo PCM signal format.
  RTC_DCHECK_EQ(1, io_data->mNumberBuffers);
  AudioBuffer* audio_buffer = &io_data->mBuffers[0];
  RTC_DCHECK(audio_buffer->mNumberChannels == 1 || audio_buffer->mNumberChannels == 2);
  RTC_DCHECK_EQ(audio_buffer->mDataByteSize,
                sizeof(int16_t) * num_frames * audio_buffer->mNumberChannels);

  // Produce silence and give player a hint about it if playout is not
  // activated.
  if (!playing_.load()) {
    *flags |= kAudioUnitRenderAction_OutputIsSilence;
    memset(static_cast<int8_t*>(audio_buffer->mData), 0, audio_buffer->mDataByteSize);
    return noErr;
  }

  // Read decoded 16-bit PCM samples from WebRTC into the
  // `io_data` destination buffer.
  playout_fine_audio_buffer_->GetPlayoutData(
      rtc::ArrayView<int16_t>(static_cast<int16_t*>(audio_buffer->mData),
                              num_frames * audio_buffer->mNumberChannels),
      cached_playout_delay_ms_.load());

  return noErr;
}

void ObjCAudioDeviceModule::HandleAudioInputInterrupted() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  io_record_thread_checker_.Detach();
}

void ObjCAudioDeviceModule::HandleAudioOutputInterrupted() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);
  io_playout_thread_checker_.Detach();
}

void ObjCAudioDeviceModule::HandleAudioInputParametersChange() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);

  if (UpdateAudioParameters(record_parameters_, RecordParameters(audio_device_))) {
    UpdateInputAudioDeviceBuffer();
  }

  UpdateAudioDelay(cached_recording_delay_ms_, [audio_device_ inputLatency]);
}

void ObjCAudioDeviceModule::HandleAudioOutputParametersChange() {
  RTC_DLOG_F(LS_VERBOSE) << "";
  RTC_DCHECK_RUN_ON(&thread_checker_);

  if (UpdateAudioParameters(playout_parameters_, PlayoutParameters(audio_device_))) {
    UpdateOutputAudioDeviceBuffer();
  }

  UpdateAudioDelay(cached_playout_delay_ms_, [audio_device_ outputLatency]);
}

#pragma mark - Not implemented/Not relevant methods from AudioDeviceModule

int32_t ObjCAudioDeviceModule::ActiveAudioLayer(AudioLayer* audioLayer) const {
  return -1;
}

int16_t ObjCAudioDeviceModule::PlayoutDevices() {
  return 0;
}

int16_t ObjCAudioDeviceModule::RecordingDevices() {
  return 0;
}

int32_t ObjCAudioDeviceModule::PlayoutDeviceName(uint16_t index,
                                                 char name[kAdmMaxDeviceNameSize],
                                                 char guid[kAdmMaxGuidSize]) {
  return -1;
}

int32_t ObjCAudioDeviceModule::RecordingDeviceName(uint16_t index,
                                                   char name[kAdmMaxDeviceNameSize],
                                                   char guid[kAdmMaxGuidSize]) {
  return -1;
}

int32_t ObjCAudioDeviceModule::SetPlayoutDevice(uint16_t index) {
  return 0;
}

int32_t ObjCAudioDeviceModule::SetPlayoutDevice(WindowsDeviceType device) {
  return -1;
}

int32_t ObjCAudioDeviceModule::SetRecordingDevice(uint16_t index) {
  return 0;
}

int32_t ObjCAudioDeviceModule::SetRecordingDevice(WindowsDeviceType device) {
  return -1;
}

int32_t ObjCAudioDeviceModule::InitSpeaker() {
  return 0;
}

bool ObjCAudioDeviceModule::SpeakerIsInitialized() const {
  return true;
}

int32_t ObjCAudioDeviceModule::InitMicrophone() {
  return 0;
}

bool ObjCAudioDeviceModule::MicrophoneIsInitialized() const {
  return true;
}

int32_t ObjCAudioDeviceModule::SpeakerVolumeIsAvailable(bool* available) {
  *available = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::SetSpeakerVolume(uint32_t volume) {
  return -1;
}

int32_t ObjCAudioDeviceModule::SpeakerVolume(uint32_t* volume) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::MaxSpeakerVolume(uint32_t* maxVolume) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::MinSpeakerVolume(uint32_t* minVolume) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::SpeakerMuteIsAvailable(bool* available) {
  *available = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::SetSpeakerMute(bool enable) {
  return -1;
}

int32_t ObjCAudioDeviceModule::SpeakerMute(bool* enabled) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::MicrophoneMuteIsAvailable(bool* available) {
  *available = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::SetMicrophoneMute(bool enable) {
  return -1;
}

int32_t ObjCAudioDeviceModule::MicrophoneMute(bool* enabled) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::MicrophoneVolumeIsAvailable(bool* available) {
  *available = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::SetMicrophoneVolume(uint32_t volume) {
  return -1;
}

int32_t ObjCAudioDeviceModule::MicrophoneVolume(uint32_t* volume) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::MaxMicrophoneVolume(uint32_t* maxVolume) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::MinMicrophoneVolume(uint32_t* minVolume) const {
  return -1;
}

int32_t ObjCAudioDeviceModule::StereoPlayoutIsAvailable(bool* available) const {
  *available = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::SetStereoPlayout(bool enable) {
  return -1;
}

int32_t ObjCAudioDeviceModule::StereoPlayout(bool* enabled) const {
  *enabled = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::StereoRecordingIsAvailable(bool* available) const {
  *available = false;
  return 0;
}

int32_t ObjCAudioDeviceModule::SetStereoRecording(bool enable) {
  return -1;
}

int32_t ObjCAudioDeviceModule::StereoRecording(bool* enabled) const {
  *enabled = false;
  return 0;
}

bool ObjCAudioDeviceModule::BuiltInAECIsAvailable() const {
  return false;
}

int32_t ObjCAudioDeviceModule::EnableBuiltInAEC(bool enable) {
  return 0;
}

bool ObjCAudioDeviceModule::BuiltInAGCIsAvailable() const {
  return false;
}

int32_t ObjCAudioDeviceModule::EnableBuiltInAGC(bool enable) {
  return 0;
}

bool ObjCAudioDeviceModule::BuiltInNSIsAvailable() const {
  return false;
}

int32_t ObjCAudioDeviceModule::EnableBuiltInNS(bool enable) {
  return 0;
}

int32_t ObjCAudioDeviceModule::GetPlayoutUnderrunCount() const {
  return -1;
}

}  // namespace objc_adm

}  // namespace webrtc