Chromium Code Reviews| 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::GetWallclockTimeForMediaTime( |
| 170 DVLOG(3) << __FUNCTION__; | 170 base::TimeDelta time) { |
| 171 base::AutoLock auto_lock(lock_); | |
| 172 if (last_render_ticks_.is_null() || playback_rate_ == 0.0) | |
| 173 return base::TimeTicks(); | |
| 171 | 174 |
| 172 base::AutoLock auto_lock(lock_); | 175 base::TimeDelta base_time; |
| 173 if (last_render_ticks_.is_null()) | 176 if (time < audio_clock_->front_timestamp()) { |
| 174 return audio_clock_->front_timestamp(); | 177 // TODO(dalecurtis): This will estimate using the wrong playback rate, if it |
| 178 // has changed recently... Is this actually a problem? | |
|
xhwang
2015/03/23 22:20:14
scherkus showed me how time could go backwards in
DaleCurtis
2015/03/25 00:31:45
If someone is rapidly oscillating the playback rat
xhwang
2015/03/25 04:10:50
Just OCC, when time goes backwards, could we rende
| |
| 179 base_time = audio_clock_->front_timestamp(); | |
| 180 } else if (time > audio_clock_->back_timestamp()) { | |
| 181 base_time = audio_clock_->back_timestamp(); | |
| 182 } else { | |
| 183 // No need to estimate time, so return the actual wallclock time. | |
| 184 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(time); | |
| 185 } | |
| 175 | 186 |
| 176 return audio_clock_->TimestampSinceWriting(base::TimeTicks::Now() - | 187 // In practice, most calls will be estimates given the relatively small window |
| 177 last_render_ticks_); | 188 // in which clients can get the actual time. |
| 189 return last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) + | |
| 190 base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() / | |
| 191 playback_rate_); | |
| 178 } | 192 } |
| 179 | 193 |
| 180 TimeSource* AudioRendererImpl::GetTimeSource() { | 194 TimeSource* AudioRendererImpl::GetTimeSource() { |
| 181 return this; | 195 return this; |
| 182 } | 196 } |
| 183 | 197 |
| 184 void AudioRendererImpl::Flush(const base::Closure& callback) { | 198 void AudioRendererImpl::Flush(const base::Closure& callback) { |
| 185 DVLOG(1) << __FUNCTION__; | 199 DVLOG(1) << __FUNCTION__; |
| 186 DCHECK(task_runner_->BelongsToCurrentThread()); | 200 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 187 | 201 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 << buffering_state; | 753 << buffering_state; |
| 740 DCHECK_NE(buffering_state_, buffering_state); | 754 DCHECK_NE(buffering_state_, buffering_state); |
| 741 lock_.AssertAcquired(); | 755 lock_.AssertAcquired(); |
| 742 buffering_state_ = buffering_state; | 756 buffering_state_ = buffering_state; |
| 743 | 757 |
| 744 task_runner_->PostTask(FROM_HERE, | 758 task_runner_->PostTask(FROM_HERE, |
| 745 base::Bind(buffering_state_cb_, buffering_state_)); | 759 base::Bind(buffering_state_cb_, buffering_state_)); |
| 746 } | 760 } |
| 747 | 761 |
| 748 } // namespace media | 762 } // namespace media |
| OLD | NEW |