| 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 #include <CoreServices/CoreServices.h> | 6 #include <CoreServices/CoreServices.h> |
| 7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/mac_logging.h" | 12 #include "base/mac/mac_logging.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "media/audio/mac/audio_manager_mac.h" | 18 #include "media/audio/mac/audio_manager_mac.h" |
| 18 #include "media/base/audio_bus.h" | 19 #include "media/base/audio_bus.h" |
| 19 #include "media/base/data_buffer.h" | 20 #include "media/base/data_buffer.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 // Number of blocks of buffers used in the |fifo_|. | 24 // Number of blocks of buffers used in the |fifo_|. |
| 24 const int kNumberOfBlocksBufferInFifo = 2; | 25 const int kNumberOfBlocksBufferInFifo = 2; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 DVLOG(1) << "logical processors: " << base::SysInfo::NumberOfProcessors(); | 230 DVLOG(1) << "logical processors: " << base::SysInfo::NumberOfProcessors(); |
| 230 DVLOG(1) << "physical processors: " << NumberOfPhysicalProcessors(); | 231 DVLOG(1) << "physical processors: " << NumberOfPhysicalProcessors(); |
| 231 DVLOG(1) << "battery power: " << is_on_battery; | 232 DVLOG(1) << "battery power: " << is_on_battery; |
| 232 DVLOG(1) << "resume events: " << num_resumes; | 233 DVLOG(1) << "resume events: " << num_resumes; |
| 233 } | 234 } |
| 234 | 235 |
| 235 // See "Technical Note TN2091 - Device input using the HAL Output Audio Unit" | 236 // See "Technical Note TN2091 - Device input using the HAL Output Audio Unit" |
| 236 // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html | 237 // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html |
| 237 // for more details and background regarding this implementation. | 238 // for more details and background regarding this implementation. |
| 238 | 239 |
| 239 AUAudioInputStream::AUAudioInputStream(AudioManagerMac* manager, | 240 AUAudioInputStream::AUAudioInputStream( |
| 240 const AudioParameters& input_params, | 241 AudioManagerMac* manager, |
| 241 AudioDeviceID audio_device_id) | 242 const AudioParameters& input_params, |
| 243 AudioDeviceID audio_device_id, |
| 244 const AudioManager::LogCallback& log_callback) |
| 242 : manager_(manager), | 245 : manager_(manager), |
| 243 number_of_frames_(input_params.frames_per_buffer()), | 246 number_of_frames_(input_params.frames_per_buffer()), |
| 244 number_of_frames_provided_(0), | 247 number_of_frames_provided_(0), |
| 245 io_buffer_frame_size_(0), | 248 io_buffer_frame_size_(0), |
| 246 sink_(nullptr), | 249 sink_(nullptr), |
| 247 audio_unit_(0), | 250 audio_unit_(0), |
| 248 input_device_id_(audio_device_id), | 251 input_device_id_(audio_device_id), |
| 249 hardware_latency_frames_(0), | 252 hardware_latency_frames_(0), |
| 250 number_of_channels_in_frame_(0), | 253 number_of_channels_in_frame_(0), |
| 251 fifo_(input_params.channels(), | 254 fifo_(input_params.channels(), |
| 252 number_of_frames_, | 255 number_of_frames_, |
| 253 kNumberOfBlocksBufferInFifo), | 256 kNumberOfBlocksBufferInFifo), |
| 254 input_callback_is_active_(false), | 257 input_callback_is_active_(false), |
| 255 start_was_deferred_(false), | 258 start_was_deferred_(false), |
| 256 buffer_size_was_changed_(false), | 259 buffer_size_was_changed_(false), |
| 257 audio_unit_render_has_worked_(false), | 260 audio_unit_render_has_worked_(false), |
| 258 device_listener_is_active_(false), | 261 device_listener_is_active_(false), |
| 259 last_sample_time_(0.0), | 262 last_sample_time_(0.0), |
| 260 last_number_of_frames_(0), | 263 last_number_of_frames_(0), |
| 261 total_lost_frames_(0), | 264 total_lost_frames_(0), |
| 262 largest_glitch_frames_(0), | 265 largest_glitch_frames_(0), |
| 263 glitches_detected_(0), | 266 glitches_detected_(0), |
| 264 number_of_restart_indications_(0), | 267 number_of_restart_indications_(0), |
| 265 number_of_restart_attempts_(0), | 268 number_of_restart_attempts_(0), |
| 266 total_number_of_restart_attempts_(0), | 269 total_number_of_restart_attempts_(0), |
| 270 log_callback_(log_callback), |
| 267 weak_factory_(this) { | 271 weak_factory_(this) { |
| 268 DCHECK(manager_); | 272 DCHECK(manager_); |
| 269 | 273 |
| 270 // Set up the desired (output) format specified by the client. | 274 // Set up the desired (output) format specified by the client. |
| 271 format_.mSampleRate = input_params.sample_rate(); | 275 format_.mSampleRate = input_params.sample_rate(); |
| 272 format_.mFormatID = kAudioFormatLinearPCM; | 276 format_.mFormatID = kAudioFormatLinearPCM; |
| 273 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | | 277 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | |
| 274 kLinearPCMFormatFlagIsSignedInteger; | 278 kLinearPCMFormatFlagIsSignedInteger; |
| 275 DCHECK(FormatIsInterleaved(format_.mFormatFlags)); | 279 DCHECK(FormatIsInterleaved(format_.mFormatFlags)); |
| 276 format_.mBitsPerChannel = input_params.bits_per_sample(); | 280 format_.mBitsPerChannel = input_params.bits_per_sample(); |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 if (last_sample_time_ == 0) | 1642 if (last_sample_time_ == 0) |
| 1639 return; // No stats gathered to report. | 1643 return; // No stats gathered to report. |
| 1640 | 1644 |
| 1641 // A value of 0 indicates that we got the buffer size we asked for. | 1645 // A value of 0 indicates that we got the buffer size we asked for. |
| 1642 UMA_HISTOGRAM_COUNTS_10000("Media.Audio.Capture.FramesProvided", | 1646 UMA_HISTOGRAM_COUNTS_10000("Media.Audio.Capture.FramesProvided", |
| 1643 number_of_frames_provided_); | 1647 number_of_frames_provided_); |
| 1644 // Even if there aren't any glitches, we want to record it to get a feel for | 1648 // Even if there aren't any glitches, we want to record it to get a feel for |
| 1645 // how often we get no glitches vs the alternative. | 1649 // how often we get no glitches vs the alternative. |
| 1646 UMA_HISTOGRAM_COUNTS("Media.Audio.Capture.Glitches", glitches_detected_); | 1650 UMA_HISTOGRAM_COUNTS("Media.Audio.Capture.Glitches", glitches_detected_); |
| 1647 | 1651 |
| 1652 auto lost_frames_ms = (total_lost_frames_ * 1000) / format_.mSampleRate; |
| 1653 std::string log_message = base::StringPrintf( |
| 1654 "AU in: Total glitches=%d. Total frames lost=%d (%.0lf ms).", |
| 1655 glitches_detected_, total_lost_frames_, lost_frames_ms); |
| 1656 log_callback_.Run(log_message); |
| 1657 |
| 1648 if (glitches_detected_ != 0) { | 1658 if (glitches_detected_ != 0) { |
| 1649 auto lost_frames_ms = (total_lost_frames_ * 1000) / format_.mSampleRate; | |
| 1650 UMA_HISTOGRAM_LONG_TIMES("Media.Audio.Capture.LostFramesInMs", | 1659 UMA_HISTOGRAM_LONG_TIMES("Media.Audio.Capture.LostFramesInMs", |
| 1651 base::TimeDelta::FromMilliseconds(lost_frames_ms)); | 1660 base::TimeDelta::FromMilliseconds(lost_frames_ms)); |
| 1652 auto largest_glitch_ms = | 1661 auto largest_glitch_ms = |
| 1653 (largest_glitch_frames_ * 1000) / format_.mSampleRate; | 1662 (largest_glitch_frames_ * 1000) / format_.mSampleRate; |
| 1654 UMA_HISTOGRAM_CUSTOM_TIMES( | 1663 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 1655 "Media.Audio.Capture.LargestGlitchMs", | 1664 "Media.Audio.Capture.LargestGlitchMs", |
| 1656 base::TimeDelta::FromMilliseconds(largest_glitch_ms), | 1665 base::TimeDelta::FromMilliseconds(largest_glitch_ms), |
| 1657 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1), | 1666 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1), |
| 1658 50); | 1667 50); |
| 1659 DLOG(WARNING) << "Total glitches=" << glitches_detected_ | 1668 DLOG(WARNING) << log_message; |
| 1660 << ". Total frames lost=" << total_lost_frames_ << " (" | |
| 1661 << lost_frames_ms << ")"; | |
| 1662 } | 1669 } |
| 1663 | 1670 |
| 1664 number_of_frames_provided_ = 0; | 1671 number_of_frames_provided_ = 0; |
| 1665 glitches_detected_ = 0; | 1672 glitches_detected_ = 0; |
| 1666 last_sample_time_ = 0; | 1673 last_sample_time_ = 0; |
| 1667 last_number_of_frames_ = 0; | 1674 last_number_of_frames_ = 0; |
| 1668 total_lost_frames_ = 0; | 1675 total_lost_frames_ = 0; |
| 1669 largest_glitch_frames_ = 0; | 1676 largest_glitch_frames_ = 0; |
| 1670 } | 1677 } |
| 1671 | 1678 |
| 1672 } // namespace media | 1679 } // namespace media |
| OLD | NEW |