OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/video/bad_call_threshold.h" | |
12 | |
13 #include "webrtc/base/checks.h" | |
14 #include "webrtc/base/logging.h" | |
15 | |
16 namespace webrtc { | |
17 | |
18 BadCallThreshold::BadCallThreshold(int threshold, | |
19 int default_measurement, | |
20 float fraction, | |
21 int max_measurements) | |
22 : buffer_(new int[max_measurements]), | |
23 max_measurements_(max_measurements), | |
24 fraction_(fraction), | |
25 threshold_(threshold), | |
26 next_index_(0), | |
27 is_high_(default_measurement >= threshold) { | |
28 RTC_CHECK_GE(fraction, 0.5f); | |
29 std::fill_n(buffer_.get(), max_measurements, default_measurement); | |
30 } | |
31 | |
32 BadCallThreshold::BadCallState BadCallThreshold::AddMeasurement( | |
33 int measurement) { | |
34 buffer_[next_index_] = measurement; | |
35 next_index_ = (next_index_ + 1) % max_measurements_; | |
36 | |
37 float frac_high = 0; | |
38 for (int i = 0; i < max_measurements_; ++i) { | |
39 if (buffer_[i] >= threshold_) | |
40 frac_high += 1.0f / max_measurements_; | |
41 } | |
42 | |
43 if (!is_high_ && frac_high >= fraction_) { | |
44 is_high_ = true; | |
45 return NEWLY_HIGH; | |
46 } | |
sprang_webrtc
2016/11/14 13:14:15
What tradeoffs are there with doing state change d
palmkvist
2016/11/15 15:01:01
You're suggesting just calculating which state we'
sprang_webrtc
2016/11/16 13:20:09
Maybe also consider returning an rtc::Optional<Sta
| |
47 | |
48 if (is_high_ && frac_high <= 1 - fraction_) { | |
49 is_high_ = false; | |
50 return NEWLY_LOW; | |
51 } | |
52 | |
53 return is_high_ ? STILL_HIGH : STILL_LOW; | |
54 } | |
55 | |
56 } // namespace webrtc | |
OLD | NEW |