Skip to content

Commit 627b2d2

Browse files
Cherry pick audio selection from m97 release (#35)
* [Mac] Allow audio device selection (#21) * first attempt * remove unused dep * init playout / recording * use AudioDeviceID as guid * switch device method * equality * default device * `isDefault` property * dont format default device name * type param * bypass * refactor * fix * append Audio to thread labels * ref * lk headers * low level apis * fix thread checks Some methods of ADM needs to be run on worker thread, otherwise RTC's thread check will fail. * switch to default device when removed * close mixerManager if didn't switch to default device * default audio device switched * expose devices update handler * fix ios compile * fix bug: don't always recreate RTCAudioDeviceModule * handle guid. Co-authored-by: Hiroshi Horie <[email protected]>
1 parent bed873d commit 627b2d2

30 files changed

+749
-76
lines changed

modules/audio_device/android/audio_device_template.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
282282
RTC_CHECK_NOTREACHED();
283283
}
284284

285-
int32_t SetAudioDeviceSink(AudioDeviceSink* sink) override {
286-
RTC_CHECK_NOTREACHED();
287-
return -1;
288-
}
289-
290285
int32_t SetSpeakerMute(bool enable) override { RTC_CHECK_NOTREACHED(); }
291286

292287
int32_t SpeakerMute(bool& enabled) const override { RTC_CHECK_NOTREACHED(); }

modules/audio_device/audio_device_data_observer.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ class ADMWrapper : public AudioDeviceModule, public AudioTransport {
307307
}
308308
#endif // WEBRTC_IOS
309309

310+
int32_t SetAudioDeviceSink(AudioDeviceSink* sink) const override {
311+
return impl_->SetAudioDeviceSink(sink);
312+
}
313+
310314
protected:
311315
rtc::scoped_refptr<AudioDeviceModule> impl_;
312316
AudioDeviceDataObserver* legacy_observer_ = nullptr;

modules/audio_device/audio_device_generic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class AudioDeviceGeneric {
135135
virtual int GetRecordAudioParameters(AudioParameters* params) const;
136136
#endif // WEBRTC_IOS
137137

138-
virtual int32_t SetAudioDeviceSink(AudioDeviceSink* sink) = 0;
138+
virtual int32_t SetAudioDeviceSink(AudioDeviceSink* sink) { return -1; }
139139

140140
virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) = 0;
141141

modules/audio_device/audio_device_impl.cc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ namespace webrtc {
7272

7373
rtc::scoped_refptr<AudioDeviceModule> AudioDeviceModule::Create(
7474
AudioLayer audio_layer,
75-
TaskQueueFactory* task_queue_factory) {
75+
TaskQueueFactory* task_queue_factory,
76+
bool bypass_voice_processing) {
7677
RTC_DLOG(LS_INFO) << __FUNCTION__;
77-
return AudioDeviceModule::CreateForTest(audio_layer, task_queue_factory);
78+
return AudioDeviceModule::CreateForTest(audio_layer, task_queue_factory, bypass_voice_processing);
7879
}
7980

8081
// static
8182
rtc::scoped_refptr<AudioDeviceModuleForTest> AudioDeviceModule::CreateForTest(
8283
AudioLayer audio_layer,
83-
TaskQueueFactory* task_queue_factory) {
84+
TaskQueueFactory* task_queue_factory,
85+
bool bypass_voice_processing) {
8486
RTC_DLOG(LS_INFO) << __FUNCTION__;
8587

8688
// The "AudioDeviceModule::kWindowsCoreAudio2" audio layer has its own
@@ -93,7 +95,7 @@ rtc::scoped_refptr<AudioDeviceModuleForTest> AudioDeviceModule::CreateForTest(
9395

9496
// Create the generic reference counted (platform independent) implementation.
9597
auto audio_device = rtc::make_ref_counted<AudioDeviceModuleImpl>(
96-
audio_layer, task_queue_factory);
98+
audio_layer, task_queue_factory, bypass_voice_processing);
9799

98100
// Ensure that the current platform is supported.
99101
if (audio_device->CheckPlatform() == -1) {
@@ -116,8 +118,13 @@ rtc::scoped_refptr<AudioDeviceModuleForTest> AudioDeviceModule::CreateForTest(
116118

117119
AudioDeviceModuleImpl::AudioDeviceModuleImpl(
118120
AudioLayer audio_layer,
119-
TaskQueueFactory* task_queue_factory)
120-
: audio_layer_(audio_layer), audio_device_buffer_(task_queue_factory) {
121+
TaskQueueFactory* task_queue_factory,
122+
bool bypass_voice_processing)
123+
: audio_layer_(audio_layer),
124+
#if defined(WEBRTC_IOS)
125+
bypass_voice_processing_(bypass_voice_processing),
126+
#endif
127+
audio_device_buffer_(task_queue_factory) {
121128
RTC_DLOG(LS_INFO) << __FUNCTION__;
122129
}
123130

@@ -280,7 +287,7 @@ int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() {
280287
#if defined(WEBRTC_IOS)
281288
if (audio_layer == kPlatformDefaultAudio) {
282289
audio_device_.reset(
283-
new ios_adm::AudioDeviceIOS(/*bypass_voice_processing=*/false));
290+
new ios_adm::AudioDeviceIOS(/*bypass_voice_processing=*/bypass_voice_processing_));
284291
RTC_LOG(LS_INFO) << "iPhone Audio APIs will be utilized.";
285292
}
286293
// END #if defined(WEBRTC_IOS)
@@ -937,6 +944,13 @@ int AudioDeviceModuleImpl::GetRecordAudioParameters(
937944
}
938945
#endif // WEBRTC_IOS
939946

947+
int32_t AudioDeviceModuleImpl::SetAudioDeviceSink(AudioDeviceSink* sink) const {
948+
RTC_LOG(LS_INFO) << __FUNCTION__ << "(" << sink << ")";
949+
int32_t ok = audio_device_->SetAudioDeviceSink(sink);
950+
RTC_LOG(LS_INFO) << "output: " << ok;
951+
return ok;
952+
}
953+
940954
AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const {
941955
RTC_LOG(LS_INFO) << __FUNCTION__;
942956
return platform_type_;

modules/audio_device/audio_device_impl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
4343
int32_t AttachAudioBuffer();
4444

4545
AudioDeviceModuleImpl(AudioLayer audio_layer,
46-
TaskQueueFactory* task_queue_factory);
46+
TaskQueueFactory* task_queue_factory,
47+
bool bypass_voice_processing = false);
4748
~AudioDeviceModuleImpl() override;
4849

4950
// Retrieve the currently utilized audio layer
@@ -145,6 +146,8 @@ class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
145146
int GetRecordAudioParameters(AudioParameters* params) const override;
146147
#endif // WEBRTC_IOS
147148

149+
int32_t SetAudioDeviceSink(AudioDeviceSink* sink) const override;
150+
148151
#if defined(WEBRTC_ANDROID)
149152
// Only use this acccessor for test purposes on Android.
150153
AudioManager* GetAndroidAudioManagerForTest() {
@@ -165,7 +168,9 @@ class AudioDeviceModuleImpl : public AudioDeviceModuleForTest {
165168
AudioLayer audio_layer_;
166169
PlatformType platform_type_ = kPlatformNotSupported;
167170
bool initialized_ = false;
168-
#if defined(WEBRTC_ANDROID)
171+
#if defined(WEBRTC_IOS)
172+
bool bypass_voice_processing_;
173+
#elif defined(WEBRTC_ANDROID)
169174
// Should be declared first to ensure that it outlives other resources.
170175
std::unique_ptr<AudioManager> audio_manager_android_;
171176
#endif

modules/audio_device/dummy/audio_device_dummy.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,5 @@ int32_t AudioDeviceDummy::PlayoutDelay(uint16_t& delayMS) const {
222222
return -1;
223223
}
224224

225-
int32_t AudioDeviceDummy::SetAudioDeviceSink(AudioDeviceSink* sink) {
226-
return -1;
227-
}
228-
229225
void AudioDeviceDummy::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {}
230226
} // namespace webrtc

modules/audio_device/dummy/audio_device_dummy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ class AudioDeviceDummy : public AudioDeviceGeneric {
109109
// Delay information and control
110110
int32_t PlayoutDelay(uint16_t& delayMS) const override;
111111

112-
int32_t SetAudioDeviceSink(AudioDeviceSink* sink) override;
113-
114112
void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
115113

116114
};

modules/audio_device/dummy/file_audio_device.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,6 @@ int32_t FileAudioDevice::PlayoutDelay(uint16_t& delayMS) const {
427427
return 0;
428428
}
429429

430-
int32_t FileAudioDevice::SetAudioDeviceSink(AudioDeviceSink* sink) {
431-
return -1;
432-
}
433-
434430
void FileAudioDevice::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
435431
MutexLock lock(&mutex_);
436432

modules/audio_device/dummy/file_audio_device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ class FileAudioDevice : public AudioDeviceGeneric {
123123
// Delay information and control
124124
int32_t PlayoutDelay(uint16_t& delayMS) const override;
125125

126-
int32_t SetAudioDeviceSink(AudioDeviceSink* sink) override;
127-
128126
void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
129127

130128
private:

modules/audio_device/include/audio_device.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ class AudioDeviceModule : public rtc::RefCountInterface {
6565
// Creates a default ADM for usage in production code.
6666
static rtc::scoped_refptr<AudioDeviceModule> Create(
6767
AudioLayer audio_layer,
68-
TaskQueueFactory* task_queue_factory);
68+
TaskQueueFactory* task_queue_factory,
69+
bool bypass_voice_processing = false);
6970
// Creates an ADM with support for extra test methods. Don't use this factory
7071
// in production code.
7172
static rtc::scoped_refptr<AudioDeviceModuleForTest> CreateForTest(
7273
AudioLayer audio_layer,
73-
TaskQueueFactory* task_queue_factory);
74+
TaskQueueFactory* task_queue_factory,
75+
bool bypass_voice_processing = false);
7476

7577
// Retrieve the currently utilized audio layer
7678
virtual int32_t ActiveAudioLayer(AudioLayer* audioLayer) const = 0;
@@ -180,6 +182,8 @@ class AudioDeviceModule : public rtc::RefCountInterface {
180182
virtual int GetRecordAudioParameters(AudioParameters* params) const = 0;
181183
#endif // WEBRTC_IOS
182184

185+
virtual int32_t SetAudioDeviceSink(AudioDeviceSink* sink) const { return -1; }
186+
183187
protected:
184188
~AudioDeviceModule() override {}
185189
};

0 commit comments

Comments
 (0)