| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/media/capture/video_capture_oracle.h" | 5 #include "content/browser/media/capture/video_capture_oracle.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 double FractionFromExpectedFrameRate(base::TimeDelta delta, int frame_rate) { | 57 double FractionFromExpectedFrameRate(base::TimeDelta delta, int frame_rate) { |
| 58 DCHECK_GT(frame_rate, 0); | 58 DCHECK_GT(frame_rate, 0); |
| 59 const base::TimeDelta expected_delta = | 59 const base::TimeDelta expected_delta = |
| 60 base::TimeDelta::FromSeconds(1) / frame_rate; | 60 base::TimeDelta::FromSeconds(1) / frame_rate; |
| 61 return (delta - expected_delta).InMillisecondsF() / | 61 return (delta - expected_delta).InMillisecondsF() / |
| 62 expected_delta.InMillisecondsF(); | 62 expected_delta.InMillisecondsF(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // anonymous namespace | 65 } // anonymous namespace |
| 66 | 66 |
| 67 VideoCaptureOracle::VideoCaptureOracle(base::TimeDelta min_capture_period, | 67 VideoCaptureOracle::VideoCaptureOracle(base::TimeDelta min_capture_period) |
| 68 bool events_are_reliable) | |
| 69 : frame_number_(0), | 68 : frame_number_(0), |
| 70 last_delivered_frame_number_(-1), | 69 last_delivered_frame_number_(-1), |
| 71 smoothing_sampler_(min_capture_period, | 70 smoothing_sampler_(min_capture_period, |
| 72 events_are_reliable, | |
| 73 kNumRedundantCapturesOfStaticContent), | 71 kNumRedundantCapturesOfStaticContent), |
| 74 content_sampler_(min_capture_period) { | 72 content_sampler_(min_capture_period) { |
| 75 } | 73 } |
| 76 | 74 |
| 77 VideoCaptureOracle::~VideoCaptureOracle() {} | 75 VideoCaptureOracle::~VideoCaptureOracle() {} |
| 78 | 76 |
| 79 bool VideoCaptureOracle::ObserveEventAndDecideCapture( | 77 bool VideoCaptureOracle::ObserveEventAndDecideCapture( |
| 80 Event event, | 78 Event event, |
| 81 const gfx::Rect& damage_rect, | 79 const gfx::Rect& damage_rect, |
| 82 base::TimeTicks event_time) { | 80 base::TimeTicks event_time) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DCHECK_LT(frame_number_ - frame_number, kMaxFrameTimestamps); | 165 DCHECK_LT(frame_number_ - frame_number, kMaxFrameTimestamps); |
| 168 return frame_timestamps_[frame_number % kMaxFrameTimestamps]; | 166 return frame_timestamps_[frame_number % kMaxFrameTimestamps]; |
| 169 } | 167 } |
| 170 | 168 |
| 171 void VideoCaptureOracle::SetFrameTimestamp(int frame_number, | 169 void VideoCaptureOracle::SetFrameTimestamp(int frame_number, |
| 172 base::TimeTicks timestamp) { | 170 base::TimeTicks timestamp) { |
| 173 frame_timestamps_[frame_number % kMaxFrameTimestamps] = timestamp; | 171 frame_timestamps_[frame_number % kMaxFrameTimestamps] = timestamp; |
| 174 } | 172 } |
| 175 | 173 |
| 176 SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period, | 174 SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period, |
| 177 bool events_are_reliable, | |
| 178 int redundant_capture_goal) | 175 int redundant_capture_goal) |
| 179 : events_are_reliable_(events_are_reliable), | 176 : min_capture_period_(min_capture_period), |
| 180 min_capture_period_(min_capture_period), | |
| 181 redundant_capture_goal_(redundant_capture_goal), | 177 redundant_capture_goal_(redundant_capture_goal), |
| 182 token_bucket_capacity_(min_capture_period + min_capture_period / 2), | 178 token_bucket_capacity_(min_capture_period + min_capture_period / 2), |
| 183 overdue_sample_count_(0), | 179 overdue_sample_count_(0), |
| 184 token_bucket_(token_bucket_capacity_) { | 180 token_bucket_(token_bucket_capacity_) { |
| 185 DCHECK_GT(min_capture_period_.InMicroseconds(), 0); | 181 DCHECK_GT(min_capture_period_.InMicroseconds(), 0); |
| 186 } | 182 } |
| 187 | 183 |
| 188 void SmoothEventSampler::ConsiderPresentationEvent(base::TimeTicks event_time) { | 184 void SmoothEventSampler::ConsiderPresentationEvent(base::TimeTicks event_time) { |
| 189 DCHECK(!event_time.is_null()); | 185 DCHECK(!event_time.is_null()); |
| 190 | 186 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 overdue_sample_count_ = 0; | 220 overdue_sample_count_ = 0; |
| 225 } else { | 221 } else { |
| 226 ++overdue_sample_count_; | 222 ++overdue_sample_count_; |
| 227 } | 223 } |
| 228 } | 224 } |
| 229 | 225 |
| 230 bool SmoothEventSampler::IsOverdueForSamplingAt(base::TimeTicks event_time) | 226 bool SmoothEventSampler::IsOverdueForSamplingAt(base::TimeTicks event_time) |
| 231 const { | 227 const { |
| 232 DCHECK(!event_time.is_null()); | 228 DCHECK(!event_time.is_null()); |
| 233 | 229 |
| 234 // If we don't get events on compositor updates on this platform, then we | 230 if (!HasUnrecordedEvent() && overdue_sample_count_ >= redundant_capture_goal_) |
| 235 // don't reliably know whether we're dirty. | 231 return false; // Not dirty. |
| 236 if (events_are_reliable_) { | |
| 237 if (!HasUnrecordedEvent() && | |
| 238 overdue_sample_count_ >= redundant_capture_goal_) { | |
| 239 return false; // Not dirty. | |
| 240 } | |
| 241 } | |
| 242 | 232 |
| 243 if (last_sample_.is_null()) | 233 if (last_sample_.is_null()) |
| 244 return true; | 234 return true; |
| 245 | 235 |
| 246 // If we're dirty but not yet old, then we've recently gotten updates, so we | 236 // If we're dirty but not yet old, then we've recently gotten updates, so we |
| 247 // won't request a sample just yet. | 237 // won't request a sample just yet. |
| 248 base::TimeDelta dirty_interval = event_time - last_sample_; | 238 base::TimeDelta dirty_interval = event_time - last_sample_; |
| 249 return dirty_interval >= | 239 return dirty_interval >= |
| 250 base::TimeDelta::FromMilliseconds(kNonAnimatingThresholdMillis); | 240 base::TimeDelta::FromMilliseconds(kNonAnimatingThresholdMillis); |
| 251 } | 241 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 if (borrowed_time_ >= min_capture_period_) { | 418 if (borrowed_time_ >= min_capture_period_) { |
| 429 borrowed_time_ -= min_capture_period_; | 419 borrowed_time_ -= min_capture_period_; |
| 430 frame_timestamp_ = base::TimeTicks(); | 420 frame_timestamp_ = base::TimeTicks(); |
| 431 } else { | 421 } else { |
| 432 sequence_offset_ += advancement; | 422 sequence_offset_ += advancement; |
| 433 frame_timestamp_ = timebase + sequence_offset_; | 423 frame_timestamp_ = timebase + sequence_offset_; |
| 434 } | 424 } |
| 435 } | 425 } |
| 436 | 426 |
| 437 } // namespace content | 427 } // namespace content |
| OLD | NEW |