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,216 @@
|
|
|
1
|
+
#define MS_CLASS "RTC::BWE::InterArrival"
|
|
2
|
+
// #define MS_LOG_DEV_LEVEL 3
|
|
3
|
+
|
|
4
|
+
#include "RTC/BWE/InterArrival.hpp"
|
|
5
|
+
#include "Logger.hpp"
|
|
6
|
+
#include "Utils.hpp"
|
|
7
|
+
#include <cmath> // std::llround()
|
|
8
|
+
|
|
9
|
+
namespace RTC
|
|
10
|
+
{
|
|
11
|
+
namespace BWE
|
|
12
|
+
{
|
|
13
|
+
/* Static. */
|
|
14
|
+
|
|
15
|
+
// Maximum arrival time delta for a packet to be absorbed into the ongoing
|
|
16
|
+
// burst.
|
|
17
|
+
static constexpr int64_t BurstDeltaThresholdUs{ 5000 };
|
|
18
|
+
// Maximum duration of a burst.
|
|
19
|
+
static constexpr int64_t MaxBurstDurationUs{ 100000 };
|
|
20
|
+
// Number of consecutive reordered groups after which the state is reset.
|
|
21
|
+
static constexpr size_t ReorderedResetThreshold{ 3 };
|
|
22
|
+
// Difference between the arrival time delta and our own time delta after
|
|
23
|
+
// which the state is reset, assuming that the remote clock has jumped.
|
|
24
|
+
static constexpr int64_t ArrivalTimeOffsetThresholdUs{ 3000000 };
|
|
25
|
+
|
|
26
|
+
/* Instance methods. */
|
|
27
|
+
|
|
28
|
+
InterArrival::InterArrival(uint32_t timestampGroupLengthTicks, double timestampToUsCoeff)
|
|
29
|
+
: timestampGroupLengthTicks(timestampGroupLengthTicks), timestampToUsCoeff(timestampToUsCoeff)
|
|
30
|
+
{
|
|
31
|
+
MS_TRACE();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
std::optional<InterArrival::Deltas> InterArrival::ComputeDeltas(
|
|
35
|
+
uint32_t timestamp, int64_t arrivalTimeUs, int64_t systemTimeUs, size_t packetSize)
|
|
36
|
+
{
|
|
37
|
+
MS_TRACE();
|
|
38
|
+
|
|
39
|
+
std::optional<Deltas> deltas;
|
|
40
|
+
|
|
41
|
+
if (this->currentGroup.IsFirstPacket())
|
|
42
|
+
{
|
|
43
|
+
// Not enough data to compute deltas yet, so just store the packet until
|
|
44
|
+
// there are two groups to compare.
|
|
45
|
+
this->currentGroup.timestamp = timestamp;
|
|
46
|
+
this->currentGroup.firstTimestamp = timestamp;
|
|
47
|
+
this->currentGroup.firstArrivalTimeUs = arrivalTimeUs;
|
|
48
|
+
}
|
|
49
|
+
else if (!IsPacketInOrder(timestamp))
|
|
50
|
+
{
|
|
51
|
+
// Reordered packet.
|
|
52
|
+
return std::nullopt;
|
|
53
|
+
}
|
|
54
|
+
else if (IsNewTimestampGroup(arrivalTimeUs, timestamp))
|
|
55
|
+
{
|
|
56
|
+
// This is the first packet of a later send burst, so the sample of the
|
|
57
|
+
// ongoing group is ready.
|
|
58
|
+
if (!this->prevGroup.IsFirstPacket())
|
|
59
|
+
{
|
|
60
|
+
const uint32_t timestampDelta = this->currentGroup.timestamp - this->prevGroup.timestamp;
|
|
61
|
+
const int64_t arrivalDeltaUs =
|
|
62
|
+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
63
|
+
this->currentGroup.completeTimeUs.value() -
|
|
64
|
+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
65
|
+
this->prevGroup.completeTimeUs.value();
|
|
66
|
+
const int64_t ownDeltaUs =
|
|
67
|
+
this->currentGroup.lastSystemTimeUs - this->prevGroup.lastSystemTimeUs;
|
|
68
|
+
|
|
69
|
+
if (arrivalDeltaUs - ownDeltaUs >= ArrivalTimeOffsetThresholdUs)
|
|
70
|
+
{
|
|
71
|
+
MS_WARN_TAG(
|
|
72
|
+
bwe,
|
|
73
|
+
"arrival time clock offset has changed, resetting [diff:%" PRIi64 " us]",
|
|
74
|
+
arrivalDeltaUs - ownDeltaUs);
|
|
75
|
+
|
|
76
|
+
Reset();
|
|
77
|
+
|
|
78
|
+
return std::nullopt;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (arrivalDeltaUs < 0)
|
|
82
|
+
{
|
|
83
|
+
// The groups have been reordered after their arrival time was taken.
|
|
84
|
+
++this->numConsecutiveReorderedGroups;
|
|
85
|
+
|
|
86
|
+
if (this->numConsecutiveReorderedGroups >= ReorderedResetThreshold)
|
|
87
|
+
{
|
|
88
|
+
MS_WARN_TAG(
|
|
89
|
+
bwe,
|
|
90
|
+
"packets between send bursts arrived out of order, resetting [arrivalDelta:%" PRIi64
|
|
91
|
+
" us]",
|
|
92
|
+
arrivalDeltaUs);
|
|
93
|
+
|
|
94
|
+
Reset();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return std::nullopt;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this->numConsecutiveReorderedGroups = 0;
|
|
101
|
+
|
|
102
|
+
// NOTE: Guaranteed by the branch right above, which returns for every
|
|
103
|
+
// negative one.
|
|
104
|
+
MS_ASSERT(arrivalDeltaUs >= 0, "arrival delta is negative");
|
|
105
|
+
|
|
106
|
+
deltas = Deltas{ .timestampDelta = timestampDelta,
|
|
107
|
+
.arrivalDeltaUs = arrivalDeltaUs,
|
|
108
|
+
.sizeDelta = static_cast<int64_t>(this->currentGroup.size) -
|
|
109
|
+
static_cast<int64_t>(this->prevGroup.size) };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this->prevGroup = this->currentGroup;
|
|
113
|
+
|
|
114
|
+
// The new packet starts the current group.
|
|
115
|
+
this->currentGroup.firstTimestamp = timestamp;
|
|
116
|
+
this->currentGroup.timestamp = timestamp;
|
|
117
|
+
this->currentGroup.firstArrivalTimeUs = arrivalTimeUs;
|
|
118
|
+
this->currentGroup.size = 0;
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
{
|
|
122
|
+
// NOTE: Not std::max() because these timestamps wrap around, so the
|
|
123
|
+
// later one is not necessarily the greater one.
|
|
124
|
+
this->currentGroup.timestamp =
|
|
125
|
+
Utils::Number::IsHigherThan<uint32_t>(timestamp, this->currentGroup.timestamp)
|
|
126
|
+
? timestamp
|
|
127
|
+
: this->currentGroup.timestamp;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Accumulate the group size.
|
|
131
|
+
this->currentGroup.size += packetSize;
|
|
132
|
+
this->currentGroup.completeTimeUs = arrivalTimeUs;
|
|
133
|
+
this->currentGroup.lastSystemTimeUs = systemTimeUs;
|
|
134
|
+
|
|
135
|
+
return deltas;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
bool InterArrival::IsPacketInOrder(uint32_t timestamp) const
|
|
139
|
+
{
|
|
140
|
+
MS_TRACE();
|
|
141
|
+
|
|
142
|
+
if (this->currentGroup.IsFirstPacket())
|
|
143
|
+
{
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// A packet of the very same timestamp as the first one of the group is in
|
|
148
|
+
// order, so this is not a strict comparison.
|
|
149
|
+
return Utils::Number::IsHigherOrEqualThan<uint32_t>(
|
|
150
|
+
timestamp, this->currentGroup.firstTimestamp);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
bool InterArrival::IsNewTimestampGroup(int64_t arrivalTimeUs, uint32_t timestamp) const
|
|
154
|
+
{
|
|
155
|
+
MS_TRACE();
|
|
156
|
+
|
|
157
|
+
if (this->currentGroup.IsFirstPacket())
|
|
158
|
+
{
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
else if (BelongsToBurst(arrivalTimeUs, timestamp))
|
|
162
|
+
{
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
{
|
|
167
|
+
// NOTE: The subtraction is done in the width of the timestamps, so a
|
|
168
|
+
// group that spans their wrap around still measures its own length.
|
|
169
|
+
const uint32_t timestampDiff = timestamp - this->currentGroup.firstTimestamp;
|
|
170
|
+
|
|
171
|
+
return timestampDiff > this->timestampGroupLengthTicks;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
bool InterArrival::BelongsToBurst(int64_t arrivalTimeUs, uint32_t timestamp) const
|
|
176
|
+
{
|
|
177
|
+
MS_TRACE();
|
|
178
|
+
|
|
179
|
+
MS_ASSERT(!this->currentGroup.IsFirstPacket(), "current group is empty");
|
|
180
|
+
|
|
181
|
+
const int64_t arrivalDeltaUs =
|
|
182
|
+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
183
|
+
arrivalTimeUs - this->currentGroup.completeTimeUs.value();
|
|
184
|
+
const uint32_t timestampDiff = timestamp - this->currentGroup.timestamp;
|
|
185
|
+
const auto sendDeltaUs = std::llround(this->timestampToUsCoeff * timestampDiff);
|
|
186
|
+
|
|
187
|
+
// Packets sent at the very same time always belong to the same burst.
|
|
188
|
+
//
|
|
189
|
+
// NOTE: Sameness is told apart with a resolution of a millisecond, which
|
|
190
|
+
// is the one every threshold of this path is expressed in. A finer one
|
|
191
|
+
// would leave packets that left together out of the burst just because
|
|
192
|
+
// the timestamps they carry can tell them apart.
|
|
193
|
+
if (std::llround(static_cast<double>(sendDeltaUs) / 1000.0) == 0)
|
|
194
|
+
{
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const int64_t propagationDeltaUs = arrivalDeltaUs - sendDeltaUs;
|
|
199
|
+
const int64_t burstDurationUs = arrivalTimeUs - this->currentGroup.firstArrivalTimeUs;
|
|
200
|
+
|
|
201
|
+
// The packet arrived earlier than its send time gap would suggest, meaning
|
|
202
|
+
// that it was serialized by the network together with the ongoing group.
|
|
203
|
+
return propagationDeltaUs < 0 && arrivalDeltaUs <= BurstDeltaThresholdUs &&
|
|
204
|
+
burstDurationUs < MaxBurstDurationUs;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void InterArrival::Reset()
|
|
208
|
+
{
|
|
209
|
+
MS_TRACE();
|
|
210
|
+
|
|
211
|
+
this->numConsecutiveReorderedGroups = 0;
|
|
212
|
+
this->currentGroup = TimestampGroup();
|
|
213
|
+
this->prevGroup = TimestampGroup();
|
|
214
|
+
}
|
|
215
|
+
} // namespace BWE
|
|
216
|
+
} // namespace RTC
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#define MS_CLASS "RTC::BWE::IntervalBudget"
|
|
2
|
+
// #define MS_LOG_DEV_LEVEL 3
|
|
3
|
+
|
|
4
|
+
#include "RTC/BWE/IntervalBudget.hpp"
|
|
5
|
+
#include "Logger.hpp"
|
|
6
|
+
|
|
7
|
+
namespace RTC
|
|
8
|
+
{
|
|
9
|
+
namespace BWE
|
|
10
|
+
{
|
|
11
|
+
/* Static. */
|
|
12
|
+
|
|
13
|
+
// Span of time the budget is measured over.
|
|
14
|
+
static constexpr int64_t WindowUs{ 500 * 1000 };
|
|
15
|
+
|
|
16
|
+
/* Instance methods. */
|
|
17
|
+
|
|
18
|
+
IntervalBudget::IntervalBudget(int64_t initialTargetBitrate)
|
|
19
|
+
: IntervalBudget(initialTargetBitrate, /*canBuildUpUnderuse*/ false)
|
|
20
|
+
{
|
|
21
|
+
MS_TRACE();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
IntervalBudget::IntervalBudget(int64_t initialTargetBitrate, bool canBuildUpUnderuse)
|
|
25
|
+
: canBuildUpUnderuse(canBuildUpUnderuse)
|
|
26
|
+
{
|
|
27
|
+
MS_TRACE();
|
|
28
|
+
|
|
29
|
+
SetTargetBitrate(initialTargetBitrate);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void IntervalBudget::SetTargetBitrate(int64_t targetBitrate)
|
|
33
|
+
{
|
|
34
|
+
MS_TRACE();
|
|
35
|
+
|
|
36
|
+
this->targetBitrate = targetBitrate;
|
|
37
|
+
// Bits over a second into bytes over the window.
|
|
38
|
+
this->maxBytesInBudget = (this->targetBitrate * WindowUs) / (8 * 1000000);
|
|
39
|
+
|
|
40
|
+
// What the budget held doesn't survive a window it no longer fits in.
|
|
41
|
+
this->bytesRemaining =
|
|
42
|
+
std::clamp(this->bytesRemaining, -this->maxBytesInBudget, this->maxBytesInBudget);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void IntervalBudget::IncreaseBudget(int64_t deltaTimeUs)
|
|
46
|
+
{
|
|
47
|
+
MS_TRACE();
|
|
48
|
+
|
|
49
|
+
// Bits over a second into the bytes that fit in the span given, which is
|
|
50
|
+
// negative when the span is, so that time running backwards takes budget
|
|
51
|
+
// away rather than leaving it untouched.
|
|
52
|
+
const int64_t bytes = (this->targetBitrate * deltaTimeUs) / (8 * 1000000);
|
|
53
|
+
|
|
54
|
+
if (this->bytesRemaining < 0 || this->canBuildUpUnderuse)
|
|
55
|
+
{
|
|
56
|
+
// The budget was overspent, so this span makes up for it.
|
|
57
|
+
this->bytesRemaining = std::min(this->bytesRemaining + bytes, this->maxBytesInBudget);
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
{
|
|
61
|
+
// What was left unspent is not available anymore.
|
|
62
|
+
this->bytesRemaining = std::min(bytes, this->maxBytesInBudget);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void IntervalBudget::UseBudget(int64_t bytes)
|
|
67
|
+
{
|
|
68
|
+
MS_TRACE();
|
|
69
|
+
|
|
70
|
+
this->bytesRemaining = std::max(this->bytesRemaining - bytes, -this->maxBytesInBudget);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
int64_t IntervalBudget::GetBytesRemaining() const
|
|
74
|
+
{
|
|
75
|
+
MS_TRACE();
|
|
76
|
+
|
|
77
|
+
return std::max<int64_t>(0, this->bytesRemaining);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
double IntervalBudget::GetBudgetRatio() const
|
|
81
|
+
{
|
|
82
|
+
MS_TRACE();
|
|
83
|
+
|
|
84
|
+
// Nothing can be left over nor owed at no bitrate at all.
|
|
85
|
+
if (this->maxBytesInBudget == 0)
|
|
86
|
+
{
|
|
87
|
+
return 0.0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return static_cast<double>(this->bytesRemaining) / static_cast<double>(this->maxBytesInBudget);
|
|
91
|
+
}
|
|
92
|
+
} // namespace BWE
|
|
93
|
+
} // namespace RTC
|