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

Side by Side Diff: media/base/wall_clock_time_source.cc

Issue 1136513004: Switch GetWallClockTime to using vectors for input and output. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments. Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | media/base/wall_clock_time_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_), ticking_(false), playback_rate_(1.0) {
14 ticking_(false),
15 playback_rate_(1.0) {
16 } 13 }
17 14
18 WallClockTimeSource::~WallClockTimeSource() { 15 WallClockTimeSource::~WallClockTimeSource() {
19 } 16 }
20 17
21 void WallClockTimeSource::StartTicking() { 18 void WallClockTimeSource::StartTicking() {
22 DVLOG(1) << __FUNCTION__; 19 DVLOG(1) << __FUNCTION__;
23 base::AutoLock auto_lock(lock_); 20 base::AutoLock auto_lock(lock_);
24 DCHECK(!ticking_); 21 DCHECK(!ticking_);
25 ticking_ = true; 22 ticking_ = true;
(...skipping 27 matching lines...) Expand all
53 base::AutoLock auto_lock(lock_); 50 base::AutoLock auto_lock(lock_);
54 CHECK(!ticking_); 51 CHECK(!ticking_);
55 base_time_ = time; 52 base_time_ = time;
56 } 53 }
57 54
58 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { 55 base::TimeDelta WallClockTimeSource::CurrentMediaTime() {
59 base::AutoLock auto_lock(lock_); 56 base::AutoLock auto_lock(lock_);
60 return CurrentMediaTime_Locked(); 57 return CurrentMediaTime_Locked();
61 } 58 }
62 59
63 base::TimeTicks WallClockTimeSource::GetWallClockTime(base::TimeDelta time) { 60 bool WallClockTimeSource::GetWallClockTimes(
61 const std::vector<base::TimeDelta>& media_timestamps,
62 std::vector<base::TimeTicks>* wall_clock_times) {
64 base::AutoLock auto_lock(lock_); 63 base::AutoLock auto_lock(lock_);
65 if (!ticking_ || playback_rate_ == 0.0) 64 if (!ticking_ || !playback_rate_)
66 return base::TimeTicks(); 65 return false;
67 66
68 // See notes about |time| values less than |base_time_| in TimeSource header. 67 DCHECK(wall_clock_times->empty());
69 return reference_wall_ticks_ + 68 wall_clock_times->reserve(media_timestamps.size());
70 base::TimeDelta::FromMicroseconds( 69 for (const auto& media_timestamp : media_timestamps) {
71 (time - base_time_).InMicroseconds() / playback_rate_); 70 wall_clock_times->push_back(
72 } 71 reference_wall_ticks_ +
73 72 base::TimeDelta::FromMicroseconds(
74 void WallClockTimeSource::SetTickClockForTesting( 73 (media_timestamp - base_time_).InMicroseconds() / playback_rate_));
75 scoped_ptr<base::TickClock> tick_clock) { 74 }
76 tick_clock_.swap(tick_clock); 75 return true;
77 } 76 }
78 77
79 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { 78 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() {
80 lock_.AssertAcquired(); 79 lock_.AssertAcquired();
81 if (!ticking_ || playback_rate_ == 0.0) 80 if (!ticking_ || !playback_rate_)
82 return base_time_; 81 return base_time_;
83 82
84 base::TimeTicks now = tick_clock_->NowTicks(); 83 base::TimeTicks now = tick_clock_->NowTicks();
85 return base_time_ + 84 return base_time_ +
86 base::TimeDelta::FromMicroseconds( 85 base::TimeDelta::FromMicroseconds(
87 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); 86 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_);
88 } 87 }
89 88
90 } // namespace media 89 } // namespace media
OLDNEW
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | media/base/wall_clock_time_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698