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

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

Issue 1864813002: 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: Fix WCVCD unit tests that test resize policies. 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 int redundant_capture_goal) 16 : token_bucket_(base::TimeDelta::Max()) {
17 : redundant_capture_goal_(redundant_capture_goal),
18 overdue_sample_count_(0),
19 token_bucket_(base::TimeDelta::Max()) {
20 SetMinCapturePeriod(min_capture_period); 17 SetMinCapturePeriod(min_capture_period);
21 } 18 }
22 19
23 void SmoothEventSampler::SetMinCapturePeriod(base::TimeDelta period) { 20 void SmoothEventSampler::SetMinCapturePeriod(base::TimeDelta period) {
24 DCHECK_GT(period, base::TimeDelta()); 21 DCHECK_GT(period, base::TimeDelta());
25 min_capture_period_ = period; 22 min_capture_period_ = period;
26 token_bucket_capacity_ = period + period / 2; 23 token_bucket_capacity_ = period + period / 2;
27 token_bucket_ = std::min(token_bucket_capacity_, token_bucket_); 24 token_bucket_ = std::min(token_bucket_capacity_, token_bucket_);
28 } 25 }
29 26
(...skipping 22 matching lines...) Expand all
52 return token_bucket_ >= min_capture_period_; 49 return token_bucket_ >= min_capture_period_;
53 } 50 }
54 51
55 void SmoothEventSampler::RecordSample() { 52 void SmoothEventSampler::RecordSample() {
56 token_bucket_ -= min_capture_period_; 53 token_bucket_ -= min_capture_period_;
57 if (token_bucket_ < base::TimeDelta()) 54 if (token_bucket_ < base::TimeDelta())
58 token_bucket_ = base::TimeDelta(); 55 token_bucket_ = base::TimeDelta();
59 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", 56 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec",
60 std::max<int64_t>(0, token_bucket_.InMicroseconds())); 57 std::max<int64_t>(0, token_bucket_.InMicroseconds()));
61 58
62 if (HasUnrecordedEvent()) { 59 if (HasUnrecordedEvent())
63 last_sample_ = current_event_; 60 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);
85 } 61 }
86 62
87 bool SmoothEventSampler::HasUnrecordedEvent() const { 63 bool SmoothEventSampler::HasUnrecordedEvent() const {
88 return !current_event_.is_null() && current_event_ != last_sample_; 64 return !current_event_.is_null() && current_event_ != last_sample_;
89 } 65 }
90 66
91 } // namespace media 67 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698