Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(712)

Unified Diff: media/base/wall_clock_time_source.cc

Issue 562673003: Make media::WallClockTimeSource thread safe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698