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,337 @@
1
+ #include "common.hpp"
2
+ #include "RTC/BWE/BweTypes.hpp"
3
+ #include "RTC/BWE/TargetRateController.hpp"
4
+ #include <catch2/catch_test_macros.hpp>
5
+
6
+ SCENARIO("BWE TargetRateController", "[bwe][targetratecontroller]")
7
+ {
8
+ constexpr int64_t InitialTimeUs{ 123456 * 1000 };
9
+ // Shortest span of send times that closes an observation of the loss
10
+ // controller, and hence the pace at which it can be fed.
11
+ constexpr int64_t ObservationDurationLowerBoundUs{ 250 * 1000 };
12
+ constexpr int64_t PacketSizeBytes{ 15000 };
13
+
14
+ int64_t sequenceNumber{ 0 };
15
+
16
+ // Results of a feedback closing one observation of the loss controller, with
17
+ // every packet reported as lost or as received.
18
+ const auto createResults = [&sequenceNumber](
19
+ int64_t firstSendTimeUs,
20
+ bool received) -> std::vector<RTC::BWE::Types::PacketResult>
21
+ {
22
+ std::vector<RTC::BWE::Types::PacketResult> packetResults(2);
23
+
24
+ for (size_t idx{ 0 }; idx < packetResults.size(); ++idx)
25
+ {
26
+ auto& packetResult = packetResults[idx];
27
+
28
+ packetResult.sentPacket.sequenceNumber = sequenceNumber++;
29
+ packetResult.sentPacket.size = PacketSizeBytes;
30
+ packetResult.sentPacket.sendTimeUs =
31
+ firstSendTimeUs + (static_cast<int64_t>(idx) * ObservationDurationLowerBoundUs);
32
+
33
+ if (received)
34
+ {
35
+ packetResult.receiveTimeUs =
36
+ firstSendTimeUs + (static_cast<int64_t>(idx + 1) * ObservationDurationLowerBoundUs);
37
+ }
38
+ }
39
+
40
+ return packetResults;
41
+ };
42
+
43
+ // Feed a bound of the given kind and let the controller act on it.
44
+ const auto feedLimit = [](
45
+ RTC::BWE::TargetRateController& targetRateController,
46
+ bool delayBased,
47
+ int64_t bitrate,
48
+ int64_t nowUs) -> void
49
+ {
50
+ if (delayBased)
51
+ {
52
+ targetRateController.SetDelayBasedEstimate(bitrate);
53
+ }
54
+ else
55
+ {
56
+ targetRateController.SetReceiverEstimate(bitrate);
57
+ }
58
+
59
+ targetRateController.Update(nowUs);
60
+ };
61
+
62
+ SECTION("the first bound applies at once but a later one has to wait")
63
+ {
64
+ // Both bounds behave the same here, so the very same case is run twice.
65
+ for (const bool delayBased : { false, true })
66
+ {
67
+ RTC::BWE::TargetRateController targetRateController;
68
+ int64_t nowUs{ InitialTimeUs };
69
+
70
+ targetRateController.SetBitrateLimits(100000, 1500000);
71
+ targetRateController.SetSendBitrate(200000);
72
+
73
+ targetRateController.UpdatePacketsLost(/*lostPackets*/ 0, /*totalPackets*/ 1, nowUs);
74
+ targetRateController.UpdateRtt(50 * 1000);
75
+
76
+ constexpr int64_t FirstBitrate{ 1000000 };
77
+ constexpr int64_t SecondBitrate{ FirstBitrate + 500000 };
78
+
79
+ feedLimit(targetRateController, delayBased, FirstBitrate, nowUs);
80
+
81
+ REQUIRE(targetRateController.GetTargetBitrate() == FirstBitrate);
82
+
83
+ // Once the start phase is over the target no longer just follows its
84
+ // bounds, so the second one only raises the ceiling.
85
+ nowUs += 2001 * 1000;
86
+
87
+ feedLimit(targetRateController, delayBased, SecondBitrate, nowUs);
88
+
89
+ REQUIRE(targetRateController.GetTargetBitrate() == FirstBitrate);
90
+ }
91
+ }
92
+
93
+ SECTION("a decrease is not reapplied while no further loss is reported")
94
+ {
95
+ constexpr int64_t MinBitrate{ 100000 };
96
+ constexpr int64_t InitialBitrate{ 1000000 };
97
+ constexpr uint8_t FractionLost{ 128 };
98
+ constexpr int64_t RttUs{ 50 * 1000 };
99
+
100
+ RTC::BWE::TargetRateController targetRateController;
101
+ int64_t nowUs{ InitialTimeUs };
102
+
103
+ targetRateController.SetBitrateLimits(MinBitrate, 1500000);
104
+ targetRateController.SetSendBitrate(InitialBitrate);
105
+
106
+ nowUs += 10000 * 1000;
107
+
108
+ REQUIRE(targetRateController.GetTargetBitrate() == InitialBitrate);
109
+ REQUIRE(targetRateController.GetFractionLost() == 0);
110
+ REQUIRE(targetRateController.GetRttUs() == 0);
111
+
112
+ // Report heavy loss so that the target goes down.
113
+ targetRateController.UpdatePacketsLost(/*lostPackets*/ 50, /*totalPackets*/ 100, nowUs);
114
+ targetRateController.UpdateRtt(RttUs);
115
+
116
+ nowUs += 1000 * 1000;
117
+
118
+ targetRateController.Update(nowUs);
119
+
120
+ const int64_t decreasedBitrate = targetRateController.GetTargetBitrate();
121
+
122
+ REQUIRE(decreasedBitrate < InitialBitrate);
123
+ // A single decrease must not reach the minimum, or this case would prove
124
+ // nothing.
125
+ REQUIRE(decreasedBitrate > MinBitrate);
126
+ REQUIRE(targetRateController.GetFractionLost() == FractionLost);
127
+ REQUIRE(targetRateController.GetRttUs() == RttUs);
128
+
129
+ // Without a new report there is nothing saying whether the decrease was
130
+ // enough, so the target must not move again in either direction.
131
+ nowUs += 1000 * 1000;
132
+
133
+ targetRateController.Update(nowUs);
134
+
135
+ REQUIRE(targetRateController.GetTargetBitrate() == decreasedBitrate);
136
+ REQUIRE(targetRateController.GetFractionLost() == FractionLost);
137
+ REQUIRE(targetRateController.GetRttUs() == RttUs);
138
+ }
139
+
140
+ SECTION("setting the send bitrate overrides the bound of the delay based path")
141
+ {
142
+ constexpr int64_t InitialBitrate{ 300000 };
143
+ constexpr int64_t DelayBasedBitrate{ 350000 };
144
+ constexpr int64_t ForcedHighBitrate{ 2500000 };
145
+
146
+ RTC::BWE::TargetRateController targetRateController;
147
+ const int64_t nowUs{ InitialTimeUs };
148
+
149
+ targetRateController.SetBitrateLimits(10000, 10000000);
150
+ targetRateController.SetSendBitrate(InitialBitrate);
151
+
152
+ targetRateController.SetDelayBasedEstimate(DelayBasedBitrate);
153
+ targetRateController.Update(nowUs);
154
+
155
+ REQUIRE(targetRateController.GetTargetBitrate() >= InitialBitrate);
156
+ REQUIRE(targetRateController.GetTargetBitrate() <= DelayBasedBitrate);
157
+
158
+ targetRateController.SetSendBitrate(ForcedHighBitrate);
159
+
160
+ REQUIRE(targetRateController.GetTargetBitrate() == ForcedHighBitrate);
161
+ }
162
+
163
+ SECTION("a negative number of lost packets doesn't overflow the reported fraction")
164
+ {
165
+ RTC::BWE::TargetRateController targetRateController;
166
+ int64_t nowUs{ InitialTimeUs };
167
+
168
+ targetRateController.SetBitrateLimits(100000, 1500000);
169
+ targetRateController.SetSendBitrate(1000000);
170
+
171
+ nowUs += 10000 * 1000;
172
+
173
+ REQUIRE(targetRateController.GetFractionLost() == 0);
174
+
175
+ targetRateController.UpdatePacketsLost(/*lostPackets*/ -1, /*totalPackets*/ 100, nowUs);
176
+
177
+ REQUIRE(targetRateController.GetFractionLost() == 0);
178
+ }
179
+
180
+ SECTION("the round trip time is above the limit once it exceeds it")
181
+ {
182
+ RTC::BWE::TargetRateController targetRateController;
183
+ const int64_t nowUs{ InitialTimeUs };
184
+
185
+ targetRateController.SetBitrateLimits(10000, 10000000);
186
+ targetRateController.SetSendBitrate(300000);
187
+
188
+ targetRateController.UpdatePropagationRtt(/*propagationRttUs*/ 5000 * 1000, nowUs);
189
+
190
+ REQUIRE(targetRateController.IsRttAboveLimit());
191
+ }
192
+
193
+ SECTION("the round trip time is below the limit while it doesn't reach it")
194
+ {
195
+ RTC::BWE::TargetRateController targetRateController;
196
+ const int64_t nowUs{ InitialTimeUs };
197
+
198
+ targetRateController.SetBitrateLimits(10000, 10000000);
199
+ targetRateController.SetSendBitrate(300000);
200
+
201
+ targetRateController.UpdatePropagationRtt(/*propagationRttUs*/ 1000 * 1000, nowUs);
202
+
203
+ REQUIRE(!targetRateController.IsRttAboveLimit());
204
+ }
205
+
206
+ SECTION("the round trip time backoff can be disabled")
207
+ {
208
+ // A limit that no round trip time can reach disables the backoff, which is
209
+ // what the sender of a link known to be slow would want.
210
+ const RTC::BWE::TargetRateController::TargetRateControllerOptions options{
211
+ .maxRttUs = RTC::BWE::Types::TimeUsInfinite
212
+ };
213
+
214
+ RTC::BWE::TargetRateController targetRateController(options);
215
+ const int64_t nowUs{ InitialTimeUs };
216
+
217
+ targetRateController.SetBitrateLimits(10000, 10000000);
218
+ targetRateController.SetSendBitrate(300000);
219
+
220
+ targetRateController.UpdatePropagationRtt(/*propagationRttUs*/ 5000 * 1000, nowUs);
221
+
222
+ REQUIRE(!targetRateController.IsRttAboveLimit());
223
+ }
224
+
225
+ SECTION("a round trip time above the limit drops the target")
226
+ {
227
+ constexpr int64_t InitialBitrate{ 300000 };
228
+
229
+ RTC::BWE::TargetRateController targetRateController;
230
+ int64_t nowUs{ InitialTimeUs };
231
+
232
+ targetRateController.SetBitrateLimits(10000, 10000000);
233
+ targetRateController.SetSendBitrate(InitialBitrate);
234
+
235
+ targetRateController.UpdatePropagationRtt(/*propagationRttUs*/ 5000 * 1000, nowUs);
236
+ targetRateController.Update(nowUs);
237
+
238
+ // Four fifths of 300000.
239
+ REQUIRE(targetRateController.GetTargetBitrate() == 240000);
240
+
241
+ // The drop happens at most once per interval.
242
+ nowUs += 500 * 1000;
243
+
244
+ targetRateController.Update(nowUs);
245
+
246
+ REQUIRE(targetRateController.GetTargetBitrate() == 240000);
247
+
248
+ nowUs += 500 * 1000;
249
+
250
+ targetRateController.Update(nowUs);
251
+
252
+ // And four fifths of that.
253
+ REQUIRE(targetRateController.GetTargetBitrate() == 192000);
254
+ }
255
+
256
+ SECTION("a report telling no loss increases the target by 8% plus a bit")
257
+ {
258
+ constexpr int64_t InitialBitrate{ 300000 };
259
+
260
+ RTC::BWE::TargetRateController targetRateController;
261
+ int64_t nowUs{ InitialTimeUs };
262
+
263
+ targetRateController.SetBitrateLimits(10000, 10000000);
264
+ targetRateController.SetSendBitrate(InitialBitrate);
265
+
266
+ // A report covering enough packets reconsiders the target by itself.
267
+ targetRateController.UpdatePacketsLost(/*lostPackets*/ 0, /*totalPackets*/ 100, nowUs);
268
+
269
+ // 8% over 300000 is 324000, plus the extra 1000.
270
+ REQUIRE(targetRateController.GetTargetBitrate() == 325000);
271
+
272
+ // Long enough for the value grown from to have left the window, so the next
273
+ // increase grows from the current target.
274
+ nowUs += 2001 * 1000;
275
+
276
+ targetRateController.Update(nowUs);
277
+
278
+ // And 8% over 325000 is 351000, plus the extra 1000.
279
+ REQUIRE(targetRateController.GetTargetBitrate() == 352000);
280
+ }
281
+
282
+ SECTION("the loss rules drive the target until the loss controller is ready")
283
+ {
284
+ constexpr int64_t InitialBitrate{ 600000 };
285
+
286
+ RTC::BWE::TargetRateController targetRateController;
287
+ int64_t nowUs{ InitialTimeUs };
288
+
289
+ targetRateController.SetBitrateLimits(10000, 10000000);
290
+ targetRateController.SetSendBitrate(InitialBitrate);
291
+ // NOTE: After SetSendBitrate(), which drops it on purpose, so that the loss
292
+ // controller has a bitrate to start its estimate from.
293
+ targetRateController.SetDelayBasedEstimate(InitialBitrate);
294
+
295
+ // Two observations, one short of what the loss controller needs.
296
+ for (int64_t i{ 0 }; i < 2; ++i)
297
+ {
298
+ targetRateController.UpdateLossBasedController(
299
+ createResults(nowUs, /*received*/ false), /*inAlr*/ false, nowUs);
300
+
301
+ nowUs += 2 * ObservationDurationLowerBoundUs;
302
+ }
303
+
304
+ // Losing every packet would have brought the estimate down, so the target
305
+ // staying put shows that nothing of it is being used yet.
306
+ REQUIRE(
307
+ targetRateController.GetLossBasedState() ==
308
+ RTC::BWE::LossBasedController::State::DELAY_BASED_ESTIMATE);
309
+ REQUIRE(targetRateController.GetTargetBitrate() == InitialBitrate);
310
+ }
311
+
312
+ SECTION("the loss controller takes the target over once it is ready")
313
+ {
314
+ constexpr int64_t InitialBitrate{ 600000 };
315
+
316
+ RTC::BWE::TargetRateController targetRateController;
317
+ int64_t nowUs{ InitialTimeUs };
318
+
319
+ targetRateController.SetBitrateLimits(10000, 10000000);
320
+ targetRateController.SetSendBitrate(InitialBitrate);
321
+ // NOTE: After SetSendBitrate(), which drops it on purpose, so that the loss
322
+ // controller has a bitrate to start its estimate from.
323
+ targetRateController.SetDelayBasedEstimate(InitialBitrate);
324
+
325
+ for (int64_t i{ 0 }; i < 3; ++i)
326
+ {
327
+ targetRateController.UpdateLossBasedController(
328
+ createResults(nowUs, /*received*/ false), /*inAlr*/ false, nowUs);
329
+
330
+ nowUs += 2 * ObservationDurationLowerBoundUs;
331
+ }
332
+
333
+ REQUIRE(
334
+ targetRateController.GetLossBasedState() == RTC::BWE::LossBasedController::State::DECREASING);
335
+ REQUIRE(targetRateController.GetTargetBitrate() < InitialBitrate);
336
+ }
337
+ }
@@ -0,0 +1,182 @@
1
+ #include "common.hpp"
2
+ #include "RTC/BWE/TrendlineEstimator.hpp"
3
+ #include <catch2/catch_test_macros.hpp>
4
+
5
+ SCENARIO("BWE TrendlineEstimator", "[bwe][trendlineestimator]")
6
+ {
7
+ // Number of packets a test is given.
8
+ constexpr size_t PacketCount{ 25 };
9
+ // Time between two consecutive groups of packets.
10
+ constexpr int64_t SendDeltaUs{ 20 * 1000 };
11
+ constexpr int64_t InitialArrivalTimeUs{ 987654321000 };
12
+
13
+ // Feed groups delivered at `deliveryPace` times the pace they were sent at,
14
+ // until the state changes or the packets are exhausted.
15
+ //
16
+ // Both `count` and `arrivalTimeUs` are shared by every run within a test, so
17
+ // that consecutive runs consume a single budget of packets and carry on from
18
+ // the network conditions left by the previous one.
19
+ auto runUntilStateChange = [](
20
+ RTC::BWE::TrendlineEstimator& trendlineEstimator,
21
+ double deliveryPace,
22
+ size_t& count,
23
+ size_t packetCount,
24
+ int64_t& arrivalTimeUs) -> void
25
+ {
26
+ const auto initialState = trendlineEstimator.GetState();
27
+ const auto arrivalDeltaUs = static_cast<int64_t>(SendDeltaUs * deliveryPace);
28
+
29
+ for (; count < packetCount; ++count)
30
+ {
31
+ arrivalTimeUs += arrivalDeltaUs;
32
+
33
+ trendlineEstimator.Update(SendDeltaUs, arrivalDeltaUs, arrivalTimeUs);
34
+
35
+ if (trendlineEstimator.GetState() != initialState)
36
+ {
37
+ return;
38
+ }
39
+ }
40
+ };
41
+
42
+ SECTION("a network delivering at the pace it's fed stays in normal state")
43
+ {
44
+ RTC::BWE::TrendlineEstimator trendlineEstimator;
45
+ size_t count{ 1 };
46
+ int64_t arrivalTimeUs{ InitialArrivalTimeUs };
47
+
48
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
49
+
50
+ runUntilStateChange(trendlineEstimator, /*deliveryPace*/ 1.0, count, PacketCount, arrivalTimeUs);
51
+
52
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
53
+ // Every packet was processed, so the state never changed.
54
+ REQUIRE(count == PacketCount);
55
+ }
56
+
57
+ SECTION("a 10% slower delivery is detected as overusing")
58
+ {
59
+ RTC::BWE::TrendlineEstimator trendlineEstimator;
60
+ size_t count{ 1 };
61
+ int64_t arrivalTimeUs{ InitialArrivalTimeUs };
62
+
63
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
64
+
65
+ runUntilStateChange(trendlineEstimator, /*deliveryPace*/ 1.1, count, PacketCount, arrivalTimeUs);
66
+
67
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::OVERUSING);
68
+
69
+ // The state is kept while the delay keeps growing.
70
+ runUntilStateChange(trendlineEstimator, /*deliveryPace*/ 1.1, count, PacketCount, arrivalTimeUs);
71
+
72
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::OVERUSING);
73
+ REQUIRE(count == PacketCount);
74
+ }
75
+
76
+ SECTION("a 15% faster delivery is detected as underusing")
77
+ {
78
+ RTC::BWE::TrendlineEstimator trendlineEstimator;
79
+ size_t count{ 1 };
80
+ int64_t arrivalTimeUs{ InitialArrivalTimeUs };
81
+
82
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
83
+
84
+ runUntilStateChange(trendlineEstimator, /*deliveryPace*/ 0.85, count, PacketCount, arrivalTimeUs);
85
+
86
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::UNDERUSING);
87
+
88
+ // The state is kept while the delay keeps shrinking.
89
+ runUntilStateChange(trendlineEstimator, /*deliveryPace*/ 0.85, count, PacketCount, arrivalTimeUs);
90
+
91
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::UNDERUSING);
92
+ REQUIRE(count == PacketCount);
93
+ }
94
+
95
+ SECTION("an isolated delay spike is not detected as overusing")
96
+ {
97
+ RTC::BWE::TrendlineEstimator trendlineEstimator;
98
+ size_t count{ 1 };
99
+ int64_t arrivalTimeUs{ InitialArrivalTimeUs };
100
+
101
+ // Fill the regression window with a well behaved network.
102
+ runUntilStateChange(trendlineEstimator, /*deliveryPace*/ 1.0, count, PacketCount, arrivalTimeUs);
103
+
104
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
105
+
106
+ // A single group arrives 50 ms late and the very next one recovers that same
107
+ // time, which is a jitter spike and not a queue that keeps growing.
108
+ arrivalTimeUs += SendDeltaUs + (50 * 1000);
109
+ trendlineEstimator.Update(SendDeltaUs, SendDeltaUs + (50 * 1000), arrivalTimeUs);
110
+
111
+ arrivalTimeUs += SendDeltaUs - (50 * 1000);
112
+ trendlineEstimator.Update(SendDeltaUs, SendDeltaUs - (50 * 1000), arrivalTimeUs);
113
+
114
+ // This is the hysteresis being tested: overuse requires the condition to
115
+ // persist over more than one sample.
116
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
117
+ }
118
+
119
+ SECTION("recovers to normal once the delay stops growing")
120
+ {
121
+ RTC::BWE::TrendlineEstimator trendlineEstimator;
122
+ size_t count{ 1 };
123
+ int64_t arrivalTimeUs{ InitialArrivalTimeUs };
124
+
125
+ runUntilStateChange(
126
+ trendlineEstimator, /*deliveryPace*/ 1.1, count, /*packetCount*/ 100, arrivalTimeUs);
127
+
128
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::OVERUSING);
129
+
130
+ // The delay stops growing but doesn't shrink either, so the accumulated
131
+ // delay flattens out and the slope goes back to zero.
132
+ runUntilStateChange(
133
+ trendlineEstimator, /*deliveryPace*/ 1.0, count, /*packetCount*/ 100, arrivalTimeUs);
134
+
135
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
136
+ }
137
+
138
+ SECTION("the slope cap doesn't get in the way of a delivery that is really slower")
139
+ {
140
+ // The cap is the slope between the least delayed samples of both ends of
141
+ // the window. Under a steadily slower delivery those are the first sample
142
+ // of each end, so the cap is the very slope being capped and nothing is
143
+ // filtered out. It only bites when the middle of the window is more
144
+ // delayed than both ends, which is not a queue growing.
145
+ const RTC::BWE::TrendlineEstimator::TrendlineEstimatorOptions options{ .enableCap = true };
146
+
147
+ RTC::BWE::TrendlineEstimator trendlineEstimator(options);
148
+ size_t count{ 1 };
149
+ int64_t arrivalTimeUs{ InitialArrivalTimeUs };
150
+
151
+ runUntilStateChange(
152
+ trendlineEstimator, /*deliveryPace*/ 1.1, count, /*packetCount*/ 100, arrivalTimeUs);
153
+
154
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::OVERUSING);
155
+ }
156
+
157
+ SECTION("a group arriving out of order doesn't throw the estimator off")
158
+ {
159
+ // Sorting only decides which sample is dropped when the window is full and
160
+ // what the ends of the window are for the slope cap, since fitting a line
161
+ // doesn't depend on the order of the points.
162
+ const RTC::BWE::TrendlineEstimator::TrendlineEstimatorOptions options{ .enableSort = true,
163
+ .enableCap = true };
164
+
165
+ RTC::BWE::TrendlineEstimator trendlineEstimator(options);
166
+
167
+ for (size_t idx{ 0 }; idx < 30; ++idx)
168
+ {
169
+ const int64_t arrivalTimeUs = InitialArrivalTimeUs + (static_cast<int64_t>(idx) * SendDeltaUs);
170
+
171
+ trendlineEstimator.Update(SendDeltaUs, SendDeltaUs, arrivalTimeUs);
172
+ }
173
+
174
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
175
+
176
+ // A group whose arrival time goes backwards, which is what a source giving
177
+ // them out of order looks like.
178
+ trendlineEstimator.Update(SendDeltaUs, SendDeltaUs, InitialArrivalTimeUs + (15 * SendDeltaUs));
179
+
180
+ REQUIRE(trendlineEstimator.GetState() == RTC::BWE::Types::BandwidthUsage::NORMAL);
181
+ }
182
+ }
@@ -0,0 +1,61 @@
1
+ #include "common.hpp"
2
+ #include "RTC/BWE/BweTypes.hpp"
3
+ #include "RTC/BWE/Utils.hpp"
4
+ #include <catch2/catch_test_macros.hpp>
5
+
6
+ SCENARIO("BWE Utils", "[bwe][utils]")
7
+ {
8
+ SECTION("ApplyBitrateFactor() gives the bitrate times the factor")
9
+ {
10
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(600000, 1.02) == 612000);
11
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(600000, 0.95) == 570000);
12
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(600000, 1.0) == 600000);
13
+ }
14
+
15
+ SECTION("ApplyBitrateFactor() rounds to the nearest bitrate, away from zero on a tie")
16
+ {
17
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(3, 0.4) == 1);
18
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(3, 0.5) == 2);
19
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(7, 0.5) == 4);
20
+ }
21
+
22
+ SECTION("ApplyBitrateFactor() gives no bitrate at all beyond what the type holds")
23
+ {
24
+ // Anything over the maximum means no limit, which is what its own value
25
+ // already means.
26
+ REQUIRE(
27
+ RTC::BWE::Utils::ApplyBitrateFactor(RTC::BWE::Types::BitrateInfinite, 1.3) ==
28
+ RTC::BWE::Types::BitrateInfinite);
29
+ REQUIRE(
30
+ RTC::BWE::Utils::ApplyBitrateFactor(RTC::BWE::Types::BitrateInfinite / 2, 4.0) ==
31
+ RTC::BWE::Types::BitrateInfinite);
32
+ REQUIRE(
33
+ RTC::BWE::Utils::ApplyBitrateFactor(RTC::BWE::Types::BitrateInfinite, 1.0) ==
34
+ RTC::BWE::Types::BitrateInfinite);
35
+ }
36
+
37
+ SECTION("ApplyBitrateFactor() never gives a negative bitrate")
38
+ {
39
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(600000, -1.0) == 0);
40
+ REQUIRE(RTC::BWE::Utils::ApplyBitrateFactor(0, 1.5) == 0);
41
+ }
42
+
43
+ SECTION("AddBitrates() gives the sum")
44
+ {
45
+ REQUIRE(RTC::BWE::Utils::AddBitrates(600000, 1000) == 601000);
46
+ REQUIRE(RTC::BWE::Utils::AddBitrates(600000, 0) == 600000);
47
+ }
48
+
49
+ SECTION("AddBitrates() gives no bitrate at all beyond what the type holds")
50
+ {
51
+ REQUIRE(
52
+ RTC::BWE::Utils::AddBitrates(RTC::BWE::Types::BitrateInfinite, 1000) ==
53
+ RTC::BWE::Types::BitrateInfinite);
54
+ REQUIRE(
55
+ RTC::BWE::Utils::AddBitrates(RTC::BWE::Types::BitrateInfinite - 1000, 1001) ==
56
+ RTC::BWE::Types::BitrateInfinite);
57
+ REQUIRE(
58
+ RTC::BWE::Utils::AddBitrates(RTC::BWE::Types::BitrateInfinite - 1000, 1000) ==
59
+ RTC::BWE::Types::BitrateInfinite);
60
+ }
61
+ }