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.
Files changed (213) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/node/lib/Consumer.d.ts.map +1 -1
  3. package/node/lib/Consumer.js +4 -51
  4. package/node/lib/Producer.d.ts.map +1 -1
  5. package/node/lib/Producer.js +4 -8
  6. package/node/lib/ProducerTypes.d.ts +4 -2
  7. package/node/lib/ProducerTypes.d.ts.map +1 -1
  8. package/node/lib/Router.d.ts.map +1 -1
  9. package/node/lib/Router.js +4 -0
  10. package/node/lib/Transport.d.ts.map +1 -1
  11. package/node/lib/Transport.js +7 -10
  12. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts +3 -4
  13. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts.map +1 -1
  14. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.js +3 -4
  15. package/node/lib/ortc.d.ts +0 -2
  16. package/node/lib/ortc.d.ts.map +1 -1
  17. package/node/lib/ortc.js +11 -21
  18. package/node/lib/rtpMappingFbsUtils.d.ts +6 -0
  19. package/node/lib/rtpMappingFbsUtils.d.ts.map +1 -0
  20. package/node/lib/rtpMappingFbsUtils.js +65 -0
  21. package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
  22. package/node/lib/rtpParametersFbsUtils.js +0 -6
  23. package/node/lib/rtpParametersTypes.d.ts +1 -1
  24. package/node/lib/rtpParametersTypes.d.ts.map +1 -1
  25. package/node/lib/rtpStreamFbsUtils.d.ts +4 -0
  26. package/node/lib/rtpStreamFbsUtils.d.ts.map +1 -0
  27. package/node/lib/rtpStreamFbsUtils.js +51 -0
  28. package/node/lib/supportedRtpCapabilities.d.ts.map +1 -1
  29. package/node/lib/supportedRtpCapabilities.js +6 -13
  30. package/node/lib/test/test-Consumer.js +1 -13
  31. package/node/lib/test/test-DataConsumer.js +9 -0
  32. package/node/lib/test/test-DataProducer.js +38 -0
  33. package/node/lib/test/test-PipeTransport.js +27 -29
  34. package/node/lib/test/test-Producer.js +97 -0
  35. package/node/lib/test/test-ortc.js +34 -14
  36. package/package.json +10 -10
  37. package/worker/fbs/FBS/meson.build +25 -0
  38. package/worker/fbs/meson.build +15 -18
  39. package/worker/fbs/rtpParameters.fbs +0 -1
  40. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  41. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +16 -2
  42. package/worker/include/DepLibUV.hpp +13 -0
  43. package/worker/include/RTC/BWE/AlrDetector.hpp +97 -0
  44. package/worker/include/RTC/BWE/BitrateProber.hpp +217 -0
  45. package/worker/include/RTC/BWE/BitrateUtils.hpp +39 -0
  46. package/worker/include/RTC/BWE/BweTypes.hpp +171 -3
  47. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +0 -14
  48. package/worker/include/RTC/BWE/InterArrival.hpp +117 -0
  49. package/worker/include/RTC/BWE/IntervalBudget.hpp +81 -0
  50. package/worker/include/RTC/BWE/LossBasedController.hpp +625 -0
  51. package/worker/include/RTC/BWE/OveruseDetector.hpp +71 -0
  52. package/worker/include/RTC/BWE/OveruseEstimator.hpp +115 -0
  53. package/worker/include/RTC/BWE/ProbeBitrateEstimator.hpp +84 -0
  54. package/worker/include/RTC/BWE/ProbeController.hpp +379 -0
  55. package/worker/include/RTC/BWE/ProbePacketGenerator.hpp +130 -0
  56. package/worker/include/RTC/BWE/ProbingScheduler.hpp +187 -0
  57. package/worker/include/RTC/BWE/RembGenerator.hpp +96 -0
  58. package/worker/include/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp +237 -0
  59. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +26 -0
  60. package/worker/include/RTC/BWE/SendPacketHistory.hpp +161 -25
  61. package/worker/include/RTC/BWE/TargetRateController.hpp +306 -0
  62. package/worker/include/RTC/BWE/TransportWideCcFeedbackGenerator.hpp +146 -0
  63. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +73 -16
  64. package/worker/include/RTC/Consts.hpp +70 -0
  65. package/worker/include/RTC/DataConsumer.hpp +3 -5
  66. package/worker/include/RTC/DirectTransport.hpp +4 -5
  67. package/worker/include/RTC/PipeTransport.hpp +4 -5
  68. package/worker/include/RTC/PlainTransport.hpp +4 -5
  69. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +6 -7
  70. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +3 -1
  71. package/worker/include/RTC/RTP/Codecs/Tools.hpp +1 -1
  72. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +0 -1
  73. package/worker/include/RTC/RTP/Packet.hpp +16 -4
  74. package/worker/include/RTC/RTP/ProbationGenerator.hpp +0 -8
  75. package/worker/include/RTC/RTP/RtpStream.hpp +12 -9
  76. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +22 -4
  77. package/worker/include/RTC/RTP/RtpStreamSend.hpp +4 -2
  78. package/worker/include/RTC/RTP/RtxStream.hpp +10 -4
  79. package/worker/include/RTC/RateCalculator.hpp +103 -24
  80. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +33 -3
  81. package/worker/include/RTC/{RtcLogger.hpp → RtcLogger/RtpPacket.hpp} +5 -3
  82. package/worker/include/RTC/RtcLogger/SendBurst.hpp +88 -0
  83. package/worker/include/RTC/RtpDictionaries.hpp +3 -4
  84. package/worker/include/RTC/SCTP/association/Association.hpp +1 -1
  85. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +36 -0
  86. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +0 -1
  87. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +9 -9
  88. package/worker/include/RTC/SCTP/rx/DataTracker.hpp +1 -1
  89. package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +11 -1
  90. package/worker/include/RTC/SctpDictionaries.hpp +2 -2
  91. package/worker/include/RTC/TcpConnection.hpp +2 -1
  92. package/worker/include/RTC/Transport.hpp +23 -8
  93. package/worker/include/RTC/TransportTuple.hpp +61 -6
  94. package/worker/include/RTC/WebRtcTransport.hpp +4 -5
  95. package/worker/include/Shared.hpp +5 -0
  96. package/worker/include/SharedInterface.hpp +10 -0
  97. package/worker/include/Utils.hpp +72 -3
  98. package/worker/include/common.hpp +12 -4
  99. package/worker/include/handles/SendCallbacks.hpp +34 -0
  100. package/worker/include/handles/TcpConnectionHandle.hpp +4 -12
  101. package/worker/include/handles/UdpSocketHandle.hpp +4 -8
  102. package/worker/meson.build +45 -1
  103. package/worker/meson_options.txt +1 -0
  104. package/worker/mocks/include/MockShared.hpp +16 -2
  105. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +1 -1
  106. package/worker/scripts/package-lock.json +6 -6
  107. package/worker/src/RTC/BWE/AimdRateControl.cpp +4 -5
  108. package/worker/src/RTC/BWE/AlrDetector.cpp +80 -0
  109. package/worker/src/RTC/BWE/BitrateProber.cpp +256 -0
  110. package/worker/src/RTC/BWE/BitrateUtils.cpp +54 -0
  111. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +2 -2
  112. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +20 -37
  113. package/worker/src/RTC/BWE/InterArrival.cpp +216 -0
  114. package/worker/src/RTC/BWE/IntervalBudget.cpp +93 -0
  115. package/worker/src/RTC/BWE/LossBasedController.cpp +1194 -0
  116. package/worker/src/RTC/BWE/OveruseDetector.cpp +128 -0
  117. package/worker/src/RTC/BWE/OveruseEstimator.cpp +166 -0
  118. package/worker/src/RTC/BWE/ProbeBitrateEstimator.cpp +222 -0
  119. package/worker/src/RTC/BWE/ProbeController.cpp +645 -0
  120. package/worker/src/RTC/BWE/ProbePacketGenerator.cpp +140 -0
  121. package/worker/src/RTC/BWE/ProbingScheduler.cpp +196 -0
  122. package/worker/src/RTC/BWE/RembGenerator.cpp +169 -0
  123. package/worker/src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp +497 -0
  124. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +47 -0
  125. package/worker/src/RTC/BWE/SendPacketHistory.cpp +173 -50
  126. package/worker/src/RTC/BWE/TargetRateController.cpp +433 -0
  127. package/worker/src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp +377 -0
  128. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +102 -5
  129. package/worker/src/RTC/Consumer.cpp +7 -5
  130. package/worker/src/RTC/DataConsumer.cpp +8 -10
  131. package/worker/src/RTC/DirectTransport.cpp +14 -8
  132. package/worker/src/RTC/DtlsTransport.cpp +8 -8
  133. package/worker/src/RTC/ICE/IceCandidate.cpp +4 -4
  134. package/worker/src/RTC/ICE/IceServer.cpp +1 -1
  135. package/worker/src/RTC/PipeTransport.cpp +13 -8
  136. package/worker/src/RTC/PlainTransport.cpp +13 -8
  137. package/worker/src/RTC/Producer.cpp +14 -31
  138. package/worker/src/RTC/RTCP/Bye.cpp +1 -1
  139. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +18 -0
  140. package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +2 -2
  141. package/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp +2 -1
  142. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +2 -2
  143. package/worker/src/RTC/RTCP/Sdes.cpp +1 -1
  144. package/worker/src/RTC/RTP/Codecs/DependencyDescriptor.cpp +2 -1
  145. package/worker/src/RTC/RTP/Packet.cpp +26 -11
  146. package/worker/src/RTC/RTP/ProbationGenerator.cpp +5 -6
  147. package/worker/src/RTC/RTP/RtpStream.cpp +1 -1
  148. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +69 -48
  149. package/worker/src/RTC/RTP/RtpStreamSend.cpp +31 -31
  150. package/worker/src/RTC/RTP/RtxStream.cpp +22 -7
  151. package/worker/src/RTC/RateCalculator.cpp +133 -28
  152. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +56 -1
  153. package/worker/src/RTC/{RtcLogger.cpp → RtcLogger/RtpPacket.cpp} +2 -2
  154. package/worker/src/RTC/RtcLogger/SendBurst.cpp +124 -0
  155. package/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +2 -12
  156. package/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +1 -1
  157. package/worker/src/RTC/SCTP/association/Association.cpp +16 -2
  158. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +106 -1
  159. package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +1 -1
  160. package/worker/src/RTC/SCTP/rx/InterleavedReassemblyStreams.cpp +3 -3
  161. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +2 -1
  162. package/worker/src/RTC/SCTP/rx/TraditionalReassemblyStreams.cpp +4 -4
  163. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +4 -4
  164. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +6 -10
  165. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +2 -2
  166. package/worker/src/RTC/SrtpSession.cpp +2 -2
  167. package/worker/src/RTC/SvcProducerStreamManager.cpp +2 -2
  168. package/worker/src/RTC/TcpConnection.cpp +2 -2
  169. package/worker/src/RTC/Transport.cpp +112 -75
  170. package/worker/src/RTC/TransportTuple.cpp +4 -4
  171. package/worker/src/RTC/WebRtcServer.cpp +4 -3
  172. package/worker/src/RTC/WebRtcTransport.cpp +20 -13
  173. package/worker/src/Utils/BitStream.cpp +24 -0
  174. package/worker/src/handles/BackoffTimerHandle.cpp +1 -1
  175. package/worker/src/handles/TcpConnectionHandle.cpp +13 -23
  176. package/worker/src/handles/UdpSocketHandle.cpp +14 -21
  177. package/worker/tasks.py +43 -18
  178. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +68 -14
  179. package/worker/test/include/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.hpp +125 -0
  180. package/worker/test/src/RTC/BWE/TestAlrDetector.cpp +110 -0
  181. package/worker/test/src/RTC/BWE/TestBitrateProber.cpp +418 -0
  182. package/worker/test/src/RTC/BWE/TestBitrateUtils.cpp +61 -0
  183. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +4 -4
  184. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +53 -37
  185. package/worker/test/src/RTC/BWE/TestInterArrival.cpp +643 -0
  186. package/worker/test/src/RTC/BWE/TestIntervalBudget.cpp +130 -0
  187. package/worker/test/src/RTC/BWE/TestLossBasedController.cpp +1199 -0
  188. package/worker/test/src/RTC/BWE/TestOveruseDetector.cpp +519 -0
  189. package/worker/test/src/RTC/BWE/TestProbeBitrateEstimator.cpp +266 -0
  190. package/worker/test/src/RTC/BWE/TestProbeController.cpp +1682 -0
  191. package/worker/test/src/RTC/BWE/TestProbePacketGenerator.cpp +265 -0
  192. package/worker/test/src/RTC/BWE/TestProbingScheduler.cpp +260 -0
  193. package/worker/test/src/RTC/BWE/TestRembGenerator.cpp +285 -0
  194. package/worker/test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp +414 -0
  195. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +296 -77
  196. package/worker/test/src/RTC/BWE/TestTargetRateController.cpp +337 -0
  197. package/worker/test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp +578 -0
  198. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +45 -0
  199. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +133 -29
  200. package/worker/test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp +625 -0
  201. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +19 -0
  202. package/worker/test/src/RTC/RTP/TestPacket.cpp +58 -4
  203. package/worker/test/src/RTC/RTP/TestProbationGenerator.cpp +3 -2
  204. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +50 -0
  205. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +59 -0
  206. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +111 -0
  207. package/worker/test/src/RTC/TestRateCalculator.cpp +322 -60
  208. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +95 -7
  209. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +34 -16
  210. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +31 -13
  211. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +37 -19
  212. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +10 -10
  213. package/worker/test/src/Utils/TestTime.cpp +120 -21
@@ -10,49 +10,105 @@ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
10
10
  constexpr size_t PacketSize{ 1000 };
11
11
  constexpr uint32_t Ssrc{ 1111 };
12
12
 
13
- SECTION("sequence numbers are given out in order, starting at zero")
13
+ // Take note of a packet without it having left yet.
14
+ const auto addPacket = [](
15
+ RTC::BWE::SendPacketHistory& sendPacketHistory,
16
+ uint16_t seq,
17
+ size_t size,
18
+ int64_t createdAtUs) -> int64_t
19
+ {
20
+ return sendPacketHistory.AddPacket(
21
+ { .ssrc = Ssrc, .seq = seq, .size = size, .createdAtUs = createdAtUs });
22
+ };
23
+
24
+ // Take note of a packet and of it having left right away, which is what most
25
+ // cases need.
26
+ const auto sendPacket =
27
+ [&addPacket](
28
+ RTC::BWE::SendPacketHistory& sendPacketHistory, uint16_t seq, size_t size, int64_t atUs) -> int64_t
29
+ {
30
+ const int64_t sequenceNumber = addPacket(sendPacketHistory, seq, size, atUs);
31
+
32
+ sendPacketHistory.ProcessSentPacket(sequenceNumber, atUs);
33
+
34
+ return sequenceNumber;
35
+ };
36
+
37
+ SECTION("a packet is retrieved as it was sent")
14
38
  {
15
39
  RTC::BWE::SendPacketHistory sendPacketHistory;
16
40
 
17
- REQUIRE(sendPacketHistory.GetLastSequenceNumber() == std::nullopt);
41
+ const int64_t sequenceNumber = sendPacketHistory.AddPacket(
42
+ { .ssrc = Ssrc, .seq = 100, .size = PacketSize, .isAudio = true, .createdAtUs = InitialTimeUs });
43
+
44
+ REQUIRE(sequenceNumber == 0);
45
+
46
+ sendPacketHistory.ProcessSentPacket(sequenceNumber, InitialTimeUs + 500);
18
47
 
19
- REQUIRE(sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs) == 0);
20
- REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 0);
48
+ const auto retrievedEntry = sendPacketHistory.RetrievePacket(0, true);
21
49
 
22
- REQUIRE(sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + 10000) == 1);
23
- REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 1);
50
+ REQUIRE(retrievedEntry.has_value());
24
51
 
25
- REQUIRE(sendPacketHistory.AddPacket(Ssrc, 102, PacketSize, false, InitialTimeUs + 20000) == 2);
26
- REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 2);
52
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
53
+ const auto& entry = retrievedEntry.value();
54
+
55
+ REQUIRE(entry.ssrc == Ssrc);
56
+ REQUIRE(entry.seq == 100);
57
+ REQUIRE(entry.createdAtUs == InitialTimeUs);
58
+ REQUIRE(entry.sentPacket.sequenceNumber == 0);
59
+ REQUIRE(entry.sentPacket.size == PacketSize);
60
+ REQUIRE(entry.sentPacket.isAudio == true);
61
+ // The send time is the one it left at, not the one it was taken note of.
62
+ REQUIRE(entry.sentPacket.sendTimeUs == InitialTimeUs + 500);
27
63
  }
28
64
 
29
- SECTION("a packet is retrieved as it was sent")
65
+ SECTION("the burst a packet belongs to survives the history")
30
66
  {
31
67
  RTC::BWE::SendPacketHistory sendPacketHistory;
32
68
 
33
- const int64_t sequenceNumber =
34
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, true, InitialTimeUs);
69
+ const RTC::BWE::Types::ProbeCluster probeCluster{ .id = 7, .minProbes = 5, .minBytes = 4000 };
70
+
71
+ const int64_t sequenceNumber = sendPacketHistory.AddPacket(
72
+ { .ssrc = Ssrc,
73
+ .seq = 100,
74
+ .size = PacketSize,
75
+ .probeCluster = probeCluster,
76
+ .createdAtUs = InitialTimeUs });
77
+
78
+ sendPacketHistory.ProcessSentPacket(sequenceNumber, InitialTimeUs);
35
79
 
36
- const auto retrievedPacket = sendPacketHistory.RetrievePacket(sequenceNumber, true);
80
+ const auto retrievedEntry = sendPacketHistory.RetrievePacket(0, true);
37
81
 
38
- REQUIRE(retrievedPacket.has_value());
82
+ REQUIRE(retrievedEntry.has_value());
39
83
 
40
84
  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
41
- const auto& sentPacket = retrievedPacket.value();
85
+ const auto& retrievedProbeCluster = retrievedEntry.value().sentPacket.probeCluster;
86
+
87
+ REQUIRE(retrievedProbeCluster.has_value());
88
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
89
+ REQUIRE(retrievedProbeCluster.value().id == 7);
90
+ }
42
91
 
43
- REQUIRE(sentPacket.sequenceNumber == sequenceNumber);
44
- REQUIRE(sentPacket.sendTimeUs == InitialTimeUs);
45
- REQUIRE(sentPacket.size == PacketSize);
46
- REQUIRE(sentPacket.audio == true);
92
+ SECTION("a packet that never left is not resolved")
93
+ {
94
+ RTC::BWE::SendPacketHistory sendPacketHistory;
95
+
96
+ addPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
97
+
98
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
99
+
100
+ sendPacketHistory.ProcessSentPacket(0, InitialTimeUs);
101
+
102
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true).has_value());
47
103
  }
48
104
 
49
- SECTION("a sequence number that was never given out is not resolved")
105
+ SECTION("a sequence number that was never taken note of is not resolved")
50
106
  {
51
107
  RTC::BWE::SendPacketHistory sendPacketHistory;
52
108
 
53
109
  REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
54
110
 
55
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
111
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
56
112
 
57
113
  REQUIRE(sendPacketHistory.RetrievePacket(-1, true) == std::nullopt);
58
114
  REQUIRE(sendPacketHistory.RetrievePacket(1, true) == std::nullopt);
@@ -63,89 +119,164 @@ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
63
119
  {
64
120
  RTC::BWE::SendPacketHistory sendPacketHistory;
65
121
 
66
- const int64_t sequenceNumber =
67
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
122
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
68
123
 
69
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true).has_value());
70
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true) == std::nullopt);
124
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true).has_value());
125
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
71
126
  }
72
127
 
73
128
  SECTION("a packet reported as lost is kept, since it may be reported as received later")
74
129
  {
75
130
  RTC::BWE::SendPacketHistory sendPacketHistory;
76
131
 
77
- const int64_t sequenceNumber =
78
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
132
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
79
133
 
80
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, false).has_value());
81
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, false).has_value());
82
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true).has_value());
83
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true) == std::nullopt);
134
+ REQUIRE(sendPacketHistory.RetrievePacket(0, false).has_value());
135
+ REQUIRE(sendPacketHistory.RetrievePacket(0, false).has_value());
136
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true).has_value());
137
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
84
138
  }
85
139
 
86
- SECTION("a packet is resolved by its SSRC and RTP sequence number too")
140
+ SECTION("the first report of a loss is told apart from the same loss reported again")
87
141
  {
88
142
  RTC::BWE::SendPacketHistory sendPacketHistory;
89
143
 
90
- const int64_t sequenceNumber =
91
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
144
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
92
145
 
93
- sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + 10000);
146
+ const auto firstReport = sendPacketHistory.RetrievePacket(0, false);
147
+
148
+ REQUIRE(firstReport.has_value());
149
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
150
+ REQUIRE(firstReport.value().previouslyReportedLost == false);
94
151
 
95
- const auto sentPacket = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
152
+ const auto secondReport = sendPacketHistory.RetrievePacket(0, false);
96
153
 
97
- REQUIRE(sentPacket.has_value());
154
+ REQUIRE(secondReport.has_value());
98
155
  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
99
- REQUIRE(sentPacket->sequenceNumber == sequenceNumber);
156
+ REQUIRE(secondReport.value().previouslyReportedLost == true);
157
+ }
158
+
159
+ SECTION("a packet is resolved by its SSRC and RTP sequence number too")
160
+ {
161
+ RTC::BWE::SendPacketHistory sendPacketHistory;
162
+
163
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
164
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + 10000);
165
+
166
+ const auto retrievedEntry = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
167
+
168
+ REQUIRE(retrievedEntry.has_value());
169
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
170
+ REQUIRE(retrievedEntry.value().sentPacket.sequenceNumber == 0);
100
171
 
101
172
  // The very same RTP sequence number of another stream is another packet.
102
173
  REQUIRE(sendPacketHistory.RetrievePacket(Ssrc + 1, 101, true) == std::nullopt);
103
174
  }
104
175
 
105
- SECTION("the latest send of a repeated SSRC and RTP sequence number takes over")
176
+ SECTION("the first send of a repeated SSRC and RTP sequence number keeps the mapping")
106
177
  {
107
178
  RTC::BWE::SendPacketHistory sendPacketHistory;
108
179
 
109
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
180
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
181
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs + 10000);
110
182
 
111
- const int64_t retransmissionSequenceNumber =
112
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs + 10000);
183
+ const auto retrievedEntry = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
113
184
 
114
- const auto sentPacket = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
185
+ REQUIRE(retrievedEntry.has_value());
186
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
187
+ REQUIRE(retrievedEntry.value().sentPacket.sequenceNumber == 0);
188
+ }
115
189
 
116
- REQUIRE(sentPacket.has_value());
190
+ SECTION("both sends of a repeated SSRC and RTP sequence number have an ambiguous arrival time")
191
+ {
192
+ RTC::BWE::SendPacketHistory sendPacketHistory;
193
+
194
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
195
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs + 10000);
196
+
197
+ const auto firstEntry = sendPacketHistory.RetrievePacket(0, true);
198
+
199
+ REQUIRE(firstEntry.has_value());
117
200
  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
118
- REQUIRE(sentPacket->sequenceNumber == retransmissionSequenceNumber);
201
+ REQUIRE(firstEntry.value().ambiguousReceiveTime == true);
202
+
203
+ const auto secondEntry = sendPacketHistory.RetrievePacket(1, true);
204
+
205
+ REQUIRE(secondEntry.has_value());
206
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
207
+ REQUIRE(secondEntry.value().ambiguousReceiveTime == true);
208
+ }
209
+
210
+ SECTION("a retransmission without RTX is ambiguous although the packet it repeats is gone")
211
+ {
212
+ RTC::BWE::SendPacketHistory sendPacketHistory;
213
+
214
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
215
+
216
+ // Reported as received, so it's not held anymore.
217
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true).has_value());
218
+
219
+ // Retransmitted reusing the very same SSRC and RTP sequence number.
220
+ const int64_t sequenceNumber = sendPacketHistory.AddPacket(
221
+ { .ssrc = Ssrc,
222
+ .seq = 100,
223
+ .size = PacketSize,
224
+ .isRetransmission = true,
225
+ .originalSsrc = Ssrc,
226
+ .createdAtUs = InitialTimeUs + 10000 });
227
+
228
+ sendPacketHistory.ProcessSentPacket(sequenceNumber, InitialTimeUs + 10000);
229
+
230
+ const auto retrievedEntry = sendPacketHistory.RetrievePacket(1, true);
231
+
232
+ REQUIRE(retrievedEntry.has_value());
233
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
234
+ REQUIRE(retrievedEntry.value().ambiguousReceiveTime == true);
119
235
  }
120
236
 
121
- SECTION("resolving the first send of a repeated one does not drop the mapping of the latest")
237
+ SECTION("a retransmission over RTX is not ambiguous, since it goes under its own SSRC")
122
238
  {
123
239
  RTC::BWE::SendPacketHistory sendPacketHistory;
124
240
 
125
- const int64_t firstSequenceNumber =
126
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
241
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
242
+
243
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true).has_value());
127
244
 
128
- const int64_t retransmissionSequenceNumber =
129
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs + 10000);
245
+ // Retransmitted over RTX, so under another SSRC and sequence number.
246
+ const int64_t sequenceNumber = sendPacketHistory.AddPacket(
247
+ { .ssrc = Ssrc + 1,
248
+ .seq = 7,
249
+ .size = PacketSize,
250
+ .isRetransmission = true,
251
+ .originalSsrc = Ssrc,
252
+ .createdAtUs = InitialTimeUs + 10000 });
130
253
 
131
- REQUIRE(sendPacketHistory.RetrievePacket(firstSequenceNumber, true).has_value());
254
+ sendPacketHistory.ProcessSentPacket(sequenceNumber, InitialTimeUs + 10000);
132
255
 
133
- const auto sentPacket = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
256
+ const auto retrievedEntry = sendPacketHistory.RetrievePacket(1, true);
134
257
 
135
- REQUIRE(sentPacket.has_value());
258
+ REQUIRE(retrievedEntry.has_value());
136
259
  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
137
- REQUIRE(sentPacket->sequenceNumber == retransmissionSequenceNumber);
260
+ REQUIRE(retrievedEntry.value().ambiguousReceiveTime == false);
138
261
  }
139
262
 
140
- SECTION("bytes in flight are those of the packets no feedback has reported on")
263
+ SECTION("bytes in flight are those of the packets that left and no feedback has reported on")
141
264
  {
142
265
  RTC::BWE::SendPacketHistory sendPacketHistory;
143
266
 
144
267
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
145
268
 
146
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
147
- sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + 10000);
148
- sendPacketHistory.AddPacket(Ssrc, 102, PacketSize, false, InitialTimeUs + 20000);
269
+ // Taking note of a packet is not yet sending it.
270
+ addPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
271
+
272
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
273
+
274
+ sendPacketHistory.ProcessSentPacket(0, InitialTimeUs);
275
+
276
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
277
+
278
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + 10000);
279
+ sendPacket(sendPacketHistory, 102, PacketSize, InitialTimeUs + 20000);
149
280
 
150
281
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == 3 * PacketSize);
151
282
 
@@ -159,31 +290,87 @@ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
159
290
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
160
291
  }
161
292
 
162
- SECTION("a packet is told the bytes that were in flight when it was sent")
293
+ SECTION("a packet that leaves twice does not count its bytes twice")
163
294
  {
164
295
  RTC::BWE::SendPacketHistory sendPacketHistory;
165
296
 
166
- sendPacketHistory.AddPacket(Ssrc, 100, 200, false, InitialTimeUs);
167
- sendPacketHistory.AddPacket(Ssrc, 101, 300, false, InitialTimeUs + 10000);
297
+ addPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
168
298
 
169
- const auto firstSentPacket = sendPacketHistory.RetrievePacket(0, false);
299
+ REQUIRE(sendPacketHistory.ProcessSentPacket(0, InitialTimeUs).has_value());
300
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
301
+
302
+ REQUIRE(sendPacketHistory.ProcessSentPacket(0, InitialTimeUs + 1000) == std::nullopt);
303
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
304
+ }
305
+
306
+ SECTION("a packet is told the bytes that were in flight when it left")
307
+ {
308
+ RTC::BWE::SendPacketHistory sendPacketHistory;
309
+
310
+ addPacket(sendPacketHistory, 100, 200, InitialTimeUs);
311
+
312
+ const auto firstSentPacket = sendPacketHistory.ProcessSentPacket(0, InitialTimeUs);
170
313
 
171
314
  REQUIRE(firstSentPacket.has_value());
172
315
  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
173
- REQUIRE(firstSentPacket->dataInFlight == 200);
316
+ REQUIRE(firstSentPacket.value().sequenceNumber == 0);
317
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
318
+ REQUIRE(firstSentPacket.value().dataInFlight == 200);
319
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 200);
174
320
 
175
- const auto secondSentPacket = sendPacketHistory.RetrievePacket(1, false);
321
+ addPacket(sendPacketHistory, 101, 300, InitialTimeUs + 10000);
322
+
323
+ const auto secondSentPacket = sendPacketHistory.ProcessSentPacket(1, InitialTimeUs + 10000);
176
324
 
177
325
  REQUIRE(secondSentPacket.has_value());
178
326
  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
179
- REQUIRE(secondSentPacket->dataInFlight == 500);
327
+ REQUIRE(secondSentPacket.value().dataInFlight == 500);
328
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 500);
329
+
330
+ // And it's what a feedback resolves it into as well.
331
+ const auto firstEntry = sendPacketHistory.RetrievePacket(0, false);
332
+
333
+ REQUIRE(firstEntry.has_value());
334
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
335
+ REQUIRE(firstEntry.value().sentPacket.dataInFlight == 200);
336
+
337
+ const auto secondEntry = sendPacketHistory.RetrievePacket(1, false);
338
+
339
+ REQUIRE(secondEntry.has_value());
340
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
341
+ REQUIRE(secondEntry.value().sentPacket.dataInFlight == 500);
342
+ }
343
+
344
+ SECTION("bytes that left untracked are attributed to the next packet that leaves")
345
+ {
346
+ RTC::BWE::SendPacketHistory sendPacketHistory;
347
+
348
+ sendPacketHistory.ProcessSentUntrackedPacket(400, InitialTimeUs);
349
+ sendPacketHistory.ProcessSentUntrackedPacket(600, InitialTimeUs + 1000);
350
+
351
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs + 2000);
352
+
353
+ const auto firstEntry = sendPacketHistory.RetrievePacket(0, false);
354
+
355
+ REQUIRE(firstEntry.has_value());
356
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
357
+ REQUIRE(firstEntry.value().sentPacket.priorUnackedData == 1000);
358
+
359
+ // They are attributed once, not to every packet that follows.
360
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + 3000);
361
+
362
+ const auto secondEntry = sendPacketHistory.RetrievePacket(1, false);
363
+
364
+ REQUIRE(secondEntry.has_value());
365
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
366
+ REQUIRE(secondEntry.value().sentPacket.priorUnackedData == 0);
180
367
  }
181
368
 
182
369
  SECTION("a packet reported as lost stops counting as in flight")
183
370
  {
184
371
  RTC::BWE::SendPacketHistory sendPacketHistory;
185
372
 
186
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
373
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
187
374
 
188
375
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
189
376
 
@@ -201,9 +388,9 @@ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
201
388
  {
202
389
  RTC::BWE::SendPacketHistory sendPacketHistory;
203
390
 
204
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
205
- sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + 10000);
206
- sendPacketHistory.AddPacket(Ssrc, 102, PacketSize, false, InitialTimeUs + 20000);
391
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
392
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + 10000);
393
+ sendPacket(sendPacketHistory, 102, PacketSize, InitialTimeUs + 20000);
207
394
 
208
395
  sendPacketHistory.RetrievePacket(2, true);
209
396
 
@@ -221,22 +408,39 @@ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
221
408
 
222
409
  RTC::BWE::SendPacketHistory sendPacketHistory({ .windowDurationUs = WindowDurationUs });
223
410
 
224
- const int64_t sequenceNumber =
225
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
411
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
226
412
 
227
413
  // Right at the window it's still held.
228
- sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + WindowDurationUs);
414
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + WindowDurationUs);
229
415
 
230
416
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == 2 * PacketSize);
231
417
 
232
- sendPacketHistory.AddPacket(Ssrc, 102, PacketSize, false, InitialTimeUs + WindowDurationUs + 1);
418
+ sendPacket(sendPacketHistory, 102, PacketSize, InitialTimeUs + WindowDurationUs + 1);
233
419
 
234
- REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true) == std::nullopt);
420
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
235
421
  REQUIRE(sendPacketHistory.RetrievePacket(Ssrc, 100, true) == std::nullopt);
236
422
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == 2 * PacketSize);
237
423
 
238
- // The sequence numbers of the dropped packets are not given out again.
239
- REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 2);
424
+ // Dropping a packet doesn't make the history forget how far the numbers got,
425
+ // so one beyond them is still refused.
426
+ REQUIRE(sendPacketHistory.RetrievePacket(3, true) == std::nullopt);
427
+ REQUIRE(sendPacketHistory.RetrievePacket(2, true).has_value());
428
+ }
429
+
430
+ SECTION("the window counts from when a packet was taken note of, not from when it left")
431
+ {
432
+ constexpr int64_t WindowDurationUs{ 1000000 };
433
+
434
+ RTC::BWE::SendPacketHistory sendPacketHistory({ .windowDurationUs = WindowDurationUs });
435
+
436
+ addPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
437
+
438
+ // It took the whole window to leave, which doesn't buy it any more time.
439
+ sendPacketHistory.ProcessSentPacket(0, InitialTimeUs + WindowDurationUs);
440
+
441
+ addPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + WindowDurationUs + 1);
442
+
443
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
240
444
  }
241
445
 
242
446
  SECTION("the window does not take out the bytes of a packet already reported on")
@@ -245,14 +449,29 @@ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
245
449
 
246
450
  RTC::BWE::SendPacketHistory sendPacketHistory({ .windowDurationUs = WindowDurationUs });
247
451
 
248
- sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
452
+ sendPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
249
453
 
250
454
  // Reported as lost, so its bytes are gone but it's still held.
251
455
  sendPacketHistory.RetrievePacket(0, false);
252
456
 
253
457
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
254
458
 
255
- sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + WindowDurationUs + 1);
459
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + WindowDurationUs + 1);
460
+
461
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
462
+ }
463
+
464
+ SECTION("the window does not take out the bytes of a packet that never left")
465
+ {
466
+ constexpr int64_t WindowDurationUs{ 1000000 };
467
+
468
+ RTC::BWE::SendPacketHistory sendPacketHistory({ .windowDurationUs = WindowDurationUs });
469
+
470
+ addPacket(sendPacketHistory, 100, PacketSize, InitialTimeUs);
471
+
472
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
473
+
474
+ sendPacket(sendPacketHistory, 101, PacketSize, InitialTimeUs + WindowDurationUs + 1);
256
475
 
257
476
  REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
258
477
  }