Chromium Code Reviews| Index: media/renderers/audio_renderer_impl.cc |
| diff --git a/media/renderers/audio_renderer_impl.cc b/media/renderers/audio_renderer_impl.cc |
| index 74ef1d249526e694db66df69135315b062108fbc..000e5238f452a83df1734d942daec1863863f9eb 100644 |
| --- a/media/renderers/audio_renderer_impl.cc |
| +++ b/media/renderers/audio_renderer_impl.cc |
| @@ -166,15 +166,29 @@ base::TimeDelta AudioRendererImpl::CurrentMediaTime() { |
| return current_media_time; |
| } |
| -base::TimeDelta AudioRendererImpl::CurrentMediaTimeForSyncingVideo() { |
| - DVLOG(3) << __FUNCTION__; |
| - |
| +base::TimeTicks AudioRendererImpl::GetWallclockTimeForMediaTime( |
| + base::TimeDelta time) { |
| base::AutoLock auto_lock(lock_); |
| - if (last_render_ticks_.is_null()) |
| - return audio_clock_->front_timestamp(); |
| + if (last_render_ticks_.is_null() || playback_rate_ == 0.0) |
| + return base::TimeTicks(); |
| + |
| + base::TimeDelta base_time; |
| + if (time < audio_clock_->front_timestamp()) { |
| + // TODO(dalecurtis): This will estimate using the wrong playback rate, if it |
| + // 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
|
| + base_time = audio_clock_->front_timestamp(); |
| + } else if (time > audio_clock_->back_timestamp()) { |
| + base_time = audio_clock_->back_timestamp(); |
| + } else { |
| + // No need to estimate time, so return the actual wallclock time. |
| + return last_render_ticks_ + audio_clock_->TimeUntilPlayback(time); |
| + } |
| - return audio_clock_->TimestampSinceWriting(base::TimeTicks::Now() - |
| - last_render_ticks_); |
| + // In practice, most calls will be estimates given the relatively small window |
| + // in which clients can get the actual time. |
| + return last_render_ticks_ + audio_clock_->TimeUntilPlayback(base_time) + |
| + base::TimeDelta::FromMicroseconds((time - base_time).InMicroseconds() / |
| + playback_rate_); |
| } |
| TimeSource* AudioRendererImpl::GetTimeSource() { |