Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport changes to congestion control from libwebrtc #922

Draft
wants to merge 81 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fa10437
Initial commit, backport main component.
Oct 10, 2022
44088eb
Initial commit, backport main component.
Oct 10, 2022
f01bd51
First failed attempt to backport Pacer, save to preserve.
Nov 14, 2022
fe738e3
Revert "First failed attempt to backport Pacer, save to preserve."
Nov 14, 2022
a43e06e
Enable Loss v2
Nov 14, 2022
60a446b
Merge branch 'v3' into bwe_backport
sarumjanuch Nov 16, 2022
f498894
Sync with latest Loss v2 changes.
Nov 17, 2022
f5ec63d
Merge remote-tracking branch 'origin/bwe_backport' into bwe_backport
Nov 17, 2022
676b92e
Sync with latest Loss v2 changes. Fix Periodic ALR when we suddenly h…
Nov 22, 2022
011731b
Revert "Sync with latest Loss v2 changes. Fix Periodic ALR when we su…
Nov 24, 2022
c8c6944
Revert "Sync with latest Loss v2 changes."
Nov 24, 2022
45b5d5c
Fix instant loss calculation when sending at high bitrates.
Nov 24, 2022
a468c21
Fix issue when no periodic ALR probing when sudden drop in BW, and th…
Nov 24, 2022
6e6f640
Increase InstantUpperBoundLossOffset slightly, because we don't have …
Nov 24, 2022
2dc6ad7
Increase InstantUpperBoundLossOffset slightly, because we don't have …
Nov 24, 2022
e7ee174
Increase InstantUpperBoundLossOffset. Fix issue when cc colpases and …
Nov 28, 2022
ad21541
Merge branch 'v3' into bwe_backport
Nov 28, 2022
e4b7bf8
clean
Nov 28, 2022
1647d07
Add BW balance multiplication to have a meaningful backoff.
Nov 30, 2022
07bea0f
Fix BW balance calculation. Adjust loss settings.
Nov 30, 2022
f613ad2
Revert to default coefficients
Nov 30, 2022
4c0202f
Apply suggestions from code review
ibc Dec 1, 2022
c4b007c
Fix default coefficients
Dec 1, 2022
2c4994f
Use sending rate instead of estimate in BW balance calculation, when …
Dec 2, 2022
036b9fd
Merge remote-tracking branch 'origin/v3' into bwe_backport
Dec 2, 2022
e545675
Update default libwebrtc fieldTrial string.
Dec 2, 2022
c5bfc17
format
Dec 2, 2022
b9a1161
Fix testing change.
Dec 2, 2022
0d99863
`Backport changes from aimd rate control, plus minor fixes.
Dec 2, 2022
619361a
`Backport changes from aimd rate control, plus minor fixes.
Dec 2, 2022
252d568
Fix log
Dec 5, 2022
0c7eef0
Backport latest changes from libwebrtc.
Dec 5, 2022
66deb26
Backport latest changes from libwebrtc.
Dec 5, 2022
23a3204
Backport latest changes from libwebrtc.
Dec 5, 2022
beb4d1d
Backport more changes. Rework trend-line estimator to produce R-squar…
Dec 7, 2022
e001c75
Adjust settings in delay bwe, add debounce in loss estimator with bac…
Dec 8, 2022
b988f54
Debounce instant loss, adjust default filed trial string
Dec 13, 2022
64c00cb
try fix maxlen
Dec 13, 2022
18f012c
Merge remote-tracking branch 'origin/v3' into bwe_backport
Dec 13, 2022
71f9459
Try update to C++14
Dec 13, 2022
9a61385
Fix Lint for long field trial string
Dec 13, 2022
a71c289
Add EventEmitter migrate to c++14
Dec 13, 2022
86a423f
Fix maxlen for fieldtrial string commnet
Dec 13, 2022
af18922
Merge remote-tracking branch 'origin/bwe_backport' into bwe_backport
Dec 13, 2022
965a5c1
Fix maxlen for field trial string comment
Dec 13, 2022
42f1bda
Merge remote-tracking branch 'origin/bwe_backport' into bwe_backport
Dec 13, 2022
96ddaa4
Fix maxlen for field trial string comment
Dec 13, 2022
b2daa7f
Fix EventEmitter
Dec 13, 2022
db290fc
Merge remote-tracking branch 'origin/c++14_EventEmitter' into c++14_E…
Dec 13, 2022
064d26e
Merge branch 'c++14_EventEmitter' into bwe_backport
Dec 13, 2022
e76b9fd
Remove old event emitter
Dec 13, 2022
e261944
test c++17
Dec 14, 2022
becaef1
remain c++14
Dec 14, 2022
4b86b18
Revert to remain on C++ 11.
Dec 19, 2022
e1333f8
Cosmetic constants.
Dec 19, 2022
6aa0b03
Add comment that explains what we are doing with R^2
Dec 19, 2022
09a4b4c
Get rid of EventEmitter.
Dec 19, 2022
47657fb
More C++ 14 cleanup.
Dec 19, 2022
fc46a65
Backport most recent libwebrtc changes, also fix some issues iwth cac…
Dec 23, 2022
a040b27
fix std -> absl
Dec 23, 2022
9f4093c
Be more resilient to bursts fixes here and there.
Dec 26, 2022
91b6923
Be more resilient to bursts fixes here and there.
Dec 26, 2022
a61ea7d
Reduce trendline window size to faster react to changes, push only va…
Jan 2, 2023
97d61ce
Adjust coefficients, enable robust estimator as acknowledged estimato…
Jan 2, 2023
4c0e7e1
Adjust coefficients more
Jan 2, 2023
ec9be0d
Refactor instant loss debounce mechanism. Add overuse counter for R s…
Jan 5, 2023
a175c36
Adjust coefficients, create separate counter for R squared overuse
Jan 9, 2023
ff76084
Adjust coefficients
Jan 9, 2023
3c2ff4b
Merge remote-tracking branch 'origin/v3' into bwe_backport
Jan 9, 2023
545a910
Limit probation rate by loss estimate rate, and don't probe when dela…
Jan 9, 2023
2594fd7
return smooth coefficient to 0.9, increase upper bound of R squared l…
Jan 10, 2023
4081d00
Pass inner estimators states to mediasoup land.
Jan 10, 2023
eef19db
format
Jan 10, 2023
eac1e6f
Add probe bitrate estimator to stats.
Jan 10, 2023
05cfade
Pass stats to nodejs land via trace event bweStats
Jan 11, 2023
f5acf13
Refactor. Add missing fields.
Jan 11, 2023
81f724d
Add typing for bweStats info, add sending rate field.
Jan 11, 2023
edb3af6
Add dot in the end of comment.
Jan 11, 2023
8c12a70
Make linter happy
Jan 11, 2023
16f67a8
Fixes here and there, try to recover bitrate when recovered from inst…
Jan 24, 2023
148a20b
Merge branch 'v3' into bwe_backport
ibc Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions node/src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,40 @@ export type TransportTuple =
/**
* Valid types for 'trace' event.
*/
export type TransportTraceEventType = 'probation' | 'bwe';
export type TransportTraceEventType = 'probation' | 'bwe' | 'bweStats';

/**
* bweStats typings for trace event.
*/
export type TransportTraceEventBweStatsInfo = {
estimatedBitrate: number;
delay: {
slope: number;
rSquared: number;
threshold: number;
rtt: number;
rateControlState: number;
delayDetectorState: number;
};
probe: {
estimatedBitrate: number;
};
loss: {
inherent: number;
avg: number;
estimatedBitrate: number;
sendingRate: number;
};
alr: boolean;
ackBitrate: number;
desiredBitrate: number;
effectiveDesiredBitrate: number;
minBitrate: number;
maxBitrate: number;
startBitrate: number;
maxPaddingBitrate: number;
sendingRate: number;
};

/**
* 'trace' event data.
Expand All @@ -81,7 +114,7 @@ export type TransportTraceEventData =
/**
* Per type information.
*/
info: any;
info: TransportTraceEventBweStatsInfo | any;
};

export type SctpState = 'new' | 'connecting' | 'connected' | 'failed' | 'closed';
Expand Down
5 changes: 3 additions & 2 deletions node/src/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ export type WorkerSettings =
* certificate is dynamically created.
*/
dtlsPrivateKeyFile?: string;

/* eslint-disable max-len */
ibc marked this conversation as resolved.
Show resolved Hide resolved
/**
* Field trials for libwebrtc.
* @private
*
* NOTE: For advanced users only. An invalid value will make the worker crash.
* Default value is
* "WebRTC-Bwe-AlrLimitedBackoff/Enabled/".
* "WebRTC-Bwe-AlrLimitedBackoff/Enabled/WebRTC-Bwe-LossBasedBweV2/BwRampupUpperBoundFactor:1.1,TrendlineIntegrationEnabled:true/WebRTC-Bwe-RobustThroughputEstimatorSettings/enabled/"
*/
libwebrtcFieldTrials?: string;
/* eslint-enable max-len */

/**
* Custom application data.
Expand Down
2 changes: 1 addition & 1 deletion rust/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub struct WorkerSettings {
///
/// NOTE: For advanced users only. An invalid value will make the worker crash.
/// Default value is
/// "WebRTC-Bwe-AlrLimitedBackoff/Enabled/".
/// "WebRTC-Bwe-AlrLimitedBackoff/Enabled/WebRTC-Bwe-LossBasedBweV2/BwRampupUpperBoundFactor:1.1,TrendlineIntegrationEnabled:true/WebRTC-Bwe-RobustThroughputEstimatorSettings/enabled/"
#[doc(hidden)]
pub libwebrtc_field_trials: Option<String>,
/// Function that will be called under worker thread before worker starts, can be used for
Expand Down
2 changes: 0 additions & 2 deletions worker/deps/libwebrtc/libwebrtc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
'libwebrtc/modules/congestion_controller/goog_cc/link_capacity_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc',
'libwebrtc/modules/congestion_controller/goog_cc/probe_controller.cc',
'libwebrtc/modules/congestion_controller/goog_cc/median_slope_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/bitrate_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/trendline_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/delay_based_bwe.cc',
Expand Down Expand Up @@ -110,7 +109,6 @@
'libwebrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h',
'libwebrtc/modules/congestion_controller/goog_cc/bitrate_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/link_capacity_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/median_slope_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/probe_controller.h',
'libwebrtc/modules/congestion_controller/goog_cc/trendline_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.h',
Expand Down
18 changes: 17 additions & 1 deletion worker/deps/libwebrtc/libwebrtc/api/transport/network_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class TargetTransferRateObserver {
virtual void OnStartRateUpdate(DataRate) {}
};

class BweStatsTracer {
public:
virtual ~BweStatsTracer() = default;
virtual void OnBweStats(BweStats) = 0;
};


// Configuration sent to factory create function. The parameters here are
// optional to use for a network controller implementation.
struct NetworkControllerConfig {
Expand Down Expand Up @@ -72,7 +79,11 @@ class NetworkControllerInterface {
// Called round trip time has been calculated by protocol specific mechanisms.
virtual NetworkControlUpdate OnRoundTripTimeUpdate(RoundTripTimeUpdate) = 0;
// Called when a packet is sent on the network.
virtual NetworkControlUpdate OnSentPacket(SentPacket) = 0;
virtual NetworkControlUpdate OnSentPacket(
SentPacket) = 0;
// Called when a packet is received from the remote client.
virtual NetworkControlUpdate OnReceivedPacket(
ReceivedPacket) = 0;
// Called when the stream specific configuration has been updated.
virtual NetworkControlUpdate OnStreamsConfig(StreamsConfig) = 0;
// Called when target transfer rate constraints has been changed.
Expand All @@ -85,6 +96,7 @@ class NetworkControllerInterface {
TransportPacketsFeedback) = 0;
// Called with network state estimate updates.
virtual NetworkControlUpdate OnNetworkStateEstimate(NetworkStateEstimate) = 0;
virtual BweStats GetBweStats() = 0;
};

// NetworkControllerFactoryInterface is an interface for creating a network
Expand All @@ -108,7 +120,11 @@ class NetworkStateEstimator {
// Gets the current best estimate according to the estimator.
virtual absl::optional<NetworkStateEstimate> GetCurrentEstimate() = 0;
// Called with per packet feedback regarding receive time.
// Used when the NetworkStateEstimator runs in the sending endpoint.
virtual void OnTransportPacketsFeedback(const TransportPacketsFeedback&) = 0;
// Called with per packet feedback regarding receive time.
// Used when the NetworkStateEstimator runs in the receiving endpoint.
virtual void OnReceivedPacket(const PacketResult&) {}
// Called when the receiving or sending endpoint changes address.
virtual void OnRouteChange(const NetworkRouteChange&) = 0;
virtual ~NetworkStateEstimator() = default;
Expand Down
13 changes: 8 additions & 5 deletions worker/deps/libwebrtc/libwebrtc/api/transport/network_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
#include <algorithm>

namespace webrtc {
// TODO(srte): Revert to using default after removing union member.
StreamsConfig::StreamsConfig() {}
StreamsConfig::StreamsConfig() = default;
StreamsConfig::StreamsConfig(const StreamsConfig&) = default;
StreamsConfig::~StreamsConfig() = default;

BweStats::BweStats() = default;
BweStats::BweStats(const BweStats&) = default;
BweStats::~BweStats() = default;

TargetRateConstraints::TargetRateConstraints() = default;
TargetRateConstraints::TargetRateConstraints(const TargetRateConstraints&) =
default;
Expand Down Expand Up @@ -49,7 +52,7 @@ std::vector<PacketResult> TransportPacketsFeedback::ReceivedWithSendInfo()
const {
std::vector<PacketResult> res;
for (const PacketResult& fb : packet_feedbacks) {
if (fb.receive_time.IsFinite()) {
if (fb.IsReceived()) {
res.push_back(fb);
}
}
Expand All @@ -59,7 +62,7 @@ std::vector<PacketResult> TransportPacketsFeedback::ReceivedWithSendInfo()
std::vector<PacketResult> TransportPacketsFeedback::LostWithSendInfo() const {
std::vector<PacketResult> res;
for (const PacketResult& fb : packet_feedbacks) {
if (fb.receive_time.IsPlusInfinity()) {
if (!fb.IsReceived()) {
res.push_back(fb);
}
}
Expand All @@ -75,7 +78,7 @@ std::vector<PacketResult> TransportPacketsFeedback::SortedByReceiveTime()
const {
std::vector<PacketResult> res;
for (const PacketResult& fb : packet_feedbacks) {
if (fb.receive_time.IsFinite()) {
if (fb.IsReceived()) {
res.push_back(fb);
}
}
Expand Down
64 changes: 61 additions & 3 deletions worker/deps/libwebrtc/libwebrtc/api/transport/network_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "api/units/data_size.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
#include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h"
#include "modules/remote_bitrate_estimator/include/bwe_defines.h"

#include <absl/types/optional.h>
#include <stdint.h>
Expand All @@ -24,6 +26,50 @@ namespace webrtc {

// Configuration

// Represents constraints and rates related to the currently enabled streams.
// This is used as input to the congestion controller via the StreamsConfig
// struct.
struct BitrateAllocationLimits {
// The total minimum send bitrate required by all sending streams.
DataRate min_allocatable_rate = DataRate::Zero();
// The total maximum allocatable bitrate for all currently available streams.
DataRate max_allocatable_rate = DataRate::Zero();
// The max bitrate to use for padding. The sum of the per-stream max padding
// rate.
DataRate max_padding_rate = DataRate::Zero();
};

struct LossEstimatorState {
~LossEstimatorState() = default;
absl::optional<DataRate> bandwidth_estimate = DataRate::Zero();
double inherent_loss;
double avg_loss;
absl::optional<DataRate> sending_rate = DataRate::Zero();
};

struct DelayBasedBweState {
RateControlState rate_control_state;
DelayIncreaseDetectorInterface::RegressionResult trend;
BandwidthUsage delay_detector_state;
double threshold;
};

struct BweStats {
BweStats();
BweStats(const BweStats&);
~BweStats();
Timestamp time = Timestamp::PlusInfinity();
absl::optional<DataRate> estimated_bitrate;
absl::optional<DataRate> acknowledged_bitrate;
DelayBasedBweState delay;
TimeDelta rtt = TimeDelta::ms(0);
bool in_alr = false;
LossEstimatorState loss_estimator_state;
absl::optional<DataRate> probe_bitrate;
};



// Use StreamsConfig for information about streams that is required for specific
// adjustments to the algorithms in network controllers. Especially useful
// for experiments.
Expand All @@ -34,9 +80,9 @@ struct StreamsConfig {
Timestamp at_time = Timestamp::PlusInfinity();
absl::optional<bool> requests_alr_probing;
absl::optional<double> pacing_factor;
union {
absl::optional<DataRate> min_total_allocated_bitrate = absl::nullopt;
};

// TODO: (srte) Use BitrateAllocationLimits here.
absl::optional<DataRate> min_total_allocated_bitrate;
absl::optional<DataRate> max_padding_rate;
absl::optional<DataRate> max_total_allocated_bitrate;
};
Expand Down Expand Up @@ -84,13 +130,20 @@ struct PacedPacketInfo {
int probe_cluster_id = kNotAProbe;
int probe_cluster_min_probes = -1;
int probe_cluster_min_bytes = -1;
int probe_cluster_bytes_sent = 0;
};

struct SentPacket {
Timestamp send_time = Timestamp::PlusInfinity();
// Size of packet with overhead up to IP layer.
DataSize size = DataSize::Zero();
// Size of preceeding packets that are not part of feedback.
DataSize prior_unacked_data = DataSize::Zero();
// Probe cluster id and parameters including bitrate, number of packets and
// number of bytes.
PacedPacketInfo pacing_info;
// True if the packet is an audio packet, false for video, padding, RTX etc.
bool audio = false;
// Transport independent sequence number, any tracked packet should have a
// sequence number that is unique over the whole call and increasing by 1 for
// each packet.
Expand Down Expand Up @@ -138,6 +191,8 @@ struct PacketResult {
PacketResult(const PacketResult&);
~PacketResult();

inline bool IsReceived() const { return !receive_time.IsPlusInfinity(); }

SentPacket sent_packet;
Timestamp receive_time = Timestamp::PlusInfinity();
};
Expand Down Expand Up @@ -166,6 +221,7 @@ struct TransportPacketsFeedback {

struct NetworkEstimate {
Timestamp at_time = Timestamp::PlusInfinity();
// Deprecated, use TargetTransferRate::target_rate instead.
DataRate bandwidth = DataRate::Infinity();
TimeDelta round_trip_time = TimeDelta::PlusInfinity();
TimeDelta bwe_period = TimeDelta::PlusInfinity();
Expand Down Expand Up @@ -199,6 +255,8 @@ struct TargetTransferRate {
// The estimate on which the target rate is based on.
NetworkEstimate network_estimate;
DataRate target_rate = DataRate::Zero();
DataRate stable_target_rate = DataRate::Zero();
double cwnd_reduce_ratio = 0;
};

// Contains updates of network controller comand state. Using optionals to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ RtpTransportControllerSend::RtpTransportControllerSend(
: packet_router_(packet_router),
pacer_(packet_router_),
observer_(nullptr),
stats_tracer_(nullptr),
controller_factory_override_(controller_factory),
process_interval_(controller_factory_override_->GetProcessInterval()),
last_report_block_time_(Timestamp::ms(DepLibUV::GetTimeMsInt64())),
Expand Down Expand Up @@ -143,6 +144,12 @@ void RtpTransportControllerSend::RegisterTargetTransferRateObserver(
MaybeCreateControllers();
}

void RtpTransportControllerSend::RegisterBweStatsTracer(webrtc::BweStatsTracer* tracer) {
MS_ASSERT(stats_tracer_ == nullptr, "stats_tracer already set");

stats_tracer_ = tracer;
}

void RtpTransportControllerSend::OnNetworkAvailability(bool network_available) {
MS_DEBUG_DEV("<<<<< network_available:%s", network_available ? "true" : "false");

Expand Down Expand Up @@ -242,6 +249,7 @@ void RtpTransportControllerSend::OnTransportFeedback(
PostUpdates(controller_->OnTransportPacketsFeedback(*feedback_msg));
pacer_.UpdateOutstandingData(
transport_feedback_adapter_.GetOutstandingData().bytes());
stats_tracer_->OnBweStats(controller_->GetBweStats());
}

void RtpTransportControllerSend::OnRemoteNetworkEstimate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class RtpTransportControllerSend final
void SetPacingFactor(float pacing_factor) override;
void RegisterTargetTransferRateObserver(
TargetTransferRateObserver* observer) override;
void RegisterBweStatsTracer(
BweStatsTracer* tracer) override;
void OnNetworkAvailability(bool network_available) override;
RtcpBandwidthObserver* GetBandwidthObserver() override;
void EnablePeriodicAlrProbing(bool enable) override;
Expand Down Expand Up @@ -102,6 +104,8 @@ class RtpTransportControllerSend final

TargetTransferRateObserver* observer_;

BweStatsTracer* stats_tracer_;

NetworkControllerFactoryInterface* const controller_factory_override_;

TransportFeedbackAdapter transport_feedback_adapter_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct NetworkRoute;
namespace webrtc {

class TargetTransferRateObserver;
class BweStatsTracer;
class Transport;
class PacedSender;
class PacketFeedbackObserver;
Expand Down Expand Up @@ -99,6 +100,8 @@ class RtpTransportControllerSendInterface {
// PacketFeedbackObserver* observer) = 0;
virtual void RegisterTargetTransferRateObserver(
TargetTransferRateObserver* observer) = 0;
virtual void RegisterBweStatsTracer(
BweStatsTracer* tracer) = 0;
virtual void OnNetworkAvailability(bool network_available) = 0;
virtual RtcpBandwidthObserver* GetBandwidthObserver() = 0;
virtual void EnablePeriodicAlrProbing(bool enable) = 0;
Expand Down
Loading