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
@@ -11,10 +11,12 @@
11
11
  #include "RTC/Consumer.hpp"
12
12
  #include "RTC/RTCP/FeedbackPs.hpp"
13
13
  #include "RTC/RTCP/FeedbackPsAfb.hpp"
14
+ #include "RTC/RTCP/FeedbackPsFir.hpp"
14
15
  #include "RTC/RTCP/FeedbackPsRemb.hpp"
15
16
  #include "RTC/RTCP/FeedbackRtpNack.hpp"
16
17
  #include "RTC/RTCP/FeedbackRtpTransport.hpp"
17
18
  #include "RTC/RTCP/XrDelaySinceLastRr.hpp"
19
+ #include "RTC/RTP/ProbationGenerator.hpp"
18
20
  #include "RTC/RtpDictionaries.hpp"
19
21
  #include "RTC/SCTP/association/Association.hpp"
20
22
  #include "RTC/SCTP/public/SctpOptions.hpp"
@@ -23,13 +25,27 @@
23
25
  #ifdef MS_RTC_LOGGER_RTP
24
26
  #include "RTC/RtcLogger.hpp"
25
27
  #endif
28
+ #ifndef MS_USE_BUILTIN_BWE
26
29
  #include <libwebrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h> // webrtc::RtpPacketSendInfo
30
+ #endif
27
31
  #include <array>
28
- #include <iterator> // std::ostream_iterator
29
- #include <map> // std::multimap
32
+ #include <limits> // std::numeric_limits
33
+ #include <map> // std::multimap
30
34
 
31
35
  namespace RTC
32
36
  {
37
+ /* Static. */
38
+
39
+ // Bitrate the outgoing target is never taken below (bps), whatever the API
40
+ // asks for.
41
+ static constexpr int64_t AbsoluteMinOutgoingBitrate{ 30000 };
42
+ // Highest bitrate the API may ask for (bps). The highest value an int64_t can
43
+ // hold is what the bandwidth estimators reserve to mean that there is no
44
+ // limit at all, so it cannot also mean a limit.
45
+ static constexpr uint64_t AbsoluteMaxBitrate{
46
+ static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) - 1
47
+ };
48
+
33
49
  /* Instance methods. */
34
50
 
35
51
  Transport::Transport(
@@ -57,7 +73,14 @@ namespace RTC
57
73
  auto initialAvailableOutgoingBitrate = options->initialAvailableOutgoingBitrate();
58
74
  initialAvailableOutgoingBitrate.has_value())
59
75
  {
60
- this->initialAvailableOutgoingBitrate = initialAvailableOutgoingBitrate.value();
76
+ if (initialAvailableOutgoingBitrate.value() > AbsoluteMaxBitrate)
77
+ {
78
+ MS_THROW_TYPE_ERROR(
79
+ "wrong initialAvailableOutgoingBitrate (must be <= %" PRIu64 ")", AbsoluteMaxBitrate);
80
+ }
81
+
82
+ this->initialAvailableOutgoingBitrate =
83
+ static_cast<int64_t>(initialAvailableOutgoingBitrate.value());
61
84
  }
62
85
 
63
86
  if (options->enableSctp())
@@ -84,7 +107,7 @@ namespace RTC
84
107
  }
85
108
 
86
109
  // Create the RTCP timer.
87
- this->rtcpTimer = this->shared->CreateTimer(this);
110
+ this->rtcpTimer = this->shared->CreateTimer(this, "transport-rtcp");
88
111
  }
89
112
 
90
113
  Transport::~Transport()
@@ -388,7 +411,7 @@ namespace RTC
388
411
  this->maxReceiveMessageSize,
389
412
  sctpParameters,
390
413
  this->sctpAssociation ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
391
- : flatbuffers::nullopt,
414
+ : flatbuffers::nullopt,
392
415
  sctpNegotiatedCapabilities,
393
416
  sctpListener,
394
417
  std::addressof(traceEventTypes));
@@ -399,7 +422,7 @@ namespace RTC
399
422
  {
400
423
  MS_TRACE();
401
424
 
402
- auto nowMs = this->shared->GetTimeMs();
425
+ const int64_t nowMs = this->shared->GetTimeMs();
403
426
 
404
427
  // Add sctpState.
405
428
  FBS::SctpAssociation::SctpState sctpState{ FBS::SctpAssociation::SctpState::NEW };
@@ -437,64 +460,86 @@ namespace RTC
437
460
  }
438
461
  }
439
462
 
463
+ #ifdef MS_USE_BUILTIN_BWE
464
+ // TODO: Take these from the built-in downlink and uplink BWE.
465
+ const flatbuffers::Optional<uint64_t> availableOutgoingBitrate{ flatbuffers::nullopt };
466
+ const flatbuffers::Optional<uint64_t> availableIncomingBitrate{ flatbuffers::nullopt };
467
+ const flatbuffers::Optional<double> rtpPacketLossReceived{ flatbuffers::nullopt };
468
+ const flatbuffers::Optional<double> rtpPacketLossSent{ flatbuffers::nullopt };
469
+ #else
470
+ const auto availableOutgoingBitrate =
471
+ this->tccClient ? flatbuffers::Optional<uint64_t>(
472
+ static_cast<uint64_t>(this->tccClient->GetAvailableBitrate()))
473
+ : flatbuffers::nullopt;
474
+ const auto availableIncomingBitrate =
475
+ this->tccServer ? flatbuffers::Optional<uint64_t>(
476
+ static_cast<uint64_t>(this->tccServer->GetAvailableBitrate()))
477
+ : flatbuffers::nullopt;
478
+ const auto rtpPacketLossReceived =
479
+ this->tccServer ? flatbuffers::Optional<double>(this->tccServer->GetPacketLoss())
480
+ : flatbuffers::nullopt;
481
+ const auto rtpPacketLossSent =
482
+ this->tccClient ? flatbuffers::Optional<double>(this->tccClient->GetPacketLoss())
483
+ : flatbuffers::nullopt;
484
+ #endif
485
+
440
486
  return FBS::Transport::CreateStatsDirect(
441
487
  builder,
442
488
  // transportId.
443
489
  this->id.c_str(),
444
490
  // timestamp.
445
- nowMs,
491
+ static_cast<uint64_t>(nowMs),
446
492
  // sctpState.
447
493
  this->sctpAssociation ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
448
- : flatbuffers::nullopt,
494
+ : flatbuffers::nullopt,
449
495
  // bytesReceived.
450
496
  this->recvTransmission.GetBytes(),
451
497
  // recvBitrate.
452
- this->recvTransmission.GetRate(nowMs),
498
+ static_cast<uint64_t>(this->recvTransmission.GetRate(nowMs)),
453
499
  // bytesSent.
454
500
  this->sendTransmission.GetBytes(),
455
501
  // sendBitrate.
456
- this->sendTransmission.GetRate(nowMs),
502
+ static_cast<uint64_t>(this->sendTransmission.GetRate(nowMs)),
457
503
  // rtpBytesReceived.
458
504
  this->recvRtpTransmission.GetBytes(),
459
505
  // rtpRecvBitrate.
460
- this->recvRtpTransmission.GetBitrate(nowMs),
506
+ static_cast<uint64_t>(this->recvRtpTransmission.GetBitrate(nowMs)),
461
507
  // rtpBytesSent.
462
508
  this->sendRtpTransmission.GetBytes(),
463
509
  // rtpSendBitrate.
464
- this->sendRtpTransmission.GetBitrate(nowMs),
510
+ static_cast<uint64_t>(this->sendRtpTransmission.GetBitrate(nowMs)),
465
511
  // rtxBytesReceived.
466
512
  this->recvRtxTransmission.GetBytes(),
467
513
  // rtxRecvBitrate.
468
- this->recvRtxTransmission.GetBitrate(nowMs),
514
+ static_cast<uint64_t>(this->recvRtxTransmission.GetBitrate(nowMs)),
469
515
  // rtxBytesSent.
470
516
  this->sendRtxTransmission.GetBytes(),
471
517
  // rtxSendBitrate.
472
- this->sendRtxTransmission.GetBitrate(nowMs),
518
+ static_cast<uint64_t>(this->sendRtxTransmission.GetBitrate(nowMs)),
473
519
  // probationBytesSent.
474
520
  this->sendProbationTransmission.GetBytes(),
475
521
  // probationSendBitrate.
476
- this->sendProbationTransmission.GetBitrate(nowMs),
522
+ static_cast<uint64_t>(this->sendProbationTransmission.GetBitrate(nowMs)),
477
523
  // availableOutgoingBitrate.
478
- this->tccClient ? flatbuffers::Optional<uint32_t>(this->tccClient->GetAvailableBitrate())
479
- : flatbuffers::nullopt,
524
+ availableOutgoingBitrate,
480
525
  // availableIncomingBitrate.
481
- this->tccServer ? flatbuffers::Optional<uint32_t>(this->tccServer->GetAvailableBitrate())
482
- : flatbuffers::nullopt,
526
+ availableIncomingBitrate,
483
527
  // maxIncomingBitrate.
484
- this->maxIncomingBitrate ? flatbuffers::Optional<uint32_t>(this->maxIncomingBitrate)
485
- : flatbuffers::nullopt,
528
+ this->maxIncomingBitrate > 0
529
+ ? flatbuffers::Optional<uint64_t>(static_cast<uint64_t>(this->maxIncomingBitrate))
530
+ : flatbuffers::nullopt,
486
531
  // maxOutgoingBitrate.
487
- this->maxOutgoingBitrate ? flatbuffers::Optional<uint32_t>(this->maxOutgoingBitrate)
488
- : flatbuffers::nullopt,
532
+ this->maxOutgoingBitrate > 0
533
+ ? flatbuffers::Optional<uint64_t>(static_cast<uint64_t>(this->maxOutgoingBitrate))
534
+ : flatbuffers::nullopt,
489
535
  // minOutgoingBitrate.
490
- this->minOutgoingBitrate ? flatbuffers::Optional<uint32_t>(this->minOutgoingBitrate)
491
- : flatbuffers::nullopt,
536
+ this->minOutgoingBitrate > 0
537
+ ? flatbuffers::Optional<uint64_t>(static_cast<uint64_t>(this->minOutgoingBitrate))
538
+ : flatbuffers::nullopt,
492
539
  // rtpPacketLossReceived.
493
- this->tccServer ? flatbuffers::Optional<double>(this->tccServer->GetPacketLoss())
494
- : flatbuffers::nullopt,
540
+ rtpPacketLossReceived,
495
541
  // rtpPacketLossSent.
496
- this->tccClient ? flatbuffers::Optional<double>(this->tccClient->GetPacketLoss())
497
- : flatbuffers::nullopt);
542
+ rtpPacketLossSent);
498
543
  }
499
544
 
500
545
  void Transport::HandleRequest(Channel::ChannelRequest* request)
@@ -507,16 +552,25 @@ namespace RTC
507
552
  {
508
553
  const auto* body = request->data->body_as<FBS::Transport::SetMaxIncomingBitrateRequest>();
509
554
 
510
- this->maxIncomingBitrate = body->maxIncomingBitrate();
555
+ if (body->maxIncomingBitrate() > AbsoluteMaxBitrate)
556
+ {
557
+ MS_THROW_TYPE_ERROR("bitrate must be <= %" PRIu64 " or 0 (unlimited)", AbsoluteMaxBitrate);
558
+ }
559
+
560
+ this->maxIncomingBitrate = static_cast<int64_t>(body->maxIncomingBitrate());
511
561
 
512
- MS_DEBUG_TAG(bwe, "maximum incoming bitrate set to %" PRIu32, this->maxIncomingBitrate);
562
+ MS_DEBUG_TAG(bwe, "maximum incoming bitrate set to %" PRIi64, this->maxIncomingBitrate);
513
563
 
514
564
  request->Accept();
515
565
 
566
+ #ifdef MS_USE_BUILTIN_BWE
567
+ // TODO: Pass maxIncomingBitrate to the built-in uplink BWE.
568
+ #else
516
569
  if (this->tccServer)
517
570
  {
518
571
  this->tccServer->SetMaxIncomingBitrate(this->maxIncomingBitrate);
519
572
  }
573
+ #endif
520
574
 
521
575
  break;
522
576
  }
@@ -524,21 +578,30 @@ namespace RTC
524
578
  case Channel::ChannelRequest::Method::TRANSPORT_SET_MAX_OUTGOING_BITRATE:
525
579
  {
526
580
  const auto* body = request->data->body_as<FBS::Transport::SetMaxOutgoingBitrateRequest>();
527
- const uint32_t bitrate = body->maxOutgoingBitrate();
528
581
 
529
- if (bitrate > 0u && bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
582
+ if (body->maxOutgoingBitrate() > AbsoluteMaxBitrate)
583
+ {
584
+ MS_THROW_TYPE_ERROR("bitrate must be <= %" PRIu64 " or 0 (unlimited)", AbsoluteMaxBitrate);
585
+ }
586
+
587
+ const auto bitrate = static_cast<int64_t>(body->maxOutgoingBitrate());
588
+
589
+ if (bitrate > 0 && bitrate < AbsoluteMinOutgoingBitrate)
530
590
  {
531
591
  MS_THROW_TYPE_ERROR(
532
- "bitrate must be >= %" PRIu32 " or 0 (unlimited)",
533
- RTC::TransportCongestionControlMinOutgoingBitrate);
592
+ "bitrate must be >= %" PRIi64 " or 0 (unlimited)", AbsoluteMinOutgoingBitrate);
534
593
  }
535
- else if (bitrate > 0u && bitrate < this->minOutgoingBitrate)
594
+ else if (bitrate > 0 && bitrate < this->minOutgoingBitrate)
536
595
  {
537
596
  MS_THROW_TYPE_ERROR(
538
- "bitrate must be >= current min outgoing bitrate (%" PRIu32 ") or 0 (unlimited)",
597
+ "bitrate must be >= current min outgoing bitrate (%" PRIi64 ") or 0 (unlimited)",
539
598
  this->minOutgoingBitrate);
540
599
  }
541
600
 
601
+ #ifdef MS_USE_BUILTIN_BWE
602
+ // TODO: Pass maxOutgoingBitrate to the built-in downlink BWE.
603
+ this->maxOutgoingBitrate = bitrate;
604
+ #else
542
605
  if (this->tccClient)
543
606
  {
544
607
  // NOTE: This may throw so don't update things before calling this
@@ -546,7 +609,7 @@ namespace RTC
546
609
  this->tccClient->SetMaxOutgoingBitrate(bitrate);
547
610
  this->maxOutgoingBitrate = bitrate;
548
611
 
549
- MS_DEBUG_TAG(bwe, "maximum outgoing bitrate set to %" PRIu32, this->maxOutgoingBitrate);
612
+ MS_DEBUG_TAG(bwe, "maximum outgoing bitrate set to %" PRIi64, this->maxOutgoingBitrate);
550
613
 
551
614
  ComputeOutgoingDesiredBitrate();
552
615
  }
@@ -554,6 +617,7 @@ namespace RTC
554
617
  {
555
618
  this->maxOutgoingBitrate = bitrate;
556
619
  }
620
+ #endif
557
621
 
558
622
  request->Accept();
559
623
 
@@ -563,21 +627,30 @@ namespace RTC
563
627
  case Channel::ChannelRequest::Method::TRANSPORT_SET_MIN_OUTGOING_BITRATE:
564
628
  {
565
629
  const auto* body = request->data->body_as<FBS::Transport::SetMinOutgoingBitrateRequest>();
566
- const uint32_t bitrate = body->minOutgoingBitrate();
567
630
 
568
- if (bitrate > 0u && bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
631
+ if (body->minOutgoingBitrate() > AbsoluteMaxBitrate)
632
+ {
633
+ MS_THROW_TYPE_ERROR("bitrate must be <= %" PRIu64 " or 0 (unlimited)", AbsoluteMaxBitrate);
634
+ }
635
+
636
+ const auto bitrate = static_cast<int64_t>(body->minOutgoingBitrate());
637
+
638
+ if (bitrate > 0 && bitrate < AbsoluteMinOutgoingBitrate)
569
639
  {
570
640
  MS_THROW_TYPE_ERROR(
571
- "bitrate must be >= %" PRIu32 " or 0 (unlimited)",
572
- RTC::TransportCongestionControlMinOutgoingBitrate);
641
+ "bitrate must be >= %" PRIi64 " or 0 (unlimited)", AbsoluteMinOutgoingBitrate);
573
642
  }
574
- else if (bitrate > 0u && this->maxOutgoingBitrate > 0 && bitrate > this->maxOutgoingBitrate)
643
+ else if (bitrate > 0 && this->maxOutgoingBitrate > 0 && bitrate > this->maxOutgoingBitrate)
575
644
  {
576
645
  MS_THROW_TYPE_ERROR(
577
- "bitrate must be <= current max outgoing bitrate (%" PRIu32 ") or 0 (unlimited)",
646
+ "bitrate must be <= current max outgoing bitrate (%" PRIi64 ") or 0 (unlimited)",
578
647
  this->maxOutgoingBitrate);
579
648
  }
580
649
 
650
+ #ifdef MS_USE_BUILTIN_BWE
651
+ // TODO: Pass minOutgoingBitrate to the built-in downlink BWE.
652
+ this->minOutgoingBitrate = bitrate;
653
+ #else
581
654
  if (this->tccClient)
582
655
  {
583
656
  // NOTE: This may throw so don't update things before calling this
@@ -585,7 +658,7 @@ namespace RTC
585
658
  this->tccClient->SetMinOutgoingBitrate(bitrate);
586
659
  this->minOutgoingBitrate = bitrate;
587
660
 
588
- MS_DEBUG_TAG(bwe, "minimum outgoing bitrate set to %" PRIu32, this->minOutgoingBitrate);
661
+ MS_DEBUG_TAG(bwe, "minimum outgoing bitrate set to %" PRIi64, this->minOutgoingBitrate);
589
662
 
590
663
  ComputeOutgoingDesiredBitrate();
591
664
  }
@@ -593,6 +666,7 @@ namespace RTC
593
666
  {
594
667
  this->minOutgoingBitrate = bitrate;
595
668
  }
669
+ #endif
596
670
 
597
671
  request->Accept();
598
672
 
@@ -703,6 +777,10 @@ namespace RTC
703
777
 
704
778
  request->Accept(FBS::Response::Body::Transport_ProduceResponse, responseOffset);
705
779
 
780
+ #ifdef MS_USE_BUILTIN_BWE
781
+ // TODO: Create the built-in uplink BWE here, choosing transport-cc or
782
+ // REMB out of the Producer RTP header extensions and RTCP feedback.
783
+ #else
706
784
  // Check if TransportCongestionControlServer or REMB server must be
707
785
  // created.
708
786
  const auto& rtpHeaderExtensionIds = producer->GetRtpHeaderExtensionIds();
@@ -780,6 +858,7 @@ namespace RTC
780
858
  }
781
859
  }
782
860
  }
861
+ #endif
783
862
 
784
863
  break;
785
864
  }
@@ -846,6 +925,11 @@ namespace RTC
846
925
 
847
926
  request->Accept(FBS::Response::Body::Transport_ConsumeResponse, responseOffset);
848
927
 
928
+ #ifdef MS_USE_BUILTIN_BWE
929
+ // TODO: Create the built-in downlink BWE here, choosing transport-cc or
930
+ // REMB out of the Consumer RTP header extensions and RTCP feedback, and
931
+ // tell every Consumer that we manage its bitrate.
932
+ #else
849
933
  // Check if Transport Congestion Control client must be created.
850
934
  const auto& rtpHeaderExtensionIds = consumer->GetRtpHeaderExtensionIds();
851
935
  const auto& codecs = consumer->GetRtpParameters().codecs;
@@ -925,6 +1009,7 @@ namespace RTC
925
1009
  this,
926
1010
  this->shared,
927
1011
  bweType,
1012
+ AbsoluteMinOutgoingBitrate,
928
1013
  this->initialAvailableOutgoingBitrate,
929
1014
  this->maxOutgoingBitrate,
930
1015
  this->minOutgoingBitrate);
@@ -942,56 +1027,6 @@ namespace RTC
942
1027
  {
943
1028
  consumer->SetExternallyManagedBitrate();
944
1029
  }
945
-
946
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
947
- // Create SenderBandwidthEstimator if:
948
- // - not already created,
949
- // - it's a video Consumer, and
950
- // - there is transport-wide-cc-01 RTP header extension, and
951
- // - there is "transport-cc" in codecs RTCP feedback.
952
- //
953
- if (
954
- !this->senderBwe && consumer->GetKind() == RTC::Media::Kind::VIDEO &&
955
- rtpHeaderExtensionIds.transportWideCc01 != 0u &&
956
- std::any_of(
957
- codecs.begin(),
958
- codecs.end(),
959
- [](const RTC::RtpCodecParameters& codec)
960
- {
961
- return std::any_of(
962
- codec.rtcpFeedback.begin(),
963
- codec.rtcpFeedback.end(),
964
- [](const RTC::RtcpFeedback& fb)
965
- {
966
- return fb.type == "transport-cc";
967
- });
968
- }))
969
- {
970
- MS_DEBUG_TAG(bwe, "enabling SenderBandwidthEstimator");
971
-
972
- // Tell all the Consumers that we are gonna manage their bitrate.
973
- for (auto& kv : this->mapConsumers)
974
- {
975
- auto* consumer = kv.second;
976
-
977
- consumer->SetExternallyManagedBitrate();
978
- };
979
-
980
- this->senderBwe = std::make_shared<RTC::SenderBandwidthEstimator>(
981
- this, this->shared, this->initialAvailableOutgoingBitrate);
982
-
983
- if (IsConnected())
984
- {
985
- this->senderBwe->TransportConnected();
986
- }
987
- }
988
-
989
- // If applicable, tell the new Consumer that we are gonna manage its
990
- // bitrate.
991
- if (this->senderBwe)
992
- {
993
- consumer->SetExternallyManagedBitrate();
994
- }
995
1030
  #endif
996
1031
 
997
1032
  if (IsConnected())
@@ -1347,10 +1382,14 @@ namespace RTC
1347
1382
 
1348
1383
  // This may be the latest active Consumer with BWE. If so we have to stop
1349
1384
  // probation.
1385
+ #ifdef MS_USE_BUILTIN_BWE
1386
+ // TODO: Do it when the built-in downlink BWE is in place.
1387
+ #else
1350
1388
  if (this->tccClient)
1351
1389
  {
1352
1390
  ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true);
1353
1391
  }
1392
+ #endif
1354
1393
 
1355
1394
  break;
1356
1395
  }
@@ -1468,7 +1507,7 @@ namespace RTC
1468
1507
  {
1469
1508
  MS_TRACE();
1470
1509
 
1471
- switch (notification->event)
1510
+ switch (notification->data->event())
1472
1511
  {
1473
1512
  default:
1474
1513
  {
@@ -1512,8 +1551,11 @@ namespace RTC
1512
1551
  }
1513
1552
 
1514
1553
  // Start the RTCP timer.
1515
- this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2));
1554
+ this->rtcpTimer->Start(RTC::RTCP::MaxVideoIntervalMs / 2);
1516
1555
 
1556
+ #ifdef MS_USE_BUILTIN_BWE
1557
+ // TODO: Tell the built-in downlink and uplink BWE.
1558
+ #else
1517
1559
  // Tell the TransportCongestionControlClient.
1518
1560
  if (this->tccClient)
1519
1561
  {
@@ -1525,13 +1567,6 @@ namespace RTC
1525
1567
  {
1526
1568
  this->tccServer->TransportConnected();
1527
1569
  }
1528
-
1529
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
1530
- // Tell the SenderBandwidthEstimator.
1531
- if (this->senderBwe)
1532
- {
1533
- this->senderBwe->TransportConnected();
1534
- }
1535
1570
  #endif
1536
1571
  }
1537
1572
 
@@ -1550,6 +1585,9 @@ namespace RTC
1550
1585
  // Stop the RTCP timer.
1551
1586
  this->rtcpTimer->Stop();
1552
1587
 
1588
+ #ifdef MS_USE_BUILTIN_BWE
1589
+ // TODO: Tell the built-in downlink and uplink BWE.
1590
+ #else
1553
1591
  // Tell the TransportCongestionControlClient.
1554
1592
  if (this->tccClient)
1555
1593
  {
@@ -1561,17 +1599,10 @@ namespace RTC
1561
1599
  {
1562
1600
  this->tccServer->TransportDisconnected();
1563
1601
  }
1564
-
1565
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
1566
- // Tell the SenderBandwidthEstimator.
1567
- if (this->senderBwe)
1568
- {
1569
- this->senderBwe->TransportDisconnected();
1570
- }
1571
1602
  #endif
1572
1603
  }
1573
1604
 
1574
- void Transport::ReceiveRtpPacket(RTC::RTP::Packet* packet)
1605
+ void Transport::ReceiveRtpPacket(RTC::RTP::Packet* packet, int64_t receivedAtUs)
1575
1606
  {
1576
1607
  MS_TRACE();
1577
1608
 
@@ -1583,13 +1614,15 @@ namespace RTC
1583
1614
  // them.
1584
1615
  packet->AssignExtensionIds(this->recvRtpHeaderExtensionIds);
1585
1616
 
1586
- auto nowMs = this->shared->GetTimeMs();
1587
-
1617
+ #ifdef MS_USE_BUILTIN_BWE
1618
+ // TODO: Feed the built-in uplink BWE.
1619
+ #else
1588
1620
  // Feed the TransportCongestionControlServer.
1589
1621
  if (this->tccServer)
1590
1622
  {
1591
- this->tccServer->IncomingPacket(nowMs, packet);
1623
+ this->tccServer->IncomingPacket(receivedAtUs, packet);
1592
1624
  }
1625
+ #endif
1593
1626
 
1594
1627
  // Get the associated Producer.
1595
1628
  RTC::Producer* producer = this->rtpListener.GetProducer(packet);
@@ -1621,7 +1654,7 @@ namespace RTC
1621
1654
  // producer->id.c_str());
1622
1655
 
1623
1656
  // Pass the RTP packet to the corresponding Producer.
1624
- auto result = producer->ReceiveRtpPacket(packet);
1657
+ auto result = producer->ReceiveRtpPacket(packet, receivedAtUs);
1625
1658
 
1626
1659
  switch (result)
1627
1660
  {
@@ -1650,14 +1683,14 @@ namespace RTC
1650
1683
  delete packet;
1651
1684
  }
1652
1685
 
1653
- void Transport::ReceiveRtcpPacket(RTC::RTCP::Packet* packet)
1686
+ void Transport::ReceiveRtcpPacket(RTC::RTCP::Packet* packet, int64_t receivedAtUs)
1654
1687
  {
1655
1688
  MS_TRACE();
1656
1689
 
1657
1690
  // Handle each RTCP packet.
1658
1691
  while (packet)
1659
1692
  {
1660
- HandleRtcpPacket(packet);
1693
+ HandleRtcpPacket(packet, receivedAtUs);
1661
1694
 
1662
1695
  auto* previousPacket = packet;
1663
1696
 
@@ -1667,7 +1700,7 @@ namespace RTC
1667
1700
  }
1668
1701
  }
1669
1702
 
1670
- void Transport::ReceiveSctpData(const uint8_t* data, size_t len)
1703
+ void Transport::ReceiveSctpData(const uint8_t* data, size_t len, int64_t receivedAtUs)
1671
1704
  {
1672
1705
  MS_TRACE();
1673
1706
 
@@ -1679,7 +1712,7 @@ namespace RTC
1679
1712
  }
1680
1713
 
1681
1714
  // Pass it to the SctpAssociation.
1682
- this->sctpAssociation->ReceiveSctpData(data, len);
1715
+ this->sctpAssociation->ReceiveSctpData(data, len, receivedAtUs);
1683
1716
  }
1684
1717
 
1685
1718
  void Transport::SendSctpMessage(
@@ -1708,7 +1741,7 @@ namespace RTC
1708
1741
  .unordered = !sctpStreamParameters.ordered,
1709
1742
  .lifetimeMs = sctpStreamParameters.ordered
1710
1743
  ? std::nullopt
1711
- : std::optional<uint64_t>(sctpStreamParameters.maxPacketLifeTime),
1744
+ : std::optional<int64_t>(sctpStreamParameters.maxPacketLifeTime),
1712
1745
  .maxRetransmissions = sctpStreamParameters.ordered
1713
1746
  ? std::nullopt
1714
1747
  : std::optional<uint64_t>(sctpStreamParameters.maxRetransmits),
@@ -1732,7 +1765,7 @@ namespace RTC
1732
1765
 
1733
1766
  case RTC::SCTP::Types::SendMessageStatus::ERROR_RESOURCE_EXHAUSTION:
1734
1767
  {
1735
- const auto sendStatusStringView = RTC::SCTP::Types::SendMessageStatusToString(sendStatus);
1768
+ const auto sendStatusStringView = RTC::SCTP::Types::sendMessageStatusToString(sendStatus);
1736
1769
 
1737
1770
  MS_WARN_TAG(
1738
1771
  sctp,
@@ -1752,7 +1785,7 @@ namespace RTC
1752
1785
 
1753
1786
  default:
1754
1787
  {
1755
- const auto sendStatusStringView = RTC::SCTP::Types::SendMessageStatusToString(sendStatus);
1788
+ const auto sendStatusStringView = RTC::SCTP::Types::sendMessageStatusToString(sendStatus);
1756
1789
 
1757
1790
  MS_WARN_TAG(
1758
1791
  sctp,
@@ -1933,7 +1966,7 @@ namespace RTC
1933
1966
  }
1934
1967
  }
1935
1968
 
1936
- void Transport::HandleRtcpPacket(RTC::RTCP::Packet* packet)
1969
+ void Transport::HandleRtcpPacket(RTC::RTCP::Packet* packet, int64_t receivedAtUs)
1937
1970
  {
1938
1971
  MS_TRACE();
1939
1972
 
@@ -1970,12 +2003,15 @@ namespace RTC
1970
2003
  continue;
1971
2004
  }
1972
2005
 
1973
- consumer->ReceiveRtcpReceiverReport(report);
2006
+ consumer->ReceiveRtcpReceiverReport(report, receivedAtUs);
1974
2007
  }
1975
2008
 
2009
+ #ifdef MS_USE_BUILTIN_BWE
2010
+ // TODO: Feed the Receiver Report to the built-in downlink BWE.
2011
+ #else
1976
2012
  if (this->tccClient && !this->mapConsumers.empty())
1977
2013
  {
1978
- float rtt = 0;
2014
+ float rttMs = 0;
1979
2015
 
1980
2016
  // Retrieve the RTT from the first active consumer.
1981
2017
  for (auto& kv : this->mapConsumers)
@@ -1984,14 +2020,15 @@ namespace RTC
1984
2020
 
1985
2021
  if (consumer->IsActive())
1986
2022
  {
1987
- rtt = consumer->GetRtt();
2023
+ rttMs = consumer->GetRttMs();
1988
2024
 
1989
2025
  break;
1990
2026
  }
1991
2027
  }
1992
2028
 
1993
- this->tccClient->ReceiveRtcpReceiverReport(rr, rtt, this->shared->GetTimeMsInt64());
2029
+ this->tccClient->ReceiveRtcpReceiverReport(rr, rttMs, receivedAtUs);
1994
2030
  }
2031
+ #endif
1995
2032
 
1996
2033
  break;
1997
2034
  }
@@ -2085,11 +2122,16 @@ namespace RTC
2085
2122
  {
2086
2123
  auto* remb = static_cast<RTC::RTCP::FeedbackPsRembPacket*>(afb);
2087
2124
 
2125
+ #ifdef MS_USE_BUILTIN_BWE
2126
+ // TODO: Pass the REMB bitrate to the built-in downlink BWE.
2127
+ (void)remb;
2128
+ #else
2088
2129
  // Pass it to the TCC client.
2089
2130
  if (this->tccClient && this->tccClient->GetBweType() == RTC::BweType::REMB)
2090
2131
  {
2091
2132
  this->tccClient->ReceiveEstimatedBitrate(remb->GetBitrate());
2092
2133
  }
2134
+ #endif
2093
2135
 
2094
2136
  break;
2095
2137
  }
@@ -2132,7 +2174,7 @@ namespace RTC
2132
2174
  if (
2133
2175
  !consumer && feedback->GetMessageType() != RTC::RTCP::FeedbackRtp::MessageType::TCC &&
2134
2176
  (feedback->GetMediaSsrc() != RTC::RTP::ProbationGenerator::Ssrc ||
2135
- !GetConsumerByRtxSsrc(feedback->GetMediaSsrc())))
2177
+ !GetConsumerByRtxSsrc(feedback->GetMediaSsrc())))
2136
2178
  {
2137
2179
  MS_DEBUG_TAG(
2138
2180
  rtcp,
@@ -2171,17 +2213,14 @@ namespace RTC
2171
2213
  {
2172
2214
  auto* feedback = static_cast<RTC::RTCP::FeedbackRtpTransportPacket*>(packet);
2173
2215
 
2216
+ #ifdef MS_USE_BUILTIN_BWE
2217
+ // TODO: Feed the transport-cc feedback to the built-in downlink BWE.
2218
+ (void)feedback;
2219
+ #else
2174
2220
  if (this->tccClient)
2175
2221
  {
2176
2222
  this->tccClient->ReceiveRtcpTransportFeedback(feedback);
2177
2223
  }
2178
-
2179
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
2180
- // Pass it to the SenderBandwidthEstimator client.
2181
- if (this->senderBwe)
2182
- {
2183
- this->senderBwe->ReceiveRtcpTransportFeedback(feedback);
2184
- }
2185
2224
  #endif
2186
2225
 
2187
2226
  break;
@@ -2222,7 +2261,7 @@ namespace RTC
2222
2261
  continue;
2223
2262
  }
2224
2263
 
2225
- producer->ReceiveRtcpSenderReport(report);
2264
+ producer->ReceiveRtcpSenderReport(report, receivedAtUs);
2226
2265
  }
2227
2266
 
2228
2267
  break;
@@ -2283,7 +2322,7 @@ namespace RTC
2283
2322
  continue;
2284
2323
  }
2285
2324
 
2286
- producer->ReceiveRtcpXrDelaySinceLastRr(ssrcInfo);
2325
+ producer->ReceiveRtcpXrDelaySinceLastRr(ssrcInfo, receivedAtUs);
2287
2326
  }
2288
2327
 
2289
2328
  break;
@@ -2297,7 +2336,7 @@ namespace RTC
2297
2336
  {
2298
2337
  auto* consumer = kv.second;
2299
2338
 
2300
- consumer->ReceiveRtcpXrReceiverReferenceTime(rrt);
2339
+ consumer->ReceiveRtcpXrReceiverReferenceTime(rrt, receivedAtUs);
2301
2340
  }
2302
2341
 
2303
2342
  break;
@@ -2320,7 +2359,7 @@ namespace RTC
2320
2359
  }
2321
2360
  }
2322
2361
 
2323
- void Transport::SendRtcp(uint64_t nowMs)
2362
+ void Transport::SendRtcp(int64_t nowUs)
2324
2363
  {
2325
2364
  MS_TRACE();
2326
2365
 
@@ -2329,7 +2368,7 @@ namespace RTC
2329
2368
  for (auto& kv : this->mapConsumers)
2330
2369
  {
2331
2370
  auto* consumer = kv.second;
2332
- auto rtcpAdded = consumer->GetRtcp(packet.get(), nowMs);
2371
+ auto rtcpAdded = consumer->GetRtcp(packet.get(), nowUs);
2333
2372
 
2334
2373
  // RTCP data couldn't be added because the Compound packet is full.
2335
2374
  // Send the RTCP compound packet and request for RTCP again.
@@ -2341,14 +2380,14 @@ namespace RTC
2341
2380
  packet.reset(new RTC::RTCP::CompoundPacket());
2342
2381
 
2343
2382
  // Retrieve the RTCP again.
2344
- consumer->GetRtcp(packet.get(), nowMs);
2383
+ consumer->GetRtcp(packet.get(), nowUs);
2345
2384
  }
2346
2385
  }
2347
2386
 
2348
2387
  for (auto& kv : this->mapProducers)
2349
2388
  {
2350
2389
  auto* producer = kv.second;
2351
- auto rtcpAdded = producer->GetRtcp(packet.get(), nowMs);
2390
+ auto rtcpAdded = producer->GetRtcp(packet.get(), nowUs);
2352
2391
 
2353
2392
  // RTCP data couldn't be added because the Compound packet is full.
2354
2393
  // Send the RTCP compound packet and request for RTCP again.
@@ -2360,7 +2399,7 @@ namespace RTC
2360
2399
  packet.reset(new RTC::RTCP::CompoundPacket());
2361
2400
 
2362
2401
  // Retrieve the RTCP again.
2363
- producer->GetRtcp(packet.get(), nowMs);
2402
+ producer->GetRtcp(packet.get(), nowUs);
2364
2403
  }
2365
2404
  }
2366
2405
 
@@ -2375,6 +2414,9 @@ namespace RTC
2375
2414
  {
2376
2415
  MS_TRACE();
2377
2416
 
2417
+ #ifdef MS_USE_BUILTIN_BWE
2418
+ // TODO: Distribute the bitrate the built-in downlink BWE reports.
2419
+ #else
2378
2420
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2379
2421
 
2380
2422
  std::multimap<uint8_t, RTC::Consumer*> multimapPriorityConsumer;
@@ -2397,18 +2439,18 @@ namespace RTC
2397
2439
  return;
2398
2440
  }
2399
2441
 
2400
- bool baseAllocation = true;
2401
- uint32_t availableBitrate = this->tccClient->GetAvailableBitrate();
2442
+ bool baseAllocation = true;
2443
+ int64_t availableBitrate = this->tccClient->GetAvailableBitrate();
2402
2444
 
2403
2445
  this->tccClient->RescheduleNextAvailableBitrateEvent();
2404
2446
 
2405
- MS_DEBUG_DEV("before layer-by-layer iterations [availableBitrate:%" PRIu32 "]", availableBitrate);
2447
+ MS_DEBUG_DEV("before layer-by-layer iterations [availableBitrate:%" PRIi64 "]", availableBitrate);
2406
2448
 
2407
2449
  // Redistribute the available bitrate by allowing Consumers to increase
2408
2450
  // layer by layer. Initially try to spread the bitrate across all
2409
2451
  // consumers. Then allocate the excess bitrate to Consumers starting
2410
2452
  // with the highest priorty.
2411
- while (availableBitrate > 0u)
2453
+ while (availableBitrate > 0)
2412
2454
  {
2413
2455
  auto previousAvailableBitrate = availableBitrate;
2414
2456
 
@@ -2421,17 +2463,15 @@ namespace RTC
2421
2463
  // NOLINTNEXTLINE(bugprone-too-small-loop-variable)
2422
2464
  for (uint8_t i{ 1u }; i <= (baseAllocation ? 1u : priority); ++i)
2423
2465
  {
2424
- uint32_t usedBitrate{ 0u };
2425
- const bool considerLoss = (bweType == RTC::BweType::REMB);
2426
-
2427
- usedBitrate = consumer->IncreaseLayer(availableBitrate, considerLoss);
2466
+ const bool considerLoss = (bweType == RTC::BweType::REMB);
2467
+ const int64_t usedBitrate = consumer->IncreaseLayer(availableBitrate, considerLoss);
2428
2468
 
2429
2469
  MS_ASSERT(usedBitrate <= availableBitrate, "Consumer used more layer bitrate than given");
2430
2470
 
2431
2471
  availableBitrate -= usedBitrate;
2432
2472
 
2433
- // Exit the loop fast if used bitrate is 0.
2434
- if (usedBitrate == 0u)
2473
+ // Exit the loop fast if no bitrate was used.
2474
+ if (usedBitrate <= 0)
2435
2475
  {
2436
2476
  break;
2437
2477
  }
@@ -2447,7 +2487,7 @@ namespace RTC
2447
2487
  baseAllocation = false;
2448
2488
  }
2449
2489
 
2450
- MS_DEBUG_DEV("after layer-by-layer iterations [availableBitrate:%" PRIu32 "]", availableBitrate);
2490
+ MS_DEBUG_DEV("after layer-by-layer iterations [availableBitrate:%" PRIi64 "]", availableBitrate);
2451
2491
 
2452
2492
  // Finally instruct Consumers to apply their computed layers.
2453
2493
  for (auto it = multimapPriorityConsumer.rbegin(); it != multimapPriorityConsumer.rend(); ++it)
@@ -2456,15 +2496,20 @@ namespace RTC
2456
2496
 
2457
2497
  consumer->ApplyLayers();
2458
2498
  }
2499
+ #endif
2459
2500
  }
2460
2501
 
2461
2502
  void Transport::ComputeOutgoingDesiredBitrate(bool forceBitrate)
2462
2503
  {
2463
2504
  MS_TRACE();
2464
2505
 
2506
+ #ifdef MS_USE_BUILTIN_BWE
2507
+ // TODO: Give the total desired bitrate to the built-in downlink BWE.
2508
+ (void)forceBitrate;
2509
+ #else
2465
2510
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2466
2511
 
2467
- uint32_t totalDesiredBitrate{ 0u };
2512
+ int64_t totalDesiredBitrate{ 0 };
2468
2513
 
2469
2514
  for (auto& kv : this->mapConsumers)
2470
2515
  {
@@ -2474,9 +2519,10 @@ namespace RTC
2474
2519
  totalDesiredBitrate += desiredBitrate;
2475
2520
  }
2476
2521
 
2477
- MS_DEBUG_DEV("total desired bitrate: %" PRIu32, totalDesiredBitrate);
2522
+ MS_DEBUG_DEV("total desired bitrate: %" PRIi64, totalDesiredBitrate);
2478
2523
 
2479
2524
  this->tccClient->SetDesiredBitrate(totalDesiredBitrate, forceBitrate);
2525
+ #endif
2480
2526
  }
2481
2527
 
2482
2528
  inline void Transport::EmitTraceEventProbationType(RTC::RTP::Packet* /*packet*/) const
@@ -2492,7 +2538,7 @@ namespace RTC
2492
2538
  auto notification = FBS::Transport::CreateTraceNotification(
2493
2539
  this->shared->GetChannelNotifier()->GetBufferBuilder(),
2494
2540
  FBS::Transport::TraceEventType::PROBATION,
2495
- this->shared->GetTimeMs(),
2541
+ static_cast<uint64_t>(this->shared->GetTimeMs()),
2496
2542
  FBS::Common::TraceDirection::DIRECTION_OUT);
2497
2543
 
2498
2544
  this->shared->GetChannelNotifier()->Emit(
@@ -2502,6 +2548,7 @@ namespace RTC
2502
2548
  notification);
2503
2549
  }
2504
2550
 
2551
+ #ifndef MS_USE_BUILTIN_BWE
2505
2552
  inline void Transport::EmitTraceEventBweType(
2506
2553
  RTC::TransportCongestionControlClient::Bitrates& bitrates) const
2507
2554
  {
@@ -2517,18 +2564,18 @@ namespace RTC
2517
2564
  this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC
2518
2565
  ? FBS::Transport::BweType::TRANSPORT_CC
2519
2566
  : FBS::Transport::BweType::REMB,
2520
- bitrates.desiredBitrate,
2521
- bitrates.effectiveDesiredBitrate,
2522
- bitrates.minBitrate,
2523
- bitrates.maxBitrate,
2524
- bitrates.startBitrate,
2525
- bitrates.maxPaddingBitrate,
2526
- bitrates.availableBitrate);
2567
+ static_cast<uint64_t>(bitrates.desiredBitrate),
2568
+ static_cast<uint64_t>(bitrates.effectiveDesiredBitrate),
2569
+ static_cast<uint64_t>(bitrates.minBitrate),
2570
+ static_cast<uint64_t>(bitrates.maxBitrate),
2571
+ static_cast<uint64_t>(bitrates.startBitrate),
2572
+ static_cast<uint64_t>(bitrates.maxPaddingBitrate),
2573
+ static_cast<uint64_t>(bitrates.availableBitrate));
2527
2574
 
2528
2575
  auto notification = FBS::Transport::CreateTraceNotification(
2529
2576
  this->shared->GetChannelNotifier()->GetBufferBuilder(),
2530
2577
  FBS::Transport::TraceEventType::BWE,
2531
- this->shared->GetTimeMs(),
2578
+ static_cast<uint64_t>(this->shared->GetTimeMs()),
2532
2579
  FBS::Common::TraceDirection::DIRECTION_OUT,
2533
2580
  FBS::Transport::TraceInfo::BweTraceInfo,
2534
2581
  traceInfo.Union());
@@ -2539,6 +2586,7 @@ namespace RTC
2539
2586
  FBS::Notification::Body::Transport_TraceNotification,
2540
2587
  notification);
2541
2588
  }
2589
+ #endif
2542
2590
 
2543
2591
  void Transport::OnProducerPaused(RTC::Producer* producer)
2544
2592
  {
@@ -2589,6 +2637,15 @@ namespace RTC
2589
2637
  this->listener->OnTransportProducerRtcpSenderReport(this, producer, rtpStream, first);
2590
2638
  }
2591
2639
 
2640
+ void Transport::OnProducerSpatialLayerActivityChanged(
2641
+ RTC::Producer* producer, RTC::RTP::RtpStreamRecv* rtpStream, uint8_t spatialLayer, bool isActive)
2642
+ {
2643
+ MS_TRACE();
2644
+
2645
+ this->listener->OnTransportProducerSpatialLayerActivityChanged(
2646
+ this, producer, rtpStream, spatialLayer, isActive);
2647
+ }
2648
+
2592
2649
  void Transport::OnProducerRtpPacketReceived(RTC::Producer* producer, RTC::RTP::Packet* packet)
2593
2650
  {
2594
2651
  MS_TRACE();
@@ -2610,7 +2667,7 @@ namespace RTC
2610
2667
  return this->listener->OnTransportNeedWorstRemoteFractionLost(this, producer, mappedSsrc);
2611
2668
  }
2612
2669
 
2613
- std::optional<uint64_t> Transport::OnProducerNeedLocalCaptureMs(
2670
+ std::optional<int64_t> Transport::OnProducerNeedLocalCaptureAtUs(
2614
2671
  RTC::Producer* producer, const RTC::RTP::RtpStreamRecv* rtpStream, uint32_t ts)
2615
2672
  {
2616
2673
  MS_TRACE();
@@ -2625,10 +2682,10 @@ namespace RTC
2625
2682
 
2626
2683
  const auto& remoteCaptureTimeEstimator = it->second;
2627
2684
 
2628
- return remoteCaptureTimeEstimator.GetLocalCaptureMs(rtpStream, ts);
2685
+ return remoteCaptureTimeEstimator.GetLocalCaptureAtUs(rtpStream, ts);
2629
2686
  }
2630
2687
 
2631
- std::optional<int64_t> Transport::OnProducerNeedRemoteClockOffsetMs(const RTC::Producer* producer)
2688
+ std::optional<int64_t> Transport::OnProducerNeedRemoteClockOffsetUs(const RTC::Producer* producer)
2632
2689
  {
2633
2690
  MS_TRACE();
2634
2691
 
@@ -2641,9 +2698,9 @@ namespace RTC
2641
2698
  }
2642
2699
 
2643
2700
  const auto& remoteCaptureTimeEstimator = it->second;
2644
- const auto clockOffsetMs = remoteCaptureTimeEstimator.GetClockOffsetMs();
2701
+ const auto clockOffsetUs = remoteCaptureTimeEstimator.GetClockOffsetUs();
2645
2702
 
2646
- if (!clockOffsetMs.has_value())
2703
+ if (!clockOffsetUs.has_value())
2647
2704
  {
2648
2705
  return std::nullopt;
2649
2706
  }
@@ -2651,9 +2708,9 @@ namespace RTC
2651
2708
  // NOTE: The estimator gives the offset against our own monotonic clock, while what
2652
2709
  // a receiver reconstructs out of the Sender Reports we send is the clock we
2653
2710
  // announce, so the distance to the NTP epoch has to be taken into account. Both
2654
- // terms are huge and their sum is small, so they are added as milliseconds before
2711
+ // terms are huge and their sum is small, so they are added as microseconds before
2655
2712
  // anything scales them up.
2656
- return clockOffsetMs.value() + static_cast<int64_t>(this->shared->GetNtpOffsetMs());
2713
+ return clockOffsetUs.value() + this->shared->GetNtpOffsetUs();
2657
2714
  }
2658
2715
 
2659
2716
  void Transport::OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RTP::Packet* packet)
@@ -2666,8 +2723,13 @@ namespace RTC
2666
2723
  #endif
2667
2724
 
2668
2725
  // Update abs-send-time if present.
2669
- packet->UpdateAbsSendTime(this->shared->GetTimeMs());
2726
+ packet->UpdateAbsSendTime(this->shared->GetTimeUs());
2670
2727
 
2728
+ #ifdef MS_USE_BUILTIN_BWE
2729
+ // TODO: Write the transport wide sequence number the built-in downlink BWE
2730
+ // hands out and register the send in it.
2731
+ SendRtpPacket(consumer, packet);
2732
+ #else
2671
2733
  // Update transport wide sequence number if present.
2672
2734
  if (
2673
2735
  this->tccClient && this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC &&
@@ -2696,38 +2758,6 @@ namespace RTC
2696
2758
 
2697
2759
  auto* shared = this->shared;
2698
2760
 
2699
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
2700
- std::weak_ptr<RTC::SenderBandwidthEstimator> senderBweWeakPtr(this->senderBwe);
2701
- RTC::SenderBandwidthEstimator::SentInfo sentInfo;
2702
-
2703
- sentInfo.wideSeq = this->transportWideCcSeq;
2704
- sentInfo.size = packet->GetLength();
2705
- sentInfo.sendingAtMs = this->shared->GetTimeMs();
2706
-
2707
- const auto* cb = new onSendCallback(
2708
- [tccClientWeakPtr, shared, packetInfo, senderBweWeakPtr, sentInfo](bool sent) mutable
2709
- {
2710
- if (sent)
2711
- {
2712
- auto tccClient = tccClientWeakPtr.lock();
2713
-
2714
- if (tccClient)
2715
- {
2716
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2717
- }
2718
-
2719
- auto senderBwe = senderBweWeakPtr.lock();
2720
-
2721
- if (senderBwe)
2722
- {
2723
- sentInfo.sentAtMs = shared->GetTimeMs();
2724
- senderBwe->RtpPacketSent(sentInfo);
2725
- }
2726
- }
2727
- });
2728
-
2729
- SendRtpPacket(consumer, packet, cb);
2730
- #else
2731
2761
  const auto* cb = new onSendCallback(
2732
2762
  [tccClientWeakPtr, shared, packetInfo](bool sent)
2733
2763
  {
@@ -2737,18 +2767,18 @@ namespace RTC
2737
2767
 
2738
2768
  if (tccClient)
2739
2769
  {
2740
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2770
+ tccClient->PacketSent(packetInfo, shared->GetTimeUs());
2741
2771
  }
2742
2772
  }
2743
2773
  });
2744
2774
 
2745
2775
  SendRtpPacket(consumer, packet, cb);
2746
- #endif
2747
2776
  }
2748
2777
  else
2749
2778
  {
2750
2779
  SendRtpPacket(consumer, packet);
2751
2780
  }
2781
+ #endif
2752
2782
 
2753
2783
  this->sendRtpTransmission.Update(packet);
2754
2784
  }
@@ -2758,8 +2788,13 @@ namespace RTC
2758
2788
  MS_TRACE();
2759
2789
 
2760
2790
  // Update abs-send-time if present.
2761
- packet->UpdateAbsSendTime(this->shared->GetTimeMs());
2791
+ packet->UpdateAbsSendTime(this->shared->GetTimeUs());
2762
2792
 
2793
+ #ifdef MS_USE_BUILTIN_BWE
2794
+ // TODO: Write the transport wide sequence number the built-in downlink BWE
2795
+ // hands out and register the send in it.
2796
+ SendRtpPacket(consumer, packet);
2797
+ #else
2763
2798
  // Update transport wide sequence number if present.
2764
2799
  if (
2765
2800
  this->tccClient && this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC &&
@@ -2783,38 +2818,6 @@ namespace RTC
2783
2818
 
2784
2819
  auto* shared = this->shared;
2785
2820
 
2786
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
2787
- std::weak_ptr<RTC::SenderBandwidthEstimator> senderBweWeakPtr = this->senderBwe;
2788
- RTC::SenderBandwidthEstimator::SentInfo sentInfo;
2789
-
2790
- sentInfo.wideSeq = this->transportWideCcSeq;
2791
- sentInfo.size = packet->GetLength();
2792
- sentInfo.sendingAtMs = this->shared->GetTimeMs();
2793
-
2794
- const auto* cb = new onSendCallback(
2795
- [tccClientWeakPtr, shared, packetInfo, senderBweWeakPtr, sentInfo](bool sent) mutable
2796
- {
2797
- if (sent)
2798
- {
2799
- auto tccClient = tccClientWeakPtr.lock();
2800
-
2801
- if (tccClient)
2802
- {
2803
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2804
- }
2805
-
2806
- auto senderBwe = senderBweWeakPtr.lock();
2807
-
2808
- if (senderBwe)
2809
- {
2810
- sentInfo.sentAtMs = shared->GetTimeMs();
2811
- senderBwe->RtpPacketSent(sentInfo);
2812
- }
2813
- }
2814
- });
2815
-
2816
- SendRtpPacket(consumer, packet, cb);
2817
- #else
2818
2821
  const auto* cb = new onSendCallback(
2819
2822
  [tccClientWeakPtr, shared, packetInfo](bool sent)
2820
2823
  {
@@ -2824,18 +2827,18 @@ namespace RTC
2824
2827
 
2825
2828
  if (tccClient)
2826
2829
  {
2827
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2830
+ tccClient->PacketSent(packetInfo, shared->GetTimeUs());
2828
2831
  }
2829
2832
  }
2830
2833
  });
2831
2834
 
2832
2835
  SendRtpPacket(consumer, packet, cb);
2833
- #endif
2834
2836
  }
2835
2837
  else
2836
2838
  {
2837
2839
  SendRtpPacket(consumer, packet);
2838
2840
  }
2841
+ #endif
2839
2842
 
2840
2843
  this->sendRtxTransmission.Update(packet);
2841
2844
  }
@@ -2858,7 +2861,9 @@ namespace RTC
2858
2861
  {
2859
2862
  MS_TRACE();
2860
2863
 
2864
+ #ifndef MS_USE_BUILTIN_BWE
2861
2865
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2866
+ #endif
2862
2867
 
2863
2868
  DistributeAvailableOutgoingBitrate();
2864
2869
  ComputeOutgoingDesiredBitrate();
@@ -2868,7 +2873,9 @@ namespace RTC
2868
2873
  {
2869
2874
  MS_TRACE();
2870
2875
 
2876
+ #ifndef MS_USE_BUILTIN_BWE
2871
2877
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2878
+ #endif
2872
2879
 
2873
2880
  DistributeAvailableOutgoingBitrate();
2874
2881
 
@@ -2908,10 +2915,14 @@ namespace RTC
2908
2915
  delete consumer;
2909
2916
 
2910
2917
  // This may be the latest active Consumer with BWE. If so we have to stop probation.
2918
+ #ifdef MS_USE_BUILTIN_BWE
2919
+ // TODO: Do it when the built-in downlink BWE is in place.
2920
+ #else
2911
2921
  if (this->tccClient)
2912
2922
  {
2913
2923
  ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true);
2914
2924
  }
2925
+ #endif
2915
2926
  }
2916
2927
 
2917
2928
  void Transport::OnDataProducerMessageReceived(
@@ -3106,7 +3117,7 @@ namespace RTC
3106
3117
  {
3107
3118
  MS_TRACE();
3108
3119
 
3109
- const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3120
+ const auto errorKindStringView = RTC::SCTP::Types::errorKindToString(errorKind);
3110
3121
 
3111
3122
  if (errorKind == RTC::SCTP::Types::ErrorKind::SUCCESS || errorKind == RTC::SCTP::Types::ErrorKind::PEER_REPORTED)
3112
3123
  {
@@ -3156,7 +3167,7 @@ namespace RTC
3156
3167
  {
3157
3168
  MS_TRACE();
3158
3169
 
3159
- const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3170
+ const auto errorKindStringView = RTC::SCTP::Types::errorKindToString(errorKind);
3160
3171
 
3161
3172
  if (errorKind == RTC::SCTP::Types::ErrorKind::SUCCESS || errorKind == RTC::SCTP::Types::ErrorKind::PEER_REPORTED)
3162
3173
  {
@@ -3213,7 +3224,7 @@ namespace RTC
3213
3224
  {
3214
3225
  MS_TRACE();
3215
3226
 
3216
- const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3227
+ const auto errorKindStringView = RTC::SCTP::Types::errorKindToString(errorKind);
3217
3228
 
3218
3229
  MS_WARN_TAG(
3219
3230
  sctp,
@@ -3391,13 +3402,14 @@ namespace RTC
3391
3402
  return IsConnected() && (!this->mapDataProducers.empty() || !this->mapDataConsumers.empty());
3392
3403
  }
3393
3404
 
3405
+ #ifndef MS_USE_BUILTIN_BWE
3394
3406
  void Transport::OnTransportCongestionControlClientBitrates(
3395
3407
  RTC::TransportCongestionControlClient* /*tccClient*/,
3396
3408
  RTC::TransportCongestionControlClient::Bitrates& bitrates)
3397
3409
  {
3398
3410
  MS_TRACE();
3399
3411
 
3400
- MS_DEBUG_DEV("outgoing available bitrate:%" PRIu32, bitrates.availableBitrate);
3412
+ MS_DEBUG_DEV("outgoing available bitrate:%" PRIi64, bitrates.availableBitrate);
3401
3413
 
3402
3414
  DistributeAvailableOutgoingBitrate();
3403
3415
  ComputeOutgoingDesiredBitrate();
@@ -3414,7 +3426,7 @@ namespace RTC
3414
3426
  MS_TRACE();
3415
3427
 
3416
3428
  // Update abs-send-time if present.
3417
- packet->UpdateAbsSendTime(this->shared->GetTimeMs());
3429
+ packet->UpdateAbsSendTime(this->shared->GetTimeUs());
3418
3430
 
3419
3431
  // Update transport wide sequence number if present.
3420
3432
  if (
@@ -3442,39 +3454,6 @@ namespace RTC
3442
3454
 
3443
3455
  auto* shared = this->shared;
3444
3456
 
3445
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
3446
- std::weak_ptr<RTC::SenderBandwidthEstimator> senderBweWeakPtr = this->senderBwe;
3447
- RTC::SenderBandwidthEstimator::SentInfo sentInfo;
3448
-
3449
- sentInfo.wideSeq = this->transportWideCcSeq;
3450
- sentInfo.size = packet->GetLength();
3451
- sentInfo.isProbation = true;
3452
- sentInfo.sendingAtMs = this->shared->GetTimeMs();
3453
-
3454
- const auto* cb = new onSendCallback(
3455
- [tccClientWeakPtr, shared, packetInfo, senderBweWeakPtr, sentInfo](bool sent) mutable
3456
- {
3457
- if (sent)
3458
- {
3459
- auto tccClient = tccClientWeakPtr.lock();
3460
-
3461
- if (tccClient)
3462
- {
3463
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
3464
- }
3465
-
3466
- auto senderBwe = senderBweWeakPtr.lock();
3467
-
3468
- if (senderBwe)
3469
- {
3470
- sentInfo.sentAtMs = shared->GetTimeMs();
3471
- senderBwe->RtpPacketSent(sentInfo);
3472
- }
3473
- }
3474
- });
3475
-
3476
- SendRtpPacket(nullptr, packet, cb);
3477
- #else
3478
3457
  const auto* cb = new onSendCallback(
3479
3458
  [tccClientWeakPtr, shared, packetInfo](bool sent)
3480
3459
  {
@@ -3484,13 +3463,12 @@ namespace RTC
3484
3463
 
3485
3464
  if (tccClient)
3486
3465
  {
3487
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
3466
+ tccClient->PacketSent(packetInfo, shared->GetTimeUs());
3488
3467
  }
3489
3468
  }
3490
3469
  });
3491
3470
 
3492
3471
  SendRtpPacket(nullptr, packet, cb);
3493
- #endif
3494
3472
  }
3495
3473
  else
3496
3474
  {
@@ -3503,7 +3481,7 @@ namespace RTC
3503
3481
  this->sendProbationTransmission.Update(packet);
3504
3482
 
3505
3483
  MS_DEBUG_DEV(
3506
- "probation sent [seq:%" PRIu16 ", wideSeq:%" PRIu16 ", size:%zu, bitrate:%" PRIu32 "]",
3484
+ "probation sent [seq:%" PRIu16 ", wideSeq:%" PRIu16 ", size:%zu, bitrate:%" PRIi64 "]",
3507
3485
  packet->GetSequenceNumber(),
3508
3486
  this->transportWideCcSeq,
3509
3487
  packet->GetLength(),
@@ -3519,24 +3497,6 @@ namespace RTC
3519
3497
 
3520
3498
  SendRtcpPacket(packet);
3521
3499
  }
3522
-
3523
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
3524
- void Transport::OnSenderBandwidthEstimatorAvailableBitrate(
3525
- RTC::SenderBandwidthEstimator* /*senderBwe*/,
3526
- uint32_t availableBitrate,
3527
- uint32_t previousAvailableBitrate)
3528
- {
3529
- MS_TRACE();
3530
-
3531
- MS_DEBUG_DEV(
3532
- "outgoing available bitrate [now:%" PRIu32 ", before:%" PRIu32 "]",
3533
- availableBitrate,
3534
- previousAvailableBitrate);
3535
-
3536
- // TODO: Uncomment once just SenderBandwidthEstimator is used.
3537
- // DistributeAvailableOutgoingBitrate();
3538
- // ComputeOutgoingDesiredBitrate();
3539
- }
3540
3500
  #endif
3541
3501
 
3542
3502
  void Transport::OnTimer(TimerHandleInterface* timer)
@@ -3546,19 +3506,18 @@ namespace RTC
3546
3506
  // RTCP timer.
3547
3507
  if (timer == this->rtcpTimer)
3548
3508
  {
3549
- auto interval = static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs);
3550
- const uint64_t nowMs = this->shared->GetTimeMs();
3509
+ auto intervalMs = static_cast<int64_t>(RTC::RTCP::MaxVideoIntervalMs);
3551
3510
 
3552
- SendRtcp(nowMs);
3511
+ SendRtcp(this->shared->GetTimeUs());
3553
3512
 
3554
3513
  /*
3555
3514
  * The interval between RTCP packets is varied randomly over the range
3556
3515
  * [1.0, 1.5] times the calculated interval to avoid unintended
3557
3516
  * synchronization of all participants.
3558
3517
  */
3559
- interval *= static_cast<float>(Utils::Crypto::GetRandomUInt<uint16_t>(10, 15)) / 10;
3518
+ intervalMs *= static_cast<float>(Utils::Crypto::GetRandomUInt<uint16_t>(10, 15)) / 10;
3560
3519
 
3561
- this->rtcpTimer->Start(interval);
3520
+ this->rtcpTimer->Start(intervalMs);
3562
3521
  }
3563
3522
  }
3564
3523
  } // namespace RTC