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

Side by Side Diff: media/capture/content/smooth_event_sampler.cc

Issue 1865283003: Revert of Tab/Desktop Capture: Use requests instead of timer-based refreshing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_refresh_from_sinks
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/capture/content/smooth_event_sampler.h" 5 #include "media/capture/content/smooth_event_sampler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period) 15 SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period,
16 : token_bucket_(base::TimeDelta::Max()) { 16 int redundant_capture_goal)
17 : redundant_capture_goal_(redundant_capture_goal),
18 overdue_sample_count_(0),
19 token_bucket_(base::TimeDelta::Max()) {
17 SetMinCapturePeriod(min_capture_period); 20 SetMinCapturePeriod(min_capture_period);
18 } 21 }
19 22
20 void SmoothEventSampler::SetMinCapturePeriod(base::TimeDelta period) { 23 void SmoothEventSampler::SetMinCapturePeriod(base::TimeDelta period) {
21 DCHECK_GT(period, base::TimeDelta()); 24 DCHECK_GT(period, base::TimeDelta());
22 min_capture_period_ = period; 25 min_capture_period_ = period;
23 token_bucket_capacity_ = period + period / 2; 26 token_bucket_capacity_ = period + period / 2;
24 token_bucket_ = std::min(token_bucket_capacity_, token_bucket_); 27 token_bucket_ = std::min(token_bucket_capacity_, token_bucket_);
25 } 28 }
26 29
(...skipping 22 matching lines...) Expand all
49 return token_bucket_ >= min_capture_period_; 52 return token_bucket_ >= min_capture_period_;
50 } 53 }
51 54
52 void SmoothEventSampler::RecordSample() { 55 void SmoothEventSampler::RecordSample() {
53 token_bucket_ -= min_capture_period_; 56 token_bucket_ -= min_capture_period_;
54 if (token_bucket_ < base::TimeDelta()) 57 if (token_bucket_ < base::TimeDelta())
55 token_bucket_ = base::TimeDelta(); 58 token_bucket_ = base::TimeDelta();
56 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", 59 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec",
57 std::max<int64_t>(0, token_bucket_.InMicroseconds())); 60 std::max<int64_t>(0, token_bucket_.InMicroseconds()));
58 61
59 if (HasUnrecordedEvent()) 62 if (HasUnrecordedEvent()) {
60 last_sample_ = current_event_; 63 last_sample_ = current_event_;
64 overdue_sample_count_ = 0;
65 } else {
66 ++overdue_sample_count_;
67 }
68 }
69
70 bool SmoothEventSampler::IsOverdueForSamplingAt(
71 base::TimeTicks event_time) const {
72 DCHECK(!event_time.is_null());
73
74 if (!HasUnrecordedEvent() && overdue_sample_count_ >= redundant_capture_goal_)
75 return false; // Not dirty.
76
77 if (last_sample_.is_null())
78 return true;
79
80 // If we're dirty but not yet old, then we've recently gotten updates, so we
81 // won't request a sample just yet.
82 base::TimeDelta dirty_interval = event_time - last_sample_;
83 return dirty_interval >=
84 base::TimeDelta::FromMilliseconds(OVERDUE_DIRTY_THRESHOLD_MILLIS);
61 } 85 }
62 86
63 bool SmoothEventSampler::HasUnrecordedEvent() const { 87 bool SmoothEventSampler::HasUnrecordedEvent() const {
64 return !current_event_.is_null() && current_event_ != last_sample_; 88 return !current_event_.is_null() && current_event_ != last_sample_;
65 } 89 }
66 90
67 } // namespace media 91 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/content/smooth_event_sampler.h ('k') | media/capture/content/smooth_event_sampler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698