Commit 27977555 authored by Oskar Sundbom's avatar Oskar Sundbom Committed by Commit Bot

Mac AEC: Only restart the stream on output device change if started

When using APM in Audio Service, the output device for a microphone
with native echo cancellation support may be set before the stream
has started. Currently, this causes the audio unit to be restarted,
even when it shouldn't. This CL avoids that.

Bug: 882420, b/115305826
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I6c25e8225f918dd4da2e4e0637e4808e03acf125
Reviewed-on: https://chromium-review.googlesource.com/1243067Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Reviewed-by: default avatarHenrik Grunell <grunell@chromium.org>
Commit-Queue: Oskar Sundbom <ossu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594669}
parent 046a611c
......@@ -954,44 +954,51 @@ void AUAudioInputStream::SetOutputDeviceForAec(
}
if (audio_device_id != output_device_id_for_aec_) {
log_callback_.Run(
base::StringPrintf("AU in: Output device for AEC changed to '%s' (%d)",
output_device_id.c_str(), audio_device_id));
SwitchVoiceProcessingOutputDevice(audio_device_id);
output_device_id_for_aec_ = audio_device_id;
log_callback_.Run(base::StringPrintf(
"AU in: Output device for AEC changed to '%s' (%d)",
output_device_id.c_str(), output_device_id_for_aec_));
// Only restart the stream if it has previously been started.
if (audio_unit_)
ReinitializeVoiceProcessingAudioUnit();
}
}
void AUAudioInputStream::SwitchVoiceProcessingOutputDevice(
AudioDeviceID output_device_id) {
void AUAudioInputStream::ReinitializeVoiceProcessingAudioUnit() {
DCHECK(use_voice_processing_);
DCHECK(audio_unit_);
output_device_id_for_aec_ = output_device_id;
if (!audio_unit_)
return;
const bool was_running = IsRunning();
OSStatus result = noErr;
if (IsRunning()) {
if (was_running) {
result = AudioOutputUnitStop(audio_unit_);
DCHECK_EQ(result, noErr);
}
CloseAudioUnit();
// Reset things to a state similar to before the audio unit was opened.
// Most of these will be no-ops if the audio unit was opened but not started.
SetInputCallbackIsActive(false);
ReportAndResetStats();
io_buffer_frame_size_ = 0;
got_input_callback_ = false;
OpenVoiceProcessingAU();
if (was_running) {
result = AudioOutputUnitStart(audio_unit_);
if (result != noErr) {
OSSTATUS_DLOG(ERROR, result) << "Failed to start acquiring data";
Stop();
return;
}
}
log_callback_.Run(base::StringPrintf(
"AU in: Successfully reinitialized AEC for output device id=%d.",
output_device_id));
output_device_id_for_aec_));
}
// static
......
......@@ -149,7 +149,7 @@ class MEDIA_EXPORT AUAudioInputStream
void CloseAudioUnit();
// Reinitializes the AudioUnit to use a new output device.
void SwitchVoiceProcessingOutputDevice(AudioDeviceID output_device_id);
void ReinitializeVoiceProcessingAudioUnit();
// Adds extra UMA stats when it has been detected that startup failed.
void AddHistogramsForFailedStartup();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment