| 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/smooth_event_sampler.h" | 5 #include "device/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 device { |
| 14 | 14 |
| 15 SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period) | 15 SmoothEventSampler::SmoothEventSampler(base::TimeDelta min_capture_period) |
| 16 : token_bucket_(base::TimeDelta::Max()) { | 16 : token_bucket_(base::TimeDelta::Max()) { |
| 17 SetMinCapturePeriod(min_capture_period); | 17 SetMinCapturePeriod(min_capture_period); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void SmoothEventSampler::SetMinCapturePeriod(base::TimeDelta period) { | 20 void SmoothEventSampler::SetMinCapturePeriod(base::TimeDelta period) { |
| 21 DCHECK_GT(period, base::TimeDelta()); | 21 DCHECK_GT(period, base::TimeDelta()); |
| 22 min_capture_period_ = period; | 22 min_capture_period_ = period; |
| 23 token_bucket_capacity_ = period + period / 2; | 23 token_bucket_capacity_ = period + period / 2; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 std::max<int64_t>(0, token_bucket_.InMicroseconds())); | 57 std::max<int64_t>(0, token_bucket_.InMicroseconds())); |
| 58 | 58 |
| 59 if (HasUnrecordedEvent()) | 59 if (HasUnrecordedEvent()) |
| 60 last_sample_ = current_event_; | 60 last_sample_ = current_event_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool SmoothEventSampler::HasUnrecordedEvent() const { | 63 bool SmoothEventSampler::HasUnrecordedEvent() const { |
| 64 return !current_event_.is_null() && current_event_ != last_sample_; | 64 return !current_event_.is_null() && current_event_ != last_sample_; |
| 65 } | 65 } |
| 66 | 66 |
| 67 } // namespace media | 67 } // namespace device |
| OLD | NEW |