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