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
@@ -196,7 +196,7 @@ namespace RTC
196
196
  {
197
197
  StreamReset streamReset = std::get<StreamReset>(std::move(data));
198
198
  listener->OnAssociationStreamsResetPerformed(streamReset.streamIds);
199
- },
199
+ },
200
200
  StreamReset{ .streamIds = { outboundStreamIds.begin(), outboundStreamIds.end() } });
201
201
  }
202
202
 
@@ -212,9 +212,9 @@ namespace RTC
212
212
  {
213
213
  StreamReset streamReset = std::get<StreamReset>(std::move(data));
214
214
  listener->OnAssociationStreamsResetFailed(streamReset.streamIds, streamReset.errorMessage);
215
- },
215
+ },
216
216
  StreamReset{ .streamIds = { outboundStreamIds.begin(), outboundStreamIds.end() },
217
- .errorMessage = std::string(errorMessage) });
217
+ .errorMessage = std::string(errorMessage) });
218
218
  }
219
219
 
220
220
  void AssociationListenerDeferrer::OnAssociationInboundStreamsReset(
@@ -229,7 +229,7 @@ namespace RTC
229
229
  {
230
230
  StreamReset streamReset = std::get<StreamReset>(std::move(data));
231
231
  listener->OnAssociationInboundStreamsReset(streamReset.streamIds);
232
- },
232
+ },
233
233
  StreamReset{ .streamIds = { inboundStreamIds.begin(), inboundStreamIds.end() } });
234
234
  }
235
235
 
@@ -35,7 +35,7 @@ namespace RTC
35
35
  capabilities.partialReliability =
36
36
  remoteForwardTsnSupportedParameter ||
37
37
  (remoteSupportedExtensionsParameter &&
38
- remoteSupportedExtensionsParameter->IncludesChunkType(Chunk::ChunkType::FORWARD_TSN));
38
+ remoteSupportedExtensionsParameter->IncludesChunkType(Chunk::ChunkType::FORWARD_TSN));
39
39
 
40
40
  // Remote announces Message Interleaving support via Supported Extensions
41
41
  // parameter.
@@ -71,8 +71,9 @@ namespace RTC
71
71
 
72
72
  if (intervalDurationShouldIncludeRtt)
73
73
  {
74
+ // NOTE: The timer takes milliseconds, so the RTO is truncated here.
74
75
  this->intervalTimer->SetBaseTimeoutMs(
75
- this->intervalDurationMs + this->tcbContext->GetCurrentRtoMs());
76
+ this->intervalDurationMs + (this->tcbContext->GetCurrentRtoUs() / 1000));
76
77
  }
77
78
  else
78
79
  {
@@ -149,24 +150,27 @@ namespace RTC
149
150
  return;
150
151
  }
151
152
 
152
- const uint64_t createdAtMs = Utils::Byte::Get8Bytes(info, 0);
153
- const uint64_t nowMs = this->shared->GetTimeMs();
153
+ // NOTE: The peer echoes back the info we wrote, so this value cannot be
154
+ // trusted. The guard below rejects it unless it's a past instant, which
155
+ // also rejects a negative resulting from garbage above 2^63.
156
+ const auto createdAtUs = static_cast<int64_t>(Utils::Byte::Get8Bytes(info, 0));
157
+ const int64_t nowUs = this->shared->GetTimeUs();
154
158
 
155
- if (createdAtMs > 0 && createdAtMs <= nowMs)
159
+ if (createdAtUs > 0 && createdAtUs <= nowUs)
156
160
  {
157
- const uint64_t rttMs = nowMs - createdAtMs;
161
+ const int64_t rttUs = nowUs - createdAtUs;
158
162
 
159
- MS_DEBUG_DEV("valid HEARTBEAT-ACK chunk received, calling ObserveRttMs(%" PRIu64 ")", rttMs);
163
+ MS_DEBUG_DEV("valid HEARTBEAT-ACK chunk received, calling ObserveRttUs(%" PRIi64 ")", rttUs);
160
164
 
161
- this->tcbContext->ObserveRttMs(rttMs);
165
+ this->tcbContext->ObserveRttUs(rttUs);
162
166
  }
163
167
  else
164
168
  {
165
169
  MS_WARN_DEV(
166
- "ignoring received HEARTBEAT-ACK chunk with invalid info content [createdAtMs:%" PRIu64
167
- ", nowMs:%" PRIu64 "]",
168
- createdAtMs,
169
- nowMs);
170
+ "ignoring received HEARTBEAT-ACK chunk with invalid info content [createdAtUs:%" PRIi64
171
+ ", nowUs:%" PRIi64 "]",
172
+ createdAtUs,
173
+ nowUs);
170
174
  }
171
175
 
172
176
  // https://datatracker.ietf.org/doc/html/rfc9260#section-8.1
@@ -176,7 +180,7 @@ namespace RTC
176
180
  this->tcbContext->ClearTxErrorCounter();
177
181
  }
178
182
 
179
- void HeartbeatHandler::OnIntervalTimer(uint64_t& /*baseTimeoutMs*/, bool& /*stop*/)
183
+ void HeartbeatHandler::OnIntervalTimer(int64_t& /*baseTimeoutMs*/, bool& /*stop*/)
180
184
  {
181
185
  MS_TRACE();
182
186
 
@@ -204,14 +208,17 @@ namespace RTC
204
208
  return;
205
209
  }
206
210
 
207
- this->timeoutTimer->SetBaseTimeoutMs(this->tcbContext->GetCurrentRtoMs());
211
+ // NOTE: The timer takes milliseconds, so the RTO is truncated here.
212
+ this->timeoutTimer->SetBaseTimeoutMs(this->tcbContext->GetCurrentRtoUs() / 1000);
208
213
  this->timeoutTimer->Start();
209
214
 
210
215
  alignas(8) uint8_t info[HeartbeatInfoLength];
211
216
 
212
- const uint64_t nowMs = this->shared->GetTimeMs();
217
+ // NOTE: This is read back in HandleReceivedHeartbeatAckChunk() when the
218
+ // peer echoes it, so both sides of it must use the same unit.
219
+ const int64_t nowUs = this->shared->GetTimeUs();
213
220
 
214
- Utils::Byte::Set8Bytes(info, 0, nowMs);
221
+ Utils::Byte::Set8Bytes(info, 0, static_cast<uint64_t>(nowUs));
215
222
 
216
223
  auto packet = this->tcbContext->CreatePacket();
217
224
  auto* heartbeatRequestChunk = packet->BuildChunkInPlace<HeartbeatRequestChunk>();
@@ -222,12 +229,12 @@ namespace RTC
222
229
  heartbeatInfoParameter->Consolidate();
223
230
  heartbeatRequestChunk->Consolidate();
224
231
 
225
- MS_DEBUG_DEV("sending HEARTBEAT-REQUEST chunk with info content [nowMs:%" PRIu64 "]", nowMs);
232
+ MS_DEBUG_DEV("sending HEARTBEAT-REQUEST chunk with info content [nowUs:%" PRIi64 "]", nowUs);
226
233
 
227
234
  this->tcbContext->SendPacket(packet.get());
228
235
  }
229
236
 
230
- void HeartbeatHandler::OnTimeoutTimer(uint64_t& /*baseTimeoutMs*/, bool& stop)
237
+ void HeartbeatHandler::OnTimeoutTimer(int64_t& /*baseTimeoutMs*/, bool& stop)
231
238
  {
232
239
  MS_TRACE();
233
240
 
@@ -261,7 +268,7 @@ namespace RTC
261
268
  }
262
269
 
263
270
  void HeartbeatHandler::OnBackoffTimer(
264
- BackoffTimerHandleInterface* backoffTimer, uint64_t& baseTimeoutMs, bool& stop)
271
+ BackoffTimerHandleInterface* backoffTimer, int64_t& baseTimeoutMs, bool& stop)
265
272
  {
266
273
  MS_TRACE();
267
274
 
@@ -49,7 +49,7 @@ namespace RTC
49
49
  uint32_t remoteAdvertisedReceiverWindowCredit,
50
50
  uint64_t tieTag,
51
51
  const Capabilities& remoteCapabilities,
52
- uint64_t creationTimestampMs,
52
+ int64_t creationTimestampUs,
53
53
  const uint8_t* macKey,
54
54
  size_t macKeyLength)
55
55
  {
@@ -66,7 +66,7 @@ namespace RTC
66
66
  remoteAdvertisedReceiverWindowCredit,
67
67
  tieTag,
68
68
  remoteCapabilities,
69
- creationTimestampMs,
69
+ creationTimestampUs,
70
70
  macKey,
71
71
  macKeyLength);
72
72
 
@@ -86,7 +86,7 @@ namespace RTC
86
86
  uint32_t remoteAdvertisedReceiverWindowCredit,
87
87
  uint64_t tieTag,
88
88
  const Capabilities& remoteCapabilities,
89
- uint64_t creationTimestampMs,
89
+ int64_t creationTimestampUs,
90
90
  const uint8_t* macKey,
91
91
  size_t macKeyLength)
92
92
  {
@@ -132,7 +132,8 @@ namespace RTC
132
132
  // bytes (including the timestamp).
133
133
  //
134
134
  // @see RFC 9260 section 5.1.3.
135
- Utils::Byte::Set8Bytes(buffer, StateCookie::TimestampOffset, creationTimestampMs);
135
+ Utils::Byte::Set8Bytes(
136
+ buffer, StateCookie::TimestampOffset, static_cast<uint64_t>(creationTimestampUs));
136
137
 
137
138
  const uint8_t* mac = Utils::Crypto::GetHmacSha1(
138
139
  reinterpret_cast<const char*>(macKey), macKeyLength, buffer, StateCookie::MacOffset);
@@ -228,7 +229,7 @@ namespace RTC
228
229
  SetLength(
229
230
  bufferLength == StateCookie::AuthenticatedStateCookieLength
230
231
  ? StateCookie::AuthenticatedStateCookieLength
231
- : StateCookie::StateCookieLength);
232
+ : StateCookie::StateCookieLength);
232
233
  }
233
234
 
234
235
  StateCookie::~StateCookie()
@@ -258,7 +259,7 @@ namespace RTC
258
259
 
259
260
  if (IsAuthenticated())
260
261
  {
261
- MS_DUMP_CLEAN(indentation, " creation timestamp (ms): %" PRIu64, GetCreationTimestampMs());
262
+ MS_DUMP_CLEAN(indentation, " creation timestamp (us): %" PRIi64, GetCreationTimestampUs());
262
263
  }
263
264
 
264
265
  MS_DUMP_CLEAN(indentation, " remote capabilities:");
@@ -77,7 +77,8 @@ namespace RTC
77
77
  this->retransmissionQueue->GetLastAssignedTsn(),
78
78
  this->retransmissionQueue->BeginResetStreams());
79
79
 
80
- this->reConfigTimer->SetBaseTimeoutMs(this->tcbContext->GetCurrentRtoMs());
80
+ // NOTE: The timer takes milliseconds, so the RTO is truncated here.
81
+ this->reConfigTimer->SetBaseTimeoutMs(this->tcbContext->GetCurrentRtoUs() / 1000);
81
82
  this->reConfigTimer->Start();
82
83
 
83
84
  AddReConfigChunk(packet);
@@ -142,6 +143,63 @@ namespace RTC
142
143
  }
143
144
  }
144
145
 
146
+ bool StreamResetHandler::MayLeaveDeferredReset()
147
+ {
148
+ MS_TRACE();
149
+
150
+ if (!this->deferredIncomingRequest.has_value())
151
+ {
152
+ return false;
153
+ }
154
+
155
+ // https://tools.ietf.org/html/rfc6525#section-5.2.2
156
+ //
157
+ // "In this mode, any data arriving with a TSN larger than the Sender's
158
+ // Last Assigned TSN for the affected stream(s) MUST be queued locally and
159
+ // held until the cumulative acknowledgment point reaches the Sender's Last
160
+ // Assigned TSN."
161
+ //
162
+ // So deferred reset processing must end as soon as the cumulative ack TSN
163
+ // reaches the sender's last assigned TSN. Otherwise the queued data would
164
+ // be held (and accounted for) until the peer decides to retransmit its
165
+ // request, which it may never do.
166
+ if (this->dataTracker->IsLaterThanCumulativeAckedTsn(this->deferredIncomingRequest->senderLastAssignedTsn))
167
+ {
168
+ return false;
169
+ }
170
+
171
+ MS_DEBUG_DEV(
172
+ "leaving deferred reset processing, sender last assigned tsn %" PRIu32 " reached",
173
+ this->deferredIncomingRequest->senderLastAssignedTsn);
174
+
175
+ // Remember the request being performed here. The peer was told "in
176
+ // progress" and will retry it with a new request sequence number, and that
177
+ // retry must not reset the very same streams a second time.
178
+ this->performedDeferredRequest = std::move(this->deferredIncomingRequest);
179
+
180
+ this->deferredIncomingRequest = std::nullopt;
181
+
182
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
183
+ const auto& streamIds = this->performedDeferredRequest.value().streamIds;
184
+
185
+ // https://tools.ietf.org/html/rfc6525#section-5.2.2
186
+ //
187
+ // E3) "If no stream numbers are listed in the parameter, then all incoming
188
+ // streams MUST be reset to 0 as the next expected SSN. If specific stream
189
+ // numbers are listed, then only these specific streams MUST be reset to 0,
190
+ // and all other non-listed SSNs remain unchanged." E4: "Any queued TSNs
191
+ // (queued at step E2) MUST now be released and processed normally."
192
+ this->reassemblyQueue->ResetStreamsAndLeaveDeferredReset(streamIds);
193
+
194
+ this->associationListenerDeferrer.OnAssociationInboundStreamsReset(streamIds);
195
+
196
+ // The request has now been performed, so a retransmission of it must get
197
+ // the final response rather than "in progress" again.
198
+ this->lastProcessedReqResult = ReconfigurationResponseParameter::Result::SUCCESS_PERFORMED;
199
+
200
+ return true;
201
+ }
202
+
145
203
  bool StreamResetHandler::ValidateReceivedReConfigChunk(const ReConfigChunk* receivedReConfigChunk)
146
204
  {
147
205
  MS_TRACE();
@@ -168,21 +226,21 @@ namespace RTC
168
226
 
169
227
  if (
170
228
  (firstParameter->GetType() == Parameter::ParameterType::OUTGOING_SSN_RESET_REQUEST &&
171
- secondParameter->GetType() == Parameter::ParameterType::INCOMING_SSN_RESET_REQUEST) ||
229
+ secondParameter->GetType() == Parameter::ParameterType::INCOMING_SSN_RESET_REQUEST) ||
172
230
  (firstParameter->GetType() == Parameter::ParameterType::INCOMING_SSN_RESET_REQUEST &&
173
- secondParameter->GetType() == Parameter::ParameterType::OUTGOING_SSN_RESET_REQUEST) ||
231
+ secondParameter->GetType() == Parameter::ParameterType::OUTGOING_SSN_RESET_REQUEST) ||
174
232
  (firstParameter->GetType() == Parameter::ParameterType::ADD_OUTGOING_STREAMS_REQUEST &&
175
- secondParameter->GetType() == Parameter::ParameterType::ADD_INCOMING_STREAMS_REQUEST) ||
233
+ secondParameter->GetType() == Parameter::ParameterType::ADD_INCOMING_STREAMS_REQUEST) ||
176
234
  (firstParameter->GetType() == Parameter::ParameterType::ADD_INCOMING_STREAMS_REQUEST &&
177
- secondParameter->GetType() == Parameter::ParameterType::ADD_OUTGOING_STREAMS_REQUEST) ||
235
+ secondParameter->GetType() == Parameter::ParameterType::ADD_OUTGOING_STREAMS_REQUEST) ||
178
236
  (firstParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE &&
179
- secondParameter->GetType() == Parameter::ParameterType::OUTGOING_SSN_RESET_REQUEST) ||
237
+ secondParameter->GetType() == Parameter::ParameterType::OUTGOING_SSN_RESET_REQUEST) ||
180
238
  (firstParameter->GetType() == Parameter::ParameterType::OUTGOING_SSN_RESET_REQUEST &&
181
- secondParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE) ||
239
+ secondParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE) ||
182
240
  (firstParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE &&
183
- secondParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE) ||
241
+ secondParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE) ||
184
242
  (firstParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE &&
185
- secondParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE))
243
+ secondParameter->GetType() == Parameter::ParameterType::RECONFIGURATION_RESPONSE))
186
244
  {
187
245
  return true;
188
246
  }
@@ -283,6 +341,11 @@ namespace RTC
283
341
  validationResult == ReqSeqNbrValidationResult::RETRANSMISSION &&
284
342
  this->lastProcessedReqResult != ReconfigurationResponseParameter::Result::IN_PROGRESS)
285
343
  {
344
+ // The peer is getting the final result of this request, so there is no
345
+ // longer a need to remember that it may have been performed when leaving
346
+ // deferred reset processing.
347
+ this->performedDeferredRequest = std::nullopt;
348
+
286
349
  auto* reconfigurationResponseParameter =
287
350
  reConfigChunk->BuildParameterInPlace<ReconfigurationResponseParameter>();
288
351
 
@@ -300,7 +363,33 @@ namespace RTC
300
363
  // "In Progress" request. In all cases, re-evaluate the state.
301
364
  this->lastProcessedReqSeqNbr = requestSn;
302
365
 
303
- if (
366
+ // This very same request may have already been performed when the
367
+ // cumulative ack TSN reached its sender's last assigned TSN. The peer was
368
+ // told "in progress" and doesn't know it yet, so it retries it with a new
369
+ // request sequence number. Resetting those streams again would set their
370
+ // next expected SSN back to 0 after post reset data may have already been
371
+ // received, so just reply the final result.
372
+ const bool alreadyPerformed =
373
+ this->performedDeferredRequest.has_value() &&
374
+ this->performedDeferredRequest->senderLastAssignedTsn ==
375
+ receivedOutgoingSsnResetRequestParameter->GetSenderLastAssignedTsn() &&
376
+ this->performedDeferredRequest->streamIds ==
377
+ receivedOutgoingSsnResetRequestParameter->GetStreamIds();
378
+
379
+ this->performedDeferredRequest = std::nullopt;
380
+
381
+ if (alreadyPerformed)
382
+ {
383
+ // Set the result again rather than relying on the one stored when the
384
+ // reset was performed, since a received incoming stream reset request
385
+ // may have overwritten it in the meantime.
386
+ this->lastProcessedReqResult = ReconfigurationResponseParameter::Result::SUCCESS_PERFORMED;
387
+
388
+ MS_DEBUG_DEV(
389
+ "reset outgoing already performed when leaving deferred reset processing, sender last assigned tsn %" PRIu32,
390
+ receivedOutgoingSsnResetRequestParameter->GetSenderLastAssignedTsn());
391
+ }
392
+ else if (
304
393
  this->dataTracker->IsLaterThanCumulativeAckedTsn(
305
394
  receivedOutgoingSsnResetRequestParameter->GetSenderLastAssignedTsn()))
306
395
  {
@@ -313,6 +402,21 @@ namespace RTC
313
402
  receivedOutgoingSsnResetRequestParameter->GetSenderLastAssignedTsn(),
314
403
  receivedOutgoingSsnResetRequestParameter->GetStreamIds());
315
404
 
405
+ // Remember the request so that deferred reset processing can end as soon
406
+ // as the cumulative ack TSN reaches the sender's last assigned TSN,
407
+ // without depending on the peer retransmitting its request.
408
+ //
409
+ // NOTE: Just like ReassemblyQueue::EnterDeferredReset() does, a new
410
+ // request is ignored while already in deferred reset processing.
411
+ if (!this->deferredIncomingRequest.has_value())
412
+ {
413
+ this->deferredIncomingRequest = DeferredIncomingRequest{
414
+ .senderLastAssignedTsn =
415
+ receivedOutgoingSsnResetRequestParameter->GetSenderLastAssignedTsn(),
416
+ .streamIds = receivedOutgoingSsnResetRequestParameter->GetStreamIds(),
417
+ };
418
+ }
419
+
316
420
  // "If the endpoint enters 'deferred reset processing', it MUST put a
317
421
  // Re-configuration Response Parameter into a RE-CONFIG chunk indicating
318
422
  // 'In progress' and MUST send the RE-CONFIG chunk.
@@ -334,6 +438,8 @@ namespace RTC
334
438
  this->reassemblyQueue->ResetStreamsAndLeaveDeferredReset(
335
439
  receivedOutgoingSsnResetRequestParameter->GetStreamIds());
336
440
 
441
+ this->deferredIncomingRequest = std::nullopt;
442
+
337
443
  this->associationListenerDeferrer.OnAssociationInboundStreamsReset(
338
444
  receivedOutgoingSsnResetRequestParameter->GetStreamIds());
339
445
 
@@ -435,7 +541,8 @@ namespace RTC
435
541
  // Force this request to be sent again, but with the same `reqSeqNbr`.
436
542
  this->currentRequest->SetDeferred(true);
437
543
 
438
- this->reConfigTimer->SetBaseTimeoutMs(this->tcbContext->GetCurrentRtoMs());
544
+ // NOTE: The timer takes milliseconds, so the RTO is truncated here.
545
+ this->reConfigTimer->SetBaseTimeoutMs(this->tcbContext->GetCurrentRtoUs() / 1000);
439
546
  this->reConfigTimer->Start();
440
547
 
441
548
  break;
@@ -469,7 +576,7 @@ namespace RTC
469
576
  }
470
577
  }
471
578
 
472
- void StreamResetHandler::OnReConfigTimer(uint64_t& baseTimeoutMs, bool& stop)
579
+ void StreamResetHandler::OnReConfigTimer(int64_t& baseTimeoutMs, bool& stop)
473
580
  {
474
581
  MS_TRACE();
475
582
 
@@ -520,11 +627,12 @@ namespace RTC
520
627
 
521
628
  this->tcbContext->SendPacket(packet.get());
522
629
 
523
- baseTimeoutMs = this->tcbContext->GetCurrentRtoMs();
630
+ // NOTE: The timer takes milliseconds, so the RTO is truncated here.
631
+ baseTimeoutMs = this->tcbContext->GetCurrentRtoUs() / 1000;
524
632
  }
525
633
 
526
634
  void StreamResetHandler::OnBackoffTimer(
527
- BackoffTimerHandleInterface* backoffTimer, uint64_t& baseTimeoutMs, bool& stop)
635
+ BackoffTimerHandleInterface* backoffTimer, int64_t& baseTimeoutMs, bool& stop)
528
636
  {
529
637
  MS_TRACE();
530
638
 
@@ -125,27 +125,31 @@ namespace RTC
125
125
  MS_DUMP_CLEAN(indentation, "</SCTP::TransmissionControlBlock>");
126
126
  }
127
127
 
128
- void TransmissionControlBlock::ObserveRttMs(uint64_t rttMs)
128
+ void TransmissionControlBlock::ObserveRttUs(int64_t rttUs)
129
129
  {
130
130
  MS_TRACE();
131
131
 
132
132
  #if MS_LOG_DEV_LEVEL == 3
133
- const auto prevRtoMs = this->rto.GetRtoMs();
133
+ const auto prevRtoUs = this->rto.GetRtoUs();
134
134
  #endif
135
135
 
136
- this->rto.ObserveRttMs(rttMs);
136
+ this->rto.ObserveRttUs(rttUs);
137
137
 
138
138
  MS_DEBUG_DEV(
139
- "new rtt:%" PRIu64 ", previous rto:%" PRIu64 ", new rto:%" PRIu64 ", srtt:%" PRIu64,
140
- rttMs,
141
- prevRtoMs,
142
- this->rto.GetRtoMs(),
143
- this->rto.GetSrttMs());
139
+ "new rtt:%" PRIi64 " us, previous rto:%" PRIi64 " us, new rto:%" PRIi64 " us, srtt:%" PRIi64
140
+ " us",
141
+ rttUs,
142
+ prevRtoUs,
143
+ this->rto.GetRtoUs(),
144
+ this->rto.GetSrttUs());
144
145
 
145
- this->t3RtxTimer->SetBaseTimeoutMs(this->rto.GetRtoMs());
146
+ // NOTE: The timers take milliseconds, so the RTO is truncated here. It is
147
+ // hundreds of milliseconds long, so the sub-millisecond part is noise.
148
+ this->t3RtxTimer->SetBaseTimeoutMs(this->rto.GetRtoUs() / 1000);
146
149
 
147
- const uint64_t delayedAckTimeoutMs = std::min(
148
- static_cast<uint64_t>(this->rto.GetRtoMs() * 0.5), this->sctpOptions.delayedAckMaxTimeoutMs);
150
+ const int64_t delayedAckTimeoutMs = std::min(
151
+ static_cast<int64_t>((this->rto.GetRtoUs() * 0.5) / 1000),
152
+ this->sctpOptions.delayedAckMaxTimeoutMs);
149
153
 
150
154
  this->delayedAckTimer->SetBaseTimeoutMs(delayedAckTimeoutMs);
151
155
  }
@@ -211,11 +215,11 @@ namespace RTC
211
215
  SendPacket(packet.get());
212
216
  }
213
217
 
214
- void TransmissionControlBlock::MayAddForwardTsnChunk(Packet* packet, uint64_t nowMs)
218
+ void TransmissionControlBlock::MayAddForwardTsnChunk(Packet* packet, int64_t nowUs)
215
219
  {
216
220
  MS_TRACE();
217
221
 
218
- if (nowMs >= this->limitForwardTsnUntilMs && this->retransmissionQueue.ShouldSendForwardTsn(nowMs))
222
+ if (nowUs >= this->limitForwardTsnUntilUs && this->retransmissionQueue.ShouldSendForwardTsn(nowUs))
219
223
  {
220
224
  if (this->negotiatedCapabilities.messageInterleaving)
221
225
  {
@@ -233,7 +237,7 @@ namespace RTC
233
237
  // before sending a duplicate FORWARD TSN."
234
238
  // "Any delay applied to the sending of FORWARD TSN chunk SHOULD NOT
235
239
  // exceed 200ms and MUST NOT exceed 500ms".
236
- this->limitForwardTsnUntilMs = nowMs + std::min(uint64_t{ 200 }, this->rto.GetSrttMs());
240
+ this->limitForwardTsnUntilUs = nowUs + std::min(int64_t{ 200 * 1000 }, this->rto.GetSrttUs());
237
241
  }
238
242
  }
239
243
 
@@ -284,7 +288,7 @@ namespace RTC
284
288
  SendPacket(packet.get());
285
289
  }
286
290
 
287
- void TransmissionControlBlock::SendBufferedPackets(uint64_t nowMs, bool addCookieAckChunk)
291
+ void TransmissionControlBlock::SendBufferedPackets(int64_t nowUs, bool addCookieAckChunk)
288
292
  {
289
293
  MS_TRACE();
290
294
 
@@ -338,9 +342,7 @@ namespace RTC
338
342
  packet.get(), this->reassemblyQueue.GetRemainingBytes());
339
343
  }
340
344
 
341
- const uint64_t nowMs = this->shared->GetTimeMs();
342
-
343
- MayAddForwardTsnChunk(packet.get(), nowMs);
345
+ MayAddForwardTsnChunk(packet.get(), nowUs);
344
346
 
345
347
  if (this->streamResetHandler.ShouldSendStreamResetRequest())
346
348
  {
@@ -349,7 +351,7 @@ namespace RTC
349
351
  }
350
352
 
351
353
  auto chunksToSend =
352
- this->retransmissionQueue.GetChunksToSend(nowMs, packet->GetAvailableLength());
354
+ this->retransmissionQueue.GetChunksToSend(nowUs, packet->GetAvailableLength());
353
355
 
354
356
  if (!chunksToSend.empty())
355
357
  {
@@ -409,7 +411,7 @@ namespace RTC
409
411
  }
410
412
  }
411
413
 
412
- void TransmissionControlBlock::OnT3RtxTimer(uint64_t& /*baseTimeoutMs*/, bool& stop)
414
+ void TransmissionControlBlock::OnT3RtxTimer(int64_t& /*baseTimeoutMs*/, bool& stop)
413
415
  {
414
416
  MS_TRACE();
415
417
 
@@ -439,9 +441,9 @@ namespace RTC
439
441
  {
440
442
  this->retransmissionQueue.HandleT3RtxTimerExpiry();
441
443
 
442
- const uint64_t nowMs = this->shared->GetTimeMs();
444
+ const int64_t nowUs = this->shared->GetTimeUs();
443
445
 
444
- SendBufferedPackets(nowMs);
446
+ SendBufferedPackets(nowUs);
445
447
  }
446
448
  else
447
449
  {
@@ -455,7 +457,7 @@ namespace RTC
455
457
  }
456
458
  }
457
459
 
458
- void TransmissionControlBlock::OnDelayedAckTimer(uint64_t& /*baseTimeoutMs*/, bool& /*stop*/)
460
+ void TransmissionControlBlock::OnDelayedAckTimer(int64_t& /*baseTimeoutMs*/, bool& /*stop*/)
459
461
  {
460
462
  MS_TRACE();
461
463
 
@@ -482,7 +484,7 @@ namespace RTC
482
484
  }
483
485
 
484
486
  void TransmissionControlBlock::OnBackoffTimer(
485
- BackoffTimerHandleInterface* backoffTimer, uint64_t& baseTimeoutMs, bool& stop)
487
+ BackoffTimerHandleInterface* backoffTimer, int64_t& baseTimeoutMs, bool& stop)
486
488
  {
487
489
  MS_TRACE();
488
490
 
@@ -496,11 +498,11 @@ namespace RTC
496
498
  }
497
499
  }
498
500
 
499
- void TransmissionControlBlock::OnRetransmissionQueueNewRttMs(uint64_t newRttMs)
501
+ void TransmissionControlBlock::OnRetransmissionQueueNewRttUs(int64_t newRttUs)
500
502
  {
501
503
  MS_TRACE();
502
504
 
503
- ObserveRttMs(newRttMs);
505
+ ObserveRttUs(newRttUs);
504
506
  }
505
507
 
506
508
  void TransmissionControlBlock::OnRetransmissionQueueClearRetransmissionCounter()
@@ -5,7 +5,6 @@
5
5
  #include "Logger.hpp"
6
6
  #include "MediaSoupErrors.hpp"
7
7
  #include <cstring> // std::memmove()
8
- #include <ranges>
9
8
 
10
9
  namespace RTC
11
10
  {
@@ -123,7 +123,7 @@ namespace RTC
123
123
  uint32_t remoteAdvertisedReceiverWindowCredit,
124
124
  uint64_t tieTag,
125
125
  const Capabilities& remoteCapabilities,
126
- uint64_t creationTimestampMs,
126
+ int64_t creationTimestampUs,
127
127
  const uint8_t* macKey,
128
128
  size_t macKeyLength)
129
129
  {
@@ -148,7 +148,7 @@ namespace RTC
148
148
  remoteAdvertisedReceiverWindowCredit,
149
149
  tieTag,
150
150
  remoteCapabilities,
151
- creationTimestampMs,
151
+ creationTimestampUs,
152
152
  macKey,
153
153
  macKeyLength);
154
154
 
@@ -14,7 +14,7 @@ namespace RTC
14
14
  {
15
15
  MS_TRACE();
16
16
 
17
- auto peerImplementationStringView = Types::SctpImplementationToString(this->peerImplementation);
17
+ auto peerImplementationStringView = Types::sctpImplementationToString(this->peerImplementation);
18
18
 
19
19
  MS_DUMP_CLEAN(indentation, "<SCTP::AssociationMetrics>");
20
20
  MS_DUMP_CLEAN(indentation, " tx packets count: %" PRIu64, this->txPacketsCount);
@@ -24,7 +24,7 @@ namespace RTC
24
24
  MS_DUMP_CLEAN(indentation, " rtx packets count: %" PRIu64, this->rtxPacketsCount);
25
25
  MS_DUMP_CLEAN(indentation, " rtx bytes count: %" PRIu64, this->rtxBytesCount);
26
26
  MS_DUMP_CLEAN(indentation, " current congestion window (bytes): %zu", this->cwndBytes);
27
- MS_DUMP_CLEAN(indentation, " smoothed round trip time (ms): %" PRIu64, this->srttMs);
27
+ MS_DUMP_CLEAN(indentation, " smoothed round trip time (ms): %" PRIi64, this->srttMs);
28
28
  MS_DUMP_CLEAN(indentation, " unacked data count: %zu", this->unackDataCount);
29
29
  MS_DUMP_CLEAN(
30
30
  indentation, " peer's last announced receiver window size: %" PRIu32, this->peerRwndBytes);
@@ -34,23 +34,23 @@ namespace RTC
34
34
  " total buffered amount low threshold: %zu",
35
35
  this->totalBufferedAmountLowThreshold);
36
36
  MS_DUMP_CLEAN(indentation, " default stream priority: %" PRIu16, this->defaultStreamPriority);
37
- MS_DUMP_CLEAN(indentation, " max rtt (ms): %" PRIu64, this->maxRttMs);
38
- MS_DUMP_CLEAN(indentation, " initial rto (ms): %" PRIu64, this->initialRtoMs);
39
- MS_DUMP_CLEAN(indentation, " min rto (ms): %" PRIu64, this->minRtoMs);
40
- MS_DUMP_CLEAN(indentation, " max rto (ms): %" PRIu64, this->maxRtoMs);
41
- MS_DUMP_CLEAN(indentation, " t1-init timeout (ms): %" PRIu64, this->t1InitTimeoutMs);
42
- MS_DUMP_CLEAN(indentation, " t1-cookie timeout (ms): %" PRIu64, this->t1CookieTimeoutMs);
43
- MS_DUMP_CLEAN(indentation, " t2-shutdown timeout (ms): %" PRIu64, this->t2ShutdownTimeoutMs);
37
+ MS_DUMP_CLEAN(indentation, " max rtt (ms): %" PRIi64, this->maxRttMs);
38
+ MS_DUMP_CLEAN(indentation, " initial rto (ms): %" PRIi64, this->initialRtoMs);
39
+ MS_DUMP_CLEAN(indentation, " min rto (ms): %" PRIi64, this->minRtoMs);
40
+ MS_DUMP_CLEAN(indentation, " max rto (ms): %" PRIi64, this->maxRtoMs);
41
+ MS_DUMP_CLEAN(indentation, " t1-init timeout (ms): %" PRIi64, this->t1InitTimeoutMs);
42
+ MS_DUMP_CLEAN(indentation, " t1-cookie timeout (ms): %" PRIi64, this->t1CookieTimeoutMs);
43
+ MS_DUMP_CLEAN(indentation, " t2-shutdown timeout (ms): %" PRIi64, this->t2ShutdownTimeoutMs);
44
44
  MS_DUMP_CLEAN(
45
45
  indentation,
46
46
  " timer max backoff timeout (ms): %s",
47
47
  this->timerMaxBackoffTimeoutMs
48
48
  ? std::to_string(this->timerMaxBackoffTimeoutMs.value()).c_str()
49
- : "Infinite");
50
- MS_DUMP_CLEAN(indentation, " heartbeat interval (ms): %" PRIu64, this->heartbeatIntervalMs);
49
+ : "Infinite");
50
+ MS_DUMP_CLEAN(indentation, " heartbeat interval (ms): %" PRIi64, this->heartbeatIntervalMs);
51
51
  MS_DUMP_CLEAN(
52
- indentation, " delayed ack max timeout (ms): %" PRIu64, this->delayedAckMaxTimeoutMs);
53
- MS_DUMP_CLEAN(indentation, " min rtt variance (ms): %" PRIu64, this->minRttVarianceMs);
52
+ indentation, " delayed ack max timeout (ms): %" PRIi64, this->delayedAckMaxTimeoutMs);
53
+ MS_DUMP_CLEAN(indentation, " min rtt variance (ms): %" PRIi64, this->minRttVarianceMs);
54
54
  MS_DUMP_CLEAN(indentation, " initial cwnd mtus: %zu", this->initialCwndMtus);
55
55
  MS_DUMP_CLEAN(indentation, " min cwnd mtus: %zu", this->minCwndMtus);
56
56
  MS_DUMP_CLEAN(
@@ -62,12 +62,12 @@ namespace RTC
62
62
  indentation,
63
63
  " max retransmissions: %s",
64
64
  this->maxRetransmissions ? std::to_string(this->maxRetransmissions.value()).c_str()
65
- : "Infinite");
65
+ : "Infinite");
66
66
  MS_DUMP_CLEAN(
67
67
  indentation,
68
68
  " max init retransmissions: %s",
69
69
  this->maxInitRetransmissions ? std::to_string(this->maxInitRetransmissions.value()).c_str()
70
- : "Infinite");
70
+ : "Infinite");
71
71
  MS_DUMP_CLEAN(
72
72
  indentation, " enable partial reliability: %s", this->enablePartialReliability ? "yes" : "no");
73
73
  MS_DUMP_CLEAN(
@@ -256,7 +256,7 @@ namespace RTC
256
256
  if (
257
257
  this->ackState == AckState::IMMEDIATE ||
258
258
  (alsoIfDelayed &&
259
- (this->ackState == AckState::BECOMING_DELAYED || this->ackState == AckState::DELAYED)))
259
+ (this->ackState == AckState::BECOMING_DELAYED || this->ackState == AckState::DELAYED)))
260
260
  {
261
261
  UpdateAckState(AckState::IDLE, "should send SACK");
262
262