| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/wall_clock_time_source.h" | 5 #include "media/base/wall_clock_time_source.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/time/default_tick_clock.h" | 8 #include "base/time/default_tick_clock.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 base::AutoLock auto_lock(lock_); | 53 base::AutoLock auto_lock(lock_); |
| 54 CHECK(!ticking_); | 54 CHECK(!ticking_); |
| 55 base_time_ = time; | 55 base_time_ = time; |
| 56 } | 56 } |
| 57 | 57 |
| 58 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { | 58 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { |
| 59 base::AutoLock auto_lock(lock_); | 59 base::AutoLock auto_lock(lock_); |
| 60 return CurrentMediaTime_Locked(); | 60 return CurrentMediaTime_Locked(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 base::TimeTicks WallClockTimeSource::GetWallClockTime(base::TimeDelta time) { | 63 base::TimeTicks WallClockTimeSource::GetWallClockTime(base::TimeDelta time, |
| 64 base::AutoLock auto_lock(lock_); | 64 int request_flags) { |
| 65 if (!ticking_ || playback_rate_ == 0.0) | 65 if (request_flags & SUSPEND_TIME) |
| 66 lock_.Acquire(); |
| 67 |
| 68 lock_.AssertAcquired(); |
| 69 if (!ticking_ || playback_rate_ == 0.0) { |
| 70 lock_.Release(); |
| 66 return base::TimeTicks(); | 71 return base::TimeTicks(); |
| 72 } |
| 67 | 73 |
| 68 // See notes about |time| values less than |base_time_| in TimeSource header. | 74 // See notes about |time| values less than |base_time_| in TimeSource header. |
| 69 return reference_wall_ticks_ + | 75 const base::TimeTicks result = |
| 70 base::TimeDelta::FromMicroseconds( | 76 reference_wall_ticks_ + |
| 71 (time - base_time_).InMicroseconds() / playback_rate_); | 77 base::TimeDelta::FromMicroseconds((time - base_time_).InMicroseconds() / |
| 78 playback_rate_); |
| 79 |
| 80 if (request_flags & RESUME_TIME) |
| 81 lock_.Release(); |
| 82 |
| 83 return result; |
| 72 } | 84 } |
| 73 | 85 |
| 74 void WallClockTimeSource::SetTickClockForTesting( | 86 void WallClockTimeSource::SetTickClockForTesting( |
| 75 scoped_ptr<base::TickClock> tick_clock) { | 87 scoped_ptr<base::TickClock> tick_clock) { |
| 76 tick_clock_.swap(tick_clock); | 88 tick_clock_.swap(tick_clock); |
| 77 } | 89 } |
| 78 | 90 |
| 79 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { | 91 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { |
| 80 lock_.AssertAcquired(); | 92 lock_.AssertAcquired(); |
| 81 if (!ticking_ || playback_rate_ == 0.0) | 93 if (!ticking_ || playback_rate_ == 0.0) |
| 82 return base_time_; | 94 return base_time_; |
| 83 | 95 |
| 84 base::TimeTicks now = tick_clock_->NowTicks(); | 96 base::TimeTicks now = tick_clock_->NowTicks(); |
| 85 return base_time_ + | 97 return base_time_ + |
| 86 base::TimeDelta::FromMicroseconds( | 98 base::TimeDelta::FromMicroseconds( |
| 87 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); | 99 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); |
| 88 } | 100 } |
| 89 | 101 |
| 90 } // namespace media | 102 } // namespace media |
| OLD | NEW |