[feat] move rtp packet sender out of channel module

This commit is contained in:
dijunkun
2025-03-13 21:11:20 +08:00
parent 23df1f3b60
commit d2b45b91e7
32 changed files with 681 additions and 266 deletions

View File

@@ -26,23 +26,30 @@ BandwidthLimitedCause GetBandwidthLimitedCause(LossBasedState loss_based_state,
BandwidthUsage bandwidth_usage) {
if (bandwidth_usage == BandwidthUsage::kBwOverusing ||
bandwidth_usage == BandwidthUsage::kBwUnderusing) {
LOG_ERROR("kDelayBasedLimitedDelayIncreased");
return BandwidthLimitedCause::kDelayBasedLimitedDelayIncreased;
} else if (is_rtt_above_limit) {
LOG_ERROR("kDelayBasedLimitedDelayIncreased");
return BandwidthLimitedCause::kRttBasedBackOffHighRtt;
}
switch (loss_based_state) {
case LossBasedState::kDecreasing:
// Probes may not be sent in this state.
LOG_ERROR("kLossLimitedBwe");
return BandwidthLimitedCause::kLossLimitedBwe;
case webrtc::LossBasedState::kIncreaseUsingPadding:
// Probes may not be sent in this state.
LOG_ERROR("kLossLimitedBwe");
return BandwidthLimitedCause::kLossLimitedBwe;
case LossBasedState::kIncreasing:
LOG_ERROR("kLossLimitedBweIncreasing");
// Probes may be sent in this state.
return BandwidthLimitedCause::kLossLimitedBweIncreasing;
case LossBasedState::kDelayBasedEstimate:
// LOG_ERROR("kDelayBasedLimited");
return BandwidthLimitedCause::kDelayBasedLimited;
default:
LOG_ERROR("kLossLimitedBwe");
return BandwidthLimitedCause::kLossLimitedBwe;
}
}
@@ -87,6 +94,13 @@ CongestionControl::CongestionControl()
CongestionControl::~CongestionControl() {}
NetworkControlUpdate CongestionControl::OnNetworkAvailability(
NetworkAvailability msg) {
NetworkControlUpdate update;
update.probe_cluster_configs = probe_controller_->OnNetworkAvailability(msg);
return update;
}
NetworkControlUpdate CongestionControl::OnProcessInterval(ProcessInterval msg) {
NetworkControlUpdate update;
if (initial_config_) {
@@ -122,7 +136,6 @@ NetworkControlUpdate CongestionControl::OnProcessInterval(ProcessInterval msg) {
auto probes = probe_controller_->Process(msg.at_time);
update.probe_cluster_configs.insert(update.probe_cluster_configs.end(),
probes.begin(), probes.end());
update.congestion_window = current_data_window_;
MaybeTriggerOnNetworkChanged(&update, msg.at_time);
@@ -407,8 +420,10 @@ void CongestionControl::MaybeTriggerOnNetworkChanged(
update->probe_cluster_configs.insert(update->probe_cluster_configs.end(),
probes.begin(), probes.end());
update->pacer_config = GetPacingRates(at_time);
// LOG_INFO("bwe {} pushback_target_bps={} estimate_bps={}", at_time.ms(),
// last_pushback_target_rate_.bps(), loss_based_target_rate.bps());
// LOG_INFO("bwe {} pushback_target_bps={} estimate_bps={}",
// at_time.ms(),
// last_pushback_target_rate_.bps(),
// loss_based_target_rate.bps());
}
}

View File

@@ -23,6 +23,8 @@ class CongestionControl {
~CongestionControl();
public:
NetworkControlUpdate OnNetworkAvailability(NetworkAvailability msg);
NetworkControlUpdate OnProcessInterval(ProcessInterval msg);
NetworkControlUpdate OnTransportLossReport(TransportLossReport msg);

View File

@@ -397,6 +397,8 @@ void PacingController::ProcessPackets() {
if (now + early_execute_margin < target_send_time) {
// We are too early, but if queue is empty still allow draining some debt.
// Probing is allowed to be sent up to kMinSleepTime early.
LOG_ERROR("!!!!!!! too early, target_send_time {}, now {}, {}",
target_send_time.ms(), now.ms(), early_execute_margin.ms());
UpdateBudgetWithElapsedTime(UpdateTimeAndGetElapsed(now));
return;
}
@@ -664,8 +666,8 @@ void PacingController::MaybeUpdateMediaRateDueToLongQueue(Timestamp now) {
DataRate min_rate_needed = queue_size_data / avg_time_left;
if (min_rate_needed > pacing_rate_) {
adjusted_media_rate_ = min_rate_needed;
LOG_INFO("bwe:large_pacing_queue pacing_rate_kbps={}",
pacing_rate_.kbps());
// LOG_INFO("bwe:large_pacing_queue pacing_rate_kbps={}",
// pacing_rate_.kbps());
}
}
}

View File

@@ -108,6 +108,7 @@ std::vector<ProbeClusterConfig> ProbeController::SetBitrates(
if (start_bitrate > DataRate::Zero()) {
start_bitrate_ = start_bitrate;
estimated_bitrate_ = start_bitrate;
LOG_WARN("1 setting estimated_bitrate_ = {}", estimated_bitrate_.bps());
} else if (start_bitrate_.IsZero()) {
start_bitrate_ = min_bitrate;
}
@@ -117,10 +118,11 @@ std::vector<ProbeClusterConfig> ProbeController::SetBitrates(
DataRate old_max_bitrate = max_bitrate_;
max_bitrate_ =
max_bitrate.IsFinite() ? max_bitrate : kDefaultMaxProbingBitrate;
switch (state_) {
case State::kInit:
if (network_available_) return InitiateExponentialProbing(at_time);
if (network_available_) {
return InitiateExponentialProbing(at_time);
}
break;
case State::kWaitingForProbingResult:
@@ -131,6 +133,7 @@ std::vector<ProbeClusterConfig> ProbeController::SetBitrates(
// estimate then initiate probing.
if (!estimated_bitrate_.IsZero() && old_max_bitrate < max_bitrate_ &&
estimated_bitrate_ < max_bitrate_) {
LOG_WARN("probing complete");
return InitiateProbing(at_time, {max_bitrate_}, false);
}
break;
@@ -150,8 +153,9 @@ std::vector<ProbeClusterConfig> ProbeController::OnMaxTotalAllocatedBitrate(
allow_allocation_probe) {
max_total_allocated_bitrate_ = max_total_allocated_bitrate;
if (!config_.first_allocation_probe_scale)
if (!config_.first_allocation_probe_scale) {
return std::vector<ProbeClusterConfig>();
}
DataRate first_probe_rate =
max_total_allocated_bitrate * config_.first_allocation_probe_scale;
@@ -174,7 +178,7 @@ std::vector<ProbeClusterConfig> ProbeController::OnMaxTotalAllocatedBitrate(
probes.push_back(second_probe_rate);
}
bool allow_further_probing = limited_by_current_bwe;
LOG_WARN("allow_further_probing {}", allow_further_probing);
return InitiateProbing(at_time, probes, allow_further_probing);
}
if (!max_total_allocated_bitrate.IsZero()) {
@@ -228,12 +232,10 @@ std::vector<ProbeClusterConfig> ProbeController::InitiateExponentialProbing(
max_total_allocated_bitrate_.IsZero()) {
last_allowed_repeated_initial_probe_ =
at_time + config_.repeated_initial_probing_time_period;
// LOG_INFO("Repeated initial probing enabled, last allowed probe: {} now:
// {}",
// ToString(last_allowed_repeated_initial_probe_),
// ToString(at_time));
LOG_INFO("Repeated initial probing enabled, last allowed probe: {} now: {}",
last_allowed_repeated_initial_probe_.ms(), at_time.ms());
}
LOG_WARN("InitiateExponentialProbing");
return InitiateProbing(at_time, probes, true);
}
@@ -246,7 +248,6 @@ std::vector<ProbeClusterConfig> ProbeController::SetEstimatedBitrate(
bitrate_before_last_large_drop_ = estimated_bitrate_;
}
estimated_bitrate_ = bitrate;
if (state_ == State::kWaitingForProbingResult) {
// Continue probing if probing results indicate channel has greater
// capacity unless we already reached the needed bitrate.
@@ -264,13 +265,14 @@ std::vector<ProbeClusterConfig> ProbeController::SetEstimatedBitrate(
? network_estimate_->link_capacity_upper *
config_.further_probe_threshold
: DataRate::PlusInfinity();
// LOG_INFO(
// "Measured bitrate: {} Minimum to probe further: {} upper limit: {}",
// bitrate, ToString(min_bitrate_to_probe_further_),
// ToString(network_state_estimate_probe_further_limit));
LOG_INFO(
"Measured bitrate: {} Minimum to probe further: {} upper limit: {}",
bitrate.bps(), min_bitrate_to_probe_further_.bps(),
network_state_estimate_probe_further_limit.bps());
if (bitrate > min_bitrate_to_probe_further_ &&
bitrate <= network_state_estimate_probe_further_limit) {
LOG_WARN("InitiateProbing SetEstimatedBitrate");
return InitiateProbing(
at_time, {config_.further_exponential_probe_scale * bitrate}, true);
}
@@ -323,6 +325,7 @@ std::vector<ProbeClusterConfig> ProbeController::RequestProbe(
time_since_probe > kMinTimeBetweenAlrProbes) {
LOG_INFO("Detected big bandwidth drop, start probing");
last_bwe_drop_probing_time_ = at_time;
LOG_WARN("InitiateProbing RequestProbe");
return InitiateProbing(at_time, {suggested_probe}, false);
}
}
@@ -341,6 +344,7 @@ void ProbeController::Reset(Timestamp at_time) {
min_bitrate_to_probe_further_ = DataRate::PlusInfinity();
time_last_probing_initiated_ = Timestamp::Zero();
estimated_bitrate_ = DataRate::Zero();
LOG_WARN("3 setting estimated_bitrate_ = {}", estimated_bitrate_.bps());
network_estimate_ = std::nullopt;
start_bitrate_ = DataRate::Zero();
max_bitrate_ = kDefaultMaxProbingBitrate;
@@ -413,15 +417,21 @@ std::vector<ProbeClusterConfig> ProbeController::Process(Timestamp at_time) {
UpdateState(State::kProbingComplete);
}
}
if (estimated_bitrate_.IsZero() || state_ != State::kProbingComplete) {
return {};
}
if (TimeForNextRepeatedInitialProbe(at_time)) {
LOG_WARN(
"InitiateProbing TimeForNextRepeatedInitialProbe, estimated_bitrate_ = "
"{}",
estimated_bitrate_.bps());
return InitiateProbing(
at_time, {estimated_bitrate_ * config_.first_exponential_probe_scale},
true);
}
if (TimeForAlrProbe(at_time) || TimeForNetworkStateProbe(at_time)) {
LOG_WARN("InitiateProbing TimeForNetworkStateProbe");
return InitiateProbing(
at_time, {estimated_bitrate_ * config_.alr_probe_scale}, true);
}
@@ -505,7 +515,6 @@ std::vector<ProbeClusterConfig> ProbeController::InitiateProbing(
if (config_.network_state_estimate_probing_interval.IsFinite() &&
network_estimate_ && network_estimate_->link_capacity_upper.IsFinite()) {
if (network_estimate_->link_capacity_upper.IsZero()) {
LOG_INFO("Not sending probe, Network state estimate is zero");
return {};
}
max_probe_bitrate = std::min(
@@ -522,6 +531,7 @@ std::vector<ProbeClusterConfig> ProbeController::InitiateProbing(
}
pending_probes.push_back(CreateProbeClusterConfig(now, bitrate));
}
LOG_ERROR("2 pending probes size {}", pending_probes.size());
time_last_probing_initiated_ = now;
if (probe_further) {
UpdateState(State::kWaitingForProbingResult);

View File

@@ -163,6 +163,7 @@ SendSideBandwidthEstimation::SendSideBandwidthEstimation()
low_loss_threshold_(kDefaultLowLossThreshold),
high_loss_threshold_(kDefaultHighLossThreshold),
bitrate_threshold_(kDefaultBitrateThreshold),
loss_based_state_(LossBasedState::kDelayBasedEstimate),
disable_receiver_limit_caps_only_(false) {
// rtt_backoff_ =
}
@@ -407,7 +408,7 @@ void SendSideBandwidthEstimation::UpdateEstimate(Timestamp at_time) {
// it would take over one second since the lower packet loss to achieve
// 108kbps.
DataRate new_bitrate = DataRate::BitsPerSec(
min_bitrate_history_.front().second.bps() * 1.5 + 0.5);
min_bitrate_history_.front().second.bps() * 1.08 + 0.5);
// Add 1 kbps extra, just to make sure that we do not get stuck
// (gives a little extra increase at low rates, negligible at higher