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