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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 base::TimeDelta current_media_time; | 159 base::TimeDelta current_media_time; |
160 { | 160 { |
161 base::AutoLock auto_lock(lock_); | 161 base::AutoLock auto_lock(lock_); |
162 current_media_time = audio_clock_->front_timestamp(); | 162 current_media_time = audio_clock_->front_timestamp(); |
163 } | 163 } |
164 | 164 |
165 DVLOG(2) << __FUNCTION__ << ": " << current_media_time; | 165 DVLOG(2) << __FUNCTION__ << ": " << current_media_time; |
166 return current_media_time; | 166 return current_media_time; |
167 } | 167 } |
168 | 168 |
169 base::TimeDelta AudioRendererImpl::CurrentMediaTimeForSyncingVideo() { | 169 base::TimeTicks AudioRendererImpl::GetWallClockTime(base::TimeDelta time) { |
170 DVLOG(3) << __FUNCTION__; | 170 base::AutoLock auto_lock(lock_); |
| 171 if (last_render_ticks_.is_null() || playback_rate_ == 0.0) |
| 172 return base::TimeTicks(); |
171 | 173 |
172 base::AutoLock auto_lock(lock_); | 174 base::TimeDelta base_time; |
173 if (last_render_ticks_.is_null()) | 175 if (time < audio_clock_->front_timestamp()) { |
174 return audio_clock_->front_timestamp(); | 176 // See notes about |time| values less than |base_time| in TimeSource header. |
| 177 base_time = audio_clock_->front_timestamp(); |
| 178 } else if (time > audio_clock_->back_timestamp()) { |
| 179 base_time = audio_clock_->back_timestamp(); |
| 180 } else { |
| 181 // No need to estimate time, so return the actual wallclock time. |
| 182 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(time); |
| 183 } |
175 | 184 |
176 return audio_clock_->TimestampSinceWriting(base::TimeTicks::Now() - | 185 // In practice, most calls will be estimates given the relatively small window |
177 last_render_ticks_); | 186 // in which clients can get the actual time. |
| 187 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) + |
| 188 base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() / |
| 189 playback_rate_); |
178 } | 190 } |
179 | 191 |
180 TimeSource* AudioRendererImpl::GetTimeSource() { | 192 TimeSource* AudioRendererImpl::GetTimeSource() { |
181 return this; | 193 return this; |
182 } | 194 } |
183 | 195 |
184 void AudioRendererImpl::Flush(const base::Closure& callback) { | 196 void AudioRendererImpl::Flush(const base::Closure& callback) { |
185 DVLOG(1) << __FUNCTION__; | 197 DVLOG(1) << __FUNCTION__; |
186 DCHECK(task_runner_->BelongsToCurrentThread()); | 198 DCHECK(task_runner_->BelongsToCurrentThread()); |
187 | 199 |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 << buffering_state; | 750 << buffering_state; |
739 DCHECK_NE(buffering_state_, buffering_state); | 751 DCHECK_NE(buffering_state_, buffering_state); |
740 lock_.AssertAcquired(); | 752 lock_.AssertAcquired(); |
741 buffering_state_ = buffering_state; | 753 buffering_state_ = buffering_state; |
742 | 754 |
743 task_runner_->PostTask(FROM_HERE, | 755 task_runner_->PostTask(FROM_HERE, |
744 base::Bind(buffering_state_cb_, buffering_state_)); | 756 base::Bind(buffering_state_cb_, buffering_state_)); |
745 } | 757 } |
746 | 758 |
747 } // namespace media | 759 } // namespace media |
OLD | NEW |