| OLD | NEW |
| 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 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_DLOG(ERROR, result) << "AudioUnitRender() failed "; | 588 OSSTATUS_LOG(ERROR, result) << "AudioUnitRender() failed "; |
| 589 if (result != kAudioUnitErr_TooManyFramesToProcess) { | 589 if (result == kAudioUnitErr_TooManyFramesToProcess) { |
| 590 audio_input->HandleError(result); | |
| 591 } else { | |
| 592 DCHECK(!audio_input->last_success_time_.is_null()); | 590 DCHECK(!audio_input->last_success_time_.is_null()); |
| 593 // We delay stopping the stream for kAudioUnitErr_TooManyFramesToProcess | 591 // We delay stopping the stream for kAudioUnitErr_TooManyFramesToProcess |
| 594 // since it has been observed that some USB headsets can cause this error | 592 // since it has been observed that some USB headsets can cause this error |
| 595 // but only for a few initial frames at startup and then then the stream | 593 // but only for a few initial frames at startup and then then the stream |
| 596 // returns to a stable state again. See b/19524368 for details. | 594 // returns to a stable state again. See b/19524368 for details. |
| 597 // Instead, we measure time since last valid audio frame and call | 595 // Instead, we measure time since last valid audio frame and call |
| 598 // HandleError() only if a too long error sequence is detected. We do | 596 // HandleError() only if a too long error sequence is detected. We do |
| 599 // this to avoid ending up in a non recoverable bad core audio state. | 597 // this to avoid ending up in a non recoverable bad core audio state. |
| 600 base::TimeDelta time_since_last_success = | 598 base::TimeDelta time_since_last_success = |
| 601 base::TimeTicks::Now() - audio_input->last_success_time_; | 599 base::TimeTicks::Now() - audio_input->last_success_time_; |
| 602 if ((time_since_last_success > | 600 if ((time_since_last_success > |
| 603 base::TimeDelta::FromSeconds(kMaxErrorTimeoutInSeconds))) { | 601 base::TimeDelta::FromSeconds(kMaxErrorTimeoutInSeconds))) { |
| 604 DLOG(ERROR) << "Too long sequence of TooManyFramesToProcess errors!"; | 602 LOG(ERROR) << "Too long sequence of TooManyFramesToProcess errors!"; |
| 605 audio_input->HandleError(result); | 603 audio_input->HandleError(result); |
| 606 } | 604 } |
| 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 // We have also seen kAudioUnitErr_NoConnection in some cases. Bailing |
| 613 // out for this error for now. |
| 614 audio_input->HandleError(result); |
| 607 } | 615 } |
| 608 return result; | 616 return result; |
| 609 } | 617 } |
| 610 // Update time of successful call to AudioUnitRender(). | 618 // Update time of successful call to AudioUnitRender(). |
| 611 audio_input->last_success_time_ = base::TimeTicks::Now(); | 619 audio_input->last_success_time_ = base::TimeTicks::Now(); |
| 612 | 620 |
| 613 // Deliver recorded data to the consumer as a callback. | 621 // Deliver recorded data to the consumer as a callback. |
| 614 return audio_input->Provide(number_of_frames, | 622 return audio_input->Provide(number_of_frames, |
| 615 audio_input->audio_buffer_list(), | 623 audio_input->audio_buffer_list(), |
| 616 time_stamp); | 624 time_stamp); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 manager_->low_latency_input_streams()); | 856 manager_->low_latency_input_streams()); |
| 849 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", | 857 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", |
| 850 manager_->basic_input_streams()); | 858 manager_->basic_input_streams()); |
| 851 // TODO(henrika): this value will currently always report true. It should be | 859 // TODO(henrika): this value will currently always report true. It should be |
| 852 // fixed when we understand the problem better. | 860 // fixed when we understand the problem better. |
| 853 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", | 861 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", |
| 854 GetAutomaticGainControl()); | 862 GetAutomaticGainControl()); |
| 855 } | 863 } |
| 856 | 864 |
| 857 } // namespace media | 865 } // namespace media |
| OLD | NEW |