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
|
@@ -8,18 +8,37 @@ namespace bweHelpers
|
|
|
8
8
|
{
|
|
9
9
|
/* Static. */
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
|
|
11
|
+
// Lowest capacity the link can be given, which is what keeps the transmission
|
|
12
|
+
// time below from dividing by a capacity of zero bits per millisecond.
|
|
13
|
+
static constexpr int64_t MinCapacityBps{ 1000 };
|
|
14
|
+
// Offset added to the send times so that they don't share the origin with the
|
|
15
|
+
// arrival ones, which would hide a mistake mixing both references.
|
|
16
|
+
static constexpr int64_t SendSideOffsetUs{ 1000 * 1000 };
|
|
13
17
|
|
|
14
18
|
/* Instance methods. */
|
|
15
19
|
|
|
16
|
-
RtpStream::RtpStream(
|
|
20
|
+
RtpStream::RtpStream(
|
|
21
|
+
int fps, int64_t bitrateBps, uint32_t ssrc, uint32_t frequency, uint32_t rtpTimestampOffset)
|
|
22
|
+
: fps(fps),
|
|
23
|
+
ssrc(ssrc),
|
|
24
|
+
frequency(frequency),
|
|
25
|
+
rtpTimestampOffset(rtpTimestampOffset),
|
|
26
|
+
bitrateBps(bitrateBps)
|
|
17
27
|
{
|
|
18
28
|
MS_TRACE();
|
|
19
29
|
|
|
20
30
|
MS_ASSERT(fps > 0, "fps must be greater than zero [fps:%d]", fps);
|
|
21
31
|
}
|
|
22
32
|
|
|
33
|
+
void RtpStream::SetBitrateBps(int64_t bitrateBps)
|
|
34
|
+
{
|
|
35
|
+
MS_TRACE();
|
|
36
|
+
|
|
37
|
+
MS_ASSERT(bitrateBps >= 0, "bitrate must not be negative [bitrate:%" PRIi64 "]", bitrateBps);
|
|
38
|
+
|
|
39
|
+
this->bitrateBps = bitrateBps;
|
|
40
|
+
}
|
|
41
|
+
|
|
23
42
|
int64_t RtpStream::GenerateFrame(
|
|
24
43
|
int64_t timeNowUs,
|
|
25
44
|
int64_t& nextSequenceNumber,
|
|
@@ -27,38 +46,54 @@ namespace bweHelpers
|
|
|
27
46
|
{
|
|
28
47
|
MS_TRACE();
|
|
29
48
|
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
return this->nextRtpTimeUs;
|
|
33
|
-
}
|
|
49
|
+
std::vector<Packet> packets;
|
|
34
50
|
|
|
35
|
-
const
|
|
36
|
-
const size_t numPackets = std::max<size_t>((bitsPerFrame + (4 * Mtu)) / (8 * Mtu), 1);
|
|
37
|
-
const size_t payloadSize = (bitsPerFrame + (4 * numPackets)) / (8 * numPackets);
|
|
51
|
+
const int64_t nextRtpTimeUs = GenerateFrame(timeNowUs, packets);
|
|
38
52
|
|
|
39
|
-
for (
|
|
53
|
+
for (const auto& packet : packets)
|
|
40
54
|
{
|
|
41
55
|
RTC::BWE::Types::PacketResult packetResult;
|
|
42
56
|
|
|
43
|
-
packetResult.sentPacket.sendTimeUs =
|
|
44
|
-
packetResult.sentPacket.size =
|
|
57
|
+
packetResult.sentPacket.sendTimeUs = packet.sendTimeUs;
|
|
58
|
+
packetResult.sentPacket.size = packet.size;
|
|
45
59
|
packetResult.sentPacket.sequenceNumber = nextSequenceNumber++;
|
|
46
60
|
|
|
47
61
|
packetResults.push_back(packetResult);
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return this->nextRtpTimeUs;
|
|
64
|
+
return nextRtpTimeUs;
|
|
53
65
|
}
|
|
54
66
|
|
|
55
|
-
|
|
67
|
+
int64_t RtpStream::GenerateFrame(int64_t timeNowUs, std::vector<Packet>& packets)
|
|
56
68
|
{
|
|
57
69
|
MS_TRACE();
|
|
58
70
|
|
|
59
|
-
|
|
71
|
+
if (timeNowUs < this->nextRtpTimeUs)
|
|
72
|
+
{
|
|
73
|
+
return this->nextRtpTimeUs;
|
|
74
|
+
}
|
|
60
75
|
|
|
61
|
-
this->bitrateBps
|
|
76
|
+
const size_t bitsPerFrame = (this->bitrateBps + (this->fps / 2)) / this->fps;
|
|
77
|
+
const size_t numPackets = std::max<size_t>((bitsPerFrame + (4 * Mtu)) / (8 * Mtu), 1);
|
|
78
|
+
const size_t payloadSize = (bitsPerFrame + (4 * numPackets)) / (8 * numPackets);
|
|
79
|
+
const int64_t sendTimeUs = timeNowUs + SendSideOffsetUs;
|
|
80
|
+
const auto rtpTimestamp =
|
|
81
|
+
this->rtpTimestampOffset +
|
|
82
|
+
static_cast<uint32_t>((((this->frequency / 1000) * sendTimeUs) + 500) / 1000);
|
|
83
|
+
|
|
84
|
+
for (size_t idx{ 0 }; idx < numPackets; ++idx)
|
|
85
|
+
{
|
|
86
|
+
packets.push_back(
|
|
87
|
+
Packet{ .ssrc = this->ssrc,
|
|
88
|
+
.rtpTimestamp = rtpTimestamp,
|
|
89
|
+
.sendTimeUs = sendTimeUs,
|
|
90
|
+
.arrivalTimeUs = 0,
|
|
91
|
+
.size = payloadSize });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this->nextRtpTimeUs = timeNowUs + ((1000000 + (this->fps / 2)) / this->fps);
|
|
95
|
+
|
|
96
|
+
return this->nextRtpTimeUs;
|
|
62
97
|
}
|
|
63
98
|
|
|
64
99
|
bool RtpStream::Compare(const std::unique_ptr<RtpStream>& lhs, const std::unique_ptr<RtpStream>& rhs)
|
|
@@ -72,6 +107,11 @@ namespace bweHelpers
|
|
|
72
107
|
: capacityBps(capacityBps), prevArrivalTimeUs(timeNowUs)
|
|
73
108
|
{
|
|
74
109
|
MS_TRACE();
|
|
110
|
+
|
|
111
|
+
MS_ASSERT(
|
|
112
|
+
capacityBps >= MinCapacityBps,
|
|
113
|
+
"capacity must be at least one bit per millisecond [capacity:%" PRIi64 "]",
|
|
114
|
+
capacityBps);
|
|
75
115
|
}
|
|
76
116
|
|
|
77
117
|
void LinkSimulator::AddStream(std::unique_ptr<RtpStream> stream)
|
|
@@ -86,11 +126,28 @@ namespace bweHelpers
|
|
|
86
126
|
MS_TRACE();
|
|
87
127
|
|
|
88
128
|
MS_ASSERT(
|
|
89
|
-
capacityBps
|
|
129
|
+
capacityBps >= MinCapacityBps,
|
|
130
|
+
"capacity must be at least one bit per millisecond [capacity:%" PRIi64 "]",
|
|
131
|
+
capacityBps);
|
|
90
132
|
|
|
91
133
|
this->capacityBps = capacityBps;
|
|
92
134
|
}
|
|
93
135
|
|
|
136
|
+
void LinkSimulator::SetRtpTimestampOffset(uint32_t ssrc, uint32_t rtpTimestampOffset)
|
|
137
|
+
{
|
|
138
|
+
MS_TRACE();
|
|
139
|
+
|
|
140
|
+
for (auto& stream : this->streams)
|
|
141
|
+
{
|
|
142
|
+
if (stream->GetSsrc() == ssrc)
|
|
143
|
+
{
|
|
144
|
+
stream->SetRtpTimestampOffset(rtpTimestampOffset);
|
|
145
|
+
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
94
151
|
void LinkSimulator::SetBitrateBps(int64_t bitrateBps)
|
|
95
152
|
{
|
|
96
153
|
MS_TRACE();
|
|
@@ -139,22 +196,21 @@ namespace bweHelpers
|
|
|
139
196
|
MS_TRACE();
|
|
140
197
|
|
|
141
198
|
MS_ASSERT(packetResults.empty(), "the given vector is not empty");
|
|
199
|
+
MS_ASSERT(!this->streams.empty(), "no stream to generate a frame of");
|
|
142
200
|
MS_ASSERT(
|
|
143
|
-
this->capacityBps
|
|
144
|
-
"capacity must be
|
|
201
|
+
this->capacityBps >= MinCapacityBps,
|
|
202
|
+
"capacity must be at least one bit per millisecond [capacity:%" PRIi64 "]",
|
|
145
203
|
this->capacityBps);
|
|
146
204
|
|
|
147
205
|
auto it = std::ranges::min_element(this->streams, RtpStream::Compare);
|
|
148
206
|
|
|
149
|
-
|
|
207
|
+
auto& dueStream = *it;
|
|
208
|
+
|
|
209
|
+
dueStream->GenerateFrame(timeNowUs, nextSequenceNumber, packetResults);
|
|
150
210
|
|
|
151
211
|
for (auto& packetResult : packetResults)
|
|
152
212
|
{
|
|
153
|
-
|
|
154
|
-
const int64_t capacityBpUs = this->capacityBps / 1000;
|
|
155
|
-
const int64_t requiredNetworkTimeUs =
|
|
156
|
-
((8 * 1000 * static_cast<int64_t>(packetResult.sentPacket.size)) + (capacityBpUs / 2)) /
|
|
157
|
-
capacityBpUs;
|
|
213
|
+
const int64_t requiredNetworkTimeUs = GetRequiredNetworkTimeUs(packetResult.sentPacket.size);
|
|
158
214
|
|
|
159
215
|
// A packet arrives once the link is free again, so it queues behind the
|
|
160
216
|
// previous one whenever the stream is sending above the capacity.
|
|
@@ -166,6 +222,54 @@ namespace bweHelpers
|
|
|
166
222
|
|
|
167
223
|
it = std::ranges::min_element(this->streams, RtpStream::Compare);
|
|
168
224
|
|
|
169
|
-
|
|
225
|
+
auto& nextDueStream = *it;
|
|
226
|
+
|
|
227
|
+
return std::max(nextDueStream->GetNextRtpTimeUs(), timeNowUs);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
int64_t LinkSimulator::GenerateFrame(int64_t timeNowUs, std::vector<Packet>& packets)
|
|
231
|
+
{
|
|
232
|
+
MS_TRACE();
|
|
233
|
+
|
|
234
|
+
MS_ASSERT(packets.empty(), "the given vector is not empty");
|
|
235
|
+
MS_ASSERT(!this->streams.empty(), "no stream to generate a frame of");
|
|
236
|
+
MS_ASSERT(
|
|
237
|
+
this->capacityBps >= MinCapacityBps,
|
|
238
|
+
"capacity must be at least one bit per millisecond [capacity:%" PRIi64 "]",
|
|
239
|
+
this->capacityBps);
|
|
240
|
+
|
|
241
|
+
auto it = std::ranges::min_element(this->streams, RtpStream::Compare);
|
|
242
|
+
|
|
243
|
+
auto& dueStream = *it;
|
|
244
|
+
|
|
245
|
+
dueStream->GenerateFrame(timeNowUs, packets);
|
|
246
|
+
|
|
247
|
+
for (auto& packet : packets)
|
|
248
|
+
{
|
|
249
|
+
const int64_t requiredNetworkTimeUs = GetRequiredNetworkTimeUs(packet.size);
|
|
250
|
+
|
|
251
|
+
// A packet arrives once the link is free again, so it queues behind the
|
|
252
|
+
// previous one whenever the stream is sending above the capacity.
|
|
253
|
+
this->prevArrivalTimeUs =
|
|
254
|
+
std::max(timeNowUs + requiredNetworkTimeUs, this->prevArrivalTimeUs + requiredNetworkTimeUs);
|
|
255
|
+
|
|
256
|
+
packet.arrivalTimeUs = this->prevArrivalTimeUs;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
it = std::ranges::min_element(this->streams, RtpStream::Compare);
|
|
260
|
+
|
|
261
|
+
auto& nextDueStream = *it;
|
|
262
|
+
|
|
263
|
+
return std::max(nextDueStream->GetNextRtpTimeUs(), timeNowUs);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
int64_t LinkSimulator::GetRequiredNetworkTimeUs(size_t size) const
|
|
267
|
+
{
|
|
268
|
+
MS_TRACE();
|
|
269
|
+
|
|
270
|
+
// Time the link needs to put a packet of that size on the wire.
|
|
271
|
+
const int64_t capacityBpUs = this->capacityBps / 1000;
|
|
272
|
+
|
|
273
|
+
return ((8 * 1000 * static_cast<int64_t>(size)) + (capacityBpUs / 2)) / capacityBpUs;
|
|
170
274
|
}
|
|
171
275
|
} // namespace bweHelpers
|