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/audio_output_resampler.h" | 5 #include "media/audio/audio_output_resampler.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/metrics/sparse_histogram.h" | |
14 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "media/audio/audio_output_proxy.h" | 19 #include "media/audio/audio_output_proxy.h" |
19 #include "media/audio/sample_rates.h" | 20 #include "media/audio/sample_rates.h" |
20 #include "media/base/audio_converter.h" | 21 #include "media/base/audio_converter.h" |
21 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
22 | 23 |
23 namespace media { | 24 namespace media { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 UMA_HISTOGRAM_ENUMERATION( | 129 UMA_HISTOGRAM_ENUMERATION( |
129 "Media.FallbackHardwareAudioSamplesPerSecond", | 130 "Media.FallbackHardwareAudioSamplesPerSecond", |
130 asr, kAudioSampleRateMax + 1); | 131 asr, kAudioSampleRateMax + 1); |
131 } else { | 132 } else { |
132 UMA_HISTOGRAM_COUNTS( | 133 UMA_HISTOGRAM_COUNTS( |
133 "Media.FallbackHardwareAudioSamplesPerSecondUnexpected", | 134 "Media.FallbackHardwareAudioSamplesPerSecondUnexpected", |
134 output_params.sample_rate()); | 135 output_params.sample_rate()); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
139 // Record UMA statistics for input/output rebuffering. | |
140 static void RecordRebufferingStats(const AudioParameters& input_params, | |
141 const AudioParameters& output_params) { | |
142 const int& input_buffer_size = input_params.frames_per_buffer(); | |
143 const int& output_buffer_size = output_params.frames_per_buffer(); | |
Ilya Sherman
2016/08/24 22:20:23
nit: An int is generally going to be smaller or eq
o1ka
2016/08/25 11:48:34
It's extending lifetime of a temporary rather than
| |
144 DCHECK(input_buffer_size); | |
145 DCHECK(output_buffer_size); | |
146 int value = (output_buffer_size - input_buffer_size) * 1000 / | |
147 std::min(input_buffer_size, output_buffer_size); | |
Ilya Sherman
2016/08/24 22:20:23
What is the possible range for these values? It's
o1ka
2016/08/25 11:48:34
For both buffer sizes the range is between 128 and
Ilya Sherman
2016/08/26 00:35:34
I think you are trying to pack too much into a sin
| |
148 | |
149 switch (input_params.latency_tag()) { | |
150 case AudioLatency::LATENCY_EXACT_MS: | |
151 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
152 "Media.Audio.Render.BufferSizeMismatch.LatencyExactMs", value); | |
153 return; | |
154 case AudioLatency::LATENCY_INTERACTIVE: | |
155 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
156 "Media.Audio.Render.BufferSizeMismatch.LatencyInteractive", value); | |
157 return; | |
158 case AudioLatency::LATENCY_RTC: | |
159 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
160 "Media.Audio.Render.BufferSizeMismatch.LatencyRtc", value); | |
161 return; | |
162 case AudioLatency::LATENCY_PLAYBACK: | |
163 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
164 "Media.Audio.Render.BufferSizeMismatch.LatencyPlayback", value); | |
165 return; | |
166 default: | |
Ilya Sherman
2016/08/24 22:20:23
Please explicitly list all possible cases. AFAICT
o1ka
2016/08/25 11:48:34
Agree. Done
| |
167 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
168 "Media.Audio.Render.BufferSizeMismatch.LatencyOther", value); | |
169 } | |
170 } | |
171 | |
138 // Converts low latency based |output_params| into high latency appropriate | 172 // Converts low latency based |output_params| into high latency appropriate |
139 // output parameters in error situations. | 173 // output parameters in error situations. |
140 void AudioOutputResampler::SetupFallbackParams() { | 174 void AudioOutputResampler::SetupFallbackParams() { |
141 // Only Windows has a high latency output driver that is not the same as the low | 175 // Only Windows has a high latency output driver that is not the same as the low |
142 // latency path. | 176 // latency path. |
143 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
144 // Choose AudioParameters appropriate for opening the device in high latency | 178 // Choose AudioParameters appropriate for opening the device in high latency |
145 // mode. |kMinLowLatencyFrameSize| is arbitrarily based on Pepper Flash's | 179 // mode. |kMinLowLatencyFrameSize| is arbitrarily based on Pepper Flash's |
146 // MAXIMUM frame size for low latency. | 180 // MAXIMUM frame size for low latency. |
147 static const int kMinLowLatencyFrameSize = 2048; | 181 static const int kMinLowLatencyFrameSize = 2048; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 | 381 |
348 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, | 382 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, |
349 const AudioParameters& output_params) | 383 const AudioParameters& output_params) |
350 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / | 384 : io_ratio_(static_cast<double>(input_params.GetBytesPerSecond()) / |
351 output_params.GetBytesPerSecond()), | 385 output_params.GetBytesPerSecond()), |
352 source_callback_(nullptr), | 386 source_callback_(nullptr), |
353 input_bytes_per_frame_(input_params.GetBytesPerFrame()), | 387 input_bytes_per_frame_(input_params.GetBytesPerFrame()), |
354 audio_converter_(input_params, output_params, false), | 388 audio_converter_(input_params, output_params, false), |
355 error_occurred_(false), | 389 error_occurred_(false), |
356 input_buffer_size_(input_params.frames_per_buffer()), | 390 input_buffer_size_(input_params.frames_per_buffer()), |
357 output_buffer_size_(output_params.frames_per_buffer()) {} | 391 output_buffer_size_(output_params.frames_per_buffer()) { |
392 RecordRebufferingStats(input_params, output_params); | |
393 } | |
358 | 394 |
359 OnMoreDataConverter::~OnMoreDataConverter() { | 395 OnMoreDataConverter::~OnMoreDataConverter() { |
360 // Ensure Stop() has been called so we don't end up with an AudioOutputStream | 396 // Ensure Stop() has been called so we don't end up with an AudioOutputStream |
361 // calling back into OnMoreData() after destruction. | 397 // calling back into OnMoreData() after destruction. |
362 CHECK(!source_callback_); | 398 CHECK(!source_callback_); |
363 } | 399 } |
364 | 400 |
365 void OnMoreDataConverter::Start( | 401 void OnMoreDataConverter::Start( |
366 AudioOutputStream::AudioSourceCallback* callback) { | 402 AudioOutputStream::AudioSourceCallback* callback) { |
367 CHECK(!source_callback_); | 403 CHECK(!source_callback_); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 447 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
412 return frames > 0 ? 1 : 0; | 448 return frames > 0 ? 1 : 0; |
413 } | 449 } |
414 | 450 |
415 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 451 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
416 error_occurred_ = true; | 452 error_occurred_ = true; |
417 source_callback_->OnError(stream); | 453 source_callback_->OnError(stream); |
418 } | 454 } |
419 | 455 |
420 } // namespace media | 456 } // namespace media |
OLD | NEW |