| OLD | NEW |
| 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/video_capture_oracle.h" | 5 #include "media/capture/content/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/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 } // anonymous namespace | 95 } // anonymous namespace |
| 96 | 96 |
| 97 VideoCaptureOracle::VideoCaptureOracle( | 97 VideoCaptureOracle::VideoCaptureOracle( |
| 98 base::TimeDelta min_capture_period, | 98 base::TimeDelta min_capture_period, |
| 99 const gfx::Size& max_frame_size, | 99 const gfx::Size& max_frame_size, |
| 100 media::ResolutionChangePolicy resolution_change_policy, | 100 media::ResolutionChangePolicy resolution_change_policy, |
| 101 bool enable_auto_throttling) | 101 bool enable_auto_throttling) |
| 102 : auto_throttling_enabled_(enable_auto_throttling), | 102 : auto_throttling_enabled_(enable_auto_throttling), |
| 103 next_frame_number_(0), | 103 next_frame_number_(0), |
| 104 source_is_dirty_(true), |
| 104 last_successfully_delivered_frame_number_(-1), | 105 last_successfully_delivered_frame_number_(-1), |
| 105 num_frames_pending_(0), | 106 num_frames_pending_(0), |
| 106 smoothing_sampler_(min_capture_period), | 107 smoothing_sampler_(min_capture_period), |
| 107 content_sampler_(min_capture_period), | 108 content_sampler_(min_capture_period), |
| 108 resolution_chooser_(max_frame_size, resolution_change_policy), | 109 resolution_chooser_(max_frame_size, resolution_change_policy), |
| 109 buffer_pool_utilization_(base::TimeDelta::FromMicroseconds( | 110 buffer_pool_utilization_(base::TimeDelta::FromMicroseconds( |
| 110 kBufferUtilizationEvaluationMicros)), | 111 kBufferUtilizationEvaluationMicros)), |
| 111 estimated_capable_area_(base::TimeDelta::FromMicroseconds( | 112 estimated_capable_area_(base::TimeDelta::FromMicroseconds( |
| 112 kConsumerCapabilityEvaluationMicros)) { | 113 kConsumerCapabilityEvaluationMicros)) { |
| 113 VLOG(1) << "Auto-throttling is " | 114 VLOG(1) << "Auto-throttling is " |
| (...skipping 17 matching lines...) Expand all Loading... |
| 131 base::TimeTicks event_time) { | 132 base::TimeTicks event_time) { |
| 132 DCHECK_GE(event, 0); | 133 DCHECK_GE(event, 0); |
| 133 DCHECK_LT(event, kNumEvents); | 134 DCHECK_LT(event, kNumEvents); |
| 134 if (event_time < last_event_time_[event]) { | 135 if (event_time < last_event_time_[event]) { |
| 135 LOG(WARNING) << "Event time is not monotonically non-decreasing. " | 136 LOG(WARNING) << "Event time is not monotonically non-decreasing. " |
| 136 << "Deciding not to capture this frame."; | 137 << "Deciding not to capture this frame."; |
| 137 return false; | 138 return false; |
| 138 } | 139 } |
| 139 last_event_time_[event] = event_time; | 140 last_event_time_[event] = event_time; |
| 140 | 141 |
| 142 // If the event indicates a change to the source content, set a flag that will |
| 143 // prevent passive refresh requests until a capture is made. |
| 144 if (event != kActiveRefreshRequest && event != kPassiveRefreshRequest) |
| 145 source_is_dirty_ = true; |
| 146 |
| 141 bool should_sample = false; | 147 bool should_sample = false; |
| 142 duration_of_next_frame_ = base::TimeDelta(); | 148 duration_of_next_frame_ = base::TimeDelta(); |
| 143 switch (event) { | 149 switch (event) { |
| 144 case kCompositorUpdate: { | 150 case kCompositorUpdate: { |
| 145 smoothing_sampler_.ConsiderPresentationEvent(event_time); | 151 smoothing_sampler_.ConsiderPresentationEvent(event_time); |
| 146 const bool had_proposal = content_sampler_.HasProposal(); | 152 const bool had_proposal = content_sampler_.HasProposal(); |
| 147 content_sampler_.ConsiderPresentationEvent(damage_rect, event_time); | 153 content_sampler_.ConsiderPresentationEvent(damage_rect, event_time); |
| 148 if (content_sampler_.HasProposal()) { | 154 if (content_sampler_.HasProposal()) { |
| 149 VLOG_IF(1, !had_proposal) << "Content sampler now detects animation."; | 155 VLOG_IF(1, !had_proposal) << "Content sampler now detects animation."; |
| 150 should_sample = content_sampler_.ShouldSample(); | 156 should_sample = content_sampler_.ShouldSample(); |
| 151 if (should_sample) { | 157 if (should_sample) { |
| 152 event_time = content_sampler_.frame_timestamp(); | 158 event_time = content_sampler_.frame_timestamp(); |
| 153 duration_of_next_frame_ = content_sampler_.sampling_period(); | 159 duration_of_next_frame_ = content_sampler_.sampling_period(); |
| 154 } | 160 } |
| 155 last_time_animation_was_detected_ = event_time; | 161 last_time_animation_was_detected_ = event_time; |
| 156 } else { | 162 } else { |
| 157 VLOG_IF(1, had_proposal) << "Content sampler detects animation ended."; | 163 VLOG_IF(1, had_proposal) << "Content sampler detects animation ended."; |
| 158 should_sample = smoothing_sampler_.ShouldSample(); | 164 should_sample = smoothing_sampler_.ShouldSample(); |
| 159 } | 165 } |
| 160 break; | 166 break; |
| 161 } | 167 } |
| 162 | 168 |
| 169 case kPassiveRefreshRequest: |
| 170 if (source_is_dirty_) |
| 171 break; |
| 172 // Intentional flow-through to next case here! |
| 163 case kActiveRefreshRequest: | 173 case kActiveRefreshRequest: |
| 164 case kPassiveRefreshRequest: | |
| 165 case kMouseCursorUpdate: | 174 case kMouseCursorUpdate: |
| 166 // Only allow non-compositor samplings when content has not recently been | 175 // Only allow non-compositor samplings when content has not recently been |
| 167 // animating, and only if there are no samplings currently in progress. | 176 // animating, and only if there are no samplings currently in progress. |
| 168 if (num_frames_pending_ == 0) { | 177 if (num_frames_pending_ == 0) { |
| 169 if (!content_sampler_.HasProposal() || | 178 if (!content_sampler_.HasProposal() || |
| 170 ((event_time - last_time_animation_was_detected_).InMicroseconds() > | 179 ((event_time - last_time_animation_was_detected_).InMicroseconds() > |
| 171 kAnimationHaltPeriodBeforeOtherSamplingMicros)) { | 180 kAnimationHaltPeriodBeforeOtherSamplingMicros)) { |
| 172 smoothing_sampler_.ConsiderPresentationEvent(event_time); | 181 smoothing_sampler_.ConsiderPresentationEvent(event_time); |
| 173 should_sample = smoothing_sampler_.ShouldSample(); | 182 should_sample = smoothing_sampler_.ShouldSample(); |
| 174 } | 183 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return true; | 223 return true; |
| 215 } | 224 } |
| 216 | 225 |
| 217 int VideoCaptureOracle::next_frame_number() const { | 226 int VideoCaptureOracle::next_frame_number() const { |
| 218 return next_frame_number_; | 227 return next_frame_number_; |
| 219 } | 228 } |
| 220 | 229 |
| 221 void VideoCaptureOracle::RecordCapture(double pool_utilization) { | 230 void VideoCaptureOracle::RecordCapture(double pool_utilization) { |
| 222 DCHECK(std::isfinite(pool_utilization) && pool_utilization >= 0.0); | 231 DCHECK(std::isfinite(pool_utilization) && pool_utilization >= 0.0); |
| 223 | 232 |
| 233 source_is_dirty_ = false; |
| 234 |
| 224 smoothing_sampler_.RecordSample(); | 235 smoothing_sampler_.RecordSample(); |
| 225 const base::TimeTicks timestamp = GetFrameTimestamp(next_frame_number_); | 236 const base::TimeTicks timestamp = GetFrameTimestamp(next_frame_number_); |
| 226 content_sampler_.RecordSample(timestamp); | 237 content_sampler_.RecordSample(timestamp); |
| 227 | 238 |
| 228 if (auto_throttling_enabled_) { | 239 if (auto_throttling_enabled_) { |
| 229 buffer_pool_utilization_.Update(pool_utilization, timestamp); | 240 buffer_pool_utilization_.Update(pool_utilization, timestamp); |
| 230 AnalyzeAndAdjust(timestamp); | 241 AnalyzeAndAdjust(timestamp); |
| 231 } | 242 } |
| 232 | 243 |
| 233 num_frames_pending_++; | 244 num_frames_pending_++; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 264 return false; | 275 return false; |
| 265 } | 276 } |
| 266 | 277 |
| 267 if (!IsFrameInRecentHistory(frame_number)) { | 278 if (!IsFrameInRecentHistory(frame_number)) { |
| 268 LOG(WARNING) << "Very old capture being ignored: frame #" << frame_number; | 279 LOG(WARNING) << "Very old capture being ignored: frame #" << frame_number; |
| 269 return false; | 280 return false; |
| 270 } | 281 } |
| 271 | 282 |
| 272 if (!capture_was_successful) { | 283 if (!capture_was_successful) { |
| 273 VLOG(2) << "Capture of frame #" << frame_number << " was not successful."; | 284 VLOG(2) << "Capture of frame #" << frame_number << " was not successful."; |
| 285 // Since capture of this frame might have been required for capturing an |
| 286 // update to the source content, set the dirty flag. |
| 287 source_is_dirty_ = true; |
| 274 return false; | 288 return false; |
| 275 } | 289 } |
| 276 | 290 |
| 277 DCHECK_NE(last_successfully_delivered_frame_number_, frame_number); | 291 DCHECK_NE(last_successfully_delivered_frame_number_, frame_number); |
| 278 last_successfully_delivered_frame_number_ = frame_number; | 292 last_successfully_delivered_frame_number_ = frame_number; |
| 279 | 293 |
| 280 *frame_timestamp = GetFrameTimestamp(frame_number); | 294 *frame_timestamp = GetFrameTimestamp(frame_number); |
| 281 | 295 |
| 282 // If enabled, log a measurement of how this frame timestamp has incremented | 296 // If enabled, log a measurement of how this frame timestamp has incremented |
| 283 // in relation to an ideal increment. | 297 // in relation to an ideal increment. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // Content is not animating, so permit an immediate increase in the capture | 566 // Content is not animating, so permit an immediate increase in the capture |
| 553 // area. This allows the system to quickly improve the quality of | 567 // area. This allows the system to quickly improve the quality of |
| 554 // non-animating content (frame drops are not much of a concern). | 568 // non-animating content (frame drops are not much of a concern). |
| 555 VLOG(2) << "Proposing a " | 569 VLOG(2) << "Proposing a " |
| 556 << (100.0 * (increased_area - current_area) / current_area) | 570 << (100.0 * (increased_area - current_area) / current_area) |
| 557 << "% increase in capture area for non-animating content. :-)"; | 571 << "% increase in capture area for non-animating content. :-)"; |
| 558 return increased_area; | 572 return increased_area; |
| 559 } | 573 } |
| 560 | 574 |
| 561 } // namespace media | 575 } // namespace media |
| OLD | NEW |