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

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

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Changes based on comments 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_stream_sink.h" 5 #include "media/audio/audio_output_stream_sink.h"
6 6
7 #include <algorithm>
7 #include <cmath> 8 #include <cmath>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 AudioOutputStreamSink::AudioOutputStreamSink() 17 AudioOutputStreamSink::AudioOutputStreamSink()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 76
76 OutputDeviceInfo AudioOutputStreamSink::GetOutputDeviceInfo() { 77 OutputDeviceInfo AudioOutputStreamSink::GetOutputDeviceInfo() {
77 return OutputDeviceInfo(); 78 return OutputDeviceInfo();
78 } 79 }
79 80
80 bool AudioOutputStreamSink::CurrentThreadIsRenderingThread() { 81 bool AudioOutputStreamSink::CurrentThreadIsRenderingThread() {
81 NOTIMPLEMENTED(); 82 NOTIMPLEMENTED();
82 return false; 83 return false;
83 } 84 }
84 85
85 int AudioOutputStreamSink::OnMoreData(AudioBus* dest, 86 int AudioOutputStreamSink::OnMoreData(base::TimeTicks target_playout_time,
86 uint32_t total_bytes_delay, 87 int prior_frames_skipped,
87 uint32_t frames_skipped) { 88 AudioBus* dest) {
88 // Note: Runs on the audio thread created by the OS. 89 // Note: Runs on the audio thread created by the OS.
89 base::AutoLock al(callback_lock_); 90 base::AutoLock al(callback_lock_);
90 if (!active_render_callback_) 91 if (!active_render_callback_)
91 return 0; 92 return 0;
92 93
93 uint32_t frames_delayed = std::round(static_cast<double>(total_bytes_delay) / 94 base::TimeDelta delay =
94 active_params_.GetBytesPerFrame()); 95 std::max(target_playout_time - base::TimeTicks::Now(), base::TimeDelta());
96 uint32_t frames_delayed = delay.InSeconds() * active_params_.sample_rate();
miu 2016/08/31 23:26:54 s/InSeconds/InSecondsF/ to prevent serious loss of
James West 2016/09/13 07:40:50 Done.
95 97
96 return active_render_callback_->Render(dest, frames_delayed, frames_skipped); 98 return active_render_callback_->Render(dest, frames_delayed,
99 prior_frames_skipped);
97 } 100 }
98 101
99 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) { 102 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) {
100 // Note: Runs on the audio thread created by the OS. 103 // Note: Runs on the audio thread created by the OS.
101 base::AutoLock al(callback_lock_); 104 base::AutoLock al(callback_lock_);
102 if (active_render_callback_) 105 if (active_render_callback_)
103 active_render_callback_->OnRenderError(); 106 active_render_callback_->OnRenderError();
104 } 107 }
105 108
106 void AudioOutputStreamSink::DoStart(const AudioParameters& params) { 109 void AudioOutputStreamSink::DoStart(const AudioParameters& params) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void AudioOutputStreamSink::DoSetVolume(double volume) { 150 void AudioOutputStreamSink::DoSetVolume(double volume) {
148 DCHECK(audio_task_runner_->BelongsToCurrentThread()); 151 DCHECK(audio_task_runner_->BelongsToCurrentThread());
149 stream_->SetVolume(volume); 152 stream_->SetVolume(volume);
150 } 153 }
151 154
152 void AudioOutputStreamSink::ClearCallback() { 155 void AudioOutputStreamSink::ClearCallback() {
153 base::AutoLock al(callback_lock_); 156 base::AutoLock al(callback_lock_);
154 active_render_callback_ = NULL; 157 active_render_callback_ = NULL;
155 } 158 }
156 159
157 } // namepace media 160 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698