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/audio_output_controller.h" | 5 #include "media/audio/audio_output_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 20 #include "media/base/audio_timestamp_helper.h" | 20 #include "media/base/audio_timestamp_helper.h" |
| 21 | 21 |
| 22 using base::TimeDelta; | 22 using base::TimeDelta; |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 namespace { | |
| 26 // Time in seconds between two successive measurements of audio power levels. | |
| 27 constexpr int kPowerMonitorLogIntervalSeconds = 15; | |
| 28 } // namespace | |
| 25 | 29 |
| 26 AudioOutputController::AudioOutputController( | 30 AudioOutputController::AudioOutputController( |
| 27 AudioManager* audio_manager, | 31 AudioManager* audio_manager, |
| 28 EventHandler* handler, | 32 EventHandler* handler, |
| 29 const AudioParameters& params, | 33 const AudioParameters& params, |
| 30 const std::string& output_device_id, | 34 const std::string& output_device_id, |
| 31 SyncReader* sync_reader) | 35 SyncReader* sync_reader) |
| 32 : audio_manager_(audio_manager), | 36 : audio_manager_(audio_manager), |
| 33 params_(params), | 37 params_(params), |
| 34 handler_(handler), | 38 handler_(handler), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 162 |
| 159 // We can start from created or paused state. | 163 // We can start from created or paused state. |
| 160 if (state_ != kCreated && state_ != kPaused) | 164 if (state_ != kCreated && state_ != kPaused) |
| 161 return; | 165 return; |
| 162 | 166 |
| 163 // Ask for first packet. | 167 // Ask for first packet. |
| 164 sync_reader_->RequestMoreData(base::TimeDelta(), base::TimeTicks(), 0); | 168 sync_reader_->RequestMoreData(base::TimeDelta(), base::TimeTicks(), 0); |
| 165 | 169 |
| 166 state_ = kPlaying; | 170 state_ = kPlaying; |
| 167 | 171 |
| 172 if (will_monitor_audio_levels()) { | |
| 173 last_audio_level_log_time_ = base::TimeTicks::Now(); | |
|
liberato (no reviews please)
2017/05/30 17:00:53
i think that this will be default-constructed to 0
ossu-chromium
2017/05/31 11:44:40
Acknowledged.
ossu-chromium
2017/05/31 11:44:40
It needs to be reset to something in DoPlay, and N
liberato (no reviews please)
2017/05/31 19:39:22
ah -- i mis-read the diff. yeah, you're right.
a
| |
| 174 } | |
| 175 | |
| 168 stream_->Start(this); | 176 stream_->Start(this); |
| 169 | 177 |
| 170 // For UMA tracking purposes, start the wedge detection timer. This allows us | 178 // For UMA tracking purposes, start the wedge detection timer. This allows us |
| 171 // to record statistics about the number of wedged playbacks in the field. | 179 // to record statistics about the number of wedged playbacks in the field. |
| 172 // | 180 // |
| 173 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after | 181 // WedgeCheck() will look to see if |on_more_io_data_called_| is true after |
| 174 // the timeout expires. Care must be taken to ensure the wedge check delay is | 182 // the timeout expires. Care must be taken to ensure the wedge check delay is |
| 175 // large enough that the value isn't queried while OnMoreDataIO() is setting | 183 // large enough that the value isn't queried while OnMoreDataIO() is setting |
| 176 // it. | 184 // it. |
| 177 // | 185 // |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 const base::TimeTicks reference_time = delay_timestamp + delay; | 289 const base::TimeTicks reference_time = delay_timestamp + delay; |
| 282 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); | 290 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); |
| 283 dest->CopyTo(copy.get()); | 291 dest->CopyTo(copy.get()); |
| 284 message_loop_->PostTask( | 292 message_loop_->PostTask( |
| 285 FROM_HERE, | 293 FROM_HERE, |
| 286 base::BindOnce( | 294 base::BindOnce( |
| 287 &AudioOutputController::BroadcastDataToDuplicationTargets, this, | 295 &AudioOutputController::BroadcastDataToDuplicationTargets, this, |
| 288 std::move(copy), reference_time)); | 296 std::move(copy), reference_time)); |
| 289 } | 297 } |
| 290 | 298 |
| 291 if (will_monitor_audio_levels()) | 299 if (will_monitor_audio_levels()) { |
| 292 power_monitor_.Scan(*dest, frames); | 300 power_monitor_.Scan(*dest, frames); |
| 293 | 301 |
| 302 const auto now = base::TimeTicks::Now(); | |
| 303 if ((now - last_audio_level_log_time_).InSeconds() > | |
| 304 kPowerMonitorLogIntervalSeconds) { | |
| 305 std::pair<float, bool> power_and_clip = | |
| 306 power_monitor_.ReadCurrentPowerAndClip(); | |
| 307 | |
| 308 handler_->OnLog( | |
| 309 base::StringPrintf("AOC::OnMoreData: average audio level=%.2f dBFS", | |
| 310 power_and_clip.first)); | |
| 311 last_audio_level_log_time_ = now; | |
| 312 } | |
| 313 } | |
| 314 | |
| 294 return frames; | 315 return frames; |
| 295 } | 316 } |
| 296 | 317 |
| 297 void AudioOutputController::BroadcastDataToDuplicationTargets( | 318 void AudioOutputController::BroadcastDataToDuplicationTargets( |
| 298 std::unique_ptr<AudioBus> audio_bus, | 319 std::unique_ptr<AudioBus> audio_bus, |
| 299 base::TimeTicks reference_time) { | 320 base::TimeTicks reference_time) { |
| 300 DCHECK(message_loop_->BelongsToCurrentThread()); | 321 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 301 if (state_ != kPlaying || duplication_targets_.empty()) | 322 if (state_ != kPlaying || duplication_targets_.empty()) |
| 302 return; | 323 return; |
| 303 | 324 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 DCHECK(message_loop_->BelongsToCurrentThread()); | 511 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 491 | 512 |
| 492 // If we should be playing and we haven't, that's a wedge. | 513 // If we should be playing and we haven't, that's a wedge. |
| 493 if (state_ == kPlaying) { | 514 if (state_ == kPlaying) { |
| 494 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 515 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
| 495 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 516 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
| 496 } | 517 } |
| 497 } | 518 } |
| 498 | 519 |
| 499 } // namespace media | 520 } // namespace media |
| OLD | NEW |