Chromium Code Reviews| 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 #include <string> | |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/mac/mac_logging.h" | 11 #include "base/mac/mac_logging.h" |
| 11 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "media/audio/mac/audio_manager_mac.h" | 15 #include "media/audio/mac/audio_manager_mac.h" |
| 15 #include "media/base/audio_bus.h" | 16 #include "media/base/audio_bus.h" |
| 16 #include "media/base/data_buffer.h" | 17 #include "media/base/data_buffer.h" |
| 17 | 18 |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 // Receive audio from the AUHAL from the output scope of the Audio Unit. | 580 // Receive audio from the AUHAL from the output scope of the Audio Unit. |
| 580 OSStatus result = AudioUnitRender(audio_input->audio_unit(), | 581 OSStatus result = AudioUnitRender(audio_input->audio_unit(), |
| 581 flags, | 582 flags, |
| 582 time_stamp, | 583 time_stamp, |
| 583 bus_number, | 584 bus_number, |
| 584 number_of_frames, | 585 number_of_frames, |
| 585 audio_input->audio_buffer_list()); | 586 audio_input->audio_buffer_list()); |
| 586 if (result) { | 587 if (result) { |
| 587 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.AudioInputCbErrorMac", result); | 588 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.AudioInputCbErrorMac", result); |
| 588 OSSTATUS_LOG(ERROR, result) << "AudioUnitRender() failed "; | 589 OSSTATUS_LOG(ERROR, result) << "AudioUnitRender() failed "; |
| 589 if (result == kAudioUnitErr_TooManyFramesToProcess) { | 590 if (result == kAudioUnitErr_TooManyFramesToProcess || |
| 591 result == kAudioUnitErr_CannotDoInCurrentContext) { | |
| 590 DCHECK(!audio_input->last_success_time_.is_null()); | 592 DCHECK(!audio_input->last_success_time_.is_null()); |
| 591 // We delay stopping the stream for kAudioUnitErr_TooManyFramesToProcess | 593 // We delay stopping the stream for kAudioUnitErr_TooManyFramesToProcess |
| 592 // since it has been observed that some USB headsets can cause this error | 594 // 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 | 595 // 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. | 596 // returns to a stable state again. See b/19524368 for details. |
| 595 // Instead, we measure time since last valid audio frame and call | 597 // Instead, we measure time since last valid audio frame and call |
| 596 // HandleError() only if a too long error sequence is detected. We do | 598 // 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. | 599 // this to avoid ending up in a non recoverable bad core audio state. |
| 598 base::TimeDelta time_since_last_success = | 600 base::TimeDelta time_since_last_success = |
| 599 base::TimeTicks::Now() - audio_input->last_success_time_; | 601 base::TimeTicks::Now() - audio_input->last_success_time_; |
| 600 if ((time_since_last_success > | 602 if ((time_since_last_success > |
| 601 base::TimeDelta::FromSeconds(kMaxErrorTimeoutInSeconds))) { | 603 base::TimeDelta::FromSeconds(kMaxErrorTimeoutInSeconds))) { |
| 602 LOG(ERROR) << "Too long sequence of TooManyFramesToProcess errors!"; | 604 std::string err = (result == kAudioUnitErr_TooManyFramesToProcess) |
|
tommi (sloooow) - chröme
2016/01/21 15:09:20
const char*
| |
| 605 ? "kAudioUnitErr_TooManyFramesToProcess" | |
| 606 : "kAudioUnitErr_CannotDoInCurrentContext"; | |
| 607 LOG(ERROR) << "Too long sequence of " << err << " errors!"; | |
| 603 audio_input->HandleError(result); | 608 audio_input->HandleError(result); |
| 604 } | 609 } |
| 605 } else if (result == kAudioUnitErr_CannotDoInCurrentContext) { | 610 } else if (result == kAudioUnitErr_CannotDoInCurrentContext) { |
|
tommi (sloooow) - chröme
2016/01/21 15:09:20
this check is now superfluous, right?
| |
| 606 // Returned when an audio unit is in a state where it can't perform the | 611 // Returned when an audio unit is in a state where it can't perform the |
| 607 // requested action now - but it could later. | 612 // requested action now - but it could later. |
| 608 // TODO(henrika): figure out why we see this error message; do nothing | 613 // TODO(henrika): figure out why we see this error message; do nothing |
| 609 // for now. Hoping that we will get back on track soon. | 614 // for now. Hoping that we will get back on track soon. |
| 610 LOG(ERROR) << "kAudioUnitErr_CannotDoInCurrentContext"; | 615 // LOG(ERROR) << "kAudioUnitErr_CannotDoInCurrentContext"; |
| 611 } else { | 616 } else { |
| 612 // We have also seen kAudioUnitErr_NoConnection in some cases. Bailing | 617 // We have also seen kAudioUnitErr_NoConnection in some cases. Bailing |
| 613 // out for this error for now. | 618 // out for this error for now. |
| 614 audio_input->HandleError(result); | 619 audio_input->HandleError(result); |
| 615 } | 620 } |
| 616 return result; | 621 return result; |
| 617 } | 622 } |
| 618 // Update time of successful call to AudioUnitRender(). | 623 // Update time of successful call to AudioUnitRender(). |
| 619 audio_input->last_success_time_ = base::TimeTicks::Now(); | 624 audio_input->last_success_time_ = base::TimeTicks::Now(); |
| 620 | 625 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 manager_->low_latency_input_streams()); | 861 manager_->low_latency_input_streams()); |
| 857 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", | 862 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", |
| 858 manager_->basic_input_streams()); | 863 manager_->basic_input_streams()); |
| 859 // TODO(henrika): this value will currently always report true. It should be | 864 // TODO(henrika): this value will currently always report true. It should be |
| 860 // fixed when we understand the problem better. | 865 // fixed when we understand the problem better. |
| 861 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", | 866 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", |
| 862 GetAutomaticGainControl()); | 867 GetAutomaticGainControl()); |
| 863 } | 868 } |
| 864 | 869 |
| 865 } // namespace media | 870 } // namespace media |
| OLD | NEW |