Skip to content

Commit

Permalink
fix : Dynamically switch sound cards (#40)
Browse files Browse the repository at this point in the history
* fix : Dynamically switch sound cards

* No capture or playback is performed until initialized.
  • Loading branch information
zjzhang-cn authored Aug 19, 2022
1 parent 080bd87 commit b81338a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/rtc_audio_device_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,29 @@ int32_t AudioDeviceImpl::RecordingDeviceName(uint16_t index,
int32_t AudioDeviceImpl::SetPlayoutDevice(uint16_t index) {
return worker_thread_->Invoke<int32_t>(RTC_FROM_HERE, [&] {
RTC_DCHECK_RUN_ON(worker_thread_);
return audio_device_module_->SetPlayoutDevice(index);
if (audio_device_module_->Playing()) {
audio_device_module_->StopPlayout();
audio_device_module_->SetPlayoutDevice(index);
audio_device_module_->InitPlayout();
return audio_device_module_->StartPlayout();
} else {
return audio_device_module_->SetPlayoutDevice(index);
}

});
}

int32_t AudioDeviceImpl::SetRecordingDevice(uint16_t index) {
return worker_thread_->Invoke<int32_t>(RTC_FROM_HERE, [&] {
RTC_DCHECK_RUN_ON(worker_thread_);
return audio_device_module_->SetRecordingDevice(index);
if (audio_device_module_->Recording()) {
audio_device_module_->StopRecording();
audio_device_module_->SetRecordingDevice(index);
audio_device_module_->InitRecording();
return audio_device_module_->StartRecording();
} else {
return audio_device_module_->SetRecordingDevice(index);
}
});
}

Expand Down

0 comments on commit b81338a

Please sign in to comment.