2016-10-04 08:43:09 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/pacing/alr_detector.h"
|
|
|
|
|
|
2017-06-30 13:27:40 -07:00
|
|
|
#include <string>
|
|
|
|
|
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/checks.h"
|
|
|
|
|
#include "webrtc/rtc_base/format_macros.h"
|
|
|
|
|
#include "webrtc/rtc_base/logging.h"
|
2017-07-11 06:56:04 -07:00
|
|
|
#include "webrtc/rtc_base/timeutils.h"
|
2017-06-30 13:27:40 -07:00
|
|
|
#include "webrtc/system_wrappers/include/field_trial.h"
|
2016-10-04 08:43:09 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2017-06-30 13:27:40 -07:00
|
|
|
const char* AlrDetector::kScreenshareProbingBweExperimentName =
|
|
|
|
|
"WebRTC-ProbingScreenshareBwe";
|
2017-08-08 06:51:05 -07:00
|
|
|
const char* AlrDetector::kStrictPacingAndProbingExperimentName =
|
|
|
|
|
"WebRTC-StrictPacingAndProbing";
|
2017-06-30 13:27:40 -07:00
|
|
|
|
2016-10-04 08:43:09 -07:00
|
|
|
AlrDetector::AlrDetector()
|
2017-07-11 06:56:04 -07:00
|
|
|
: bandwidth_usage_percent_(kDefaultAlrBandwidthUsagePercent),
|
|
|
|
|
alr_start_budget_level_percent_(kDefaultAlrStartBudgetLevelPercent),
|
|
|
|
|
alr_stop_budget_level_percent_(kDefaultAlrStopBudgetLevelPercent),
|
|
|
|
|
alr_budget_(0, true) {
|
2017-08-08 06:51:05 -07:00
|
|
|
RTC_CHECK(
|
|
|
|
|
field_trial::FindFullName(kStrictPacingAndProbingExperimentName)
|
|
|
|
|
.empty() ||
|
|
|
|
|
field_trial::FindFullName(kScreenshareProbingBweExperimentName).empty());
|
2017-06-30 13:27:40 -07:00
|
|
|
rtc::Optional<AlrExperimentSettings> experiment_settings =
|
2017-08-08 06:51:05 -07:00
|
|
|
ParseAlrSettingsFromFieldTrial(kScreenshareProbingBweExperimentName);
|
|
|
|
|
if (!experiment_settings) {
|
|
|
|
|
experiment_settings =
|
|
|
|
|
ParseAlrSettingsFromFieldTrial(kStrictPacingAndProbingExperimentName);
|
|
|
|
|
}
|
2017-06-30 13:27:40 -07:00
|
|
|
if (experiment_settings) {
|
2017-07-11 06:56:04 -07:00
|
|
|
alr_stop_budget_level_percent_ =
|
|
|
|
|
experiment_settings->alr_stop_budget_level_percent;
|
|
|
|
|
alr_start_budget_level_percent_ =
|
|
|
|
|
experiment_settings->alr_start_budget_level_percent;
|
|
|
|
|
bandwidth_usage_percent_ = experiment_settings->alr_bandwidth_usage_percent;
|
2017-06-30 13:27:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 08:43:09 -07:00
|
|
|
|
|
|
|
|
AlrDetector::~AlrDetector() {}
|
|
|
|
|
|
2017-07-11 06:56:04 -07:00
|
|
|
void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t delta_time_ms) {
|
|
|
|
|
alr_budget_.UseBudget(bytes_sent);
|
|
|
|
|
alr_budget_.IncreaseBudget(delta_time_ms);
|
|
|
|
|
|
|
|
|
|
if (alr_budget_.budget_level_percent() > alr_start_budget_level_percent_ &&
|
|
|
|
|
!alr_started_time_ms_) {
|
|
|
|
|
alr_started_time_ms_.emplace(rtc::TimeMillis());
|
|
|
|
|
} else if (alr_budget_.budget_level_percent() <
|
|
|
|
|
alr_stop_budget_level_percent_ &&
|
|
|
|
|
alr_started_time_ms_) {
|
|
|
|
|
alr_started_time_ms_.reset();
|
2016-10-04 08:43:09 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
|
|
|
|
|
RTC_DCHECK(bitrate_bps);
|
2017-07-11 06:56:04 -07:00
|
|
|
alr_budget_.set_target_rate_kbps(bitrate_bps * bandwidth_usage_percent_ /
|
|
|
|
|
(1000 * 100));
|
2016-10-04 08:43:09 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 13:11:13 -08:00
|
|
|
rtc::Optional<int64_t> AlrDetector::GetApplicationLimitedRegionStartTime()
|
|
|
|
|
const {
|
|
|
|
|
return alr_started_time_ms_;
|
2016-10-04 08:43:09 -07:00
|
|
|
}
|
|
|
|
|
|
2017-06-30 13:27:40 -07:00
|
|
|
rtc::Optional<AlrDetector::AlrExperimentSettings>
|
2017-08-08 06:51:05 -07:00
|
|
|
AlrDetector::ParseAlrSettingsFromFieldTrial(const char* experiment_name) {
|
2017-06-30 13:27:40 -07:00
|
|
|
rtc::Optional<AlrExperimentSettings> ret;
|
2017-08-08 06:51:05 -07:00
|
|
|
std::string group_name = field_trial::FindFullName(experiment_name);
|
2017-06-30 13:27:40 -07:00
|
|
|
|
|
|
|
|
const std::string kIgnoredSuffix = "_Dogfood";
|
|
|
|
|
if (group_name.rfind(kIgnoredSuffix) ==
|
|
|
|
|
group_name.length() - kIgnoredSuffix.length()) {
|
|
|
|
|
group_name.resize(group_name.length() - kIgnoredSuffix.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (group_name.empty())
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
AlrExperimentSettings settings;
|
2017-07-11 06:56:04 -07:00
|
|
|
if (sscanf(group_name.c_str(), "%f,%" PRId64 ",%d,%d,%d",
|
2017-06-30 13:27:40 -07:00
|
|
|
&settings.pacing_factor, &settings.max_paced_queue_time,
|
2017-07-11 06:56:04 -07:00
|
|
|
&settings.alr_bandwidth_usage_percent,
|
|
|
|
|
&settings.alr_start_budget_level_percent,
|
|
|
|
|
&settings.alr_stop_budget_level_percent) == 5) {
|
2017-06-30 13:27:40 -07:00
|
|
|
ret.emplace(settings);
|
2017-08-08 06:51:05 -07:00
|
|
|
LOG(LS_INFO) << "Using ALR experiment settings: "
|
2017-06-30 13:27:40 -07:00
|
|
|
"pacing factor: "
|
|
|
|
|
<< settings.pacing_factor << ", max pacer queue length: "
|
|
|
|
|
<< settings.max_paced_queue_time
|
2017-07-11 06:56:04 -07:00
|
|
|
<< ", ALR start bandwidth usage percent: "
|
|
|
|
|
<< settings.alr_bandwidth_usage_percent
|
|
|
|
|
<< ", ALR end budget level percent: "
|
|
|
|
|
<< settings.alr_start_budget_level_percent
|
|
|
|
|
<< ", ALR end budget level percent: "
|
|
|
|
|
<< settings.alr_stop_budget_level_percent;
|
2017-08-08 06:51:05 -07:00
|
|
|
} else {
|
|
|
|
|
LOG(LS_INFO) << "Failed to parse ALR experiment: " << experiment_name;
|
2017-06-30 13:27:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 08:43:09 -07:00
|
|
|
} // namespace webrtc
|