mediasoup 3.26.0 → 3.27.1

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 (322) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/node/lib/DataConsumer.js +1 -1
  3. package/node/lib/Router.js +1 -1
  4. package/node/lib/Transport.js +15 -15
  5. package/node/lib/fbs/rtp-parameters/encoding-mapping.d.ts +2 -6
  6. package/node/lib/fbs/rtp-parameters/encoding-mapping.d.ts.map +1 -1
  7. package/node/lib/fbs/rtp-parameters/encoding-mapping.js +7 -19
  8. package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.d.ts +4 -4
  9. package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.js +2 -2
  10. package/node/lib/fbs/rtp-stream/bitrate-by-layer.d.ts +5 -5
  11. package/node/lib/fbs/rtp-stream/bitrate-by-layer.d.ts.map +1 -1
  12. package/node/lib/fbs/rtp-stream/bitrate-by-layer.js +3 -3
  13. package/node/lib/fbs/rtp-stream/recv-stats.d.ts +5 -5
  14. package/node/lib/fbs/rtp-stream/recv-stats.d.ts.map +1 -1
  15. package/node/lib/fbs/rtp-stream/recv-stats.js +3 -3
  16. package/node/lib/fbs/rtp-stream/send-stats.d.ts +5 -5
  17. package/node/lib/fbs/rtp-stream/send-stats.d.ts.map +1 -1
  18. package/node/lib/fbs/rtp-stream/send-stats.js +3 -3
  19. package/node/lib/fbs/transport/bwe-trace-info.d.ts +23 -23
  20. package/node/lib/fbs/transport/bwe-trace-info.d.ts.map +1 -1
  21. package/node/lib/fbs/transport/bwe-trace-info.js +15 -15
  22. package/node/lib/fbs/transport/options.d.ts +5 -5
  23. package/node/lib/fbs/transport/options.js +2 -2
  24. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.d.ts +5 -5
  25. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.d.ts.map +1 -1
  26. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.js +3 -3
  27. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.d.ts +5 -5
  28. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.d.ts.map +1 -1
  29. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.js +3 -3
  30. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.d.ts +5 -5
  31. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.d.ts.map +1 -1
  32. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.js +3 -3
  33. package/node/lib/fbs/transport/stats.d.ts +38 -38
  34. package/node/lib/fbs/transport/stats.d.ts.map +1 -1
  35. package/node/lib/fbs/transport/stats.js +25 -25
  36. package/node/lib/ortc.d.ts +0 -1
  37. package/node/lib/ortc.d.ts.map +1 -1
  38. package/node/lib/ortc.js +1 -2
  39. package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
  40. package/node/lib/rtpParametersFbsUtils.js +2 -2
  41. package/package.json +9 -9
  42. package/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc +10 -10
  43. package/worker/deps/libwebrtc/libwebrtc/mediasoup_helpers.h +6 -6
  44. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc +1 -1
  45. package/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc +7 -7
  46. package/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h +1 -1
  47. package/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc +1 -1
  48. package/worker/fbs/FBS/meson.build +25 -0
  49. package/worker/fbs/meson.build +15 -18
  50. package/worker/fbs/rtpParameters.fbs +1 -2
  51. package/worker/fbs/rtpStream.fbs +3 -3
  52. package/worker/fbs/transport.fbs +23 -23
  53. package/worker/fuzzer/include/RTC/FuzzerDtlsTransport.hpp +4 -1
  54. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  55. package/worker/fuzzer/src/RTC/FuzzerDtlsTransport.cpp +8 -5
  56. package/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp +3 -3
  57. package/worker/fuzzer/src/RTC/FuzzerTrendCalculator.cpp +6 -6
  58. package/worker/fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTransport.cpp +3 -3
  59. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +2 -2
  60. package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +5 -5
  61. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +3 -3
  62. package/worker/fuzzer/src/fuzzer.cpp +4 -0
  63. package/worker/include/Channel/ChannelNotification.hpp +3 -3
  64. package/worker/include/Channel/ChannelRequest.hpp +1 -1
  65. package/worker/include/Channel/ChannelSocket.hpp +11 -0
  66. package/worker/include/DepLibUV.hpp +16 -33
  67. package/worker/include/RTC/ActiveSpeakerObserver.hpp +11 -11
  68. package/worker/include/RTC/AudioLevelObserver.hpp +4 -4
  69. package/worker/include/RTC/BWE/AcknowledgedBitrateEstimatorInterface.hpp +55 -0
  70. package/worker/include/RTC/BWE/AimdRateControl.hpp +190 -0
  71. package/worker/include/RTC/BWE/BweTypes.hpp +211 -0
  72. package/worker/include/RTC/BWE/DelayBasedBwe.hpp +173 -0
  73. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +72 -0
  74. package/worker/include/RTC/BWE/InterArrivalDelta.hpp +106 -0
  75. package/worker/include/RTC/BWE/LinkCapacityEstimator.hpp +84 -0
  76. package/worker/include/RTC/BWE/LossBasedController.hpp +520 -0
  77. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +94 -0
  78. package/worker/include/RTC/BWE/SendPacketHistory.hpp +137 -0
  79. package/worker/include/RTC/BWE/TargetRateController.hpp +306 -0
  80. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +143 -0
  81. package/worker/include/RTC/BWE/Utils.hpp +39 -0
  82. package/worker/include/RTC/Consts.hpp +6 -6
  83. package/worker/include/RTC/Consumer.hpp +14 -12
  84. package/worker/include/RTC/DataConsumer.hpp +3 -3
  85. package/worker/include/RTC/DataProducer.hpp +3 -3
  86. package/worker/include/RTC/DtlsTransport.hpp +5 -2
  87. package/worker/include/RTC/ICE/IceCandidate.hpp +2 -2
  88. package/worker/include/RTC/ICE/IceServer.hpp +3 -3
  89. package/worker/include/RTC/KeyFrameRequestManager.hpp +3 -3
  90. package/worker/include/RTC/NEW_RTCP/packet/Packet.hpp +1 -1
  91. package/worker/include/RTC/NackGenerator.hpp +12 -12
  92. package/worker/include/RTC/PipeProducerStreamManager.hpp +3 -4
  93. package/worker/include/RTC/PipeTransport.hpp +18 -5
  94. package/worker/include/RTC/PlainTransport.hpp +18 -5
  95. package/worker/include/RTC/PortManager.hpp +4 -4
  96. package/worker/include/RTC/Producer.hpp +21 -12
  97. package/worker/include/RTC/ProducerStreamManager.hpp +12 -6
  98. package/worker/include/RTC/RTCP/Bye.hpp +2 -2
  99. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +4 -4
  100. package/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp +3 -3
  101. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +54 -39
  102. package/worker/include/RTC/RTCP/Packet.hpp +3 -3
  103. package/worker/include/RTC/RTCP/ReceiverReport.hpp +3 -3
  104. package/worker/include/RTC/RTCP/Sdes.hpp +2 -2
  105. package/worker/include/RTC/RTCP/XR.hpp +2 -2
  106. package/worker/include/RTC/RTCP/XrDelaySinceLastRr.hpp +1 -1
  107. package/worker/include/RTC/RTP/Codecs/H264.hpp +1 -1
  108. package/worker/include/RTC/RTP/Codecs/Opus.hpp +2 -2
  109. package/worker/include/RTC/RTP/Codecs/PayloadDescriptorHandler.hpp +3 -3
  110. package/worker/include/RTC/RTP/Codecs/VP8.hpp +2 -2
  111. package/worker/include/RTC/RTP/Codecs/VP9.hpp +2 -2
  112. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +12 -12
  113. package/worker/include/RTC/RTP/Packet.hpp +13 -13
  114. package/worker/include/RTC/RTP/ProbationGenerator.hpp +1 -1
  115. package/worker/include/RTC/RTP/RetransmissionBuffer.hpp +7 -7
  116. package/worker/include/RTC/RTP/RtpStream.hpp +37 -51
  117. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +59 -41
  118. package/worker/include/RTC/RTP/RtpStreamSend.hpp +20 -14
  119. package/worker/include/RTC/RTP/RtxStream.hpp +12 -13
  120. package/worker/include/RTC/RateCalculator.hpp +50 -44
  121. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +5 -4
  122. package/worker/include/RTC/RemoteClockOffsetEstimator.hpp +11 -11
  123. package/worker/include/RTC/Router.hpp +6 -0
  124. package/worker/include/RTC/RtcLogger.hpp +1 -1
  125. package/worker/include/RTC/RtpDictionaries.hpp +10 -10
  126. package/worker/include/RTC/SCTP/association/Association.hpp +56 -28
  127. package/worker/include/RTC/SCTP/association/HeartbeatHandler.hpp +4 -4
  128. package/worker/include/RTC/SCTP/association/StateCookie.hpp +14 -14
  129. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +38 -2
  130. package/worker/include/RTC/SCTP/association/TransmissionControlBlock.hpp +12 -12
  131. package/worker/include/RTC/SCTP/association/TransmissionControlBlockContextInterface.hpp +4 -4
  132. package/worker/include/RTC/SCTP/packet/TLV.hpp +1 -1
  133. package/worker/include/RTC/SCTP/packet/parameters/StateCookieParameter.hpp +3 -3
  134. package/worker/include/RTC/SCTP/public/AssociationInterface.hpp +4 -1
  135. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +1 -1
  136. package/worker/include/RTC/SCTP/public/SctpOptions.hpp +12 -12
  137. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +6 -6
  138. package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +10 -0
  139. package/worker/include/RTC/SCTP/tx/OutstandingData.hpp +15 -16
  140. package/worker/include/RTC/SCTP/tx/RetransmissionQueue.hpp +7 -8
  141. package/worker/include/RTC/SCTP/tx/RetransmissionTimeout.hpp +20 -16
  142. package/worker/include/RTC/SCTP/tx/RoundRobinSendQueue.hpp +5 -6
  143. package/worker/include/RTC/SCTP/tx/SendQueueInterface.hpp +2 -2
  144. package/worker/include/RTC/SCTP/tx/StreamScheduler.hpp +5 -5
  145. package/worker/include/RTC/SctpDictionaries.hpp +3 -3
  146. package/worker/include/RTC/Serializable.hpp +1 -1
  147. package/worker/include/RTC/SimpleProducerStreamManager.hpp +3 -4
  148. package/worker/include/RTC/SimulcastProducerStreamManager.hpp +6 -7
  149. package/worker/include/RTC/SvcProducerStreamManager.hpp +6 -5
  150. package/worker/include/RTC/TcpConnection.hpp +9 -3
  151. package/worker/include/RTC/TcpServer.hpp +3 -0
  152. package/worker/include/RTC/Transport.hpp +52 -45
  153. package/worker/include/RTC/TransportCongestionControlClient.hpp +30 -25
  154. package/worker/include/RTC/TransportCongestionControlServer.hpp +17 -17
  155. package/worker/include/RTC/TrendCalculator.hpp +5 -5
  156. package/worker/include/RTC/UdpSocket.hpp +11 -2
  157. package/worker/include/RTC/WebRtcServer.hpp +20 -5
  158. package/worker/include/RTC/WebRtcTransport.hpp +35 -10
  159. package/worker/include/Settings.hpp +4 -2
  160. package/worker/include/Shared.hpp +5 -20
  161. package/worker/include/SharedInterface.hpp +6 -28
  162. package/worker/include/Utils.hpp +40 -21
  163. package/worker/include/common.hpp +4 -0
  164. package/worker/include/handles/BackoffTimerHandle.hpp +4 -4
  165. package/worker/include/handles/BackoffTimerHandleInterface.hpp +5 -5
  166. package/worker/include/handles/TcpConnectionHandle.hpp +6 -6
  167. package/worker/include/handles/TcpServerHandle.hpp +1 -1
  168. package/worker/include/handles/TimerHandle.hpp +15 -9
  169. package/worker/include/handles/TimerHandleInterface.hpp +10 -4
  170. package/worker/include/handles/UdpSocketHandle.hpp +3 -3
  171. package/worker/include/handles/UnixStreamSocketHandle.hpp +2 -2
  172. package/worker/meson.build +87 -36
  173. package/worker/meson_options.txt +1 -0
  174. package/worker/mocks/include/MockShared.hpp +24 -23
  175. package/worker/mocks/include/RTC/SCTP/association/MockTransmissionControlBlockContext.hpp +51 -27
  176. package/worker/mocks/include/RTC/SCTP/tx/MockSendQueue.hpp +11 -11
  177. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +10 -10
  178. package/worker/mocks/include/handles/MockTimerHandle.hpp +60 -22
  179. package/worker/mocks/src/MockShared.cpp +51 -5
  180. package/worker/mocks/src/handles/MockBackoffTimerHandle.cpp +29 -15
  181. package/worker/mocks/src/handles/MockTimerHandle.cpp +117 -0
  182. package/worker/scripts/clang-scripts.mjs +2 -2
  183. package/worker/src/Channel/ChannelNotification.cpp +5 -6
  184. package/worker/src/Channel/ChannelSocket.cpp +20 -2
  185. package/worker/src/DepLibUV.cpp +4 -5
  186. package/worker/src/RTC/ActiveSpeakerObserver.cpp +59 -47
  187. package/worker/src/RTC/AudioLevelObserver.cpp +7 -7
  188. package/worker/src/RTC/BWE/AimdRateControl.cpp +468 -0
  189. package/worker/src/RTC/BWE/BweTypes.cpp +61 -0
  190. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +275 -0
  191. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +148 -0
  192. package/worker/src/RTC/BWE/InterArrivalDelta.cpp +181 -0
  193. package/worker/src/RTC/BWE/LinkCapacityEstimator.cpp +133 -0
  194. package/worker/src/RTC/BWE/LossBasedController.cpp +1046 -0
  195. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +245 -0
  196. package/worker/src/RTC/BWE/SendPacketHistory.cpp +184 -0
  197. package/worker/src/RTC/BWE/TargetRateController.cpp +435 -0
  198. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +311 -0
  199. package/worker/src/RTC/BWE/Utils.cpp +54 -0
  200. package/worker/src/RTC/Consumer.cpp +48 -35
  201. package/worker/src/RTC/DataConsumer.cpp +4 -4
  202. package/worker/src/RTC/DataProducer.cpp +3 -3
  203. package/worker/src/RTC/DirectTransport.cpp +2 -2
  204. package/worker/src/RTC/DtlsTransport.cpp +14 -11
  205. package/worker/src/RTC/ICE/IceServer.cpp +2 -2
  206. package/worker/src/RTC/KeyFrameRequestManager.cpp +16 -12
  207. package/worker/src/RTC/NackGenerator.cpp +12 -12
  208. package/worker/src/RTC/PipeProducerStreamManager.cpp +6 -6
  209. package/worker/src/RTC/PipeTransport.cpp +16 -13
  210. package/worker/src/RTC/PlainTransport.cpp +25 -16
  211. package/worker/src/RTC/Producer.cpp +50 -36
  212. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +13 -6
  213. package/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp +14 -5
  214. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +76 -50
  215. package/worker/src/RTC/RTP/Codecs/VP8.cpp +1 -1
  216. package/worker/src/RTC/RTP/Codecs/VP9.cpp +4 -4
  217. package/worker/src/RTC/RTP/Packet.cpp +9 -10
  218. package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +6 -6
  219. package/worker/src/RTC/RTP/RtpStream.cpp +19 -19
  220. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +146 -81
  221. package/worker/src/RTC/RTP/RtpStreamSend.cpp +49 -44
  222. package/worker/src/RTC/RTP/RtxStream.cpp +7 -10
  223. package/worker/src/RTC/RateCalculator.cpp +99 -136
  224. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +13 -13
  225. package/worker/src/RTC/RemoteClockOffsetEstimator.cpp +18 -17
  226. package/worker/src/RTC/Router.cpp +18 -1
  227. package/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp +5 -2
  228. package/worker/src/RTC/SCTP/association/Association.cpp +146 -103
  229. package/worker/src/RTC/SCTP/association/AssociationListenerDeferrer.cpp +4 -4
  230. package/worker/src/RTC/SCTP/association/Capabilities.cpp +1 -1
  231. package/worker/src/RTC/SCTP/association/HeartbeatHandler.cpp +25 -18
  232. package/worker/src/RTC/SCTP/association/StateCookie.cpp +7 -6
  233. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +122 -14
  234. package/worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp +28 -26
  235. package/worker/src/RTC/SCTP/packet/chunks/SackChunk.cpp +0 -1
  236. package/worker/src/RTC/SCTP/packet/parameters/StateCookieParameter.cpp +2 -2
  237. package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +2 -2
  238. package/worker/src/RTC/SCTP/public/SctpOptions.cpp +13 -13
  239. package/worker/src/RTC/SCTP/rx/DataTracker.cpp +1 -1
  240. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +5 -5
  241. package/worker/src/RTC/SCTP/tx/OutstandingData.cpp +15 -15
  242. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +15 -15
  243. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +29 -26
  244. package/worker/src/RTC/SCTP/tx/RoundRobinSendQueue.cpp +12 -11
  245. package/worker/src/RTC/SCTP/tx/StreamScheduler.cpp +4 -4
  246. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +2 -2
  247. package/worker/src/RTC/SimpleProducerStreamManager.cpp +10 -10
  248. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +39 -37
  249. package/worker/src/RTC/SvcProducerStreamManager.cpp +39 -25
  250. package/worker/src/RTC/TcpConnection.cpp +9 -3
  251. package/worker/src/RTC/TcpServer.cpp +7 -2
  252. package/worker/src/RTC/Transport.cpp +266 -307
  253. package/worker/src/RTC/TransportCongestionControlClient.cpp +78 -71
  254. package/worker/src/RTC/TransportCongestionControlServer.cpp +38 -40
  255. package/worker/src/RTC/TrendCalculator.cpp +3 -3
  256. package/worker/src/RTC/UdpSocket.cpp +14 -3
  257. package/worker/src/RTC/WebRtcServer.cpp +20 -14
  258. package/worker/src/RTC/WebRtcTransport.cpp +35 -30
  259. package/worker/src/Settings.cpp +10 -0
  260. package/worker/src/Shared.cpp +2 -2
  261. package/worker/src/Utils/Crypto.cpp +2 -2
  262. package/worker/src/Worker.cpp +5 -1
  263. package/worker/src/handles/BackoffTimerHandle.cpp +24 -11
  264. package/worker/src/handles/TimerHandle.cpp +74 -25
  265. package/worker/src/lib.cpp +6 -0
  266. package/worker/tasks.py +197 -45
  267. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +117 -0
  268. package/worker/test/src/RTC/BWE/TestAimdRateControl.cpp +400 -0
  269. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +568 -0
  270. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +546 -0
  271. package/worker/test/src/RTC/BWE/TestInterArrivalDelta.cpp +301 -0
  272. package/worker/test/src/RTC/BWE/TestLinkCapacityEstimator.cpp +115 -0
  273. package/worker/test/src/RTC/BWE/TestLossBasedController.cpp +1199 -0
  274. package/worker/test/src/RTC/BWE/TestRobustThroughputEstimator.cpp +433 -0
  275. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +259 -0
  276. package/worker/test/src/RTC/BWE/TestTargetRateController.cpp +337 -0
  277. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +182 -0
  278. package/worker/test/src/RTC/BWE/TestUtils.cpp +61 -0
  279. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +171 -0
  280. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +1 -1
  281. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +1 -1
  282. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +246 -208
  283. package/worker/test/src/RTC/RTP/TestPacket.cpp +11 -11
  284. package/worker/test/src/RTC/RTP/TestRetransmissionBuffer.cpp +12 -12
  285. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +23 -16
  286. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +13 -13
  287. package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +27 -22
  288. package/worker/test/src/RTC/SCTP/association/TestHeartbeatHandler.cpp +21 -15
  289. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +6 -6
  290. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +128 -13
  291. package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +3 -3
  292. package/worker/test/src/RTC/SCTP/packet/chunks/TestForwardTsnChunk.cpp +2 -2
  293. package/worker/test/src/RTC/SCTP/packet/chunks/TestIForwardTsnChunk.cpp +23 -23
  294. package/worker/test/src/RTC/SCTP/packet/chunks/TestInitChunk.cpp +1 -1
  295. package/worker/test/src/RTC/SCTP/packet/chunks/TestSackChunk.cpp +1 -1
  296. package/worker/test/src/RTC/SCTP/packet/parameters/TestIPv6AddressParameter.cpp +1 -1
  297. package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +37 -37
  298. package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +10 -10
  299. package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +1 -1
  300. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +93 -93
  301. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +247 -247
  302. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +100 -80
  303. package/worker/test/src/RTC/SCTP/tx/TestRoundRobinSendQueue.cpp +163 -163
  304. package/worker/test/src/RTC/SCTP/tx/TestStreamScheduler.cpp +76 -77
  305. package/worker/test/src/RTC/TestConsumer.cpp +8 -3
  306. package/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +3 -3
  307. package/worker/test/src/RTC/TestNackGenerator.cpp +3 -3
  308. package/worker/test/src/RTC/TestPipeProducerStreamManager.cpp +5 -5
  309. package/worker/test/src/RTC/TestRateCalculator.cpp +110 -14
  310. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +22 -17
  311. package/worker/test/src/RTC/TestRemoteClockOffsetEstimator.cpp +87 -85
  312. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +54 -47
  313. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +83 -69
  314. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +76 -65
  315. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +72 -66
  316. package/worker/test/src/RTC/TestTransportTuple.cpp +19 -4
  317. package/worker/test/src/TestDepLibUV.cpp +19 -0
  318. package/worker/test/src/Utils/TestTime.cpp +57 -26
  319. package/worker/test/src/testHelpers.cpp +1 -1
  320. package/worker/test/src/tests.cpp +6 -0
  321. package/worker/include/RTC/SenderBandwidthEstimator.hpp +0 -118
  322. package/worker/src/RTC/SenderBandwidthEstimator.cpp +0 -269
@@ -0,0 +1,433 @@
1
+ #include "common.hpp"
2
+ #include "RTC/BWE/BweTypes.hpp"
3
+ #include "RTC/BWE/RobustThroughputEstimator.hpp"
4
+ #include <catch2/catch_test_macros.hpp>
5
+ #include <catch2/matchers/catch_matchers_floating_point.hpp>
6
+
7
+ SCENARIO("BWE RobustThroughputEstimator", "[bwe][robustthroughputestimator]")
8
+ {
9
+ constexpr size_t PacketSize{ 1000 };
10
+ constexpr int64_t Rate800Kbps{ 800000 };
11
+ constexpr int64_t Rate1600Kbps{ 1600000 };
12
+ constexpr int64_t Rate400Kbps{ 400000 };
13
+ constexpr int64_t Rate200Kbps{ 200000 };
14
+ constexpr int64_t Rate4800Kbps{ 4800000 };
15
+
16
+ // Builds the packets a feedback would report, advancing the send and the
17
+ // arrival clocks at the given rates.
18
+ struct FeedbackGenerator
19
+ {
20
+ std::vector<RTC::BWE::Types::PacketResult> CreateFeedbackVector(
21
+ size_t numberOfPackets, size_t packetSize, int64_t sendRate, int64_t recvRate)
22
+ {
23
+ std::vector<RTC::BWE::Types::PacketResult> packetResults(numberOfPackets);
24
+
25
+ for (size_t idx{ 0 }; idx < numberOfPackets; ++idx)
26
+ {
27
+ packetResults[idx].sentPacket.sendTimeUs = this->sendClockUs;
28
+ packetResults[idx].sentPacket.sequenceNumber = this->sequenceNumber;
29
+ packetResults[idx].sentPacket.size = packetSize;
30
+
31
+ this->sendClockUs += static_cast<int64_t>(packetSize) * 8 * 1000000 / sendRate;
32
+ this->recvClockUs += static_cast<int64_t>(packetSize) * 8 * 1000000 / recvRate;
33
+ this->sequenceNumber += 1;
34
+
35
+ packetResults[idx].receiveTimeUs = this->recvClockUs;
36
+ }
37
+
38
+ return packetResults;
39
+ }
40
+
41
+ int64_t sendClockUs{ 100000 * 1000 };
42
+ int64_t recvClockUs{ 10000 * 1000 };
43
+ int64_t sequenceNumber{ 100 };
44
+ };
45
+
46
+ SECTION("there is no estimate until there are enough packets")
47
+ {
48
+ FeedbackGenerator feedbackGenerator;
49
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
50
+
51
+ auto packetResults =
52
+ feedbackGenerator.CreateFeedbackVector(9, PacketSize, Rate800Kbps, Rate800Kbps);
53
+
54
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
55
+
56
+ REQUIRE(!throughputEstimator.GetBitrate().has_value());
57
+
58
+ // The estimate appears once `requiredPackets` packets have been received.
59
+ packetResults = feedbackGenerator.CreateFeedbackVector(1, PacketSize, Rate800Kbps, Rate800Kbps);
60
+
61
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
62
+
63
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
64
+
65
+ // And it stays put while the send and arrival rates do.
66
+ packetResults = feedbackGenerator.CreateFeedbackVector(15, PacketSize, Rate800Kbps, Rate800Kbps);
67
+
68
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
69
+
70
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
71
+ }
72
+
73
+ SECTION("the estimate follows the rate up and down")
74
+ {
75
+ FeedbackGenerator feedbackGenerator;
76
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
77
+
78
+ // One second at 800 kbps, stable.
79
+ for (int i{ 0 }; i < 10; ++i)
80
+ {
81
+ const auto packetResults =
82
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate800Kbps, Rate800Kbps);
83
+
84
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
85
+
86
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
87
+ }
88
+
89
+ // One second at 1600 kbps, the estimate climbs without overshooting.
90
+ for (int i{ 0 }; i < 20; ++i)
91
+ {
92
+ const auto packetResults =
93
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate1600Kbps, Rate1600Kbps);
94
+
95
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
96
+
97
+ const auto throughput = throughputEstimator.GetBitrate();
98
+
99
+ REQUIRE(throughput.has_value());
100
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
101
+ REQUIRE(throughput.value() >= Rate800Kbps);
102
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
103
+ REQUIRE(throughput.value() <= Rate1600Kbps);
104
+ }
105
+
106
+ // Another second at 1600 kbps, now stable there.
107
+ for (int i{ 0 }; i < 20; ++i)
108
+ {
109
+ const auto packetResults =
110
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate1600Kbps, Rate1600Kbps);
111
+
112
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
113
+
114
+ REQUIRE(throughputEstimator.GetBitrate() == Rate1600Kbps);
115
+ }
116
+
117
+ // Down to 400 kbps, the estimate falls without undershooting.
118
+ for (int i{ 0 }; i < 5; ++i)
119
+ {
120
+ const auto packetResults =
121
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate400Kbps, Rate400Kbps);
122
+
123
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
124
+
125
+ const auto throughput = throughputEstimator.GetBitrate();
126
+
127
+ REQUIRE(throughput.has_value());
128
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
129
+ REQUIRE(throughput.value() <= Rate1600Kbps);
130
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
131
+ REQUIRE(throughput.value() >= Rate400Kbps);
132
+ }
133
+
134
+ // And stable at 400 kbps.
135
+ for (int i{ 0 }; i < 5; ++i)
136
+ {
137
+ const auto packetResults =
138
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate400Kbps, Rate400Kbps);
139
+
140
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
141
+
142
+ REQUIRE(throughputEstimator.GetBitrate() == Rate400Kbps);
143
+ }
144
+ }
145
+
146
+ SECTION("the estimate is capped by the arrival rate")
147
+ {
148
+ FeedbackGenerator feedbackGenerator;
149
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
150
+
151
+ const auto packetResults =
152
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate800Kbps, Rate200Kbps);
153
+
154
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
155
+
156
+ const auto throughput = throughputEstimator.GetBitrate();
157
+
158
+ REQUIRE(throughput.has_value());
159
+ REQUIRE_THAT(
160
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
161
+ static_cast<double>(throughput.value()),
162
+ Catch::Matchers::WithinAbs(Rate200Kbps, 0.05 * Rate200Kbps));
163
+ }
164
+
165
+ SECTION("the estimate is capped by the send rate")
166
+ {
167
+ FeedbackGenerator feedbackGenerator;
168
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
169
+
170
+ const auto packetResults =
171
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate400Kbps, Rate800Kbps);
172
+
173
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
174
+
175
+ const auto throughput = throughputEstimator.GetBitrate();
176
+
177
+ REQUIRE(throughput.has_value());
178
+ REQUIRE_THAT(
179
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
180
+ static_cast<double>(throughput.value()),
181
+ Catch::Matchers::WithinAbs(Rate400Kbps, 0.05 * Rate400Kbps));
182
+ }
183
+
184
+ SECTION("a delay spike doesn't drop the estimate")
185
+ {
186
+ // A 500 ms window amplifies the effect of the spike.
187
+ constexpr RTC::BWE::RobustThroughputEstimator::RobustThroughputEstimatorOptions ShortWindowOptions{
188
+ .minWindowDurationUs = 500 * 1000
189
+ };
190
+
191
+ FeedbackGenerator feedbackGenerator;
192
+ RTC::BWE::RobustThroughputEstimator throughputEstimator(ShortWindowOptions);
193
+
194
+ auto packetResults =
195
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate800Kbps, Rate800Kbps);
196
+
197
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
198
+
199
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
200
+
201
+ // The spike: 25 packets are sent and none arrives.
202
+ feedbackGenerator.recvClockUs += 250 * 1000;
203
+
204
+ // They are all delivered over the next 50 ms. Five more were sent
205
+ // meanwhile, so 30 packets of 1000 bytes in 50 ms, which is 4800 kbps.
206
+ for (int i{ 0 }; i < 30; ++i)
207
+ {
208
+ packetResults =
209
+ feedbackGenerator.CreateFeedbackVector(1, PacketSize, Rate800Kbps, Rate4800Kbps);
210
+
211
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
212
+
213
+ const auto throughput = throughputEstimator.GetBitrate();
214
+
215
+ REQUIRE(throughput.has_value());
216
+ REQUIRE_THAT(
217
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
218
+ static_cast<double>(throughput.value()),
219
+ Catch::Matchers::WithinAbs(Rate800Kbps, 0.05 * Rate800Kbps));
220
+ }
221
+
222
+ // Back to the normal rate. Once the packets from before the gap leave the
223
+ // window the arrival rate looks high, but the send rate caps the estimate.
224
+ for (int i{ 0 }; i < 20; ++i)
225
+ {
226
+ packetResults = feedbackGenerator.CreateFeedbackVector(5, PacketSize, Rate800Kbps, Rate800Kbps);
227
+
228
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
229
+
230
+ const auto throughput = throughputEstimator.GetBitrate();
231
+
232
+ REQUIRE(throughput.has_value());
233
+ REQUIRE_THAT(
234
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
235
+ static_cast<double>(throughput.value()),
236
+ Catch::Matchers::WithinAbs(Rate800Kbps, 0.05 * Rate800Kbps));
237
+ }
238
+ }
239
+
240
+ SECTION("losing half of the packets halves the estimate")
241
+ {
242
+ FeedbackGenerator feedbackGenerator;
243
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
244
+
245
+ auto packetResults =
246
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate800Kbps, Rate800Kbps);
247
+
248
+ for (size_t idx{ 0 }; idx < packetResults.size(); ++idx)
249
+ {
250
+ if (idx % 2 == 1)
251
+ {
252
+ packetResults[idx].receiveTimeUs.reset();
253
+ }
254
+ }
255
+
256
+ std::ranges::sort(packetResults, RTC::BWE::Types::PacketResult::ReceiveTimeOrder());
257
+
258
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
259
+
260
+ const auto throughput = throughputEstimator.GetBitrate();
261
+
262
+ REQUIRE(throughput.has_value());
263
+ REQUIRE_THAT(
264
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
265
+ static_cast<double>(throughput.value()),
266
+ Catch::Matchers::WithinAbs(Rate800Kbps / 2.0, 0.05 * Rate800Kbps / 2.0));
267
+ }
268
+
269
+ SECTION("a reordered feedback drops the estimate and it recovers when it arrives")
270
+ {
271
+ FeedbackGenerator feedbackGenerator;
272
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
273
+
274
+ auto packetResults =
275
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate800Kbps, Rate800Kbps);
276
+
277
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
278
+
279
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
280
+
281
+ const auto delayedPacketResults =
282
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate800Kbps, Rate800Kbps);
283
+
284
+ packetResults = feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate800Kbps, Rate800Kbps);
285
+
286
+ // Some feedback is missing, so the estimate is expected to drop.
287
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
288
+
289
+ const auto throughput = throughputEstimator.GetBitrate();
290
+
291
+ REQUIRE(throughput.has_value());
292
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
293
+ REQUIRE(throughput.value() < Rate800Kbps);
294
+
295
+ // And it recovers completely as soon as the missing feedback arrives.
296
+ throughputEstimator.IncomingPacketFeedbackVector(delayedPacketResults);
297
+
298
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
299
+
300
+ // From there on it's as stable as if nothing had been reordered.
301
+ for (int i{ 0 }; i < 10; ++i)
302
+ {
303
+ packetResults =
304
+ feedbackGenerator.CreateFeedbackVector(15, PacketSize, Rate800Kbps, Rate800Kbps);
305
+
306
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
307
+
308
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
309
+ }
310
+ }
311
+
312
+ SECTION("a packet arriving a second late doesn't drop the estimate")
313
+ {
314
+ // A 500 ms window amplifies the effect of the reordering.
315
+ constexpr RTC::BWE::RobustThroughputEstimator::RobustThroughputEstimatorOptions ShortWindowOptions{
316
+ .minWindowDurationUs = 500 * 1000
317
+ };
318
+
319
+ FeedbackGenerator feedbackGenerator;
320
+ RTC::BWE::RobustThroughputEstimator throughputEstimator(ShortWindowOptions);
321
+
322
+ auto delayedPacketResults =
323
+ feedbackGenerator.CreateFeedbackVector(1, PacketSize, Rate800Kbps, Rate800Kbps);
324
+
325
+ for (int i{ 0 }; i < 10; ++i)
326
+ {
327
+ const auto packetResults =
328
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate800Kbps, Rate800Kbps);
329
+
330
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
331
+
332
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
333
+ }
334
+
335
+ // The delayed packet arrives about a second after it should have. With a
336
+ // 500 ms window it was sent well before the second oldest packet, and even
337
+ // so the send rate must not drop.
338
+ delayedPacketResults.front().receiveTimeUs = feedbackGenerator.recvClockUs;
339
+
340
+ throughputEstimator.IncomingPacketFeedbackVector(delayedPacketResults);
341
+
342
+ {
343
+ const auto throughput = throughputEstimator.GetBitrate();
344
+
345
+ REQUIRE(throughput.has_value());
346
+ REQUIRE_THAT(
347
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
348
+ static_cast<double>(throughput.value()),
349
+ Catch::Matchers::WithinAbs(Rate800Kbps, 0.05 * Rate800Kbps));
350
+ }
351
+
352
+ for (int i{ 0 }; i < 10; ++i)
353
+ {
354
+ const auto packetResults =
355
+ feedbackGenerator.CreateFeedbackVector(10, PacketSize, Rate800Kbps, Rate800Kbps);
356
+
357
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
358
+
359
+ const auto throughput = throughputEstimator.GetBitrate();
360
+
361
+ REQUIRE(throughput.has_value());
362
+ REQUIRE_THAT(
363
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
364
+ static_cast<double>(throughput.value()),
365
+ Catch::Matchers::WithinAbs(Rate800Kbps, 0.05 * Rate800Kbps));
366
+ }
367
+ }
368
+
369
+ SECTION("the window is dropped when the arrival clock moves backwards")
370
+ {
371
+ FeedbackGenerator feedbackGenerator;
372
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
373
+
374
+ auto packetResults =
375
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate800Kbps, Rate800Kbps);
376
+
377
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
378
+
379
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
380
+
381
+ feedbackGenerator.recvClockUs -= 2 * 1000 * 1000;
382
+
383
+ packetResults =
384
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate1600Kbps, Rate1600Kbps);
385
+
386
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
387
+
388
+ REQUIRE(throughputEstimator.GetBitrate() == Rate1600Kbps);
389
+ }
390
+
391
+ SECTION("pausing and resuming the stream invalidates the estimate until there is data again")
392
+ {
393
+ FeedbackGenerator feedbackGenerator;
394
+ RTC::BWE::RobustThroughputEstimator throughputEstimator;
395
+
396
+ auto packetResults =
397
+ feedbackGenerator.CreateFeedbackVector(20, PacketSize, Rate800Kbps, Rate800Kbps);
398
+
399
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
400
+
401
+ {
402
+ const auto throughput = throughputEstimator.GetBitrate();
403
+
404
+ REQUIRE(throughput.has_value());
405
+ REQUIRE_THAT(
406
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
407
+ static_cast<double>(throughput.value()),
408
+ Catch::Matchers::WithinAbs(Rate800Kbps, 0.05 * Rate800Kbps));
409
+ }
410
+
411
+ // Nothing is sent and no feedback arrives for 60 seconds.
412
+ feedbackGenerator.sendClockUs += 60 * 1000 * 1000;
413
+ feedbackGenerator.recvClockUs += 60 * 1000 * 1000;
414
+
415
+ // Sending resumes at the same rate. The estimate is invalid at first, since
416
+ // there is no recent data to compute it from.
417
+ packetResults = feedbackGenerator.CreateFeedbackVector(5, PacketSize, Rate800Kbps, Rate800Kbps);
418
+
419
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
420
+
421
+ REQUIRE(!throughputEstimator.GetBitrate().has_value());
422
+
423
+ // And it's back to the usual level once there is enough data again.
424
+ for (int i{ 0 }; i < 4; ++i)
425
+ {
426
+ packetResults = feedbackGenerator.CreateFeedbackVector(5, PacketSize, Rate800Kbps, Rate800Kbps);
427
+
428
+ throughputEstimator.IncomingPacketFeedbackVector(packetResults);
429
+
430
+ REQUIRE(throughputEstimator.GetBitrate() == Rate800Kbps);
431
+ }
432
+ }
433
+ }
@@ -0,0 +1,259 @@
1
+ #include "common.hpp"
2
+ #include "RTC/BWE/SendPacketHistory.hpp"
3
+ #include <catch2/catch_test_macros.hpp>
4
+
5
+ SCENARIO("BWE SendPacketHistory", "[bwe][sendpackethistory]")
6
+ {
7
+ // The clock starts well away from zero so that a mistake taking a time for a
8
+ // duration doesn't go unnoticed.
9
+ constexpr int64_t InitialTimeUs{ 100000000 };
10
+ constexpr size_t PacketSize{ 1000 };
11
+ constexpr uint32_t Ssrc{ 1111 };
12
+
13
+ SECTION("sequence numbers are given out in order, starting at zero")
14
+ {
15
+ RTC::BWE::SendPacketHistory sendPacketHistory;
16
+
17
+ REQUIRE(sendPacketHistory.GetLastSequenceNumber() == std::nullopt);
18
+
19
+ REQUIRE(sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs) == 0);
20
+ REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 0);
21
+
22
+ REQUIRE(sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + 10000) == 1);
23
+ REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 1);
24
+
25
+ REQUIRE(sendPacketHistory.AddPacket(Ssrc, 102, PacketSize, false, InitialTimeUs + 20000) == 2);
26
+ REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 2);
27
+ }
28
+
29
+ SECTION("a packet is retrieved as it was sent")
30
+ {
31
+ RTC::BWE::SendPacketHistory sendPacketHistory;
32
+
33
+ const int64_t sequenceNumber =
34
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, true, InitialTimeUs);
35
+
36
+ const auto retrievedPacket = sendPacketHistory.RetrievePacket(sequenceNumber, true);
37
+
38
+ REQUIRE(retrievedPacket.has_value());
39
+
40
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
41
+ const auto& sentPacket = retrievedPacket.value();
42
+
43
+ REQUIRE(sentPacket.sequenceNumber == sequenceNumber);
44
+ REQUIRE(sentPacket.sendTimeUs == InitialTimeUs);
45
+ REQUIRE(sentPacket.size == PacketSize);
46
+ REQUIRE(sentPacket.audio == true);
47
+ }
48
+
49
+ SECTION("a sequence number that was never given out is not resolved")
50
+ {
51
+ RTC::BWE::SendPacketHistory sendPacketHistory;
52
+
53
+ REQUIRE(sendPacketHistory.RetrievePacket(0, true) == std::nullopt);
54
+
55
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
56
+
57
+ REQUIRE(sendPacketHistory.RetrievePacket(-1, true) == std::nullopt);
58
+ REQUIRE(sendPacketHistory.RetrievePacket(1, true) == std::nullopt);
59
+ REQUIRE(sendPacketHistory.RetrievePacket(1000000, true) == std::nullopt);
60
+ }
61
+
62
+ SECTION("a packet reported as received is not resolved twice")
63
+ {
64
+ RTC::BWE::SendPacketHistory sendPacketHistory;
65
+
66
+ const int64_t sequenceNumber =
67
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
68
+
69
+ REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true).has_value());
70
+ REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true) == std::nullopt);
71
+ }
72
+
73
+ SECTION("a packet reported as lost is kept, since it may be reported as received later")
74
+ {
75
+ RTC::BWE::SendPacketHistory sendPacketHistory;
76
+
77
+ const int64_t sequenceNumber =
78
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
79
+
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);
84
+ }
85
+
86
+ SECTION("a packet is resolved by its SSRC and RTP sequence number too")
87
+ {
88
+ RTC::BWE::SendPacketHistory sendPacketHistory;
89
+
90
+ const int64_t sequenceNumber =
91
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
92
+
93
+ sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + 10000);
94
+
95
+ const auto sentPacket = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
96
+
97
+ REQUIRE(sentPacket.has_value());
98
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
99
+ REQUIRE(sentPacket->sequenceNumber == sequenceNumber);
100
+
101
+ // The very same RTP sequence number of another stream is another packet.
102
+ REQUIRE(sendPacketHistory.RetrievePacket(Ssrc + 1, 101, true) == std::nullopt);
103
+ }
104
+
105
+ SECTION("the latest send of a repeated SSRC and RTP sequence number takes over")
106
+ {
107
+ RTC::BWE::SendPacketHistory sendPacketHistory;
108
+
109
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
110
+
111
+ const int64_t retransmissionSequenceNumber =
112
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs + 10000);
113
+
114
+ const auto sentPacket = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
115
+
116
+ REQUIRE(sentPacket.has_value());
117
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
118
+ REQUIRE(sentPacket->sequenceNumber == retransmissionSequenceNumber);
119
+ }
120
+
121
+ SECTION("resolving the first send of a repeated one does not drop the mapping of the latest")
122
+ {
123
+ RTC::BWE::SendPacketHistory sendPacketHistory;
124
+
125
+ const int64_t firstSequenceNumber =
126
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
127
+
128
+ const int64_t retransmissionSequenceNumber =
129
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs + 10000);
130
+
131
+ REQUIRE(sendPacketHistory.RetrievePacket(firstSequenceNumber, true).has_value());
132
+
133
+ const auto sentPacket = sendPacketHistory.RetrievePacket(Ssrc, 100, true);
134
+
135
+ REQUIRE(sentPacket.has_value());
136
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
137
+ REQUIRE(sentPacket->sequenceNumber == retransmissionSequenceNumber);
138
+ }
139
+
140
+ SECTION("bytes in flight are those of the packets no feedback has reported on")
141
+ {
142
+ RTC::BWE::SendPacketHistory sendPacketHistory;
143
+
144
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
145
+
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);
149
+
150
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 3 * PacketSize);
151
+
152
+ // Reporting on a packet settles every packet before it as well.
153
+ sendPacketHistory.RetrievePacket(1, true);
154
+
155
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
156
+
157
+ sendPacketHistory.RetrievePacket(2, true);
158
+
159
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
160
+ }
161
+
162
+ SECTION("a packet is told the bytes that were in flight when it was sent")
163
+ {
164
+ RTC::BWE::SendPacketHistory sendPacketHistory;
165
+
166
+ sendPacketHistory.AddPacket(Ssrc, 100, 200, false, InitialTimeUs);
167
+ sendPacketHistory.AddPacket(Ssrc, 101, 300, false, InitialTimeUs + 10000);
168
+
169
+ const auto firstSentPacket = sendPacketHistory.RetrievePacket(0, false);
170
+
171
+ REQUIRE(firstSentPacket.has_value());
172
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
173
+ REQUIRE(firstSentPacket->dataInFlight == 200);
174
+
175
+ const auto secondSentPacket = sendPacketHistory.RetrievePacket(1, false);
176
+
177
+ REQUIRE(secondSentPacket.has_value());
178
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
179
+ REQUIRE(secondSentPacket->dataInFlight == 500);
180
+ }
181
+
182
+ SECTION("a packet reported as lost stops counting as in flight")
183
+ {
184
+ RTC::BWE::SendPacketHistory sendPacketHistory;
185
+
186
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
187
+
188
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
189
+
190
+ sendPacketHistory.RetrievePacket(0, false);
191
+
192
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
193
+
194
+ // It's still held, and reporting on it again changes nothing.
195
+ sendPacketHistory.RetrievePacket(0, true);
196
+
197
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
198
+ }
199
+
200
+ SECTION("a feedback arriving out of order does not take bytes out twice")
201
+ {
202
+ RTC::BWE::SendPacketHistory sendPacketHistory;
203
+
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);
207
+
208
+ sendPacketHistory.RetrievePacket(2, true);
209
+
210
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
211
+
212
+ sendPacketHistory.RetrievePacket(0, true);
213
+ sendPacketHistory.RetrievePacket(1, true);
214
+
215
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
216
+ }
217
+
218
+ SECTION("packets held for longer than the window are dropped")
219
+ {
220
+ constexpr int64_t WindowDurationUs{ 1000000 };
221
+
222
+ RTC::BWE::SendPacketHistory sendPacketHistory({ .windowDurationUs = WindowDurationUs });
223
+
224
+ const int64_t sequenceNumber =
225
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
226
+
227
+ // Right at the window it's still held.
228
+ sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + WindowDurationUs);
229
+
230
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 2 * PacketSize);
231
+
232
+ sendPacketHistory.AddPacket(Ssrc, 102, PacketSize, false, InitialTimeUs + WindowDurationUs + 1);
233
+
234
+ REQUIRE(sendPacketHistory.RetrievePacket(sequenceNumber, true) == std::nullopt);
235
+ REQUIRE(sendPacketHistory.RetrievePacket(Ssrc, 100, true) == std::nullopt);
236
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 2 * PacketSize);
237
+
238
+ // The sequence numbers of the dropped packets are not given out again.
239
+ REQUIRE(sendPacketHistory.GetLastSequenceNumber() == 2);
240
+ }
241
+
242
+ SECTION("the window does not take out the bytes of a packet already reported on")
243
+ {
244
+ constexpr int64_t WindowDurationUs{ 1000000 };
245
+
246
+ RTC::BWE::SendPacketHistory sendPacketHistory({ .windowDurationUs = WindowDurationUs });
247
+
248
+ sendPacketHistory.AddPacket(Ssrc, 100, PacketSize, false, InitialTimeUs);
249
+
250
+ // Reported as lost, so its bytes are gone but it's still held.
251
+ sendPacketHistory.RetrievePacket(0, false);
252
+
253
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == 0);
254
+
255
+ sendPacketHistory.AddPacket(Ssrc, 101, PacketSize, false, InitialTimeUs + WindowDurationUs + 1);
256
+
257
+ REQUIRE(sendPacketHistory.GetOutstandingBytes() == PacketSize);
258
+ }
259
+ }