mediasoup 3.26.0 → 3.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/CHANGELOG.md +11 -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/rtpParameters.fbs +1 -2
  49. package/worker/fbs/rtpStream.fbs +3 -3
  50. package/worker/fbs/transport.fbs +23 -23
  51. package/worker/fuzzer/include/RTC/FuzzerDtlsTransport.hpp +4 -1
  52. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  53. package/worker/fuzzer/src/RTC/FuzzerDtlsTransport.cpp +8 -5
  54. package/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp +3 -3
  55. package/worker/fuzzer/src/RTC/FuzzerTrendCalculator.cpp +6 -6
  56. package/worker/fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTransport.cpp +3 -3
  57. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +2 -2
  58. package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +5 -5
  59. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +3 -3
  60. package/worker/fuzzer/src/fuzzer.cpp +4 -0
  61. package/worker/include/Channel/ChannelNotification.hpp +3 -3
  62. package/worker/include/Channel/ChannelRequest.hpp +1 -1
  63. package/worker/include/Channel/ChannelSocket.hpp +11 -0
  64. package/worker/include/DepLibUV.hpp +16 -33
  65. package/worker/include/RTC/ActiveSpeakerObserver.hpp +11 -11
  66. package/worker/include/RTC/AudioLevelObserver.hpp +4 -4
  67. package/worker/include/RTC/BWE/AcknowledgedBitrateEstimatorInterface.hpp +55 -0
  68. package/worker/include/RTC/BWE/AimdRateControl.hpp +190 -0
  69. package/worker/include/RTC/BWE/BweTypes.hpp +211 -0
  70. package/worker/include/RTC/BWE/DelayBasedBwe.hpp +173 -0
  71. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +72 -0
  72. package/worker/include/RTC/BWE/InterArrivalDelta.hpp +106 -0
  73. package/worker/include/RTC/BWE/LinkCapacityEstimator.hpp +84 -0
  74. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +94 -0
  75. package/worker/include/RTC/BWE/SendPacketHistory.hpp +137 -0
  76. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +101 -0
  77. package/worker/include/RTC/Consts.hpp +6 -6
  78. package/worker/include/RTC/Consumer.hpp +14 -12
  79. package/worker/include/RTC/DataConsumer.hpp +3 -3
  80. package/worker/include/RTC/DataProducer.hpp +3 -3
  81. package/worker/include/RTC/DtlsTransport.hpp +5 -2
  82. package/worker/include/RTC/ICE/IceCandidate.hpp +2 -2
  83. package/worker/include/RTC/ICE/IceServer.hpp +3 -3
  84. package/worker/include/RTC/KeyFrameRequestManager.hpp +3 -3
  85. package/worker/include/RTC/NEW_RTCP/packet/Packet.hpp +1 -1
  86. package/worker/include/RTC/NackGenerator.hpp +12 -12
  87. package/worker/include/RTC/PipeProducerStreamManager.hpp +3 -4
  88. package/worker/include/RTC/PipeTransport.hpp +18 -5
  89. package/worker/include/RTC/PlainTransport.hpp +18 -5
  90. package/worker/include/RTC/PortManager.hpp +4 -4
  91. package/worker/include/RTC/Producer.hpp +21 -12
  92. package/worker/include/RTC/ProducerStreamManager.hpp +12 -6
  93. package/worker/include/RTC/RTCP/Bye.hpp +2 -2
  94. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +4 -4
  95. package/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp +3 -3
  96. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +54 -39
  97. package/worker/include/RTC/RTCP/Packet.hpp +3 -3
  98. package/worker/include/RTC/RTCP/ReceiverReport.hpp +3 -3
  99. package/worker/include/RTC/RTCP/Sdes.hpp +2 -2
  100. package/worker/include/RTC/RTCP/XR.hpp +2 -2
  101. package/worker/include/RTC/RTCP/XrDelaySinceLastRr.hpp +1 -1
  102. package/worker/include/RTC/RTP/Codecs/H264.hpp +1 -1
  103. package/worker/include/RTC/RTP/Codecs/Opus.hpp +2 -2
  104. package/worker/include/RTC/RTP/Codecs/PayloadDescriptorHandler.hpp +3 -3
  105. package/worker/include/RTC/RTP/Codecs/VP8.hpp +2 -2
  106. package/worker/include/RTC/RTP/Codecs/VP9.hpp +2 -2
  107. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +12 -12
  108. package/worker/include/RTC/RTP/Packet.hpp +13 -13
  109. package/worker/include/RTC/RTP/ProbationGenerator.hpp +1 -1
  110. package/worker/include/RTC/RTP/RetransmissionBuffer.hpp +7 -7
  111. package/worker/include/RTC/RTP/RtpStream.hpp +37 -51
  112. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +59 -41
  113. package/worker/include/RTC/RTP/RtpStreamSend.hpp +20 -14
  114. package/worker/include/RTC/RTP/RtxStream.hpp +12 -13
  115. package/worker/include/RTC/RateCalculator.hpp +50 -44
  116. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +5 -4
  117. package/worker/include/RTC/RemoteClockOffsetEstimator.hpp +11 -11
  118. package/worker/include/RTC/Router.hpp +6 -0
  119. package/worker/include/RTC/RtcLogger.hpp +1 -1
  120. package/worker/include/RTC/RtpDictionaries.hpp +10 -10
  121. package/worker/include/RTC/SCTP/association/Association.hpp +56 -28
  122. package/worker/include/RTC/SCTP/association/HeartbeatHandler.hpp +4 -4
  123. package/worker/include/RTC/SCTP/association/StateCookie.hpp +14 -14
  124. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +2 -2
  125. package/worker/include/RTC/SCTP/association/TransmissionControlBlock.hpp +12 -12
  126. package/worker/include/RTC/SCTP/association/TransmissionControlBlockContextInterface.hpp +4 -4
  127. package/worker/include/RTC/SCTP/packet/TLV.hpp +1 -1
  128. package/worker/include/RTC/SCTP/packet/parameters/StateCookieParameter.hpp +3 -3
  129. package/worker/include/RTC/SCTP/public/AssociationInterface.hpp +4 -1
  130. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +1 -1
  131. package/worker/include/RTC/SCTP/public/SctpOptions.hpp +12 -12
  132. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +1 -1
  133. package/worker/include/RTC/SCTP/tx/OutstandingData.hpp +15 -16
  134. package/worker/include/RTC/SCTP/tx/RetransmissionQueue.hpp +7 -8
  135. package/worker/include/RTC/SCTP/tx/RetransmissionTimeout.hpp +20 -16
  136. package/worker/include/RTC/SCTP/tx/RoundRobinSendQueue.hpp +5 -6
  137. package/worker/include/RTC/SCTP/tx/SendQueueInterface.hpp +2 -2
  138. package/worker/include/RTC/SCTP/tx/StreamScheduler.hpp +5 -5
  139. package/worker/include/RTC/SctpDictionaries.hpp +3 -3
  140. package/worker/include/RTC/Serializable.hpp +1 -1
  141. package/worker/include/RTC/SimpleProducerStreamManager.hpp +3 -4
  142. package/worker/include/RTC/SimulcastProducerStreamManager.hpp +6 -7
  143. package/worker/include/RTC/SvcProducerStreamManager.hpp +6 -5
  144. package/worker/include/RTC/TcpConnection.hpp +9 -3
  145. package/worker/include/RTC/TcpServer.hpp +3 -0
  146. package/worker/include/RTC/Transport.hpp +52 -45
  147. package/worker/include/RTC/TransportCongestionControlClient.hpp +30 -25
  148. package/worker/include/RTC/TransportCongestionControlServer.hpp +17 -17
  149. package/worker/include/RTC/TrendCalculator.hpp +5 -5
  150. package/worker/include/RTC/UdpSocket.hpp +11 -2
  151. package/worker/include/RTC/WebRtcServer.hpp +20 -5
  152. package/worker/include/RTC/WebRtcTransport.hpp +35 -10
  153. package/worker/include/Settings.hpp +4 -2
  154. package/worker/include/Shared.hpp +5 -20
  155. package/worker/include/SharedInterface.hpp +6 -28
  156. package/worker/include/Utils.hpp +40 -21
  157. package/worker/include/common.hpp +4 -0
  158. package/worker/include/handles/BackoffTimerHandle.hpp +4 -4
  159. package/worker/include/handles/BackoffTimerHandleInterface.hpp +5 -5
  160. package/worker/include/handles/TcpConnectionHandle.hpp +6 -6
  161. package/worker/include/handles/TcpServerHandle.hpp +1 -1
  162. package/worker/include/handles/TimerHandle.hpp +15 -9
  163. package/worker/include/handles/TimerHandleInterface.hpp +10 -4
  164. package/worker/include/handles/UdpSocketHandle.hpp +3 -3
  165. package/worker/include/handles/UnixStreamSocketHandle.hpp +2 -2
  166. package/worker/meson.build +81 -36
  167. package/worker/meson_options.txt +1 -0
  168. package/worker/mocks/include/MockShared.hpp +24 -23
  169. package/worker/mocks/include/RTC/SCTP/association/MockTransmissionControlBlockContext.hpp +51 -27
  170. package/worker/mocks/include/RTC/SCTP/tx/MockSendQueue.hpp +11 -11
  171. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +10 -10
  172. package/worker/mocks/include/handles/MockTimerHandle.hpp +60 -22
  173. package/worker/mocks/src/MockShared.cpp +51 -5
  174. package/worker/mocks/src/handles/MockBackoffTimerHandle.cpp +29 -15
  175. package/worker/mocks/src/handles/MockTimerHandle.cpp +117 -0
  176. package/worker/scripts/clang-scripts.mjs +2 -2
  177. package/worker/src/Channel/ChannelNotification.cpp +5 -6
  178. package/worker/src/Channel/ChannelSocket.cpp +20 -2
  179. package/worker/src/DepLibUV.cpp +4 -5
  180. package/worker/src/RTC/ActiveSpeakerObserver.cpp +59 -47
  181. package/worker/src/RTC/AudioLevelObserver.cpp +7 -7
  182. package/worker/src/RTC/BWE/AimdRateControl.cpp +468 -0
  183. package/worker/src/RTC/BWE/BweTypes.cpp +61 -0
  184. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +275 -0
  185. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +148 -0
  186. package/worker/src/RTC/BWE/InterArrivalDelta.cpp +181 -0
  187. package/worker/src/RTC/BWE/LinkCapacityEstimator.cpp +133 -0
  188. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +245 -0
  189. package/worker/src/RTC/BWE/SendPacketHistory.cpp +184 -0
  190. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +233 -0
  191. package/worker/src/RTC/Consumer.cpp +48 -35
  192. package/worker/src/RTC/DataConsumer.cpp +4 -4
  193. package/worker/src/RTC/DataProducer.cpp +3 -3
  194. package/worker/src/RTC/DirectTransport.cpp +2 -2
  195. package/worker/src/RTC/DtlsTransport.cpp +14 -11
  196. package/worker/src/RTC/ICE/IceServer.cpp +2 -2
  197. package/worker/src/RTC/KeyFrameRequestManager.cpp +16 -12
  198. package/worker/src/RTC/NackGenerator.cpp +12 -12
  199. package/worker/src/RTC/PipeProducerStreamManager.cpp +6 -6
  200. package/worker/src/RTC/PipeTransport.cpp +16 -13
  201. package/worker/src/RTC/PlainTransport.cpp +25 -16
  202. package/worker/src/RTC/Producer.cpp +50 -36
  203. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +13 -6
  204. package/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp +14 -5
  205. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +76 -50
  206. package/worker/src/RTC/RTP/Codecs/VP8.cpp +1 -1
  207. package/worker/src/RTC/RTP/Codecs/VP9.cpp +4 -4
  208. package/worker/src/RTC/RTP/Packet.cpp +9 -10
  209. package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +6 -6
  210. package/worker/src/RTC/RTP/RtpStream.cpp +19 -19
  211. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +146 -81
  212. package/worker/src/RTC/RTP/RtpStreamSend.cpp +49 -44
  213. package/worker/src/RTC/RTP/RtxStream.cpp +7 -10
  214. package/worker/src/RTC/RateCalculator.cpp +99 -136
  215. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +13 -13
  216. package/worker/src/RTC/RemoteClockOffsetEstimator.cpp +18 -17
  217. package/worker/src/RTC/Router.cpp +18 -1
  218. package/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp +5 -2
  219. package/worker/src/RTC/SCTP/association/Association.cpp +131 -102
  220. package/worker/src/RTC/SCTP/association/AssociationListenerDeferrer.cpp +4 -4
  221. package/worker/src/RTC/SCTP/association/Capabilities.cpp +1 -1
  222. package/worker/src/RTC/SCTP/association/HeartbeatHandler.cpp +25 -18
  223. package/worker/src/RTC/SCTP/association/StateCookie.cpp +7 -6
  224. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +16 -13
  225. package/worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp +28 -26
  226. package/worker/src/RTC/SCTP/packet/chunks/SackChunk.cpp +0 -1
  227. package/worker/src/RTC/SCTP/packet/parameters/StateCookieParameter.cpp +2 -2
  228. package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +1 -1
  229. package/worker/src/RTC/SCTP/public/SctpOptions.cpp +13 -13
  230. package/worker/src/RTC/SCTP/rx/DataTracker.cpp +1 -1
  231. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +5 -5
  232. package/worker/src/RTC/SCTP/tx/OutstandingData.cpp +15 -15
  233. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +15 -15
  234. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +29 -26
  235. package/worker/src/RTC/SCTP/tx/RoundRobinSendQueue.cpp +12 -11
  236. package/worker/src/RTC/SCTP/tx/StreamScheduler.cpp +4 -4
  237. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +2 -2
  238. package/worker/src/RTC/SimpleProducerStreamManager.cpp +10 -10
  239. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +39 -37
  240. package/worker/src/RTC/SvcProducerStreamManager.cpp +39 -25
  241. package/worker/src/RTC/TcpConnection.cpp +9 -3
  242. package/worker/src/RTC/TcpServer.cpp +7 -2
  243. package/worker/src/RTC/Transport.cpp +242 -302
  244. package/worker/src/RTC/TransportCongestionControlClient.cpp +78 -71
  245. package/worker/src/RTC/TransportCongestionControlServer.cpp +38 -40
  246. package/worker/src/RTC/TrendCalculator.cpp +3 -3
  247. package/worker/src/RTC/UdpSocket.cpp +14 -3
  248. package/worker/src/RTC/WebRtcServer.cpp +20 -14
  249. package/worker/src/RTC/WebRtcTransport.cpp +35 -30
  250. package/worker/src/Settings.cpp +10 -0
  251. package/worker/src/Shared.cpp +2 -2
  252. package/worker/src/Utils/Crypto.cpp +2 -2
  253. package/worker/src/Worker.cpp +5 -1
  254. package/worker/src/handles/BackoffTimerHandle.cpp +24 -11
  255. package/worker/src/handles/TimerHandle.cpp +74 -25
  256. package/worker/src/lib.cpp +6 -0
  257. package/worker/tasks.py +171 -44
  258. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +117 -0
  259. package/worker/test/src/RTC/BWE/TestAimdRateControl.cpp +400 -0
  260. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +568 -0
  261. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +546 -0
  262. package/worker/test/src/RTC/BWE/TestInterArrivalDelta.cpp +301 -0
  263. package/worker/test/src/RTC/BWE/TestLinkCapacityEstimator.cpp +115 -0
  264. package/worker/test/src/RTC/BWE/TestRobustThroughputEstimator.cpp +433 -0
  265. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +259 -0
  266. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +137 -0
  267. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +171 -0
  268. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +1 -1
  269. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +1 -1
  270. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +246 -208
  271. package/worker/test/src/RTC/RTP/TestPacket.cpp +11 -11
  272. package/worker/test/src/RTC/RTP/TestRetransmissionBuffer.cpp +12 -12
  273. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +23 -16
  274. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +13 -13
  275. package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +27 -22
  276. package/worker/test/src/RTC/SCTP/association/TestHeartbeatHandler.cpp +21 -15
  277. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +6 -6
  278. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +17 -13
  279. package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +3 -3
  280. package/worker/test/src/RTC/SCTP/packet/chunks/TestForwardTsnChunk.cpp +2 -2
  281. package/worker/test/src/RTC/SCTP/packet/chunks/TestIForwardTsnChunk.cpp +23 -23
  282. package/worker/test/src/RTC/SCTP/packet/chunks/TestInitChunk.cpp +1 -1
  283. package/worker/test/src/RTC/SCTP/packet/chunks/TestSackChunk.cpp +1 -1
  284. package/worker/test/src/RTC/SCTP/packet/parameters/TestIPv6AddressParameter.cpp +1 -1
  285. package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +37 -37
  286. package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +10 -10
  287. package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +1 -1
  288. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +93 -93
  289. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +247 -247
  290. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +100 -80
  291. package/worker/test/src/RTC/SCTP/tx/TestRoundRobinSendQueue.cpp +163 -163
  292. package/worker/test/src/RTC/SCTP/tx/TestStreamScheduler.cpp +76 -77
  293. package/worker/test/src/RTC/TestConsumer.cpp +8 -3
  294. package/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +3 -3
  295. package/worker/test/src/RTC/TestNackGenerator.cpp +3 -3
  296. package/worker/test/src/RTC/TestPipeProducerStreamManager.cpp +5 -5
  297. package/worker/test/src/RTC/TestRateCalculator.cpp +110 -14
  298. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +22 -17
  299. package/worker/test/src/RTC/TestRemoteClockOffsetEstimator.cpp +87 -85
  300. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +54 -47
  301. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +83 -69
  302. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +76 -65
  303. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +72 -66
  304. package/worker/test/src/RTC/TestTransportTuple.cpp +19 -4
  305. package/worker/test/src/TestDepLibUV.cpp +19 -0
  306. package/worker/test/src/Utils/TestTime.cpp +57 -26
  307. package/worker/test/src/testHelpers.cpp +1 -1
  308. package/worker/test/src/tests.cpp +6 -0
  309. package/worker/include/RTC/SenderBandwidthEstimator.hpp +0 -118
  310. package/worker/src/RTC/SenderBandwidthEstimator.cpp +0 -269
@@ -0,0 +1,468 @@
1
+ #define MS_CLASS "RTC::BWE::AimdRateControl"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "RTC/BWE/AimdRateControl.hpp"
5
+ #include "Logger.hpp"
6
+ #include <cmath>
7
+
8
+ namespace RTC
9
+ {
10
+ namespace BWE
11
+ {
12
+ /* Static. */
13
+
14
+ // RTT assumed until a measured one is given.
15
+ static constexpr int64_t DefaultRttUs{ 200 * 1000 };
16
+ // Time a throughput has to be measured for before it's taken as the initial
17
+ // target bitrate.
18
+ static constexpr int64_t InitializationTimeUs{ 5 * 1000 * 1000 };
19
+ // Window over which the throughput is measured.
20
+ static constexpr int64_t BitrateWindowUs{ 1000 * 1000 };
21
+ // Bounds of how often the bitrate may be reduced, derived from the RTT.
22
+ static constexpr int64_t MinBitrateReductionIntervalUs{ 10 * 1000 };
23
+ static constexpr int64_t MaxBitrateReductionIntervalUs{ 200 * 1000 };
24
+ // Bitrate the target is never taken below unless configured otherwise (bps).
25
+ static constexpr int64_t CongestionControllerMinBitrate{ 5000 };
26
+ // Bitrate the target starts from before anything has been measured (bps).
27
+ static constexpr int64_t MaxConfiguredBitrate{ 30000 * 1000 };
28
+ // Headroom allowed on top of the measured throughput when increasing (bps).
29
+ static constexpr int64_t IncreaseLimitHeadroom{ 10 * 1000 };
30
+ // Amount subtracted from the backed off bitrate to get rid of any
31
+ // self-induced delay (bps).
32
+ static constexpr int64_t DecreaseMargin{ 5 * 1000 };
33
+ // Smallest multiplicative increase applied (bps).
34
+ static constexpr int64_t MinMultiplicativeIncrease{ 1000 };
35
+ // Base of the multiplicative increase, which is 8% per second.
36
+ static constexpr double MultiplicativeIncreaseAlpha{ 1.08 };
37
+ // Interval between frames assumed when sizing the additive increase.
38
+ static constexpr int64_t FrameIntervalUs{ 1000 * 1000 / 30 };
39
+ // Packet size assumed when sizing the additive increase (bytes).
40
+ static constexpr int64_t PacketSizeBytes{ 1200 };
41
+ // Delay of the overuse detector assumed when sizing the additive increase.
42
+ static constexpr int64_t DetectorDelayUs{ 100 * 1000 };
43
+ // Smallest additive increase applied (bps per second).
44
+ static constexpr double MinIncreaseRateBpsPerSecond{ 4000 };
45
+ // Size of a feedback message assumed when deciding how often to send it
46
+ // (bytes).
47
+ static constexpr int64_t RtcpSizeBytes{ 80 };
48
+ // Fraction of the bitrate devoted to feedback.
49
+ static constexpr double FeedbackBandwidthFraction{ 0.05 };
50
+ // Bounds of how often feedback is sent.
51
+ static constexpr int64_t MinFeedbackIntervalUs{ 200 * 1000 };
52
+ static constexpr int64_t MaxFeedbackIntervalUs{ 1000 * 1000 };
53
+
54
+ static_assert(
55
+ BitrateWindowUs <= InitializationTimeUs,
56
+ "the throughput window must fit within the initialization time");
57
+
58
+ /* Instance methods. */
59
+
60
+ AimdRateControl::AimdRateControl() : AimdRateControl(AimdRateControlOptions{})
61
+ {
62
+ MS_TRACE();
63
+ }
64
+
65
+ AimdRateControl::AimdRateControl(AimdRateControlOptions options)
66
+ : options(options),
67
+ minConfiguredBitrate(CongestionControllerMinBitrate),
68
+ maxConfiguredBitrate(MaxConfiguredBitrate),
69
+ currentBitrate(this->maxConfiguredBitrate),
70
+ latestEstimatedThroughput(this->currentBitrate),
71
+ rttUs(DefaultRttUs)
72
+ {
73
+ MS_TRACE();
74
+ }
75
+
76
+ int64_t AimdRateControl::Update(const Types::RateControlInput& input, int64_t atTimeUs)
77
+ {
78
+ MS_TRACE();
79
+
80
+ // Take the throughput being measured as the initial target bitrate, once it
81
+ // has been measured for long enough.
82
+ if (!this->bitrateIsInitialized)
83
+ {
84
+ if (!this->timeFirstThroughputEstimateUs.has_value())
85
+ {
86
+ if (input.estimatedThroughput.has_value())
87
+ {
88
+ this->timeFirstThroughputEstimateUs = atTimeUs;
89
+ }
90
+ }
91
+ else if (
92
+ atTimeUs - this->timeFirstThroughputEstimateUs.value() > InitializationTimeUs &&
93
+ input.estimatedThroughput.has_value())
94
+ {
95
+ this->currentBitrate = input.estimatedThroughput.value();
96
+ this->bitrateIsInitialized = true;
97
+ }
98
+ }
99
+
100
+ ChangeBitrate(input, atTimeUs);
101
+
102
+ return this->currentBitrate;
103
+ }
104
+
105
+ void AimdRateControl::SetEstimate(int64_t bitrate, int64_t atTimeUs)
106
+ {
107
+ MS_TRACE();
108
+
109
+ this->bitrateIsInitialized = true;
110
+ this->currentBitrate = ClampBitrate(bitrate);
111
+ this->timeLastBitrateChangeUs = atTimeUs;
112
+ }
113
+
114
+ void AimdRateControl::SetStartBitrate(int64_t startBitrate)
115
+ {
116
+ MS_TRACE();
117
+
118
+ this->currentBitrate = startBitrate;
119
+ this->latestEstimatedThroughput = this->currentBitrate;
120
+ this->bitrateIsInitialized = true;
121
+ }
122
+
123
+ void AimdRateControl::SetMinBitrate(int64_t minBitrate)
124
+ {
125
+ MS_TRACE();
126
+
127
+ this->minConfiguredBitrate = minBitrate;
128
+ this->currentBitrate = std::max(minBitrate, this->currentBitrate);
129
+ }
130
+
131
+ void AimdRateControl::SetRttUs(int64_t rttUs)
132
+ {
133
+ MS_TRACE();
134
+
135
+ this->rttUs = rttUs;
136
+ }
137
+
138
+ void AimdRateControl::SetInApplicationLimitedRegion(bool inAlr)
139
+ {
140
+ MS_TRACE();
141
+
142
+ this->inAlr = inAlr;
143
+ }
144
+
145
+ void AimdRateControl::SetNetworkStateEstimate(
146
+ const std::optional<Types::NetworkStateEstimate>& estimate)
147
+ {
148
+ MS_TRACE();
149
+
150
+ this->networkEstimate = estimate;
151
+ }
152
+
153
+ bool AimdRateControl::IsTimeToReduceFurther(int64_t atTimeUs, int64_t estimatedThroughput) const
154
+ {
155
+ MS_TRACE();
156
+
157
+ const int64_t bitrateReductionIntervalUs =
158
+ std::clamp(this->rttUs, MinBitrateReductionIntervalUs, MaxBitrateReductionIntervalUs);
159
+
160
+ // The bitrate has never been changed, so there is nothing to wait for.
161
+ if (!this->timeLastBitrateChangeUs.has_value())
162
+ {
163
+ return true;
164
+ }
165
+
166
+ if (atTimeUs - this->timeLastBitrateChangeUs.value() >= bitrateReductionIntervalUs)
167
+ {
168
+ return true;
169
+ }
170
+
171
+ if (IsValidEstimate())
172
+ {
173
+ const int64_t threshold = std::llround(0.5 * static_cast<double>(GetLatestEstimate()));
174
+
175
+ return estimatedThroughput < threshold;
176
+ }
177
+
178
+ return false;
179
+ }
180
+
181
+ bool AimdRateControl::IsInitialTimeToReduceFurther(int64_t atTimeUs) const
182
+ {
183
+ MS_TRACE();
184
+
185
+ return IsValidEstimate() && IsTimeToReduceFurther(atTimeUs, (GetLatestEstimate() / 2) - 1);
186
+ }
187
+
188
+ double AimdRateControl::GetNearMaxIncreaseRateBpsPerSecond() const
189
+ {
190
+ MS_TRACE();
191
+
192
+ MS_ASSERT(this->currentBitrate != 0, "current bitrate is zero");
193
+
194
+ // Size of a frame at the current bitrate, rounded to the nearest byte.
195
+ const int64_t frameSizeBytes = ((this->currentBitrate * FrameIntervalUs) + 4000000) / 8000000;
196
+ const double packetsPerFrame =
197
+ std::ceil(static_cast<double>(frameSizeBytes) / static_cast<double>(PacketSizeBytes));
198
+ const int64_t avgPacketSizeBytes =
199
+ std::llround(static_cast<double>(frameSizeBytes) / packetsPerFrame);
200
+
201
+ // Time the network takes to react to a change, which is a round trip plus
202
+ // the delay of the overuse detector, doubled to stay on the safe side.
203
+ const int64_t responseTimeUs = (this->rttUs + DetectorDelayUs) * 2;
204
+ // NOTE: The division is deliberately an integer one, since it's the
205
+ // resolution at which a bitrate is expressed.
206
+ const int64_t increaseRateBpsPerSecond = avgPacketSizeBytes * 8000000 / responseTimeUs;
207
+
208
+ return std::max(MinIncreaseRateBpsPerSecond, static_cast<double>(increaseRateBpsPerSecond));
209
+ }
210
+
211
+ int64_t AimdRateControl::GetFeedbackIntervalUs() const
212
+ {
213
+ MS_TRACE();
214
+
215
+ const int64_t rtcpBitrate = std::llround(FeedbackBandwidthFraction * this->currentBitrate);
216
+ const int64_t intervalUs = (RtcpSizeBytes * 8 * 1000000) / rtcpBitrate;
217
+
218
+ return std::clamp(intervalUs, MinFeedbackIntervalUs, MaxFeedbackIntervalUs);
219
+ }
220
+
221
+ void AimdRateControl::ChangeBitrate(const Types::RateControlInput& input, int64_t atTimeUs)
222
+ {
223
+ MS_TRACE();
224
+
225
+ std::optional<int64_t> newBitrate;
226
+ const int64_t estimatedThroughput =
227
+ input.estimatedThroughput.value_or(this->latestEstimatedThroughput);
228
+
229
+ if (input.estimatedThroughput.has_value())
230
+ {
231
+ this->latestEstimatedThroughput = input.estimatedThroughput.value();
232
+ }
233
+
234
+ // An overuse must always make us reduce the bitrate, even before the first
235
+ // estimate has been established. By acting on it we end up with a valid
236
+ // estimate.
237
+ if (!this->bitrateIsInitialized && input.bandwidthUsage != Types::BandwidthUsage::OVERUSING)
238
+ {
239
+ return;
240
+ }
241
+
242
+ ChangeState(input, atTimeUs);
243
+
244
+ switch (this->rateControlState)
245
+ {
246
+ case RateControlState::HOLD:
247
+ {
248
+ break;
249
+ }
250
+
251
+ case RateControlState::INCREASE:
252
+ {
253
+ // The measured throughput is way above what the link was estimated to
254
+ // hold, so that estimate no longer describes this link.
255
+ if (estimatedThroughput > this->linkCapacity.GetUpperBound())
256
+ {
257
+ this->linkCapacity.Reset();
258
+ }
259
+
260
+ // Limit the new bitrate by the throughput to avoid unbounded increases.
261
+ // A bit more lag is allowed at very low rates so that an encoder with
262
+ // uneven output doesn't get us stuck.
263
+ int64_t increaseLimit =
264
+ std::llround(1.5 * static_cast<double>(estimatedThroughput)) + IncreaseLimitHeadroom;
265
+
266
+ if (this->options.sendSide && this->inAlr && this->options.noBitrateIncreaseInAlr)
267
+ {
268
+ // Don't increase the delay based estimate while in an application
269
+ // limited region, since the network gives no feedback that could tell
270
+ // whether the new estimate is correct. If we had previously increased
271
+ // above the limit, for instance because of a probe, no further change
272
+ // is allowed either.
273
+ increaseLimit = this->currentBitrate;
274
+ }
275
+
276
+ if (this->currentBitrate < increaseLimit)
277
+ {
278
+ int64_t increasedBitrate{ 0 };
279
+ const auto linkCapacityEstimate = this->linkCapacity.GetEstimate();
280
+
281
+ if (linkCapacityEstimate.has_value())
282
+ {
283
+ // The estimate of the link capacity is dropped whenever the measured
284
+ // throughput strays too far from it, so having one means that the
285
+ // target is reasonably close to the capacity and a small step is
286
+ // enough.
287
+ MS_ASSERT(
288
+ this->timeLastBitrateChangeUs.has_value(),
289
+ "there is a link capacity estimate but the bitrate was never changed");
290
+
291
+ const int64_t additiveIncrease =
292
+ AdditiveRateIncrease(atTimeUs, this->timeLastBitrateChangeUs.value());
293
+
294
+ increasedBitrate = this->currentBitrate + additiveIncrease;
295
+ }
296
+ else
297
+ {
298
+ // Without an estimate of the link capacity, ramp up faster to
299
+ // discover it.
300
+ const int64_t multiplicativeIncrease = MultiplicativeRateIncrease(
301
+ atTimeUs, this->timeLastBitrateChangeUs, this->currentBitrate);
302
+
303
+ increasedBitrate = this->currentBitrate + multiplicativeIncrease;
304
+ }
305
+
306
+ newBitrate = std::min(increasedBitrate, increaseLimit);
307
+ }
308
+
309
+ this->timeLastBitrateChangeUs = atTimeUs;
310
+
311
+ break;
312
+ }
313
+
314
+ case RateControlState::DECREASE:
315
+ {
316
+ // Drop slightly below the measured throughput to get rid of any
317
+ // self-induced delay.
318
+ int64_t decreasedBitrate =
319
+ std::llround(this->options.backoffFactor * static_cast<double>(estimatedThroughput));
320
+
321
+ if (decreasedBitrate > DecreaseMargin)
322
+ {
323
+ decreasedBitrate -= DecreaseMargin;
324
+ }
325
+
326
+ if (decreasedBitrate > this->currentBitrate)
327
+ {
328
+ const auto linkCapacityEstimate = this->linkCapacity.GetEstimate();
329
+
330
+ if (linkCapacityEstimate.has_value())
331
+ {
332
+ decreasedBitrate = std::llround(
333
+ this->options.backoffFactor * static_cast<double>(linkCapacityEstimate.value()));
334
+ }
335
+ }
336
+
337
+ // Avoid increasing the bitrate while overusing.
338
+ if (decreasedBitrate < this->currentBitrate)
339
+ {
340
+ newBitrate = decreasedBitrate;
341
+ }
342
+
343
+ // The throughput is far below what the link was estimated to hold, so
344
+ // drop that estimate to let the overuse below update it right away.
345
+ if (estimatedThroughput < this->linkCapacity.GetLowerBound())
346
+ {
347
+ this->linkCapacity.Reset();
348
+ }
349
+
350
+ this->bitrateIsInitialized = true;
351
+
352
+ this->linkCapacity.OnOveruseDetected(estimatedThroughput);
353
+
354
+ // Stay on hold until the queues of the network are drained.
355
+ this->rateControlState = RateControlState::HOLD;
356
+ this->timeLastBitrateChangeUs = atTimeUs;
357
+
358
+ break;
359
+ }
360
+
361
+ NO_DEFAULT_GCC();
362
+ }
363
+
364
+ this->currentBitrate = ClampBitrate(newBitrate.value_or(this->currentBitrate));
365
+ }
366
+
367
+ void AimdRateControl::ChangeState(const Types::RateControlInput& input, int64_t atTimeUs)
368
+ {
369
+ MS_TRACE();
370
+
371
+ switch (input.bandwidthUsage)
372
+ {
373
+ case Types::BandwidthUsage::NORMAL:
374
+ {
375
+ if (this->rateControlState == RateControlState::HOLD)
376
+ {
377
+ this->timeLastBitrateChangeUs = atTimeUs;
378
+ this->rateControlState = RateControlState::INCREASE;
379
+ }
380
+
381
+ break;
382
+ }
383
+
384
+ case Types::BandwidthUsage::OVERUSING:
385
+ {
386
+ if (this->rateControlState != RateControlState::DECREASE)
387
+ {
388
+ this->rateControlState = RateControlState::DECREASE;
389
+ }
390
+
391
+ break;
392
+ }
393
+
394
+ case Types::BandwidthUsage::UNDERUSING:
395
+ {
396
+ this->rateControlState = RateControlState::HOLD;
397
+
398
+ break;
399
+ }
400
+
401
+ NO_DEFAULT_GCC();
402
+ }
403
+ }
404
+
405
+ int64_t AimdRateControl::ClampBitrate(int64_t newBitrate) const
406
+ {
407
+ MS_TRACE();
408
+
409
+ if (
410
+ this->options.estimateBoundedIncrease && this->networkEstimate.has_value() &&
411
+ this->networkEstimate.value().linkCapacityUpper.has_value())
412
+ {
413
+ const int64_t linkCapacityUpper = this->networkEstimate.value().linkCapacityUpper.value();
414
+ const int64_t upperBound = this->options.useCurrentEstimateAsMinUpperBound
415
+ ? std::max(linkCapacityUpper, this->currentBitrate)
416
+ : linkCapacityUpper;
417
+
418
+ newBitrate = std::min(upperBound, newBitrate);
419
+ }
420
+
421
+ if (
422
+ this->networkEstimate.has_value() &&
423
+ this->networkEstimate.value().linkCapacityLower.has_value() &&
424
+ newBitrate < this->currentBitrate)
425
+ {
426
+ const int64_t linkCapacityLower = this->networkEstimate.value().linkCapacityLower.value();
427
+
428
+ newBitrate = std::min(
429
+ this->currentBitrate,
430
+ std::max(
431
+ newBitrate,
432
+ static_cast<int64_t>(
433
+ std::llround(this->options.backoffFactor * static_cast<double>(linkCapacityLower)))));
434
+ }
435
+
436
+ return std::max(newBitrate, this->minConfiguredBitrate);
437
+ }
438
+
439
+ int64_t AimdRateControl::MultiplicativeRateIncrease(
440
+ int64_t atTimeUs, std::optional<int64_t> lastTimeUs, int64_t currentBitrate) const
441
+ {
442
+ MS_TRACE();
443
+
444
+ double alpha{ MultiplicativeIncreaseAlpha };
445
+
446
+ if (lastTimeUs.has_value())
447
+ {
448
+ const double timeSinceLastUpdateSeconds =
449
+ static_cast<double>(atTimeUs - lastTimeUs.value()) / 1000000.0;
450
+
451
+ alpha = std::pow(alpha, std::min(timeSinceLastUpdateSeconds, 1.0));
452
+ }
453
+
454
+ return std::max(
455
+ static_cast<int64_t>(std::llround(static_cast<double>(currentBitrate) * (alpha - 1.0))),
456
+ MinMultiplicativeIncrease);
457
+ }
458
+
459
+ int64_t AimdRateControl::AdditiveRateIncrease(int64_t atTimeUs, int64_t lastTimeUs) const
460
+ {
461
+ MS_TRACE();
462
+
463
+ const double timePeriodSeconds = static_cast<double>(atTimeUs - lastTimeUs) / 1000000.0;
464
+
465
+ return static_cast<int64_t>(GetNearMaxIncreaseRateBpsPerSecond() * timePeriodSeconds);
466
+ }
467
+ } // namespace BWE
468
+ } // namespace RTC
@@ -0,0 +1,61 @@
1
+ #define MS_CLASS "RTC::BWE::Types"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "RTC/BWE/BweTypes.hpp"
5
+ #include "Logger.hpp"
6
+
7
+ namespace RTC
8
+ {
9
+ namespace BWE
10
+ {
11
+ namespace Types
12
+ {
13
+ /* Instance methods. */
14
+
15
+ bool PacketResult::ReceiveTimeOrder::operator()(const PacketResult& lhs, const PacketResult& rhs) const
16
+ {
17
+ MS_TRACE();
18
+
19
+ if (lhs.receiveTimeUs != rhs.receiveTimeUs)
20
+ {
21
+ return lhs.receiveTimeUs < rhs.receiveTimeUs;
22
+ }
23
+
24
+ if (lhs.sentPacket.sendTimeUs != rhs.sentPacket.sendTimeUs)
25
+ {
26
+ return lhs.sentPacket.sendTimeUs < rhs.sentPacket.sendTimeUs;
27
+ }
28
+
29
+ return lhs.sentPacket.sequenceNumber < rhs.sentPacket.sequenceNumber;
30
+ }
31
+
32
+ std::vector<PacketResult> TransportPacketsFeedback::SortedByReceiveTime() const
33
+ {
34
+ MS_TRACE();
35
+
36
+ auto packetResults = ReceivedWithSendInfo();
37
+
38
+ std::ranges::sort(packetResults, PacketResult::ReceiveTimeOrder());
39
+
40
+ return packetResults;
41
+ }
42
+
43
+ std::vector<PacketResult> TransportPacketsFeedback::ReceivedWithSendInfo() const
44
+ {
45
+ MS_TRACE();
46
+
47
+ std::vector<PacketResult> packetResults;
48
+
49
+ for (const auto& packetResult : this->packetFeedbacks)
50
+ {
51
+ if (packetResult.IsReceived())
52
+ {
53
+ packetResults.push_back(packetResult);
54
+ }
55
+ }
56
+
57
+ return packetResults;
58
+ }
59
+ } // namespace Types
60
+ } // namespace BWE
61
+ } // namespace RTC