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 <limits> | 10 #include <limits> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
13 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
14 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 | 19 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 if (stream_ != diverting_to_stream_) | 286 if (stream_ != diverting_to_stream_) |
286 OnDeviceChange(); | 287 OnDeviceChange(); |
287 } | 288 } |
288 | 289 |
289 void AudioOutputController::DoReportError() { | 290 void AudioOutputController::DoReportError() { |
290 DCHECK(message_loop_->BelongsToCurrentThread()); | 291 DCHECK(message_loop_->BelongsToCurrentThread()); |
291 if (state_ != kClosed) | 292 if (state_ != kClosed) |
292 handler_->OnError(); | 293 handler_->OnError(); |
293 } | 294 } |
294 | 295 |
295 int AudioOutputController::OnMoreData(AudioBus* dest, | 296 int AudioOutputController::OnMoreData(base::TimeTicks target_playout_time, |
296 uint32_t total_bytes_delay, | 297 int prior_frames_skipped, |
297 uint32_t frames_skipped) { | 298 AudioBus* dest) { |
298 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); | 299 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); |
299 | 300 |
300 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() | 301 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() |
301 // may have already fired if OnMoreData() took an abnormal amount of time). | 302 // may have already fired if OnMoreData() took an abnormal amount of time). |
302 // Since this thread is the only writer of |on_more_io_data_called_| once the | 303 // Since this thread is the only writer of |on_more_io_data_called_| once the |
303 // thread starts, its safe to compare and then increment. | 304 // thread starts, its safe to compare and then increment. |
304 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) | 305 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) |
305 base::AtomicRefCountInc(&on_more_io_data_called_); | 306 base::AtomicRefCountInc(&on_more_io_data_called_); |
306 | 307 |
307 sync_reader_->Read(dest); | 308 sync_reader_->Read(dest); |
308 | 309 |
310 const base::TimeDelta delay = | |
chcunningham
2016/08/27 00:36:18
Can you add a comment explaining why this guard is
miu
2016/08/31 23:26:54
Looks like this API change should propagate throug
jameswest
2016/09/07 21:52:16
When the number of bytes is passed to UpdatePendin
miu
2016/09/07 22:19:36
The consumer is media::AudioDeviceThread: https://
James West
2016/09/13 07:40:50
I'm happy to do this, but I think it should be a s
miu
2016/09/16 18:35:58
SGTM.
| |
311 std::max(target_playout_time - base::TimeTicks::Now(), base::TimeDelta()); | |
312 const int total_bytes_delay = delay.InSeconds() * params_.GetBytesPerSecond(); | |
miu
2016/08/31 23:26:54
s/InSeconds/InSecondsF/ to prevent serious loss of
James West
2016/09/13 07:40:50
Done.
| |
309 const int frames = dest->frames(); | 313 const int frames = dest->frames(); |
310 sync_reader_->UpdatePendingBytes( | 314 sync_reader_->UpdatePendingBytes( |
311 total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); | 315 total_bytes_delay + frames * params_.GetBytesPerFrame(), |
316 prior_frames_skipped); | |
312 | 317 |
313 bool need_to_duplicate = false; | 318 bool need_to_duplicate = false; |
314 { | 319 { |
315 base::AutoLock lock(duplication_targets_lock_); | 320 base::AutoLock lock(duplication_targets_lock_); |
316 need_to_duplicate = !duplication_targets_.empty(); | 321 need_to_duplicate = !duplication_targets_.empty(); |
317 } | 322 } |
318 if (need_to_duplicate) { | 323 if (need_to_duplicate) { |
319 const base::TimeTicks reference_time = | |
320 base::TimeTicks::Now() + | |
321 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | |
322 total_bytes_delay / | |
323 params_.GetBytesPerSecond()); | |
324 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); | 324 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); |
325 dest->CopyTo(copy.get()); | 325 dest->CopyTo(copy.get()); |
326 message_loop_->PostTask( | 326 message_loop_->PostTask( |
327 FROM_HERE, | 327 FROM_HERE, |
328 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets, | 328 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets, |
329 this, base::Passed(©), reference_time)); | 329 this, base::Passed(©), target_playout_time)); |
330 } | 330 } |
331 | 331 |
332 if (will_monitor_audio_levels()) | 332 if (will_monitor_audio_levels()) |
333 power_monitor_.Scan(*dest, frames); | 333 power_monitor_.Scan(*dest, frames); |
334 | 334 |
335 return frames; | 335 return frames; |
336 } | 336 } |
337 | 337 |
338 void AudioOutputController::BroadcastDataToDuplicationTargets( | 338 void AudioOutputController::BroadcastDataToDuplicationTargets( |
339 std::unique_ptr<AudioBus> audio_bus, | 339 std::unique_ptr<AudioBus> audio_bus, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 DCHECK(message_loop_->BelongsToCurrentThread()); | 505 DCHECK(message_loop_->BelongsToCurrentThread()); |
506 | 506 |
507 // If we should be playing and we haven't, that's a wedge. | 507 // If we should be playing and we haven't, that's a wedge. |
508 if (state_ == kPlaying) { | 508 if (state_ == kPlaying) { |
509 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 509 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
510 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 510 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
511 } | 511 } |
512 } | 512 } |
513 | 513 |
514 } // namespace media | 514 } // namespace media |
OLD | NEW |