| 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> | 13 #include <string> |
| 14 | 14 |
| 15 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 15 #include "webrtc/rtc_base/checks.h" | 16 #include "webrtc/rtc_base/checks.h" |
| 16 #include "webrtc/rtc_base/format_macros.h" | 17 #include "webrtc/rtc_base/format_macros.h" |
| 17 #include "webrtc/rtc_base/logging.h" | 18 #include "webrtc/rtc_base/logging.h" |
| 18 #include "webrtc/rtc_base/timeutils.h" | 19 #include "webrtc/rtc_base/timeutils.h" |
| 19 #include "webrtc/system_wrappers/include/field_trial.h" | 20 #include "webrtc/system_wrappers/include/field_trial.h" |
| 20 | 21 |
| 21 namespace webrtc { | 22 namespace webrtc { |
| 22 | 23 |
| 23 const char AlrDetector::kScreenshareProbingBweExperimentName[] = | 24 const char AlrDetector::kScreenshareProbingBweExperimentName[] = |
| 24 "WebRTC-ProbingScreenshareBwe"; | 25 "WebRTC-ProbingScreenshareBwe"; |
| 25 const char AlrDetector::kStrictPacingAndProbingExperimentName[] = | 26 const char AlrDetector::kStrictPacingAndProbingExperimentName[] = |
| 26 "WebRTC-StrictPacingAndProbing"; | 27 "WebRTC-StrictPacingAndProbing"; |
| 27 | 28 |
| 28 AlrDetector::AlrDetector() | 29 AlrDetector::AlrDetector() : AlrDetector(nullptr) {} |
| 30 |
| 31 AlrDetector::AlrDetector(RtcEventLog* event_log) |
| 29 : bandwidth_usage_percent_(kDefaultAlrBandwidthUsagePercent), | 32 : bandwidth_usage_percent_(kDefaultAlrBandwidthUsagePercent), |
| 30 alr_start_budget_level_percent_(kDefaultAlrStartBudgetLevelPercent), | 33 alr_start_budget_level_percent_(kDefaultAlrStartBudgetLevelPercent), |
| 31 alr_stop_budget_level_percent_(kDefaultAlrStopBudgetLevelPercent), | 34 alr_stop_budget_level_percent_(kDefaultAlrStopBudgetLevelPercent), |
| 32 alr_budget_(0, true) { | 35 alr_budget_(0, true), |
| 36 event_log_(event_log) { |
| 33 RTC_CHECK( | 37 RTC_CHECK( |
| 34 field_trial::FindFullName(kStrictPacingAndProbingExperimentName) | 38 field_trial::FindFullName(kStrictPacingAndProbingExperimentName) |
| 35 .empty() || | 39 .empty() || |
| 36 field_trial::FindFullName(kScreenshareProbingBweExperimentName).empty()); | 40 field_trial::FindFullName(kScreenshareProbingBweExperimentName).empty()); |
| 37 rtc::Optional<AlrExperimentSettings> experiment_settings = | 41 rtc::Optional<AlrExperimentSettings> experiment_settings = |
| 38 ParseAlrSettingsFromFieldTrial(kScreenshareProbingBweExperimentName); | 42 ParseAlrSettingsFromFieldTrial(kScreenshareProbingBweExperimentName); |
| 39 if (!experiment_settings) { | 43 if (!experiment_settings) { |
| 40 experiment_settings = | 44 experiment_settings = |
| 41 ParseAlrSettingsFromFieldTrial(kStrictPacingAndProbingExperimentName); | 45 ParseAlrSettingsFromFieldTrial(kStrictPacingAndProbingExperimentName); |
| 42 } | 46 } |
| 43 if (experiment_settings) { | 47 if (experiment_settings) { |
| 44 alr_stop_budget_level_percent_ = | 48 alr_stop_budget_level_percent_ = |
| 45 experiment_settings->alr_stop_budget_level_percent; | 49 experiment_settings->alr_stop_budget_level_percent; |
| 46 alr_start_budget_level_percent_ = | 50 alr_start_budget_level_percent_ = |
| 47 experiment_settings->alr_start_budget_level_percent; | 51 experiment_settings->alr_start_budget_level_percent; |
| 48 bandwidth_usage_percent_ = experiment_settings->alr_bandwidth_usage_percent; | 52 bandwidth_usage_percent_ = experiment_settings->alr_bandwidth_usage_percent; |
| 49 } | 53 } |
| 50 } | 54 } |
| 51 | 55 |
| 52 AlrDetector::~AlrDetector() {} | 56 AlrDetector::~AlrDetector() {} |
| 53 | 57 |
| 54 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t delta_time_ms) { | 58 void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t delta_time_ms) { |
| 55 alr_budget_.UseBudget(bytes_sent); | 59 alr_budget_.UseBudget(bytes_sent); |
| 56 alr_budget_.IncreaseBudget(delta_time_ms); | 60 alr_budget_.IncreaseBudget(delta_time_ms); |
| 57 | |
| 58 if (alr_budget_.budget_level_percent() > alr_start_budget_level_percent_ && | 61 if (alr_budget_.budget_level_percent() > alr_start_budget_level_percent_ && |
| 59 !alr_started_time_ms_) { | 62 !alr_started_time_ms_) { |
| 60 alr_started_time_ms_.emplace(rtc::TimeMillis()); | 63 alr_started_time_ms_.emplace(rtc::TimeMillis()); |
| 61 } else if (alr_budget_.budget_level_percent() < | 64 } else if (alr_budget_.budget_level_percent() < |
| 62 alr_stop_budget_level_percent_ && | 65 alr_stop_budget_level_percent_ && |
| 63 alr_started_time_ms_) { | 66 alr_started_time_ms_) { |
| 64 alr_started_time_ms_.reset(); | 67 alr_started_time_ms_.reset(); |
| 65 } | 68 } |
| 69 int usage = 100 - alr_budget_.budget_level_percent(); |
| 70 uint32_t usage_kbps = usage * alr_budget_.target_rate_kbps() / 200; |
| 71 usage_kbps *= 100.0 / bandwidth_usage_percent_; |
| 72 if (event_log_) |
| 73 event_log_->LogAlrState(alr_started_time_ms_.has_value(), |
| 74 usage_kbps * 1000); |
| 66 } | 75 } |
| 67 | 76 |
| 68 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { | 77 void AlrDetector::SetEstimatedBitrate(int bitrate_bps) { |
| 69 RTC_DCHECK(bitrate_bps); | 78 RTC_DCHECK(bitrate_bps); |
| 70 alr_budget_.set_target_rate_kbps(bitrate_bps * bandwidth_usage_percent_ / | 79 alr_budget_.set_target_rate_kbps(bitrate_bps * bandwidth_usage_percent_ / |
| 71 (1000 * 100)); | 80 (1000 * 100)); |
| 72 } | 81 } |
| 73 | 82 |
| 74 rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime() | 83 rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime() |
| 75 const { | 84 const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 << ", ALR end budget level percent: " | 117 << ", ALR end budget level percent: " |
| 109 << settings.alr_stop_budget_level_percent; | 118 << settings.alr_stop_budget_level_percent; |
| 110 } else { | 119 } else { |
| 111 LOG(LS_INFO) << "Failed to parse ALR experiment: " << experiment_name; | 120 LOG(LS_INFO) << "Failed to parse ALR experiment: " << experiment_name; |
| 112 } | 121 } |
| 113 | 122 |
| 114 return ret; | 123 return ret; |
| 115 } | 124 } |
| 116 | 125 |
| 117 } // namespace webrtc | 126 } // namespace webrtc |
| OLD | NEW |