Don't perform DataCallback if the input object has been stopped.
Fix signed/unsigned mismatch.
Protect against NumberOfEnumeratedDevices and Get[In|Out]putDeviceNames returning inconsistent results.
It's possible for an device to be counted but getting its name fails, in which case the utility function returns true but would continue from its loop filling the AudioDeviceNames vector, leading to a smaller output than the later code expects.
Bug: b/144382120
Change-Id: Iab008c28f03023c830011d229b1f1c7e3e7bb5ee
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160226
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29871}
diff --git a/modules/audio_device/win/core_audio_input_win.cc b/modules/audio_device/win/core_audio_input_win.cc
index 5350076..8c1b06e 100644
--- a/modules/audio_device/win/core_audio_input_win.cc
+++ b/modules/audio_device/win/core_audio_input_win.cc
@@ -261,6 +261,13 @@
bool CoreAudioInput::OnDataCallback(uint64_t device_frequency) {
RTC_DCHECK_RUN_ON(&thread_checker_audio_);
+
+ if (!initialized_ || !is_active_) {
+ // This is concurrent examination of state across multiple threads so will
+ // be somewhat error prone, but we should still be defensive and not use
+ // audio_capture_client_ if we know it's not there.
+ return false;
+ }
if (num_data_callbacks_ == 0) {
RTC_LOG(INFO) << "--- Input audio stream is alive ---";
}