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

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

Issue 2237243002: CL for perf tryjob on linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 8
9 namespace media { 9 namespace media {
10 10
11 WallClockTimeSource::WallClockTimeSource() 11 WallClockTimeSource::WallClockTimeSource()
12 : tick_clock_(&default_tick_clock_), ticking_(false), playback_rate_(1.0) { 12 : tick_clock_(&default_tick_clock_), ticking_(false), playback_rate_(1.0) {
13 } 13 }
14 14
15 WallClockTimeSource::~WallClockTimeSource() { 15 WallClockTimeSource::~WallClockTimeSource() {
16 } 16 }
17 17
18 void WallClockTimeSource::StartTicking() { 18 void WallClockTimeSource::StartTicking() {
19 DVLOG(1) << __func__; 19 DVLOG(1) << __func__;
20 base::AutoLock auto_lock(lock_); 20 base::AutoLock auto_lock(lock_);
21 DCHECK(!ticking_); 21 DCHECK(!ticking_);
22 ticking_ = true; 22 ticking_ = true;
23 reference_time_ = tick_clock_->NowTicks(); 23 reference_time_ = tick_clock_->NowTicks();
24 } 24 }
25 25
26 void WallClockTimeSource::StopTicking() { 26 void WallClockTimeSource::StopTicking() {
27 DVLOG(1) << __func__; 27 DVLOG(1) << __func__;
28 base::AutoLock auto_lock(lock_); 28 base::AutoLock auto_lock(lock_);
29 DCHECK(ticking_); 29 DCHECK(ticking_);
30 base_timestamp_ = CurrentMediaTime_Locked(); 30 base_timestamp_ = CurrentMediaTime_Locked(&reference_time_);
31 ticking_ = false; 31 ticking_ = false;
32 reference_time_ = tick_clock_->NowTicks();
33 } 32 }
34 33
35 void WallClockTimeSource::SetPlaybackRate(double playback_rate) { 34 void WallClockTimeSource::SetPlaybackRate(double playback_rate) {
36 DVLOG(1) << __func__ << "(" << playback_rate << ")"; 35 DVLOG(1) << __func__ << "(" << playback_rate << ")";
37 base::AutoLock auto_lock(lock_); 36 base::AutoLock auto_lock(lock_);
38 // Estimate current media time using old rate to use as a new base time for 37 // Estimate current media time using old rate to use as a new base time for
39 // the new rate. 38 // the new rate.
40 if (ticking_) { 39 if (ticking_) {
41 base_timestamp_ = CurrentMediaTime_Locked(); 40 base_timestamp_ = CurrentMediaTime_Locked(&reference_time_);
42 reference_time_ = tick_clock_->NowTicks();
43 } 41 }
44 42
45 playback_rate_ = playback_rate; 43 playback_rate_ = playback_rate;
46 } 44 }
47 45
48 void WallClockTimeSource::SetMediaTime(base::TimeDelta time) { 46 void WallClockTimeSource::SetMediaTime(base::TimeDelta time) {
49 DVLOG(1) << __func__ << "(" << time.InMicroseconds() << ")"; 47 DVLOG(1) << __func__ << "(" << time.InMicroseconds() << ")";
50 base::AutoLock auto_lock(lock_); 48 base::AutoLock auto_lock(lock_);
51 CHECK(!ticking_); 49 CHECK(!ticking_);
52 base_timestamp_ = time; 50 base_timestamp_ = time;
53 } 51 }
54 52
55 base::TimeDelta WallClockTimeSource::CurrentMediaTime() { 53 base::TimeDelta WallClockTimeSource::CurrentMediaTime(
54 base::TimeTicks* reference) {
56 base::AutoLock auto_lock(lock_); 55 base::AutoLock auto_lock(lock_);
57 return CurrentMediaTime_Locked(); 56 return CurrentMediaTime_Locked(reference);
58 } 57 }
59 58
60 bool WallClockTimeSource::GetWallClockTimes( 59 bool WallClockTimeSource::GetWallClockTimes(
61 const std::vector<base::TimeDelta>& media_timestamps, 60 const std::vector<base::TimeDelta>& media_timestamps,
62 std::vector<base::TimeTicks>* wall_clock_times) { 61 std::vector<base::TimeTicks>* wall_clock_times) {
63 base::AutoLock auto_lock(lock_); 62 base::AutoLock auto_lock(lock_);
64 DCHECK(wall_clock_times->empty()); 63 DCHECK(wall_clock_times->empty());
65 64
66 if (media_timestamps.empty()) { 65 if (media_timestamps.empty()) {
67 wall_clock_times->push_back(reference_time_); 66 wall_clock_times->push_back(reference_time_);
68 } else { 67 } else {
69 // When playback is paused (rate is zero), assume a rate of 1.0. 68 // When playback is paused (rate is zero), assume a rate of 1.0.
70 const double playback_rate = playback_rate_ ? playback_rate_ : 1.0; 69 const double playback_rate = playback_rate_ ? playback_rate_ : 1.0;
71 70
72 wall_clock_times->reserve(media_timestamps.size()); 71 wall_clock_times->reserve(media_timestamps.size());
73 for (const auto& media_timestamp : media_timestamps) { 72 for (const auto& media_timestamp : media_timestamps) {
74 wall_clock_times->push_back(reference_time_ + 73 wall_clock_times->push_back(reference_time_ +
75 (media_timestamp - base_timestamp_) / 74 (media_timestamp - base_timestamp_) /
76 playback_rate); 75 playback_rate);
77 } 76 }
78 } 77 }
79 78
80 return playback_rate_ && ticking_; 79 return playback_rate_ && ticking_;
81 } 80 }
82 81
83 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked() { 82 base::TimeDelta WallClockTimeSource::CurrentMediaTime_Locked(
83 base::TimeTicks* reference) {
84 lock_.AssertAcquired(); 84 lock_.AssertAcquired();
85 if (!ticking_ || !playback_rate_)
86 return base_timestamp_;
87 85
88 base::TimeTicks now = tick_clock_->NowTicks(); 86 base::TimeTicks now_ticks;
89 return base_timestamp_ + 87 base::TimeDelta media_time = base_timestamp_;
90 base::TimeDelta::FromMicroseconds( 88 if (ticking_ && playback_rate_) {
91 (now - reference_time_).InMicroseconds() * playback_rate_); 89 now_ticks = tick_clock_->NowTicks();
90 media_time += base::TimeDelta::FromMicroseconds(
91 (now_ticks - reference_time_).InMicroseconds() * playback_rate_);
92 }
93
94 if (reference) {
95 *reference = now_ticks.is_null() ? tick_clock_->NowTicks() : now_ticks;
96 }
97
98 return media_time;
92 } 99 }
93 100
94 } // namespace media 101 } // 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