Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: media/audio/audio_output_controller.cc

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix Windows CQ errors. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::TimeDelta delay,
296 uint32_t total_bytes_delay, 297 base::TimeTicks /* delay_timestamp */,
297 uint32_t frames_skipped) { 298 int prior_frames_skipped,
299 AudioBus* dest) {
298 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData"); 300 TRACE_EVENT0("audio", "AudioOutputController::OnMoreData");
299 301
300 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck() 302 // Indicate that we haven't wedged (at least not indefinitely, WedgeCheck()
301 // may have already fired if OnMoreData() took an abnormal amount of time). 303 // 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 304 // 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. 305 // thread starts, its safe to compare and then increment.
304 if (base::AtomicRefCountIsZero(&on_more_io_data_called_)) 306 if (base::AtomicRefCountIsZero(&on_more_io_data_called_))
305 base::AtomicRefCountInc(&on_more_io_data_called_); 307 base::AtomicRefCountInc(&on_more_io_data_called_);
306 308
307 sync_reader_->Read(dest); 309 sync_reader_->Read(dest);
308 310
311 const int total_bytes_delay =
312 delay.InSecondsF() * params_.GetBytesPerSecond();
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 = 324 const base::TimeTicks reference_time = base::TimeTicks::Now() + delay;
miu 2016/09/28 23:04:41 Seems like this should be: reference_time = del
jameswest 2016/09/29 00:52:24 Done.
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_)); 325 std::unique_ptr<AudioBus> copy(AudioBus::Create(params_));
325 dest->CopyTo(copy.get()); 326 dest->CopyTo(copy.get());
326 message_loop_->PostTask( 327 message_loop_->PostTask(
327 FROM_HERE, 328 FROM_HERE,
328 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets, 329 base::Bind(&AudioOutputController::BroadcastDataToDuplicationTargets,
329 this, base::Passed(&copy), reference_time)); 330 this, base::Passed(&copy), reference_time));
330 } 331 }
331 332
332 if (will_monitor_audio_levels()) 333 if (will_monitor_audio_levels())
333 power_monitor_.Scan(*dest, frames); 334 power_monitor_.Scan(*dest, frames);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 DCHECK(message_loop_->BelongsToCurrentThread()); 506 DCHECK(message_loop_->BelongsToCurrentThread());
506 507
507 // If we should be playing and we haven't, that's a wedge. 508 // If we should be playing and we haven't, that's a wedge.
508 if (state_ == kPlaying) { 509 if (state_ == kPlaying) {
509 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess", 510 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputControllerPlaybackStartupSuccess",
510 base::AtomicRefCountIsOne(&on_more_io_data_called_)); 511 base::AtomicRefCountIsOne(&on_more_io_data_called_));
511 } 512 }
512 } 513 }
513 514
514 } // namespace media 515 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698