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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // time between events (a common case), or when RecordSample() is not being | 190 // time between events (a common case), or when RecordSample() is not being |
191 // called often enough (a bug). On the other hand, if RecordSample() is being | 191 // called often enough (a bug). On the other hand, if RecordSample() is being |
192 // called too often (e.g., as a reaction to IsOverdueForSamplingAt()), the | 192 // called too often (e.g., as a reaction to IsOverdueForSamplingAt()), the |
193 // bucket will underflow. | 193 // bucket will underflow. |
194 if (!current_event_.is_null()) { | 194 if (!current_event_.is_null()) { |
195 if (current_event_ < event_time) { | 195 if (current_event_ < event_time) { |
196 token_bucket_ += event_time - current_event_; | 196 token_bucket_ += event_time - current_event_; |
197 if (token_bucket_ > token_bucket_capacity_) | 197 if (token_bucket_ > token_bucket_capacity_) |
198 token_bucket_ = token_bucket_capacity_; | 198 token_bucket_ = token_bucket_capacity_; |
199 } | 199 } |
200 TRACE_COUNTER1("mirroring", | 200 TRACE_COUNTER1("gpu.capture", |
201 "MirroringTokenBucketUsec", | 201 "MirroringTokenBucketUsec", |
202 std::max<int64>(0, token_bucket_.InMicroseconds())); | 202 std::max<int64>(0, token_bucket_.InMicroseconds())); |
203 } | 203 } |
204 current_event_ = event_time; | 204 current_event_ = event_time; |
205 } | 205 } |
206 | 206 |
207 bool SmoothEventSampler::ShouldSample() const { | 207 bool SmoothEventSampler::ShouldSample() const { |
208 return token_bucket_ >= min_capture_period_; | 208 return token_bucket_ >= min_capture_period_; |
209 } | 209 } |
210 | 210 |
211 void SmoothEventSampler::RecordSample() { | 211 void SmoothEventSampler::RecordSample() { |
212 token_bucket_ -= min_capture_period_; | 212 token_bucket_ -= min_capture_period_; |
213 if (token_bucket_ < base::TimeDelta()) | 213 if (token_bucket_ < base::TimeDelta()) |
214 token_bucket_ = base::TimeDelta(); | 214 token_bucket_ = base::TimeDelta(); |
215 TRACE_COUNTER1("mirroring", | 215 TRACE_COUNTER1("gpu.capture", |
216 "MirroringTokenBucketUsec", | 216 "MirroringTokenBucketUsec", |
217 std::max<int64>(0, token_bucket_.InMicroseconds())); | 217 std::max<int64>(0, token_bucket_.InMicroseconds())); |
218 | 218 |
219 if (HasUnrecordedEvent()) { | 219 if (HasUnrecordedEvent()) { |
220 last_sample_ = current_event_; | 220 last_sample_ = current_event_; |
221 overdue_sample_count_ = 0; | 221 overdue_sample_count_ = 0; |
222 } else { | 222 } else { |
223 ++overdue_sample_count_; | 223 ++overdue_sample_count_; |
224 } | 224 } |
225 } | 225 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 if (borrowed_time_ >= min_capture_period_) { | 419 if (borrowed_time_ >= min_capture_period_) { |
420 borrowed_time_ -= min_capture_period_; | 420 borrowed_time_ -= min_capture_period_; |
421 frame_timestamp_ = base::TimeTicks(); | 421 frame_timestamp_ = base::TimeTicks(); |
422 } else { | 422 } else { |
423 sequence_offset_ += advancement; | 423 sequence_offset_ += advancement; |
424 frame_timestamp_ = timebase + sequence_offset_; | 424 frame_timestamp_ = timebase + sequence_offset_; |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 } // namespace content | 428 } // namespace content |
OLD | NEW |