mediasoup 3.27.0 → 3.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/node/lib/Consumer.d.ts.map +1 -1
- package/node/lib/Consumer.js +4 -51
- package/node/lib/Producer.d.ts.map +1 -1
- package/node/lib/Producer.js +4 -8
- package/node/lib/ProducerTypes.d.ts +4 -2
- package/node/lib/ProducerTypes.d.ts.map +1 -1
- package/node/lib/Router.d.ts.map +1 -1
- package/node/lib/Router.js +4 -0
- package/node/lib/Transport.d.ts.map +1 -1
- package/node/lib/Transport.js +7 -10
- package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts +3 -4
- package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts.map +1 -1
- package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.js +3 -4
- package/node/lib/ortc.d.ts +0 -2
- package/node/lib/ortc.d.ts.map +1 -1
- package/node/lib/ortc.js +11 -21
- package/node/lib/rtpMappingFbsUtils.d.ts +6 -0
- package/node/lib/rtpMappingFbsUtils.d.ts.map +1 -0
- package/node/lib/rtpMappingFbsUtils.js +65 -0
- package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
- package/node/lib/rtpParametersFbsUtils.js +0 -6
- package/node/lib/rtpParametersTypes.d.ts +1 -1
- package/node/lib/rtpParametersTypes.d.ts.map +1 -1
- package/node/lib/rtpStreamFbsUtils.d.ts +4 -0
- package/node/lib/rtpStreamFbsUtils.d.ts.map +1 -0
- package/node/lib/rtpStreamFbsUtils.js +51 -0
- package/node/lib/supportedRtpCapabilities.d.ts.map +1 -1
- package/node/lib/supportedRtpCapabilities.js +6 -13
- package/node/lib/test/test-Consumer.js +1 -13
- package/node/lib/test/test-DataConsumer.js +9 -0
- package/node/lib/test/test-DataProducer.js +38 -0
- package/node/lib/test/test-PipeTransport.js +27 -29
- package/node/lib/test/test-Producer.js +97 -0
- package/node/lib/test/test-ortc.js +34 -14
- package/package.json +10 -10
- package/worker/fbs/FBS/meson.build +25 -0
- package/worker/fbs/meson.build +15 -18
- package/worker/fbs/rtpParameters.fbs +0 -1
- package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
- package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +16 -2
- package/worker/include/DepLibUV.hpp +13 -0
- package/worker/include/RTC/BWE/AlrDetector.hpp +97 -0
- package/worker/include/RTC/BWE/BitrateProber.hpp +217 -0
- package/worker/include/RTC/BWE/BitrateUtils.hpp +39 -0
- package/worker/include/RTC/BWE/BweTypes.hpp +171 -3
- package/worker/include/RTC/BWE/FeedbackAdapter.hpp +0 -14
- package/worker/include/RTC/BWE/InterArrival.hpp +117 -0
- package/worker/include/RTC/BWE/IntervalBudget.hpp +81 -0
- package/worker/include/RTC/BWE/LossBasedController.hpp +625 -0
- package/worker/include/RTC/BWE/OveruseDetector.hpp +71 -0
- package/worker/include/RTC/BWE/OveruseEstimator.hpp +115 -0
- package/worker/include/RTC/BWE/ProbeBitrateEstimator.hpp +84 -0
- package/worker/include/RTC/BWE/ProbeController.hpp +379 -0
- package/worker/include/RTC/BWE/ProbePacketGenerator.hpp +130 -0
- package/worker/include/RTC/BWE/ProbingScheduler.hpp +187 -0
- package/worker/include/RTC/BWE/RembGenerator.hpp +96 -0
- package/worker/include/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp +237 -0
- package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +26 -0
- package/worker/include/RTC/BWE/SendPacketHistory.hpp +161 -25
- package/worker/include/RTC/BWE/TargetRateController.hpp +306 -0
- package/worker/include/RTC/BWE/TransportWideCcFeedbackGenerator.hpp +146 -0
- package/worker/include/RTC/BWE/TrendlineEstimator.hpp +73 -16
- package/worker/include/RTC/Consts.hpp +70 -0
- package/worker/include/RTC/DataConsumer.hpp +3 -5
- package/worker/include/RTC/DirectTransport.hpp +4 -5
- package/worker/include/RTC/PipeTransport.hpp +4 -5
- package/worker/include/RTC/PlainTransport.hpp +4 -5
- package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +6 -7
- package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +3 -1
- package/worker/include/RTC/RTP/Codecs/Tools.hpp +1 -1
- package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +0 -1
- package/worker/include/RTC/RTP/Packet.hpp +16 -4
- package/worker/include/RTC/RTP/ProbationGenerator.hpp +0 -8
- package/worker/include/RTC/RTP/RtpStream.hpp +12 -9
- package/worker/include/RTC/RTP/RtpStreamRecv.hpp +22 -4
- package/worker/include/RTC/RTP/RtpStreamSend.hpp +4 -2
- package/worker/include/RTC/RTP/RtxStream.hpp +10 -4
- package/worker/include/RTC/RateCalculator.hpp +103 -24
- package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +33 -3
- package/worker/include/RTC/{RtcLogger.hpp → RtcLogger/RtpPacket.hpp} +5 -3
- package/worker/include/RTC/RtcLogger/SendBurst.hpp +88 -0
- package/worker/include/RTC/RtpDictionaries.hpp +3 -4
- package/worker/include/RTC/SCTP/association/Association.hpp +1 -1
- package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +36 -0
- package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +0 -1
- package/worker/include/RTC/SCTP/public/SctpTypes.hpp +9 -9
- package/worker/include/RTC/SCTP/rx/DataTracker.hpp +1 -1
- package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +11 -1
- package/worker/include/RTC/SctpDictionaries.hpp +2 -2
- package/worker/include/RTC/TcpConnection.hpp +2 -1
- package/worker/include/RTC/Transport.hpp +23 -8
- package/worker/include/RTC/TransportTuple.hpp +61 -6
- package/worker/include/RTC/WebRtcTransport.hpp +4 -5
- package/worker/include/Shared.hpp +5 -0
- package/worker/include/SharedInterface.hpp +10 -0
- package/worker/include/Utils.hpp +72 -3
- package/worker/include/common.hpp +12 -4
- package/worker/include/handles/SendCallbacks.hpp +34 -0
- package/worker/include/handles/TcpConnectionHandle.hpp +4 -12
- package/worker/include/handles/UdpSocketHandle.hpp +4 -8
- package/worker/meson.build +45 -1
- package/worker/meson_options.txt +1 -0
- package/worker/mocks/include/MockShared.hpp +16 -2
- package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +1 -1
- package/worker/scripts/package-lock.json +6 -6
- package/worker/src/RTC/BWE/AimdRateControl.cpp +4 -5
- package/worker/src/RTC/BWE/AlrDetector.cpp +80 -0
- package/worker/src/RTC/BWE/BitrateProber.cpp +256 -0
- package/worker/src/RTC/BWE/BitrateUtils.cpp +54 -0
- package/worker/src/RTC/BWE/DelayBasedBwe.cpp +2 -2
- package/worker/src/RTC/BWE/FeedbackAdapter.cpp +20 -37
- package/worker/src/RTC/BWE/InterArrival.cpp +216 -0
- package/worker/src/RTC/BWE/IntervalBudget.cpp +93 -0
- package/worker/src/RTC/BWE/LossBasedController.cpp +1194 -0
- package/worker/src/RTC/BWE/OveruseDetector.cpp +128 -0
- package/worker/src/RTC/BWE/OveruseEstimator.cpp +166 -0
- package/worker/src/RTC/BWE/ProbeBitrateEstimator.cpp +222 -0
- package/worker/src/RTC/BWE/ProbeController.cpp +645 -0
- package/worker/src/RTC/BWE/ProbePacketGenerator.cpp +140 -0
- package/worker/src/RTC/BWE/ProbingScheduler.cpp +196 -0
- package/worker/src/RTC/BWE/RembGenerator.cpp +169 -0
- package/worker/src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp +497 -0
- package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +47 -0
- package/worker/src/RTC/BWE/SendPacketHistory.cpp +173 -50
- package/worker/src/RTC/BWE/TargetRateController.cpp +433 -0
- package/worker/src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp +377 -0
- package/worker/src/RTC/BWE/TrendlineEstimator.cpp +102 -5
- package/worker/src/RTC/Consumer.cpp +7 -5
- package/worker/src/RTC/DataConsumer.cpp +8 -10
- package/worker/src/RTC/DirectTransport.cpp +14 -8
- package/worker/src/RTC/DtlsTransport.cpp +8 -8
- package/worker/src/RTC/ICE/IceCandidate.cpp +4 -4
- package/worker/src/RTC/ICE/IceServer.cpp +1 -1
- package/worker/src/RTC/PipeTransport.cpp +13 -8
- package/worker/src/RTC/PlainTransport.cpp +13 -8
- package/worker/src/RTC/Producer.cpp +14 -31
- package/worker/src/RTC/RTCP/Bye.cpp +1 -1
- package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +18 -0
- package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +2 -2
- package/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp +2 -1
- package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +2 -2
- package/worker/src/RTC/RTCP/Sdes.cpp +1 -1
- package/worker/src/RTC/RTP/Codecs/DependencyDescriptor.cpp +2 -1
- package/worker/src/RTC/RTP/Packet.cpp +26 -11
- package/worker/src/RTC/RTP/ProbationGenerator.cpp +5 -6
- package/worker/src/RTC/RTP/RtpStream.cpp +1 -1
- package/worker/src/RTC/RTP/RtpStreamRecv.cpp +69 -48
- package/worker/src/RTC/RTP/RtpStreamSend.cpp +31 -31
- package/worker/src/RTC/RTP/RtxStream.cpp +22 -7
- package/worker/src/RTC/RateCalculator.cpp +133 -28
- package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +56 -1
- package/worker/src/RTC/{RtcLogger.cpp → RtcLogger/RtpPacket.cpp} +2 -2
- package/worker/src/RTC/RtcLogger/SendBurst.cpp +124 -0
- package/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +2 -12
- package/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +1 -1
- package/worker/src/RTC/SCTP/association/Association.cpp +16 -2
- package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +106 -1
- package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +1 -1
- package/worker/src/RTC/SCTP/rx/InterleavedReassemblyStreams.cpp +3 -3
- package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +2 -1
- package/worker/src/RTC/SCTP/rx/TraditionalReassemblyStreams.cpp +4 -4
- package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +4 -4
- package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +6 -10
- package/worker/src/RTC/SimulcastProducerStreamManager.cpp +2 -2
- package/worker/src/RTC/SrtpSession.cpp +2 -2
- package/worker/src/RTC/SvcProducerStreamManager.cpp +2 -2
- package/worker/src/RTC/TcpConnection.cpp +2 -2
- package/worker/src/RTC/Transport.cpp +112 -75
- package/worker/src/RTC/TransportTuple.cpp +4 -4
- package/worker/src/RTC/WebRtcServer.cpp +4 -3
- package/worker/src/RTC/WebRtcTransport.cpp +20 -13
- package/worker/src/Utils/BitStream.cpp +24 -0
- package/worker/src/handles/BackoffTimerHandle.cpp +1 -1
- package/worker/src/handles/TcpConnectionHandle.cpp +13 -23
- package/worker/src/handles/UdpSocketHandle.cpp +14 -21
- package/worker/tasks.py +43 -18
- package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +68 -14
- package/worker/test/include/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.hpp +125 -0
- package/worker/test/src/RTC/BWE/TestAlrDetector.cpp +110 -0
- package/worker/test/src/RTC/BWE/TestBitrateProber.cpp +418 -0
- package/worker/test/src/RTC/BWE/TestBitrateUtils.cpp +61 -0
- package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +4 -4
- package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +53 -37
- package/worker/test/src/RTC/BWE/TestInterArrival.cpp +643 -0
- package/worker/test/src/RTC/BWE/TestIntervalBudget.cpp +130 -0
- package/worker/test/src/RTC/BWE/TestLossBasedController.cpp +1199 -0
- package/worker/test/src/RTC/BWE/TestOveruseDetector.cpp +519 -0
- package/worker/test/src/RTC/BWE/TestProbeBitrateEstimator.cpp +266 -0
- package/worker/test/src/RTC/BWE/TestProbeController.cpp +1682 -0
- package/worker/test/src/RTC/BWE/TestProbePacketGenerator.cpp +265 -0
- package/worker/test/src/RTC/BWE/TestProbingScheduler.cpp +260 -0
- package/worker/test/src/RTC/BWE/TestRembGenerator.cpp +285 -0
- package/worker/test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp +414 -0
- package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +296 -77
- package/worker/test/src/RTC/BWE/TestTargetRateController.cpp +337 -0
- package/worker/test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp +578 -0
- package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +45 -0
- package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +133 -29
- package/worker/test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp +625 -0
- package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +19 -0
- package/worker/test/src/RTC/RTP/TestPacket.cpp +58 -4
- package/worker/test/src/RTC/RTP/TestProbationGenerator.cpp +3 -2
- package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +50 -0
- package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +59 -0
- package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +111 -0
- package/worker/test/src/RTC/TestRateCalculator.cpp +322 -60
- package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +95 -7
- package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +34 -16
- package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +31 -13
- package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +37 -19
- package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +10 -10
- package/worker/test/src/Utils/TestTime.cpp +120 -21
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
#define MS_CLASS "RTC::BWE::TargetRateController"
|
|
2
|
+
// #define MS_LOG_DEV_LEVEL 3
|
|
3
|
+
|
|
4
|
+
#include "RTC/BWE/TargetRateController.hpp"
|
|
5
|
+
#include "Logger.hpp"
|
|
6
|
+
#include "RTC/BWE/BitrateUtils.hpp"
|
|
7
|
+
#include "RTC/Consts.hpp"
|
|
8
|
+
|
|
9
|
+
namespace RTC
|
|
10
|
+
{
|
|
11
|
+
namespace BWE
|
|
12
|
+
{
|
|
13
|
+
/* Static. */
|
|
14
|
+
|
|
15
|
+
// How far back the lowest target is looked for when increasing.
|
|
16
|
+
static constexpr int64_t BweIncreaseIntervalUs{ 1000 * 1000 };
|
|
17
|
+
// Minimum time between two decreases caused by loss, on top of a round trip
|
|
18
|
+
// time.
|
|
19
|
+
static constexpr int64_t BweDecreaseIntervalUs{ 300 * 1000 };
|
|
20
|
+
// How long the target is allowed to just follow its bounds after the first
|
|
21
|
+
// loss report.
|
|
22
|
+
static constexpr int64_t StartPhaseUs{ 2000 * 1000 };
|
|
23
|
+
// Packets a loss report must cover before its fraction of lost packets says
|
|
24
|
+
// anything.
|
|
25
|
+
static constexpr int64_t LimitNumPackets{ 20 };
|
|
26
|
+
// Age over which the latest loss report is not acted upon anymore. Reports
|
|
27
|
+
// are expected within [0.5, 1.5] s intervals, so this is 1.2 times the
|
|
28
|
+
// longest interval that still counts as uniform.
|
|
29
|
+
static constexpr int64_t MaxLossReportAgeUs{ 6000 * 1000 };
|
|
30
|
+
|
|
31
|
+
/* Instance methods. */
|
|
32
|
+
|
|
33
|
+
TargetRateController::TargetRateController()
|
|
34
|
+
: TargetRateController(TargetRateControllerOptions{})
|
|
35
|
+
{
|
|
36
|
+
MS_TRACE();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
TargetRateController::TargetRateController(TargetRateControllerOptions options)
|
|
40
|
+
: options(options),
|
|
41
|
+
minBitrateConfigured(Consts::BweMinBitrate),
|
|
42
|
+
maxBitrateConfigured(Consts::BweMaxBitrate)
|
|
43
|
+
{
|
|
44
|
+
MS_TRACE();
|
|
45
|
+
|
|
46
|
+
this->lossBasedController.SetBitrateLimits(
|
|
47
|
+
this->minBitrateConfigured, this->maxBitrateConfigured);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
int64_t TargetRateController::GetTargetBitrate() const
|
|
51
|
+
{
|
|
52
|
+
MS_TRACE();
|
|
53
|
+
|
|
54
|
+
int64_t target = this->currentTarget;
|
|
55
|
+
|
|
56
|
+
// Unless it has been told to drive the target, the bound asked for by the
|
|
57
|
+
// receiver caps only the value handed out, which is why it's applied here
|
|
58
|
+
// and not in GetUpperLimit().
|
|
59
|
+
if (!this->options.disableReceiverLimitCapsOnly)
|
|
60
|
+
{
|
|
61
|
+
target = std::min(target, this->receiverLimit);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return std::max(this->minBitrateConfigured, target);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void TargetRateController::OnRouteChange()
|
|
68
|
+
{
|
|
69
|
+
MS_TRACE();
|
|
70
|
+
|
|
71
|
+
this->lostPacketsSinceLastLossUpdate = 0;
|
|
72
|
+
this->expectedPacketsSinceLastLossUpdate = 0;
|
|
73
|
+
this->currentTarget = 0;
|
|
74
|
+
this->minBitrateConfigured = Consts::BweMinBitrate;
|
|
75
|
+
this->maxBitrateConfigured = Consts::BweMaxBitrate;
|
|
76
|
+
this->hasDecreasedSinceLastFractionLoss = false;
|
|
77
|
+
this->lastFractionLost = 0;
|
|
78
|
+
this->lastRttUs = 0;
|
|
79
|
+
this->receiverLimit = Types::BitrateInfinite;
|
|
80
|
+
this->delayBasedLimit = Types::BitrateInfinite;
|
|
81
|
+
this->firstLossReportAtUs.reset();
|
|
82
|
+
this->lastLossReportAtUs.reset();
|
|
83
|
+
this->lastDecreaseAtUs.reset();
|
|
84
|
+
|
|
85
|
+
// A loss controller that is allowed to take over during the start phase
|
|
86
|
+
// would otherwise carry what it learnt about the previous path into the
|
|
87
|
+
// start phase that is about to begin again.
|
|
88
|
+
if (this->lossBasedController.IsUsedInStartPhase())
|
|
89
|
+
{
|
|
90
|
+
this->lossBasedController.Reset();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void TargetRateController::SetBitrateLimits(int64_t minBitrate, int64_t maxBitrate)
|
|
95
|
+
{
|
|
96
|
+
MS_TRACE();
|
|
97
|
+
|
|
98
|
+
this->minBitrateConfigured = std::max(minBitrate, Consts::BweMinBitrate);
|
|
99
|
+
|
|
100
|
+
// No maximum at all is not a maximum of every bitrate there is, it means
|
|
101
|
+
// that the one this controller picks for itself applies.
|
|
102
|
+
if (maxBitrate > 0 && maxBitrate != Types::BitrateInfinite)
|
|
103
|
+
{
|
|
104
|
+
this->maxBitrateConfigured = std::max(this->minBitrateConfigured, maxBitrate);
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
{
|
|
108
|
+
this->maxBitrateConfigured = Consts::BweMaxBitrate;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this->lossBasedController.SetBitrateLimits(
|
|
112
|
+
this->minBitrateConfigured, this->maxBitrateConfigured);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
void TargetRateController::SetAcknowledgedBitrate(int64_t acknowledgedBitrate)
|
|
116
|
+
{
|
|
117
|
+
MS_TRACE();
|
|
118
|
+
|
|
119
|
+
// Not knowing what the link delivers is not the same as it delivering
|
|
120
|
+
// nothing, so the last figure that was known is kept instead.
|
|
121
|
+
if (acknowledgedBitrate == Types::BitrateInfinite)
|
|
122
|
+
{
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// NOTE: Nothing else in here looks at it, it's only of use to the loss
|
|
127
|
+
// controller.
|
|
128
|
+
this->lossBasedController.SetAcknowledgedBitrate(acknowledgedBitrate);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
void TargetRateController::UpdateLossBasedController(
|
|
132
|
+
const std::vector<Types::PacketResult>& packetResults, bool inAlr, int64_t nowUs)
|
|
133
|
+
{
|
|
134
|
+
MS_TRACE();
|
|
135
|
+
|
|
136
|
+
this->lossBasedController.UpdateBitrateEstimate(packetResults, this->delayBasedLimit, inAlr);
|
|
137
|
+
|
|
138
|
+
Update(nowUs);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void TargetRateController::SetSendBitrate(int64_t bitrate)
|
|
142
|
+
{
|
|
143
|
+
MS_TRACE();
|
|
144
|
+
|
|
145
|
+
// Drop the bound of the delay based path so that it cannot cap the given
|
|
146
|
+
// value.
|
|
147
|
+
this->delayBasedLimit = Types::BitrateInfinite;
|
|
148
|
+
|
|
149
|
+
// NOTE: A bitrate outside the configured bounds is brought into them
|
|
150
|
+
// rather than rejected, since this value comes from the application.
|
|
151
|
+
SetTargetBitrate(bitrate);
|
|
152
|
+
|
|
153
|
+
// Clear the history so that the new value is grown from directly instead
|
|
154
|
+
// of from whatever the target was before.
|
|
155
|
+
this->minBitrateHistory.clear();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
void TargetRateController::SetDelayBasedEstimate(int64_t bitrate)
|
|
159
|
+
{
|
|
160
|
+
MS_TRACE();
|
|
161
|
+
|
|
162
|
+
this->delayBasedLimit = bitrate == 0 ? Types::BitrateInfinite : bitrate;
|
|
163
|
+
|
|
164
|
+
ApplyTargetLimits();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
void TargetRateController::SetReceiverEstimate(int64_t bitrate)
|
|
168
|
+
{
|
|
169
|
+
MS_TRACE();
|
|
170
|
+
|
|
171
|
+
this->receiverLimit = bitrate == 0 ? Types::BitrateInfinite : bitrate;
|
|
172
|
+
|
|
173
|
+
ApplyTargetLimits();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
void TargetRateController::UpdatePacketsLost(int64_t lostPackets, int64_t totalPackets, int64_t nowUs)
|
|
177
|
+
{
|
|
178
|
+
MS_TRACE();
|
|
179
|
+
|
|
180
|
+
if (!this->firstLossReportAtUs.has_value())
|
|
181
|
+
{
|
|
182
|
+
this->firstLossReportAtUs = nowUs;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (totalPackets <= 0)
|
|
186
|
+
{
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const int64_t expectedPackets = this->expectedPacketsSinceLastLossUpdate + totalPackets;
|
|
191
|
+
|
|
192
|
+
// Accumulate reports until they cover enough packets.
|
|
193
|
+
if (expectedPackets < LimitNumPackets)
|
|
194
|
+
{
|
|
195
|
+
this->expectedPacketsSinceLastLossUpdate = expectedPackets;
|
|
196
|
+
this->lostPacketsSinceLastLossUpdate += lostPackets;
|
|
197
|
+
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this->hasDecreasedSinceLastFractionLoss = false;
|
|
202
|
+
|
|
203
|
+
// NOTE: The reported fraction is in 1/256 units, hence the shift.
|
|
204
|
+
const int64_t lostQ8 =
|
|
205
|
+
std::max<int64_t>(this->lostPacketsSinceLastLossUpdate + lostPackets, 0) << 8;
|
|
206
|
+
|
|
207
|
+
this->lastFractionLost = static_cast<uint8_t>(std::min<int64_t>(lostQ8 / expectedPackets, 255));
|
|
208
|
+
|
|
209
|
+
this->lostPacketsSinceLastLossUpdate = 0;
|
|
210
|
+
this->expectedPacketsSinceLastLossUpdate = 0;
|
|
211
|
+
this->lastLossReportAtUs = nowUs;
|
|
212
|
+
|
|
213
|
+
Update(nowUs);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
void TargetRateController::UpdateRtt(int64_t rttUs)
|
|
217
|
+
{
|
|
218
|
+
MS_TRACE();
|
|
219
|
+
|
|
220
|
+
// A round trip time cannot always be computed, since it needs a sender
|
|
221
|
+
// report to refer to.
|
|
222
|
+
if (rttUs > 0)
|
|
223
|
+
{
|
|
224
|
+
this->lastRttUs = rttUs;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
void TargetRateController::UpdatePropagationRtt(int64_t propagationRttUs, int64_t nowUs)
|
|
229
|
+
{
|
|
230
|
+
MS_TRACE();
|
|
231
|
+
|
|
232
|
+
this->rttBackoff.lastPropagationRttAtUs = nowUs;
|
|
233
|
+
this->rttBackoff.lastPropagationRttUs = propagationRttUs;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
void TargetRateController::OnPacketSent(int64_t sentAtUs)
|
|
237
|
+
{
|
|
238
|
+
MS_TRACE();
|
|
239
|
+
|
|
240
|
+
this->rttBackoff.lastPacketSentAtUs = sentAtUs;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
void TargetRateController::Update(int64_t nowUs)
|
|
244
|
+
{
|
|
245
|
+
MS_TRACE();
|
|
246
|
+
|
|
247
|
+
// A round trip time this long means that the queues of the network are
|
|
248
|
+
// full, which neither loss nor delay may have noticed yet.
|
|
249
|
+
if (IsRttAboveLimit())
|
|
250
|
+
{
|
|
251
|
+
const bool mayDecrease =
|
|
252
|
+
!this->lastDecreaseAtUs.has_value() ||
|
|
253
|
+
nowUs - this->lastDecreaseAtUs.value() >= this->options.rttBackoffDropIntervalUs;
|
|
254
|
+
|
|
255
|
+
if (mayDecrease && this->currentTarget > this->options.rttBackoffBitrateFloor)
|
|
256
|
+
{
|
|
257
|
+
this->lastDecreaseAtUs = nowUs;
|
|
258
|
+
|
|
259
|
+
const auto bitrate = std::max<int64_t>(
|
|
260
|
+
BitrateUtils::ApplyBitrateFactor(
|
|
261
|
+
this->currentTarget, this->options.rttBackoffDropFraction),
|
|
262
|
+
this->options.rttBackoffBitrateFloor);
|
|
263
|
+
|
|
264
|
+
SetTargetBitrate(bitrate);
|
|
265
|
+
}
|
|
266
|
+
else
|
|
267
|
+
{
|
|
268
|
+
ApplyTargetLimits();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// The bounds are trusted during the first seconds as long as no loss has
|
|
275
|
+
// been reported, so that the initial probing can raise the target.
|
|
276
|
+
if (this->lastFractionLost == 0 && IsInStartPhase(nowUs) && !this->lossBasedController.IsReadyToUseInStartPhase())
|
|
277
|
+
{
|
|
278
|
+
int64_t bitrate = this->currentTarget;
|
|
279
|
+
|
|
280
|
+
if (this->receiverLimit != Types::BitrateInfinite)
|
|
281
|
+
{
|
|
282
|
+
bitrate = std::max(this->receiverLimit, bitrate);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (this->delayBasedLimit != Types::BitrateInfinite)
|
|
286
|
+
{
|
|
287
|
+
bitrate = std::max(this->delayBasedLimit, bitrate);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (bitrate != this->currentTarget)
|
|
291
|
+
{
|
|
292
|
+
// Take the target being left behind as the value to grow from, since
|
|
293
|
+
// the new one was not reached by increasing.
|
|
294
|
+
this->minBitrateHistory.clear();
|
|
295
|
+
this->minBitrateHistory.emplace_back(nowUs, this->currentTarget);
|
|
296
|
+
|
|
297
|
+
SetTargetBitrate(bitrate);
|
|
298
|
+
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
UpdateMinBitrateHistory(nowUs);
|
|
304
|
+
|
|
305
|
+
// Once the loss controller can tell congestion from the loss the link has
|
|
306
|
+
// by itself, its estimate replaces the coarse rules below.
|
|
307
|
+
if (this->lossBasedController.IsReady())
|
|
308
|
+
{
|
|
309
|
+
const auto result = this->lossBasedController.GetResult();
|
|
310
|
+
|
|
311
|
+
this->lossBasedState = result.state;
|
|
312
|
+
|
|
313
|
+
SetTargetBitrate(result.bitrate);
|
|
314
|
+
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// No loss report has covered enough packets yet.
|
|
319
|
+
if (!this->lastLossReportAtUs.has_value())
|
|
320
|
+
{
|
|
321
|
+
ApplyTargetLimits();
|
|
322
|
+
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (nowUs - this->lastLossReportAtUs.value() < MaxLossReportAgeUs)
|
|
327
|
+
{
|
|
328
|
+
const double loss = this->lastFractionLost / 256.0;
|
|
329
|
+
|
|
330
|
+
if (this->currentTarget < this->options.bitrateThreshold || loss <= this->options.lowLossThreshold)
|
|
331
|
+
{
|
|
332
|
+
// Increase by 8% of the lowest target of the last second. Growing
|
|
333
|
+
// from the lowest value instead of from the current one lets a sender
|
|
334
|
+
// that was throttled ramp up a second faster.
|
|
335
|
+
// Add a bit on top of the 8%, which is what keeps the target from
|
|
336
|
+
// getting stuck at low bitrates and is negligible at high ones.
|
|
337
|
+
const auto bitrate = BitrateUtils::AddBitrates(
|
|
338
|
+
BitrateUtils::ApplyBitrateFactor(this->minBitrateHistory.front().second, 1.08), 1000);
|
|
339
|
+
|
|
340
|
+
SetTargetBitrate(bitrate);
|
|
341
|
+
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Loss between both thresholds means doing nothing at all.
|
|
346
|
+
if (this->currentTarget > this->options.bitrateThreshold && loss > this->options.highLossThreshold)
|
|
347
|
+
{
|
|
348
|
+
const bool mayDecrease =
|
|
349
|
+
!this->lastDecreaseAtUs.has_value() ||
|
|
350
|
+
nowUs - this->lastDecreaseAtUs.value() >= BweDecreaseIntervalUs + this->lastRttUs;
|
|
351
|
+
|
|
352
|
+
if (!this->hasDecreasedSinceLastFractionLoss && mayDecrease)
|
|
353
|
+
{
|
|
354
|
+
this->lastDecreaseAtUs = nowUs;
|
|
355
|
+
|
|
356
|
+
// The new bitrate is the current one times (1 - 0.5 * lossRate),
|
|
357
|
+
// where the reported fraction is 256 times that loss rate.
|
|
358
|
+
const auto bitrate = static_cast<int64_t>(
|
|
359
|
+
(this->currentTarget * static_cast<double>(512 - this->lastFractionLost)) / 512.0);
|
|
360
|
+
|
|
361
|
+
this->hasDecreasedSinceLastFractionLoss = true;
|
|
362
|
+
|
|
363
|
+
SetTargetBitrate(bitrate);
|
|
364
|
+
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
ApplyTargetLimits();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
bool TargetRateController::IsInStartPhase(int64_t nowUs) const
|
|
374
|
+
{
|
|
375
|
+
MS_TRACE();
|
|
376
|
+
|
|
377
|
+
return !this->firstLossReportAtUs.has_value() ||
|
|
378
|
+
nowUs - this->firstLossReportAtUs.value() < StartPhaseUs;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
void TargetRateController::UpdateMinBitrateHistory(int64_t nowUs)
|
|
382
|
+
{
|
|
383
|
+
MS_TRACE();
|
|
384
|
+
|
|
385
|
+
// Drop the points that fell out of the window. The window is closed a
|
|
386
|
+
// millisecond early, so that a target which has only just aged out of it
|
|
387
|
+
// doesn't hold the increase back.
|
|
388
|
+
while (!this->minBitrateHistory.empty() &&
|
|
389
|
+
nowUs - this->minBitrateHistory.front().first + 1000 > BweIncreaseIntervalUs)
|
|
390
|
+
{
|
|
391
|
+
this->minBitrateHistory.pop_front();
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Sliding window minimum: drop the points not lower than the current
|
|
395
|
+
// target before pushing it, since they can never be the minimum again.
|
|
396
|
+
while (!this->minBitrateHistory.empty() &&
|
|
397
|
+
this->currentTarget <= this->minBitrateHistory.back().second)
|
|
398
|
+
{
|
|
399
|
+
this->minBitrateHistory.pop_back();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
this->minBitrateHistory.emplace_back(nowUs, this->currentTarget);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
int64_t TargetRateController::GetUpperLimit() const
|
|
406
|
+
{
|
|
407
|
+
MS_TRACE();
|
|
408
|
+
|
|
409
|
+
int64_t upperLimit = this->delayBasedLimit;
|
|
410
|
+
|
|
411
|
+
if (this->options.disableReceiverLimitCapsOnly)
|
|
412
|
+
{
|
|
413
|
+
upperLimit = std::min(upperLimit, this->receiverLimit);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return std::min(upperLimit, this->maxBitrateConfigured);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
void TargetRateController::SetTargetBitrate(int64_t bitrate)
|
|
420
|
+
{
|
|
421
|
+
MS_TRACE();
|
|
422
|
+
|
|
423
|
+
this->currentTarget = std::max(this->minBitrateConfigured, std::min(bitrate, GetUpperLimit()));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
void TargetRateController::ApplyTargetLimits()
|
|
427
|
+
{
|
|
428
|
+
MS_TRACE();
|
|
429
|
+
|
|
430
|
+
SetTargetBitrate(this->currentTarget);
|
|
431
|
+
}
|
|
432
|
+
} // namespace BWE
|
|
433
|
+
} // namespace RTC
|