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" | |
9 | 8 |
10 namespace media { | 9 namespace media { |
11 | 10 |
12 WallClockTimeSource::WallClockTimeSource() | 11 WallClockTimeSource::WallClockTimeSource() |
13 : tick_clock_(new base::DefaultTickClock()), | 12 : tick_clock_(&default_tick_clock_), |
14 ticking_(false), | 13 ticking_(false), |
15 playback_rate_(1.0) { | 14 playback_rate_(1.0) { |
16 } | 15 } |
17 | 16 |
18 WallClockTimeSource::~WallClockTimeSource() { | 17 WallClockTimeSource::~WallClockTimeSource() { |
19 } | 18 } |
20 | 19 |
21 void WallClockTimeSource::StartTicking() { | 20 void WallClockTimeSource::StartTicking() { |
22 DVLOG(1) << __FUNCTION__; | 21 DVLOG(1) << __FUNCTION__; |
23 base::AutoLock auto_lock(lock_); | 22 base::AutoLock auto_lock(lock_); |
(...skipping 29 matching lines...) Expand all Loading... |
53 base::AutoLock auto_lock(lock_); | 52 base::AutoLock auto_lock(lock_); |
54 CHECK(!ticking_); | 53 CHECK(!ticking_); |
55 base_time_ = time; | 54 base_time_ = time; |
56 } | 55 } |
57 | 56 |
58 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { | 57 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { |
59 base::AutoLock auto_lock(lock_); | 58 base::AutoLock auto_lock(lock_); |
60 return CurrentMediaTime_Locked(); | 59 return CurrentMediaTime_Locked(); |
61 } | 60 } |
62 | 61 |
63 base::TimeTicks WallClockTimeSource::GetWallClockTime(base::TimeDelta time) { | 62 bool WallClockTimeSource::GetWallClockTime( |
| 63 const std::vector<base::TimeDelta>& media_timestamps, |
| 64 std::vector<base::TimeTicks>* wall_clock_times) { |
64 base::AutoLock auto_lock(lock_); | 65 base::AutoLock auto_lock(lock_); |
65 if (!ticking_ || playback_rate_ == 0.0) | 66 if (!ticking_ || !playback_rate_) |
66 return base::TimeTicks(); | 67 return false; |
67 | 68 |
68 // See notes about |time| values less than |base_time_| in TimeSource header. | 69 DCHECK(wall_clock_times->empty()); |
69 return reference_wall_ticks_ + | 70 wall_clock_times->reserve(media_timestamps.size()); |
70 base::TimeDelta::FromMicroseconds( | 71 for (const auto& media_timestamp : media_timestamps) { |
71 (time - base_time_).InMicroseconds() / playback_rate_); | 72 wall_clock_times->push_back( |
72 } | 73 reference_wall_ticks_ + |
73 | 74 base::TimeDelta::FromMicroseconds( |
74 void WallClockTimeSource::SetTickClockForTesting( | 75 (media_timestamp - base_time_).InMicroseconds() / playback_rate_)); |
75 scoped_ptr<base::TickClock> tick_clock) { | 76 } |
76 tick_clock_.swap(tick_clock); | 77 return true; |
77 } | 78 } |
78 | 79 |
79 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { | 80 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { |
80 lock_.AssertAcquired(); | 81 lock_.AssertAcquired(); |
81 if (!ticking_ || playback_rate_ == 0.0) | 82 if (!ticking_ || !playback_rate_) |
82 return base_time_; | 83 return base_time_; |
83 | 84 |
84 base::TimeTicks now = tick_clock_->NowTicks(); | 85 base::TimeTicks now = tick_clock_->NowTicks(); |
85 return base_time_ + | 86 return base_time_ + |
86 base::TimeDelta::FromMicroseconds( | 87 base::TimeDelta::FromMicroseconds( |
87 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); | 88 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); |
88 } | 89 } |
89 | 90 |
90 } // namespace media | 91 } // namespace media |
OLD | NEW |