Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/overuse_detector.cc

Issue 2808513003: Add SafeClamp(), which accepts args of different types (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" 11 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
12 12
13 #include <math.h> 13 #include <math.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <sstream> 17 #include <sstream>
18 #include <string> 18 #include <string>
19 19
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/base/logging.h" 21 #include "webrtc/base/logging.h"
22 #include "webrtc/base/safe_minmax.h"
22 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" 23 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
23 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" 24 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
24 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 25 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
25 #include "webrtc/system_wrappers/include/field_trial.h" 26 #include "webrtc/system_wrappers/include/field_trial.h"
26 27
27 namespace webrtc { 28 namespace webrtc {
28 29
29 const char kAdaptiveThresholdExperiment[] = "WebRTC-AdaptiveBweThreshold"; 30 const char kAdaptiveThresholdExperiment[] = "WebRTC-AdaptiveBweThreshold";
30 const char kEnabledPrefix[] = "Enabled"; 31 const char kEnabledPrefix[] = "Enabled";
31 const size_t kEnabledPrefixLength = sizeof(kEnabledPrefix) - 1; 32 const size_t kEnabledPrefixLength = sizeof(kEnabledPrefix) - 1;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // by a sudden capacity drop. 138 // by a sudden capacity drop.
138 last_update_ms_ = now_ms; 139 last_update_ms_ = now_ms;
139 return; 140 return;
140 } 141 }
141 142
142 const double k = fabs(modified_offset) < threshold_ ? k_down_ : k_up_; 143 const double k = fabs(modified_offset) < threshold_ ? k_down_ : k_up_;
143 const int64_t kMaxTimeDeltaMs = 100; 144 const int64_t kMaxTimeDeltaMs = 100;
144 int64_t time_delta_ms = std::min(now_ms - last_update_ms_, kMaxTimeDeltaMs); 145 int64_t time_delta_ms = std::min(now_ms - last_update_ms_, kMaxTimeDeltaMs);
145 threshold_ += 146 threshold_ +=
146 k * (fabs(modified_offset) - threshold_) * time_delta_ms; 147 k * (fabs(modified_offset) - threshold_) * time_delta_ms;
147 148 threshold_ = rtc::SafeClamp(threshold_, 6.f, 600.f);
148 const double kMinThreshold = 6;
149 const double kMaxThreshold = 600;
150 threshold_ = std::min(std::max(threshold_, kMinThreshold), kMaxThreshold);
151
152 last_update_ms_ = now_ms; 149 last_update_ms_ = now_ms;
153 } 150 }
154 151
155 void OveruseDetector::InitializeExperiment() { 152 void OveruseDetector::InitializeExperiment() {
156 RTC_DCHECK(in_experiment_); 153 RTC_DCHECK(in_experiment_);
157 double k_up = 0.0; 154 double k_up = 0.0;
158 double k_down = 0.0; 155 double k_down = 0.0;
159 overusing_time_threshold_ = kOverUsingTimeThreshold; 156 overusing_time_threshold_ = kOverUsingTimeThreshold;
160 if (ReadExperimentConstants(&k_up, &k_down)) { 157 if (ReadExperimentConstants(&k_up, &k_down)) {
161 k_up_ = k_up; 158 k_up_ = k_up;
162 k_down_ = k_down; 159 k_down_ = k_down;
163 } 160 }
164 } 161 }
165 } // namespace webrtc 162 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698