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 = target_playout_time - base::TimeTicks::Now(); | |
DaleCurtis
2016/07/27 18:25:55
Hmm, if you don't pipe this through to the rendere
jameswest
2016/07/27 23:07:50
We don't use this renderer for Cast multizone audi
DaleCurtis
2016/07/28 01:21:47
I thought this API was still used with WebAudio? O
jameswest
2016/07/28 02:09:39
It's not used for multizone audio playback, but I
chcunningham
2016/07/29 01:21:09
Should we be gaurding against negative values here
miu
2016/07/30 21:17:02
If negative delay creeps in, for output streams wh
jameswest
2016/08/26 02:08:47
There are some cases where the delay will be negat
chcunningham
2016/08/27 00:36:18
I'm fine with either approach. I slightly favor th
| |
311 const int total_bytes_delay = delay.InSeconds() * params_.GetBytesPerSecond(); | |
309 const int frames = dest->frames(); | 312 const int frames = dest->frames(); |
310 sync_reader_->UpdatePendingBytes( | 313 sync_reader_->UpdatePendingBytes( |
311 total_bytes_delay + frames * params_.GetBytesPerFrame(), frames_skipped); | 314 total_bytes_delay + frames * params_.GetBytesPerFrame(), |
315 prior_frames_skipped); | |
312 | 316 |
313 bool need_to_duplicate = false; | 317 bool need_to_duplicate = false; |
314 { | 318 { |
315 base::AutoLock lock(duplication_targets_lock_); | 319 base::AutoLock lock(duplication_targets_lock_); |
316 need_to_duplicate = !duplication_targets_.empty(); | 320 need_to_duplicate = !duplication_targets_.empty(); |
317 } | 321 } |
318 if (need_to_duplicate) { | 322 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_)); | 323 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_)); |
325 dest->CopyTo(copy.get()); | 324 dest->CopyTo(copy.get()); |
326 message_loop_->PostTask( | 325 message_loop_->PostTask( |
327 FROM_HERE, | 326 FROM_HERE, |
328 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets, | 327 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets, |
329 this, base::Passed(©), reference_time)); | 328 this, base::Passed(©), target_playout_time)); |
330 } | 329 } |
331 | 330 |
332 if (will_monitor_audio_levels()) | 331 if (will_monitor_audio_levels()) |
333 power_monitor_.Scan(*dest, frames); | 332 power_monitor_.Scan(*dest, frames); |
334 | 333 |
335 return frames; | 334 return frames; |
336 } | 335 } |
337 | 336 |
338 void AudioOutputController::BroadcastDataToDuplicationTargets( | 337 void AudioOutputController::BroadcastDataToDuplicationTargets( |
339 std::unique_ptr<AudioBus> audio_bus, | 338 std::unique_ptr<AudioBus> audio_bus, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 DCHECK(message_loop_->BelongsToCurrentThread()); | 504 DCHECK(message_loop_->BelongsToCurrentThread()); |
506 | 505 |
507 // If we should be playing and we haven't, that's a wedge. | 506 // If we should be playing and we haven't, that's a wedge. |
508 if (state_ == kPlaying) { | 507 if (state_ == kPlaying) { |
509 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", | 508 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", |
510 base::AtomicRefCountIsOne(&on_more_io_data_called_)); | 509 base::AtomicRefCountIsOne(&on_more_io_data_called_)); |
511 } | 510 } |
512 } | 511 } |
513 | 512 |
514 } // namespace media | 513 } // namespace media |
OLD | NEW |