Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac.cc

Issue 1612943003: Shuts down input audio for long sequence of AudioUnitRender errors on Mac OSX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/mac/audio_low_latency_input_mac.h" 5 #include "media/audio/mac/audio_low_latency_input_mac.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/mac_logging.h" 10 #include "base/mac/mac_logging.h"
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // Receive audio from the AUHAL from the output scope of the Audio Unit. 579 // Receive audio from the AUHAL from the output scope of the Audio Unit.
580 OSStatus result = AudioUnitRender(audio_input->audio_unit(), 580 OSStatus result = AudioUnitRender(audio_input->audio_unit(),
581 flags, 581 flags,
582 time_stamp, 582 time_stamp,
583 bus_number, 583 bus_number,
584 number_of_frames, 584 number_of_frames,
585 audio_input->audio_buffer_list()); 585 audio_input->audio_buffer_list());
586 if (result) { 586 if (result) {
587 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.AudioInputCbErrorMac", result); 587 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.AudioInputCbErrorMac", result);
588 OSSTATUS_LOG(ERROR, result) << "AudioUnitRender() failed "; 588 OSSTATUS_LOG(ERROR, result) << "AudioUnitRender() failed ";
589 if (result == kAudioUnitErr_TooManyFramesToProcess) { 589 if (result == kAudioUnitErr_TooManyFramesToProcess ||
590 result == kAudioUnitErr_CannotDoInCurrentContext) {
590 DCHECK(!audio_input->last_success_time_.is_null()); 591 DCHECK(!audio_input->last_success_time_.is_null());
591 // We delay stopping the stream for kAudioUnitErr_TooManyFramesToProcess 592 // We delay stopping the stream for kAudioUnitErr_TooManyFramesToProcess
592 // since it has been observed that some USB headsets can cause this error 593 // since it has been observed that some USB headsets can cause this error
593 // but only for a few initial frames at startup and then then the stream 594 // but only for a few initial frames at startup and then then the stream
594 // returns to a stable state again. See b/19524368 for details. 595 // returns to a stable state again. See b/19524368 for details.
595 // Instead, we measure time since last valid audio frame and call 596 // Instead, we measure time since last valid audio frame and call
596 // HandleError() only if a too long error sequence is detected. We do 597 // HandleError() only if a too long error sequence is detected. We do
597 // this to avoid ending up in a non recoverable bad core audio state. 598 // this to avoid ending up in a non recoverable bad core audio state.
599 // Also including kAudioUnitErr_CannotDoInCurrentContext since long
600 // sequences can be produced in combination with e.g. sample-rate changes
601 // for input devices.
598 base::TimeDelta time_since_last_success = 602 base::TimeDelta time_since_last_success =
599 base::TimeTicks::Now() - audio_input->last_success_time_; 603 base::TimeTicks::Now() - audio_input->last_success_time_;
600 if ((time_since_last_success > 604 if ((time_since_last_success >
601 base::TimeDelta::FromSeconds(kMaxErrorTimeoutInSeconds))) { 605 base::TimeDelta::FromSeconds(kMaxErrorTimeoutInSeconds))) {
602 LOG(ERROR) << "Too long sequence of TooManyFramesToProcess errors!"; 606 const char* err = (result == kAudioUnitErr_TooManyFramesToProcess)
607 ? "kAudioUnitErr_TooManyFramesToProcess"
608 : "kAudioUnitErr_CannotDoInCurrentContext";
609 LOG(ERROR) << "Too long sequence of " << err << " errors!";
603 audio_input->HandleError(result); 610 audio_input->HandleError(result);
604 } 611 }
605 } else if (result == kAudioUnitErr_CannotDoInCurrentContext) {
606 // Returned when an audio unit is in a state where it can't perform the
607 // requested action now - but it could later.
608 // TODO(henrika): figure out why we see this error message; do nothing
609 // for now. Hoping that we will get back on track soon.
610 LOG(ERROR) << "kAudioUnitErr_CannotDoInCurrentContext";
611 } else { 612 } else {
612 // We have also seen kAudioUnitErr_NoConnection in some cases. Bailing 613 // We have also seen kAudioUnitErr_NoConnection in some cases. Bailing
613 // out for this error for now. 614 // out for this error for now.
614 audio_input->HandleError(result); 615 audio_input->HandleError(result);
615 } 616 }
616 return result; 617 return result;
617 } 618 }
618 // Update time of successful call to AudioUnitRender(). 619 // Update time of successful call to AudioUnitRender().
619 audio_input->last_success_time_ = base::TimeTicks::Now(); 620 audio_input->last_success_time_ = base::TimeTicks::Now();
620 621
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 manager_->low_latency_input_streams()); 857 manager_->low_latency_input_streams());
857 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", 858 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac",
858 manager_->basic_input_streams()); 859 manager_->basic_input_streams());
859 // TODO(henrika): this value will currently always report true. It should be 860 // TODO(henrika): this value will currently always report true. It should be
860 // fixed when we understand the problem better. 861 // fixed when we understand the problem better.
861 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", 862 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac",
862 GetAutomaticGainControl()); 863 GetAutomaticGainControl());
863 } 864 }
864 865
865 } // namespace media 866 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698