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> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
11 | 13 |
12 namespace media { | 14 namespace media { |
13 | 15 |
14 AudioOutputStreamSink::AudioOutputStreamSink() | 16 AudioOutputStreamSink::AudioOutputStreamSink() |
15 : initialized_(false), | 17 : initialized_(false), |
16 started_(false), | 18 started_(false), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 78 } |
77 | 79 |
78 int AudioOutputStreamSink::OnMoreData(AudioBus* dest, | 80 int AudioOutputStreamSink::OnMoreData(AudioBus* dest, |
79 uint32_t total_bytes_delay, | 81 uint32_t total_bytes_delay, |
80 uint32_t frames_skipped) { | 82 uint32_t frames_skipped) { |
81 // Note: Runs on the audio thread created by the OS. | 83 // Note: Runs on the audio thread created by the OS. |
82 base::AutoLock al(callback_lock_); | 84 base::AutoLock al(callback_lock_); |
83 if (!active_render_callback_) | 85 if (!active_render_callback_) |
84 return 0; | 86 return 0; |
85 | 87 |
86 return active_render_callback_->Render( | 88 uint32_t frames_delayed = std::round(static_cast<double>(total_bytes_delay) / |
87 dest, total_bytes_delay * 1000.0 / active_params_.GetBytesPerSecond(), 0); | 89 active_params_.GetBytesPerFrame()); |
| 90 |
| 91 return active_render_callback_->Render(dest, frames_delayed, frames_skipped); |
88 } | 92 } |
89 | 93 |
90 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) { | 94 void AudioOutputStreamSink::OnError(AudioOutputStream* stream) { |
91 // Note: Runs on the audio thread created by the OS. | 95 // Note: Runs on the audio thread created by the OS. |
92 base::AutoLock al(callback_lock_); | 96 base::AutoLock al(callback_lock_); |
93 if (active_render_callback_) | 97 if (active_render_callback_) |
94 active_render_callback_->OnRenderError(); | 98 active_render_callback_->OnRenderError(); |
95 } | 99 } |
96 | 100 |
97 void AudioOutputStreamSink::DoStart(const AudioParameters& params) { | 101 void AudioOutputStreamSink::DoStart(const AudioParameters& params) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 143 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
140 stream_->SetVolume(volume); | 144 stream_->SetVolume(volume); |
141 } | 145 } |
142 | 146 |
143 void AudioOutputStreamSink::ClearCallback() { | 147 void AudioOutputStreamSink::ClearCallback() { |
144 base::AutoLock al(callback_lock_); | 148 base::AutoLock al(callback_lock_); |
145 active_render_callback_ = NULL; | 149 active_render_callback_ = NULL; |
146 } | 150 } |
147 | 151 |
148 } // namepace media | 152 } // namepace media |
OLD | NEW |