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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#include "DepLibUV.hpp"
|
|
2
1
|
#include "RTC/RTP/Codecs/PayloadDescriptorHandler.hpp"
|
|
3
2
|
#include "RTC/RTP/RtpStreamRecv.hpp"
|
|
4
3
|
#include "RTC/SimpleProducerStreamManager.hpp"
|
|
@@ -139,12 +138,20 @@ namespace
|
|
|
139
138
|
// RtpStreamRecvListener must outlive the RtpStreamRecv.
|
|
140
139
|
RtpStreamRecvListener streamRecvListener; // NOLINT(readability-identifier-naming)
|
|
141
140
|
|
|
141
|
+
// Milliseconds between the packets fed by feedRtpStreamRecv() below.
|
|
142
|
+
constexpr int64_t PacketSpacingMs{ 1 };
|
|
143
|
+
|
|
144
|
+
// Current time, which the helpers below move so that traffic spans a period
|
|
145
|
+
// instead of happening all at once.
|
|
146
|
+
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
147
|
+
int64_t nowUs{ 1000000000000 };
|
|
148
|
+
|
|
142
149
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
143
150
|
mocks::MockShared shared(/*getTimeUs*/
|
|
144
151
|
[]() -> int64_t
|
|
145
152
|
{
|
|
146
|
-
return
|
|
147
|
-
});
|
|
153
|
+
return nowUs;
|
|
154
|
+
});
|
|
148
155
|
|
|
149
156
|
std::unique_ptr<RTC::SimpleProducerStreamManager> createManager(
|
|
150
157
|
MockListener* listener,
|
|
@@ -179,7 +186,9 @@ namespace
|
|
|
179
186
|
std::addressof(streamRecvListener), std::addressof(shared), params, 0u, false);
|
|
180
187
|
}
|
|
181
188
|
|
|
182
|
-
// Feed packets into the RtpStreamRecv so GetBitrate() returns non-zero.
|
|
189
|
+
// Feed packets into the RtpStreamRecv so GetBitrate() returns non-zero. They
|
|
190
|
+
// are spread in time because a bitrate is measured over the period its samples
|
|
191
|
+
// span, and samples taken all at once span none.
|
|
183
192
|
void feedRtpStreamRecv(RTC::RTP::RtpStreamRecv* rtpStream, RTC::RTP::Packet* packet, uint16_t count)
|
|
184
193
|
{
|
|
185
194
|
auto firstSeq = static_cast<uint16_t>(packet->GetSequenceNumber() + 1);
|
|
@@ -187,18 +196,27 @@ namespace
|
|
|
187
196
|
|
|
188
197
|
for (uint16_t seq = firstSeq; Utils::Number::IsLowerThan<uint16_t>(seq, lastSeq); ++seq)
|
|
189
198
|
{
|
|
199
|
+
if (seq != firstSeq)
|
|
200
|
+
{
|
|
201
|
+
nowUs += PacketSpacingMs * 1000;
|
|
202
|
+
}
|
|
203
|
+
|
|
190
204
|
packet->SetSequenceNumber(seq);
|
|
191
205
|
rtpStream->ReceivePacket(packet, shared.GetTimeUs());
|
|
192
206
|
}
|
|
193
207
|
|
|
194
|
-
|
|
208
|
+
// The packets span the gaps between them plus the millisecond the first one
|
|
209
|
+
// was taken in.
|
|
210
|
+
const auto periodMs = static_cast<double>(((count - 1) * PacketSpacingMs) + 1);
|
|
195
211
|
|
|
196
|
-
// bitrate (bps) =
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
|
|
212
|
+
// bitrate (bps) = bytes * 8000 / periodMs, where the packet that starts the
|
|
213
|
+
// period is left out of the bytes because the period does not cover the time
|
|
214
|
+
// it took to arrive.
|
|
215
|
+
const auto expectedBitrate = static_cast<int64_t>(std::trunc(
|
|
216
|
+
((static_cast<double>(count - 1) * static_cast<double>(packet->GetLength()) * 8000.0) / periodMs) +
|
|
217
|
+
0.5));
|
|
200
218
|
|
|
201
|
-
REQUIRE(rtpStream->GetBitrate(
|
|
219
|
+
REQUIRE(rtpStream->GetBitrate(shared.GetTimeMs()) == expectedBitrate);
|
|
202
220
|
}
|
|
203
221
|
} // namespace
|
|
204
222
|
|
|
@@ -411,7 +429,7 @@ SCENARIO("SimpleProducerStreamManager", "[rtp][producerstreammanager][simple]")
|
|
|
411
429
|
// Feed packets so the stream has non-zero bitrate.
|
|
412
430
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
413
431
|
|
|
414
|
-
const int64_t nowMs =
|
|
432
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
415
433
|
const auto streamBitrate = rtpStream->GetBitrate(nowMs);
|
|
416
434
|
const auto usedBitrate = manager->IncreaseLayer(
|
|
417
435
|
/*bitrate*/ streamBitrate + 1, /*considerLoss*/ false, /*lossPercentage*/ 0.0f, nowMs);
|
|
@@ -432,7 +450,7 @@ SCENARIO("SimpleProducerStreamManager", "[rtp][producerstreammanager][simple]")
|
|
|
432
450
|
// Feed packets so the stream has non-zero bitrate.
|
|
433
451
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
434
452
|
|
|
435
|
-
const int64_t nowMs =
|
|
453
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
436
454
|
const auto streamBitrate = rtpStream->GetBitrate(nowMs);
|
|
437
455
|
const int64_t availableBitrate = streamBitrate - 1;
|
|
438
456
|
auto usedBitrate = manager->IncreaseLayer(
|
|
@@ -454,7 +472,7 @@ SCENARIO("SimpleProducerStreamManager", "[rtp][producerstreammanager][simple]")
|
|
|
454
472
|
// Feed packets so the stream has non-zero bitrate.
|
|
455
473
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
456
474
|
|
|
457
|
-
const int64_t nowMs =
|
|
475
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
458
476
|
|
|
459
477
|
// First call claims bitrate.
|
|
460
478
|
auto usedBitrate = manager->IncreaseLayer(
|
|
@@ -482,7 +500,7 @@ SCENARIO("SimpleProducerStreamManager", "[rtp][producerstreammanager][simple]")
|
|
|
482
500
|
// Feed packets so the stream has non-zero bitrate.
|
|
483
501
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
484
502
|
|
|
485
|
-
const int64_t nowMs =
|
|
503
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
486
504
|
|
|
487
505
|
// First iteration: claim bitrate and apply.
|
|
488
506
|
manager->IncreaseLayer(
|
|
@@ -509,7 +527,7 @@ SCENARIO("SimpleProducerStreamManager", "[rtp][producerstreammanager][simple]")
|
|
|
509
527
|
// Feed packets so the stream has non-zero bitrate.
|
|
510
528
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
511
529
|
|
|
512
|
-
const int64_t nowMs =
|
|
530
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
513
531
|
const auto streamBitrate = rtpStream->GetBitrate(nowMs);
|
|
514
532
|
const auto desiredBitrate = manager->GetDesiredBitrate(nowMs);
|
|
515
533
|
|
|
@@ -530,7 +548,7 @@ SCENARIO("SimpleProducerStreamManager", "[rtp][producerstreammanager][simple]")
|
|
|
530
548
|
// Feed packets so the stream has non-zero bitrate.
|
|
531
549
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
532
550
|
|
|
533
|
-
const int64_t nowMs =
|
|
551
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
534
552
|
auto desiredBitrate = manager->GetDesiredBitrate(nowMs);
|
|
535
553
|
|
|
536
554
|
REQUIRE(desiredBitrate == 0);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#include "DepLibUV.hpp"
|
|
2
1
|
#include "RTC/RTCP/SenderReport.hpp"
|
|
3
2
|
#include "RTC/RTP/Codecs/PayloadDescriptorHandler.hpp"
|
|
4
3
|
#include "RTC/RTP/RtpStreamRecv.hpp"
|
|
@@ -148,12 +147,20 @@ namespace
|
|
|
148
147
|
// RtpStreamRecvListener must outlive the RtpStreamRecv.
|
|
149
148
|
RtpStreamRecvListener streamRecvListener; // NOLINT(readability-identifier-naming)
|
|
150
149
|
|
|
150
|
+
// Milliseconds between the packets fed by feedRtpStreamRecv() below.
|
|
151
|
+
constexpr int64_t PacketSpacingMs{ 1 };
|
|
152
|
+
|
|
153
|
+
// Current time, which the helpers below move so that traffic spans a period
|
|
154
|
+
// instead of happening all at once.
|
|
155
|
+
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
156
|
+
int64_t nowUs{ 1000000000000 };
|
|
157
|
+
|
|
151
158
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
152
159
|
mocks::MockShared shared(/*getTimeUs*/
|
|
153
160
|
[]() -> int64_t
|
|
154
161
|
{
|
|
155
|
-
return
|
|
156
|
-
});
|
|
162
|
+
return nowUs;
|
|
163
|
+
});
|
|
157
164
|
|
|
158
165
|
std::unique_ptr<RTC::SimulcastProducerStreamManager> createManager(
|
|
159
166
|
MockListener* listener,
|
|
@@ -198,7 +205,9 @@ namespace
|
|
|
198
205
|
std::addressof(streamRecvListener), std::addressof(shared), params, 0u, false);
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
// Feed packets into the RtpStreamRecv so GetBitrate() returns non-zero.
|
|
208
|
+
// Feed packets into the RtpStreamRecv so GetBitrate() returns non-zero. They
|
|
209
|
+
// are spread in time because a bitrate is measured over the period its samples
|
|
210
|
+
// span, and samples taken all at once span none.
|
|
202
211
|
void feedRtpStreamRecv(RTC::RTP::RtpStreamRecv* rtpStream, RTC::RTP::Packet* packet, uint16_t count)
|
|
203
212
|
{
|
|
204
213
|
auto firstSeq = static_cast<uint16_t>(packet->GetSequenceNumber() + 1);
|
|
@@ -206,18 +215,27 @@ namespace
|
|
|
206
215
|
|
|
207
216
|
for (uint16_t seq = firstSeq; Utils::Number::IsLowerThan<uint16_t>(seq, lastSeq); ++seq)
|
|
208
217
|
{
|
|
218
|
+
if (seq != firstSeq)
|
|
219
|
+
{
|
|
220
|
+
nowUs += PacketSpacingMs * 1000;
|
|
221
|
+
}
|
|
222
|
+
|
|
209
223
|
packet->SetSequenceNumber(seq);
|
|
210
224
|
rtpStream->ReceivePacket(packet, shared.GetTimeUs());
|
|
211
225
|
}
|
|
212
226
|
|
|
213
|
-
|
|
227
|
+
// The packets span the gaps between them plus the millisecond the first one
|
|
228
|
+
// was taken in.
|
|
229
|
+
const auto periodMs = static_cast<double>(((count - 1) * PacketSpacingMs) + 1);
|
|
214
230
|
|
|
215
|
-
// bitrate (bps) =
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
231
|
+
// bitrate (bps) = bytes * 8000 / periodMs, where the packet that starts the
|
|
232
|
+
// period is left out of the bytes because the period does not cover the time
|
|
233
|
+
// it took to arrive.
|
|
234
|
+
const auto expectedBitrate = static_cast<int64_t>(std::trunc(
|
|
235
|
+
((static_cast<double>(count - 1) * static_cast<double>(packet->GetLength()) * 8000.0) / periodMs) +
|
|
236
|
+
0.5));
|
|
219
237
|
|
|
220
|
-
REQUIRE(rtpStream->GetBitrate(
|
|
238
|
+
REQUIRE(rtpStream->GetBitrate(shared.GetTimeMs()) == expectedBitrate);
|
|
221
239
|
}
|
|
222
240
|
} // namespace
|
|
223
241
|
|
|
@@ -1236,7 +1254,7 @@ SCENARIO("SimulcastProducerStreamManager", "[rtp][producerstreammanager][simulca
|
|
|
1236
1254
|
packet->SetSsrc(MappedSsrc0);
|
|
1237
1255
|
feedRtpStreamRecv(rtpStream0.get(), packet.get(), 100);
|
|
1238
1256
|
|
|
1239
|
-
const int64_t nowMs =
|
|
1257
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1240
1258
|
|
|
1241
1259
|
// First call claims bitrate.
|
|
1242
1260
|
auto usedBitrate = manager->IncreaseLayer(
|
|
@@ -1267,7 +1285,7 @@ SCENARIO("SimulcastProducerStreamManager", "[rtp][producerstreammanager][simulca
|
|
|
1267
1285
|
packet->SetSsrc(MappedSsrc0);
|
|
1268
1286
|
feedRtpStreamRecv(rtpStream0.get(), packet.get(), 100);
|
|
1269
1287
|
|
|
1270
|
-
const int64_t nowMs =
|
|
1288
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1271
1289
|
|
|
1272
1290
|
// First iteration: claim layer 0.
|
|
1273
1291
|
manager->IncreaseLayer(
|
|
@@ -1304,7 +1322,7 @@ SCENARIO("SimulcastProducerStreamManager", "[rtp][producerstreammanager][simulca
|
|
|
1304
1322
|
packet->SetSsrc(MappedSsrc1);
|
|
1305
1323
|
feedRtpStreamRecv(rtpStream1.get(), packet.get(), 100);
|
|
1306
1324
|
|
|
1307
|
-
const int64_t nowMs =
|
|
1325
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1308
1326
|
auto bitrate0 = rtpStream0->GetBitrate(nowMs);
|
|
1309
1327
|
auto bitrate1 = rtpStream1->GetBitrate(nowMs);
|
|
1310
1328
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#include "DepLibUV.hpp"
|
|
2
1
|
#include "RTC/RTP/Codecs/PayloadDescriptorHandler.hpp"
|
|
3
2
|
#include "RTC/RTP/RtpStreamRecv.hpp"
|
|
4
3
|
#include "RTC/SvcProducerStreamManager.hpp"
|
|
@@ -154,12 +153,20 @@ namespace
|
|
|
154
153
|
// RtpStreamRecvListener must outlive the RtpStreamRecv.
|
|
155
154
|
RtpStreamRecvListener streamRecvListener; // NOLINT(readability-identifier-naming)
|
|
156
155
|
|
|
156
|
+
// Milliseconds between the packets fed by feedRtpStreamRecv() below.
|
|
157
|
+
constexpr int64_t PacketSpacingMs{ 1 };
|
|
158
|
+
|
|
159
|
+
// Current time, which the helpers below move so that traffic spans a period
|
|
160
|
+
// instead of happening all at once.
|
|
161
|
+
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
162
|
+
int64_t nowUs{ 1000000000000 };
|
|
163
|
+
|
|
157
164
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
158
165
|
mocks::MockShared shared(/*getTimeUs*/
|
|
159
166
|
[]() -> int64_t
|
|
160
167
|
{
|
|
161
|
-
return
|
|
162
|
-
});
|
|
168
|
+
return nowUs;
|
|
169
|
+
});
|
|
163
170
|
|
|
164
171
|
std::unique_ptr<RTC::SvcProducerStreamManager> createManager(
|
|
165
172
|
MockListener* listener,
|
|
@@ -201,7 +208,9 @@ namespace
|
|
|
201
208
|
std::addressof(streamRecvListener), std::addressof(shared), params, 0u, false);
|
|
202
209
|
}
|
|
203
210
|
|
|
204
|
-
// Feed packets into the RtpStreamRecv so GetBitrate() returns non-zero.
|
|
211
|
+
// Feed packets into the RtpStreamRecv so GetBitrate() returns non-zero. They
|
|
212
|
+
// are spread in time because a bitrate is measured over the period its samples
|
|
213
|
+
// span, and samples taken all at once span none.
|
|
205
214
|
void feedRtpStreamRecv(RTC::RTP::RtpStreamRecv* rtpStream, RTC::RTP::Packet* packet, uint16_t count)
|
|
206
215
|
{
|
|
207
216
|
auto firstSeq = static_cast<uint16_t>(packet->GetSequenceNumber() + 1);
|
|
@@ -209,18 +218,27 @@ namespace
|
|
|
209
218
|
|
|
210
219
|
for (uint16_t seq = firstSeq; Utils::Number::IsLowerThan<uint16_t>(seq, lastSeq); ++seq)
|
|
211
220
|
{
|
|
221
|
+
if (seq != firstSeq)
|
|
222
|
+
{
|
|
223
|
+
nowUs += PacketSpacingMs * 1000;
|
|
224
|
+
}
|
|
225
|
+
|
|
212
226
|
packet->SetSequenceNumber(seq);
|
|
213
227
|
rtpStream->ReceivePacket(packet, shared.GetTimeUs());
|
|
214
228
|
}
|
|
215
229
|
|
|
216
|
-
|
|
230
|
+
// The packets span the gaps between them plus the millisecond the first one
|
|
231
|
+
// was taken in.
|
|
232
|
+
const auto periodMs = static_cast<double>(((count - 1) * PacketSpacingMs) + 1);
|
|
217
233
|
|
|
218
|
-
// bitrate (bps) =
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
234
|
+
// bitrate (bps) = bytes * 8000 / periodMs, where the packet that starts the
|
|
235
|
+
// period is left out of the bytes because the period does not cover the time
|
|
236
|
+
// it took to arrive.
|
|
237
|
+
const auto expectedBitrate = static_cast<int64_t>(std::trunc(
|
|
238
|
+
((static_cast<double>(count - 1) * static_cast<double>(packet->GetLength()) * 8000.0) / periodMs) +
|
|
239
|
+
0.5));
|
|
222
240
|
|
|
223
|
-
REQUIRE(rtpStream->GetBitrate(
|
|
241
|
+
REQUIRE(rtpStream->GetBitrate(shared.GetTimeMs()) == expectedBitrate);
|
|
224
242
|
}
|
|
225
243
|
} // namespace
|
|
226
244
|
|
|
@@ -943,7 +961,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
943
961
|
|
|
944
962
|
manager->SetExternallyManagedBitrate();
|
|
945
963
|
|
|
946
|
-
const int64_t nowMs =
|
|
964
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
947
965
|
auto usedBitrate = manager->IncreaseLayer(
|
|
948
966
|
/*bitrate*/ 1000000, /*considerLoss*/ false, /*lossPercentage*/ 0.0f, nowMs);
|
|
949
967
|
|
|
@@ -960,7 +978,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
960
978
|
manager->SetExternallyManagedBitrate();
|
|
961
979
|
|
|
962
980
|
// Score is 0 by default (no RTP received + inactivity check disabled).
|
|
963
|
-
const int64_t nowMs =
|
|
981
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
964
982
|
auto usedBitrate = manager->IncreaseLayer(
|
|
965
983
|
/*bitrate*/ 1000000, /*considerLoss*/ false, /*lossPercentage*/ 0.0f, nowMs);
|
|
966
984
|
|
|
@@ -987,7 +1005,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
987
1005
|
// Feed packets so the stream has non-zero bitrate.
|
|
988
1006
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
989
1007
|
|
|
990
|
-
const int64_t nowMs =
|
|
1008
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
991
1009
|
|
|
992
1010
|
// First call claims bitrate.
|
|
993
1011
|
auto usedBitrate = manager->IncreaseLayer(
|
|
@@ -1021,7 +1039,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
1021
1039
|
// Feed packets so the stream has non-zero bitrate.
|
|
1022
1040
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
1023
1041
|
|
|
1024
|
-
const int64_t nowMs =
|
|
1042
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1025
1043
|
|
|
1026
1044
|
// First iteration.
|
|
1027
1045
|
manager->IncreaseLayer(
|
|
@@ -1082,7 +1100,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
1082
1100
|
MockListener listener;
|
|
1083
1101
|
auto manager = createManager(std::addressof(listener));
|
|
1084
1102
|
|
|
1085
|
-
const int64_t nowMs =
|
|
1103
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1086
1104
|
auto desiredBitrate = manager->GetDesiredBitrate(nowMs);
|
|
1087
1105
|
|
|
1088
1106
|
REQUIRE(desiredBitrate == 0);
|
|
@@ -1106,7 +1124,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
1106
1124
|
|
|
1107
1125
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
1108
1126
|
|
|
1109
|
-
const int64_t nowMs =
|
|
1127
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1110
1128
|
auto streamBitrate = rtpStream->GetBitrate(nowMs);
|
|
1111
1129
|
auto desiredBitrate = manager->GetDesiredBitrate(nowMs);
|
|
1112
1130
|
|
|
@@ -1132,7 +1150,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
1132
1150
|
// Feed packets so total stream bitrate > 0.
|
|
1133
1151
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
1134
1152
|
|
|
1135
|
-
const int64_t nowMs =
|
|
1153
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1136
1154
|
auto desiredBitrate = manager->GetDesiredBitrate(nowMs);
|
|
1137
1155
|
|
|
1138
1156
|
// K-SVC returns the max per-spatial-layer bitrate. With a plain RtpStreamRecv
|
|
@@ -1243,7 +1261,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
1243
1261
|
|
|
1244
1262
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
1245
1263
|
|
|
1246
|
-
const int64_t nowMs =
|
|
1264
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1247
1265
|
auto streamBitrate = rtpStream->GetBitrate(nowMs);
|
|
1248
1266
|
|
|
1249
1267
|
// With 1% loss virtualBitrate = 1.08 * bitrate, so we can afford the stream
|
|
@@ -1274,7 +1292,7 @@ SCENARIO("SvcProducerStreamManager", "[rtp][producerstreammanager][svc]")
|
|
|
1274
1292
|
|
|
1275
1293
|
feedRtpStreamRecv(rtpStream.get(), packet.get(), 100);
|
|
1276
1294
|
|
|
1277
|
-
const int64_t nowMs =
|
|
1295
|
+
const int64_t nowMs = shared.GetTimeMs();
|
|
1278
1296
|
auto streamBitrate = rtpStream->GetBitrate(nowMs);
|
|
1279
1297
|
|
|
1280
1298
|
// With 50% loss virtualBitrate = (1 - 0.5*0.5) * bitrate = 0.75 * bitrate.
|
|
@@ -186,10 +186,10 @@ SCENARIO("TransportCongestionControlServer", "[rtp]")
|
|
|
186
186
|
// clang-format off
|
|
187
187
|
std::vector<TestTransportCongestionControlServerInput> inputs
|
|
188
188
|
{
|
|
189
|
-
{
|
|
190
|
-
{
|
|
191
|
-
{
|
|
192
|
-
{
|
|
189
|
+
{ 1u, 1000000 },
|
|
190
|
+
{ 3u, 1050000 },
|
|
191
|
+
{ 5u, 1100000 },
|
|
192
|
+
{ 6u, 1150000 },
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
TestResults results
|
|
@@ -215,12 +215,12 @@ SCENARIO("TransportCongestionControlServer", "[rtp]")
|
|
|
215
215
|
// clang-format off
|
|
216
216
|
std::vector<TestTransportCongestionControlServerInput> inputs
|
|
217
217
|
{
|
|
218
|
-
{
|
|
219
|
-
{
|
|
220
|
-
{
|
|
221
|
-
{
|
|
222
|
-
{
|
|
223
|
-
{
|
|
218
|
+
{ 1u, 1000000 },
|
|
219
|
+
{ 1u, 1050000 },
|
|
220
|
+
{ 2u, 1100000 },
|
|
221
|
+
{ 3u, 1150000 },
|
|
222
|
+
{ 3u, 1200000 },
|
|
223
|
+
{ 4u, 1250000 },
|
|
224
224
|
};
|
|
225
225
|
|
|
226
226
|
TestResults results
|
|
@@ -2,39 +2,138 @@
|
|
|
2
2
|
#include "DepLibUV.hpp"
|
|
3
3
|
#include "Utils.hpp"
|
|
4
4
|
#include <catch2/catch_test_macros.hpp>
|
|
5
|
+
#include <cstdlib> // std::abs()
|
|
6
|
+
#include <limits>
|
|
5
7
|
|
|
6
8
|
SCENARIO("Utils::Time", "[utils][time]")
|
|
7
9
|
{
|
|
8
|
-
SECTION("
|
|
10
|
+
SECTION("TimeUsToMs()")
|
|
11
|
+
{
|
|
12
|
+
REQUIRE(Utils::Time::TimeUsToMs(0) == 0);
|
|
13
|
+
REQUIRE(Utils::Time::TimeUsToMs(1000) == 1);
|
|
14
|
+
REQUIRE(Utils::Time::TimeUsToMs(1499) == 1);
|
|
15
|
+
// Halves upwards.
|
|
16
|
+
REQUIRE(Utils::Time::TimeUsToMs(1500) == 2);
|
|
17
|
+
REQUIRE(Utils::Time::TimeUsToMs(1501) == 2);
|
|
18
|
+
REQUIRE(Utils::Time::TimeUsToMs(3990000000750000) == 3990000000750);
|
|
19
|
+
|
|
20
|
+
// A negative instant rounds the same way, so halves still go upwards rather
|
|
21
|
+
// than towards zero.
|
|
22
|
+
REQUIRE(Utils::Time::TimeUsToMs(-1000) == -1);
|
|
23
|
+
REQUIRE(Utils::Time::TimeUsToMs(-1499) == -1);
|
|
24
|
+
REQUIRE(Utils::Time::TimeUsToMs(-1500) == -1);
|
|
25
|
+
REQUIRE(Utils::Time::TimeUsToMs(-1501) == -2);
|
|
26
|
+
REQUIRE(Utils::Time::TimeUsToMs(-500) == 0);
|
|
27
|
+
REQUIRE(Utils::Time::TimeUsToMs(-501) == -1);
|
|
28
|
+
|
|
29
|
+
// The extremes are rounded rather than overflowing.
|
|
30
|
+
REQUIRE(Utils::Time::TimeUsToMs(std::numeric_limits<int64_t>::max()) == 9223372036854776LL);
|
|
31
|
+
REQUIRE(Utils::Time::TimeUsToMs(std::numeric_limits<int64_t>::min()) == -9223372036854776LL);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
SECTION("NtpToTimeUs()")
|
|
9
35
|
{
|
|
10
36
|
const auto nowUs = DepLibUV::GetTimeUs();
|
|
11
|
-
const auto ntp = Utils::Time::
|
|
12
|
-
const auto nowUs2 = Utils::Time::
|
|
13
|
-
const auto ntp2 = Utils::Time::
|
|
37
|
+
const auto ntp = Utils::Time::TimeUsToNtp(nowUs);
|
|
38
|
+
const auto nowUs2 = Utils::Time::NtpToTimeUs(ntp);
|
|
39
|
+
const auto ntp2 = Utils::Time::TimeUsToNtp(nowUs2);
|
|
14
40
|
|
|
15
41
|
REQUIRE(nowUs2 == nowUs);
|
|
16
42
|
REQUIRE(ntp2.seconds == ntp.seconds);
|
|
17
43
|
REQUIRE(ntp2.fractions == ntp.fractions);
|
|
18
44
|
}
|
|
19
45
|
|
|
20
|
-
SECTION("
|
|
46
|
+
SECTION("TimeUsToNtp()")
|
|
21
47
|
{
|
|
22
|
-
auto ntp = Utils::Time::
|
|
48
|
+
auto ntp = Utils::Time::TimeUsToNtp(1500000);
|
|
23
49
|
|
|
24
50
|
REQUIRE(ntp.seconds == 1);
|
|
25
51
|
// Half a second in NTP fractional units.
|
|
26
52
|
REQUIRE(ntp.fractions == 2147483648);
|
|
27
53
|
|
|
28
54
|
// A real NTP instant, seconds since Jan 1, 1900, which still fits in 32 bits.
|
|
29
|
-
ntp = Utils::Time::
|
|
55
|
+
ntp = Utils::Time::TimeUsToNtp(3990000000750000);
|
|
30
56
|
|
|
31
57
|
REQUIRE(ntp.seconds == 3990000000);
|
|
32
|
-
REQUIRE(Utils::Time::
|
|
58
|
+
REQUIRE(Utils::Time::NtpToTimeUs(ntp) == 3990000000750000);
|
|
33
59
|
|
|
34
60
|
// Sub-millisecond times are kept.
|
|
35
|
-
REQUIRE(Utils::Time::
|
|
36
|
-
REQUIRE(Utils::Time::
|
|
37
|
-
REQUIRE(Utils::Time::
|
|
61
|
+
REQUIRE(Utils::Time::TimeUsToNtp(1000500).fractions > Utils::Time::TimeUsToNtp(1000000).fractions);
|
|
62
|
+
REQUIRE(Utils::Time::TimeUsToNtp(1000500).fractions < Utils::Time::TimeUsToNtp(1001000).fractions);
|
|
63
|
+
REQUIRE(Utils::Time::NtpToTimeUs(Utils::Time::TimeUsToNtp(1000500)) == 1000500);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Middle 32 bits of the given NTP timestamp.
|
|
67
|
+
auto toCompactNtp = [](uint32_t seconds, uint32_t fractions) -> uint32_t
|
|
68
|
+
{
|
|
69
|
+
return (seconds << 16) | (fractions >> 16);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
auto toTimeUs = [](uint32_t seconds, uint32_t fractions) -> int64_t
|
|
73
|
+
{
|
|
74
|
+
return Utils::Time::NtpToTimeUs(Utils::Time::Ntp{ .seconds = seconds, .fractions = fractions });
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
SECTION("CompactNtpIntervalToTimeUs()")
|
|
78
|
+
{
|
|
79
|
+
{
|
|
80
|
+
const int64_t diffUs = toTimeUs(0x12654, 0x64335) - toTimeUs(0x12345, 0x23456);
|
|
81
|
+
const uint32_t compactNtpDiff = toCompactNtp(0x12654, 0x64335) - toCompactNtp(0x12345, 0x23456);
|
|
82
|
+
|
|
83
|
+
REQUIRE(std::abs(Utils::Time::CompactNtpIntervalToTimeUs(compactNtpDiff) - diffUs) <= 1000);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The later timestamp has the lower compact NTP representation, which is fine as
|
|
87
|
+
// long as the difference is computed with unsigned arithmetic.
|
|
88
|
+
{
|
|
89
|
+
const int64_t diffUs = toTimeUs(0x20000, 0x64335) - toTimeUs(0x1ffff, 0x23456);
|
|
90
|
+
|
|
91
|
+
REQUIRE(diffUs > 0);
|
|
92
|
+
REQUIRE(toCompactNtp(0x20000, 0x64335) < toCompactNtp(0x1ffff, 0x23456));
|
|
93
|
+
|
|
94
|
+
const uint32_t compactNtpDiff = toCompactNtp(0x20000, 0x64335) - toCompactNtp(0x1ffff, 0x23456);
|
|
95
|
+
|
|
96
|
+
REQUIRE(std::abs(Utils::Time::CompactNtpIntervalToTimeUs(compactNtpDiff) - diffUs) <= 1000);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// A difference close to 2^16 seconds is a negative one.
|
|
100
|
+
{
|
|
101
|
+
const int64_t diffUs = toTimeUs(0x1ffff, 0x64335) - toTimeUs(0x20000, 0x23456);
|
|
102
|
+
|
|
103
|
+
REQUIRE(diffUs < 0);
|
|
104
|
+
|
|
105
|
+
const uint32_t compactNtpDiff = toCompactNtp(0x1ffff, 0x64335) - toCompactNtp(0x20000, 0x23456);
|
|
106
|
+
|
|
107
|
+
REQUIRE(std::abs(Utils::Time::CompactNtpIntervalToTimeUs(compactNtpDiff) - diffUs) <= 1000);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Right in the middle, both +2^15 and -2^15 seconds are valid results.
|
|
111
|
+
REQUIRE(std::abs(Utils::Time::CompactNtpIntervalToTimeUs(0x80000000)) == 0x8000 * 1000000LL);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
SECTION("CompactNtpRttToTimeUs()")
|
|
115
|
+
{
|
|
116
|
+
// A difference close to 2^15 seconds is still a positive one.
|
|
117
|
+
{
|
|
118
|
+
const int64_t diffUs = toTimeUs(0x17fff, 0xffff5) - toTimeUs(0x10000, 0x00006);
|
|
119
|
+
|
|
120
|
+
REQUIRE(std::abs(diffUs - (((1 << 15) - 1) * 1000000LL)) <= 1000);
|
|
121
|
+
|
|
122
|
+
const uint32_t compactNtpDiff = toCompactNtp(0x17fff, 0xffff5) - toCompactNtp(0x10000, 0x00006);
|
|
123
|
+
|
|
124
|
+
REQUIRE(std::abs(Utils::Time::CompactNtpRttToTimeUs(compactNtpDiff) - diffUs) <= 1000);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// A negative round trip time yields 1 millisecond.
|
|
128
|
+
{
|
|
129
|
+
const int64_t diffUs = toTimeUs(0x1ffff, 0x64335) - toTimeUs(0x20000, 0x23456);
|
|
130
|
+
|
|
131
|
+
REQUIRE(diffUs < 0);
|
|
132
|
+
|
|
133
|
+
const uint32_t compactNtpDiff = toCompactNtp(0x1ffff, 0x64335) - toCompactNtp(0x20000, 0x23456);
|
|
134
|
+
|
|
135
|
+
REQUIRE(Utils::Time::CompactNtpRttToTimeUs(compactNtpDiff) == 1000);
|
|
136
|
+
}
|
|
38
137
|
}
|
|
39
138
|
|
|
40
139
|
SECTION("TimeUsToAbsSendTime()")
|
|
@@ -63,25 +162,25 @@ SCENARIO("Utils::Time", "[utils][time]")
|
|
|
63
162
|
REQUIRE(Utils::Time::TimeUsToAbsSendTime(-WrapPeriodUs) == 0);
|
|
64
163
|
}
|
|
65
164
|
|
|
66
|
-
SECTION("
|
|
165
|
+
SECTION("TimeUsToQ32x32()")
|
|
67
166
|
{
|
|
68
167
|
// A whole second is the fractional unit itself.
|
|
69
168
|
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
70
|
-
REQUIRE(Utils::Time::
|
|
169
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(1000000).value() == 4294967296);
|
|
71
170
|
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
72
|
-
REQUIRE(Utils::Time::
|
|
171
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(-1000000).value() == -4294967296);
|
|
73
172
|
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
74
|
-
REQUIRE(Utils::Time::
|
|
173
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(0).value() == 0);
|
|
75
174
|
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
76
|
-
REQUIRE(Utils::Time::
|
|
175
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(1000).value() == 4294967);
|
|
77
176
|
|
|
78
177
|
// Seconds are 32 bits wide in the format, so 2^31 seconds no longer fit.
|
|
79
178
|
constexpr int64_t OutOfRangeUs{ (1LL << 31) * 1000000 };
|
|
80
179
|
|
|
81
|
-
REQUIRE(Utils::Time::
|
|
82
|
-
REQUIRE(Utils::Time::
|
|
83
|
-
REQUIRE(Utils::Time::
|
|
84
|
-
REQUIRE(Utils::Time::
|
|
180
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(OutOfRangeUs) == std::nullopt);
|
|
181
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(-OutOfRangeUs) == std::nullopt);
|
|
182
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(OutOfRangeUs - 1).has_value());
|
|
183
|
+
REQUIRE(Utils::Time::TimeUsToQ32x32(-OutOfRangeUs + 1).has_value());
|
|
85
184
|
}
|
|
86
185
|
|
|
87
186
|
SECTION("Q32x32ToTimeUs()")
|
|
@@ -93,7 +192,7 @@ SCENARIO("Utils::Time", "[utils][time]")
|
|
|
93
192
|
for (const int64_t us : { 1, -1, 1000, -1000, 1000000, -1000000, 123456789, -123456789 })
|
|
94
193
|
{
|
|
95
194
|
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
|
96
|
-
REQUIRE(Utils::Time::Q32x32ToTimeUs(Utils::Time::
|
|
195
|
+
REQUIRE(Utils::Time::Q32x32ToTimeUs(Utils::Time::TimeUsToQ32x32(us).value()) == us);
|
|
97
196
|
}
|
|
98
197
|
}
|
|
99
198
|
}
|