mediasoup 3.27.1 → 3.29.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 (297) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/node/lib/Consumer.d.ts.map +1 -1
  3. package/node/lib/Consumer.js +4 -51
  4. package/node/lib/PipeTransportTypes.d.ts +6 -1
  5. package/node/lib/PipeTransportTypes.d.ts.map +1 -1
  6. package/node/lib/PlainTransportTypes.d.ts +6 -1
  7. package/node/lib/PlainTransportTypes.d.ts.map +1 -1
  8. package/node/lib/Producer.d.ts.map +1 -1
  9. package/node/lib/Producer.js +4 -8
  10. package/node/lib/ProducerTypes.d.ts +4 -2
  11. package/node/lib/ProducerTypes.d.ts.map +1 -1
  12. package/node/lib/Router.d.ts +4 -4
  13. package/node/lib/Router.d.ts.map +1 -1
  14. package/node/lib/Router.js +14 -7
  15. package/node/lib/RouterTypes.d.ts +7 -1
  16. package/node/lib/RouterTypes.d.ts.map +1 -1
  17. package/node/lib/Transport.d.ts +2 -1
  18. package/node/lib/Transport.d.ts.map +1 -1
  19. package/node/lib/Transport.js +24 -16
  20. package/node/lib/TransportTypes.d.ts +12 -2
  21. package/node/lib/TransportTypes.d.ts.map +1 -1
  22. package/node/lib/WebRtcTransportTypes.d.ts +6 -1
  23. package/node/lib/WebRtcTransportTypes.d.ts.map +1 -1
  24. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts +3 -4
  25. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts.map +1 -1
  26. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.js +3 -4
  27. package/node/lib/fbs/transport/options.d.ts +6 -2
  28. package/node/lib/fbs/transport/options.d.ts.map +1 -1
  29. package/node/lib/fbs/transport/options.js +19 -7
  30. package/node/lib/fbs/transport/sctp-zero-checksum.d.ts +6 -0
  31. package/node/lib/fbs/transport/sctp-zero-checksum.d.ts.map +1 -0
  32. package/node/lib/fbs/transport/sctp-zero-checksum.js +11 -0
  33. package/node/lib/fbs/transport/stats.d.ts +2 -8
  34. package/node/lib/fbs/transport/stats.d.ts.map +1 -1
  35. package/node/lib/fbs/transport/stats.js +5 -29
  36. package/node/lib/fbs/transport.d.ts +1 -0
  37. package/node/lib/fbs/transport.d.ts.map +1 -1
  38. package/node/lib/fbs/transport.js +4 -2
  39. package/node/lib/ortc.d.ts +0 -2
  40. package/node/lib/ortc.d.ts.map +1 -1
  41. package/node/lib/ortc.js +11 -21
  42. package/node/lib/rtpMappingFbsUtils.d.ts +6 -0
  43. package/node/lib/rtpMappingFbsUtils.d.ts.map +1 -0
  44. package/node/lib/rtpMappingFbsUtils.js +65 -0
  45. package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
  46. package/node/lib/rtpParametersFbsUtils.js +0 -6
  47. package/node/lib/rtpParametersTypes.d.ts +1 -1
  48. package/node/lib/rtpParametersTypes.d.ts.map +1 -1
  49. package/node/lib/rtpStreamFbsUtils.d.ts +4 -0
  50. package/node/lib/rtpStreamFbsUtils.d.ts.map +1 -0
  51. package/node/lib/rtpStreamFbsUtils.js +51 -0
  52. package/node/lib/supportedRtpCapabilities.d.ts.map +1 -1
  53. package/node/lib/supportedRtpCapabilities.js +6 -13
  54. package/node/lib/test/test-Consumer.js +1 -13
  55. package/node/lib/test/test-DataConsumer.js +9 -0
  56. package/node/lib/test/test-DataProducer.js +38 -0
  57. package/node/lib/test/test-PipeTransport.js +27 -29
  58. package/node/lib/test/test-Producer.js +97 -0
  59. package/node/lib/test/test-ortc.js +34 -14
  60. package/npm-scripts.mjs +35 -44
  61. package/package.json +14 -10
  62. package/worker/fbs/rtpParameters.fbs +0 -1
  63. package/worker/fbs/transport.fbs +9 -2
  64. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  65. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +16 -2
  66. package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +14 -1
  67. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +17 -4
  68. package/worker/include/DepLibUV.hpp +13 -0
  69. package/worker/include/RTC/BWE/AimdRateControl.hpp +9 -9
  70. package/worker/include/RTC/BWE/AlrDetector.hpp +97 -0
  71. package/worker/include/RTC/BWE/BitrateProber.hpp +217 -0
  72. package/worker/include/RTC/BWE/{Utils.hpp → BitrateUtils.hpp} +3 -3
  73. package/worker/include/RTC/BWE/BweTypes.hpp +207 -2
  74. package/worker/include/RTC/BWE/DelayBasedBwe.hpp +3 -3
  75. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +2 -16
  76. package/worker/include/RTC/BWE/InterArrival.hpp +117 -0
  77. package/worker/include/RTC/BWE/IntervalBudget.hpp +81 -0
  78. package/worker/include/RTC/BWE/LossBasedController.hpp +109 -4
  79. package/worker/include/RTC/BWE/OveruseDetector.hpp +72 -0
  80. package/worker/include/RTC/BWE/OveruseEstimator.hpp +115 -0
  81. package/worker/include/RTC/BWE/ProbeBitrateEstimator.hpp +84 -0
  82. package/worker/include/RTC/BWE/ProbeController.hpp +379 -0
  83. package/worker/include/RTC/BWE/ProbePacketGenerator.hpp +126 -0
  84. package/worker/include/RTC/BWE/ProbingScheduler.hpp +183 -0
  85. package/worker/include/RTC/BWE/ReceiverTransportCongestionController.hpp +148 -0
  86. package/worker/include/RTC/BWE/RembGenerator.hpp +97 -0
  87. package/worker/include/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp +237 -0
  88. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +26 -0
  89. package/worker/include/RTC/BWE/SendPacketHistory.hpp +161 -25
  90. package/worker/include/RTC/BWE/SenderTransportCongestionController.hpp +343 -0
  91. package/worker/include/RTC/BWE/TargetRateController.hpp +4 -1
  92. package/worker/include/RTC/BWE/TransportWideCcFeedbackGenerator.hpp +147 -0
  93. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +18 -3
  94. package/worker/include/RTC/Consts.hpp +70 -0
  95. package/worker/include/RTC/Consumer.hpp +8 -1
  96. package/worker/include/RTC/DataConsumer.hpp +3 -5
  97. package/worker/include/RTC/DirectTransport.hpp +4 -5
  98. package/worker/include/RTC/PipeTransport.hpp +4 -5
  99. package/worker/include/RTC/PlainTransport.hpp +4 -5
  100. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +6 -7
  101. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +3 -1
  102. package/worker/include/RTC/RTP/Codecs/Tools.hpp +1 -1
  103. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +0 -1
  104. package/worker/include/RTC/RTP/Packet.hpp +16 -4
  105. package/worker/include/RTC/RTP/ProbationGenerator.hpp +0 -8
  106. package/worker/include/RTC/RTP/RetransmissionBuffer.hpp +36 -10
  107. package/worker/include/RTC/RTP/RtpStream.hpp +33 -9
  108. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +23 -4
  109. package/worker/include/RTC/RTP/RtpStreamSend.hpp +126 -11
  110. package/worker/include/RTC/RTP/RtxStream.hpp +10 -4
  111. package/worker/include/RTC/RateCalculator.hpp +103 -24
  112. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +33 -3
  113. package/worker/include/RTC/{RtcLogger.hpp → RtcLogger/RtpPacket.hpp} +5 -3
  114. package/worker/include/RTC/RtcLogger/SendBurst.hpp +88 -0
  115. package/worker/include/RTC/RtpDictionaries.hpp +3 -4
  116. package/worker/include/RTC/SCTP/association/Association.hpp +1 -1
  117. package/worker/include/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.hpp +12 -3
  118. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +0 -1
  119. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +4 -4
  120. package/worker/include/RTC/SCTP/rx/DataTracker.hpp +1 -1
  121. package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +1 -1
  122. package/worker/include/RTC/SctpDictionaries.hpp +2 -2
  123. package/worker/include/RTC/TcpConnection.hpp +2 -1
  124. package/worker/include/RTC/Transport.hpp +23 -8
  125. package/worker/include/RTC/TransportCongestionControlClient.hpp +0 -5
  126. package/worker/include/RTC/TransportCongestionControlServer.hpp +0 -5
  127. package/worker/include/RTC/TransportTuple.hpp +61 -6
  128. package/worker/include/RTC/WebRtcTransport.hpp +4 -5
  129. package/worker/include/Shared.hpp +5 -0
  130. package/worker/include/SharedInterface.hpp +10 -0
  131. package/worker/include/Utils.hpp +81 -5
  132. package/worker/include/common.hpp +12 -4
  133. package/worker/include/handles/SendCallbacks.hpp +34 -0
  134. package/worker/include/handles/TcpConnectionHandle.hpp +4 -12
  135. package/worker/include/handles/UdpSocketHandle.hpp +4 -8
  136. package/worker/meson.build +45 -3
  137. package/worker/meson_options.txt +1 -0
  138. package/worker/mocks/include/MockShared.hpp +16 -2
  139. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +1 -1
  140. package/worker/scripts/package-lock.json +6 -6
  141. package/worker/src/RTC/BWE/AimdRateControl.cpp +26 -27
  142. package/worker/src/RTC/BWE/AlrDetector.cpp +80 -0
  143. package/worker/src/RTC/BWE/BitrateProber.cpp +256 -0
  144. package/worker/src/RTC/BWE/{Utils.cpp → BitrateUtils.cpp} +4 -4
  145. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +18 -22
  146. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +21 -38
  147. package/worker/src/RTC/BWE/InterArrival.cpp +216 -0
  148. package/worker/src/RTC/BWE/IntervalBudget.cpp +93 -0
  149. package/worker/src/RTC/BWE/LossBasedController.cpp +189 -41
  150. package/worker/src/RTC/BWE/OveruseDetector.cpp +128 -0
  151. package/worker/src/RTC/BWE/OveruseEstimator.cpp +166 -0
  152. package/worker/src/RTC/BWE/ProbeBitrateEstimator.cpp +222 -0
  153. package/worker/src/RTC/BWE/ProbeController.cpp +645 -0
  154. package/worker/src/RTC/BWE/ProbePacketGenerator.cpp +135 -0
  155. package/worker/src/RTC/BWE/ProbingScheduler.cpp +191 -0
  156. package/worker/src/RTC/BWE/ReceiverTransportCongestionController.cpp +207 -0
  157. package/worker/src/RTC/BWE/RembGenerator.cpp +169 -0
  158. package/worker/src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp +497 -0
  159. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +47 -0
  160. package/worker/src/RTC/BWE/SendPacketHistory.cpp +173 -50
  161. package/worker/src/RTC/BWE/SenderTransportCongestionController.cpp +599 -0
  162. package/worker/src/RTC/BWE/TargetRateController.cpp +12 -14
  163. package/worker/src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp +376 -0
  164. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +24 -5
  165. package/worker/src/RTC/Consumer.cpp +10 -7
  166. package/worker/src/RTC/DataConsumer.cpp +10 -12
  167. package/worker/src/RTC/DirectTransport.cpp +14 -8
  168. package/worker/src/RTC/DtlsTransport.cpp +8 -8
  169. package/worker/src/RTC/ICE/IceCandidate.cpp +4 -4
  170. package/worker/src/RTC/ICE/IceServer.cpp +1 -1
  171. package/worker/src/RTC/PipeTransport.cpp +13 -8
  172. package/worker/src/RTC/PlainTransport.cpp +13 -8
  173. package/worker/src/RTC/Producer.cpp +14 -31
  174. package/worker/src/RTC/RTCP/Bye.cpp +1 -1
  175. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +18 -0
  176. package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +2 -2
  177. package/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp +2 -1
  178. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +2 -2
  179. package/worker/src/RTC/RTCP/Sdes.cpp +1 -1
  180. package/worker/src/RTC/RTP/Codecs/DependencyDescriptor.cpp +2 -1
  181. package/worker/src/RTC/RTP/Packet.cpp +26 -11
  182. package/worker/src/RTC/RTP/ProbationGenerator.cpp +5 -6
  183. package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +21 -8
  184. package/worker/src/RTC/RTP/RtpStream.cpp +1 -4
  185. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +109 -102
  186. package/worker/src/RTC/RTP/RtpStreamSend.cpp +442 -258
  187. package/worker/src/RTC/RTP/RtxStream.cpp +32 -22
  188. package/worker/src/RTC/RateCalculator.cpp +133 -28
  189. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +56 -1
  190. package/worker/src/RTC/{RtcLogger.cpp → RtcLogger/RtpPacket.cpp} +2 -2
  191. package/worker/src/RTC/RtcLogger/SendBurst.cpp +124 -0
  192. package/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +2 -12
  193. package/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +1 -1
  194. package/worker/src/RTC/SCTP/association/Association.cpp +4 -3
  195. package/worker/src/RTC/SCTP/association/StateCookie.cpp +26 -6
  196. package/worker/src/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.cpp +4 -3
  197. package/worker/src/RTC/SCTP/rx/InterleavedReassemblyStreams.cpp +3 -3
  198. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +4 -2
  199. package/worker/src/RTC/SCTP/rx/TraditionalReassemblyStreams.cpp +4 -4
  200. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +4 -2
  201. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +4 -4
  202. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +6 -10
  203. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +2 -2
  204. package/worker/src/RTC/SrtpSession.cpp +2 -2
  205. package/worker/src/RTC/SvcProducerStreamManager.cpp +2 -2
  206. package/worker/src/RTC/TcpConnection.cpp +2 -2
  207. package/worker/src/RTC/Transport.cpp +160 -113
  208. package/worker/src/RTC/TransportCongestionControlClient.cpp +0 -66
  209. package/worker/src/RTC/TransportCongestionControlServer.cpp +0 -55
  210. package/worker/src/RTC/TransportTuple.cpp +4 -4
  211. package/worker/src/RTC/WebRtcServer.cpp +4 -3
  212. package/worker/src/RTC/WebRtcTransport.cpp +20 -13
  213. package/worker/src/Utils/BitStream.cpp +24 -0
  214. package/worker/src/Utils/Crypto.cpp +114 -98
  215. package/worker/src/handles/BackoffTimerHandle.cpp +1 -1
  216. package/worker/src/handles/TcpConnectionHandle.cpp +13 -23
  217. package/worker/src/handles/UdpSocketHandle.cpp +14 -21
  218. package/worker/subprojects/catch2.wrap +6 -6
  219. package/worker/subprojects/openssl.wrap +11 -12
  220. package/worker/subprojects/packagefiles/ankerl-unordered-dense/meson.build +1 -1
  221. package/worker/subprojects/unordered-dense.wrap +4 -4
  222. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +68 -14
  223. package/worker/test/include/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.hpp +125 -0
  224. package/worker/test/src/RTC/BWE/TestAlrDetector.cpp +110 -0
  225. package/worker/test/src/RTC/BWE/TestBitrateProber.cpp +418 -0
  226. package/worker/test/src/RTC/BWE/TestBitrateUtils.cpp +61 -0
  227. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +9 -9
  228. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +79 -60
  229. package/worker/test/src/RTC/BWE/TestInterArrival.cpp +643 -0
  230. package/worker/test/src/RTC/BWE/TestInterArrivalDelta.cpp +8 -8
  231. package/worker/test/src/RTC/BWE/TestIntervalBudget.cpp +130 -0
  232. package/worker/test/src/RTC/BWE/TestOveruseDetector.cpp +519 -0
  233. package/worker/test/src/RTC/BWE/TestProbeBitrateEstimator.cpp +266 -0
  234. package/worker/test/src/RTC/BWE/TestProbeController.cpp +1685 -0
  235. package/worker/test/src/RTC/BWE/TestProbePacketGenerator.cpp +250 -0
  236. package/worker/test/src/RTC/BWE/TestProbingScheduler.cpp +236 -0
  237. package/worker/test/src/RTC/BWE/TestReceiverTransportCongestionController.cpp +346 -0
  238. package/worker/test/src/RTC/BWE/TestRembGenerator.cpp +285 -0
  239. package/worker/test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp +414 -0
  240. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +296 -77
  241. package/worker/test/src/RTC/BWE/TestSenderTransportCongestionController.cpp +510 -0
  242. package/worker/test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp +580 -0
  243. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +6 -6
  244. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +133 -29
  245. package/worker/test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp +624 -0
  246. package/worker/test/src/RTC/RTCP/TestBye.cpp +1 -1
  247. package/worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp +1 -1
  248. package/worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp +1 -1
  249. package/worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp +1 -1
  250. package/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp +1 -1
  251. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +20 -1
  252. package/worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp +1 -1
  253. package/worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp +1 -1
  254. package/worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp +1 -1
  255. package/worker/test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp +1 -1
  256. package/worker/test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp +1 -1
  257. package/worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp +1 -1
  258. package/worker/test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp +1 -1
  259. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp +1 -1
  260. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +1 -1
  261. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +1 -1
  262. package/worker/test/src/RTC/RTCP/TestReceiverReport.cpp +1 -1
  263. package/worker/test/src/RTC/RTCP/TestSenderReport.cpp +1 -1
  264. package/worker/test/src/RTC/RTP/TestPacket.cpp +58 -4
  265. package/worker/test/src/RTC/RTP/TestProbationGenerator.cpp +3 -2
  266. package/worker/test/src/RTC/RTP/TestRetransmissionBuffer.cpp +60 -28
  267. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +50 -0
  268. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +804 -23
  269. package/worker/test/src/RTC/RTP/TestSharedPacket.cpp +1 -1
  270. package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +42 -0
  271. package/worker/test/src/RTC/SCTP/association/TestNegotiatedCapabilities.cpp +54 -5
  272. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +80 -15
  273. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +410 -3
  274. package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +1 -1
  275. package/worker/test/src/RTC/SCTP/packet/parameters/TestZeroChecksumAcceptableParameter.cpp +37 -5
  276. package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +5 -4
  277. package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +1 -1
  278. package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +1 -1
  279. package/worker/test/src/RTC/SCTP/rx/TestTraditionalReassemblyStreams.cpp +1 -1
  280. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +1 -1
  281. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +11 -10
  282. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +1 -1
  283. package/worker/test/src/RTC/TestNackGenerator.cpp +1 -1
  284. package/worker/test/src/RTC/TestPortManager.cpp +2 -2
  285. package/worker/test/src/RTC/TestRateCalculator.cpp +323 -61
  286. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +103 -9
  287. package/worker/test/src/RTC/TestRemoteClockOffsetEstimator.cpp +13 -13
  288. package/worker/test/src/RTC/TestRtpEncodingParameters.cpp +1 -1
  289. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +34 -16
  290. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +31 -13
  291. package/worker/test/src/RTC/TestSubchannelsCodec.cpp +2 -2
  292. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +37 -19
  293. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +11 -11
  294. package/worker/test/src/RTC/TestTransportTuple.cpp +3 -2
  295. package/worker/test/src/Utils/TestCrypto.cpp +71 -2
  296. package/worker/test/src/Utils/TestTime.cpp +120 -21
  297. package/worker/test/src/RTC/BWE/TestUtils.cpp +0 -61
@@ -0,0 +1,183 @@
1
+ #ifndef MS_RTC_BWE_PROBING_SCHEDULER_HPP
2
+ #define MS_RTC_BWE_PROBING_SCHEDULER_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "handles/TimerHandleInterface.hpp"
6
+ #include "RTC/BWE/BitrateProber.hpp"
7
+ #include "RTC/BWE/BweTypes.hpp"
8
+ #include "RTC/BWE/ProbePacketGenerator.hpp"
9
+ #include "RTC/RTP/Packet.hpp"
10
+ #include "SharedInterface.hpp"
11
+ #include <vector>
12
+
13
+ namespace RTC
14
+ {
15
+ namespace BWE
16
+ {
17
+ /**
18
+ * Puts a probing burst on the wire at the pace it was asked for.
19
+ *
20
+ * Somebody else decides that a burst is worth sending and at what bitrate;
21
+ * this is what turns that decision into packets leaving at the right
22
+ * instants. It holds the burst, asks for the packets that carry the bytes
23
+ * due right now, hands them over one by one, and arms a timer for the next
24
+ * shot.
25
+ *
26
+ * The spacing is the whole point. A burst is a bitrate held for a few
27
+ * milliseconds, so letting its packets go as fast as the socket takes them
28
+ * measures the queue of whoever is in the way instead of the link. The
29
+ * instants come from the burst's own start and the bytes gone out so far, so
30
+ * a packet that leaves late is made up for by the ones behind it rather than
31
+ * dragging the whole burst below the bitrate asked for.
32
+ *
33
+ * @remarks
34
+ * - It is not a pacer. Nothing but the packets of a burst goes through here,
35
+ * media is never queued, and there is no timer running while no burst is
36
+ * being emitted.
37
+ */
38
+ class ProbingScheduler : public ProbePacketGenerator::Listener,
39
+ public TimerHandleInterface::Listener
40
+ {
41
+ public:
42
+ class Listener
43
+ {
44
+ public:
45
+ virtual ~Listener() = default;
46
+
47
+ public:
48
+ /**
49
+ * A packet of the burst is ready to go out.
50
+ *
51
+ * @remarks
52
+ * - The packet must be sent before returning, since the next one is
53
+ * built over the very same instance.
54
+ * - It carries room for the abs-send-time and for the transport wide
55
+ * sequence number but no value for either, so both have to be written
56
+ * here.
57
+ * - This must not destroy the `ProbingScheduler`, not even indirectly.
58
+ * It goes on reading its own members after this returns.
59
+ */
60
+ virtual void OnProbingSchedulerSendRtpPacket(
61
+ ProbingScheduler* probingScheduler,
62
+ RTC::RTP::Packet* packet,
63
+ const Types::ProbeCluster& probeCluster) = 0;
64
+ };
65
+
66
+ private:
67
+ /**
68
+ * Holds what a shot needs while it is being emitted. The packets are
69
+ * handed over through a callback, so there is no scope of our own to keep
70
+ * it in, and this makes sure it doesn't outlive the shot.
71
+ */
72
+ class ScopedShot
73
+ {
74
+ public:
75
+ ScopedShot(ProbingScheduler& probingScheduler, const Types::ProbeCluster& probeCluster);
76
+
77
+ ~ScopedShot();
78
+
79
+ ScopedShot(const ScopedShot&) = delete;
80
+ ScopedShot& operator=(const ScopedShot&) = delete;
81
+
82
+ private:
83
+ ProbingScheduler& probingScheduler;
84
+ };
85
+
86
+ public:
87
+ ProbingScheduler(Listener* listener, SharedInterface* shared);
88
+
89
+ ~ProbingScheduler() override = default;
90
+
91
+ // NOTE: It hands itself over as the listener of what it owns, so a copy
92
+ // would leave those pointing at the instance it came from.
93
+ ProbingScheduler(const ProbingScheduler&) = delete;
94
+ ProbingScheduler& operator=(const ProbingScheduler&) = delete;
95
+
96
+ /**
97
+ * Take the bursts that have been asked for.
98
+ *
99
+ * @remarks
100
+ * - Nothing goes out within this call. The first burst begins on the turn
101
+ * of the event loop that follows, so that the send path never runs
102
+ * inside a call that may itself come from the send path.
103
+ * - They are emitted in the order they were asked for, and one asked for
104
+ * long ago is dropped rather than sent late.
105
+ */
106
+ void CreateProbeClusters(const std::vector<Types::ProbeClusterConfig>& clusterConfigs);
107
+
108
+ /**
109
+ * Bytes that every packet carries on top of its own length once it's on
110
+ * the network, so that a burst measures what the link really has to
111
+ * carry.
112
+ *
113
+ * @remarks
114
+ * - It depends on the path the packets take, so it has to be set again
115
+ * whenever that changes.
116
+ */
117
+ void SetPacketOverhead(size_t packetOverhead)
118
+ {
119
+ this->packetOverhead = packetOverhead;
120
+ }
121
+
122
+ /**
123
+ * Whether a burst is being emitted right now.
124
+ */
125
+ bool IsProbing() const
126
+ {
127
+ return this->bitrateProber.IsProbing();
128
+ }
129
+
130
+ /* Pure virtual methods inherited from RTC::BWE::ProbePacketGenerator::Listener. */
131
+ public:
132
+ void OnProbePacketGeneratorSendRtpPacket(
133
+ ProbePacketGenerator* probePacketGenerator, RTC::RTP::Packet* packet) override;
134
+
135
+ /* Pure virtual methods inherited from TimerHandleInterface::Listener. */
136
+ public:
137
+ void OnTimer(TimerHandleInterface* timer) override;
138
+
139
+ private:
140
+ /**
141
+ * Emit every shot that is due by now and arm the timer for the next one,
142
+ * or stop it if there is nothing left to emit.
143
+ *
144
+ * @remarks
145
+ * - More than one may be due when the event loop was held up for longer
146
+ * than the time between two shots. Leaving them for later turns of the
147
+ * loop would stretch the burst and have it measure a bitrate below the
148
+ * one it was asked for.
149
+ */
150
+ void Process();
151
+
152
+ /**
153
+ * Arm the timer for the given instant, or stop it if there is none.
154
+ */
155
+ void ScheduleNextProbe(std::optional<int64_t> nextProbeTimeUs, int64_t nowUs);
156
+
157
+ private:
158
+ // Passed by argument.
159
+ Listener* listener{ nullptr };
160
+ SharedInterface* shared{ nullptr };
161
+ // Others.
162
+ // Decides which burst is being emitted and at what instant each of its
163
+ // packets is due.
164
+ BitrateProber bitrateProber;
165
+ // Makes the packets that carry the bytes of a burst.
166
+ ProbePacketGenerator probePacketGenerator;
167
+ // Allocated by this.
168
+ const std::unique_ptr<TimerHandleInterface> nextProbeTimer;
169
+ // Bytes each packet carries on top of its own length once it's on the
170
+ // network.
171
+ size_t packetOverhead{ 0 };
172
+ // The burst the current shot belongs to, which travels with each of its
173
+ // packets. Only meaningful while a shot is being emitted, since it's the
174
+ // generator that calls back and it knows nothing about bursts.
175
+ Types::ProbeCluster shotProbeCluster;
176
+ // Bytes of the current shot that have gone out, overhead included, which
177
+ // is only meaningful while one is being emitted.
178
+ size_t shotSentBytes{ 0 };
179
+ };
180
+ } // namespace BWE
181
+ } // namespace RTC
182
+
183
+ #endif
@@ -0,0 +1,148 @@
1
+ #ifndef MS_RTC_BWE_RECEIVER_TRANSPORT_CONGESTION_CONTROLLER_HPP
2
+ #define MS_RTC_BWE_RECEIVER_TRANSPORT_CONGESTION_CONTROLLER_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "RTC/BWE/BweTypes.hpp"
6
+ #include "RTC/BWE/RembGenerator.hpp"
7
+ #include "RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp"
8
+ #include "RTC/BWE/TransportWideCcFeedbackGenerator.hpp"
9
+ #include "RTC/Consts.hpp"
10
+ #include "RTC/RTCP/Packet.hpp"
11
+ #include "RTC/RTP/Packet.hpp"
12
+ #include "RTC/RtpDictionaries.hpp"
13
+ #include "SharedInterface.hpp"
14
+ #include <vector>
15
+
16
+ namespace RTC
17
+ {
18
+ namespace BWE
19
+ {
20
+ /**
21
+ * Everything the receiving side of a transport does about congestion, which
22
+ * amounts to telling the remote sender how much it may send towards us.
23
+ *
24
+ * How that is said depends on what both endpoints negotiated. With
25
+ * transport-cc nothing is estimated here: the instant each packet arrived is
26
+ * reported back and the remote sender does the estimating. With REMB it is
27
+ * the other way round, and a bitrate is computed here and announced.
28
+ *
29
+ * The cap the application sets is announced as a REMB either way, since that
30
+ * is the only way to tell a remote sender to hold back.
31
+ */
32
+ class ReceiverTransportCongestionController : public TransportWideCcFeedbackGenerator::Listener,
33
+ public RemoteBitrateEstimatorAbsSendTime::Listener,
34
+ public RembGenerator::Listener
35
+ {
36
+ public:
37
+ class Listener
38
+ {
39
+ public:
40
+ virtual ~Listener() = default;
41
+
42
+ public:
43
+ /**
44
+ * An RTCP packet is ready for the remote sender.
45
+ *
46
+ * @param packet - Packet to send. It belongs to the caller, so the
47
+ * listener must neither destroy it nor keep it around after this call
48
+ * returns.
49
+ */
50
+ virtual void OnReceiverTransportCongestionControllerSendRtcpPacket(
51
+ ReceiverTransportCongestionController* receiverTransportCongestionControl,
52
+ RTC::RTCP::Packet* packet) = 0;
53
+ };
54
+
55
+ struct ReceiverTransportCongestionControllerOptions
56
+ {
57
+ /**
58
+ * Mechanism both endpoints negotiated, which decides what is done with
59
+ * every packet that comes in.
60
+ */
61
+ Types::CongestionControlType congestionControlType;
62
+ /**
63
+ * Largest an RTCP packet may be on this transport (bytes).
64
+ */
65
+ size_t maxRtcpPacketLen{ RTC::Consts::RtcpPacketMaxSize };
66
+ };
67
+
68
+ public:
69
+ ReceiverTransportCongestionController(
70
+ Listener* listener,
71
+ SharedInterface* shared,
72
+ ReceiverTransportCongestionControllerOptions options);
73
+
74
+ ~ReceiverTransportCongestionController() override = default;
75
+
76
+ ReceiverTransportCongestionController(const ReceiverTransportCongestionController&) = delete;
77
+ ReceiverTransportCongestionController& operator=(
78
+ const ReceiverTransportCongestionController&) = delete;
79
+
80
+ /**
81
+ * Feed a received RTP packet.
82
+ *
83
+ * @param receivedAtUs - Instant the packet arrived.
84
+ * @param kind - Media the stream the packet belongs to carries.
85
+ */
86
+ void ReceiveRtpPacket(int64_t receivedAtUs, const RTC::RTP::Packet* packet, RTC::Media::Kind kind);
87
+
88
+ /**
89
+ * Feed the round trip time towards the remote senders, which bounds how
90
+ * often the estimation of the incoming link may be reduced.
91
+ */
92
+ void OnRttUpdate(int64_t avgRttUs);
93
+
94
+ /**
95
+ * Forget a stream, so that it no longer takes part in the estimation of
96
+ * the incoming link nor in the streams the remote sender is told about.
97
+ */
98
+ void RemoveStream(uint32_t ssrc);
99
+
100
+ /**
101
+ * Cap what the remote sender is told it may send (bps), or zero to let it
102
+ * send whatever the incoming link is estimated to bear.
103
+ */
104
+ void SetMaxIncomingBitrate(int64_t bitrate);
105
+
106
+ /**
107
+ * Latest estimation of the incoming link (bps), or no value while there is
108
+ * none and whenever the estimating is the remote sender's job.
109
+ */
110
+ std::optional<int64_t> GetAvailableBitrate() const;
111
+
112
+ /* Pure virtual methods inherited from TransportWideCcFeedbackGenerator::Listener. */
113
+ public:
114
+ void OnTransportWideCcFeedbackGeneratorSendPacket(
115
+ TransportWideCcFeedbackGenerator* transportWideCcFeedbackGenerator,
116
+ RTC::RTCP::FeedbackRtpTransportPacket* packet) override;
117
+
118
+ /* Pure virtual methods inherited from RemoteBitrateEstimatorAbsSendTime::Listener. */
119
+ public:
120
+ void OnRemoteBitrateEstimatorAbsSendTimeBitrateChanged(
121
+ RemoteBitrateEstimatorAbsSendTime* remoteBitrateEstimator,
122
+ const std::vector<uint32_t>& ssrcs,
123
+ int64_t bitrate) override;
124
+
125
+ /* Pure virtual methods inherited from RembGenerator::Listener. */
126
+ public:
127
+ void OnRembGeneratorSendPacket(
128
+ RembGenerator* rembGenerator, RTC::RTCP::FeedbackPsRembPacket* packet) override;
129
+
130
+ private:
131
+ const ReceiverTransportCongestionControllerOptions options;
132
+
133
+ // Passed by argument.
134
+ Listener* listener{ nullptr };
135
+ SharedInterface* shared{ nullptr };
136
+ // Allocated by this, the first one only in transport-cc mode and the
137
+ // second one only in REMB mode.
138
+ std::unique_ptr<TransportWideCcFeedbackGenerator> transportWideCcFeedbackGenerator;
139
+ std::unique_ptr<RemoteBitrateEstimatorAbsSendTime> remoteBitrateEstimator;
140
+ // Others.
141
+ // It lives in both modes, since the cap is announced as a REMB whatever
142
+ // was negotiated.
143
+ RembGenerator rembGenerator;
144
+ };
145
+ } // namespace BWE
146
+ } // namespace RTC
147
+
148
+ #endif
@@ -0,0 +1,97 @@
1
+ #ifndef MS_RTC_BWE_REMB_GENERATOR_HPP
2
+ #define MS_RTC_BWE_REMB_GENERATOR_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "RTC/RTCP/FeedbackPsRemb.hpp"
6
+ #include <vector>
7
+
8
+ namespace RTC
9
+ {
10
+ namespace BWE
11
+ {
12
+ /**
13
+ * Tells the remote sender how much it may send towards us, as a REMB.
14
+ *
15
+ * Two things end up in that single number: what the incoming link is
16
+ * estimated to bear, and the cap the application asked for.
17
+ */
18
+ class RembGenerator
19
+ {
20
+ public:
21
+ class Listener
22
+ {
23
+ public:
24
+ virtual ~Listener() = default;
25
+
26
+ public:
27
+ /**
28
+ * A REMB packet is ready for the remote sender.
29
+ *
30
+ * @param packet - Packet to send. It belongs to the caller, so the
31
+ * listener must neither destroy it nor keep it around after this call
32
+ * returns.
33
+ */
34
+ virtual void OnRembGeneratorSendPacket(
35
+ RembGenerator* rembGenerator, RTC::RTCP::FeedbackPsRembPacket* packet) = 0;
36
+ };
37
+
38
+ public:
39
+ explicit RembGenerator(Listener* listener);
40
+
41
+ RembGenerator(const RembGenerator&) = delete;
42
+ RembGenerator& operator=(const RembGenerator&) = delete;
43
+
44
+ /**
45
+ * Feed a new estimation of what the incoming link bears (bps).
46
+ *
47
+ * @param nowMs - Current instant.
48
+ * @param ssrcs - Streams the estimation applies to.
49
+ *
50
+ * @remarks
51
+ * - A REMB goes out when the estimation drops enough to be worth telling
52
+ * right away, and otherwise no more often than every 200 ms.
53
+ */
54
+ void OnReceiveBitrateChanged(int64_t nowMs, const std::vector<uint32_t>& ssrcs, int64_t bitrate);
55
+
56
+ /**
57
+ * Cap what is announced to the remote sender (bps), or no value to
58
+ * announce whatever is estimated.
59
+ *
60
+ * @param nowMs - Current instant.
61
+ */
62
+ void SetMaxIncomingBitrate(int64_t nowMs, std::optional<int64_t> bitrate);
63
+
64
+ /**
65
+ * Announce the cap again, or that it is gone, which is what gets either
66
+ * across when there is no estimation driving anything.
67
+ *
68
+ * @param nowMs - Current instant.
69
+ */
70
+ void MaySendLimitationRembFeedback(int64_t nowMs);
71
+
72
+ private:
73
+ /**
74
+ * Build a REMB carrying the given bitrate and hand it to the listener.
75
+ */
76
+ void SendRemb(int64_t bitrate, const std::vector<uint32_t>& ssrcs);
77
+
78
+ private:
79
+ // Passed by argument.
80
+ Listener* listener{ nullptr };
81
+ // Others.
82
+ // Instant the latest REMB was sent at, or no value until one is.
83
+ std::optional<int64_t> lastRembSentAtMs;
84
+ // Bitrate the latest REMB carried, or no value until one is sent. Zero is
85
+ // a value of its own, since that is how a REMB says there is no limit.
86
+ std::optional<int64_t> lastSentRembBitrate;
87
+ // Most that may be announced, or no value when there is no cap.
88
+ std::optional<int64_t> maxIncomingBitrate;
89
+ // Instant the cap was last announced at, or no value until it is.
90
+ std::optional<int64_t> limitationRembSentAtMs;
91
+ // How many REMBs announcing that the cap is gone are still owed.
92
+ uint8_t unlimitedRembCounter{ 0 };
93
+ };
94
+ } // namespace BWE
95
+ } // namespace RTC
96
+
97
+ #endif
@@ -0,0 +1,237 @@
1
+ #ifndef MS_RTC_BWE_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP
2
+ #define MS_RTC_BWE_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "RTC/BWE/AimdRateControl.hpp"
6
+ #include "RTC/BWE/InterArrival.hpp"
7
+ #include "RTC/BWE/OveruseDetector.hpp"
8
+ #include "RTC/BWE/OveruseEstimator.hpp"
9
+ #include "RTC/RTP/Packet.hpp"
10
+ #include "RTC/RateCalculator.hpp"
11
+ #include <ankerl/unordered_dense.h>
12
+ #include <list>
13
+ #include <vector>
14
+
15
+ namespace RTC
16
+ {
17
+ namespace BWE
18
+ {
19
+ /**
20
+ * Estimates the bandwidth of the incoming link out of the 'abs-send-time' RTP
21
+ * extension, for senders that do not negotiate transport-cc.
22
+ *
23
+ * There is no feedback to work with here: all the information available is
24
+ * the instant each packet says it left the sender and the instant it arrived,
25
+ * so the estimation is the delay based detection over the whole group of
26
+ * incoming streams. It also detects the bursts a sender emits at the
27
+ * beginning of a call and takes their rate as a shortcut to an estimate,
28
+ * which is what makes the first seconds of a call usable.
29
+ *
30
+ * The result travels back to the sender as a REMB, so whoever owns this class
31
+ * gets both the estimate and the streams it applies to.
32
+ */
33
+ class RemoteBitrateEstimatorAbsSendTime
34
+ {
35
+ public:
36
+ class Listener
37
+ {
38
+ public:
39
+ virtual ~Listener() = default;
40
+
41
+ public:
42
+ /**
43
+ * The estimation of the incoming link changed, so the remote senders of
44
+ * the given streams have to be told about it.
45
+ *
46
+ * @param ssrcs - Streams the estimation applies to, which are those that
47
+ * have sent something recently.
48
+ * @param bitrate - Estimated bitrate of the incoming link (bps).
49
+ */
50
+ virtual void OnRemoteBitrateEstimatorAbsSendTimeBitrateChanged(
51
+ RemoteBitrateEstimatorAbsSendTime* remoteBitrateEstimator,
52
+ const std::vector<uint32_t>& ssrcs,
53
+ int64_t bitrate) = 0;
54
+ };
55
+
56
+ private:
57
+ /**
58
+ * A packet that may belong to a burst emitted by the sender.
59
+ */
60
+ struct Probe
61
+ {
62
+ /**
63
+ * Instant the packet says it left the sender, in the sender's own
64
+ * timeline (us).
65
+ */
66
+ int64_t sendTimeUs;
67
+ /**
68
+ * Instant the packet arrived (us).
69
+ */
70
+ int64_t receiveTimeUs;
71
+ /**
72
+ * Size of the packet (bytes).
73
+ */
74
+ size_t payloadSize;
75
+ };
76
+
77
+ /**
78
+ * A run of consecutive probes whose send deltas are close enough to each
79
+ * other to look like a single burst.
80
+ *
81
+ * @remarks
82
+ * - While a run is being accumulated the fields below hold sums rather than
83
+ * means, and they are divided by `count` when the run is closed.
84
+ */
85
+ struct Cluster
86
+ {
87
+ /**
88
+ * Rate at which the burst was sent (bps).
89
+ */
90
+ int64_t GetSendBitrate() const
91
+ {
92
+ return (static_cast<int64_t>(this->meanSize) * 8 * 1000000) / this->sendMeanUs;
93
+ }
94
+
95
+ /**
96
+ * Rate at which the burst was received (bps).
97
+ */
98
+ int64_t GetReceiveBitrate() const
99
+ {
100
+ return (static_cast<int64_t>(this->meanSize) * 8 * 1000000) / this->receiveMeanUs;
101
+ }
102
+
103
+ /**
104
+ * Mean time between the send instants of two consecutive probes (us).
105
+ */
106
+ int64_t sendMeanUs{ 0 };
107
+ /**
108
+ * Mean time between the arrival instants of two consecutive probes (us).
109
+ */
110
+ int64_t receiveMeanUs{ 0 };
111
+ /**
112
+ * Mean size of the probes (bytes).
113
+ */
114
+ size_t meanSize{ 0 };
115
+ /**
116
+ * Number of probes in the run.
117
+ */
118
+ int count{ 0 };
119
+ /**
120
+ * How many of those probes came far enough apart from the previous one
121
+ * for the gap to be measurable.
122
+ */
123
+ int numAboveMinDelta{ 0 };
124
+ };
125
+
126
+ enum class ProbeResult : uint8_t
127
+ {
128
+ BITRATE_UPDATED,
129
+ NO_UPDATE
130
+ };
131
+
132
+ public:
133
+ explicit RemoteBitrateEstimatorAbsSendTime(Listener* listener);
134
+
135
+ RemoteBitrateEstimatorAbsSendTime(const RemoteBitrateEstimatorAbsSendTime&) = delete;
136
+ RemoteBitrateEstimatorAbsSendTime& operator=(const RemoteBitrateEstimatorAbsSendTime&) = delete;
137
+
138
+ /**
139
+ * Feed a received RTP packet.
140
+ *
141
+ * @param packet - Received packet, which is ignored unless it carries the
142
+ * 'abs-send-time' extension.
143
+ * @param arrivalTimeUs - Instant the packet arrived.
144
+ * @param nowUs - Current instant, which is not the one above when packets
145
+ * are processed in batches.
146
+ */
147
+ void ReceiveRtpPacket(const RTC::RTP::Packet* packet, int64_t arrivalTimeUs, int64_t nowUs);
148
+
149
+ /**
150
+ * Feed the round trip time towards the senders, which bounds how often the
151
+ * estimation may be reduced.
152
+ */
153
+ void OnRttUpdate(int64_t avgRttUs);
154
+
155
+ /**
156
+ * Forget a stream, so that it no longer takes part in the estimation nor in
157
+ * the streams reported to the listener.
158
+ */
159
+ void RemoveStream(uint32_t ssrc);
160
+
161
+ /**
162
+ * Latest estimation of the incoming link (bps), or zero while there is
163
+ * none or no stream is active.
164
+ */
165
+ int64_t GetLatestEstimate() const;
166
+
167
+ private:
168
+ /**
169
+ * Whether the given send delta is close enough to the mean of the run being
170
+ * accumulated to belong to it.
171
+ */
172
+ static bool IsWithinClusterBounds(int64_t sendDeltaUs, const Cluster& clusterAggregate);
173
+
174
+ /**
175
+ * Close the run being accumulated and keep it, unless it is too short or
176
+ * covers no time at all.
177
+ */
178
+ static void MaybeAddCluster(const Cluster& clusterAggregate, std::list<Cluster>& clusters);
179
+
180
+ /**
181
+ * Split the probes seen so far into runs of similar send deltas.
182
+ */
183
+ std::list<Cluster> ComputeClusters() const;
184
+
185
+ /**
186
+ * The fastest run that looks like a burst that made it through, or none if
187
+ * no run does.
188
+ */
189
+ const Cluster* FindBestProbe(const std::list<Cluster>& clusters) const;
190
+
191
+ /**
192
+ * Look at the probes seen so far and take the rate of the best burst as the
193
+ * estimation, if it beats what is already known.
194
+ */
195
+ ProbeResult ProcessClusters(int64_t nowUs);
196
+
197
+ /**
198
+ * Whether the given rate says something that the current estimation does
199
+ * not already say.
200
+ */
201
+ bool IsBitrateImproving(int64_t probeBitrate) const;
202
+
203
+ /**
204
+ * Forget the streams that have been silent for too long, and start the
205
+ * delay based detection over when none is left.
206
+ */
207
+ void TimeoutStreams(int64_t nowUs);
208
+
209
+ private:
210
+ Listener* listener{ nullptr };
211
+ // Recreated whenever every stream times out, since the groups of a stream
212
+ // that is gone say nothing about the ones of whatever comes next.
213
+ std::unique_ptr<InterArrival> interArrival;
214
+ std::unique_ptr<OveruseEstimator> overuseEstimator;
215
+ OveruseDetector overuseDetector;
216
+ // Rate at which data is coming in, which is what bounds the estimation.
217
+ RTC::RateCalculator incomingRateCalculator;
218
+ // Whether the meter above has reported a rate at least once, so that a
219
+ // stream falling silent can be told apart from never having measured
220
+ // anything.
221
+ bool incomingBitrateInitialized{ false };
222
+ // Packets big enough to have been paced by the sender, kept while a burst
223
+ // is still being looked for.
224
+ std::list<Probe> probes;
225
+ // Instant of the first packet ever fed, which bounds how long bursts are
226
+ // looked for.
227
+ std::optional<int64_t> firstPacketTimeUs;
228
+ // Instant the listener was told about the estimation for the last time.
229
+ std::optional<int64_t> lastUpdateUs;
230
+ // Instant each stream was last seen at.
231
+ ankerl::unordered_dense::map<uint32_t, int64_t> ssrcs;
232
+ AimdRateControl remoteRateControl;
233
+ };
234
+ } // namespace BWE
235
+ } // namespace RTC
236
+
237
+ #endif