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 #include "media/base/buffers.h" | |
xhwang
2015/03/23 22:20:14
not needed?
BTW, media/base/buffers.h should be r
DaleCurtis
2015/03/25 00:31:45
Done.
| |
9 | 10 |
10 namespace media { | 11 namespace media { |
11 | 12 |
12 WallClockTimeSource::WallClockTimeSource() | 13 WallClockTimeSource::WallClockTimeSource() |
13 : tick_clock_(new base::DefaultTickClock()), | 14 : tick_clock_(new base::DefaultTickClock()), |
14 ticking_(false), | 15 ticking_(false), |
15 playback_rate_(1.0f) { | 16 playback_rate_(1.0f) { |
16 } | 17 } |
17 | 18 |
18 WallClockTimeSource::~WallClockTimeSource() { | 19 WallClockTimeSource::~WallClockTimeSource() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 base::AutoLock auto_lock(lock_); | 54 base::AutoLock auto_lock(lock_); |
54 CHECK(!ticking_); | 55 CHECK(!ticking_); |
55 base_time_ = time; | 56 base_time_ = time; |
56 } | 57 } |
57 | 58 |
58 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { | 59 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { |
59 base::AutoLock auto_lock(lock_); | 60 base::AutoLock auto_lock(lock_); |
60 return CurrentMediaTime_Locked(); | 61 return CurrentMediaTime_Locked(); |
61 } | 62 } |
62 | 63 |
63 base::TimeDelta WallClockTimeSource::CurrentMediaTimeForSyncingVideo() { | 64 base::TimeTicks WallClockTimeSource::GetWallclockTimeForMediaTime( |
64 return CurrentMediaTime(); | 65 base::TimeDelta time) { |
66 base::AutoLock auto_lock(lock_); | |
67 if (!ticking_ || playback_rate_ == 0.0 || time < base_time_) | |
xhwang
2015/03/23 22:20:14
Can we do DCHECK(time >= base_time_)?
DaleCurtis
2015/03/25 00:31:45
Actually this condition was incorrect, it needs to
xhwang
2015/03/25 04:10:50
Acknowledged.
| |
68 return base::TimeTicks(); | |
69 | |
70 return reference_wall_ticks_ + | |
71 base::TimeDelta::FromMicroseconds( | |
72 (time - base_time_).InMicroseconds() * playback_rate_); | |
65 } | 73 } |
66 | 74 |
67 void WallClockTimeSource::SetTickClockForTesting( | 75 void WallClockTimeSource::SetTickClockForTesting( |
68 scoped_ptr<base::TickClock> tick_clock) { | 76 scoped_ptr<base::TickClock> tick_clock) { |
69 tick_clock_.swap(tick_clock); | 77 tick_clock_.swap(tick_clock); |
70 } | 78 } |
71 | 79 |
72 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { | 80 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { |
73 lock_.AssertAcquired(); | 81 lock_.AssertAcquired(); |
74 if (!ticking_) | 82 if (!ticking_) |
75 return base_time_; | 83 return base_time_; |
76 | 84 |
77 base::TimeTicks now = tick_clock_->NowTicks(); | 85 base::TimeTicks now = tick_clock_->NowTicks(); |
78 return base_time_ + | 86 return base_time_ + |
79 base::TimeDelta::FromMicroseconds( | 87 base::TimeDelta::FromMicroseconds( |
80 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); | 88 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); |
81 } | 89 } |
82 | 90 |
83 } // namespace media | 91 } // namespace media |
OLD | NEW |