Index: media/capture/content/smooth_event_sampler.cc |
diff --git a/media/capture/content/smooth_event_sampler.cc b/media/capture/content/smooth_event_sampler.cc |
index 7f7297f2038192655b24528e4ae29db1778d1c53..9ac263dd13fc2a8c91c30fb8a3dc22e2de1fb858 100644 |
--- a/media/capture/content/smooth_event_sampler.cc |
+++ b/media/capture/content/smooth_event_sampler.cc |
@@ -12,8 +12,11 @@ |
namespace media { |
-SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period) |
- : token_bucket_(base::TimeDelta::Max()) { |
+SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period, |
+ int redundant_capture_goal) |
+ : redundant_capture_goal_(redundant_capture_goal), |
+ overdue_sample_count_(0), |
+ token_bucket_(base::TimeDelta::Max()) { |
SetMinCapturePeriod(min_capture_period); |
} |
@@ -56,8 +59,29 @@ |
TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", |
std::max<int64_t>(0, token_bucket_.InMicroseconds())); |
- if (HasUnrecordedEvent()) |
+ if (HasUnrecordedEvent()) { |
last_sample_ = current_event_; |
+ overdue_sample_count_ = 0; |
+ } else { |
+ ++overdue_sample_count_; |
+ } |
+} |
+ |
+bool SmoothEventSampler::IsOverdueForSamplingAt( |
+ base::TimeTicks event_time) const { |
+ DCHECK(!event_time.is_null()); |
+ |
+ if (!HasUnrecordedEvent() && overdue_sample_count_ >= redundant_capture_goal_) |
+ return false; // Not dirty. |
+ |
+ if (last_sample_.is_null()) |
+ return true; |
+ |
+ // If we're dirty but not yet old, then we've recently gotten updates, so we |
+ // won't request a sample just yet. |
+ base::TimeDelta dirty_interval = event_time - last_sample_; |
+ return dirty_interval >= |
+ base::TimeDelta::FromMilliseconds(OVERDUE_DIRTY_THRESHOLD_MILLIS); |
} |
bool SmoothEventSampler::HasUnrecordedEvent() const { |