mediasoup 3.26.0 → 3.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/node/lib/DataConsumer.js +1 -1
  3. package/node/lib/Router.js +1 -1
  4. package/node/lib/Transport.js +15 -15
  5. package/node/lib/fbs/rtp-parameters/encoding-mapping.d.ts +2 -6
  6. package/node/lib/fbs/rtp-parameters/encoding-mapping.d.ts.map +1 -1
  7. package/node/lib/fbs/rtp-parameters/encoding-mapping.js +7 -19
  8. package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.d.ts +4 -4
  9. package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.js +2 -2
  10. package/node/lib/fbs/rtp-stream/bitrate-by-layer.d.ts +5 -5
  11. package/node/lib/fbs/rtp-stream/bitrate-by-layer.d.ts.map +1 -1
  12. package/node/lib/fbs/rtp-stream/bitrate-by-layer.js +3 -3
  13. package/node/lib/fbs/rtp-stream/recv-stats.d.ts +5 -5
  14. package/node/lib/fbs/rtp-stream/recv-stats.d.ts.map +1 -1
  15. package/node/lib/fbs/rtp-stream/recv-stats.js +3 -3
  16. package/node/lib/fbs/rtp-stream/send-stats.d.ts +5 -5
  17. package/node/lib/fbs/rtp-stream/send-stats.d.ts.map +1 -1
  18. package/node/lib/fbs/rtp-stream/send-stats.js +3 -3
  19. package/node/lib/fbs/transport/bwe-trace-info.d.ts +23 -23
  20. package/node/lib/fbs/transport/bwe-trace-info.d.ts.map +1 -1
  21. package/node/lib/fbs/transport/bwe-trace-info.js +15 -15
  22. package/node/lib/fbs/transport/options.d.ts +5 -5
  23. package/node/lib/fbs/transport/options.js +2 -2
  24. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.d.ts +5 -5
  25. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.d.ts.map +1 -1
  26. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.js +3 -3
  27. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.d.ts +5 -5
  28. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.d.ts.map +1 -1
  29. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.js +3 -3
  30. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.d.ts +5 -5
  31. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.d.ts.map +1 -1
  32. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.js +3 -3
  33. package/node/lib/fbs/transport/stats.d.ts +38 -38
  34. package/node/lib/fbs/transport/stats.d.ts.map +1 -1
  35. package/node/lib/fbs/transport/stats.js +25 -25
  36. package/node/lib/ortc.d.ts +0 -1
  37. package/node/lib/ortc.d.ts.map +1 -1
  38. package/node/lib/ortc.js +1 -2
  39. package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
  40. package/node/lib/rtpParametersFbsUtils.js +2 -2
  41. package/package.json +9 -9
  42. package/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc +10 -10
  43. package/worker/deps/libwebrtc/libwebrtc/mediasoup_helpers.h +6 -6
  44. package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc +1 -1
  45. package/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc +7 -7
  46. package/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h +1 -1
  47. package/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc +1 -1
  48. package/worker/fbs/rtpParameters.fbs +1 -2
  49. package/worker/fbs/rtpStream.fbs +3 -3
  50. package/worker/fbs/transport.fbs +23 -23
  51. package/worker/fuzzer/include/RTC/FuzzerDtlsTransport.hpp +4 -1
  52. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  53. package/worker/fuzzer/src/RTC/FuzzerDtlsTransport.cpp +8 -5
  54. package/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp +3 -3
  55. package/worker/fuzzer/src/RTC/FuzzerTrendCalculator.cpp +6 -6
  56. package/worker/fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTransport.cpp +3 -3
  57. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +2 -2
  58. package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +5 -5
  59. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +3 -3
  60. package/worker/fuzzer/src/fuzzer.cpp +4 -0
  61. package/worker/include/Channel/ChannelNotification.hpp +3 -3
  62. package/worker/include/Channel/ChannelRequest.hpp +1 -1
  63. package/worker/include/Channel/ChannelSocket.hpp +11 -0
  64. package/worker/include/DepLibUV.hpp +16 -33
  65. package/worker/include/RTC/ActiveSpeakerObserver.hpp +11 -11
  66. package/worker/include/RTC/AudioLevelObserver.hpp +4 -4
  67. package/worker/include/RTC/BWE/AcknowledgedBitrateEstimatorInterface.hpp +55 -0
  68. package/worker/include/RTC/BWE/AimdRateControl.hpp +190 -0
  69. package/worker/include/RTC/BWE/BweTypes.hpp +211 -0
  70. package/worker/include/RTC/BWE/DelayBasedBwe.hpp +173 -0
  71. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +72 -0
  72. package/worker/include/RTC/BWE/InterArrivalDelta.hpp +106 -0
  73. package/worker/include/RTC/BWE/LinkCapacityEstimator.hpp +84 -0
  74. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +94 -0
  75. package/worker/include/RTC/BWE/SendPacketHistory.hpp +137 -0
  76. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +101 -0
  77. package/worker/include/RTC/Consts.hpp +6 -6
  78. package/worker/include/RTC/Consumer.hpp +14 -12
  79. package/worker/include/RTC/DataConsumer.hpp +3 -3
  80. package/worker/include/RTC/DataProducer.hpp +3 -3
  81. package/worker/include/RTC/DtlsTransport.hpp +5 -2
  82. package/worker/include/RTC/ICE/IceCandidate.hpp +2 -2
  83. package/worker/include/RTC/ICE/IceServer.hpp +3 -3
  84. package/worker/include/RTC/KeyFrameRequestManager.hpp +3 -3
  85. package/worker/include/RTC/NEW_RTCP/packet/Packet.hpp +1 -1
  86. package/worker/include/RTC/NackGenerator.hpp +12 -12
  87. package/worker/include/RTC/PipeProducerStreamManager.hpp +3 -4
  88. package/worker/include/RTC/PipeTransport.hpp +18 -5
  89. package/worker/include/RTC/PlainTransport.hpp +18 -5
  90. package/worker/include/RTC/PortManager.hpp +4 -4
  91. package/worker/include/RTC/Producer.hpp +21 -12
  92. package/worker/include/RTC/ProducerStreamManager.hpp +12 -6
  93. package/worker/include/RTC/RTCP/Bye.hpp +2 -2
  94. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +4 -4
  95. package/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp +3 -3
  96. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +54 -39
  97. package/worker/include/RTC/RTCP/Packet.hpp +3 -3
  98. package/worker/include/RTC/RTCP/ReceiverReport.hpp +3 -3
  99. package/worker/include/RTC/RTCP/Sdes.hpp +2 -2
  100. package/worker/include/RTC/RTCP/XR.hpp +2 -2
  101. package/worker/include/RTC/RTCP/XrDelaySinceLastRr.hpp +1 -1
  102. package/worker/include/RTC/RTP/Codecs/H264.hpp +1 -1
  103. package/worker/include/RTC/RTP/Codecs/Opus.hpp +2 -2
  104. package/worker/include/RTC/RTP/Codecs/PayloadDescriptorHandler.hpp +3 -3
  105. package/worker/include/RTC/RTP/Codecs/VP8.hpp +2 -2
  106. package/worker/include/RTC/RTP/Codecs/VP9.hpp +2 -2
  107. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +12 -12
  108. package/worker/include/RTC/RTP/Packet.hpp +13 -13
  109. package/worker/include/RTC/RTP/ProbationGenerator.hpp +1 -1
  110. package/worker/include/RTC/RTP/RetransmissionBuffer.hpp +7 -7
  111. package/worker/include/RTC/RTP/RtpStream.hpp +37 -51
  112. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +59 -41
  113. package/worker/include/RTC/RTP/RtpStreamSend.hpp +20 -14
  114. package/worker/include/RTC/RTP/RtxStream.hpp +12 -13
  115. package/worker/include/RTC/RateCalculator.hpp +50 -44
  116. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +5 -4
  117. package/worker/include/RTC/RemoteClockOffsetEstimator.hpp +11 -11
  118. package/worker/include/RTC/Router.hpp +6 -0
  119. package/worker/include/RTC/RtcLogger.hpp +1 -1
  120. package/worker/include/RTC/RtpDictionaries.hpp +10 -10
  121. package/worker/include/RTC/SCTP/association/Association.hpp +56 -28
  122. package/worker/include/RTC/SCTP/association/HeartbeatHandler.hpp +4 -4
  123. package/worker/include/RTC/SCTP/association/StateCookie.hpp +14 -14
  124. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +2 -2
  125. package/worker/include/RTC/SCTP/association/TransmissionControlBlock.hpp +12 -12
  126. package/worker/include/RTC/SCTP/association/TransmissionControlBlockContextInterface.hpp +4 -4
  127. package/worker/include/RTC/SCTP/packet/TLV.hpp +1 -1
  128. package/worker/include/RTC/SCTP/packet/parameters/StateCookieParameter.hpp +3 -3
  129. package/worker/include/RTC/SCTP/public/AssociationInterface.hpp +4 -1
  130. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +1 -1
  131. package/worker/include/RTC/SCTP/public/SctpOptions.hpp +12 -12
  132. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +1 -1
  133. package/worker/include/RTC/SCTP/tx/OutstandingData.hpp +15 -16
  134. package/worker/include/RTC/SCTP/tx/RetransmissionQueue.hpp +7 -8
  135. package/worker/include/RTC/SCTP/tx/RetransmissionTimeout.hpp +20 -16
  136. package/worker/include/RTC/SCTP/tx/RoundRobinSendQueue.hpp +5 -6
  137. package/worker/include/RTC/SCTP/tx/SendQueueInterface.hpp +2 -2
  138. package/worker/include/RTC/SCTP/tx/StreamScheduler.hpp +5 -5
  139. package/worker/include/RTC/SctpDictionaries.hpp +3 -3
  140. package/worker/include/RTC/Serializable.hpp +1 -1
  141. package/worker/include/RTC/SimpleProducerStreamManager.hpp +3 -4
  142. package/worker/include/RTC/SimulcastProducerStreamManager.hpp +6 -7
  143. package/worker/include/RTC/SvcProducerStreamManager.hpp +6 -5
  144. package/worker/include/RTC/TcpConnection.hpp +9 -3
  145. package/worker/include/RTC/TcpServer.hpp +3 -0
  146. package/worker/include/RTC/Transport.hpp +52 -45
  147. package/worker/include/RTC/TransportCongestionControlClient.hpp +30 -25
  148. package/worker/include/RTC/TransportCongestionControlServer.hpp +17 -17
  149. package/worker/include/RTC/TrendCalculator.hpp +5 -5
  150. package/worker/include/RTC/UdpSocket.hpp +11 -2
  151. package/worker/include/RTC/WebRtcServer.hpp +20 -5
  152. package/worker/include/RTC/WebRtcTransport.hpp +35 -10
  153. package/worker/include/Settings.hpp +4 -2
  154. package/worker/include/Shared.hpp +5 -20
  155. package/worker/include/SharedInterface.hpp +6 -28
  156. package/worker/include/Utils.hpp +40 -21
  157. package/worker/include/common.hpp +4 -0
  158. package/worker/include/handles/BackoffTimerHandle.hpp +4 -4
  159. package/worker/include/handles/BackoffTimerHandleInterface.hpp +5 -5
  160. package/worker/include/handles/TcpConnectionHandle.hpp +6 -6
  161. package/worker/include/handles/TcpServerHandle.hpp +1 -1
  162. package/worker/include/handles/TimerHandle.hpp +15 -9
  163. package/worker/include/handles/TimerHandleInterface.hpp +10 -4
  164. package/worker/include/handles/UdpSocketHandle.hpp +3 -3
  165. package/worker/include/handles/UnixStreamSocketHandle.hpp +2 -2
  166. package/worker/meson.build +81 -36
  167. package/worker/meson_options.txt +1 -0
  168. package/worker/mocks/include/MockShared.hpp +24 -23
  169. package/worker/mocks/include/RTC/SCTP/association/MockTransmissionControlBlockContext.hpp +51 -27
  170. package/worker/mocks/include/RTC/SCTP/tx/MockSendQueue.hpp +11 -11
  171. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +10 -10
  172. package/worker/mocks/include/handles/MockTimerHandle.hpp +60 -22
  173. package/worker/mocks/src/MockShared.cpp +51 -5
  174. package/worker/mocks/src/handles/MockBackoffTimerHandle.cpp +29 -15
  175. package/worker/mocks/src/handles/MockTimerHandle.cpp +117 -0
  176. package/worker/scripts/clang-scripts.mjs +2 -2
  177. package/worker/src/Channel/ChannelNotification.cpp +5 -6
  178. package/worker/src/Channel/ChannelSocket.cpp +20 -2
  179. package/worker/src/DepLibUV.cpp +4 -5
  180. package/worker/src/RTC/ActiveSpeakerObserver.cpp +59 -47
  181. package/worker/src/RTC/AudioLevelObserver.cpp +7 -7
  182. package/worker/src/RTC/BWE/AimdRateControl.cpp +468 -0
  183. package/worker/src/RTC/BWE/BweTypes.cpp +61 -0
  184. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +275 -0
  185. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +148 -0
  186. package/worker/src/RTC/BWE/InterArrivalDelta.cpp +181 -0
  187. package/worker/src/RTC/BWE/LinkCapacityEstimator.cpp +133 -0
  188. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +245 -0
  189. package/worker/src/RTC/BWE/SendPacketHistory.cpp +184 -0
  190. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +233 -0
  191. package/worker/src/RTC/Consumer.cpp +48 -35
  192. package/worker/src/RTC/DataConsumer.cpp +4 -4
  193. package/worker/src/RTC/DataProducer.cpp +3 -3
  194. package/worker/src/RTC/DirectTransport.cpp +2 -2
  195. package/worker/src/RTC/DtlsTransport.cpp +14 -11
  196. package/worker/src/RTC/ICE/IceServer.cpp +2 -2
  197. package/worker/src/RTC/KeyFrameRequestManager.cpp +16 -12
  198. package/worker/src/RTC/NackGenerator.cpp +12 -12
  199. package/worker/src/RTC/PipeProducerStreamManager.cpp +6 -6
  200. package/worker/src/RTC/PipeTransport.cpp +16 -13
  201. package/worker/src/RTC/PlainTransport.cpp +25 -16
  202. package/worker/src/RTC/Producer.cpp +50 -36
  203. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +13 -6
  204. package/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp +14 -5
  205. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +76 -50
  206. package/worker/src/RTC/RTP/Codecs/VP8.cpp +1 -1
  207. package/worker/src/RTC/RTP/Codecs/VP9.cpp +4 -4
  208. package/worker/src/RTC/RTP/Packet.cpp +9 -10
  209. package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +6 -6
  210. package/worker/src/RTC/RTP/RtpStream.cpp +19 -19
  211. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +146 -81
  212. package/worker/src/RTC/RTP/RtpStreamSend.cpp +49 -44
  213. package/worker/src/RTC/RTP/RtxStream.cpp +7 -10
  214. package/worker/src/RTC/RateCalculator.cpp +99 -136
  215. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +13 -13
  216. package/worker/src/RTC/RemoteClockOffsetEstimator.cpp +18 -17
  217. package/worker/src/RTC/Router.cpp +18 -1
  218. package/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp +5 -2
  219. package/worker/src/RTC/SCTP/association/Association.cpp +131 -102
  220. package/worker/src/RTC/SCTP/association/AssociationListenerDeferrer.cpp +4 -4
  221. package/worker/src/RTC/SCTP/association/Capabilities.cpp +1 -1
  222. package/worker/src/RTC/SCTP/association/HeartbeatHandler.cpp +25 -18
  223. package/worker/src/RTC/SCTP/association/StateCookie.cpp +7 -6
  224. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +16 -13
  225. package/worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp +28 -26
  226. package/worker/src/RTC/SCTP/packet/chunks/SackChunk.cpp +0 -1
  227. package/worker/src/RTC/SCTP/packet/parameters/StateCookieParameter.cpp +2 -2
  228. package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +1 -1
  229. package/worker/src/RTC/SCTP/public/SctpOptions.cpp +13 -13
  230. package/worker/src/RTC/SCTP/rx/DataTracker.cpp +1 -1
  231. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +5 -5
  232. package/worker/src/RTC/SCTP/tx/OutstandingData.cpp +15 -15
  233. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +15 -15
  234. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +29 -26
  235. package/worker/src/RTC/SCTP/tx/RoundRobinSendQueue.cpp +12 -11
  236. package/worker/src/RTC/SCTP/tx/StreamScheduler.cpp +4 -4
  237. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +2 -2
  238. package/worker/src/RTC/SimpleProducerStreamManager.cpp +10 -10
  239. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +39 -37
  240. package/worker/src/RTC/SvcProducerStreamManager.cpp +39 -25
  241. package/worker/src/RTC/TcpConnection.cpp +9 -3
  242. package/worker/src/RTC/TcpServer.cpp +7 -2
  243. package/worker/src/RTC/Transport.cpp +242 -302
  244. package/worker/src/RTC/TransportCongestionControlClient.cpp +78 -71
  245. package/worker/src/RTC/TransportCongestionControlServer.cpp +38 -40
  246. package/worker/src/RTC/TrendCalculator.cpp +3 -3
  247. package/worker/src/RTC/UdpSocket.cpp +14 -3
  248. package/worker/src/RTC/WebRtcServer.cpp +20 -14
  249. package/worker/src/RTC/WebRtcTransport.cpp +35 -30
  250. package/worker/src/Settings.cpp +10 -0
  251. package/worker/src/Shared.cpp +2 -2
  252. package/worker/src/Utils/Crypto.cpp +2 -2
  253. package/worker/src/Worker.cpp +5 -1
  254. package/worker/src/handles/BackoffTimerHandle.cpp +24 -11
  255. package/worker/src/handles/TimerHandle.cpp +74 -25
  256. package/worker/src/lib.cpp +6 -0
  257. package/worker/tasks.py +171 -44
  258. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +117 -0
  259. package/worker/test/src/RTC/BWE/TestAimdRateControl.cpp +400 -0
  260. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +568 -0
  261. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +546 -0
  262. package/worker/test/src/RTC/BWE/TestInterArrivalDelta.cpp +301 -0
  263. package/worker/test/src/RTC/BWE/TestLinkCapacityEstimator.cpp +115 -0
  264. package/worker/test/src/RTC/BWE/TestRobustThroughputEstimator.cpp +433 -0
  265. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +259 -0
  266. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +137 -0
  267. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +171 -0
  268. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +1 -1
  269. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +1 -1
  270. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +246 -208
  271. package/worker/test/src/RTC/RTP/TestPacket.cpp +11 -11
  272. package/worker/test/src/RTC/RTP/TestRetransmissionBuffer.cpp +12 -12
  273. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +23 -16
  274. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +13 -13
  275. package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +27 -22
  276. package/worker/test/src/RTC/SCTP/association/TestHeartbeatHandler.cpp +21 -15
  277. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +6 -6
  278. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +17 -13
  279. package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +3 -3
  280. package/worker/test/src/RTC/SCTP/packet/chunks/TestForwardTsnChunk.cpp +2 -2
  281. package/worker/test/src/RTC/SCTP/packet/chunks/TestIForwardTsnChunk.cpp +23 -23
  282. package/worker/test/src/RTC/SCTP/packet/chunks/TestInitChunk.cpp +1 -1
  283. package/worker/test/src/RTC/SCTP/packet/chunks/TestSackChunk.cpp +1 -1
  284. package/worker/test/src/RTC/SCTP/packet/parameters/TestIPv6AddressParameter.cpp +1 -1
  285. package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +37 -37
  286. package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +10 -10
  287. package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +1 -1
  288. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +93 -93
  289. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +247 -247
  290. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +100 -80
  291. package/worker/test/src/RTC/SCTP/tx/TestRoundRobinSendQueue.cpp +163 -163
  292. package/worker/test/src/RTC/SCTP/tx/TestStreamScheduler.cpp +76 -77
  293. package/worker/test/src/RTC/TestConsumer.cpp +8 -3
  294. package/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +3 -3
  295. package/worker/test/src/RTC/TestNackGenerator.cpp +3 -3
  296. package/worker/test/src/RTC/TestPipeProducerStreamManager.cpp +5 -5
  297. package/worker/test/src/RTC/TestRateCalculator.cpp +110 -14
  298. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +22 -17
  299. package/worker/test/src/RTC/TestRemoteClockOffsetEstimator.cpp +87 -85
  300. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +54 -47
  301. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +83 -69
  302. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +76 -65
  303. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +72 -66
  304. package/worker/test/src/RTC/TestTransportTuple.cpp +19 -4
  305. package/worker/test/src/TestDepLibUV.cpp +19 -0
  306. package/worker/test/src/Utils/TestTime.cpp +57 -26
  307. package/worker/test/src/testHelpers.cpp +1 -1
  308. package/worker/test/src/tests.cpp +6 -0
  309. package/worker/include/RTC/SenderBandwidthEstimator.hpp +0 -118
  310. package/worker/src/RTC/SenderBandwidthEstimator.cpp +0 -269
@@ -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,21 @@
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
+
33
43
  /* Instance methods. */
34
44
 
35
45
  Transport::Transport(
@@ -57,7 +67,10 @@ namespace RTC
57
67
  auto initialAvailableOutgoingBitrate = options->initialAvailableOutgoingBitrate();
58
68
  initialAvailableOutgoingBitrate.has_value())
59
69
  {
60
- this->initialAvailableOutgoingBitrate = initialAvailableOutgoingBitrate.value();
70
+ // NOTE: The API gives an unsigned 64 bits bitrate, so it is clamped here.
71
+ this->initialAvailableOutgoingBitrate = static_cast<int64_t>(std::min<uint64_t>(
72
+ initialAvailableOutgoingBitrate.value(),
73
+ static_cast<uint64_t>(std::numeric_limits<int64_t>::max())));
61
74
  }
62
75
 
63
76
  if (options->enableSctp())
@@ -84,7 +97,7 @@ namespace RTC
84
97
  }
85
98
 
86
99
  // Create the RTCP timer.
87
- this->rtcpTimer = this->shared->CreateTimer(this);
100
+ this->rtcpTimer = this->shared->CreateTimer(this, "transport-rtcp");
88
101
  }
89
102
 
90
103
  Transport::~Transport()
@@ -388,7 +401,7 @@ namespace RTC
388
401
  this->maxReceiveMessageSize,
389
402
  sctpParameters,
390
403
  this->sctpAssociation ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
391
- : flatbuffers::nullopt,
404
+ : flatbuffers::nullopt,
392
405
  sctpNegotiatedCapabilities,
393
406
  sctpListener,
394
407
  std::addressof(traceEventTypes));
@@ -399,7 +412,7 @@ namespace RTC
399
412
  {
400
413
  MS_TRACE();
401
414
 
402
- auto nowMs = this->shared->GetTimeMs();
415
+ const int64_t nowMs = this->shared->GetTimeMs();
403
416
 
404
417
  // Add sctpState.
405
418
  FBS::SctpAssociation::SctpState sctpState{ FBS::SctpAssociation::SctpState::NEW };
@@ -437,64 +450,86 @@ namespace RTC
437
450
  }
438
451
  }
439
452
 
453
+ #ifdef MS_USE_BUILTIN_BWE
454
+ // TODO: Take these from the built-in downlink and uplink BWE.
455
+ const flatbuffers::Optional<uint64_t> availableOutgoingBitrate{ flatbuffers::nullopt };
456
+ const flatbuffers::Optional<uint64_t> availableIncomingBitrate{ flatbuffers::nullopt };
457
+ const flatbuffers::Optional<double> rtpPacketLossReceived{ flatbuffers::nullopt };
458
+ const flatbuffers::Optional<double> rtpPacketLossSent{ flatbuffers::nullopt };
459
+ #else
460
+ const auto availableOutgoingBitrate =
461
+ this->tccClient ? flatbuffers::Optional<uint64_t>(
462
+ static_cast<uint64_t>(this->tccClient->GetAvailableBitrate()))
463
+ : flatbuffers::nullopt;
464
+ const auto availableIncomingBitrate =
465
+ this->tccServer ? flatbuffers::Optional<uint64_t>(
466
+ static_cast<uint64_t>(this->tccServer->GetAvailableBitrate()))
467
+ : flatbuffers::nullopt;
468
+ const auto rtpPacketLossReceived =
469
+ this->tccServer ? flatbuffers::Optional<double>(this->tccServer->GetPacketLoss())
470
+ : flatbuffers::nullopt;
471
+ const auto rtpPacketLossSent =
472
+ this->tccClient ? flatbuffers::Optional<double>(this->tccClient->GetPacketLoss())
473
+ : flatbuffers::nullopt;
474
+ #endif
475
+
440
476
  return FBS::Transport::CreateStatsDirect(
441
477
  builder,
442
478
  // transportId.
443
479
  this->id.c_str(),
444
480
  // timestamp.
445
- nowMs,
481
+ static_cast<uint64_t>(nowMs),
446
482
  // sctpState.
447
483
  this->sctpAssociation ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
448
- : flatbuffers::nullopt,
484
+ : flatbuffers::nullopt,
449
485
  // bytesReceived.
450
486
  this->recvTransmission.GetBytes(),
451
487
  // recvBitrate.
452
- this->recvTransmission.GetRate(nowMs),
488
+ static_cast<uint64_t>(this->recvTransmission.GetRate(nowMs)),
453
489
  // bytesSent.
454
490
  this->sendTransmission.GetBytes(),
455
491
  // sendBitrate.
456
- this->sendTransmission.GetRate(nowMs),
492
+ static_cast<uint64_t>(this->sendTransmission.GetRate(nowMs)),
457
493
  // rtpBytesReceived.
458
494
  this->recvRtpTransmission.GetBytes(),
459
495
  // rtpRecvBitrate.
460
- this->recvRtpTransmission.GetBitrate(nowMs),
496
+ static_cast<uint64_t>(this->recvRtpTransmission.GetBitrate(nowMs)),
461
497
  // rtpBytesSent.
462
498
  this->sendRtpTransmission.GetBytes(),
463
499
  // rtpSendBitrate.
464
- this->sendRtpTransmission.GetBitrate(nowMs),
500
+ static_cast<uint64_t>(this->sendRtpTransmission.GetBitrate(nowMs)),
465
501
  // rtxBytesReceived.
466
502
  this->recvRtxTransmission.GetBytes(),
467
503
  // rtxRecvBitrate.
468
- this->recvRtxTransmission.GetBitrate(nowMs),
504
+ static_cast<uint64_t>(this->recvRtxTransmission.GetBitrate(nowMs)),
469
505
  // rtxBytesSent.
470
506
  this->sendRtxTransmission.GetBytes(),
471
507
  // rtxSendBitrate.
472
- this->sendRtxTransmission.GetBitrate(nowMs),
508
+ static_cast<uint64_t>(this->sendRtxTransmission.GetBitrate(nowMs)),
473
509
  // probationBytesSent.
474
510
  this->sendProbationTransmission.GetBytes(),
475
511
  // probationSendBitrate.
476
- this->sendProbationTransmission.GetBitrate(nowMs),
512
+ static_cast<uint64_t>(this->sendProbationTransmission.GetBitrate(nowMs)),
477
513
  // availableOutgoingBitrate.
478
- this->tccClient ? flatbuffers::Optional<uint32_t>(this->tccClient->GetAvailableBitrate())
479
- : flatbuffers::nullopt,
514
+ availableOutgoingBitrate,
480
515
  // availableIncomingBitrate.
481
- this->tccServer ? flatbuffers::Optional<uint32_t>(this->tccServer->GetAvailableBitrate())
482
- : flatbuffers::nullopt,
516
+ availableIncomingBitrate,
483
517
  // maxIncomingBitrate.
484
- this->maxIncomingBitrate ? flatbuffers::Optional<uint32_t>(this->maxIncomingBitrate)
485
- : flatbuffers::nullopt,
518
+ this->maxIncomingBitrate > 0
519
+ ? flatbuffers::Optional<uint64_t>(static_cast<uint64_t>(this->maxIncomingBitrate))
520
+ : flatbuffers::nullopt,
486
521
  // maxOutgoingBitrate.
487
- this->maxOutgoingBitrate ? flatbuffers::Optional<uint32_t>(this->maxOutgoingBitrate)
488
- : flatbuffers::nullopt,
522
+ this->maxOutgoingBitrate > 0
523
+ ? flatbuffers::Optional<uint64_t>(static_cast<uint64_t>(this->maxOutgoingBitrate))
524
+ : flatbuffers::nullopt,
489
525
  // minOutgoingBitrate.
490
- this->minOutgoingBitrate ? flatbuffers::Optional<uint32_t>(this->minOutgoingBitrate)
491
- : flatbuffers::nullopt,
526
+ this->minOutgoingBitrate > 0
527
+ ? flatbuffers::Optional<uint64_t>(static_cast<uint64_t>(this->minOutgoingBitrate))
528
+ : flatbuffers::nullopt,
492
529
  // rtpPacketLossReceived.
493
- this->tccServer ? flatbuffers::Optional<double>(this->tccServer->GetPacketLoss())
494
- : flatbuffers::nullopt,
530
+ rtpPacketLossReceived,
495
531
  // rtpPacketLossSent.
496
- this->tccClient ? flatbuffers::Optional<double>(this->tccClient->GetPacketLoss())
497
- : flatbuffers::nullopt);
532
+ rtpPacketLossSent);
498
533
  }
499
534
 
500
535
  void Transport::HandleRequest(Channel::ChannelRequest* request)
@@ -507,16 +542,22 @@ namespace RTC
507
542
  {
508
543
  const auto* body = request->data->body_as<FBS::Transport::SetMaxIncomingBitrateRequest>();
509
544
 
510
- this->maxIncomingBitrate = body->maxIncomingBitrate();
545
+ // NOTE: The API gives an unsigned 64 bits bitrate, so it is clamped here.
546
+ this->maxIncomingBitrate = static_cast<int64_t>(std::min<uint64_t>(
547
+ body->maxIncomingBitrate(), static_cast<uint64_t>(std::numeric_limits<int64_t>::max())));
511
548
 
512
- MS_DEBUG_TAG(bwe, "maximum incoming bitrate set to %" PRIu32, this->maxIncomingBitrate);
549
+ MS_DEBUG_TAG(bwe, "maximum incoming bitrate set to %" PRIi64, this->maxIncomingBitrate);
513
550
 
514
551
  request->Accept();
515
552
 
553
+ #ifdef MS_USE_BUILTIN_BWE
554
+ // TODO: Pass maxIncomingBitrate to the built-in uplink BWE.
555
+ #else
516
556
  if (this->tccServer)
517
557
  {
518
558
  this->tccServer->SetMaxIncomingBitrate(this->maxIncomingBitrate);
519
559
  }
560
+ #endif
520
561
 
521
562
  break;
522
563
  }
@@ -524,21 +565,27 @@ namespace RTC
524
565
  case Channel::ChannelRequest::Method::TRANSPORT_SET_MAX_OUTGOING_BITRATE:
525
566
  {
526
567
  const auto* body = request->data->body_as<FBS::Transport::SetMaxOutgoingBitrateRequest>();
527
- const uint32_t bitrate = body->maxOutgoingBitrate();
528
568
 
529
- if (bitrate > 0u && bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
569
+ // NOTE: The API gives an unsigned 64 bits bitrate, so it is clamped here.
570
+ const auto bitrate = static_cast<int64_t>(std::min<uint64_t>(
571
+ body->maxOutgoingBitrate(), static_cast<uint64_t>(std::numeric_limits<int64_t>::max())));
572
+
573
+ if (bitrate > 0 && bitrate < AbsoluteMinOutgoingBitrate)
530
574
  {
531
575
  MS_THROW_TYPE_ERROR(
532
- "bitrate must be >= %" PRIu32 " or 0 (unlimited)",
533
- RTC::TransportCongestionControlMinOutgoingBitrate);
576
+ "bitrate must be >= %" PRIi64 " or 0 (unlimited)", AbsoluteMinOutgoingBitrate);
534
577
  }
535
- else if (bitrate > 0u && bitrate < this->minOutgoingBitrate)
578
+ else if (bitrate > 0 && bitrate < this->minOutgoingBitrate)
536
579
  {
537
580
  MS_THROW_TYPE_ERROR(
538
- "bitrate must be >= current min outgoing bitrate (%" PRIu32 ") or 0 (unlimited)",
581
+ "bitrate must be >= current min outgoing bitrate (%" PRIi64 ") or 0 (unlimited)",
539
582
  this->minOutgoingBitrate);
540
583
  }
541
584
 
585
+ #ifdef MS_USE_BUILTIN_BWE
586
+ // TODO: Pass maxOutgoingBitrate to the built-in downlink BWE.
587
+ this->maxOutgoingBitrate = bitrate;
588
+ #else
542
589
  if (this->tccClient)
543
590
  {
544
591
  // NOTE: This may throw so don't update things before calling this
@@ -546,7 +593,7 @@ namespace RTC
546
593
  this->tccClient->SetMaxOutgoingBitrate(bitrate);
547
594
  this->maxOutgoingBitrate = bitrate;
548
595
 
549
- MS_DEBUG_TAG(bwe, "maximum outgoing bitrate set to %" PRIu32, this->maxOutgoingBitrate);
596
+ MS_DEBUG_TAG(bwe, "maximum outgoing bitrate set to %" PRIi64, this->maxOutgoingBitrate);
550
597
 
551
598
  ComputeOutgoingDesiredBitrate();
552
599
  }
@@ -554,6 +601,7 @@ namespace RTC
554
601
  {
555
602
  this->maxOutgoingBitrate = bitrate;
556
603
  }
604
+ #endif
557
605
 
558
606
  request->Accept();
559
607
 
@@ -563,21 +611,27 @@ namespace RTC
563
611
  case Channel::ChannelRequest::Method::TRANSPORT_SET_MIN_OUTGOING_BITRATE:
564
612
  {
565
613
  const auto* body = request->data->body_as<FBS::Transport::SetMinOutgoingBitrateRequest>();
566
- const uint32_t bitrate = body->minOutgoingBitrate();
567
614
 
568
- if (bitrate > 0u && bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
615
+ // NOTE: The API gives an unsigned 64 bits bitrate, so it is clamped here.
616
+ const auto bitrate = static_cast<int64_t>(std::min<uint64_t>(
617
+ body->minOutgoingBitrate(), static_cast<uint64_t>(std::numeric_limits<int64_t>::max())));
618
+
619
+ if (bitrate > 0 && bitrate < AbsoluteMinOutgoingBitrate)
569
620
  {
570
621
  MS_THROW_TYPE_ERROR(
571
- "bitrate must be >= %" PRIu32 " or 0 (unlimited)",
572
- RTC::TransportCongestionControlMinOutgoingBitrate);
622
+ "bitrate must be >= %" PRIi64 " or 0 (unlimited)", AbsoluteMinOutgoingBitrate);
573
623
  }
574
- else if (bitrate > 0u && this->maxOutgoingBitrate > 0 && bitrate > this->maxOutgoingBitrate)
624
+ else if (bitrate > 0 && this->maxOutgoingBitrate > 0 && bitrate > this->maxOutgoingBitrate)
575
625
  {
576
626
  MS_THROW_TYPE_ERROR(
577
- "bitrate must be <= current max outgoing bitrate (%" PRIu32 ") or 0 (unlimited)",
627
+ "bitrate must be <= current max outgoing bitrate (%" PRIi64 ") or 0 (unlimited)",
578
628
  this->maxOutgoingBitrate);
579
629
  }
580
630
 
631
+ #ifdef MS_USE_BUILTIN_BWE
632
+ // TODO: Pass minOutgoingBitrate to the built-in downlink BWE.
633
+ this->minOutgoingBitrate = bitrate;
634
+ #else
581
635
  if (this->tccClient)
582
636
  {
583
637
  // NOTE: This may throw so don't update things before calling this
@@ -585,7 +639,7 @@ namespace RTC
585
639
  this->tccClient->SetMinOutgoingBitrate(bitrate);
586
640
  this->minOutgoingBitrate = bitrate;
587
641
 
588
- MS_DEBUG_TAG(bwe, "minimum outgoing bitrate set to %" PRIu32, this->minOutgoingBitrate);
642
+ MS_DEBUG_TAG(bwe, "minimum outgoing bitrate set to %" PRIi64, this->minOutgoingBitrate);
589
643
 
590
644
  ComputeOutgoingDesiredBitrate();
591
645
  }
@@ -593,6 +647,7 @@ namespace RTC
593
647
  {
594
648
  this->minOutgoingBitrate = bitrate;
595
649
  }
650
+ #endif
596
651
 
597
652
  request->Accept();
598
653
 
@@ -703,6 +758,10 @@ namespace RTC
703
758
 
704
759
  request->Accept(FBS::Response::Body::Transport_ProduceResponse, responseOffset);
705
760
 
761
+ #ifdef MS_USE_BUILTIN_BWE
762
+ // TODO: Create the built-in uplink BWE here, choosing transport-cc or
763
+ // REMB out of the Producer RTP header extensions and RTCP feedback.
764
+ #else
706
765
  // Check if TransportCongestionControlServer or REMB server must be
707
766
  // created.
708
767
  const auto& rtpHeaderExtensionIds = producer->GetRtpHeaderExtensionIds();
@@ -780,6 +839,7 @@ namespace RTC
780
839
  }
781
840
  }
782
841
  }
842
+ #endif
783
843
 
784
844
  break;
785
845
  }
@@ -846,6 +906,11 @@ namespace RTC
846
906
 
847
907
  request->Accept(FBS::Response::Body::Transport_ConsumeResponse, responseOffset);
848
908
 
909
+ #ifdef MS_USE_BUILTIN_BWE
910
+ // TODO: Create the built-in downlink BWE here, choosing transport-cc or
911
+ // REMB out of the Consumer RTP header extensions and RTCP feedback, and
912
+ // tell every Consumer that we manage its bitrate.
913
+ #else
849
914
  // Check if Transport Congestion Control client must be created.
850
915
  const auto& rtpHeaderExtensionIds = consumer->GetRtpHeaderExtensionIds();
851
916
  const auto& codecs = consumer->GetRtpParameters().codecs;
@@ -925,6 +990,7 @@ namespace RTC
925
990
  this,
926
991
  this->shared,
927
992
  bweType,
993
+ AbsoluteMinOutgoingBitrate,
928
994
  this->initialAvailableOutgoingBitrate,
929
995
  this->maxOutgoingBitrate,
930
996
  this->minOutgoingBitrate);
@@ -942,56 +1008,6 @@ namespace RTC
942
1008
  {
943
1009
  consumer->SetExternallyManagedBitrate();
944
1010
  }
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
1011
  #endif
996
1012
 
997
1013
  if (IsConnected())
@@ -1347,10 +1363,14 @@ namespace RTC
1347
1363
 
1348
1364
  // This may be the latest active Consumer with BWE. If so we have to stop
1349
1365
  // probation.
1366
+ #ifdef MS_USE_BUILTIN_BWE
1367
+ // TODO: Do it when the built-in downlink BWE is in place.
1368
+ #else
1350
1369
  if (this->tccClient)
1351
1370
  {
1352
1371
  ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true);
1353
1372
  }
1373
+ #endif
1354
1374
 
1355
1375
  break;
1356
1376
  }
@@ -1468,7 +1488,7 @@ namespace RTC
1468
1488
  {
1469
1489
  MS_TRACE();
1470
1490
 
1471
- switch (notification->event)
1491
+ switch (notification->data->event())
1472
1492
  {
1473
1493
  default:
1474
1494
  {
@@ -1512,8 +1532,11 @@ namespace RTC
1512
1532
  }
1513
1533
 
1514
1534
  // Start the RTCP timer.
1515
- this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2));
1535
+ this->rtcpTimer->Start(RTC::RTCP::MaxVideoIntervalMs / 2);
1516
1536
 
1537
+ #ifdef MS_USE_BUILTIN_BWE
1538
+ // TODO: Tell the built-in downlink and uplink BWE.
1539
+ #else
1517
1540
  // Tell the TransportCongestionControlClient.
1518
1541
  if (this->tccClient)
1519
1542
  {
@@ -1525,13 +1548,6 @@ namespace RTC
1525
1548
  {
1526
1549
  this->tccServer->TransportConnected();
1527
1550
  }
1528
-
1529
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
1530
- // Tell the SenderBandwidthEstimator.
1531
- if (this->senderBwe)
1532
- {
1533
- this->senderBwe->TransportConnected();
1534
- }
1535
1551
  #endif
1536
1552
  }
1537
1553
 
@@ -1550,6 +1566,9 @@ namespace RTC
1550
1566
  // Stop the RTCP timer.
1551
1567
  this->rtcpTimer->Stop();
1552
1568
 
1569
+ #ifdef MS_USE_BUILTIN_BWE
1570
+ // TODO: Tell the built-in downlink and uplink BWE.
1571
+ #else
1553
1572
  // Tell the TransportCongestionControlClient.
1554
1573
  if (this->tccClient)
1555
1574
  {
@@ -1561,17 +1580,10 @@ namespace RTC
1561
1580
  {
1562
1581
  this->tccServer->TransportDisconnected();
1563
1582
  }
1564
-
1565
- #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
1566
- // Tell the SenderBandwidthEstimator.
1567
- if (this->senderBwe)
1568
- {
1569
- this->senderBwe->TransportDisconnected();
1570
- }
1571
1583
  #endif
1572
1584
  }
1573
1585
 
1574
- void Transport::ReceiveRtpPacket(RTC::RTP::Packet* packet)
1586
+ void Transport::ReceiveRtpPacket(RTC::RTP::Packet* packet, int64_t receivedAtUs)
1575
1587
  {
1576
1588
  MS_TRACE();
1577
1589
 
@@ -1583,13 +1595,15 @@ namespace RTC
1583
1595
  // them.
1584
1596
  packet->AssignExtensionIds(this->recvRtpHeaderExtensionIds);
1585
1597
 
1586
- auto nowMs = this->shared->GetTimeMs();
1587
-
1598
+ #ifdef MS_USE_BUILTIN_BWE
1599
+ // TODO: Feed the built-in uplink BWE.
1600
+ #else
1588
1601
  // Feed the TransportCongestionControlServer.
1589
1602
  if (this->tccServer)
1590
1603
  {
1591
- this->tccServer->IncomingPacket(nowMs, packet);
1604
+ this->tccServer->IncomingPacket(receivedAtUs, packet);
1592
1605
  }
1606
+ #endif
1593
1607
 
1594
1608
  // Get the associated Producer.
1595
1609
  RTC::Producer* producer = this->rtpListener.GetProducer(packet);
@@ -1621,7 +1635,7 @@ namespace RTC
1621
1635
  // producer->id.c_str());
1622
1636
 
1623
1637
  // Pass the RTP packet to the corresponding Producer.
1624
- auto result = producer->ReceiveRtpPacket(packet);
1638
+ auto result = producer->ReceiveRtpPacket(packet, receivedAtUs);
1625
1639
 
1626
1640
  switch (result)
1627
1641
  {
@@ -1650,14 +1664,14 @@ namespace RTC
1650
1664
  delete packet;
1651
1665
  }
1652
1666
 
1653
- void Transport::ReceiveRtcpPacket(RTC::RTCP::Packet* packet)
1667
+ void Transport::ReceiveRtcpPacket(RTC::RTCP::Packet* packet, int64_t receivedAtUs)
1654
1668
  {
1655
1669
  MS_TRACE();
1656
1670
 
1657
1671
  // Handle each RTCP packet.
1658
1672
  while (packet)
1659
1673
  {
1660
- HandleRtcpPacket(packet);
1674
+ HandleRtcpPacket(packet, receivedAtUs);
1661
1675
 
1662
1676
  auto* previousPacket = packet;
1663
1677
 
@@ -1667,7 +1681,7 @@ namespace RTC
1667
1681
  }
1668
1682
  }
1669
1683
 
1670
- void Transport::ReceiveSctpData(const uint8_t* data, size_t len)
1684
+ void Transport::ReceiveSctpData(const uint8_t* data, size_t len, int64_t receivedAtUs)
1671
1685
  {
1672
1686
  MS_TRACE();
1673
1687
 
@@ -1679,7 +1693,7 @@ namespace RTC
1679
1693
  }
1680
1694
 
1681
1695
  // Pass it to the SctpAssociation.
1682
- this->sctpAssociation->ReceiveSctpData(data, len);
1696
+ this->sctpAssociation->ReceiveSctpData(data, len, receivedAtUs);
1683
1697
  }
1684
1698
 
1685
1699
  void Transport::SendSctpMessage(
@@ -1708,7 +1722,7 @@ namespace RTC
1708
1722
  .unordered = !sctpStreamParameters.ordered,
1709
1723
  .lifetimeMs = sctpStreamParameters.ordered
1710
1724
  ? std::nullopt
1711
- : std::optional<uint64_t>(sctpStreamParameters.maxPacketLifeTime),
1725
+ : std::optional<int64_t>(sctpStreamParameters.maxPacketLifeTime),
1712
1726
  .maxRetransmissions = sctpStreamParameters.ordered
1713
1727
  ? std::nullopt
1714
1728
  : std::optional<uint64_t>(sctpStreamParameters.maxRetransmits),
@@ -1933,7 +1947,7 @@ namespace RTC
1933
1947
  }
1934
1948
  }
1935
1949
 
1936
- void Transport::HandleRtcpPacket(RTC::RTCP::Packet* packet)
1950
+ void Transport::HandleRtcpPacket(RTC::RTCP::Packet* packet, int64_t receivedAtUs)
1937
1951
  {
1938
1952
  MS_TRACE();
1939
1953
 
@@ -1970,12 +1984,15 @@ namespace RTC
1970
1984
  continue;
1971
1985
  }
1972
1986
 
1973
- consumer->ReceiveRtcpReceiverReport(report);
1987
+ consumer->ReceiveRtcpReceiverReport(report, receivedAtUs);
1974
1988
  }
1975
1989
 
1990
+ #ifdef MS_USE_BUILTIN_BWE
1991
+ // TODO: Feed the Receiver Report to the built-in downlink BWE.
1992
+ #else
1976
1993
  if (this->tccClient && !this->mapConsumers.empty())
1977
1994
  {
1978
- float rtt = 0;
1995
+ float rttMs = 0;
1979
1996
 
1980
1997
  // Retrieve the RTT from the first active consumer.
1981
1998
  for (auto& kv : this->mapConsumers)
@@ -1984,14 +2001,15 @@ namespace RTC
1984
2001
 
1985
2002
  if (consumer->IsActive())
1986
2003
  {
1987
- rtt = consumer->GetRtt();
2004
+ rttMs = consumer->GetRttMs();
1988
2005
 
1989
2006
  break;
1990
2007
  }
1991
2008
  }
1992
2009
 
1993
- this->tccClient->ReceiveRtcpReceiverReport(rr, rtt, this->shared->GetTimeMsInt64());
2010
+ this->tccClient->ReceiveRtcpReceiverReport(rr, rttMs, receivedAtUs);
1994
2011
  }
2012
+ #endif
1995
2013
 
1996
2014
  break;
1997
2015
  }
@@ -2085,11 +2103,16 @@ namespace RTC
2085
2103
  {
2086
2104
  auto* remb = static_cast<RTC::RTCP::FeedbackPsRembPacket*>(afb);
2087
2105
 
2106
+ #ifdef MS_USE_BUILTIN_BWE
2107
+ // TODO: Pass the REMB bitrate to the built-in downlink BWE.
2108
+ (void)remb;
2109
+ #else
2088
2110
  // Pass it to the TCC client.
2089
2111
  if (this->tccClient && this->tccClient->GetBweType() == RTC::BweType::REMB)
2090
2112
  {
2091
2113
  this->tccClient->ReceiveEstimatedBitrate(remb->GetBitrate());
2092
2114
  }
2115
+ #endif
2093
2116
 
2094
2117
  break;
2095
2118
  }
@@ -2132,7 +2155,7 @@ namespace RTC
2132
2155
  if (
2133
2156
  !consumer && feedback->GetMessageType() != RTC::RTCP::FeedbackRtp::MessageType::TCC &&
2134
2157
  (feedback->GetMediaSsrc() != RTC::RTP::ProbationGenerator::Ssrc ||
2135
- !GetConsumerByRtxSsrc(feedback->GetMediaSsrc())))
2158
+ !GetConsumerByRtxSsrc(feedback->GetMediaSsrc())))
2136
2159
  {
2137
2160
  MS_DEBUG_TAG(
2138
2161
  rtcp,
@@ -2171,17 +2194,14 @@ namespace RTC
2171
2194
  {
2172
2195
  auto* feedback = static_cast<RTC::RTCP::FeedbackRtpTransportPacket*>(packet);
2173
2196
 
2197
+ #ifdef MS_USE_BUILTIN_BWE
2198
+ // TODO: Feed the transport-cc feedback to the built-in downlink BWE.
2199
+ (void)feedback;
2200
+ #else
2174
2201
  if (this->tccClient)
2175
2202
  {
2176
2203
  this->tccClient->ReceiveRtcpTransportFeedback(feedback);
2177
2204
  }
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
2205
  #endif
2186
2206
 
2187
2207
  break;
@@ -2222,7 +2242,7 @@ namespace RTC
2222
2242
  continue;
2223
2243
  }
2224
2244
 
2225
- producer->ReceiveRtcpSenderReport(report);
2245
+ producer->ReceiveRtcpSenderReport(report, receivedAtUs);
2226
2246
  }
2227
2247
 
2228
2248
  break;
@@ -2283,7 +2303,7 @@ namespace RTC
2283
2303
  continue;
2284
2304
  }
2285
2305
 
2286
- producer->ReceiveRtcpXrDelaySinceLastRr(ssrcInfo);
2306
+ producer->ReceiveRtcpXrDelaySinceLastRr(ssrcInfo, receivedAtUs);
2287
2307
  }
2288
2308
 
2289
2309
  break;
@@ -2297,7 +2317,7 @@ namespace RTC
2297
2317
  {
2298
2318
  auto* consumer = kv.second;
2299
2319
 
2300
- consumer->ReceiveRtcpXrReceiverReferenceTime(rrt);
2320
+ consumer->ReceiveRtcpXrReceiverReferenceTime(rrt, receivedAtUs);
2301
2321
  }
2302
2322
 
2303
2323
  break;
@@ -2320,7 +2340,7 @@ namespace RTC
2320
2340
  }
2321
2341
  }
2322
2342
 
2323
- void Transport::SendRtcp(uint64_t nowMs)
2343
+ void Transport::SendRtcp(int64_t nowUs)
2324
2344
  {
2325
2345
  MS_TRACE();
2326
2346
 
@@ -2329,7 +2349,7 @@ namespace RTC
2329
2349
  for (auto& kv : this->mapConsumers)
2330
2350
  {
2331
2351
  auto* consumer = kv.second;
2332
- auto rtcpAdded = consumer->GetRtcp(packet.get(), nowMs);
2352
+ auto rtcpAdded = consumer->GetRtcp(packet.get(), nowUs);
2333
2353
 
2334
2354
  // RTCP data couldn't be added because the Compound packet is full.
2335
2355
  // Send the RTCP compound packet and request for RTCP again.
@@ -2341,14 +2361,14 @@ namespace RTC
2341
2361
  packet.reset(new RTC::RTCP::CompoundPacket());
2342
2362
 
2343
2363
  // Retrieve the RTCP again.
2344
- consumer->GetRtcp(packet.get(), nowMs);
2364
+ consumer->GetRtcp(packet.get(), nowUs);
2345
2365
  }
2346
2366
  }
2347
2367
 
2348
2368
  for (auto& kv : this->mapProducers)
2349
2369
  {
2350
2370
  auto* producer = kv.second;
2351
- auto rtcpAdded = producer->GetRtcp(packet.get(), nowMs);
2371
+ auto rtcpAdded = producer->GetRtcp(packet.get(), nowUs);
2352
2372
 
2353
2373
  // RTCP data couldn't be added because the Compound packet is full.
2354
2374
  // Send the RTCP compound packet and request for RTCP again.
@@ -2360,7 +2380,7 @@ namespace RTC
2360
2380
  packet.reset(new RTC::RTCP::CompoundPacket());
2361
2381
 
2362
2382
  // Retrieve the RTCP again.
2363
- producer->GetRtcp(packet.get(), nowMs);
2383
+ producer->GetRtcp(packet.get(), nowUs);
2364
2384
  }
2365
2385
  }
2366
2386
 
@@ -2375,6 +2395,9 @@ namespace RTC
2375
2395
  {
2376
2396
  MS_TRACE();
2377
2397
 
2398
+ #ifdef MS_USE_BUILTIN_BWE
2399
+ // TODO: Distribute the bitrate the built-in downlink BWE reports.
2400
+ #else
2378
2401
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2379
2402
 
2380
2403
  std::multimap<uint8_t, RTC::Consumer*> multimapPriorityConsumer;
@@ -2397,18 +2420,18 @@ namespace RTC
2397
2420
  return;
2398
2421
  }
2399
2422
 
2400
- bool baseAllocation = true;
2401
- uint32_t availableBitrate = this->tccClient->GetAvailableBitrate();
2423
+ bool baseAllocation = true;
2424
+ int64_t availableBitrate = this->tccClient->GetAvailableBitrate();
2402
2425
 
2403
2426
  this->tccClient->RescheduleNextAvailableBitrateEvent();
2404
2427
 
2405
- MS_DEBUG_DEV("before layer-by-layer iterations [availableBitrate:%" PRIu32 "]", availableBitrate);
2428
+ MS_DEBUG_DEV("before layer-by-layer iterations [availableBitrate:%" PRIi64 "]", availableBitrate);
2406
2429
 
2407
2430
  // Redistribute the available bitrate by allowing Consumers to increase
2408
2431
  // layer by layer. Initially try to spread the bitrate across all
2409
2432
  // consumers. Then allocate the excess bitrate to Consumers starting
2410
2433
  // with the highest priorty.
2411
- while (availableBitrate > 0u)
2434
+ while (availableBitrate > 0)
2412
2435
  {
2413
2436
  auto previousAvailableBitrate = availableBitrate;
2414
2437
 
@@ -2421,17 +2444,15 @@ namespace RTC
2421
2444
  // NOLINTNEXTLINE(bugprone-too-small-loop-variable)
2422
2445
  for (uint8_t i{ 1u }; i <= (baseAllocation ? 1u : priority); ++i)
2423
2446
  {
2424
- uint32_t usedBitrate{ 0u };
2425
- const bool considerLoss = (bweType == RTC::BweType::REMB);
2426
-
2427
- usedBitrate = consumer->IncreaseLayer(availableBitrate, considerLoss);
2447
+ const bool considerLoss = (bweType == RTC::BweType::REMB);
2448
+ const int64_t usedBitrate = consumer->IncreaseLayer(availableBitrate, considerLoss);
2428
2449
 
2429
2450
  MS_ASSERT(usedBitrate <= availableBitrate, "Consumer used more layer bitrate than given");
2430
2451
 
2431
2452
  availableBitrate -= usedBitrate;
2432
2453
 
2433
- // Exit the loop fast if used bitrate is 0.
2434
- if (usedBitrate == 0u)
2454
+ // Exit the loop fast if no bitrate was used.
2455
+ if (usedBitrate <= 0)
2435
2456
  {
2436
2457
  break;
2437
2458
  }
@@ -2447,7 +2468,7 @@ namespace RTC
2447
2468
  baseAllocation = false;
2448
2469
  }
2449
2470
 
2450
- MS_DEBUG_DEV("after layer-by-layer iterations [availableBitrate:%" PRIu32 "]", availableBitrate);
2471
+ MS_DEBUG_DEV("after layer-by-layer iterations [availableBitrate:%" PRIi64 "]", availableBitrate);
2451
2472
 
2452
2473
  // Finally instruct Consumers to apply their computed layers.
2453
2474
  for (auto it = multimapPriorityConsumer.rbegin(); it != multimapPriorityConsumer.rend(); ++it)
@@ -2456,15 +2477,20 @@ namespace RTC
2456
2477
 
2457
2478
  consumer->ApplyLayers();
2458
2479
  }
2480
+ #endif
2459
2481
  }
2460
2482
 
2461
2483
  void Transport::ComputeOutgoingDesiredBitrate(bool forceBitrate)
2462
2484
  {
2463
2485
  MS_TRACE();
2464
2486
 
2487
+ #ifdef MS_USE_BUILTIN_BWE
2488
+ // TODO: Give the total desired bitrate to the built-in downlink BWE.
2489
+ (void)forceBitrate;
2490
+ #else
2465
2491
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2466
2492
 
2467
- uint32_t totalDesiredBitrate{ 0u };
2493
+ int64_t totalDesiredBitrate{ 0 };
2468
2494
 
2469
2495
  for (auto& kv : this->mapConsumers)
2470
2496
  {
@@ -2474,9 +2500,10 @@ namespace RTC
2474
2500
  totalDesiredBitrate += desiredBitrate;
2475
2501
  }
2476
2502
 
2477
- MS_DEBUG_DEV("total desired bitrate: %" PRIu32, totalDesiredBitrate);
2503
+ MS_DEBUG_DEV("total desired bitrate: %" PRIi64, totalDesiredBitrate);
2478
2504
 
2479
2505
  this->tccClient->SetDesiredBitrate(totalDesiredBitrate, forceBitrate);
2506
+ #endif
2480
2507
  }
2481
2508
 
2482
2509
  inline void Transport::EmitTraceEventProbationType(RTC::RTP::Packet* /*packet*/) const
@@ -2492,7 +2519,7 @@ namespace RTC
2492
2519
  auto notification = FBS::Transport::CreateTraceNotification(
2493
2520
  this->shared->GetChannelNotifier()->GetBufferBuilder(),
2494
2521
  FBS::Transport::TraceEventType::PROBATION,
2495
- this->shared->GetTimeMs(),
2522
+ static_cast<uint64_t>(this->shared->GetTimeMs()),
2496
2523
  FBS::Common::TraceDirection::DIRECTION_OUT);
2497
2524
 
2498
2525
  this->shared->GetChannelNotifier()->Emit(
@@ -2502,6 +2529,7 @@ namespace RTC
2502
2529
  notification);
2503
2530
  }
2504
2531
 
2532
+ #ifndef MS_USE_BUILTIN_BWE
2505
2533
  inline void Transport::EmitTraceEventBweType(
2506
2534
  RTC::TransportCongestionControlClient::Bitrates& bitrates) const
2507
2535
  {
@@ -2517,18 +2545,18 @@ namespace RTC
2517
2545
  this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC
2518
2546
  ? FBS::Transport::BweType::TRANSPORT_CC
2519
2547
  : 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);
2548
+ static_cast<uint64_t>(bitrates.desiredBitrate),
2549
+ static_cast<uint64_t>(bitrates.effectiveDesiredBitrate),
2550
+ static_cast<uint64_t>(bitrates.minBitrate),
2551
+ static_cast<uint64_t>(bitrates.maxBitrate),
2552
+ static_cast<uint64_t>(bitrates.startBitrate),
2553
+ static_cast<uint64_t>(bitrates.maxPaddingBitrate),
2554
+ static_cast<uint64_t>(bitrates.availableBitrate));
2527
2555
 
2528
2556
  auto notification = FBS::Transport::CreateTraceNotification(
2529
2557
  this->shared->GetChannelNotifier()->GetBufferBuilder(),
2530
2558
  FBS::Transport::TraceEventType::BWE,
2531
- this->shared->GetTimeMs(),
2559
+ static_cast<uint64_t>(this->shared->GetTimeMs()),
2532
2560
  FBS::Common::TraceDirection::DIRECTION_OUT,
2533
2561
  FBS::Transport::TraceInfo::BweTraceInfo,
2534
2562
  traceInfo.Union());
@@ -2539,6 +2567,7 @@ namespace RTC
2539
2567
  FBS::Notification::Body::Transport_TraceNotification,
2540
2568
  notification);
2541
2569
  }
2570
+ #endif
2542
2571
 
2543
2572
  void Transport::OnProducerPaused(RTC::Producer* producer)
2544
2573
  {
@@ -2589,6 +2618,15 @@ namespace RTC
2589
2618
  this->listener->OnTransportProducerRtcpSenderReport(this, producer, rtpStream, first);
2590
2619
  }
2591
2620
 
2621
+ void Transport::OnProducerSpatialLayerActivityChanged(
2622
+ RTC::Producer* producer, RTC::RTP::RtpStreamRecv* rtpStream, uint8_t spatialLayer, bool isActive)
2623
+ {
2624
+ MS_TRACE();
2625
+
2626
+ this->listener->OnTransportProducerSpatialLayerActivityChanged(
2627
+ this, producer, rtpStream, spatialLayer, isActive);
2628
+ }
2629
+
2592
2630
  void Transport::OnProducerRtpPacketReceived(RTC::Producer* producer, RTC::RTP::Packet* packet)
2593
2631
  {
2594
2632
  MS_TRACE();
@@ -2610,7 +2648,7 @@ namespace RTC
2610
2648
  return this->listener->OnTransportNeedWorstRemoteFractionLost(this, producer, mappedSsrc);
2611
2649
  }
2612
2650
 
2613
- std::optional<uint64_t> Transport::OnProducerNeedLocalCaptureMs(
2651
+ std::optional<int64_t> Transport::OnProducerNeedLocalCaptureAtUs(
2614
2652
  RTC::Producer* producer, const RTC::RTP::RtpStreamRecv* rtpStream, uint32_t ts)
2615
2653
  {
2616
2654
  MS_TRACE();
@@ -2625,10 +2663,10 @@ namespace RTC
2625
2663
 
2626
2664
  const auto& remoteCaptureTimeEstimator = it->second;
2627
2665
 
2628
- return remoteCaptureTimeEstimator.GetLocalCaptureMs(rtpStream, ts);
2666
+ return remoteCaptureTimeEstimator.GetLocalCaptureAtUs(rtpStream, ts);
2629
2667
  }
2630
2668
 
2631
- std::optional<int64_t> Transport::OnProducerNeedRemoteClockOffsetMs(const RTC::Producer* producer)
2669
+ std::optional<int64_t> Transport::OnProducerNeedRemoteClockOffsetUs(const RTC::Producer* producer)
2632
2670
  {
2633
2671
  MS_TRACE();
2634
2672
 
@@ -2641,9 +2679,9 @@ namespace RTC
2641
2679
  }
2642
2680
 
2643
2681
  const auto& remoteCaptureTimeEstimator = it->second;
2644
- const auto clockOffsetMs = remoteCaptureTimeEstimator.GetClockOffsetMs();
2682
+ const auto clockOffsetUs = remoteCaptureTimeEstimator.GetClockOffsetUs();
2645
2683
 
2646
- if (!clockOffsetMs.has_value())
2684
+ if (!clockOffsetUs.has_value())
2647
2685
  {
2648
2686
  return std::nullopt;
2649
2687
  }
@@ -2651,9 +2689,9 @@ namespace RTC
2651
2689
  // NOTE: The estimator gives the offset against our own monotonic clock, while what
2652
2690
  // a receiver reconstructs out of the Sender Reports we send is the clock we
2653
2691
  // 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
2692
+ // terms are huge and their sum is small, so they are added as microseconds before
2655
2693
  // anything scales them up.
2656
- return clockOffsetMs.value() + static_cast<int64_t>(this->shared->GetNtpOffsetMs());
2694
+ return clockOffsetUs.value() + this->shared->GetNtpOffsetUs();
2657
2695
  }
2658
2696
 
2659
2697
  void Transport::OnConsumerSendRtpPacket(RTC::Consumer* consumer, RTC::RTP::Packet* packet)
@@ -2666,8 +2704,13 @@ namespace RTC
2666
2704
  #endif
2667
2705
 
2668
2706
  // Update abs-send-time if present.
2669
- packet->UpdateAbsSendTime(this->shared->GetTimeMs());
2707
+ packet->UpdateAbsSendTime(this->shared->GetTimeUs());
2670
2708
 
2709
+ #ifdef MS_USE_BUILTIN_BWE
2710
+ // TODO: Write the transport wide sequence number the built-in downlink BWE
2711
+ // hands out and register the send in it.
2712
+ SendRtpPacket(consumer, packet);
2713
+ #else
2671
2714
  // Update transport wide sequence number if present.
2672
2715
  if (
2673
2716
  this->tccClient && this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC &&
@@ -2696,38 +2739,6 @@ namespace RTC
2696
2739
 
2697
2740
  auto* shared = this->shared;
2698
2741
 
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
2742
  const auto* cb = new onSendCallback(
2732
2743
  [tccClientWeakPtr, shared, packetInfo](bool sent)
2733
2744
  {
@@ -2737,18 +2748,18 @@ namespace RTC
2737
2748
 
2738
2749
  if (tccClient)
2739
2750
  {
2740
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2751
+ tccClient->PacketSent(packetInfo, shared->GetTimeUs());
2741
2752
  }
2742
2753
  }
2743
2754
  });
2744
2755
 
2745
2756
  SendRtpPacket(consumer, packet, cb);
2746
- #endif
2747
2757
  }
2748
2758
  else
2749
2759
  {
2750
2760
  SendRtpPacket(consumer, packet);
2751
2761
  }
2762
+ #endif
2752
2763
 
2753
2764
  this->sendRtpTransmission.Update(packet);
2754
2765
  }
@@ -2758,8 +2769,13 @@ namespace RTC
2758
2769
  MS_TRACE();
2759
2770
 
2760
2771
  // Update abs-send-time if present.
2761
- packet->UpdateAbsSendTime(this->shared->GetTimeMs());
2772
+ packet->UpdateAbsSendTime(this->shared->GetTimeUs());
2762
2773
 
2774
+ #ifdef MS_USE_BUILTIN_BWE
2775
+ // TODO: Write the transport wide sequence number the built-in downlink BWE
2776
+ // hands out and register the send in it.
2777
+ SendRtpPacket(consumer, packet);
2778
+ #else
2763
2779
  // Update transport wide sequence number if present.
2764
2780
  if (
2765
2781
  this->tccClient && this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC &&
@@ -2783,38 +2799,6 @@ namespace RTC
2783
2799
 
2784
2800
  auto* shared = this->shared;
2785
2801
 
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
2802
  const auto* cb = new onSendCallback(
2819
2803
  [tccClientWeakPtr, shared, packetInfo](bool sent)
2820
2804
  {
@@ -2824,18 +2808,18 @@ namespace RTC
2824
2808
 
2825
2809
  if (tccClient)
2826
2810
  {
2827
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2811
+ tccClient->PacketSent(packetInfo, shared->GetTimeUs());
2828
2812
  }
2829
2813
  }
2830
2814
  });
2831
2815
 
2832
2816
  SendRtpPacket(consumer, packet, cb);
2833
- #endif
2834
2817
  }
2835
2818
  else
2836
2819
  {
2837
2820
  SendRtpPacket(consumer, packet);
2838
2821
  }
2822
+ #endif
2839
2823
 
2840
2824
  this->sendRtxTransmission.Update(packet);
2841
2825
  }
@@ -2858,7 +2842,9 @@ namespace RTC
2858
2842
  {
2859
2843
  MS_TRACE();
2860
2844
 
2845
+ #ifndef MS_USE_BUILTIN_BWE
2861
2846
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2847
+ #endif
2862
2848
 
2863
2849
  DistributeAvailableOutgoingBitrate();
2864
2850
  ComputeOutgoingDesiredBitrate();
@@ -2868,7 +2854,9 @@ namespace RTC
2868
2854
  {
2869
2855
  MS_TRACE();
2870
2856
 
2857
+ #ifndef MS_USE_BUILTIN_BWE
2871
2858
  MS_ASSERT(this->tccClient, "no TransportCongestionClient");
2859
+ #endif
2872
2860
 
2873
2861
  DistributeAvailableOutgoingBitrate();
2874
2862
 
@@ -2908,10 +2896,14 @@ namespace RTC
2908
2896
  delete consumer;
2909
2897
 
2910
2898
  // This may be the latest active Consumer with BWE. If so we have to stop probation.
2899
+ #ifdef MS_USE_BUILTIN_BWE
2900
+ // TODO: Do it when the built-in downlink BWE is in place.
2901
+ #else
2911
2902
  if (this->tccClient)
2912
2903
  {
2913
2904
  ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true);
2914
2905
  }
2906
+ #endif
2915
2907
  }
2916
2908
 
2917
2909
  void Transport::OnDataProducerMessageReceived(
@@ -3391,13 +3383,14 @@ namespace RTC
3391
3383
  return IsConnected() && (!this->mapDataProducers.empty() || !this->mapDataConsumers.empty());
3392
3384
  }
3393
3385
 
3386
+ #ifndef MS_USE_BUILTIN_BWE
3394
3387
  void Transport::OnTransportCongestionControlClientBitrates(
3395
3388
  RTC::TransportCongestionControlClient* /*tccClient*/,
3396
3389
  RTC::TransportCongestionControlClient::Bitrates& bitrates)
3397
3390
  {
3398
3391
  MS_TRACE();
3399
3392
 
3400
- MS_DEBUG_DEV("outgoing available bitrate:%" PRIu32, bitrates.availableBitrate);
3393
+ MS_DEBUG_DEV("outgoing available bitrate:%" PRIi64, bitrates.availableBitrate);
3401
3394
 
3402
3395
  DistributeAvailableOutgoingBitrate();
3403
3396
  ComputeOutgoingDesiredBitrate();
@@ -3414,7 +3407,7 @@ namespace RTC
3414
3407
  MS_TRACE();
3415
3408
 
3416
3409
  // Update abs-send-time if present.
3417
- packet->UpdateAbsSendTime(this->shared->GetTimeMs());
3410
+ packet->UpdateAbsSendTime(this->shared->GetTimeUs());
3418
3411
 
3419
3412
  // Update transport wide sequence number if present.
3420
3413
  if (
@@ -3442,39 +3435,6 @@ namespace RTC
3442
3435
 
3443
3436
  auto* shared = this->shared;
3444
3437
 
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
3438
  const auto* cb = new onSendCallback(
3479
3439
  [tccClientWeakPtr, shared, packetInfo](bool sent)
3480
3440
  {
@@ -3484,13 +3444,12 @@ namespace RTC
3484
3444
 
3485
3445
  if (tccClient)
3486
3446
  {
3487
- tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
3447
+ tccClient->PacketSent(packetInfo, shared->GetTimeUs());
3488
3448
  }
3489
3449
  }
3490
3450
  });
3491
3451
 
3492
3452
  SendRtpPacket(nullptr, packet, cb);
3493
- #endif
3494
3453
  }
3495
3454
  else
3496
3455
  {
@@ -3503,7 +3462,7 @@ namespace RTC
3503
3462
  this->sendProbationTransmission.Update(packet);
3504
3463
 
3505
3464
  MS_DEBUG_DEV(
3506
- "probation sent [seq:%" PRIu16 ", wideSeq:%" PRIu16 ", size:%zu, bitrate:%" PRIu32 "]",
3465
+ "probation sent [seq:%" PRIu16 ", wideSeq:%" PRIu16 ", size:%zu, bitrate:%" PRIi64 "]",
3507
3466
  packet->GetSequenceNumber(),
3508
3467
  this->transportWideCcSeq,
3509
3468
  packet->GetLength(),
@@ -3519,24 +3478,6 @@ namespace RTC
3519
3478
 
3520
3479
  SendRtcpPacket(packet);
3521
3480
  }
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
3481
  #endif
3541
3482
 
3542
3483
  void Transport::OnTimer(TimerHandleInterface* timer)
@@ -3546,19 +3487,18 @@ namespace RTC
3546
3487
  // RTCP timer.
3547
3488
  if (timer == this->rtcpTimer)
3548
3489
  {
3549
- auto interval = static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs);
3550
- const uint64_t nowMs = this->shared->GetTimeMs();
3490
+ auto intervalMs = static_cast<int64_t>(RTC::RTCP::MaxVideoIntervalMs);
3551
3491
 
3552
- SendRtcp(nowMs);
3492
+ SendRtcp(this->shared->GetTimeUs());
3553
3493
 
3554
3494
  /*
3555
3495
  * The interval between RTCP packets is varied randomly over the range
3556
3496
  * [1.0, 1.5] times the calculated interval to avoid unintended
3557
3497
  * synchronization of all participants.
3558
3498
  */
3559
- interval *= static_cast<float>(Utils::Crypto::GetRandomUInt<uint16_t>(10, 15)) / 10;
3499
+ intervalMs *= static_cast<float>(Utils::Crypto::GetRandomUInt<uint16_t>(10, 15)) / 10;
3560
3500
 
3561
- this->rtcpTimer->Start(interval);
3501
+ this->rtcpTimer->Start(intervalMs);
3562
3502
  }
3563
3503
  }
3564
3504
  } // namespace RTC