OLD | NEW |
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> |
| 14 |
13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/format_macros.h" |
14 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/system_wrappers/include/field_trial.h" |
15 | 19 |
16 namespace { | 20 namespace { |
17 | |
18 // Time period over which outgoing traffic is measured. | 21 // Time period over which outgoing traffic is measured. |
19 constexpr int kMeasurementPeriodMs = 500; | 22 constexpr int kMeasurementPeriodMs = 500; |
20 | 23 |
21 // Sent traffic percentage as a function of network capacity used to determine | |
22 // application-limited region. ALR region start when bandwidth usage drops below | |
23 // kAlrStartUsagePercent and ends when it raises above kAlrEndUsagePercent. | |
24 // NOTE: This is intentionally conservative at the moment until BW adjustments | |
25 // of application limited region is fine tuned. | |
26 constexpr int kAlrStartUsagePercent = 60; | |
27 constexpr int kAlrEndUsagePercent = 70; | |
28 | |
29 } // namespace | 24 } // namespace |
30 | 25 |
31 namespace webrtc { | 26 namespace webrtc { |
32 | 27 |
| 28 const char* AlrDetector::kScreenshareProbingBweExperimentName = |
| 29 "WebRTC-ProbingScreenshareBwe"; |
| 30 |
33 AlrDetector::AlrDetector() | 31 AlrDetector::AlrDetector() |
34 : rate_(kMeasurementPeriodMs, RateStatistics::kBpsScale) {} | 32 : alr_start_usage_percent_(kDefaultAlrStartUsagePercent), |
| 33 alr_end_usage_percent_(kDefaultAlrEndUsagePercent), |
| 34 rate_(kMeasurementPeriodMs, RateStatistics::kBpsScale), |
| 35 estimated_bitrate_bps_(0) { |
| 36 rtc::Optional<AlrExperimentSettings> experiment_settings = |
| 37 ParseAlrSettingsFromFieldTrial(); |
| 38 if (experiment_settings) { |
| 39 alr_start_usage_percent_ = experiment_settings->alr_start_usage_percent; |
| 40 alr_end_usage_percent_ = experiment_settings->alr_end_usage_percent; |
| 41 } |
| 42 } |
35 | 43 |
36 AlrDetector::~AlrDetector() {} | 44 AlrDetector::~AlrDetector() {} |
37 | 45 |
38 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t now_ms) { | 46 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t now_ms) { |
39 RTC_DCHECK(estimated_bitrate_bps_); | 47 RTC_DCHECK(estimated_bitrate_bps_); |
40 | 48 |
41 rate_.Update(bytes_sent, now_ms); | 49 rate_.Update(bytes_sent, now_ms); |
42 rtc::Optional<uint32_t> rate = rate_.Rate(now_ms); | 50 rtc::Optional<uint32_t> rate = rate_.Rate(now_ms); |
43 if (!rate) | 51 if (!rate) |
44 return; | 52 return; |
45 | 53 |
46 int percentage = static_cast<int>(*rate) * 100 / estimated_bitrate_bps_; | 54 int percentage = static_cast<int>(*rate) * 100 / estimated_bitrate_bps_; |
47 if (percentage < kAlrStartUsagePercent && !alr_started_time_ms_) { | 55 if (percentage < alr_start_usage_percent_ && !alr_started_time_ms_) { |
48 alr_started_time_ms_ = rtc::Optional<int64_t>(now_ms); | 56 alr_started_time_ms_ = rtc::Optional<int64_t>(now_ms); |
49 } else if (percentage > kAlrEndUsagePercent && alr_started_time_ms_) { | 57 } else if (percentage > alr_end_usage_percent_ && alr_started_time_ms_) { |
50 alr_started_time_ms_ = rtc::Optional<int64_t>(); | 58 alr_started_time_ms_ = rtc::Optional<int64_t>(); |
51 } | 59 } |
52 } | 60 } |
53 | 61 |
54 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { | 62 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { |
55 RTC_DCHECK(bitrate_bps); | 63 RTC_DCHECK(bitrate_bps); |
56 estimated_bitrate_bps_ = bitrate_bps; | 64 estimated_bitrate_bps_ = bitrate_bps; |
57 } | 65 } |
58 | 66 |
59 rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime() | 67 rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime() |
60 const { | 68 const { |
61 return alr_started_time_ms_; | 69 return alr_started_time_ms_; |
62 } | 70 } |
63 | 71 |
| 72 rtc::Optional<AlrDetector::AlrExperimentSettings> |
| 73 AlrDetector::ParseAlrSettingsFromFieldTrial() { |
| 74 rtc::Optional<AlrExperimentSettings> ret; |
| 75 std::string group_name = |
| 76 field_trial::FindFullName(kScreenshareProbingBweExperimentName); |
| 77 |
| 78 const std::string kIgnoredSuffix = "_Dogfood"; |
| 79 if (group_name.rfind(kIgnoredSuffix) == |
| 80 group_name.length() - kIgnoredSuffix.length()) { |
| 81 group_name.resize(group_name.length() - kIgnoredSuffix.length()); |
| 82 } |
| 83 |
| 84 if (group_name.empty()) |
| 85 return ret; |
| 86 |
| 87 AlrExperimentSettings settings; |
| 88 if (sscanf(group_name.c_str(), "%f-%" PRId64 "-%d-%d", |
| 89 &settings.pacing_factor, &settings.max_paced_queue_time, |
| 90 &settings.alr_start_usage_percent, |
| 91 &settings.alr_end_usage_percent) == 4) { |
| 92 ret.emplace(settings); |
| 93 LOG(LS_INFO) << "Using screenshare ALR experiment settings: " |
| 94 "pacing factor: " |
| 95 << settings.pacing_factor << ", max pacer queue length: " |
| 96 << settings.max_paced_queue_time |
| 97 << ", ALR start usage percent: " |
| 98 << settings.alr_start_usage_percent |
| 99 << ", ALR end usage percent: " |
| 100 << settings.alr_end_usage_percent; |
| 101 } |
| 102 |
| 103 return ret; |
| 104 } |
| 105 |
64 } // namespace webrtc | 106 } // namespace webrtc |
OLD | NEW |