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