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 f7a8f6ef894d843ba9dd67dc46013ffbc822ce2d..5d826435576421913ab48ed8b313644420245721 100644 |
--- a/media/base/wall_clock_time_source.cc |
+++ b/media/base/wall_clock_time_source.cc |
@@ -19,23 +19,26 @@ WallClockTimeSource::~WallClockTimeSource() { |
} |
void WallClockTimeSource::StartTicking() { |
+ base::AutoLock auto_lock(lock_); |
DCHECK(!ticking_); |
ticking_ = true; |
reference_wall_ticks_ = tick_clock_->NowTicks(); |
} |
void WallClockTimeSource::StopTicking() { |
+ base::AutoLock auto_lock(lock_); |
DCHECK(ticking_); |
- base_time_ = CurrentMediaTime(); |
+ base_time_ = CurrentMediaTime_Locked(); |
ticking_ = false; |
reference_wall_ticks_ = tick_clock_->NowTicks(); |
} |
void WallClockTimeSource::SetPlaybackRate(float playback_rate) { |
+ base::AutoLock auto_lock(lock_); |
// Estimate current media time using old rate to use as a new base time for |
// the new rate. |
if (ticking_) { |
- base_time_ = CurrentMediaTime(); |
+ base_time_ = CurrentMediaTime_Locked(); |
reference_wall_ticks_ = tick_clock_->NowTicks(); |
} |
@@ -43,18 +46,14 @@ void WallClockTimeSource::SetPlaybackRate(float playback_rate) { |
} |
void WallClockTimeSource::SetMediaTime(base::TimeDelta time) { |
+ base::AutoLock auto_lock(lock_); |
CHECK(!ticking_); |
base_time_ = time; |
} |
base::TimeDelta WallClockTimeSource::CurrentMediaTime() { |
- if (!ticking_) |
- return base_time_; |
- |
- base::TimeTicks now = tick_clock_->NowTicks(); |
- return base_time_ + |
- base::TimeDelta::FromMicroseconds( |
- (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); |
+ base::AutoLock auto_lock(lock_); |
+ return CurrentMediaTime_Locked(); |
} |
base::TimeDelta WallClockTimeSource::CurrentMediaTimeForSyncingVideo() { |
@@ -66,4 +65,15 @@ void WallClockTimeSource::SetTickClockForTesting( |
tick_clock_.swap(tick_clock); |
} |
+base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { |
+ lock_.AssertAcquired(); |
+ if (!ticking_) |
+ return base_time_; |
+ |
+ base::TimeTicks now = tick_clock_->NowTicks(); |
+ return base_time_ + |
+ base::TimeDelta::FromMicroseconds( |
+ (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); |
+} |
+ |
} // namespace media |