OLD | NEW |
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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 OutputDeviceInfo AudioOutputStreamSink::GetOutputDeviceInfo() { | 76 OutputDeviceInfo AudioOutputStreamSink::GetOutputDeviceInfo() { |
77 return OutputDeviceInfo(); | 77 return OutputDeviceInfo(); |
78 } | 78 } |
79 | 79 |
80 bool AudioOutputStreamSink::CurrentThreadIsRenderingThread() { | 80 bool AudioOutputStreamSink::CurrentThreadIsRenderingThread() { |
81 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
82 return false; | 82 return false; |
83 } | 83 } |
84 | 84 |
85 int AudioOutputStreamSink::OnMoreData(AudioBus* dest, | 85 int AudioOutputStreamSink::OnMoreData(base::TimeTicks target_playout_time, |
86 uint32_t total_bytes_delay, | 86 int prior_frames_skipped, |
87 uint32_t frames_skipped) { | 87 AudioBus* dest) { |
88 // Note: Runs on the audio thread created by the OS. | 88 // Note: Runs on the audio thread created by the OS. |
89 base::AutoLock al(callback_lock_); | 89 base::AutoLock al(callback_lock_); |
90 if (!active_render_callback_) | 90 if (!active_render_callback_) |
91 return 0; | 91 return 0; |
92 | 92 |
93 uint32_t frames_delayed = std::round(static_cast<double>(total_bytes_delay) / | 93 base::TimeDelta delay = target_playout_time - base::TimeTicks::Now(); |
94 active_params_.GetBytesPerFrame()); | 94 uint32_t frames_delayed = delay.InSeconds() * active_params_.sample_rate(); |
95 | 95 |
96 return active_render_callback_->Render(dest, frames_delayed, frames_skipped); | 96 return active_render_callback_->Render(dest, frames_delayed, |
| 97 prior_frames_skipped); |
97 } | 98 } |
98 | 99 |
99 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) { | 100 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) { |
100 // Note: Runs on the audio thread created by the OS. | 101 // Note: Runs on the audio thread created by the OS. |
101 base::AutoLock al(callback_lock_); | 102 base::AutoLock al(callback_lock_); |
102 if (active_render_callback_) | 103 if (active_render_callback_) |
103 active_render_callback_->OnRenderError(); | 104 active_render_callback_->OnRenderError(); |
104 } | 105 } |
105 | 106 |
106 void AudioOutputStreamSink::DoStart(const AudioParameters& params) { | 107 void AudioOutputStreamSink::DoStart(const AudioParameters& params) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 void AudioOutputStreamSink::DoSetVolume(double volume) { | 148 void AudioOutputStreamSink::DoSetVolume(double volume) { |
148 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 149 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
149 stream_->SetVolume(volume); | 150 stream_->SetVolume(volume); |
150 } | 151 } |
151 | 152 |
152 void AudioOutputStreamSink::ClearCallback() { | 153 void AudioOutputStreamSink::ClearCallback() { |
153 base::AutoLock al(callback_lock_); | 154 base::AutoLock al(callback_lock_); |
154 active_render_callback_ = NULL; | 155 active_render_callback_ = NULL; |
155 } | 156 } |
156 | 157 |
157 } // namepace media | 158 } // namespace media |
OLD | NEW |