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

Side by Side Diff: webrtc/modules/pacing/alr_detector.cc

Issue 2965233002: Let alr dectector use a budged to detect underuse. (Closed)
Patch Set: Rebased. Created 3 years, 5 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
« no previous file with comments | « webrtc/modules/pacing/alr_detector.h ('k') | webrtc/modules/pacing/alr_detector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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/pacing/alr_detector.h" 11 #include "webrtc/modules/pacing/alr_detector.h"
12 12
13 #include <string> 13 #include <string>
14 14
15 #include "webrtc/rtc_base/checks.h" 15 #include "webrtc/rtc_base/checks.h"
16 #include "webrtc/rtc_base/format_macros.h" 16 #include "webrtc/rtc_base/format_macros.h"
17 #include "webrtc/rtc_base/logging.h" 17 #include "webrtc/rtc_base/logging.h"
18 #include "webrtc/rtc_base/timeutils.h"
18 #include "webrtc/system_wrappers/include/field_trial.h" 19 #include "webrtc/system_wrappers/include/field_trial.h"
19 20
20 namespace {
21 // Time period over which outgoing traffic is measured.
22 constexpr int kMeasurementPeriodMs = 500;
23
24 } // namespace
25
26 namespace webrtc { 21 namespace webrtc {
27 22
28 const char* AlrDetector::kScreenshareProbingBweExperimentName = 23 const char* AlrDetector::kScreenshareProbingBweExperimentName =
29 "WebRTC-ProbingScreenshareBwe"; 24 "WebRTC-ProbingScreenshareBwe";
30 25
31 AlrDetector::AlrDetector() 26 AlrDetector::AlrDetector()
32 : alr_start_usage_percent_(kDefaultAlrStartUsagePercent), 27 : bandwidth_usage_percent_(kDefaultAlrBandwidthUsagePercent),
33 alr_end_usage_percent_(kDefaultAlrEndUsagePercent), 28 alr_start_budget_level_percent_(kDefaultAlrStartBudgetLevelPercent),
34 rate_(kMeasurementPeriodMs, RateStatistics::kBpsScale), 29 alr_stop_budget_level_percent_(kDefaultAlrStopBudgetLevelPercent),
35 estimated_bitrate_bps_(0) { 30 alr_budget_(0, true) {
36 rtc::Optional<AlrExperimentSettings> experiment_settings = 31 rtc::Optional<AlrExperimentSettings> experiment_settings =
37 ParseAlrSettingsFromFieldTrial(); 32 ParseAlrSettingsFromFieldTrial();
38 if (experiment_settings) { 33 if (experiment_settings) {
39 alr_start_usage_percent_ = experiment_settings->alr_start_usage_percent; 34 alr_stop_budget_level_percent_ =
40 alr_end_usage_percent_ = experiment_settings->alr_end_usage_percent; 35 experiment_settings->alr_stop_budget_level_percent;
36 alr_start_budget_level_percent_ =
37 experiment_settings->alr_start_budget_level_percent;
38 bandwidth_usage_percent_ = experiment_settings->alr_bandwidth_usage_percent;
41 } 39 }
42 } 40 }
43 41
44 AlrDetector::~AlrDetector() {} 42 AlrDetector::~AlrDetector() {}
45 43
46 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t now_ms) { 44 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t delta_time_ms) {
47 RTC_DCHECK(estimated_bitrate_bps_); 45 alr_budget_.UseBudget(bytes_sent);
46 alr_budget_.IncreaseBudget(delta_time_ms);
48 47
49 rate_.Update(bytes_sent, now_ms); 48 if (alr_budget_.budget_level_percent() > alr_start_budget_level_percent_ &&
50 rtc::Optional<uint32_t> rate = rate_.Rate(now_ms); 49 !alr_started_time_ms_) {
51 if (!rate) 50 alr_started_time_ms_.emplace(rtc::TimeMillis());
52 return; 51 } else if (alr_budget_.budget_level_percent() <
53 52 alr_stop_budget_level_percent_ &&
54 int percentage = static_cast<int>(*rate) * 100 / estimated_bitrate_bps_; 53 alr_started_time_ms_) {
55 if (percentage < alr_start_usage_percent_ && !alr_started_time_ms_) { 54 alr_started_time_ms_.reset();
56 alr_started_time_ms_ = rtc::Optional<int64_t>(now_ms);
57 } else if (percentage > alr_end_usage_percent_ && alr_started_time_ms_) {
58 alr_started_time_ms_ = rtc::Optional<int64_t>();
59 } 55 }
60 } 56 }
61 57
62 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { 58 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
63 RTC_DCHECK(bitrate_bps); 59 RTC_DCHECK(bitrate_bps);
64 estimated_bitrate_bps_ = bitrate_bps; 60 alr_budget_.set_target_rate_kbps(bitrate_bps * bandwidth_usage_percent_ /
61 (1000 * 100));
65 } 62 }
66 63
67 rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime() 64 rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime()
68 const { 65 const {
69 return alr_started_time_ms_; 66 return alr_started_time_ms_;
70 } 67 }
71 68
72 rtc::Optional<AlrDetector::AlrExperimentSettings> 69 rtc::Optional<AlrDetector::AlrExperimentSettings>
73 AlrDetector::ParseAlrSettingsFromFieldTrial() { 70 AlrDetector::ParseAlrSettingsFromFieldTrial() {
74 rtc::Optional<AlrExperimentSettings> ret; 71 rtc::Optional<AlrExperimentSettings> ret;
75 std::string group_name = 72 std::string group_name =
76 field_trial::FindFullName(kScreenshareProbingBweExperimentName); 73 field_trial::FindFullName(kScreenshareProbingBweExperimentName);
77 74
78 const std::string kIgnoredSuffix = "_Dogfood"; 75 const std::string kIgnoredSuffix = "_Dogfood";
79 if (group_name.rfind(kIgnoredSuffix) == 76 if (group_name.rfind(kIgnoredSuffix) ==
80 group_name.length() - kIgnoredSuffix.length()) { 77 group_name.length() - kIgnoredSuffix.length()) {
81 group_name.resize(group_name.length() - kIgnoredSuffix.length()); 78 group_name.resize(group_name.length() - kIgnoredSuffix.length());
82 } 79 }
83 80
84 if (group_name.empty()) 81 if (group_name.empty())
85 return ret; 82 return ret;
86 83
87 AlrExperimentSettings settings; 84 AlrExperimentSettings settings;
88 if (sscanf(group_name.c_str(), "%f-%" PRId64 "-%d-%d", 85 if (sscanf(group_name.c_str(), "%f,%" PRId64 ",%d,%d,%d",
89 &settings.pacing_factor, &settings.max_paced_queue_time, 86 &settings.pacing_factor, &settings.max_paced_queue_time,
90 &settings.alr_start_usage_percent, 87 &settings.alr_bandwidth_usage_percent,
91 &settings.alr_end_usage_percent) == 4) { 88 &settings.alr_start_budget_level_percent,
89 &settings.alr_stop_budget_level_percent) == 5) {
92 ret.emplace(settings); 90 ret.emplace(settings);
93 LOG(LS_INFO) << "Using screenshare ALR experiment settings: " 91 LOG(LS_INFO) << "Using screenshare ALR experiment settings: "
94 "pacing factor: " 92 "pacing factor: "
95 << settings.pacing_factor << ", max pacer queue length: " 93 << settings.pacing_factor << ", max pacer queue length: "
96 << settings.max_paced_queue_time 94 << settings.max_paced_queue_time
97 << ", ALR start usage percent: " 95 << ", ALR start bandwidth usage percent: "
98 << settings.alr_start_usage_percent 96 << settings.alr_bandwidth_usage_percent
99 << ", ALR end usage percent: " 97 << ", ALR end budget level percent: "
100 << settings.alr_end_usage_percent; 98 << settings.alr_start_budget_level_percent
99 << ", ALR end budget level percent: "
100 << settings.alr_stop_budget_level_percent;
101 } 101 }
102 102
103 return ret; 103 return ret;
104 } 104 }
105 105
106 } // namespace webrtc 106 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/alr_detector.h ('k') | webrtc/modules/pacing/alr_detector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698