Unverified 提交 b8ec1c53 authored 作者: José Luis Millán's avatar José Luis Millán 提交者: GitHub

libwebrtc: BWE tweaks and debug logs (#468)

* libwebrtc: BWE tweaks and debug logs

* TransportCongestionControlClient: set 'startBitrate' to 'availableBitrate'
上级 85a850b9
......@@ -144,7 +144,7 @@ void RtpTransportControllerSend::RegisterTargetTransferRateObserver(
}
void RtpTransportControllerSend::OnNetworkAvailability(bool network_available) {
MS_DEBUG_DEV("SignalNetworkState:%s", network_available ? "Up" : "Down");
MS_DEBUG_DEV("<<<<< network_available:%s", network_available ? "true" : "false");
NetworkAvailability msg;
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
......@@ -176,6 +176,8 @@ void RtpTransportControllerSend::EnablePeriodicAlrProbing(bool enable) {
void RtpTransportControllerSend::OnSentPacket(
const rtc::SentPacket& sent_packet, size_t size) {
MS_DEBUG_DEV("<<<<< size:%zu", size);
absl::optional<SentPacket> packet_msg =
transport_feedback_adapter_.ProcessSentPacket(sent_packet);
if (packet_msg)
......@@ -186,6 +188,8 @@ void RtpTransportControllerSend::OnSentPacket(
void RtpTransportControllerSend::OnTransportOverheadChanged(
size_t transport_overhead_bytes_per_packet) {
MS_DEBUG_DEV("<<<<< transport_overhead_bytes_per_packet:%zu", transport_overhead_bytes_per_packet);
if (transport_overhead_bytes_per_packet >= kMaxOverheadBytes) {
MS_ERROR("transport overhead exceeds: %zu", kMaxOverheadBytes);
return;
......@@ -193,6 +197,8 @@ void RtpTransportControllerSend::OnTransportOverheadChanged(
}
void RtpTransportControllerSend::OnReceivedEstimatedBitrate(uint32_t bitrate) {
MS_DEBUG_DEV("<<<<< bitrate:%zu", bitrate);
RemoteBitrateReport msg;
msg.receive_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
msg.bandwidth = DataRate::bps(bitrate);
......@@ -204,6 +210,8 @@ void RtpTransportControllerSend::OnReceivedRtcpReceiverReport(
const ReportBlockList& report_blocks,
int64_t rtt_ms,
int64_t now_ms) {
MS_DEBUG_DEV("<<<<< rtt_ms:%" PRIi64, rtt_ms);
OnReceivedRtcpReceiverReportBlocks(report_blocks, now_ms);
RoundTripTimeUpdate report;
......@@ -225,6 +233,8 @@ void RtpTransportControllerSend::OnAddPacket(
void RtpTransportControllerSend::OnTransportFeedback(
const RTC::RTCP::FeedbackRtpTransportPacket& feedback) {
MS_DEBUG_DEV("<<<<<");
absl::optional<TransportPacketsFeedback> feedback_msg =
transport_feedback_adapter_.ProcessTransportFeedback(
feedback, Timestamp::ms(DepLibUV::GetTimeMsInt64()));
......@@ -267,6 +277,8 @@ void RtpTransportControllerSend::MaybeCreateControllers() {
}
void RtpTransportControllerSend::UpdateControllerWithTimeInterval() {
MS_DEBUG_DEV("<<<<<");
// RTC_DCHECK(controller_);
MS_ASSERT(controller_, "controller not set");
......@@ -277,6 +289,8 @@ void RtpTransportControllerSend::UpdateControllerWithTimeInterval() {
}
void RtpTransportControllerSend::UpdateStreamsConfig() {
MS_DEBUG_DEV("<<<<<");
streams_config_.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
if (controller_)
PostUpdates(controller_->OnStreamsConfig(streams_config_));
......
......@@ -278,6 +278,8 @@ void SendSideBandwidthEstimation::SetBitrates(
void SendSideBandwidthEstimation::SetSendBitrate(DataRate bitrate,
Timestamp at_time) {
MS_DEBUG_DEV("bitrate: %lld", bitrate.bps());
// RTC_DCHECK_GT(bitrate, DataRate::Zero());
// Reset to avoid being capped by the estimate.
delay_based_bitrate_ = DataRate::Zero();
......@@ -311,6 +313,13 @@ void SendSideBandwidthEstimation::CurrentEstimate(int* bitrate,
*bitrate = std::max<int32_t>(current_bitrate_.bps<int>(), GetMinBitrate());
*loss = last_fraction_loss_;
*rtt = last_round_trip_time_.ms<int64_t>();
MS_DEBUG_DEV("bitrate:%d (current_bitrate_:%" PRIi64 ", GetMinBitrate():%d), loss:%d, rtt:%" PRIi64,
*bitrate,
current_bitrate_.bps(),
GetMinBitrate(),
*loss,
*rtt);
}
DataRate SendSideBandwidthEstimation::GetEstimatedLinkCapacity() const {
......@@ -622,20 +631,25 @@ DataRate SendSideBandwidthEstimation::MaybeRampupOrBackoff(DataRate new_bitrate,
void SendSideBandwidthEstimation::CapBitrateToThresholds(Timestamp at_time,
DataRate bitrate) {
if (bwe_incoming_ > DataRate::Zero() && bitrate > bwe_incoming_) {
MS_DEBUG_DEV("bwe_incoming_:%lld", bwe_incoming_.bps());
bitrate = bwe_incoming_;
}
if (delay_based_bitrate_ > DataRate::Zero() &&
bitrate > delay_based_bitrate_) {
MS_DEBUG_DEV("delay_based_bitrate_:%lld", delay_based_bitrate_.bps());
bitrate = delay_based_bitrate_;
}
if (loss_based_bandwidth_estimation_.Enabled() &&
loss_based_bandwidth_estimation_.GetEstimate() > DataRate::Zero()) {
MS_DEBUG_DEV("loss_based_bandwidth_estimation_.GetEstimate():%lld", loss_based_bandwidth_estimation_.GetEstimate().bps());
bitrate = std::min(bitrate, loss_based_bandwidth_estimation_.GetEstimate());
}
if (bitrate > max_bitrate_configured_) {
MS_DEBUG_DEV("bitrate > max_bitrate_configured_, setting bitrate to max_bitrate_configured_");
bitrate = max_bitrate_configured_;
}
if (bitrate < min_bitrate_configured_) {
MS_DEBUG_DEV("bitrate < min_bitrate_configured_");
if (last_low_bitrate_log_.IsInfinite() ||
at_time - last_low_bitrate_log_ > kLowBitrateLogPeriod) {
MS_WARN_TAG(bwe, "Estimated available bandwidth %s"
......@@ -653,6 +667,7 @@ void SendSideBandwidthEstimation::CapBitrateToThresholds(Timestamp at_time,
last_logged_fraction_loss_ = last_fraction_loss_;
last_rtc_event_log_ = at_time;
}
MS_DEBUG_DEV("current_bitrate_:%lld", current_bitrate_.bps());
current_bitrate_ = bitrate;
if (acknowledged_rate_) {
......
......@@ -172,14 +172,23 @@ DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(
// Currently overusing the bandwidth.
if (delay_detector_->State() == BandwidthUsage::kBwOverusing) {
MS_DEBUG_DEV("delay_detector_->State() == BandwidthUsage::kBwOverusing");
MS_DEBUG_DEV("in_alr: %s", in_alr ? "true" : "false");
if (in_alr && alr_limited_backoff_enabled_) {
if (rate_control_.TimeToReduceFurther(at_time, prev_bitrate_)) {
MS_DEBUG_DEV("alr_limited_backoff_enabled_ is true, prev_bitrate:%lld, result.target_bitrate:%lld",
prev_bitrate_.bps(),
result.target_bitrate.bps());
result.updated =
UpdateEstimate(at_time, prev_bitrate_, &result.target_bitrate);
result.backoff_in_alr = true;
}
} else if (acked_bitrate &&
rate_control_.TimeToReduceFurther(at_time, *acked_bitrate)) {
MS_DEBUG_DEV("acked_bitrate:%lld, result.target_bitrate:%lld",
acked_bitrate.value().bps(),
result.target_bitrate.bps());
result.updated =
UpdateEstimate(at_time, acked_bitrate, &result.target_bitrate);
} else if (!acked_bitrate && rate_control_.ValidEstimate() &&
......@@ -188,6 +197,7 @@ DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(
// rate by 50% every 200 ms.
// TODO(tschumim): Improve this and/or the acknowledged bitrate estimator
// so that we (almost) always have a bitrate estimate.
MS_DEBUG_DEV("reducing send rate by 50%% every 200 ms");
rate_control_.SetEstimate(rate_control_.LatestEstimate() / 2, at_time);
result.updated = true;
result.probe = false;
......@@ -195,6 +205,7 @@ DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(
}
} else {
if (probe_bitrate) {
MS_DEBUG_DEV("probe bitrate: %lld", probe_bitrate.value().bps());
result.probe = true;
result.updated = true;
result.target_bitrate = *probe_bitrate;
......@@ -210,11 +221,12 @@ DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(
detector_state != prev_state_) {
DataRate bitrate = result.updated ? result.target_bitrate : prev_bitrate_;
MS_DEBUG_DEV(
"[at_time:%lld, target_bitrate_bps:%lld, detector_state:%s]",
at_time.ms(), bitrate.bps(), BandwidthUsage2String(detector_state).c_str());
prev_bitrate_ = bitrate;
MS_DEBUG_DEV("setting prev_bitrate to: %lld, result.updated:%s",
prev_bitrate_.bps(),
result.updated ? "true" : "false");
prev_state_ = detector_state;
}
return result;
......
......@@ -29,7 +29,7 @@ namespace {
// Parameters for linear least squares fit of regression line to noisy data.
constexpr size_t kDefaultTrendlineWindowSize = 20;
constexpr double kDefaultTrendlineSmoothingCoeff = 0.9;
constexpr double kDefaultTrendlineSmoothingCoeff = 0.6;
constexpr double kDefaultTrendlineThresholdGain = 4.0;
const char kBweWindowSizeInPacketsExperiment[] =
"WebRTC-BweWindowSizeInPackets";
......@@ -77,7 +77,7 @@ absl::optional<double> LinearFitSlope(
}
constexpr double kMaxAdaptOffsetMs = 15.0;
constexpr double kOverUsingTimeThreshold = 10;
constexpr double kOverUsingTimeThreshold = 30;
constexpr int kMinNumDeltas = 60;
constexpr int kDeltaCounterMax = 1000;
......@@ -143,8 +143,12 @@ void TrendlineEstimator::Update(double recv_delta_ms,
accumulated_delay_ += delta_ms;
// BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", arrival_time_ms,
// accumulated_delay_);
smoothed_delay_ = smoothing_coef_ * smoothed_delay_ +
(1 - smoothing_coef_) * accumulated_delay_;
// smoothed_delay_ = smoothing_coef_ * smoothed_delay_ +
// (1 - smoothing_coef_) * accumulated_delay_;
// MS_NOTE: Apply WEMA to the current delta_ms. Don't consider the
// accumulated delay. Tests show it behaves more robustly upon delta peaks.
smoothed_delay_ = smoothing_coef_ * delta_ms +
(1 - smoothing_coef_) * smoothed_delay_;
// BWE_TEST_LOGGING_PLOT(1, "smoothed_delay_ms", arrival_time_ms,
// smoothed_delay_);
......@@ -166,8 +170,13 @@ void TrendlineEstimator::Update(double recv_delta_ms,
// BWE_TEST_LOGGING_PLOT(1, "trendline_slope", arrival_time_ms, trend);
MS_DEBUG_DEV("trend:%f, send_delta_ms:%f, recv_delta_ms:%f, delta_ms:%f arrival_time_ms:%" PRIi64 ", accumulated_delay_:%f, smoothed_delay_:%f", trend, send_delta_ms, recv_delta_ms, delta_ms, arrival_time_ms, accumulated_delay_, smoothed_delay_);
Detect(trend, send_delta_ms, arrival_time_ms);
}
else {
MS_DEBUG_DEV("no calculated deltas");
}
if (network_state_predictor_) {
hypothesis_predicted_ = network_state_predictor_->Update(
send_time_ms, arrival_time_ms, hypothesis_);
......@@ -203,6 +212,14 @@ void TrendlineEstimator::Detect(double trend, double ts_delta, int64_t now_ms) {
if (trend >= prev_trend_) {
time_over_using_ = 0;
overuse_counter_ = 0;
MS_DEBUG_DEV("hypothesis_: BandwidthUsage::kBwOverusing");
#if MS_LOG_DEV_LEVEL == 3
for (auto& kv : delay_hist_) {
MS_DEBUG_DEV("arrival_time_ms - first_arrival_time_ms_:%f, smoothed_delay_:%f", kv.first, kv.second);
}
#endif
hypothesis_ = BandwidthUsage::kBwOverusing;
}
}
......@@ -210,9 +227,11 @@ void TrendlineEstimator::Detect(double trend, double ts_delta, int64_t now_ms) {
time_over_using_ = -1;
overuse_counter_ = 0;
hypothesis_ = BandwidthUsage::kBwUnderusing;
MS_DEBUG_DEV("---- BandwidthUsage::kBwUnderusing ---");
} else {
time_over_using_ = -1;
overuse_counter_ = 0;
MS_DEBUG_DEV("---- BandwidthUsage::kBwNormal ---");
hypothesis_ = BandwidthUsage::kBwNormal;
}
prev_trend_ = trend;
......
......@@ -147,8 +147,15 @@ TransportFeedbackAdapter::ProcessTransportFeedback(
for (const PacketFeedback& rtp_feedback : feedback_vector) {
if (rtp_feedback.send_time_ms != PacketFeedback::kNoSendTime) {
auto feedback = NetworkPacketFeedbackFromRtpPacketFeedback(rtp_feedback);
MS_DEBUG_DEV("feedback received for RTP packet: [seq_num: %" PRIi64 ", send_time:%" PRIi64 ", size: %lld, feedback.receive_time:%" PRIi64,
feedback.sent_packet.sequence_number,
feedback.sent_packet.send_time.ms(),
feedback.sent_packet.size.bytes(),
feedback.receive_time.ms());
msg.packet_feedbacks.push_back(feedback);
} else if (rtp_feedback.arrival_time_ms == PacketFeedback::kNotReceived) {
MS_DEBUG_DEV("--- rtp_feedback.arrival_time_ms == PacketFeedback::kNotReceived ---");
msg.sendless_arrival_times.push_back(Timestamp::PlusInfinity());
} else {
msg.sendless_arrival_times.push_back(
......@@ -164,6 +171,8 @@ TransportFeedbackAdapter::ProcessTransportFeedback(
msg.feedback_time = feedback_receive_time;
msg.prior_in_flight = prior_in_flight;
msg.data_in_flight = GetOutstandingData();
MS_DEBUG_DEV("prior_in_flight:%lld, data_in_flight:%lld", msg.prior_in_flight.bytes(), msg.data_in_flight.bytes());
return msg;
}
......
......@@ -35,8 +35,8 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
int64_t arrival_time_ms,
int64_t system_time_ms,
size_t packet_size,
uint32_t* timestamp_delta,
int64_t* arrival_time_delta_ms,
uint32_t* timestamp_delta, // send_delta.
int64_t* arrival_time_delta_ms, // recv_delta.
int* packet_size_delta) {
MS_ASSERT(timestamp_delta != nullptr, "timestamp_delta is null");
MS_ASSERT(arrival_time_delta_ms != nullptr, "arrival_time_delta_ms is null");
......@@ -57,6 +57,9 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
current_timestamp_group_.timestamp - prev_timestamp_group_.timestamp;
*arrival_time_delta_ms = current_timestamp_group_.complete_time_ms -
prev_timestamp_group_.complete_time_ms;
MS_DEBUG_DEV("timestamp previous/current [%" PRIu32 "/%" PRIu32"] complete time previous/current [%" PRIi64 "/%" PRIi64 "]",
prev_timestamp_group_.timestamp, current_timestamp_group_.timestamp,
prev_timestamp_group_.complete_time_ms, current_timestamp_group_.complete_time_ms);
// Check system time differences to see if we have an unproportional jump
// in arrival time. In that case reset the inter-arrival computations.
int64_t system_time_delta_ms =
......@@ -98,6 +101,8 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
current_timestamp_group_.timestamp = timestamp;
current_timestamp_group_.first_arrival_ms = arrival_time_ms;
current_timestamp_group_.size = 0;
MS_DEBUG_DEV("new timestamp group: first_timestamp:%" PRIu32 ", first_arrival_ms:%" PRIi64,
current_timestamp_group_.first_timestamp, current_timestamp_group_.first_arrival_ms);
} else {
current_timestamp_group_.timestamp =
LatestTimestamp(current_timestamp_group_.timestamp, timestamp);
......
......@@ -8,10 +8,15 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#define MS_CLASS "webrtc::OveruseDetector"
// #define MS_LOG_DEV_LEVEL 3
#include "modules/remote_bitrate_estimator/overuse_detector.h"
#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "Logger.hpp"
#include <math.h>
#include <stdio.h>
#include <algorithm>
......@@ -102,6 +107,7 @@ BandwidthUsage OveruseDetector::Detect(double offset,
if (offset >= prev_offset_) {
time_over_using_ = 0;
overuse_counter_ = 0;
MS_DEBUG_DEV("hypothesis_: BandwidthUsage::kBwOverusing");
hypothesis_ = BandwidthUsage::kBwOverusing;
}
}
......
......@@ -7,8 +7,7 @@
/* Static. */
// TODO: Look for a proper value.
static const char FieldTrials[]{ "WebRTC-Pacer-MinPacketLimitMs/Enabled,100/" };
static constexpr char FieldTrials[] = "WebRTC-Bwe-AlrLimitedBackoff/Enabled/";
/* Static methods. */
......
......@@ -2013,8 +2013,15 @@ namespace RTC
auto* remb = static_cast<RTC::RTCP::FeedbackPsRembPacket*>(afb);
// Pass it to the TCC client.
if (this->tccClient)
// clang-format off
if (
this->tccClient &&
this->tccClient->GetBweType() == RTC::BweType::REMB
)
// clang-format on
{
this->tccClient->ReceiveEstimatedBitrate(remb->GetBitrate());
}
break;
}
......
......@@ -178,21 +178,20 @@ namespace RTC
this->bitrates.desiredBitrate = desiredBitrate;
this->bitrates.effectiveDesiredBitrate = this->desiredBitrateTrend.GetValue();
this->bitrates.minBitrate = MinBitrate;
// NOTE: Setting 'startBitrate' to 'availableBitrate' has proven to generate
// more stable values.
this->bitrates.startBitrate = std::max<uint32_t>(MinBitrate, this->bitrates.availableBitrate);
if (this->desiredBitrateTrend.GetValue() > 0u)
{
this->bitrates.maxBitrate = std::max<uint32_t>(
this->initialAvailableBitrate,
this->desiredBitrateTrend.GetValue() * MaxBitrateIncrementFactor);
this->bitrates.startBitrate = std::min<uint32_t>(
this->bitrates.maxBitrate,
std::max<uint32_t>(this->bitrates.availableBitrate, this->initialAvailableBitrate));
this->bitrates.maxPaddingBitrate = this->bitrates.maxBitrate * MaxPaddingBitrateFactor;
}
else
{
this->bitrates.maxBitrate = this->initialAvailableBitrate;
this->bitrates.startBitrate = this->initialAvailableBitrate;
this->bitrates.maxPaddingBitrate = 0u;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论