mediasoup 3.19.21 → 3.20.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 (649) hide show
  1. package/node/lib/ActiveSpeakerObserver.js +34 -1
  2. package/node/lib/AudioLevelObserver.js +35 -2
  3. package/node/lib/Channel.d.ts.map +1 -1
  4. package/node/lib/Channel.js +37 -5
  5. package/node/lib/Consumer.js +39 -6
  6. package/node/lib/DataConsumer.d.ts.map +1 -1
  7. package/node/lib/DataConsumer.js +39 -5
  8. package/node/lib/DataConsumerTypes.d.ts +1 -0
  9. package/node/lib/DataConsumerTypes.d.ts.map +1 -1
  10. package/node/lib/DataProducer.js +37 -4
  11. package/node/lib/DirectTransport.js +37 -4
  12. package/node/lib/DirectTransportTypes.d.ts +7 -2
  13. package/node/lib/DirectTransportTypes.d.ts.map +1 -1
  14. package/node/lib/Logger.js +4 -1
  15. package/node/lib/PipeTransport.d.ts +3 -1
  16. package/node/lib/PipeTransport.d.ts.map +1 -1
  17. package/node/lib/PipeTransport.js +56 -5
  18. package/node/lib/PipeTransportTypes.d.ts +28 -8
  19. package/node/lib/PipeTransportTypes.d.ts.map +1 -1
  20. package/node/lib/PlainTransport.d.ts +3 -1
  21. package/node/lib/PlainTransport.d.ts.map +1 -1
  22. package/node/lib/PlainTransport.js +54 -3
  23. package/node/lib/PlainTransportTypes.d.ts +27 -7
  24. package/node/lib/PlainTransportTypes.d.ts.map +1 -1
  25. package/node/lib/Producer.js +40 -7
  26. package/node/lib/Router.d.ts +5 -5
  27. package/node/lib/Router.d.ts.map +1 -1
  28. package/node/lib/Router.js +81 -36
  29. package/node/lib/RouterTypes.d.ts +25 -3
  30. package/node/lib/RouterTypes.d.ts.map +1 -1
  31. package/node/lib/RtpObserver.js +36 -3
  32. package/node/lib/Transport.d.ts +3 -1
  33. package/node/lib/Transport.d.ts.map +1 -1
  34. package/node/lib/Transport.js +74 -22
  35. package/node/lib/TransportTypes.d.ts +2 -1
  36. package/node/lib/TransportTypes.d.ts.map +1 -1
  37. package/node/lib/WebRtcServer.js +36 -3
  38. package/node/lib/WebRtcTransport.d.ts +3 -1
  39. package/node/lib/WebRtcTransport.d.ts.map +1 -1
  40. package/node/lib/WebRtcTransport.js +55 -4
  41. package/node/lib/WebRtcTransportTypes.d.ts +27 -7
  42. package/node/lib/WebRtcTransportTypes.d.ts.map +1 -1
  43. package/node/lib/Worker.d.ts +2 -1
  44. package/node/lib/Worker.d.ts.map +1 -1
  45. package/node/lib/Worker.js +71 -25
  46. package/node/lib/WorkerTypes.d.ts +0 -4
  47. package/node/lib/WorkerTypes.d.ts.map +1 -1
  48. package/node/lib/enhancedEvents.d.ts +2 -2
  49. package/node/lib/enhancedEvents.d.ts.map +1 -1
  50. package/node/lib/enhancedEvents.js +0 -2
  51. package/node/lib/fbs/active-speaker-observer/active-speaker-observer-options.js +34 -1
  52. package/node/lib/fbs/active-speaker-observer/dominant-speaker-notification.js +34 -1
  53. package/node/lib/fbs/audio-level-observer/audio-level-observer-options.js +34 -1
  54. package/node/lib/fbs/audio-level-observer/volume.js +34 -1
  55. package/node/lib/fbs/audio-level-observer/volumes-notification.js +34 -1
  56. package/node/lib/fbs/common/string-string-array.js +34 -1
  57. package/node/lib/fbs/common/string-string.js +34 -1
  58. package/node/lib/fbs/common/string-uint8.js +34 -1
  59. package/node/lib/fbs/common/uint16-string.js +34 -1
  60. package/node/lib/fbs/common/uint32-string.js +34 -1
  61. package/node/lib/fbs/consumer/base-consumer-dump.js +34 -1
  62. package/node/lib/fbs/consumer/consumer-dump.js +34 -1
  63. package/node/lib/fbs/consumer/consumer-layers.js +34 -1
  64. package/node/lib/fbs/consumer/consumer-score.js +34 -1
  65. package/node/lib/fbs/consumer/dump-response.js +34 -1
  66. package/node/lib/fbs/consumer/enable-trace-event-request.js +34 -1
  67. package/node/lib/fbs/consumer/fir-trace-info.js +34 -1
  68. package/node/lib/fbs/consumer/get-stats-response.js +34 -1
  69. package/node/lib/fbs/consumer/key-frame-trace-info.js +34 -1
  70. package/node/lib/fbs/consumer/layers-change-notification.js +34 -1
  71. package/node/lib/fbs/consumer/pli-trace-info.js +34 -1
  72. package/node/lib/fbs/consumer/rtp-notification.js +34 -1
  73. package/node/lib/fbs/consumer/rtp-trace-info.js +34 -1
  74. package/node/lib/fbs/consumer/score-notification.js +34 -1
  75. package/node/lib/fbs/consumer/set-preferred-layers-request.js +34 -1
  76. package/node/lib/fbs/consumer/set-preferred-layers-response.js +34 -1
  77. package/node/lib/fbs/consumer/set-priority-request.js +34 -1
  78. package/node/lib/fbs/consumer/set-priority-response.js +34 -1
  79. package/node/lib/fbs/consumer/trace-notification.js +34 -1
  80. package/node/lib/fbs/data-consumer/add-subchannel-request.js +34 -1
  81. package/node/lib/fbs/data-consumer/add-subchannel-response.js +34 -1
  82. package/node/lib/fbs/data-consumer/buffered-amount-low-notification.js +34 -1
  83. package/node/lib/fbs/data-consumer/dump-response.d.ts +5 -2
  84. package/node/lib/fbs/data-consumer/dump-response.d.ts.map +1 -1
  85. package/node/lib/fbs/data-consumer/dump-response.js +60 -16
  86. package/node/lib/fbs/data-consumer/get-buffered-amount-response.js +34 -1
  87. package/node/lib/fbs/data-consumer/get-stats-response.js +34 -1
  88. package/node/lib/fbs/data-consumer/message-notification.js +34 -1
  89. package/node/lib/fbs/data-consumer/remove-subchannel-request.js +34 -1
  90. package/node/lib/fbs/data-consumer/remove-subchannel-response.js +34 -1
  91. package/node/lib/fbs/data-consumer/send-request.js +34 -1
  92. package/node/lib/fbs/data-consumer/set-buffered-amount-low-threshold-request.js +34 -1
  93. package/node/lib/fbs/data-consumer/set-subchannels-request.js +34 -1
  94. package/node/lib/fbs/data-consumer/set-subchannels-response.js +34 -1
  95. package/node/lib/fbs/data-consumer/type.d.ts +5 -0
  96. package/node/lib/fbs/data-consumer/type.d.ts.map +1 -0
  97. package/node/lib/fbs/data-consumer/type.js +10 -0
  98. package/node/lib/fbs/data-consumer.d.ts +1 -0
  99. package/node/lib/fbs/data-consumer.d.ts.map +1 -1
  100. package/node/lib/fbs/data-consumer.js +3 -1
  101. package/node/lib/fbs/data-producer/dump-response.js +34 -1
  102. package/node/lib/fbs/data-producer/get-stats-response.js +34 -1
  103. package/node/lib/fbs/data-producer/send-notification.js +34 -1
  104. package/node/lib/fbs/direct-transport/direct-transport-options.js +34 -1
  105. package/node/lib/fbs/direct-transport/dump-response.js +34 -1
  106. package/node/lib/fbs/direct-transport/get-stats-response.js +34 -1
  107. package/node/lib/fbs/direct-transport/rtcp-notification.js +34 -1
  108. package/node/lib/fbs/lib-uring/dump.js +34 -1
  109. package/node/lib/fbs/log/log.js +34 -1
  110. package/node/lib/fbs/message/message.js +34 -1
  111. package/node/lib/fbs/notification/body.d.ts +24 -22
  112. package/node/lib/fbs/notification/body.d.ts.map +1 -1
  113. package/node/lib/fbs/notification/body.js +24 -20
  114. package/node/lib/fbs/notification/event.d.ts +27 -26
  115. package/node/lib/fbs/notification/event.d.ts.map +1 -1
  116. package/node/lib/fbs/notification/event.js +27 -26
  117. package/node/lib/fbs/notification/notification.d.ts +3 -2
  118. package/node/lib/fbs/notification/notification.d.ts.map +1 -1
  119. package/node/lib/fbs/notification/notification.js +34 -1
  120. package/node/lib/fbs/pipe-transport/connect-request.js +34 -1
  121. package/node/lib/fbs/pipe-transport/connect-response.js +34 -1
  122. package/node/lib/fbs/pipe-transport/dump-response.js +34 -1
  123. package/node/lib/fbs/pipe-transport/get-stats-response.js +34 -1
  124. package/node/lib/fbs/pipe-transport/pipe-transport-options.js +34 -1
  125. package/node/lib/fbs/plain-transport/connect-request.js +34 -1
  126. package/node/lib/fbs/plain-transport/connect-response.js +34 -1
  127. package/node/lib/fbs/plain-transport/dump-response.js +34 -1
  128. package/node/lib/fbs/plain-transport/get-stats-response.js +34 -1
  129. package/node/lib/fbs/plain-transport/plain-transport-options.js +34 -1
  130. package/node/lib/fbs/plain-transport/rtcp-tuple-notification.js +34 -1
  131. package/node/lib/fbs/plain-transport/tuple-notification.js +34 -1
  132. package/node/lib/fbs/producer/dump-response.js +34 -1
  133. package/node/lib/fbs/producer/enable-trace-event-request.js +34 -1
  134. package/node/lib/fbs/producer/fir-trace-info.js +34 -1
  135. package/node/lib/fbs/producer/get-stats-response.js +34 -1
  136. package/node/lib/fbs/producer/key-frame-trace-info.js +34 -1
  137. package/node/lib/fbs/producer/pli-trace-info.js +34 -1
  138. package/node/lib/fbs/producer/rtp-trace-info.js +34 -1
  139. package/node/lib/fbs/producer/score-notification.js +34 -1
  140. package/node/lib/fbs/producer/score.js +34 -1
  141. package/node/lib/fbs/producer/send-notification.js +34 -1
  142. package/node/lib/fbs/producer/sr-trace-info.js +34 -1
  143. package/node/lib/fbs/producer/trace-notification.js +34 -1
  144. package/node/lib/fbs/producer/video-orientation-change-notification.js +34 -1
  145. package/node/lib/fbs/request/request.js +34 -1
  146. package/node/lib/fbs/response/response.js +34 -1
  147. package/node/lib/fbs/router/close-rtp-observer-request.js +34 -1
  148. package/node/lib/fbs/router/close-transport-request.js +34 -1
  149. package/node/lib/fbs/router/create-active-speaker-observer-request.js +34 -1
  150. package/node/lib/fbs/router/create-audio-level-observer-request.js +34 -1
  151. package/node/lib/fbs/router/create-direct-transport-request.js +34 -1
  152. package/node/lib/fbs/router/create-pipe-transport-request.js +34 -1
  153. package/node/lib/fbs/router/create-plain-transport-request.js +34 -1
  154. package/node/lib/fbs/router/create-web-rtc-transport-request.js +34 -1
  155. package/node/lib/fbs/router/dump-response.js +34 -1
  156. package/node/lib/fbs/rtp-observer/add-producer-request.js +34 -1
  157. package/node/lib/fbs/rtp-observer/remove-producer-request.js +34 -1
  158. package/node/lib/fbs/rtp-packet/dump.js +34 -1
  159. package/node/lib/fbs/rtp-parameters/boolean.js +34 -1
  160. package/node/lib/fbs/rtp-parameters/codec-mapping.js +34 -1
  161. package/node/lib/fbs/rtp-parameters/double.js +34 -1
  162. package/node/lib/fbs/rtp-parameters/encoding-mapping.js +34 -1
  163. package/node/lib/fbs/rtp-parameters/integer32-array.js +34 -1
  164. package/node/lib/fbs/rtp-parameters/integer32.js +34 -1
  165. package/node/lib/fbs/rtp-parameters/parameter.js +34 -1
  166. package/node/lib/fbs/rtp-parameters/rtcp-feedback.js +34 -1
  167. package/node/lib/fbs/rtp-parameters/rtcp-parameters.js +34 -1
  168. package/node/lib/fbs/rtp-parameters/rtp-codec-parameters.js +34 -1
  169. package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.js +34 -1
  170. package/node/lib/fbs/rtp-parameters/rtp-header-extension-parameters.js +34 -1
  171. package/node/lib/fbs/rtp-parameters/rtp-mapping.js +34 -1
  172. package/node/lib/fbs/rtp-parameters/rtp-parameters.js +34 -1
  173. package/node/lib/fbs/rtp-parameters/rtx.js +34 -1
  174. package/node/lib/fbs/rtp-parameters/string.js +34 -1
  175. package/node/lib/fbs/rtp-stream/base-stats.js +34 -1
  176. package/node/lib/fbs/rtp-stream/bitrate-by-layer.js +34 -1
  177. package/node/lib/fbs/rtp-stream/dump.js +34 -1
  178. package/node/lib/fbs/rtp-stream/params.js +34 -1
  179. package/node/lib/fbs/rtp-stream/recv-stats.js +34 -1
  180. package/node/lib/fbs/rtp-stream/send-stats.js +34 -1
  181. package/node/lib/fbs/rtp-stream/stats.js +34 -1
  182. package/node/lib/fbs/rtx-stream/params.js +34 -1
  183. package/node/lib/fbs/rtx-stream/rtx-dump.js +34 -1
  184. package/node/lib/fbs/sctp-association/sctp-negotiated-capabilities.d.ts +24 -0
  185. package/node/lib/fbs/sctp-association/sctp-negotiated-capabilities.d.ts.map +1 -0
  186. package/node/lib/fbs/sctp-association/sctp-negotiated-capabilities.js +102 -0
  187. package/node/lib/fbs/sctp-association.d.ts +1 -0
  188. package/node/lib/fbs/sctp-association.d.ts.map +1 -1
  189. package/node/lib/fbs/sctp-association.js +4 -1
  190. package/node/lib/fbs/sctp-parameters/num-sctp-streams.js +34 -1
  191. package/node/lib/fbs/sctp-parameters/sctp-parameters.d.ts +14 -14
  192. package/node/lib/fbs/sctp-parameters/sctp-parameters.d.ts.map +1 -1
  193. package/node/lib/fbs/sctp-parameters/sctp-parameters.js +73 -40
  194. package/node/lib/fbs/sctp-parameters/sctp-stream-parameters.js +34 -1
  195. package/node/lib/fbs/sctp-parameters.d.ts +0 -1
  196. package/node/lib/fbs/sctp-parameters.d.ts.map +1 -1
  197. package/node/lib/fbs/sctp-parameters.js +1 -4
  198. package/node/lib/fbs/srtp-parameters/srtp-parameters.js +34 -1
  199. package/node/lib/fbs/transport/bwe-trace-info.js +34 -1
  200. package/node/lib/fbs/transport/close-consumer-request.js +34 -1
  201. package/node/lib/fbs/transport/close-data-consumer-request.js +34 -1
  202. package/node/lib/fbs/transport/close-data-producer-request.js +34 -1
  203. package/node/lib/fbs/transport/close-producer-request.js +34 -1
  204. package/node/lib/fbs/transport/consume-data-request.d.ts +1 -1
  205. package/node/lib/fbs/transport/consume-data-request.js +35 -2
  206. package/node/lib/fbs/transport/consume-request.js +34 -1
  207. package/node/lib/fbs/transport/consume-response.js +34 -1
  208. package/node/lib/fbs/transport/dump.d.ts +7 -4
  209. package/node/lib/fbs/transport/dump.d.ts.map +1 -1
  210. package/node/lib/fbs/transport/dump.js +66 -22
  211. package/node/lib/fbs/transport/enable-trace-event-request.js +34 -1
  212. package/node/lib/fbs/transport/listen-info.js +34 -1
  213. package/node/lib/fbs/transport/options.d.ts +14 -14
  214. package/node/lib/fbs/transport/options.d.ts.map +1 -1
  215. package/node/lib/fbs/transport/options.js +92 -51
  216. package/node/lib/fbs/transport/port-range.js +34 -1
  217. package/node/lib/fbs/transport/produce-data-request.js +34 -1
  218. package/node/lib/fbs/transport/produce-request.js +34 -1
  219. package/node/lib/fbs/transport/produce-response.js +34 -1
  220. package/node/lib/fbs/transport/recv-rtp-header-extensions.js +34 -1
  221. package/node/lib/fbs/transport/restart-ice-response.js +34 -1
  222. package/node/lib/fbs/transport/rtp-listener.js +34 -1
  223. package/node/lib/fbs/transport/sctp-listener.js +34 -1
  224. package/node/lib/fbs/transport/sctp-negotiated-capabilities-notification.d.ts +22 -0
  225. package/node/lib/fbs/transport/sctp-negotiated-capabilities-notification.d.ts.map +1 -0
  226. package/node/lib/fbs/transport/sctp-negotiated-capabilities-notification.js +93 -0
  227. package/node/lib/fbs/transport/sctp-state-change-notification.js +34 -1
  228. package/node/lib/fbs/transport/send-rtcp-notification.js +34 -1
  229. package/node/lib/fbs/transport/set-max-incoming-bitrate-request.js +34 -1
  230. package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.js +34 -1
  231. package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.js +34 -1
  232. package/node/lib/fbs/transport/socket-flags.js +34 -1
  233. package/node/lib/fbs/transport/stats.js +34 -1
  234. package/node/lib/fbs/transport/trace-notification.js +34 -1
  235. package/node/lib/fbs/transport/tuple.js +34 -1
  236. package/node/lib/fbs/transport.d.ts +1 -0
  237. package/node/lib/fbs/transport.d.ts.map +1 -1
  238. package/node/lib/fbs/transport.js +5 -2
  239. package/node/lib/fbs/web-rtc-server/dump-response.js +34 -1
  240. package/node/lib/fbs/web-rtc-server/ice-user-name-fragment.js +34 -1
  241. package/node/lib/fbs/web-rtc-server/ip-port.js +34 -1
  242. package/node/lib/fbs/web-rtc-server/tuple-hash.js +34 -1
  243. package/node/lib/fbs/web-rtc-transport/connect-request.js +34 -1
  244. package/node/lib/fbs/web-rtc-transport/connect-response.js +34 -1
  245. package/node/lib/fbs/web-rtc-transport/dtls-parameters.js +34 -1
  246. package/node/lib/fbs/web-rtc-transport/dtls-state-change-notification.js +34 -1
  247. package/node/lib/fbs/web-rtc-transport/dump-response.js +34 -1
  248. package/node/lib/fbs/web-rtc-transport/fingerprint.js +34 -1
  249. package/node/lib/fbs/web-rtc-transport/get-stats-response.js +34 -1
  250. package/node/lib/fbs/web-rtc-transport/ice-candidate.js +34 -1
  251. package/node/lib/fbs/web-rtc-transport/ice-parameters.js +34 -1
  252. package/node/lib/fbs/web-rtc-transport/ice-selected-tuple-change-notification.js +34 -1
  253. package/node/lib/fbs/web-rtc-transport/ice-state-change-notification.js +34 -1
  254. package/node/lib/fbs/web-rtc-transport/listen-individual.js +34 -1
  255. package/node/lib/fbs/web-rtc-transport/listen-server.js +34 -1
  256. package/node/lib/fbs/web-rtc-transport/web-rtc-transport-options.js +34 -1
  257. package/node/lib/fbs/worker/channel-message-handlers.js +34 -1
  258. package/node/lib/fbs/worker/close-router-request.js +34 -1
  259. package/node/lib/fbs/worker/close-web-rtc-server-request.js +34 -1
  260. package/node/lib/fbs/worker/create-router-request.js +34 -1
  261. package/node/lib/fbs/worker/create-web-rtc-server-request.js +34 -1
  262. package/node/lib/fbs/worker/dump-response.js +34 -1
  263. package/node/lib/fbs/worker/resource-usage-response.js +34 -1
  264. package/node/lib/fbs/worker/update-settings-request.js +34 -1
  265. package/node/lib/index.d.ts +1 -1
  266. package/node/lib/index.d.ts.map +1 -1
  267. package/node/lib/index.js +37 -5
  268. package/node/lib/ortc.js +36 -3
  269. package/node/lib/rtpParametersFbsUtils.js +34 -1
  270. package/node/lib/rtpStreamStatsFbsUtils.js +35 -2
  271. package/node/lib/sctpParametersFbsUtils.d.ts +2 -2
  272. package/node/lib/sctpParametersFbsUtils.d.ts.map +1 -1
  273. package/node/lib/sctpParametersFbsUtils.js +44 -7
  274. package/node/lib/sctpParametersTypes.d.ts +10 -46
  275. package/node/lib/sctpParametersTypes.d.ts.map +1 -1
  276. package/node/lib/srtpParametersFbsUtils.js +34 -1
  277. package/node/lib/test/test-ActiveSpeakerObserver.js +35 -2
  278. package/node/lib/test/test-AudioLevelObserver.js +35 -2
  279. package/node/lib/test/test-Consumer.js +37 -4
  280. package/node/lib/test/test-DataConsumer.js +35 -2
  281. package/node/lib/test/test-DataProducer.js +35 -2
  282. package/node/lib/test/test-DirectTransport.js +36 -8
  283. package/node/lib/test/test-PipeTransport.js +35 -2
  284. package/node/lib/test/test-PlainTransport.js +45 -12
  285. package/node/lib/test/test-Producer.js +37 -4
  286. package/node/lib/test/test-Router.js +35 -2
  287. package/node/lib/test/test-WebRtcServer.js +34 -1
  288. package/node/lib/test/test-WebRtcTransport.js +51 -22
  289. package/node/lib/test/test-Worker.js +37 -4
  290. package/node/lib/test/test-mediasoup.js +36 -3
  291. package/node/lib/test/test-multiopus.js +35 -2
  292. package/node/lib/test/test-ortc.js +34 -1
  293. package/node/lib/test/test-werift-sctp.js +39 -5
  294. package/npm-scripts.mjs +2 -2
  295. package/package.json +13 -11
  296. package/worker/deps/libwebrtc/LICENSE +5 -0
  297. package/worker/deps/libwebrtc/README.md +3 -3
  298. package/worker/deps/libwebrtc/libwebrtc/mediasoup_helpers.h +13 -10
  299. package/worker/fbs/dataConsumer.fbs +7 -2
  300. package/worker/fbs/dataProducer.fbs +1 -0
  301. package/worker/fbs/notification.fbs +2 -0
  302. package/worker/fbs/sctpAssociation.fbs +4 -0
  303. package/worker/fbs/sctpParameters.fbs +5 -12
  304. package/worker/fbs/transport.fbs +12 -8
  305. package/worker/fuzzer/src/RTC/FuzzerDtlsTransport.cpp +13 -3
  306. package/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp +2 -2
  307. package/worker/fuzzer/src/RTC/FuzzerSeqManager.cpp +1 -1
  308. package/worker/fuzzer/src/RTC/FuzzerTrendCalculator.cpp +5 -5
  309. package/worker/fuzzer/src/RTC/ICE/FuzzerStunPacket.cpp +9 -6
  310. package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +1 -1
  311. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +14 -2
  312. package/worker/fuzzer/src/RTC/SCTP/association/FuzzerStateCookie.cpp +1 -1
  313. package/worker/fuzzer/src/RTC/SCTP/packet/FuzzerPacket.cpp +5 -2
  314. package/worker/fuzzer/src/fuzzer.cpp +3 -10
  315. package/worker/include/Channel/ChannelMessageRegistrator.hpp +39 -0
  316. package/worker/include/Channel/ChannelMessageRegistratorInterface.hpp +32 -0
  317. package/worker/include/Channel/ChannelRequest.hpp +1 -1
  318. package/worker/include/Channel/ChannelSocket.hpp +1 -1
  319. package/worker/include/DepLibUV.hpp +1 -1
  320. package/worker/include/DepLibUring.hpp +3 -3
  321. package/worker/include/Logger.hpp +4 -4
  322. package/worker/include/MediaSoupErrors.hpp +1 -1
  323. package/worker/include/RTC/ActiveSpeakerObserver.hpp +11 -9
  324. package/worker/include/RTC/AudioLevelObserver.hpp +7 -7
  325. package/worker/include/RTC/Consumer.hpp +3 -3
  326. package/worker/include/RTC/DataConsumer.hpp +13 -17
  327. package/worker/include/RTC/DataProducer.hpp +6 -9
  328. package/worker/include/RTC/DirectTransport.hpp +4 -6
  329. package/worker/include/RTC/DtlsTransport.hpp +13 -11
  330. package/worker/include/RTC/ICE/IceServer.hpp +8 -5
  331. package/worker/include/RTC/ICE/StunPacket.hpp +1 -1
  332. package/worker/include/RTC/KeyFrameRequestManager.hpp +15 -12
  333. package/worker/include/RTC/NackGenerator.hpp +8 -6
  334. package/worker/include/RTC/PipeConsumer.hpp +1 -2
  335. package/worker/include/RTC/PipeTransport.hpp +4 -6
  336. package/worker/include/RTC/PlainTransport.hpp +4 -6
  337. package/worker/include/RTC/PortManager.hpp +1 -1
  338. package/worker/include/RTC/Producer.hpp +3 -3
  339. package/worker/include/RTC/RTCP/FeedbackPs.hpp +1 -1
  340. package/worker/include/RTC/RTCP/FeedbackRtp.hpp +1 -1
  341. package/worker/include/RTC/RTCP/FeedbackRtpNack.hpp +1 -1
  342. package/worker/include/RTC/RTCP/ReceiverReport.hpp +1 -1
  343. package/worker/include/RTC/RTP/Packet.hpp +2 -2
  344. package/worker/include/RTC/RTP/RtpStream.hpp +17 -12
  345. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +8 -6
  346. package/worker/include/RTC/RTP/RtpStreamSend.hpp +4 -1
  347. package/worker/include/RTC/RTP/RtxStream.hpp +3 -1
  348. package/worker/include/RTC/RTP/SharedPacket.hpp +1 -1
  349. package/worker/include/RTC/RateCalculator.hpp +5 -2
  350. package/worker/include/RTC/Router.hpp +7 -8
  351. package/worker/include/RTC/RtpObserver.hpp +3 -3
  352. package/worker/include/RTC/SCTP/association/Association.hpp +53 -19
  353. package/worker/include/RTC/SCTP/association/AssociationListenerDeferrer.hpp +14 -6
  354. package/worker/include/RTC/SCTP/association/HeartbeatHandler.hpp +18 -14
  355. package/worker/include/RTC/SCTP/association/PacketSender.hpp +3 -3
  356. package/worker/include/RTC/SCTP/association/StateCookie.hpp +1 -1
  357. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +49 -35
  358. package/worker/include/RTC/SCTP/association/TransmissionControlBlock.hpp +114 -31
  359. package/worker/include/RTC/SCTP/association/{TCBContext.hpp → TransmissionControlBlockContextInterface.hpp} +14 -8
  360. package/worker/include/RTC/SCTP/packet/Chunk.hpp +3 -3
  361. package/worker/include/RTC/SCTP/packet/TLV.hpp +1 -1
  362. package/worker/include/RTC/SCTP/packet/UserData.hpp +61 -17
  363. package/worker/include/RTC/SCTP/packet/chunks/AnyDataChunk.hpp +1 -1
  364. package/worker/include/RTC/SCTP/packet/chunks/AnyForwardTsnChunk.hpp +9 -9
  365. package/worker/include/RTC/SCTP/packet/chunks/AnyInitChunk.hpp +1 -1
  366. package/worker/include/RTC/SCTP/packet/chunks/DataChunk.hpp +4 -2
  367. package/worker/include/RTC/SCTP/packet/chunks/ForwardTsnChunk.hpp +3 -3
  368. package/worker/include/RTC/SCTP/packet/chunks/IDataChunk.hpp +4 -2
  369. package/worker/include/RTC/SCTP/packet/chunks/IForwardTsnChunk.hpp +3 -3
  370. package/worker/include/RTC/SCTP/packet/chunks/InitAckChunk.hpp +1 -1
  371. package/worker/include/RTC/SCTP/packet/chunks/InitChunk.hpp +1 -1
  372. package/worker/include/RTC/SCTP/packet/chunks/SackChunk.hpp +10 -3
  373. package/worker/include/RTC/SCTP/packet/chunks/ShutdownChunk.hpp +1 -1
  374. package/worker/include/RTC/SCTP/packet/errorCauses/InvalidStreamIdentifierErrorCause.hpp +1 -1
  375. package/worker/include/RTC/SCTP/packet/errorCauses/MissingMandatoryParameterErrorCause.hpp +1 -1
  376. package/worker/include/RTC/SCTP/packet/errorCauses/NoUserDataErrorCause.hpp +1 -1
  377. package/worker/include/RTC/SCTP/packet/errorCauses/StaleCookieErrorCause.hpp +1 -1
  378. package/worker/include/RTC/SCTP/packet/parameters/AddIncomingStreamsRequestParameter.hpp +1 -1
  379. package/worker/include/RTC/SCTP/packet/parameters/AddOutgoingStreamsRequestParameter.hpp +1 -1
  380. package/worker/include/RTC/SCTP/packet/parameters/CookiePreservativeParameter.hpp +1 -1
  381. package/worker/include/RTC/SCTP/packet/parameters/IncomingSsnResetRequestParameter.hpp +1 -1
  382. package/worker/include/RTC/SCTP/packet/parameters/OutgoingSsnResetRequestParameter.hpp +1 -1
  383. package/worker/include/RTC/SCTP/packet/parameters/ReconfigurationResponseParameter.hpp +1 -1
  384. package/worker/include/RTC/SCTP/packet/parameters/SsnTsnResetRequestParameter.hpp +1 -1
  385. package/worker/include/RTC/SCTP/packet/parameters/SupportedAddressTypesParameter.hpp +1 -1
  386. package/worker/include/RTC/SCTP/packet/parameters/SupportedExtensionsParameter.hpp +1 -1
  387. package/worker/include/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.hpp +1 -1
  388. package/worker/include/RTC/SCTP/public/AssociationInterface.hpp +22 -2
  389. package/worker/include/RTC/SCTP/public/{AssociationListener.hpp → AssociationListenerInterface.hpp} +5 -5
  390. package/worker/include/RTC/SCTP/public/Message.hpp +26 -10
  391. package/worker/include/RTC/SCTP/public/SctpOptions.hpp +28 -19
  392. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +21 -0
  393. package/worker/include/RTC/SCTP/rx/DataTracker.hpp +277 -0
  394. package/worker/include/RTC/SCTP/rx/InterleavedReassemblyStreams.hpp +116 -0
  395. package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +202 -0
  396. package/worker/include/RTC/SCTP/rx/ReassemblyStreamsInterface.hpp +83 -0
  397. package/worker/include/RTC/SCTP/rx/TraditionalReassemblyStreams.hpp +183 -0
  398. package/worker/include/RTC/SCTP/tx/OutstandingData.hpp +595 -0
  399. package/worker/include/RTC/SCTP/tx/RetransmissionErrorCounter.hpp +3 -3
  400. package/worker/include/RTC/SCTP/tx/RetransmissionQueue.hpp +329 -0
  401. package/worker/include/RTC/SCTP/tx/RetransmissionTimeout.hpp +11 -10
  402. package/worker/include/RTC/SCTP/tx/RoundRobinSendQueue.hpp +356 -0
  403. package/worker/include/RTC/SCTP/tx/SendQueueInterface.hpp +180 -0
  404. package/worker/include/RTC/SCTP/tx/StreamScheduler.hpp +235 -0
  405. package/worker/include/RTC/SenderBandwidthEstimator.hpp +5 -1
  406. package/worker/include/RTC/Serializable.hpp +11 -3
  407. package/worker/include/RTC/SimpleConsumer.hpp +1 -2
  408. package/worker/include/RTC/SimulcastConsumer.hpp +1 -2
  409. package/worker/include/RTC/SvcConsumer.hpp +1 -2
  410. package/worker/include/RTC/TcpServer.hpp +2 -2
  411. package/worker/include/RTC/Transport.hpp +65 -86
  412. package/worker/include/RTC/TransportCongestionControlClient.hpp +8 -5
  413. package/worker/include/RTC/TransportCongestionControlServer.hpp +8 -5
  414. package/worker/include/RTC/TransportTuple.hpp +1 -1
  415. package/worker/include/RTC/UdpSocket.hpp +1 -1
  416. package/worker/include/RTC/WebRtcServer.hpp +3 -3
  417. package/worker/include/RTC/WebRtcTransport.hpp +5 -7
  418. package/worker/include/Settings.hpp +2 -3
  419. package/worker/include/Shared.hpp +64 -0
  420. package/worker/include/SharedInterface.hpp +77 -0
  421. package/worker/include/Utils/UnwrappedSequenceNumber.hpp +270 -0
  422. package/worker/include/Utils.hpp +10 -4
  423. package/worker/include/Worker.hpp +6 -6
  424. package/worker/include/common.hpp +12 -12
  425. package/worker/include/handles/BackoffTimerHandle.hpp +28 -67
  426. package/worker/include/handles/BackoffTimerHandleInterface.hpp +123 -0
  427. package/worker/include/handles/TimerHandle.hpp +29 -20
  428. package/worker/include/handles/TimerHandleInterface.hpp +43 -0
  429. package/worker/meson.build +45 -29
  430. package/worker/meson_options.txt +2 -1
  431. package/worker/mocks/include/Channel/MockChannelMessageRegistrator.hpp +45 -0
  432. package/worker/mocks/include/MockShared.hpp +90 -0
  433. package/worker/mocks/include/RTC/SCTP/association/MockAssociationListener.hpp +308 -0
  434. package/worker/mocks/include/RTC/SCTP/association/MockTransmissionControlBlockContext.hpp +183 -0
  435. package/worker/mocks/include/RTC/SCTP/tx/MockSendQueue.hpp +262 -0
  436. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +153 -0
  437. package/worker/mocks/include/handles/MockTimerHandle.hpp +74 -0
  438. package/worker/mocks/include/mockTypes.hpp +15 -0
  439. package/worker/mocks/src/Channel/MockChannelMessageRegistrator.cpp +128 -0
  440. package/worker/mocks/src/MockShared.cpp +46 -0
  441. package/worker/mocks/src/RTC/SCTP/association/MockTransmissionControlBlockContext.cpp +39 -0
  442. package/worker/mocks/src/handles/MockBackoffTimerHandle.cpp +127 -0
  443. package/worker/scripts/clang-scripts.mjs +5 -1
  444. package/worker/scripts/package-lock.json +6 -7
  445. package/worker/src/Channel/ChannelMessageRegistrator.cpp +125 -0
  446. package/worker/src/Channel/ChannelSocket.cpp +3 -4
  447. package/worker/src/DepLibUV.cpp +1 -1
  448. package/worker/src/DepLibUring.cpp +3 -1
  449. package/worker/src/Logger.cpp +1 -1
  450. package/worker/src/MediaSoupErrors.cpp +2 -0
  451. package/worker/src/RTC/ActiveSpeakerObserver.cpp +14 -14
  452. package/worker/src/RTC/AudioLevelObserver.cpp +12 -10
  453. package/worker/src/RTC/Consumer.cpp +28 -26
  454. package/worker/src/RTC/DataConsumer.cpp +61 -71
  455. package/worker/src/RTC/DataProducer.cpp +16 -11
  456. package/worker/src/RTC/DirectTransport.cpp +21 -20
  457. package/worker/src/RTC/DtlsTransport.cpp +4 -4
  458. package/worker/src/RTC/ICE/IceServer.cpp +6 -5
  459. package/worker/src/RTC/ICE/StunPacket.cpp +1 -1
  460. package/worker/src/RTC/KeyFrameRequestManager.cpp +15 -15
  461. package/worker/src/RTC/NackGenerator.cpp +6 -6
  462. package/worker/src/RTC/PipeConsumer.cpp +6 -5
  463. package/worker/src/RTC/PipeTransport.cpp +9 -22
  464. package/worker/src/RTC/PlainTransport.cpp +16 -28
  465. package/worker/src/RTC/Producer.cpp +40 -39
  466. package/worker/src/RTC/RTCP/FeedbackPsAfb.cpp +1 -1
  467. package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +1 -2
  468. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +1 -1
  469. package/worker/src/RTC/RTCP/XR.cpp +1 -1
  470. package/worker/src/RTC/RTP/Packet.cpp +3 -1
  471. package/worker/src/RTC/RTP/ProbationGenerator.cpp +4 -4
  472. package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +1 -1
  473. package/worker/src/RTC/RTP/RtpStream.cpp +17 -10
  474. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +16 -14
  475. package/worker/src/RTC/RTP/RtpStreamSend.cpp +12 -9
  476. package/worker/src/RTC/RTP/RtxStream.cpp +7 -7
  477. package/worker/src/RTC/RTP/SharedPacket.cpp +3 -3
  478. package/worker/src/RTC/RateCalculator.cpp +1 -2
  479. package/worker/src/RTC/Router.cpp +61 -38
  480. package/worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp +1 -1
  481. package/worker/src/RTC/RtpObserver.cpp +2 -1
  482. package/worker/src/RTC/SCTP/LICENSE +44 -0
  483. package/worker/src/RTC/SCTP/association/Association.cpp +417 -411
  484. package/worker/src/RTC/SCTP/association/AssociationListenerDeferrer.cpp +46 -13
  485. package/worker/src/RTC/SCTP/association/HeartbeatHandler.cpp +47 -43
  486. package/worker/src/RTC/SCTP/association/PacketSender.cpp +8 -8
  487. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +113 -101
  488. package/worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp +291 -62
  489. package/worker/src/RTC/SCTP/packet/Chunk.cpp +5 -1
  490. package/worker/src/RTC/SCTP/packet/Packet.cpp +8 -1
  491. package/worker/src/RTC/SCTP/packet/chunks/DataChunk.cpp +17 -0
  492. package/worker/src/RTC/SCTP/packet/chunks/ForwardTsnChunk.cpp +4 -4
  493. package/worker/src/RTC/SCTP/packet/chunks/IDataChunk.cpp +25 -0
  494. package/worker/src/RTC/SCTP/packet/chunks/IForwardTsnChunk.cpp +10 -7
  495. package/worker/src/RTC/SCTP/packet/chunks/SackChunk.cpp +21 -4
  496. package/worker/src/RTC/SCTP/packet/chunks/ShutdownCompleteChunk.cpp +1 -1
  497. package/worker/src/RTC/SCTP/packet/errorCauses/NoUserDataErrorCause.cpp +1 -1
  498. package/worker/src/RTC/SCTP/packet/errorCauses/ProtocolViolationErrorCause.cpp +2 -2
  499. package/worker/src/RTC/SCTP/packet/errorCauses/UserInitiatedAbortErrorCause.cpp +1 -1
  500. package/worker/src/RTC/SCTP/public/Message.cpp +8 -0
  501. package/worker/src/RTC/SCTP/public/SctpOptions.cpp +90 -0
  502. package/worker/src/RTC/SCTP/rx/DataTracker.cpp +471 -0
  503. package/worker/src/RTC/SCTP/rx/InterleavedReassemblyStreams.cpp +327 -0
  504. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +288 -0
  505. package/worker/src/RTC/SCTP/rx/TraditionalReassemblyStreams.cpp +453 -0
  506. package/worker/src/RTC/SCTP/tx/OutstandingData.cpp +912 -0
  507. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +786 -0
  508. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +2 -2
  509. package/worker/src/RTC/SCTP/tx/RoundRobinSendQueue.cpp +752 -0
  510. package/worker/src/RTC/SCTP/tx/StreamScheduler.cpp +257 -0
  511. package/worker/src/RTC/SenderBandwidthEstimator.cpp +7 -5
  512. package/worker/src/RTC/SimpleConsumer.cpp +11 -11
  513. package/worker/src/RTC/SimulcastConsumer.cpp +16 -16
  514. package/worker/src/RTC/SrtpSession.cpp +1 -1
  515. package/worker/src/RTC/SvcConsumer.cpp +16 -16
  516. package/worker/src/RTC/TcpConnection.cpp +1 -1
  517. package/worker/src/RTC/Transport.cpp +497 -563
  518. package/worker/src/RTC/TransportCongestionControlClient.cpp +9 -8
  519. package/worker/src/RTC/TransportCongestionControlServer.cpp +5 -5
  520. package/worker/src/RTC/WebRtcServer.cpp +5 -4
  521. package/worker/src/RTC/WebRtcTransport.cpp +44 -39
  522. package/worker/src/Settings.cpp +9 -28
  523. package/worker/src/Shared.cpp +35 -0
  524. package/worker/src/Utils/Crypto.cpp +1 -1
  525. package/worker/src/Utils/String.cpp +1 -1
  526. package/worker/src/Worker.cpp +19 -48
  527. package/worker/src/handles/BackoffTimerHandle.cpp +34 -21
  528. package/worker/src/handles/TimerHandle.cpp +5 -4
  529. package/worker/src/handles/UdpSocketHandle.cpp +1 -1
  530. package/worker/src/lib.cpp +17 -16
  531. package/worker/subprojects/catch2.wrap +6 -6
  532. package/worker/tasks.py +1 -1
  533. package/worker/test/include/RTC/ICE/iceCommon.hpp +8 -7
  534. package/worker/test/include/RTC/RTP/rtpCommon.hpp +7 -6
  535. package/worker/test/include/RTC/SCTP/sctpCommon.hpp +16 -10
  536. package/worker/test/include/catch2Macros.hpp +31 -0
  537. package/worker/test/src/RTC/ICE/TestStunPacket.cpp +3 -3
  538. package/worker/test/src/RTC/ICE/iceCommon.cpp +2 -2
  539. package/worker/test/src/RTC/RTP/Codecs/TestVP8.cpp +1 -1
  540. package/worker/test/src/RTC/RTP/Codecs/TestVP9.cpp +1 -1
  541. package/worker/test/src/RTC/RTP/TestPacket.cpp +3 -3
  542. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +16 -9
  543. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +38 -23
  544. package/worker/test/src/RTC/RTP/TestSharedPacket.cpp +1 -1
  545. package/worker/test/src/RTC/RTP/rtpCommon.cpp +2 -2
  546. package/worker/test/src/RTC/SCTP/association/TestHeartbeatHandler.cpp +292 -0
  547. package/worker/test/src/RTC/SCTP/association/TestNegotiatedCapabilities.cpp +1 -1
  548. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +1 -1
  549. package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +99 -0
  550. package/worker/test/src/RTC/SCTP/packet/TestChunk.cpp +1 -1
  551. package/worker/test/src/RTC/SCTP/packet/TestPacket.cpp +1 -1
  552. package/worker/test/src/RTC/SCTP/packet/chunks/TestAbortAssociationChunk.cpp +1 -1
  553. package/worker/test/src/RTC/SCTP/packet/chunks/TestCookieAckChunk.cpp +1 -1
  554. package/worker/test/src/RTC/SCTP/packet/chunks/TestCookieEchoChunk.cpp +1 -1
  555. package/worker/test/src/RTC/SCTP/packet/chunks/TestDataChunk.cpp +77 -7
  556. package/worker/test/src/RTC/SCTP/packet/chunks/TestForwardTsnChunk.cpp +35 -26
  557. package/worker/test/src/RTC/SCTP/packet/chunks/TestHeartbeatAckChunk.cpp +1 -1
  558. package/worker/test/src/RTC/SCTP/packet/chunks/TestHeartbeatRequestChunk.cpp +1 -1
  559. package/worker/test/src/RTC/SCTP/packet/chunks/TestIDataChunk.cpp +77 -7
  560. package/worker/test/src/RTC/SCTP/packet/chunks/TestIForwardTsnChunk.cpp +59 -27
  561. package/worker/test/src/RTC/SCTP/packet/chunks/TestInitAckChunk.cpp +1 -1
  562. package/worker/test/src/RTC/SCTP/packet/chunks/TestInitChunk.cpp +1 -1
  563. package/worker/test/src/RTC/SCTP/packet/chunks/TestOperationErrorChunk.cpp +1 -1
  564. package/worker/test/src/RTC/SCTP/packet/chunks/TestReConfigChunk.cpp +1 -1
  565. package/worker/test/src/RTC/SCTP/packet/chunks/TestSackChunk.cpp +73 -35
  566. package/worker/test/src/RTC/SCTP/packet/chunks/TestShutdownAckChunk.cpp +1 -1
  567. package/worker/test/src/RTC/SCTP/packet/chunks/TestShutdownChunk.cpp +1 -1
  568. package/worker/test/src/RTC/SCTP/packet/chunks/TestShutdownCompleteChunk.cpp +1 -1
  569. package/worker/test/src/RTC/SCTP/packet/chunks/TestUnknownChunk.cpp +1 -1
  570. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestCookieReceivedWhileShuttingDownErrorCause.cpp +1 -1
  571. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestInvalidMandatoryParameterErrorCause.cpp +1 -1
  572. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestInvalidStreamIdentifierErrorCause.cpp +1 -1
  573. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestMissingMandatoryParameterErrorCause.cpp +1 -1
  574. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestNoUserDataErrorCause.cpp +1 -1
  575. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestOutOfResourceErrorCause.cpp +1 -1
  576. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestProtocolViolationErrorCause.cpp +1 -1
  577. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestRestartOfAnAssociationWithNewAddressesErrorCause.cpp +1 -1
  578. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestStaleCookieErrorCause.cpp +1 -1
  579. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestUnknownErrorCause.cpp +1 -1
  580. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestUnrecognizedChunkTypeErrorCause.cpp +1 -1
  581. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestUnrecognizedParametersErrorCause.cpp +1 -1
  582. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestUnresolvableAddressErrorCause.cpp +1 -1
  583. package/worker/test/src/RTC/SCTP/packet/errorCauses/TestUserInitiatedAbortErrorCause.cpp +1 -1
  584. package/worker/test/src/RTC/SCTP/packet/parameters/TestAddIncomingStreamsRequestParameter.cpp +1 -1
  585. package/worker/test/src/RTC/SCTP/packet/parameters/TestAddOutgoingStreamsRequestParameter.cpp +1 -1
  586. package/worker/test/src/RTC/SCTP/packet/parameters/TestCookiePreservativeParameter.cpp +1 -1
  587. package/worker/test/src/RTC/SCTP/packet/parameters/TestForwardTsnSupportedParameter.cpp +1 -1
  588. package/worker/test/src/RTC/SCTP/packet/parameters/TestHeartbeatInfoParameter.cpp +1 -1
  589. package/worker/test/src/RTC/SCTP/packet/parameters/TestIPv4AddressParameter.cpp +1 -1
  590. package/worker/test/src/RTC/SCTP/packet/parameters/TestIPv6AddressParameter.cpp +1 -1
  591. package/worker/test/src/RTC/SCTP/packet/parameters/TestIncomingSsnResetRequestParameter.cpp +1 -1
  592. package/worker/test/src/RTC/SCTP/packet/parameters/TestOutgoingSsnResetRequestParameter.cpp +1 -1
  593. package/worker/test/src/RTC/SCTP/packet/parameters/TestReconfigurationResponseParameter.cpp +1 -1
  594. package/worker/test/src/RTC/SCTP/packet/parameters/TestSsnTsnResetRequestParameter.cpp +1 -1
  595. package/worker/test/src/RTC/SCTP/packet/parameters/TestStateCookieParameter.cpp +1 -1
  596. package/worker/test/src/RTC/SCTP/packet/parameters/TestSupportedAddressTypesParameter.cpp +1 -1
  597. package/worker/test/src/RTC/SCTP/packet/parameters/TestSupportedExtensionsParameter.cpp +1 -1
  598. package/worker/test/src/RTC/SCTP/packet/parameters/TestUnknownParameter.cpp +1 -1
  599. package/worker/test/src/RTC/SCTP/packet/parameters/TestUnrecognizedParameterParameter.cpp +1 -1
  600. package/worker/test/src/RTC/SCTP/packet/parameters/TestZeroChecksumAcceptableParameter.cpp +1 -1
  601. package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +1117 -0
  602. package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +565 -0
  603. package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +557 -0
  604. package/worker/test/src/RTC/SCTP/rx/TestTraditionalReassemblyStreams.cpp +555 -0
  605. package/worker/test/src/RTC/SCTP/sctpCommon.cpp +2 -2
  606. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +1248 -0
  607. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionErrorCounter.cpp +4 -0
  608. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +2218 -0
  609. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +33 -33
  610. package/worker/test/src/RTC/SCTP/tx/TestRoundRobinSendQueue.cpp +1130 -0
  611. package/worker/test/src/RTC/SCTP/tx/TestStreamScheduler.cpp +721 -0
  612. package/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +20 -30
  613. package/worker/test/src/RTC/TestNackGenerator.cpp +11 -8
  614. package/worker/test/src/RTC/TestRateCalculator.cpp +6 -7
  615. package/worker/test/src/RTC/TestSimpleConsumer.cpp +11 -11
  616. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +15 -3
  617. package/worker/test/src/Utils/TestByte.cpp +98 -0
  618. package/worker/test/src/{RTC/SCTP/common → Utils}/TestUnwrappedSequenceNumber.cpp +2 -2
  619. package/worker/test/src/testHelpers.cpp +1 -1
  620. package/worker/test/src/tests.cpp +0 -12
  621. package/node/lib/fbs/consumer/degrade-request.d.ts +0 -30
  622. package/node/lib/fbs/consumer/degrade-request.d.ts.map +0 -1
  623. package/node/lib/fbs/consumer/degrade-request.js +0 -91
  624. package/node/lib/fbs/consumer/enable-delay-and-loss-request.d.ts +0 -24
  625. package/node/lib/fbs/consumer/enable-delay-and-loss-request.d.ts.map +0 -1
  626. package/node/lib/fbs/consumer/enable-delay-and-loss-request.js +0 -69
  627. package/node/lib/fbs/producer/degrade-request.d.ts +0 -30
  628. package/node/lib/fbs/producer/degrade-request.d.ts.map +0 -1
  629. package/node/lib/fbs/producer/degrade-request.js +0 -91
  630. package/node/lib/fbs/worker/close-notification.d.ts +0 -18
  631. package/node/lib/fbs/worker/close-notification.d.ts.map +0 -1
  632. package/node/lib/fbs/worker/close-notification.js +0 -45
  633. package/node/lib/fbs/worker/close-request.d.ts +0 -18
  634. package/node/lib/fbs/worker/close-request.d.ts.map +0 -1
  635. package/node/lib/fbs/worker/close-request.js +0 -45
  636. package/node/lib/fbs/worker/close-worker-notification.d.ts +0 -18
  637. package/node/lib/fbs/worker/close-worker-notification.d.ts.map +0 -1
  638. package/node/lib/fbs/worker/close-worker-notification.js +0 -45
  639. package/worker/include/ChannelMessageRegistrator.hpp +0 -30
  640. package/worker/include/DepUsrSCTP.hpp +0 -48
  641. package/worker/include/RTC/SCTP/TODO_SCTP.md +0 -43
  642. package/worker/include/RTC/SCTP/common/UnwrappedSequenceNumber.hpp +0 -274
  643. package/worker/include/RTC/SctpAssociation.hpp +0 -147
  644. package/worker/include/RTC/Shared.hpp +0 -23
  645. package/worker/src/ChannelMessageRegistrator.cpp +0 -119
  646. package/worker/src/DepUsrSCTP.cpp +0 -277
  647. package/worker/src/RTC/SctpAssociation.cpp +0 -1175
  648. package/worker/src/RTC/Shared.cpp +0 -23
  649. package/worker/subprojects/usrsctp.wrap +0 -8
@@ -4,11 +4,11 @@
4
4
  #include "RTC/Transport.hpp"
5
5
  #include "Logger.hpp"
6
6
  #include "MediaSoupErrors.hpp"
7
- #include "Settings.hpp"
8
7
  #include "Utils.hpp"
9
8
  #ifdef MS_LIBURING_SUPPORTED
10
9
  #include "DepLibUring.hpp"
11
10
  #endif
11
+ #include "FBS/sctpAssociation.h"
12
12
  #include "FBS/transport.h"
13
13
  #include "RTC/BweType.hpp"
14
14
  #include "RTC/Consts.hpp"
@@ -29,40 +29,42 @@
29
29
  #include "RTC/RtcLogger.hpp"
30
30
  #endif
31
31
  #include <libwebrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h> // webrtc::RtpPacketSendInfo
32
- #include <iterator> // std::ostream_iterator
33
- #include <map> // std::multimap
32
+ #include <array>
33
+ #include <iterator> // std::ostream_iterator
34
+ #include <map> // std::multimap
34
35
 
35
36
  namespace RTC
36
37
  {
37
- static const size_t DefaultSctpSendBufferSize{ 262144 }; // 2^18 bytes.
38
- static const size_t MaxSctpSendBufferSize{ 268435456 }; // 2^28 bytes.
39
-
40
38
  /* Instance methods. */
41
39
 
42
40
  Transport::Transport(
43
- RTC::Shared* shared,
41
+ SharedInterface* shared,
44
42
  const std::string& id,
45
43
  RTC::Transport::Listener* listener,
46
44
  const FBS::Transport::Options* options)
47
45
  : id(id),
48
46
  shared(shared),
49
47
  listener(listener),
50
- recvRtpTransmission(/*ignorePaddingOnlyPackets*/ false),
51
- sendRtpTransmission(/*ignorePaddingOnlyPackets*/ false),
52
- recvRtxTransmission(/*ignorePaddingOnlyPackets*/ false, 1000u),
53
- sendRtxTransmission(/*ignorePaddingOnlyPackets*/ false, 1000u),
54
- sendProbationTransmission(/*ignorePaddingOnlyPackets*/ false, 100u)
48
+ recvRtpTransmission(shared, /*ignorePaddingOnlyPackets*/ false),
49
+ sendRtpTransmission(shared, /*ignorePaddingOnlyPackets*/ false),
50
+ recvRtxTransmission(shared, /*ignorePaddingOnlyPackets*/ false, 1000u),
51
+ sendRtxTransmission(shared, /*ignorePaddingOnlyPackets*/ false, 1000u),
52
+ sendProbationTransmission(shared, /*ignorePaddingOnlyPackets*/ false, 100u)
55
53
  {
56
54
  MS_TRACE();
57
55
 
56
+ this->maxSendMessageSize = options->maxSendMessageSize();
57
+ this->maxReceiveMessageSize = options->maxReceiveMessageSize();
58
+
58
59
  if (options->direct())
59
60
  {
60
61
  this->direct = true;
61
-
62
- if (auto maxMessageSize = options->maxMessageSize(); maxMessageSize.has_value())
63
- {
64
- this->maxMessageSize = maxMessageSize.value();
65
- }
62
+ }
63
+ else
64
+ {
65
+ this->sctpSendBufferSize = options->sctpSendBufferSize();
66
+ this->sctpPerStreamSendQueueLimit = options->sctpPerStreamSendQueueLimit();
67
+ this->sctpMaxReceiverWindowBufferSize = options->sctpMaxReceiverWindowBufferSize();
66
68
  }
67
69
 
68
70
  if (
@@ -79,65 +81,21 @@ namespace RTC
79
81
  MS_THROW_TYPE_ERROR("cannot enable SCTP in a direct Transport");
80
82
  }
81
83
 
82
- // numSctpStreams is mandatory.
83
- if (!flatbuffers::IsFieldPresent(options, FBS::Transport::Options::VT_NUMSCTPSTREAMS))
84
- {
85
- MS_THROW_TYPE_ERROR("numSctpStreams missing");
86
- }
87
-
88
- // maxSctpMessageSize is mandatory.
89
- if (!flatbuffers::IsFieldPresent(options, FBS::Transport::Options::VT_MAXSCTPMESSAGESIZE))
90
- {
91
- MS_THROW_TYPE_ERROR("maxSctpMessageSize missing");
92
- }
93
-
94
- this->maxMessageSize = options->maxSctpMessageSize();
84
+ const RTC::SCTP::SctpOptions sctpOptions = {
85
+ .mtu = RTC::Consts::MaxSafeMtuSizeForSctp,
86
+ .maxSendMessageSize = this->maxSendMessageSize,
87
+ .maxSendBufferSize = this->sctpSendBufferSize,
88
+ .perStreamSendQueueLimit = this->sctpPerStreamSendQueueLimit,
89
+ .maxReceiveMessageSize = this->maxReceiveMessageSize,
90
+ .maxReceiverWindowBufferSize = this->sctpMaxReceiverWindowBufferSize
91
+ };
95
92
 
96
- size_t sctpSendBufferSize;
97
-
98
- // sctpSendBufferSize is optional.
99
- if (flatbuffers::IsFieldPresent(options, FBS::Transport::Options::VT_SCTPSENDBUFFERSIZE))
100
- {
101
- if (options->sctpSendBufferSize() > MaxSctpSendBufferSize)
102
- {
103
- MS_THROW_TYPE_ERROR("wrong sctpSendBufferSize (maximum value exceeded)");
104
- }
105
-
106
- sctpSendBufferSize = options->sctpSendBufferSize();
107
- }
108
- else
109
- {
110
- sctpSendBufferSize = DefaultSctpSendBufferSize;
111
- }
112
-
113
- if (Settings::configuration.useBuiltInSctpStack)
114
- {
115
- // TODO: SCTP: Many interesting options missing.
116
- // NOTE: When using the built-in SCTP stack, `numSctpStreams` given to the
117
- // transport is ignored.
118
- const RTC::SCTP::SctpOptions sctpOptions = { // TODO: SCTP: Sure?
119
- .maxSendMessageSize = this->maxMessageSize,
120
- .maxSendBufferSize = sctpSendBufferSize
121
- };
122
-
123
- this->sctpAssociation = std::make_unique<RTC::SCTP::Association>(sctpOptions, this);
124
- }
125
- // TODO: Remove once we only use built-in SCTP stack.
126
- else
127
- {
128
- // This may throw.
129
- this->oldSctpAssociation = new RTC::SctpAssociation(
130
- this,
131
- options->numSctpStreams()->os(),
132
- options->numSctpStreams()->mis(),
133
- this->maxMessageSize,
134
- sctpSendBufferSize,
135
- options->isDataChannel());
136
- }
93
+ this->sctpAssociation = std::make_unique<RTC::SCTP::Association>(
94
+ sctpOptions, this, this->shared, options->isDataChannel());
137
95
  }
138
96
 
139
97
  // Create the RTCP timer.
140
- this->rtcpTimer = new TimerHandle(this);
98
+ this->rtcpTimer = this->shared->CreateTimer(this);
141
99
  }
142
100
 
143
101
  Transport::~Transport()
@@ -183,24 +141,15 @@ namespace RTC
183
141
  delete dataConsumer;
184
142
  }
185
143
  this->mapDataConsumers.clear();
144
+ this->mapSctpStreamIdDataConsumers.clear();
186
145
 
187
- if (Settings::configuration.useBuiltInSctpStack)
188
- {
189
- // NOTE: When using the built-in SCTP stack we don't do anything here since
190
- // the `Destroying()` method has already been called by the Transport subclas
191
- // and it closed the SCTP Association.
192
- // NOTE: We cannot do it here in the destructor because here we are no longer
193
- // the Transport subclass but Transport parent (this is how the destruction
194
- // chain works in C++).
195
- }
196
- // TODO: Remove once we only use built-in SCTP stack.
197
- else
198
- {
199
- // Delete SCTP association.
200
- // TODO: Remove once we only use built-in SCTP stack.
201
- delete this->oldSctpAssociation;
202
- this->oldSctpAssociation = nullptr;
203
- }
146
+ // NOTE: We don't close `this->sctpAssociation` here since the
147
+ // `SetDestroying()` method has already been called by the Transport
148
+ // subclass and it closed the SCTP Association.
149
+ //
150
+ // NOTE: We cannot do it here in the destructor because here we are no longer
151
+ // the Transport subclass but Transport parent (this is how the destruction
152
+ // chain works in C++).
204
153
 
205
154
  // Delete the RTCP timer.
206
155
  delete this->rtcpTimer;
@@ -266,6 +215,7 @@ namespace RTC
266
215
  delete dataConsumer;
267
216
  }
268
217
  this->mapDataConsumers.clear();
218
+ this->mapSctpStreamIdDataConsumers.clear();
269
219
  }
270
220
 
271
221
  void Transport::ListenServerClosed()
@@ -373,7 +323,7 @@ namespace RTC
373
323
  // Add sctpListener.
374
324
  flatbuffers::Offset<FBS::Transport::SctpListener> sctpListener;
375
325
 
376
- if (Settings::configuration.useBuiltInSctpStack && this->sctpAssociation)
326
+ if (this->sctpAssociation)
377
327
  {
378
328
  // Add sctpParameters.
379
329
  sctpParameters = this->sctpAssociation->FillBuffer(builder);
@@ -409,47 +359,6 @@ namespace RTC
409
359
 
410
360
  sctpListener = this->sctpListener.FillBuffer(builder);
411
361
  }
412
- // TODO: Remove once we only use built-in SCTP stack.
413
- else if (!Settings::configuration.useBuiltInSctpStack && this->oldSctpAssociation)
414
- {
415
- // Add sctpParameters.
416
- sctpParameters = this->oldSctpAssociation->FillBuffer(builder);
417
-
418
- switch (this->oldSctpAssociation->GetState())
419
- {
420
- case RTC::SctpAssociation::SctpState::NEW:
421
- {
422
- sctpState = FBS::SctpAssociation::SctpState::NEW;
423
- break;
424
- }
425
-
426
- case RTC::SctpAssociation::SctpState::CONNECTING:
427
- {
428
- sctpState = FBS::SctpAssociation::SctpState::CONNECTING;
429
- break;
430
- }
431
-
432
- case RTC::SctpAssociation::SctpState::CONNECTED:
433
- {
434
- sctpState = FBS::SctpAssociation::SctpState::CONNECTED;
435
- break;
436
- }
437
-
438
- case RTC::SctpAssociation::SctpState::FAILED:
439
- {
440
- sctpState = FBS::SctpAssociation::SctpState::FAILED;
441
- break;
442
- }
443
-
444
- case RTC::SctpAssociation::SctpState::CLOSED:
445
- {
446
- sctpState = FBS::SctpAssociation::SctpState::CLOSED;
447
- break;
448
- }
449
- }
450
-
451
- sctpListener = this->sctpListener.FillBuffer(builder);
452
- }
453
362
 
454
363
  // Add traceEventTypes.
455
364
  std::vector<FBS::Transport::TraceEventType> traceEventTypes;
@@ -475,11 +384,11 @@ namespace RTC
475
384
  &dataConsumerIds,
476
385
  recvRtpHeaderExtensions,
477
386
  rtpListenerOffset,
478
- this->maxMessageSize,
387
+ this->maxSendMessageSize,
388
+ this->maxReceiveMessageSize,
479
389
  sctpParameters,
480
- (this->sctpAssociation || this->oldSctpAssociation)
481
- ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
482
- : flatbuffers::nullopt,
390
+ this->sctpAssociation ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
391
+ : flatbuffers::nullopt,
483
392
  sctpListener,
484
393
  &traceEventTypes);
485
394
  }
@@ -489,13 +398,13 @@ namespace RTC
489
398
  {
490
399
  MS_TRACE();
491
400
 
492
- auto nowMs = DepLibUV::GetTimeMs();
401
+ auto nowMs = this->shared->GetTimeMs();
493
402
 
494
403
  // Add sctpState.
495
404
  FBS::SctpAssociation::SctpState sctpState{ FBS::SctpAssociation::SctpState::NEW };
496
405
 
497
406
  // Add sctpState.
498
- if (Settings::configuration.useBuiltInSctpStack && this->sctpAssociation)
407
+ if (this->sctpAssociation)
499
408
  {
500
409
  // NOTE: There is never permanent FAILED state.
501
410
  switch (this->sctpAssociation->GetAssociationState())
@@ -526,42 +435,6 @@ namespace RTC
526
435
  }
527
436
  }
528
437
  }
529
- // TODO: Remove once we only use built-in SCTP stack.
530
- else if (!Settings::configuration.useBuiltInSctpStack && this->oldSctpAssociation)
531
- {
532
- switch (this->oldSctpAssociation->GetState())
533
- {
534
- case RTC::SctpAssociation::SctpState::NEW:
535
- {
536
- sctpState = FBS::SctpAssociation::SctpState::NEW;
537
- break;
538
- }
539
-
540
- case RTC::SctpAssociation::SctpState::CONNECTING:
541
- {
542
- sctpState = FBS::SctpAssociation::SctpState::CONNECTING;
543
- break;
544
- }
545
-
546
- case RTC::SctpAssociation::SctpState::CONNECTED:
547
- {
548
- sctpState = FBS::SctpAssociation::SctpState::CONNECTED;
549
- break;
550
- }
551
-
552
- case RTC::SctpAssociation::SctpState::FAILED:
553
- {
554
- sctpState = FBS::SctpAssociation::SctpState::FAILED;
555
- break;
556
- }
557
-
558
- case RTC::SctpAssociation::SctpState::CLOSED:
559
- {
560
- sctpState = FBS::SctpAssociation::SctpState::CLOSED;
561
- break;
562
- }
563
- }
564
- }
565
438
 
566
439
  return FBS::Transport::CreateStatsDirect(
567
440
  builder,
@@ -570,9 +443,8 @@ namespace RTC
570
443
  // timestamp.
571
444
  nowMs,
572
445
  // sctpState.
573
- (this->sctpAssociation || this->oldSctpAssociation)
574
- ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
575
- : flatbuffers::nullopt,
446
+ this->sctpAssociation ? flatbuffers::Optional<FBS::SctpAssociation::SctpState>(sctpState)
447
+ : flatbuffers::nullopt,
576
448
  // bytesReceived.
577
449
  this->recvTransmission.GetBytes(),
578
450
  // recvBitrate.
@@ -880,7 +752,7 @@ namespace RTC
880
752
  if (createTccServer)
881
753
  {
882
754
  this->tccServer = std::make_shared<RTC::TransportCongestionControlServer>(
883
- this, bweType, RTC::Consts::RtcpPacketMaxSize);
755
+ this, this->shared, bweType, RTC::Consts::RtcpPacketMaxSize);
884
756
 
885
757
  if (this->maxIncomingBitrate != 0u)
886
758
  {
@@ -1073,6 +945,7 @@ namespace RTC
1073
945
 
1074
946
  this->tccClient = std::make_shared<RTC::TransportCongestionControlClient>(
1075
947
  this,
948
+ this->shared,
1076
949
  bweType,
1077
950
  this->initialAvailableOutgoingBitrate,
1078
951
  this->maxOutgoingBitrate,
@@ -1127,7 +1000,7 @@ namespace RTC
1127
1000
  };
1128
1001
 
1129
1002
  this->senderBwe = std::make_shared<RTC::SenderBandwidthEstimator>(
1130
- this, this->initialAvailableOutgoingBitrate);
1003
+ this, this->shared, this->initialAvailableOutgoingBitrate);
1131
1004
 
1132
1005
  if (IsConnected())
1133
1006
  {
@@ -1154,10 +1027,7 @@ namespace RTC
1154
1027
  case Channel::ChannelRequest::Method::TRANSPORT_PRODUCE_DATA:
1155
1028
  {
1156
1029
  // Early check. The Transport must support SCTP or be direct.
1157
- if (
1158
- ((Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1159
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation)) &&
1160
- !this->direct)
1030
+ if (!this->sctpAssociation && !this->direct)
1161
1031
  {
1162
1032
  MS_THROW_ERROR("SCTP not enabled and not a direct Transport");
1163
1033
  }
@@ -1170,17 +1040,15 @@ namespace RTC
1170
1040
  CheckNoDataProducer(dataProducerId);
1171
1041
 
1172
1042
  // This may throw.
1173
- auto* dataProducer =
1174
- new RTC::DataProducer(this->shared, dataProducerId, this->maxMessageSize, this, body);
1043
+ auto* dataProducer = new RTC::DataProducer(
1044
+ this->shared, dataProducerId, this->maxReceiveMessageSize, this, body);
1175
1045
 
1176
1046
  // Verify the type of the DataProducer.
1177
1047
  switch (dataProducer->GetType())
1178
1048
  {
1179
1049
  case RTC::DataProducer::Type::SCTP:
1180
1050
  {
1181
- if (
1182
- (Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1183
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation))
1051
+ if (!this->sctpAssociation)
1184
1052
  {
1185
1053
  delete dataProducer;
1186
1054
 
@@ -1253,15 +1121,7 @@ namespace RTC
1253
1121
  if (dataProducer->GetType() == RTC::DataProducer::Type::SCTP)
1254
1122
  {
1255
1123
  // Tell to the SCTP association.
1256
- if (Settings::configuration.useBuiltInSctpStack)
1257
- {
1258
- this->sctpAssociation->MayConnect();
1259
- }
1260
- // TODO: Remove once we only use built-in SCTP stack.
1261
- else
1262
- {
1263
- this->oldSctpAssociation->HandleDataProducer(dataProducer);
1264
- }
1124
+ this->sctpAssociation->MayConnect();
1265
1125
  }
1266
1126
 
1267
1127
  break;
@@ -1270,10 +1130,7 @@ namespace RTC
1270
1130
  case Channel::ChannelRequest::Method::TRANSPORT_CONSUME_DATA:
1271
1131
  {
1272
1132
  // Early check. The Transport must support SCTP or be direct.
1273
- if (
1274
- ((Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1275
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation)) &&
1276
- !this->direct)
1133
+ if (!this->sctpAssociation && !this->direct)
1277
1134
  {
1278
1135
  MS_THROW_ERROR("SCTP not enabled and not a direct Transport");
1279
1136
  }
@@ -1288,16 +1145,14 @@ namespace RTC
1288
1145
 
1289
1146
  // This may throw.
1290
1147
  auto* dataConsumer = new RTC::DataConsumer(
1291
- this->shared, dataConsumerId, dataProducerId, this, body, this->maxMessageSize);
1148
+ this->shared, dataConsumerId, dataProducerId, this, body, this->maxSendMessageSize);
1292
1149
 
1293
1150
  // Verify the type of the DataConsumer.
1294
1151
  switch (dataConsumer->GetType())
1295
1152
  {
1296
1153
  case RTC::DataConsumer::Type::SCTP:
1297
1154
  {
1298
- if (
1299
- (Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1300
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation))
1155
+ if (!this->sctpAssociation)
1301
1156
  {
1302
1157
  delete dataConsumer;
1303
1158
 
@@ -1306,6 +1161,18 @@ namespace RTC
1306
1161
  ;
1307
1162
  }
1308
1163
 
1164
+ try
1165
+ {
1166
+ // This may throw.
1167
+ CheckNoSctpDataConsumer(dataConsumer->GetSctpStreamParameters().streamId);
1168
+ }
1169
+ catch (const MediaSoupError& error)
1170
+ {
1171
+ delete dataConsumer;
1172
+
1173
+ throw;
1174
+ }
1175
+
1309
1176
  break;
1310
1177
  }
1311
1178
 
@@ -1340,6 +1207,12 @@ namespace RTC
1340
1207
  // Insert into the maps.
1341
1208
  this->mapDataConsumers[dataConsumerId] = dataConsumer;
1342
1209
 
1210
+ if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
1211
+ {
1212
+ this->mapSctpStreamIdDataConsumers[dataConsumer->GetSctpStreamParameters().streamId] =
1213
+ dataConsumer;
1214
+ }
1215
+
1343
1216
  MS_DEBUG_DEV(
1344
1217
  "DataConsumer created [dataConsumerId:%s, dataProducerId:%s]",
1345
1218
  dataConsumerId.c_str(),
@@ -1356,29 +1229,14 @@ namespace RTC
1356
1229
 
1357
1230
  if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
1358
1231
  {
1359
- if (Settings::configuration.useBuiltInSctpStack)
1232
+ if (this->sctpAssociation->GetAssociationState() == RTC::SCTP::Types::AssociationState::CONNECTED)
1360
1233
  {
1361
- if (this->sctpAssociation->GetAssociationState() == RTC::SCTP::Types::AssociationState::CONNECTED)
1362
- {
1363
- // Tell to the DataConsumer.
1364
- dataConsumer->SctpAssociationConnected();
1365
- }
1366
-
1367
- // Tell to the SCTP association.
1368
- this->sctpAssociation->MayConnect();
1234
+ // Tell to the DataConsumer.
1235
+ dataConsumer->SctpAssociationConnected();
1369
1236
  }
1370
- // TODO: Remove once we only use built-in SCTP stack.
1371
- else
1372
- {
1373
- if (this->oldSctpAssociation->GetState() == RTC::SctpAssociation::SctpState::CONNECTED)
1374
- {
1375
- // Tell to the DataConsumer.
1376
- dataConsumer->SctpAssociationConnected();
1377
- }
1378
1237
 
1379
- // Tell to the SCTP association.
1380
- this->oldSctpAssociation->HandleDataConsumer(dataConsumer);
1381
- }
1238
+ // Tell to the SCTP association.
1239
+ this->sctpAssociation->MayConnect();
1382
1240
  }
1383
1241
 
1384
1242
  break;
@@ -1423,7 +1281,7 @@ namespace RTC
1423
1281
  const auto* body = request->data->body_as<FBS::Transport::CloseProducerRequest>();
1424
1282
 
1425
1283
  // This may throw.
1426
- RTC::Producer* producer = GetProducerById(body->producerId()->str());
1284
+ RTC::Producer* producer = AssertAndGetProducerById(body->producerId()->str());
1427
1285
 
1428
1286
  // Remove it from the RtpListener.
1429
1287
  this->rtpListener.RemoveProducer(producer);
@@ -1462,7 +1320,7 @@ namespace RTC
1462
1320
  const auto* body = request->data->body_as<FBS::Transport::CloseConsumerRequest>();
1463
1321
 
1464
1322
  // This may throw.
1465
- RTC::Consumer* consumer = GetConsumerById(body->consumerId()->str());
1323
+ RTC::Consumer* consumer = AssertAndGetConsumerById(body->consumerId()->str());
1466
1324
 
1467
1325
  // Remove it from the maps.
1468
1326
  this->mapConsumers.erase(consumer->id);
@@ -1505,10 +1363,7 @@ namespace RTC
1505
1363
 
1506
1364
  case Channel::ChannelRequest::Method::TRANSPORT_CLOSE_DATAPRODUCER:
1507
1365
  {
1508
- if (
1509
- ((Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1510
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation)) &&
1511
- !this->direct)
1366
+ if (!this->sctpAssociation && !this->direct)
1512
1367
  {
1513
1368
  MS_THROW_ERROR("cannot close DataProducer, SCTP not enabled and not a direct Transport");
1514
1369
  }
@@ -1516,7 +1371,7 @@ namespace RTC
1516
1371
  const auto* body = request->data->body_as<FBS::Transport::CloseDataProducerRequest>();
1517
1372
 
1518
1373
  // This may throw.
1519
- RTC::DataProducer* dataProducer = GetDataProducerById(body->dataProducerId()->str());
1374
+ RTC::DataProducer* dataProducer = AssertAndGetDataProducerById(body->dataProducerId()->str());
1520
1375
 
1521
1376
  if (dataProducer->GetType() == RTC::DataProducer::Type::SCTP)
1522
1377
  {
@@ -1527,25 +1382,24 @@ namespace RTC
1527
1382
  // Remove it from the map.
1528
1383
  this->mapDataProducers.erase(dataProducer->id);
1529
1384
 
1385
+ // https://datatracker.ietf.org/doc/html/rfc8831#section-6.7
1386
+ //
1387
+ // "Closing of a data channel MUST be signaled by resetting the corresponding
1388
+ // outgoing streams [RFC6525]. This means that if one side decides to close
1389
+ // the data channel, it resets the corresponding outgoing stream. When the
1390
+ // peer sees that an incoming stream was reset, it also resets its
1391
+ // corresponding outgoing stream."
1392
+ if (this->sctpAssociation && this->sctpAssociation->IsDataChannel())
1393
+ {
1394
+ this->sctpAssociation->ResetStreams(
1395
+ std::array<uint16_t, 1>{ dataProducer->GetSctpStreamParameters().streamId });
1396
+ }
1397
+
1530
1398
  // Notify the listener.
1531
1399
  this->listener->OnTransportDataProducerClosed(this, dataProducer);
1532
1400
 
1533
1401
  MS_DEBUG_DEV("DataProducer closed [dataProducerId:%s]", dataProducer->id.c_str());
1534
1402
 
1535
- if (dataProducer->GetType() == RTC::DataProducer::Type::SCTP)
1536
- {
1537
- if (Settings::configuration.useBuiltInSctpStack)
1538
- {
1539
- // TODO: SCTP
1540
- }
1541
- // TODO: Remove once we only use built-in SCTP stack.
1542
- else
1543
- {
1544
- // Tell the SctpAssociation so it can reset the SCTP stream.
1545
- this->oldSctpAssociation->DataProducerClosed(dataProducer);
1546
- }
1547
- }
1548
-
1549
1403
  // Delete it.
1550
1404
  delete dataProducer;
1551
1405
 
@@ -1556,10 +1410,7 @@ namespace RTC
1556
1410
 
1557
1411
  case Channel::ChannelRequest::Method::TRANSPORT_CLOSE_DATACONSUMER:
1558
1412
  {
1559
- if (
1560
- ((Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1561
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation)) &&
1562
- !this->direct)
1413
+ if (!this->sctpAssociation && !this->direct)
1563
1414
  {
1564
1415
  MS_THROW_ERROR("cannot close DataConsumer, SCTP not enabled and not a direct Transport");
1565
1416
  }
@@ -1567,30 +1418,27 @@ namespace RTC
1567
1418
  const auto* body = request->data->body_as<FBS::Transport::CloseDataConsumerRequest>();
1568
1419
 
1569
1420
  // This may throw.
1570
- RTC::DataConsumer* dataConsumer = GetDataConsumerById(body->dataConsumerId()->str());
1421
+ RTC::DataConsumer* dataConsumer = AssertAndGetDataConsumerById(body->dataConsumerId()->str());
1571
1422
 
1572
1423
  // Remove it from the maps.
1573
1424
  this->mapDataConsumers.erase(dataConsumer->id);
1574
1425
 
1426
+ if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
1427
+ {
1428
+ this->mapSctpStreamIdDataConsumers.erase(dataConsumer->GetSctpStreamParameters().streamId);
1429
+ }
1430
+
1431
+ if (this->sctpAssociation)
1432
+ {
1433
+ this->sctpAssociation->ResetStreams(
1434
+ std::array<uint16_t, 1>{ dataConsumer->GetSctpStreamParameters().streamId });
1435
+ }
1436
+
1575
1437
  // Notify the listener.
1576
1438
  this->listener->OnTransportDataConsumerClosed(this, dataConsumer);
1577
1439
 
1578
1440
  MS_DEBUG_DEV("DataConsumer closed [dataConsumerId:%s]", dataConsumer->id.c_str());
1579
1441
 
1580
- if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
1581
- {
1582
- if (Settings::configuration.useBuiltInSctpStack)
1583
- {
1584
- // TODO: SCTP
1585
- }
1586
- // TODO: Remove once we only use built-in SCTP stack.
1587
- else
1588
- {
1589
- // Tell the SctpAssociation so it can reset the SCTP stream.
1590
- this->oldSctpAssociation->DataConsumerClosed(dataConsumer);
1591
- }
1592
- }
1593
-
1594
1442
  // Delete it.
1595
1443
  delete dataConsumer;
1596
1444
 
@@ -1629,23 +1477,20 @@ namespace RTC
1629
1477
  }
1630
1478
  }
1631
1479
 
1632
- void Transport::Destroying()
1480
+ void Transport::SetDestroying()
1633
1481
  {
1634
1482
  MS_TRACE();
1635
1483
 
1636
- if (Settings::configuration.useBuiltInSctpStack)
1484
+ if (this->sctpAssociation)
1637
1485
  {
1638
- if (this->sctpAssociation)
1639
- {
1640
- // NOTE: We don't invoke `Shutdown()` but `Close()` in the SCTP Association
1641
- // because at this point we are closing everything and we won't have any
1642
- // chance to complete the SCTP SHUTDOWN + SHUTDOWN_ACK + SHUTDOWN_COMPLETE
1643
- // dance, so we invoke `Close()` which just sends a SCTP ABORT.
1644
- this->sctpAssociation->Close();
1645
- }
1486
+ // NOTE: We don't invoke `Shutdown()` but `Close()` in the SCTP Association
1487
+ // because at this point we are closing everything and we won't have any
1488
+ // chance to complete the SCTP SHUTDOWN + SHUTDOWN_ACK + SHUTDOWN_COMPLETE
1489
+ // dance, so we invoke `Close()` which just sends a SCTP ABORT.
1490
+ this->sctpAssociation->Close();
1646
1491
  }
1647
1492
 
1648
- this->destroying = true;
1493
+ this->isDestroying = true;
1649
1494
  }
1650
1495
 
1651
1496
  void Transport::Connected()
@@ -1669,15 +1514,10 @@ namespace RTC
1669
1514
  }
1670
1515
 
1671
1516
  // Tell the SctpAssociation.
1672
- if (Settings::configuration.useBuiltInSctpStack && this->sctpAssociation)
1517
+ if (this->sctpAssociation)
1673
1518
  {
1674
1519
  this->sctpAssociation->MayConnect();
1675
1520
  }
1676
- // TODO: Remove once we only use built-in SCTP stack.
1677
- else if (!Settings::configuration.useBuiltInSctpStack && this->oldSctpAssociation)
1678
- {
1679
- this->oldSctpAssociation->TransportConnected();
1680
- }
1681
1521
 
1682
1522
  // Start the RTCP timer.
1683
1523
  this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2));
@@ -1723,13 +1563,6 @@ namespace RTC
1723
1563
  dataConsumer->TransportDisconnected();
1724
1564
  }
1725
1565
 
1726
- // TODO: Remove once we only use built-in SCTP stack.
1727
- // Tell the SctpAssociation.
1728
- if (!Settings::configuration.useBuiltInSctpStack && this->oldSctpAssociation)
1729
- {
1730
- this->oldSctpAssociation->TransportDisconnected();
1731
- }
1732
-
1733
1566
  // Stop the RTCP timer.
1734
1567
  this->rtcpTimer->Stop();
1735
1568
 
@@ -1766,7 +1599,7 @@ namespace RTC
1766
1599
  // them.
1767
1600
  packet->AssignExtensionIds(this->recvRtpHeaderExtensionIds);
1768
1601
 
1769
- auto nowMs = DepLibUV::GetTimeMs();
1602
+ auto nowMs = this->shared->GetTimeMs();
1770
1603
 
1771
1604
  // Feed the TransportCongestionControlServer.
1772
1605
  if (this->tccServer)
@@ -1854,9 +1687,7 @@ namespace RTC
1854
1687
  {
1855
1688
  MS_TRACE();
1856
1689
 
1857
- if (
1858
- (Settings::configuration.useBuiltInSctpStack && !this->sctpAssociation) ||
1859
- (!Settings::configuration.useBuiltInSctpStack && !this->oldSctpAssociation))
1690
+ if (!this->sctpAssociation)
1860
1691
  {
1861
1692
  MS_DEBUG_TAG(sctp, "ignoring SCTP packet (SCTP not enabled)");
1862
1693
 
@@ -1864,14 +1695,97 @@ namespace RTC
1864
1695
  }
1865
1696
 
1866
1697
  // Pass it to the SctpAssociation.
1867
- if (Settings::configuration.useBuiltInSctpStack)
1698
+ this->sctpAssociation->ReceiveSctpData(data, len);
1699
+ }
1700
+
1701
+ void Transport::SendSctpMessage(
1702
+ RTC::DataConsumer* dataConsumer, RTC::SCTP::Message message, onQueuedCallback* cb)
1703
+ {
1704
+ MS_TRACE();
1705
+
1706
+ // NOTE: The `message` must already have its `streamId` pointing to the same
1707
+ // as in the `dataConsumer` if its type is "sctp", or 0 otherwise.
1708
+
1709
+ if (!this->sctpAssociation)
1868
1710
  {
1869
- this->sctpAssociation->ReceiveSctpData(data, len);
1711
+ MS_THROW_ERROR("SCTP not enabled");
1712
+
1713
+ if (cb)
1714
+ {
1715
+ (*cb)(false, false);
1716
+ delete cb;
1717
+ }
1718
+
1719
+ return;
1870
1720
  }
1871
- else
1721
+
1722
+ const auto& sctpStreamParameters = dataConsumer->GetSctpStreamParameters();
1723
+ const RTC::SCTP::SendMessageOptions sendMessageOptions{
1724
+ .unordered = !sctpStreamParameters.ordered,
1725
+ .lifetimeMs = sctpStreamParameters.ordered
1726
+ ? std::nullopt
1727
+ : std::optional<uint64_t>(sctpStreamParameters.maxPacketLifeTime),
1728
+ .maxRetransmissions = sctpStreamParameters.ordered
1729
+ ? std::nullopt
1730
+ : std::optional<uint64_t>(sctpStreamParameters.maxRetransmits),
1731
+ // NOTE: We don't set `lifecyleId` in production.
1732
+ };
1733
+
1734
+ const auto sendStatus =
1735
+ this->sctpAssociation->SendMessage(std::move(message), sendMessageOptions);
1736
+
1737
+ switch (sendStatus)
1872
1738
  {
1873
- this->oldSctpAssociation->ProcessSctpData(data, len);
1739
+ case RTC::SCTP::Types::SendMessageStatus::SUCCESS:
1740
+ {
1741
+ if (cb)
1742
+ {
1743
+ (*cb)(true, /*sctpSendBufferFull*/ false);
1744
+ }
1745
+
1746
+ break;
1747
+ }
1748
+
1749
+ case RTC::SCTP::Types::SendMessageStatus::ERROR_RESOURCE_EXHAUSTION:
1750
+ {
1751
+ const auto sendStatusStringView = RTC::SCTP::Types::SendMessageStatusToString(sendStatus);
1752
+
1753
+ MS_WARN_TAG(
1754
+ sctp,
1755
+ "failed to send SCTP message [sendStatus:%.*s]",
1756
+ static_cast<int>(sendStatusStringView.size()),
1757
+ sendStatusStringView.data());
1758
+
1759
+ if (cb)
1760
+ {
1761
+ (*cb)(false, /*sctpSendBufferFull*/ true);
1762
+ }
1763
+
1764
+ dataConsumer->SctpSendBufferFull();
1765
+
1766
+ break;
1767
+ }
1768
+
1769
+ default:
1770
+ {
1771
+ const auto sendStatusStringView = RTC::SCTP::Types::SendMessageStatusToString(sendStatus);
1772
+
1773
+ MS_WARN_TAG(
1774
+ sctp,
1775
+ "failed to send SCTP message [sendStatus:%.*s]",
1776
+ static_cast<int>(sendStatusStringView.size()),
1777
+ sendStatusStringView.data());
1778
+
1779
+ if (cb)
1780
+ {
1781
+ (*cb)(false, /*sctpSendBufferFull*/ false);
1782
+ }
1783
+
1784
+ break;
1785
+ }
1874
1786
  }
1787
+
1788
+ delete cb;
1875
1789
  }
1876
1790
 
1877
1791
  void Transport::CheckNoDataProducer(const std::string& dataProducerId) const
@@ -1892,7 +1806,17 @@ namespace RTC
1892
1806
  }
1893
1807
  }
1894
1808
 
1895
- RTC::Producer* Transport::GetProducerById(const std::string& producerId) const
1809
+ void Transport::CheckNoSctpDataConsumer(uint16_t streamId) const
1810
+ {
1811
+ MS_TRACE();
1812
+
1813
+ if (this->mapSctpStreamIdDataConsumers.find(streamId) != this->mapSctpStreamIdDataConsumers.end())
1814
+ {
1815
+ MS_THROW_ERROR("an SCTP DataConsumer with same streamId %" PRIu16 " already exists", streamId);
1816
+ }
1817
+ }
1818
+
1819
+ RTC::Producer* Transport::AssertAndGetProducerById(const std::string& producerId) const
1896
1820
  {
1897
1821
  MS_TRACE();
1898
1822
 
@@ -1906,7 +1830,7 @@ namespace RTC
1906
1830
  return it->second;
1907
1831
  }
1908
1832
 
1909
- RTC::Consumer* Transport::GetConsumerById(const std::string& consumerId) const
1833
+ RTC::Consumer* Transport::AssertAndGetConsumerById(const std::string& consumerId) const
1910
1834
  {
1911
1835
  MS_TRACE();
1912
1836
 
@@ -1952,7 +1876,7 @@ namespace RTC
1952
1876
  return consumer;
1953
1877
  }
1954
1878
 
1955
- RTC::DataProducer* Transport::GetDataProducerById(const std::string& dataProducerId) const
1879
+ RTC::DataProducer* Transport::AssertAndGetDataProducerById(const std::string& dataProducerId) const
1956
1880
  {
1957
1881
  MS_TRACE();
1958
1882
 
@@ -1966,7 +1890,7 @@ namespace RTC
1966
1890
  return it->second;
1967
1891
  }
1968
1892
 
1969
- RTC::DataConsumer* Transport::GetDataConsumerById(const std::string& dataConsumerId) const
1893
+ RTC::DataConsumer* Transport::AssertAndGetDataConsumerById(const std::string& dataConsumerId) const
1970
1894
  {
1971
1895
  MS_TRACE();
1972
1896
 
@@ -1980,6 +1904,20 @@ namespace RTC
1980
1904
  return it->second;
1981
1905
  }
1982
1906
 
1907
+ RTC::DataConsumer* Transport::GetSctpDataConsumerByStreamId(uint16_t streamId) const
1908
+ {
1909
+ MS_TRACE();
1910
+
1911
+ auto it = this->mapSctpStreamIdDataConsumers.find(streamId);
1912
+
1913
+ if (it == this->mapSctpStreamIdDataConsumers.end())
1914
+ {
1915
+ MS_THROW_ERROR("SCTP DataConsumer with streamId %" PRIu16 " not found", streamId);
1916
+ }
1917
+
1918
+ return it->second;
1919
+ }
1920
+
1983
1921
  void Transport::HandleRtcpPacket(RTC::RTCP::Packet* packet)
1984
1922
  {
1985
1923
  MS_TRACE();
@@ -2037,7 +1975,7 @@ namespace RTC
2037
1975
  }
2038
1976
  }
2039
1977
 
2040
- this->tccClient->ReceiveRtcpReceiverReport(rr, rtt, DepLibUV::GetTimeMsInt64());
1978
+ this->tccClient->ReceiveRtcpReceiverReport(rr, rtt, this->shared->GetTimeMsInt64());
2041
1979
  }
2042
1980
 
2043
1981
  break;
@@ -2553,12 +2491,12 @@ namespace RTC
2553
2491
 
2554
2492
  // TODO: Missing trace info (RTP packet dump).
2555
2493
  auto notification = FBS::Transport::CreateTraceNotification(
2556
- this->shared->channelNotifier->GetBufferBuilder(),
2494
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
2557
2495
  FBS::Transport::TraceEventType::PROBATION,
2558
- DepLibUV::GetTimeMs(),
2496
+ this->shared->GetTimeMs(),
2559
2497
  FBS::Common::TraceDirection::DIRECTION_OUT);
2560
2498
 
2561
- this->shared->channelNotifier->Emit(
2499
+ this->shared->GetChannelNotifier()->Emit(
2562
2500
  this->id,
2563
2501
  FBS::Notification::Event::TRANSPORT_TRACE,
2564
2502
  FBS::Notification::Body::Transport_TraceNotification,
@@ -2576,7 +2514,7 @@ namespace RTC
2576
2514
  }
2577
2515
 
2578
2516
  auto traceInfo = FBS::Transport::CreateBweTraceInfo(
2579
- this->shared->channelNotifier->GetBufferBuilder(),
2517
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
2580
2518
  this->tccClient->GetBweType() == RTC::BweType::TRANSPORT_CC
2581
2519
  ? FBS::Transport::BweType::TRANSPORT_CC
2582
2520
  : FBS::Transport::BweType::REMB,
@@ -2589,14 +2527,14 @@ namespace RTC
2589
2527
  bitrates.availableBitrate);
2590
2528
 
2591
2529
  auto notification = FBS::Transport::CreateTraceNotification(
2592
- this->shared->channelNotifier->GetBufferBuilder(),
2530
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
2593
2531
  FBS::Transport::TraceEventType::BWE,
2594
- DepLibUV::GetTimeMs(),
2532
+ this->shared->GetTimeMs(),
2595
2533
  FBS::Common::TraceDirection::DIRECTION_OUT,
2596
2534
  FBS::Transport::TraceInfo::BweTraceInfo,
2597
2535
  traceInfo.Union());
2598
2536
 
2599
- this->shared->channelNotifier->Emit(
2537
+ this->shared->GetChannelNotifier()->Emit(
2600
2538
  this->id,
2601
2539
  FBS::Notification::Event::TRANSPORT_TRACE,
2602
2540
  FBS::Notification::Body::Transport_TraceNotification,
@@ -2674,7 +2612,7 @@ namespace RTC
2674
2612
  #endif
2675
2613
 
2676
2614
  // Update abs-send-time if present.
2677
- packet->UpdateAbsSendTime(DepLibUV::GetTimeMs());
2615
+ packet->UpdateAbsSendTime(this->shared->GetTimeMs());
2678
2616
 
2679
2617
  // Update transport wide sequence number if present.
2680
2618
  if (
@@ -2702,16 +2640,18 @@ namespace RTC
2702
2640
  // send callbacks.
2703
2641
  const std::weak_ptr<RTC::TransportCongestionControlClient> tccClientWeakPtr(this->tccClient);
2704
2642
 
2643
+ auto* shared = this->shared;
2644
+
2705
2645
  #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
2706
2646
  std::weak_ptr<RTC::SenderBandwidthEstimator> senderBweWeakPtr(this->senderBwe);
2707
2647
  RTC::SenderBandwidthEstimator::SentInfo sentInfo;
2708
2648
 
2709
2649
  sentInfo.wideSeq = this->transportWideCcSeq;
2710
2650
  sentInfo.size = packet->GetLength();
2711
- sentInfo.sendingAtMs = DepLibUV::GetTimeMs();
2651
+ sentInfo.sendingAtMs = this->shared->GetTimeMs();
2712
2652
 
2713
- auto* cb = new onSendCallback(
2714
- [tccClientWeakPtr, packetInfo, senderBweWeakPtr, sentInfo](bool sent)
2653
+ const auto* cb = new onSendCallback(
2654
+ [tccClientWeakPtr, shared, packetInfo, senderBweWeakPtr, sentInfo](bool sent) mutable
2715
2655
  {
2716
2656
  if (sent)
2717
2657
  {
@@ -2719,14 +2659,14 @@ namespace RTC
2719
2659
 
2720
2660
  if (tccClient)
2721
2661
  {
2722
- tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
2662
+ tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2723
2663
  }
2724
2664
 
2725
2665
  auto senderBwe = senderBweWeakPtr.lock();
2726
2666
 
2727
2667
  if (senderBwe)
2728
2668
  {
2729
- sentInfo.sentAtMs = DepLibUV::GetTimeMs();
2669
+ sentInfo.sentAtMs = shared->GetTimeMs();
2730
2670
  senderBwe->RtpPacketSent(sentInfo);
2731
2671
  }
2732
2672
  }
@@ -2735,7 +2675,7 @@ namespace RTC
2735
2675
  SendRtpPacket(consumer, packet, cb);
2736
2676
  #else
2737
2677
  const auto* cb = new onSendCallback(
2738
- [tccClientWeakPtr, packetInfo](bool sent)
2678
+ [tccClientWeakPtr, shared, packetInfo](bool sent)
2739
2679
  {
2740
2680
  if (sent)
2741
2681
  {
@@ -2743,7 +2683,7 @@ namespace RTC
2743
2683
 
2744
2684
  if (tccClient)
2745
2685
  {
2746
- tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
2686
+ tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2747
2687
  }
2748
2688
  }
2749
2689
  });
@@ -2764,7 +2704,7 @@ namespace RTC
2764
2704
  MS_TRACE();
2765
2705
 
2766
2706
  // Update abs-send-time if present.
2767
- packet->UpdateAbsSendTime(DepLibUV::GetTimeMs());
2707
+ packet->UpdateAbsSendTime(this->shared->GetTimeMs());
2768
2708
 
2769
2709
  // Update transport wide sequence number if present.
2770
2710
  if (
@@ -2787,16 +2727,18 @@ namespace RTC
2787
2727
 
2788
2728
  const std::weak_ptr<RTC::TransportCongestionControlClient> tccClientWeakPtr(this->tccClient);
2789
2729
 
2730
+ auto* shared = this->shared;
2731
+
2790
2732
  #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
2791
2733
  std::weak_ptr<RTC::SenderBandwidthEstimator> senderBweWeakPtr = this->senderBwe;
2792
2734
  RTC::SenderBandwidthEstimator::SentInfo sentInfo;
2793
2735
 
2794
2736
  sentInfo.wideSeq = this->transportWideCcSeq;
2795
2737
  sentInfo.size = packet->GetLength();
2796
- sentInfo.sendingAtMs = DepLibUV::GetTimeMs();
2738
+ sentInfo.sendingAtMs = this->shared->GetTimeMs();
2797
2739
 
2798
- auto* cb = new onSendCallback(
2799
- [tccClientWeakPtr, packetInfo, senderBweWeakPtr, sentInfo](bool sent)
2740
+ const auto* cb = new onSendCallback(
2741
+ [tccClientWeakPtr, shared, packetInfo, senderBweWeakPtr, sentInfo](bool sent) mutable
2800
2742
  {
2801
2743
  if (sent)
2802
2744
  {
@@ -2804,14 +2746,14 @@ namespace RTC
2804
2746
 
2805
2747
  if (tccClient)
2806
2748
  {
2807
- tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
2749
+ tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2808
2750
  }
2809
2751
 
2810
2752
  auto senderBwe = senderBweWeakPtr.lock();
2811
2753
 
2812
2754
  if (senderBwe)
2813
2755
  {
2814
- sentInfo.sentAtMs = DepLibUV::GetTimeMs();
2756
+ sentInfo.sentAtMs = shared->GetTimeMs();
2815
2757
  senderBwe->RtpPacketSent(sentInfo);
2816
2758
  }
2817
2759
  }
@@ -2820,7 +2762,7 @@ namespace RTC
2820
2762
  SendRtpPacket(consumer, packet, cb);
2821
2763
  #else
2822
2764
  const auto* cb = new onSendCallback(
2823
- [tccClientWeakPtr, packetInfo](bool sent)
2765
+ [tccClientWeakPtr, shared, packetInfo](bool sent)
2824
2766
  {
2825
2767
  if (sent)
2826
2768
  {
@@ -2828,7 +2770,7 @@ namespace RTC
2828
2770
 
2829
2771
  if (tccClient)
2830
2772
  {
2831
- tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
2773
+ tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
2832
2774
  }
2833
2775
  }
2834
2776
  });
@@ -2906,6 +2848,8 @@ namespace RTC
2906
2848
  // Notify the listener.
2907
2849
  this->listener->OnTransportConsumerProducerClosed(this, consumer);
2908
2850
 
2851
+ MS_DEBUG_DEV("Consumer closed [consumerId:%s]", consumer->id.c_str());
2852
+
2909
2853
  // Delete it.
2910
2854
  delete consumer;
2911
2855
 
@@ -2918,16 +2862,14 @@ namespace RTC
2918
2862
 
2919
2863
  void Transport::OnDataProducerMessageReceived(
2920
2864
  RTC::DataProducer* dataProducer,
2921
- const uint8_t* msg,
2922
- size_t len,
2923
- uint32_t ppid,
2865
+ RTC::SCTP::Message message,
2924
2866
  std::vector<uint16_t>& subchannels,
2925
2867
  std::optional<uint16_t> requiredSubchannel)
2926
2868
  {
2927
2869
  MS_TRACE();
2928
2870
 
2929
2871
  this->listener->OnTransportDataProducerMessageReceived(
2930
- this, dataProducer, msg, len, ppid, subchannels, requiredSubchannel);
2872
+ this, dataProducer, std::move(message), subchannels, requiredSubchannel);
2931
2873
  }
2932
2874
 
2933
2875
  void Transport::OnDataProducerPaused(RTC::DataProducer* dataProducer)
@@ -2945,35 +2887,56 @@ namespace RTC
2945
2887
  }
2946
2888
 
2947
2889
  void Transport::OnDataConsumerSendMessage(
2948
- RTC::DataConsumer* dataConsumer, const uint8_t* msg, size_t len, uint32_t ppid, onQueuedCallback* cb)
2890
+ RTC::DataConsumer* dataConsumer, RTC::SCTP::Message message, onQueuedCallback* cb)
2949
2891
  {
2950
2892
  MS_TRACE();
2951
2893
 
2952
- SendMessage(dataConsumer, msg, len, ppid, cb);
2894
+ SendMessage(dataConsumer, std::move(message), cb);
2953
2895
  }
2954
2896
 
2955
2897
  void Transport::OnDataConsumerNeedBufferedAmount(
2956
- RTC::DataConsumer* /*dataConsumer*/, uint32_t& bufferedAmount)
2898
+ const RTC::DataConsumer* dataConsumer, uint32_t& bufferedAmount) const
2957
2899
  {
2958
2900
  MS_TRACE();
2959
2901
 
2960
- if (Settings::configuration.useBuiltInSctpStack && this->sctpAssociation)
2902
+ if (this->sctpAssociation)
2903
+ {
2904
+ bufferedAmount = static_cast<uint32_t>(this->sctpAssociation->GetStreamBufferedAmount(
2905
+ dataConsumer->GetSctpStreamParameters().streamId));
2906
+ }
2907
+ else
2961
2908
  {
2962
- // TODO: SCTP
2963
- // TODO: Let's see how to obtain `streamId` argument from the DataConsumer.
2964
- // bufferedAmount = this->sctpAssociation->GetStreamBufferedAmount(streamId);
2909
+ bufferedAmount = 0;
2965
2910
  }
2966
- // TODO: Remove once we only use built-in SCTP stack.
2967
- else if (!Settings::configuration.useBuiltInSctpStack && this->oldSctpAssociation)
2911
+ }
2912
+
2913
+ void Transport::OnDataConsumerNeedBufferedAmountLowThreshold(
2914
+ const RTC::DataConsumer* dataConsumer, uint32_t& bufferedAmountLowThreshold) const
2915
+ {
2916
+ if (this->sctpAssociation)
2968
2917
  {
2969
- // NOTE: The underlaying SCTP association uses a common send buffer for all
2970
- // data consumers, hence the value given by this method indicates the data
2971
- // buffered for all data consumers in the transport.
2972
- bufferedAmount = this->oldSctpAssociation->GetSctpBufferedAmount();
2918
+ bufferedAmountLowThreshold =
2919
+ static_cast<uint32_t>(this->sctpAssociation->GetStreamBufferedAmountLowThreshold(
2920
+ dataConsumer->GetSctpStreamParameters().streamId));
2973
2921
  }
2974
2922
  else
2975
2923
  {
2976
- bufferedAmount = 0;
2924
+ bufferedAmountLowThreshold = 0;
2925
+ }
2926
+ }
2927
+
2928
+ void Transport::OnDataConsumerSetBufferedAmountLowThreshold(
2929
+ const RTC::DataConsumer* dataConsumer, uint32_t bytes) const
2930
+ {
2931
+ MS_TRACE();
2932
+
2933
+ MS_ASSERT(
2934
+ dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP, "DataConsumer must have type SCTP");
2935
+
2936
+ if (this->sctpAssociation)
2937
+ {
2938
+ this->sctpAssociation->SetStreamBufferedAmountLowThreshold(
2939
+ dataConsumer->GetSctpStreamParameters().streamId, static_cast<size_t>(bytes));
2977
2940
  }
2978
2941
  }
2979
2942
 
@@ -2984,26 +2947,22 @@ namespace RTC
2984
2947
  // Remove it from the maps.
2985
2948
  this->mapDataConsumers.erase(dataConsumer->id);
2986
2949
 
2987
- // Notify the listener.
2988
- this->listener->OnTransportDataConsumerDataProducerClosed(this, dataConsumer);
2989
-
2990
- if (Settings::configuration.useBuiltInSctpStack)
2950
+ if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
2991
2951
  {
2992
- if (this->sctpAssociation && dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
2993
- {
2994
- // TODO: SCTP
2995
- }
2952
+ this->mapSctpStreamIdDataConsumers.erase(dataConsumer->GetSctpStreamParameters().streamId);
2996
2953
  }
2997
- // TODO: Remove once we only use built-in SCTP stack.
2998
- else
2954
+
2955
+ if (this->sctpAssociation)
2999
2956
  {
3000
- if (this->oldSctpAssociation && dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
3001
- {
3002
- // Tell the SctpAssociation so it can reset the SCTP stream.
3003
- this->oldSctpAssociation->DataConsumerClosed(dataConsumer);
3004
- }
2957
+ this->sctpAssociation->ResetStreams(
2958
+ std::array<uint16_t, 1>{ dataConsumer->GetSctpStreamParameters().streamId });
3005
2959
  }
3006
2960
 
2961
+ // Notify the listener.
2962
+ this->listener->OnTransportDataConsumerDataProducerClosed(this, dataConsumer);
2963
+
2964
+ MS_DEBUG_DEV("DataConsumer closed [dataConsumerId:%s]", dataConsumer->id.c_str());
2965
+
3007
2966
  // Delete it.
3008
2967
  delete dataConsumer;
3009
2968
  }
@@ -3015,15 +2974,15 @@ namespace RTC
3015
2974
  // Ignore if destroying.
3016
2975
  // NOTE: This is because when the child class (i.e. WebRtcTransport) is deleted,
3017
2976
  // its destructor is called first and then the parent Transport's destructor,
3018
- // and we would end here calling SendSctpData() which is an abstract method.
3019
- if (this->destroying)
2977
+ // and we would end here calling SendData() which is an abstract method.
2978
+ if (this->isDestroying)
3020
2979
  {
3021
2980
  MS_WARN_DEV("ignoring sending data because Transport is being destroying");
3022
2981
 
3023
2982
  return false;
3024
2983
  }
3025
2984
 
3026
- return SendSctpData(data, len);
2985
+ return SendData(data, len);
3027
2986
  }
3028
2987
 
3029
2988
  void Transport::OnAssociationConnecting()
@@ -3031,14 +2990,15 @@ namespace RTC
3031
2990
  MS_TRACE();
3032
2991
 
3033
2992
  // Notify the Node Transport.
3034
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3035
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::CONNECTING);
2993
+ auto sctpStateChangeNotification = FBS::Transport::CreateSctpStateChangeNotification(
2994
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
2995
+ FBS::SctpAssociation::SctpState::CONNECTING);
3036
2996
 
3037
- this->shared->channelNotifier->Emit(
2997
+ this->shared->GetChannelNotifier()->Emit(
3038
2998
  this->id,
3039
2999
  FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3040
3000
  FBS::Notification::Body::Transport_SctpStateChangeNotification,
3041
- sctpStateChangeOffset);
3001
+ sctpStateChangeNotification);
3042
3002
  }
3043
3003
 
3044
3004
  void Transport::OnAssociationConnected()
@@ -3056,26 +3016,56 @@ namespace RTC
3056
3016
  }
3057
3017
  }
3058
3018
 
3059
- // Notify the Node Transport.
3060
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3061
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::CONNECTED);
3019
+ // Notify the upper layer.
3062
3020
 
3063
- this->shared->channelNotifier->Emit(
3021
+ // First tell it about the SCTP negotiated capabilities.
3022
+ auto sctpNegotiatedCapabilitiesOffset = FBS::SctpAssociation::CreateSctpNegotiatedCapabilities(
3023
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
3024
+ this->sctpAssociation->GetNegotiatedMaxOutboundStreams(),
3025
+ this->sctpAssociation->GetNegotiatedMaxInboundStreams());
3026
+
3027
+ auto sctpNegotiatedCapabilitiesNotification =
3028
+ FBS::Transport::CreateSctpNegotiatedCapabilitiesNotification(
3029
+ this->shared->GetChannelNotifier()->GetBufferBuilder(), sctpNegotiatedCapabilitiesOffset);
3030
+
3031
+ this->shared->GetChannelNotifier()->Emit(
3032
+ this->id,
3033
+ FBS::Notification::Event::TRANSPORT_SCTP_NEGOTIATED_CAPABILITIES,
3034
+ FBS::Notification::Body::Transport_SctpNegotiatedCapabilitiesNotification,
3035
+ sctpNegotiatedCapabilitiesNotification);
3036
+
3037
+ // Then announce "connected" SCTP state.
3038
+ auto sctpStateChangeNotification = FBS::Transport::CreateSctpStateChangeNotification(
3039
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
3040
+ FBS::SctpAssociation::SctpState::CONNECTED);
3041
+
3042
+ this->shared->GetChannelNotifier()->Emit(
3064
3043
  this->id,
3065
3044
  FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3066
3045
  FBS::Notification::Body::Transport_SctpStateChangeNotification,
3067
- sctpStateChangeOffset);
3046
+ sctpStateChangeNotification);
3068
3047
 
3069
- // TODO: SCTP: REMOVE
3070
- MS_DUMP("---- SCTP Association connected, dump():");
3048
+ // For debugging purposes.
3049
+ #if MS_LOG_DEV_LEVEL == 3
3050
+ MS_DUMP("--- SCTP association connected:");
3071
3051
  this->sctpAssociation->Dump();
3052
+ #endif
3072
3053
  }
3073
3054
 
3074
- void Transport::OnAssociationFailed(
3075
- RTC::SCTP::Types::ErrorKind /*errorKind*/, std::string_view /*errorMessage*/)
3055
+ void Transport::OnAssociationFailed(RTC::SCTP::Types::ErrorKind errorKind, std::string_view errorMessage)
3076
3056
  {
3077
3057
  MS_TRACE();
3078
3058
 
3059
+ const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3060
+
3061
+ MS_WARN_TAG(
3062
+ sctp,
3063
+ "SCTP association failed [errorKind:%.*s, message:%.*s]",
3064
+ static_cast<int>(errorKindStringView.size()),
3065
+ errorKindStringView.data(),
3066
+ static_cast<int>(errorMessage.size()),
3067
+ errorMessage.data());
3068
+
3079
3069
  // Tell all DataConsumers.
3080
3070
  for (auto& kv : this->mapDataConsumers)
3081
3071
  {
@@ -3088,21 +3078,34 @@ namespace RTC
3088
3078
  }
3089
3079
 
3090
3080
  // Notify the Node Transport.
3091
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3092
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::FAILED);
3081
+ auto sctpStateChangeNotification = FBS::Transport::CreateSctpStateChangeNotification(
3082
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
3083
+ FBS::SctpAssociation::SctpState::FAILED);
3093
3084
 
3094
- this->shared->channelNotifier->Emit(
3085
+ this->shared->GetChannelNotifier()->Emit(
3095
3086
  this->id,
3096
3087
  FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3097
3088
  FBS::Notification::Body::Transport_SctpStateChangeNotification,
3098
- sctpStateChangeOffset);
3089
+ sctpStateChangeNotification);
3099
3090
  }
3100
3091
 
3101
- void Transport::OnAssociationClosed(
3102
- RTC::SCTP::Types::ErrorKind /*errorKind*/, std::string_view /*errorMessage*/)
3092
+ void Transport::OnAssociationClosed(RTC::SCTP::Types::ErrorKind errorKind, std::string_view errorMessage)
3103
3093
  {
3104
3094
  MS_TRACE();
3105
3095
 
3096
+ if (errorKind != RTC::SCTP::Types::ErrorKind::SUCCESS)
3097
+ {
3098
+ const auto errorKindStringView = RTC::SCTP::Types::ErrorKindToString(errorKind);
3099
+
3100
+ MS_WARN_TAG(
3101
+ sctp,
3102
+ "SCTP association closed [errorKind:%.*s, message:%.*s]",
3103
+ static_cast<int>(errorKindStringView.size()),
3104
+ errorKindStringView.data(),
3105
+ static_cast<int>(errorMessage.size()),
3106
+ errorMessage.data());
3107
+ }
3108
+
3106
3109
  // Tell all DataConsumers.
3107
3110
  for (auto& kv : this->mapDataConsumers)
3108
3111
  {
@@ -3115,21 +3118,22 @@ namespace RTC
3115
3118
  }
3116
3119
 
3117
3120
  // Notify the Node Transport.
3118
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3119
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::CLOSED);
3121
+ auto sctpStateChangeNotification = FBS::Transport::CreateSctpStateChangeNotification(
3122
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
3123
+ FBS::SctpAssociation::SctpState::CLOSED);
3120
3124
 
3121
- this->shared->channelNotifier->Emit(
3125
+ this->shared->GetChannelNotifier()->Emit(
3122
3126
  this->id,
3123
3127
  FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3124
3128
  FBS::Notification::Body::Transport_SctpStateChangeNotification,
3125
- sctpStateChangeOffset);
3129
+ sctpStateChangeNotification);
3126
3130
  }
3127
3131
 
3128
3132
  void Transport::OnAssociationRestarted()
3129
3133
  {
3130
3134
  MS_TRACE();
3131
3135
 
3132
- // TODO: SCTP
3136
+ MS_DEBUG_TAG(sctp, "SCTP association restarted");
3133
3137
  }
3134
3138
 
3135
3139
  void Transport::OnAssociationError(RTC::SCTP::Types::ErrorKind errorKind, std::string_view errorMessage)
@@ -3140,236 +3144,164 @@ namespace RTC
3140
3144
 
3141
3145
  MS_WARN_TAG(
3142
3146
  sctp,
3143
- "SCTP Association error [kind:%.*s, message:%.*s]",
3147
+ "SCTP association error [errorKind:%.*s, message:%.*s]",
3144
3148
  static_cast<int>(errorKindStringView.size()),
3145
3149
  errorKindStringView.data(),
3146
3150
  static_cast<int>(errorMessage.size()),
3147
3151
  errorMessage.data());
3148
3152
  }
3149
3153
 
3150
- void Transport::OnAssociationMessageReceived(RTC::SCTP::Message /*message*/)
3151
- {
3152
- MS_TRACE();
3153
-
3154
- // TODO: SCTP
3155
- }
3156
-
3157
- void Transport::OnAssociationStreamsResetPerformed(std::span<const uint16_t> /*outboundStreamIds*/)
3154
+ void Transport::OnAssociationMessageReceived(RTC::SCTP::Message message)
3158
3155
  {
3159
3156
  MS_TRACE();
3160
3157
 
3161
- // TODO: SCTP
3162
- }
3158
+ RTC::DataProducer* dataProducer = this->sctpListener.GetDataProducer(message.GetStreamId());
3163
3159
 
3164
- void Transport::OnAssociationStreamsResetFailed(
3165
- std::span<const uint16_t> /*outboundStreamIds*/, std::string_view /*errorMessage*/)
3166
- {
3167
- MS_TRACE();
3160
+ if (!dataProducer)
3161
+ {
3162
+ MS_WARN_TAG(
3163
+ sctp,
3164
+ "no suitable DataProducer for received SCTP message [streamId:%" PRIu16 "]",
3165
+ message.GetStreamId());
3168
3166
 
3169
- // TODO: SCTP
3170
- }
3167
+ return;
3168
+ }
3171
3169
 
3172
- void Transport::OnAssociationInboundStreamsReset(std::span<const uint16_t> /*inboundStreamIds*/)
3173
- {
3174
- MS_TRACE();
3170
+ // Pass the SCTP message to the corresponding DataProducer.
3171
+ try
3172
+ {
3173
+ static thread_local std::vector<uint16_t> emptySubchannels;
3175
3174
 
3176
- // TODO: SCTP
3175
+ dataProducer->ReceiveMessage(
3176
+ std::move(message), emptySubchannels, /*requiredSubchannel*/ std::nullopt);
3177
+ }
3178
+ catch (std::exception& error)
3179
+ {
3180
+ MS_WARN_TAG(
3181
+ sctp,
3182
+ "DataProducer::ReceiveMessage() failed for received SCTP message [streamId:%" PRIu16 "]: %s",
3183
+ message.GetStreamId(),
3184
+ error.what());
3185
+ }
3177
3186
  }
3178
3187
 
3179
- void Transport::OnAssociationStreamBufferedAmountLow(uint16_t /*streamId*/)
3188
+ void Transport::OnAssociationStreamsResetPerformed(std::span<const uint16_t> /*outboundStreamIds*/)
3180
3189
  {
3181
3190
  MS_TRACE();
3182
3191
 
3183
- // TODO: SCTP
3192
+ MS_DEBUG_DEV("SCTP association streams reset performed");
3184
3193
  }
3185
3194
 
3186
- void Transport::OnAssociationTotalBufferedAmountLow()
3195
+ void Transport::OnAssociationStreamsResetFailed(
3196
+ std::span<const uint16_t> /*outboundStreamIds*/, std::string_view errorMessage)
3187
3197
  {
3188
3198
  MS_TRACE();
3189
3199
 
3190
- // TODO: SCTP
3200
+ MS_WARN_TAG(
3201
+ sctp,
3202
+ "SCTP association streams reset failed [message:%.*s]",
3203
+ static_cast<int>(errorMessage.size()),
3204
+ errorMessage.data());
3191
3205
  }
3192
3206
 
3193
- bool Transport::OnAssociationIsTransportReadyForSctp()
3207
+ void Transport::OnAssociationInboundStreamsReset(std::span<const uint16_t> inboundStreamIds)
3194
3208
  {
3195
3209
  MS_TRACE();
3196
3210
 
3197
- // We are ready for SCTP traffic if the transport is connected (e.g. the
3198
- // WebRtcTransport has ICE and DTLS connected) and there is at least a
3199
- // DataProducer or DataConsumer.
3211
+ // https://datatracker.ietf.org/doc/html/rfc8831#section-6.7
3200
3212
  //
3201
- // NOTE: We don't want to start SCTP connection if there are no DataProducers
3202
- // and DataConsumers because the peer (e.g. a browser) may have not started
3203
- // its SCTP stack (e.g. no "m=application" media section in its SDP) so if we
3204
- // initiate the SCTP connection it would fail after some time.
3205
- return IsConnected() && (this->mapDataProducers.size() > 0 || this->mapDataConsumers.size() > 0);
3206
- }
3207
-
3208
- // TODO: SCTP: Add OnAssociationLifecycleMessageXxxxxx() methods.
3209
-
3210
- void Transport::OnSctpAssociationConnecting(RTC::SctpAssociation* /*sctpAssociation*/)
3211
- {
3212
- MS_TRACE();
3213
-
3214
- // Notify the Node Transport.
3215
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3216
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::CONNECTING);
3217
-
3218
- this->shared->channelNotifier->Emit(
3219
- this->id,
3220
- FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3221
- FBS::Notification::Body::Transport_SctpStateChangeNotification,
3222
- sctpStateChangeOffset);
3223
- }
3224
-
3225
- void Transport::OnSctpAssociationConnected(RTC::SctpAssociation* /*sctpAssociation*/)
3226
- {
3227
- MS_TRACE();
3228
-
3229
- // Tell all DataConsumers.
3230
- for (auto& kv : this->mapDataConsumers)
3213
+ // "Closing of a data channel MUST be signaled by resetting the corresponding
3214
+ // outgoing streams [RFC6525]. This means that if one side decides to close
3215
+ // the data channel, it resets the corresponding outgoing stream. When the
3216
+ // peer sees that an incoming stream was reset, it also resets its
3217
+ // corresponding outgoing stream."
3218
+ if (this->sctpAssociation->IsDataChannel())
3231
3219
  {
3232
- auto* dataConsumer = kv.second;
3220
+ std::vector<RTC::DataConsumer*> dataConsumersToClose;
3221
+ std::vector<uint16_t> streamsToReset;
3233
3222
 
3234
- if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
3223
+ for (const auto streamId : inboundStreamIds)
3235
3224
  {
3236
- dataConsumer->SctpAssociationConnected();
3237
- }
3238
- }
3239
-
3240
- // Notify the Node Transport.
3241
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3242
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::CONNECTED);
3225
+ // Only reset the outgoing stream if there is a live DataConsumer
3226
+ // using it. If the DataChannel was closed by the app, the DataConsumer
3227
+ // will have already been closed and removed.
3228
+ const auto it = this->mapSctpStreamIdDataConsumers.find(streamId);
3243
3229
 
3244
- this->shared->channelNotifier->Emit(
3245
- this->id,
3246
- FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3247
- FBS::Notification::Body::Transport_SctpStateChangeNotification,
3248
- sctpStateChangeOffset);
3249
- }
3250
-
3251
- void Transport::OnSctpAssociationFailed(RTC::SctpAssociation* /*sctpAssociation*/)
3252
- {
3253
- MS_TRACE();
3230
+ if (it != this->mapSctpStreamIdDataConsumers.end())
3231
+ {
3232
+ auto* dataConsumer = it->second;
3254
3233
 
3255
- // Tell all DataConsumers.
3256
- for (auto& kv : this->mapDataConsumers)
3257
- {
3258
- auto* dataConsumer = kv.second;
3234
+ dataConsumersToClose.push_back(dataConsumer);
3235
+ streamsToReset.push_back(streamId);
3236
+ }
3237
+ }
3259
3238
 
3260
- if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
3239
+ if (!dataConsumersToClose.empty())
3261
3240
  {
3262
- dataConsumer->SctpAssociationClosed();
3263
- }
3264
- }
3241
+ this->sctpAssociation->ResetStreams(streamsToReset);
3265
3242
 
3266
- // Notify the Node Transport.
3267
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3268
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::FAILED);
3243
+ for (auto* dataConsumer : dataConsumersToClose)
3244
+ {
3245
+ // Remove it from the maps.
3246
+ this->mapDataConsumers.erase(dataConsumer->id);
3269
3247
 
3270
- this->shared->channelNotifier->Emit(
3271
- this->id,
3272
- FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3273
- FBS::Notification::Body::Transport_SctpStateChangeNotification,
3274
- sctpStateChangeOffset);
3275
- }
3248
+ if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
3249
+ {
3250
+ this->mapSctpStreamIdDataConsumers.erase(dataConsumer->GetSctpStreamParameters().streamId);
3251
+ }
3276
3252
 
3277
- void Transport::OnSctpAssociationClosed(RTC::SctpAssociation* /*sctpAssociation*/)
3278
- {
3279
- MS_TRACE();
3253
+ // Notify the listener.
3254
+ this->listener->OnTransportDataConsumerClosed(this, dataConsumer);
3280
3255
 
3281
- // Tell all DataConsumers.
3282
- for (auto& kv : this->mapDataConsumers)
3283
- {
3284
- auto* dataConsumer = kv.second;
3256
+ MS_DEBUG_DEV(
3257
+ "SCTP DataConsumer closed via SCTP inbound stream reset [dataConsumerId:%s, streamId:%" PRIu16
3258
+ "]",
3259
+ dataConsumer->id.c_str(),
3260
+ dataConsumer->GetSctpStreamParameters().streamId);
3285
3261
 
3286
- if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
3287
- {
3288
- dataConsumer->SctpAssociationClosed();
3262
+ // Delete it.
3263
+ delete dataConsumer;
3264
+ }
3289
3265
  }
3290
3266
  }
3291
-
3292
- // Notify the Node Transport.
3293
- auto sctpStateChangeOffset = FBS::Transport::CreateSctpStateChangeNotification(
3294
- this->shared->channelNotifier->GetBufferBuilder(), FBS::SctpAssociation::SctpState::CLOSED);
3295
-
3296
- this->shared->channelNotifier->Emit(
3297
- this->id,
3298
- FBS::Notification::Event::TRANSPORT_SCTP_STATE_CHANGE,
3299
- FBS::Notification::Body::Transport_SctpStateChangeNotification,
3300
- sctpStateChangeOffset);
3301
3267
  }
3302
3268
 
3303
- void Transport::OnSctpAssociationSendData(
3304
- RTC::SctpAssociation* /*sctpAssociation*/, const uint8_t* data, size_t len)
3269
+ void Transport::OnAssociationStreamBufferedAmountLow(uint16_t streamId)
3305
3270
  {
3306
3271
  MS_TRACE();
3307
3272
 
3308
- // Ignore if destroying.
3309
- // NOTE: This is because when the child class (i.e. WebRtcTransport) is deleted,
3310
- // its destructor is called first and then the parent Transport's destructor,
3311
- // and we would end here calling SendSctpData() which is an abstract method.
3312
- if (this->destroying)
3313
- {
3314
- MS_WARN_DEV("ignoring sending data because Transport is being destroying");
3273
+ const auto* dataConsumer = GetSctpDataConsumerByStreamId(streamId);
3315
3274
 
3275
+ if (!dataConsumer)
3276
+ {
3316
3277
  return;
3317
3278
  }
3318
3279
 
3319
- SendSctpData(data, len);
3280
+ dataConsumer->SctpBufferedAmountLow(this->sctpAssociation->GetStreamBufferedAmount(streamId));
3320
3281
  }
3321
3282
 
3322
- void Transport::OnSctpAssociationMessageReceived(
3323
- RTC::SctpAssociation* /*sctpAssociation*/,
3324
- uint16_t streamId,
3325
- const uint8_t* msg,
3326
- size_t len,
3327
- uint32_t ppid)
3283
+ void Transport::OnAssociationTotalBufferedAmountLow()
3328
3284
  {
3329
3285
  MS_TRACE();
3330
3286
 
3331
- RTC::DataProducer* dataProducer = this->sctpListener.GetDataProducer(streamId);
3332
-
3333
- if (!dataProducer)
3334
- {
3335
- MS_WARN_TAG(
3336
- sctp, "no suitable DataProducer for received SCTP message [streamId:%" PRIu16 "]", streamId);
3337
-
3338
- return;
3339
- }
3340
-
3341
- // Pass the SCTP message to the corresponding DataProducer.
3342
- try
3343
- {
3344
- static std::vector<uint16_t> emptySubchannels;
3345
-
3346
- dataProducer->ReceiveMessage(
3347
- msg, len, ppid, emptySubchannels, /*requiredSubchannel*/ std::nullopt);
3348
- }
3349
- catch (std::exception& error)
3350
- {
3351
- MS_WARN_TAG(
3352
- sctp,
3353
- "DataProducer::ReceiveMessage() failed for received SCTP message [streamId:%" PRIu16 "]: %s",
3354
- streamId,
3355
- error.what());
3356
- }
3287
+ // TODO: SCTP: Here we should emit a new event to the upper layer saying
3288
+ // that the transport SCTP total buffered amount is low. However we don't
3289
+ // expose `SctpOptions::totalBufferedAmountLowThreshold` to Transport.
3357
3290
  }
3358
3291
 
3359
- void Transport::OnSctpAssociationBufferedAmount(
3360
- RTC::SctpAssociation* /*sctpAssociation*/, uint32_t bufferedAmount)
3292
+ bool Transport::OnAssociationIsTransportReadyForSctp()
3361
3293
  {
3362
3294
  MS_TRACE();
3363
3295
 
3364
- for (const auto& kv : this->mapDataConsumers)
3365
- {
3366
- auto* dataConsumer = kv.second;
3367
-
3368
- if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
3369
- {
3370
- dataConsumer->SetSctpAssociationBufferedAmount(bufferedAmount);
3371
- }
3372
- }
3296
+ // We are ready for SCTP traffic if the transport is connected (e.g. the
3297
+ // WebRtcTransport has ICE and DTLS connected) and there is at least a
3298
+ // DataProducer or DataConsumer.
3299
+ //
3300
+ // NOTE: We don't want to start SCTP connection if there are no DataProducers
3301
+ // and DataConsumers because the peer (e.g. a browser) may have not started
3302
+ // its SCTP stack (e.g. no "m=application" media section in its SDP) so if we
3303
+ // initiate the SCTP connection it would fail after some time.
3304
+ return IsConnected() && (!this->mapDataProducers.empty() || !this->mapDataConsumers.empty());
3373
3305
  }
3374
3306
 
3375
3307
  void Transport::OnTransportCongestionControlClientBitrates(
@@ -3395,7 +3327,7 @@ namespace RTC
3395
3327
  MS_TRACE();
3396
3328
 
3397
3329
  // Update abs-send-time if present.
3398
- packet->UpdateAbsSendTime(DepLibUV::GetTimeMs());
3330
+ packet->UpdateAbsSendTime(this->shared->GetTimeMs());
3399
3331
 
3400
3332
  // Update transport wide sequence number if present.
3401
3333
  if (
@@ -3421,6 +3353,8 @@ namespace RTC
3421
3353
 
3422
3354
  const std::weak_ptr<RTC::TransportCongestionControlClient> tccClientWeakPtr(this->tccClient);
3423
3355
 
3356
+ auto* shared = this->shared;
3357
+
3424
3358
  #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
3425
3359
  std::weak_ptr<RTC::SenderBandwidthEstimator> senderBweWeakPtr = this->senderBwe;
3426
3360
  RTC::SenderBandwidthEstimator::SentInfo sentInfo;
@@ -3428,10 +3362,10 @@ namespace RTC
3428
3362
  sentInfo.wideSeq = this->transportWideCcSeq;
3429
3363
  sentInfo.size = packet->GetLength();
3430
3364
  sentInfo.isProbation = true;
3431
- sentInfo.sendingAtMs = DepLibUV::GetTimeMs();
3365
+ sentInfo.sendingAtMs = this->shared->GetTimeMs();
3432
3366
 
3433
- auto* cb = new onSendCallback(
3434
- [tccClientWeakPtr, packetInfo, senderBweWeakPtr, sentInfo](bool sent)
3367
+ const auto* cb = new onSendCallback(
3368
+ [tccClientWeakPtr, shared, packetInfo, senderBweWeakPtr, sentInfo](bool sent) mutable
3435
3369
  {
3436
3370
  if (sent)
3437
3371
  {
@@ -3439,14 +3373,14 @@ namespace RTC
3439
3373
 
3440
3374
  if (tccClient)
3441
3375
  {
3442
- tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
3376
+ tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
3443
3377
  }
3444
3378
 
3445
3379
  auto senderBwe = senderBweWeakPtr.lock();
3446
3380
 
3447
3381
  if (senderBwe)
3448
3382
  {
3449
- sentInfo.sentAtMs = DepLibUV::GetTimeMs();
3383
+ sentInfo.sentAtMs = shared->GetTimeMs();
3450
3384
  senderBwe->RtpPacketSent(sentInfo);
3451
3385
  }
3452
3386
  }
@@ -3455,7 +3389,7 @@ namespace RTC
3455
3389
  SendRtpPacket(nullptr, packet, cb);
3456
3390
  #else
3457
3391
  const auto* cb = new onSendCallback(
3458
- [tccClientWeakPtr, packetInfo](bool sent)
3392
+ [tccClientWeakPtr, shared, packetInfo](bool sent)
3459
3393
  {
3460
3394
  if (sent)
3461
3395
  {
@@ -3463,7 +3397,7 @@ namespace RTC
3463
3397
 
3464
3398
  if (tccClient)
3465
3399
  {
3466
- tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
3400
+ tccClient->PacketSent(packetInfo, shared->GetTimeMsInt64());
3467
3401
  }
3468
3402
  }
3469
3403
  });
@@ -3486,7 +3420,7 @@ namespace RTC
3486
3420
  packet->GetSequenceNumber(),
3487
3421
  this->transportWideCcSeq,
3488
3422
  packet->GetLength(),
3489
- this->sendProbationTransmission.GetBitrate(DepLibUV::GetTimeMs()));
3423
+ this->sendProbationTransmission.GetBitrate(this->shared->GetTimeMs()));
3490
3424
  }
3491
3425
 
3492
3426
  void Transport::OnTransportCongestionControlServerSendRtcpPacket(
@@ -3518,7 +3452,7 @@ namespace RTC
3518
3452
  }
3519
3453
  #endif
3520
3454
 
3521
- void Transport::OnTimer(TimerHandle* timer)
3455
+ void Transport::OnTimer(TimerHandleInterface* timer)
3522
3456
  {
3523
3457
  MS_TRACE();
3524
3458
 
@@ -3526,7 +3460,7 @@ namespace RTC
3526
3460
  if (timer == this->rtcpTimer)
3527
3461
  {
3528
3462
  auto interval = static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs);
3529
- const uint64_t nowMs = DepLibUV::GetTimeMs();
3463
+ const uint64_t nowMs = this->shared->GetTimeMs();
3530
3464
 
3531
3465
  SendRtcp(nowMs);
3532
3466