| Index: media/base/wall_clock_time_source.cc
|
| diff --git a/media/base/wall_clock_time_source.cc b/media/base/wall_clock_time_source.cc
|
| index 16a1a30fbbe5be784b9963965290d74e2aceadba..08429fdf8fc7db9257bbf56e6652429c95ffa57e 100644
|
| --- a/media/base/wall_clock_time_source.cc
|
| +++ b/media/base/wall_clock_time_source.cc
|
| @@ -27,9 +27,8 @@ void WallClockTimeSource::StopTicking() {
|
| DVLOG(1) << __func__;
|
| base::AutoLock auto_lock(lock_);
|
| DCHECK(ticking_);
|
| - base_timestamp_ = CurrentMediaTime_Locked();
|
| + base_timestamp_ = CurrentMediaTime_Locked(&reference_time_);
|
| ticking_ = false;
|
| - reference_time_ = tick_clock_->NowTicks();
|
| }
|
|
|
| void WallClockTimeSource::SetPlaybackRate(double playback_rate) {
|
| @@ -38,8 +37,7 @@ void WallClockTimeSource::SetPlaybackRate(double playback_rate) {
|
| // Estimate current media time using old rate to use as a new base time for
|
| // the new rate.
|
| if (ticking_) {
|
| - base_timestamp_ = CurrentMediaTime_Locked();
|
| - reference_time_ = tick_clock_->NowTicks();
|
| + base_timestamp_ = CurrentMediaTime_Locked(&reference_time_);
|
| }
|
|
|
| playback_rate_ = playback_rate;
|
| @@ -52,9 +50,10 @@ void WallClockTimeSource::SetMediaTime(base::TimeDelta time) {
|
| base_timestamp_ = time;
|
| }
|
|
|
| -base::TimeDelta WallClockTimeSource::CurrentMediaTime() {
|
| +base::TimeDelta WallClockTimeSource::CurrentMediaTime(
|
| + base::TimeTicks* reference) {
|
| base::AutoLock auto_lock(lock_);
|
| - return CurrentMediaTime_Locked();
|
| + return CurrentMediaTime_Locked(reference);
|
| }
|
|
|
| bool WallClockTimeSource::GetWallClockTimes(
|
| @@ -80,15 +79,23 @@ bool WallClockTimeSource::GetWallClockTimes(
|
| return playback_rate_ && ticking_;
|
| }
|
|
|
| -base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() {
|
| +base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked(
|
| + base::TimeTicks* reference) {
|
| lock_.AssertAcquired();
|
| - if (!ticking_ || !playback_rate_)
|
| - return base_timestamp_;
|
|
|
| - base::TimeTicks now = tick_clock_->NowTicks();
|
| - return base_timestamp_ +
|
| - base::TimeDelta::FromMicroseconds(
|
| - (now - reference_time_).InMicroseconds() * playback_rate_);
|
| + base::TimeTicks now_ticks;
|
| + base::TimeDelta media_time = base_timestamp_;
|
| + if (ticking_ && playback_rate_) {
|
| + now_ticks = tick_clock_->NowTicks();
|
| + media_time += base::TimeDelta::FromMicroseconds(
|
| + (now_ticks - reference_time_).InMicroseconds() * playback_rate_);
|
| + }
|
| +
|
| + if (reference) {
|
| + *reference = now_ticks.is_null() ? tick_clock_->NowTicks() : now_ticks;
|
| + }
|
| +
|
| + return media_time;
|
| }
|
|
|
| } // namespace media
|
|
|