werift 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (437) hide show
  1. package/README.md +63 -0
  2. package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
  3. package/lib/common/src/binary.d.ts +1 -3
  4. package/lib/common/src/binary.js +8 -6
  5. package/lib/common/src/binary.js.map +1 -1
  6. package/lib/common/src/binaryData.js +2 -1
  7. package/lib/common/src/binaryData.js.map +1 -1
  8. package/lib/common/src/log.js +5 -7
  9. package/lib/common/src/log.js.map +1 -1
  10. package/lib/common/src/transport.js +10 -5
  11. package/lib/common/src/transport.js.map +1 -1
  12. package/lib/dtls/src/context/cipher.d.ts +1 -1
  13. package/lib/dtls/src/context/cipher.js +6 -3
  14. package/lib/dtls/src/context/cipher.js.map +1 -1
  15. package/lib/dtls/src/context/dtls.js +4 -2
  16. package/lib/dtls/src/context/dtls.js.map +1 -1
  17. package/lib/dtls/src/context/transport.js +2 -1
  18. package/lib/dtls/src/context/transport.js.map +1 -1
  19. package/lib/dtls/src/flight/client/flight1.js +2 -1
  20. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  21. package/lib/dtls/src/flight/client/flight5.js +4 -2
  22. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  23. package/lib/dtls/src/flight/flight.d.ts +1 -1
  24. package/lib/dtls/src/flight/flight.js +8 -4
  25. package/lib/dtls/src/flight/flight.js.map +1 -1
  26. package/lib/dtls/src/flight/server/flight4.js +4 -2
  27. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  28. package/lib/dtls/src/flight/server/flight6.js +2 -1
  29. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  30. package/lib/dtls/src/handshake/const.d.ts +17 -13
  31. package/lib/dtls/src/handshake/const.js +16 -14
  32. package/lib/dtls/src/handshake/const.js.map +1 -1
  33. package/lib/dtls/src/handshake/message/alert.js +4 -2
  34. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  35. package/lib/dtls/src/handshake/message/certificate.js +2 -1
  36. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  37. package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
  38. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  39. package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
  40. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  41. package/lib/dtls/src/handshake/message/client/hello.js +14 -7
  42. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  43. package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
  44. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  45. package/lib/dtls/src/handshake/message/finished.js +2 -1
  46. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  47. package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
  48. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  49. package/lib/dtls/src/handshake/message/server/hello.js +12 -6
  50. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  51. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  52. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
  53. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  54. package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
  55. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  56. package/lib/dtls/src/handshake/random.d.ts +2 -2
  57. package/lib/dtls/src/handshake/random.js +5 -2
  58. package/lib/dtls/src/handshake/random.js.map +1 -1
  59. package/lib/dtls/src/record/const.d.ts +43 -33
  60. package/lib/dtls/src/record/const.js +43 -36
  61. package/lib/dtls/src/record/const.js.map +1 -1
  62. package/lib/dtls/src/record/message/fragment.js +12 -6
  63. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  64. package/lib/dtls/src/record/message/header.js +10 -5
  65. package/lib/dtls/src/record/message/header.js.map +1 -1
  66. package/lib/dtls/src/record/message/plaintext.js +4 -2
  67. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  68. package/lib/dtls/src/record/receive.js +2 -2
  69. package/lib/dtls/src/record/receive.js.map +1 -1
  70. package/lib/dtls/src/socket.js +4 -2
  71. package/lib/dtls/src/socket.js.map +1 -1
  72. package/lib/ice/src/candidate.d.ts +1 -1
  73. package/lib/ice/src/candidate.js +24 -12
  74. package/lib/ice/src/candidate.js.map +1 -1
  75. package/lib/ice/src/dns/lookup.d.ts +10 -1
  76. package/lib/ice/src/dns/lookup.js +42 -7
  77. package/lib/ice/src/dns/lookup.js.map +1 -1
  78. package/lib/ice/src/exceptions.d.ts +21 -5
  79. package/lib/ice/src/exceptions.js +58 -13
  80. package/lib/ice/src/exceptions.js.map +1 -1
  81. package/lib/ice/src/ice.d.ts +52 -8
  82. package/lib/ice/src/ice.js +288 -152
  83. package/lib/ice/src/ice.js.map +1 -1
  84. package/lib/ice/src/iceBase.d.ts +126 -11
  85. package/lib/ice/src/iceBase.js +165 -12
  86. package/lib/ice/src/iceBase.js.map +1 -1
  87. package/lib/ice/src/stun/transaction.d.ts +30 -1
  88. package/lib/ice/src/stun/transaction.js +86 -17
  89. package/lib/ice/src/stun/transaction.js.map +1 -1
  90. package/lib/ice/src/turn/credential.d.ts +49 -0
  91. package/lib/ice/src/turn/credential.js +78 -0
  92. package/lib/ice/src/turn/credential.js.map +1 -0
  93. package/lib/ice/src/turn/protocol.d.ts +29 -8
  94. package/lib/ice/src/turn/protocol.js +121 -48
  95. package/lib/ice/src/turn/protocol.js.map +1 -1
  96. package/lib/ice-server/src/stun/attributes.d.ts +2 -0
  97. package/lib/ice-server/src/stun/attributes.js +7 -1
  98. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  99. package/lib/ice-server/src/stun/const.d.ts +24 -16
  100. package/lib/ice-server/src/stun/const.js +22 -18
  101. package/lib/ice-server/src/stun/const.js.map +1 -1
  102. package/lib/ice-server/src/stun/message.d.ts +1 -3
  103. package/lib/ice-server/src/stun/message.js +13 -9
  104. package/lib/ice-server/src/stun/message.js.map +1 -1
  105. package/lib/index.mjs +9770 -2648
  106. package/lib/nonstandard/index.mjs +2428 -1052
  107. package/lib/polyfill/dom.mjs +8738 -1815
  108. package/lib/polyfill/index.mjs +8738 -1815
  109. package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
  110. package/lib/rtp/src/codec/assertPayload.js +12 -0
  111. package/lib/rtp/src/codec/assertPayload.js.map +1 -0
  112. package/lib/rtp/src/codec/av1.js +2 -0
  113. package/lib/rtp/src/codec/av1.js.map +1 -1
  114. package/lib/rtp/src/codec/h264.js +35 -43
  115. package/lib/rtp/src/codec/h264.js.map +1 -1
  116. package/lib/rtp/src/codec/vp8.js +11 -5
  117. package/lib/rtp/src/codec/vp8.js.map +1 -1
  118. package/lib/rtp/src/codec/vp9.js +12 -0
  119. package/lib/rtp/src/codec/vp9.js.map +1 -1
  120. package/lib/rtp/src/extra/container/mp4/container.js +2 -1
  121. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  122. package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
  123. package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
  124. package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
  125. package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
  126. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  127. package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
  128. package/lib/rtp/src/extra/container/ogg/index.js +1 -0
  129. package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
  130. package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
  131. package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
  132. package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
  133. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
  134. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  135. package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
  136. package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
  137. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  138. package/lib/rtp/src/extra/processor/dtx.js +4 -2
  139. package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
  140. package/lib/rtp/src/extra/processor/index.d.ts +2 -0
  141. package/lib/rtp/src/extra/processor/index.js +2 -0
  142. package/lib/rtp/src/extra/processor/index.js.map +1 -1
  143. package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
  144. package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
  145. package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
  146. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
  147. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
  148. package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
  149. package/lib/rtp/src/extra/processor/lipsync.js +202 -51
  150. package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
  151. package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
  152. package/lib/rtp/src/extra/processor/mp4.js +6 -3
  153. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  154. package/lib/rtp/src/extra/processor/mute.js +4 -2
  155. package/lib/rtp/src/extra/processor/mute.js.map +1 -1
  156. package/lib/rtp/src/extra/processor/nack.js +4 -2
  157. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  158. package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
  159. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  160. package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
  161. package/lib/rtp/src/extra/processor/ogg.js +221 -0
  162. package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
  163. package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
  164. package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
  165. package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
  166. package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
  167. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  168. package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
  169. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  170. package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
  171. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  172. package/lib/rtp/src/extra/processor/webm.js +14 -7
  173. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  174. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  175. package/lib/rtp/src/index.d.ts +7 -0
  176. package/lib/rtp/src/index.js +7 -0
  177. package/lib/rtp/src/index.js.map +1 -1
  178. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
  179. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
  180. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  181. package/lib/rtp/src/rtcp/rtcp.js +8 -4
  182. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  183. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
  184. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
  185. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
  186. package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
  187. package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
  188. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  189. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
  190. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
  191. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
  192. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
  193. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
  194. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
  195. package/lib/rtp/src/rtcp/sr.js +1 -0
  196. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  197. package/lib/rtp/src/rtp/continuity.d.ts +36 -0
  198. package/lib/rtp/src/rtp/continuity.js +100 -0
  199. package/lib/rtp/src/rtp/continuity.js.map +1 -0
  200. package/lib/rtp/src/rtp/headerExtension.js +41 -21
  201. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  202. package/lib/rtp/src/rtp/padding.d.ts +17 -0
  203. package/lib/rtp/src/rtp/padding.js +37 -0
  204. package/lib/rtp/src/rtp/padding.js.map +1 -0
  205. package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
  206. package/lib/rtp/src/rtp/red/encoder.js +14 -1
  207. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  208. package/lib/rtp/src/rtp/red/packet.js +24 -8
  209. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  210. package/lib/rtp/src/rtp/rtp.d.ts +24 -1
  211. package/lib/rtp/src/rtp/rtp.js +70 -29
  212. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  213. package/lib/rtp/src/rtp/rtx.js +3 -0
  214. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  215. package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
  216. package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
  217. package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
  218. package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
  219. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  220. package/lib/rtp/src/srtp/cipher/index.js +8 -4
  221. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  222. package/lib/rtp/src/srtp/context/context.js +6 -3
  223. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  224. package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
  225. package/lib/rtp/src/srtp/context/srtcp.js +33 -0
  226. package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
  227. package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
  228. package/lib/rtp/src/srtp/context/srtp.js +34 -10
  229. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  230. package/lib/rtp/src/srtp/error.d.ts +8 -0
  231. package/lib/rtp/src/srtp/error.js +13 -1
  232. package/lib/rtp/src/srtp/error.js.map +1 -1
  233. package/lib/rtp/src/srtp/packet.js +4 -1
  234. package/lib/rtp/src/srtp/packet.js.map +1 -1
  235. package/lib/rtp/src/srtp/replay.d.ts +24 -0
  236. package/lib/rtp/src/srtp/replay.js +75 -0
  237. package/lib/rtp/src/srtp/replay.js.map +1 -0
  238. package/lib/rtp/src/srtp/session.js +2 -1
  239. package/lib/rtp/src/srtp/session.js.map +1 -1
  240. package/lib/rtp/src/srtp/srtcp.js +2 -1
  241. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  242. package/lib/rtp/src/srtp/srtp.js +2 -1
  243. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  244. package/lib/rtp/src/util.js +2 -1
  245. package/lib/rtp/src/util.js.map +1 -1
  246. package/lib/sctp/src/chunk.d.ts +5 -0
  247. package/lib/sctp/src/chunk.js +31 -8
  248. package/lib/sctp/src/chunk.js.map +1 -1
  249. package/lib/sctp/src/const.d.ts +25 -17
  250. package/lib/sctp/src/const.js +23 -19
  251. package/lib/sctp/src/const.js.map +1 -1
  252. package/lib/sctp/src/param.d.ts +6 -2
  253. package/lib/sctp/src/param.js +22 -8
  254. package/lib/sctp/src/param.js.map +1 -1
  255. package/lib/sctp/src/sctp.d.ts +80 -0
  256. package/lib/sctp/src/sctp.js +655 -108
  257. package/lib/sctp/src/sctp.js.map +1 -1
  258. package/lib/sctp/src/transport.js +4 -2
  259. package/lib/sctp/src/transport.js.map +1 -1
  260. package/lib/webrtc/src/api/peerConfig.d.ts +48 -5
  261. package/lib/webrtc/src/api/peerConfig.js +41 -0
  262. package/lib/webrtc/src/api/peerConfig.js.map +1 -1
  263. package/lib/webrtc/src/dataChannel.d.ts +10 -0
  264. package/lib/webrtc/src/dataChannel.js +24 -4
  265. package/lib/webrtc/src/dataChannel.js.map +1 -1
  266. package/lib/webrtc/src/media/index.d.ts +10 -0
  267. package/lib/webrtc/src/media/index.js +70 -0
  268. package/lib/webrtc/src/media/index.js.map +1 -1
  269. package/lib/webrtc/src/media/receiver/nack.js +2 -1
  270. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  271. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
  272. package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
  273. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  274. package/lib/webrtc/src/media/router.d.ts +14 -1
  275. package/lib/webrtc/src/media/router.js +46 -2
  276. package/lib/webrtc/src/media/router.js.map +1 -1
  277. package/lib/webrtc/src/media/rtpReceiver.d.ts +30 -2
  278. package/lib/webrtc/src/media/rtpReceiver.js +175 -26
  279. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  280. package/lib/webrtc/src/media/rtpSender.d.ts +184 -70
  281. package/lib/webrtc/src/media/rtpSender.js +626 -449
  282. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  283. package/lib/webrtc/src/media/rtpTransceiver.d.ts +1 -3
  284. package/lib/webrtc/src/media/rtpTransceiver.js +10 -7
  285. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  286. package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
  287. package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
  288. package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
  289. package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
  290. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
  291. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
  292. package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
  293. package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
  294. package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
  295. package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
  296. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
  297. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
  298. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
  299. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
  300. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
  301. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
  302. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
  303. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
  304. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
  305. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
  306. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
  307. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
  308. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
  309. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
  310. package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
  311. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
  312. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
  313. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
  314. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
  315. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
  316. package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
  317. package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
  318. package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
  319. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
  320. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
  321. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
  322. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
  323. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
  324. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
  325. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
  326. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
  327. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
  328. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
  329. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
  330. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
  331. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
  332. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
  333. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
  334. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
  335. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
  336. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
  337. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
  338. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
  339. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
  340. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
  341. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
  342. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
  343. package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
  344. package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
  345. package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
  346. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
  347. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
  348. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
  349. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
  350. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
  351. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
  352. package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
  353. package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
  354. package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
  355. package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
  356. package/lib/webrtc/src/media/sender/padding.js +134 -0
  357. package/lib/webrtc/src/media/sender/padding.js.map +1 -0
  358. package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
  359. package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
  360. package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
  361. package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
  362. package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
  363. package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
  364. package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
  365. package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
  366. package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
  367. package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -33
  368. package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
  369. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  370. package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
  371. package/lib/webrtc/src/media/sender/senderStats.js +322 -0
  372. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
  373. package/lib/webrtc/src/media/track.d.ts +20 -2
  374. package/lib/webrtc/src/media/track.js +23 -5
  375. package/lib/webrtc/src/media/track.js.map +1 -1
  376. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
  377. package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
  378. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
  379. package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
  380. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
  381. package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
  382. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
  383. package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
  384. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
  385. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +1 -1
  386. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +22 -6
  387. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
  388. package/lib/webrtc/src/negotiation/transportActivation.js +19 -8
  389. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
  390. package/lib/webrtc/src/negotiationTransaction.d.ts +8 -1
  391. package/lib/webrtc/src/negotiationTransaction.js +18 -5
  392. package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
  393. package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
  394. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  395. package/lib/webrtc/src/nonstandard/navigator.js +4 -3
  396. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  397. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
  398. package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
  399. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  400. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
  401. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
  402. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  403. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
  404. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
  405. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
  406. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
  407. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  408. package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
  409. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  410. package/lib/webrtc/src/peerConnection.d.ts +44 -1
  411. package/lib/webrtc/src/peerConnection.js +74 -8
  412. package/lib/webrtc/src/peerConnection.js.map +1 -1
  413. package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
  414. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  415. package/lib/webrtc/src/sctpManager.d.ts +46 -14
  416. package/lib/webrtc/src/sctpManager.js +88 -25
  417. package/lib/webrtc/src/sctpManager.js.map +1 -1
  418. package/lib/webrtc/src/sdp.js +12 -6
  419. package/lib/webrtc/src/sdp.js.map +1 -1
  420. package/lib/webrtc/src/secureTransportManager.d.ts +52 -4
  421. package/lib/webrtc/src/secureTransportManager.js +106 -23
  422. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  423. package/lib/webrtc/src/transceiverManager.js +8 -3
  424. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  425. package/lib/webrtc/src/transport/dtls.d.ts +53 -1
  426. package/lib/webrtc/src/transport/dtls.js +131 -31
  427. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  428. package/lib/webrtc/src/transport/ice.d.ts +10 -86
  429. package/lib/webrtc/src/transport/ice.js +70 -31
  430. package/lib/webrtc/src/transport/ice.js.map +1 -1
  431. package/lib/webrtc/src/transport/sctp.d.ts +2 -0
  432. package/lib/webrtc/src/transport/sctp.js +66 -20
  433. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  434. package/lib/webrtc/src/utils.d.ts +36 -3
  435. package/lib/webrtc/src/utils.js +56 -16
  436. package/lib/webrtc/src/utils.js.map +1 -1
  437. package/package.json +8 -6
@@ -30,40 +30,58 @@ const common_1 = require("../imports/common");
30
30
  const rtp_1 = require("../imports/rtp");
31
31
  const utils_1 = require("../utils");
32
32
  const codecCompatibility_1 = require("./codecCompatibility");
33
+ const bandwidthEstimator_1 = require("./sender/bandwidthEstimator");
34
+ const estimatorBinding_1 = require("./sender/estimatorBinding");
35
+ const outgoingQueue_1 = require("./sender/outgoingQueue");
36
+ const padding_1 = require("./sender/padding");
37
+ const pendingRtp_1 = require("./sender/pendingRtp");
38
+ const rtpWire_1 = require("./sender/rtpWire");
33
39
  const senderBWE_1 = require("./sender/senderBWE");
40
+ const senderStats_1 = require("./sender/senderStats");
41
+ const sendPacer_1 = require("./sender/sendPacer");
34
42
  const stats_1 = require("./stats");
35
43
  const track_1 = require("./track");
36
44
  const log = (0, rtp_1.debug)("werift:packages/webrtc/src/media/rtpSender.ts");
45
+ /** NACK history: the last sent media packets by sequence number modulo this. */
37
46
  const RTP_HISTORY_SIZE = 128;
38
- const DEFAULT_PENDING_RTP_MAX_LENGTH = 256;
39
- const RTT_ALPHA = 0.85;
40
- function resolvePendingRtpOptions(pendingRtp) {
41
- if (pendingRtp === true) {
42
- return { enabled: true, maxLength: DEFAULT_PENDING_RTP_MAX_LENGTH };
43
- }
44
- if (pendingRtp == undefined || pendingRtp === false) {
45
- return { enabled: false, maxLength: DEFAULT_PENDING_RTP_MAX_LENGTH };
46
- }
47
- const maxLength = typeof pendingRtp.maxLength === "number" &&
48
- Number.isFinite(pendingRtp.maxLength) &&
49
- pendingRtp.maxLength >= 1
50
- ? Math.floor(pendingRtp.maxLength)
51
- : DEFAULT_PENDING_RTP_MAX_LENGTH;
52
- return { enabled: pendingRtp.enabled ?? true, maxLength };
53
- }
54
- function freezeRtpContinuityOffsets(lastOutputSeq, lastOutputTimestamp, firstInputSeq, firstInputTimestamp, timestampStep) {
55
- return {
56
- seqOffset: (0, common_1.uint16Add)((0, common_1.uint16Add)(lastOutputSeq, 1), -firstInputSeq),
57
- timestampOffset: (0, common_1.uint32Add)((0, common_1.uint32Add)(lastOutputTimestamp, timestampStep), -firstInputTimestamp),
58
- };
59
- }
47
+ // RTCRtpSender sends one media stream: negotiation parameters, track binding,
48
+ // the RTP send path, RTCP feedback and stats. Parts with their own state live
49
+ // in ./sender/ (internal, not exported):
50
+ //
51
+ // - estimatorBinding.ts: the bandwidth estimator, its generation and process timer
52
+ // - outgoingQueue.ts / sendPacer.ts: the GCC send FIFO and pacing
53
+ // - padding.ts: probe / loss padding drain on the RTX stream
54
+ // - pendingRtp.ts: RTP held until DTLS connects
55
+ // - senderStats.ts: counters, reception reports, Sender Reports, stats
56
+ // - rtpWire.ts: send FIFO size estimate and the DTLS write
57
+ // Generic RTP pieces (RtpContinuity, header extension rebuild / hop-by-hop
58
+ // stamping, RTX padding packets, RED size estimate) live in werift-rtp.
60
59
  class RTCRtpSender {
60
+ /**
61
+ * Active send-side bandwidth estimator (TWCC-driven).
62
+ *
63
+ * Default is {@link LightweightBandwidthEstimator} (lightweight cumulative algorithm).
64
+ * Replace only with {@link setBandwidthEstimator} (e.g. `new GccBandwidthEstimator()`).
65
+ *
66
+ * Prefer {@link onAvailableBitrate} on this sender for bitrate notifications that
67
+ * survive estimator swaps. Algorithm-specific events remain on concrete instances.
68
+ *
69
+ * **TypeScript compatibility:** {@link CongestionEventsCompatibility} fields
70
+ * (`onCongestion` / `onCongestionScore`) are present on every estimator so
71
+ * existing `sender.senderBWE.onCongestion.subscribe(...)` still type-checks.
72
+ * They fire only on {@link LightweightBandwidthEstimator}; GCC / disabled are no-ops.
73
+ * Prefer `sender.senderBWE as LightweightBandwidthEstimator` (or
74
+ * {@link isLightweightBandwidthEstimator}) for lightweight-only APIs.
75
+ */
76
+ get senderBWE() {
77
+ return this.bwe.estimator;
78
+ }
61
79
  constructor(trackOrKind, options = {}) {
62
80
  Object.defineProperty(this, "trackOrKind", {
63
81
  enumerable: true,
64
82
  configurable: true,
65
83
  writable: true,
66
- value: trackOrKind
84
+ value: void 0
67
85
  });
68
86
  Object.defineProperty(this, "type", {
69
87
  enumerable: true,
@@ -119,191 +137,195 @@ class RTCRtpSender {
119
137
  writable: true,
120
138
  value: new common_1.Event()
121
139
  });
122
- /** Fires for a FIR addressed to this sender with a new sequence number (RFC 5104 4.3.1). */
123
- Object.defineProperty(this, "onFullIntraRequest", {
140
+ /**
141
+ * Active send-side bandwidth estimator (TWCC-driven) with its generation
142
+ * and process timer. Replaced only via {@link setBandwidthEstimator}.
143
+ */
144
+ Object.defineProperty(this, "bwe", {
124
145
  enumerable: true,
125
146
  configurable: true,
126
147
  writable: true,
127
- value: new common_1.Event()
148
+ value: void 0
128
149
  });
129
150
  /**
130
- * Fires for every key frame request addressed to this sender: each PLI, and each FIR
131
- * that is not a retransmission. Fires in addition to onPictureLossIndication / onFullIntraRequest.
151
+ * Stable recommended send bitrate event (**bps**, change-only).
152
+ * Bridged from the active {@link BandwidthEstimator}; subscriptions survive
153
+ * {@link setBandwidthEstimator} without re-subscribing.
154
+ *
155
+ * Prefer this over `senderBWE.onAvailableBitrate` for application adaptation.
132
156
  */
133
- Object.defineProperty(this, "onKeyFrameRequest", {
157
+ Object.defineProperty(this, "onAvailableBitrate", {
134
158
  enumerable: true,
135
159
  configurable: true,
136
160
  writable: true,
137
161
  value: new common_1.Event()
138
162
  });
139
- Object.defineProperty(this, "senderBWE", {
140
- enumerable: true,
141
- configurable: true,
142
- writable: true,
143
- value: new senderBWE_1.SenderBandwidthEstimator()
144
- });
145
- Object.defineProperty(this, "cname", {
163
+ /**
164
+ * Probe cluster configs (target bps / min packets). Bridged from the active
165
+ * {@link BandwidthEstimator}; GCC fires this, lightweight / disabled never do.
166
+ */
167
+ Object.defineProperty(this, "onProbeClusterConfig", {
146
168
  enumerable: true,
147
169
  configurable: true,
148
170
  writable: true,
149
- value: void 0
171
+ value: new common_1.Event()
150
172
  });
151
- Object.defineProperty(this, "mid", {
173
+ /**
174
+ * @internal Sim / test only. When false, skip the **media** token-bucket
175
+ * (pin GetPacingRates). Probe `next_probe_time` waits stay enabled so
176
+ * BitrateProber timing is not disabled by accident.
177
+ *
178
+ * Peer/Chrome sims turn this off during the congestion phase so the
179
+ * synthetic generate rate hits the bottleneck, then turn it back on
180
+ * when the app follows {@link onAvailableBitrate}.
181
+ */
182
+ Object.defineProperty(this, "mediaPacingEnabled", {
152
183
  enumerable: true,
153
184
  configurable: true,
154
185
  writable: true,
155
- value: void 0
186
+ value: true
156
187
  });
157
- Object.defineProperty(this, "rtpStreamId", {
188
+ /** Token-bucket pacer for **media** (not probe) rate enforcement. */
189
+ Object.defineProperty(this, "pacer", {
158
190
  enumerable: true,
159
191
  configurable: true,
160
192
  writable: true,
161
- value: void 0
193
+ value: new sendPacer_1.MediaPacer()
162
194
  });
163
- Object.defineProperty(this, "repairedRtpStreamId", {
195
+ /**
196
+ * pin `pending_untracked_size_` — bytes sent without TWCC tracking,
197
+ * attached to the next tracked packet as `priorUnackedBytes`.
198
+ */
199
+ Object.defineProperty(this, "pendingUntrackedBytes", {
164
200
  enumerable: true,
165
201
  configurable: true,
166
202
  writable: true,
167
- value: void 0
203
+ value: 0
168
204
  });
169
- Object.defineProperty(this, "rtxPayloadType", {
205
+ /**
206
+ * GCC send FIFO: reservation → pacing wait → seq / TSN assignment → DTLS write.
207
+ * Probe padding may call {@link sendRtpInternal} on this stack only after
208
+ * the current packet's DTLS write ({@link nestOutgoingPadding}); timer /
209
+ * cluster events always enqueue so they cannot share a DTLS write.
210
+ */
211
+ Object.defineProperty(this, "outgoing", {
170
212
  enumerable: true,
171
213
  configurable: true,
172
214
  writable: true,
173
215
  value: void 0
174
216
  });
175
- Object.defineProperty(this, "rtxSequenceNumber", {
217
+ /**
218
+ * Set only around post-DTLS {@link maybeInjectProbePadding} so padding can
219
+ * drain on the same FIFO task without deadlock. Must stay false during
220
+ * probe/pacing wait, or a cluster event would send in parallel.
221
+ */
222
+ Object.defineProperty(this, "nestOutgoingPadding", {
176
223
  enumerable: true,
177
224
  configurable: true,
178
225
  writable: true,
179
- value: (0, common_1.random16)()
226
+ value: false
180
227
  });
181
- Object.defineProperty(this, "redRedundantPayloadType", {
228
+ Object.defineProperty(this, "padding", {
182
229
  enumerable: true,
183
230
  configurable: true,
184
231
  writable: true,
185
232
  value: void 0
186
233
  });
187
- Object.defineProperty(this, "_redDistance", {
188
- enumerable: true,
189
- configurable: true,
190
- writable: true,
191
- value: 2
192
- });
193
- Object.defineProperty(this, "redEncoder", {
234
+ /** Fires for a FIR addressed to this sender with a new sequence number (RFC 5104 4.3.1). */
235
+ Object.defineProperty(this, "onFullIntraRequest", {
194
236
  enumerable: true,
195
237
  configurable: true,
196
238
  writable: true,
197
- value: new rtp_1.RedEncoder(this._redDistance)
239
+ value: new common_1.Event()
198
240
  });
199
- Object.defineProperty(this, "headerExtensions", {
241
+ /**
242
+ * Fires for every key frame request addressed to this sender: each PLI, and each FIR
243
+ * that is not a retransmission. Fires in addition to onPictureLossIndication / onFullIntraRequest.
244
+ */
245
+ Object.defineProperty(this, "onKeyFrameRequest", {
200
246
  enumerable: true,
201
247
  configurable: true,
202
248
  writable: true,
203
- value: []
249
+ value: new common_1.Event()
204
250
  });
205
- Object.defineProperty(this, "disposeTrack", {
251
+ Object.defineProperty(this, "cname", {
206
252
  enumerable: true,
207
253
  configurable: true,
208
254
  writable: true,
209
255
  value: void 0
210
256
  });
211
- Object.defineProperty(this, "sendEncodings", {
212
- enumerable: true,
213
- configurable: true,
214
- writable: true,
215
- value: [{}]
216
- });
217
- // # stats
218
- Object.defineProperty(this, "lastSRtimestamp", {
257
+ Object.defineProperty(this, "mid", {
219
258
  enumerable: true,
220
259
  configurable: true,
221
260
  writable: true,
222
261
  value: void 0
223
262
  });
224
- Object.defineProperty(this, "lastSentSRTimestamp", {
263
+ Object.defineProperty(this, "rtpStreamId", {
225
264
  enumerable: true,
226
265
  configurable: true,
227
266
  writable: true,
228
267
  value: void 0
229
268
  });
230
- Object.defineProperty(this, "ntpTimestamp", {
231
- enumerable: true,
232
- configurable: true,
233
- writable: true,
234
- value: 0n
235
- });
236
- Object.defineProperty(this, "rtpTimestamp", {
237
- enumerable: true,
238
- configurable: true,
239
- writable: true,
240
- value: 0
241
- });
242
- Object.defineProperty(this, "octetCount", {
269
+ Object.defineProperty(this, "repairedRtpStreamId", {
243
270
  enumerable: true,
244
271
  configurable: true,
245
272
  writable: true,
246
- value: 0
273
+ value: void 0
247
274
  });
248
- Object.defineProperty(this, "packetCount", {
275
+ Object.defineProperty(this, "rtxPayloadType", {
249
276
  enumerable: true,
250
277
  configurable: true,
251
278
  writable: true,
252
- value: 0
279
+ value: void 0
253
280
  });
254
- Object.defineProperty(this, "headerBytesSent", {
281
+ Object.defineProperty(this, "rtxSequenceNumber", {
255
282
  enumerable: true,
256
283
  configurable: true,
257
284
  writable: true,
258
- value: 0
285
+ value: (0, common_1.random16)()
259
286
  });
260
- Object.defineProperty(this, "rtt", {
287
+ Object.defineProperty(this, "redRedundantPayloadType", {
261
288
  enumerable: true,
262
289
  configurable: true,
263
290
  writable: true,
264
291
  value: void 0
265
292
  });
266
- Object.defineProperty(this, "totalRoundTripTime", {
267
- enumerable: true,
268
- configurable: true,
269
- writable: true,
270
- value: 0
271
- });
272
- Object.defineProperty(this, "roundTripTimeMeasurements", {
293
+ Object.defineProperty(this, "_redDistance", {
273
294
  enumerable: true,
274
295
  configurable: true,
275
296
  writable: true,
276
- value: 0
297
+ value: 2
277
298
  });
278
- Object.defineProperty(this, "retransmittedPacketsSent", {
299
+ Object.defineProperty(this, "redEncoder", {
279
300
  enumerable: true,
280
301
  configurable: true,
281
302
  writable: true,
282
- value: 0
303
+ value: new rtp_1.RedEncoder(this._redDistance)
283
304
  });
284
- Object.defineProperty(this, "retransmittedBytesSent", {
305
+ Object.defineProperty(this, "headerExtensions", {
285
306
  enumerable: true,
286
307
  configurable: true,
287
308
  writable: true,
288
- value: 0
309
+ value: []
289
310
  });
290
- Object.defineProperty(this, "nackCount", {
311
+ Object.defineProperty(this, "disposeTrack", {
291
312
  enumerable: true,
292
313
  configurable: true,
293
314
  writable: true,
294
- value: 0
315
+ value: void 0
295
316
  });
296
- Object.defineProperty(this, "pliCount", {
317
+ Object.defineProperty(this, "sendEncodings", {
297
318
  enumerable: true,
298
319
  configurable: true,
299
320
  writable: true,
300
- value: 0
321
+ value: [{}]
301
322
  });
302
- Object.defineProperty(this, "firCount", {
323
+ // # stats
324
+ Object.defineProperty(this, "stats", {
303
325
  enumerable: true,
304
326
  configurable: true,
305
327
  writable: true,
306
- value: 0
328
+ value: new senderStats_1.SenderStatistics()
307
329
  });
308
330
  /**
309
331
  * Last FIR sequence number per (FIR sender SSRC, FCI target SSRC): RFC 5104
@@ -315,18 +337,6 @@ class RTCRtpSender {
315
337
  writable: true,
316
338
  value: new Map()
317
339
  });
318
- Object.defineProperty(this, "remotePacketsLost", {
319
- enumerable: true,
320
- configurable: true,
321
- writable: true,
322
- value: void 0
323
- });
324
- Object.defineProperty(this, "remoteFractionLost", {
325
- enumerable: true,
326
- configurable: true,
327
- writable: true,
328
- value: void 0
329
- });
330
340
  Object.defineProperty(this, "receiverEstimatedMaxBitrate", {
331
341
  enumerable: true,
332
342
  configurable: true,
@@ -334,41 +344,11 @@ class RTCRtpSender {
334
344
  value: 0n
335
345
  });
336
346
  // rtp
337
- Object.defineProperty(this, "sequenceNumber", {
338
- enumerable: true,
339
- configurable: true,
340
- writable: true,
341
- value: void 0
342
- });
343
- Object.defineProperty(this, "timestamp", {
344
- enumerable: true,
345
- configurable: true,
346
- writable: true,
347
- value: void 0
348
- });
349
- Object.defineProperty(this, "timestampOffset", {
350
- enumerable: true,
351
- configurable: true,
352
- writable: true,
353
- value: 0
354
- });
355
- Object.defineProperty(this, "seqOffset", {
356
- enumerable: true,
357
- configurable: true,
358
- writable: true,
359
- value: 0
360
- });
361
- Object.defineProperty(this, "rtpContinuityPending", {
362
- enumerable: true,
363
- configurable: true,
364
- writable: true,
365
- value: false
366
- });
367
- Object.defineProperty(this, "pendingTimestampStep", {
347
+ Object.defineProperty(this, "continuity", {
368
348
  enumerable: true,
369
349
  configurable: true,
370
350
  writable: true,
371
- value: 1
351
+ value: new rtp_1.RtpContinuity()
372
352
  });
373
353
  Object.defineProperty(this, "rtpCache", {
374
354
  enumerable: true,
@@ -380,21 +360,28 @@ class RTCRtpSender {
380
360
  enumerable: true,
381
361
  configurable: true,
382
362
  writable: true,
383
- value: []
363
+ value: void 0
384
364
  });
385
- Object.defineProperty(this, "drainingPendingRtp", {
365
+ /**
366
+ * Bumped on replaceTrack / detachTrack / onSourceChanged. Media accepted
367
+ * under an older epoch is dropped before it can allocate seq/timestamp, so
368
+ * it neither consumes the new source's continuity offset nor leaks out
369
+ * after `replaceTrack(null)`.
370
+ */
371
+ Object.defineProperty(this, "sourceEpoch", {
386
372
  enumerable: true,
387
373
  configurable: true,
388
374
  writable: true,
389
- value: false
375
+ value: 0
390
376
  });
391
- Object.defineProperty(this, "pendingRtpEnabled", {
377
+ /** Aborted on every source epoch bump to wake probe / pacing waits. */
378
+ Object.defineProperty(this, "sourceEpochCancel", {
392
379
  enumerable: true,
393
380
  configurable: true,
394
381
  writable: true,
395
- value: void 0
382
+ value: new AbortController()
396
383
  });
397
- Object.defineProperty(this, "pendingRtpMaxLength", {
384
+ Object.defineProperty(this, "pendingRtpEnabled", {
398
385
  enumerable: true,
399
386
  configurable: true,
400
387
  writable: true,
@@ -481,16 +468,32 @@ class RTCRtpSender {
481
468
  writable: true,
482
469
  value: false
483
470
  });
484
- const pendingRtp = resolvePendingRtpOptions(options.pendingRtp);
471
+ this.trackOrKind = trackOrKind;
472
+ const pendingRtp = (0, pendingRtp_1.resolvePendingRtpOptions)(options.pendingRtp);
485
473
  this.pendingRtpEnabled = pendingRtp.enabled;
486
- this.pendingRtpMaxLength = pendingRtp.maxLength;
474
+ this.pendingRtp = new pendingRtp_1.PendingRtpQueue(pendingRtp.maxLength);
487
475
  this.kind =
488
476
  typeof this.trackOrKind === "string"
489
477
  ? this.trackOrKind
490
478
  : this.trackOrKind.kind;
479
+ this.bwe = new estimatorBinding_1.EstimatorBinding(options?.bandwidthEstimator ?? new senderBWE_1.LightweightBandwidthEstimator(), {
480
+ onAvailableBitrate: (bps) => this.onAvailableBitrate.execute(bps),
481
+ onProbeClusterConfig: (cfg) => {
482
+ this.onProbeClusterConfig.execute(cfg);
483
+ // pin BitrateProber: no prepaid token-bucket credit. Probe packets
484
+ // wait on next_probe_time = started_at + sent_bytes / send_bitrate.
485
+ void this.maybeInjectProbePadding();
486
+ },
487
+ // pin GetPacingRates padding_rate while kIncreaseUsingPadding.
488
+ onProcessTick: () => void this.maybeInjectLossPadding(),
489
+ isStopped: () => this.stopped,
490
+ });
491
+ this.outgoing = new outgoingQueue_1.OutgoingQueue(this.kind, () => (0, bandwidthEstimator_1.needsPacedSendPath)(this.bwe.estimator));
492
+ this.padding = this.createPaddingInjector();
491
493
  if (typeof trackOrKind !== "string") {
492
494
  this.registerTrack(trackOrKind);
493
495
  }
496
+ this.bwe.syncProcessTimer();
494
497
  }
495
498
  get transport() {
496
499
  return this.dtlsTransport ?? null;
@@ -502,7 +505,8 @@ class RTCRtpSender {
502
505
  this.streamIds = value ? [value] : [];
503
506
  }
504
507
  setDtlsTransport(dtlsTransport) {
505
- if (this.dtlsTransport) {
508
+ const previous = this.dtlsTransport;
509
+ if (previous) {
506
510
  this.dtlsDisposer.forEach((dispose) => dispose());
507
511
  }
508
512
  this.dtlsTransport = dtlsTransport;
@@ -512,14 +516,80 @@ class RTCRtpSender {
512
516
  this.dtlsDisposer = [];
513
517
  return;
514
518
  }
519
+ if (previous && previous !== dtlsTransport) {
520
+ this.resetBweForNewTransport();
521
+ }
515
522
  this.dtlsDisposer = [
516
523
  this.dtlsTransport.onStateChange.subscribe((state) => {
524
+ this.syncNetworkAvailability();
517
525
  if (state === "connected") {
518
526
  this.onReady.execute();
519
527
  void this.drainPendingRtp();
520
528
  }
521
529
  }).unSubscribe,
522
530
  ];
531
+ this.syncNetworkAvailability();
532
+ }
533
+ /**
534
+ * Replace the send-side bandwidth estimator used for TWCC-driven BWE.
535
+ *
536
+ * Default is the lightweight {@link LightweightBandwidthEstimator}. Pass e.g.
537
+ * `new GccBandwidthEstimator()` to use Google Congestion Control.
538
+ *
539
+ * Behavior on swap:
540
+ * 1. Bumps the estimator generation so in-flight sends discard
541
+ * `rtpPacketSent` delivery and in-flight {@link maybeInjectProbePadding}
542
+ * loops exit (cancelled — no packets to disposed / previous estimator).
543
+ * 2. Stops delivering `rtpPacketSent` / `receiveTWCC` to the previous instance.
544
+ * 3. Unbinds the stable {@link onAvailableBitrate} bridge, then `dispose()`/`reset()` the old instance.
545
+ * 4. **Always** `reset()` the injected `impl` so a previously used instance
546
+ * starts clean (no implicit state merge), then rebinds the bridge.
547
+ * 5. Clears {@link pendingUntrackedBytes} and pacing credit so the next
548
+ * estimator's first `SentInfo.priorUnackedBytes` is 0.
549
+ *
550
+ * Subscriptions to {@link onAvailableBitrate} on this sender are preserved.
551
+ * Re-subscribe algorithm-specific events on the new concrete instance.
552
+ */
553
+ setBandwidthEstimator(impl) {
554
+ // Invalidate in-flight media/padding so they do not touch the next estimator
555
+ // (or revive a disposed probe controller after dispose/reset).
556
+ this.bwe.replace(impl);
557
+ this.resetBweSendTransientState();
558
+ this.syncNetworkAvailability();
559
+ this.bwe.syncProcessTimer();
560
+ // New generation may have missed onProbeClusterConfig while the previous
561
+ // drain still held the same-generation re-entry lock.
562
+ void this.maybeInjectProbePadding();
563
+ }
564
+ /**
565
+ * A new DTLS transport has its own transport-wide sequence space and path:
566
+ * drop the estimator's path state ({@link EstimatorBinding.resetForNewRoute},
567
+ * which also bumps the generation so in-flight sends on the old transport
568
+ * do not report their old TSN) and the pacing / unacked leftovers.
569
+ */
570
+ resetBweForNewTransport() {
571
+ this.bwe.resetForNewRoute();
572
+ this.resetBweSendTransientState();
573
+ this.bwe.syncProcessTimer();
574
+ }
575
+ /** Drop pacing leftover and unacked bytes that belonged to the previous BWE generation. */
576
+ resetBweSendTransientState() {
577
+ this.pacer.reset();
578
+ this.pendingUntrackedBytes = 0;
579
+ }
580
+ /** Initial probes wait until DTLS can send; also on a swap onto a connected sender. */
581
+ syncNetworkAvailability() {
582
+ this.bwe.syncNetworkAvailability(this.dtlsTransport?.state === "connected");
583
+ }
584
+ /**
585
+ * Effective send pacing rate (bps): estimator estimate, raised to the active
586
+ * probe target while probing. 0 when unknown. Lightweight returns 0 from
587
+ * {@link BandwidthEstimator.getPacingBitrateBps} so media is unpaced.
588
+ */
589
+ get pacingBitrateBps() {
590
+ const estimator = this.bwe.estimator;
591
+ const paced = estimator.getPacingBitrateBps();
592
+ return paced > 0 ? paced : estimator.availableBitrate;
523
593
  }
524
594
  get redDistance() {
525
595
  return this._redDistance;
@@ -577,6 +647,7 @@ class RTCRtpSender {
577
647
  this.cname = params.rtcp?.cname;
578
648
  this.mid = params.muxId;
579
649
  this.headerExtensions = params.headerExtensions;
650
+ // Keep a RID set via sendEncodings/setParameters when SDP carries none.
580
651
  this.rtpStreamId = params.rtpStreamId ?? this.rtpStreamId;
581
652
  this.repairedRtpStreamId = params.repairedRtpStreamId;
582
653
  this.negotiatedCodecs = [...params.codecs];
@@ -608,8 +679,12 @@ class RTCRtpSender {
608
679
  if (this.sendSuppressed === suppressed)
609
680
  return;
610
681
  this.sendSuppressed = suppressed;
611
- if (suppressed)
612
- this.discardPendingRtp();
682
+ if (suppressed) {
683
+ this.pendingRtp.discard();
684
+ // Drop media already accepted into the send FIFO and release a packet
685
+ // parked in a probe / pacing wait (same path as a source switch).
686
+ this.invalidateQueuedSource();
687
+ }
613
688
  else
614
689
  void this.drainPendingRtp();
615
690
  }
@@ -619,66 +694,12 @@ class RTCRtpSender {
619
694
  this.dtlsTransport?.state === "connected" &&
620
695
  !!this.codec);
621
696
  }
622
- settlePendingRtp(item, error) {
623
- if (error == undefined) {
624
- item.resolve();
625
- return;
626
- }
627
- item.reject(error);
628
- }
629
- discardPendingRtp() {
630
- const dropped = this.pendingRtp.splice(0);
631
- for (const item of dropped) {
632
- this.settlePendingRtp(item);
633
- }
634
- }
635
- enqueuePendingRtp(rtp, resolve, reject) {
636
- const packet = Buffer.isBuffer(rtp)
637
- ? rtp_1.RtpPacket.deSerialize(rtp)
638
- : rtp.clone();
639
- this.pendingRtp.push({ packet, resolve, reject });
640
- while (this.pendingRtp.length > this.pendingRtpMaxLength) {
641
- const dropped = this.pendingRtp.shift();
642
- if (dropped) {
643
- this.settlePendingRtp(dropped);
644
- }
645
- }
646
- }
647
697
  /**
648
- * Send queued RTP once DTLS is connected and a codec is set. Used only when
649
- * pending RTP is enabled: `writeRtp` / `sendRtp` may run before ICE/DTLS
650
- * completes; dropping those packets would lose the start of a media source.
651
- * `drainingPendingRtp` blocks re-entry while `dispatchRtp` is awaited;
652
- * packets enqueued during that wait are drained by the recursive call after
653
- * the flag is cleared.
698
+ * Send queued RTP once DTLS is connected and a codec is set.
699
+ * Drain uses {@link sendRtpInternal} so GCC pacing / TWCC stay on the send path.
654
700
  */
655
- async drainPendingRtp() {
656
- if (this.drainingPendingRtp) {
657
- return;
658
- }
659
- this.drainingPendingRtp = true;
660
- try {
661
- while (this.pendingRtp.length > 0 && this.canSendRtp()) {
662
- const item = this.pendingRtp.shift();
663
- if (!this.canSendRtp()) {
664
- this.settlePendingRtp(item);
665
- continue;
666
- }
667
- try {
668
- await this.dispatchRtp(item.packet);
669
- this.settlePendingRtp(item);
670
- }
671
- catch (error) {
672
- this.settlePendingRtp(item, error);
673
- }
674
- }
675
- }
676
- finally {
677
- this.drainingPendingRtp = false;
678
- }
679
- if (this.pendingRtp.length > 0 && this.canSendRtp()) {
680
- await this.drainPendingRtp();
681
- }
701
+ drainPendingRtp() {
702
+ return this.pendingRtp.drain(() => this.canSendRtp(), (packet, sourceEpoch) => this.dispatchMedia(packet, sourceEpoch));
682
703
  }
683
704
  registerTrack(track) {
684
705
  if (track.stopped)
@@ -734,9 +755,12 @@ class RTCRtpSender {
734
755
  if (incompatible) {
735
756
  throw (0, errors_1.createWebRtcDomException)("InvalidModificationError", `Track codec ${sourceCodecs.map((codec) => codec.mimeType).join(", ")} is incompatible with negotiated codec ${incompatible.mimeType}`);
736
757
  }
737
- if (this.sequenceNumber != undefined) {
758
+ if (this.continuity.sequenceNumber != undefined) {
738
759
  this.scheduleRtpContinuity();
739
760
  }
761
+ else {
762
+ this.invalidateQueuedSource();
763
+ }
740
764
  this.registerTrack(track);
741
765
  log("replaceTrack", "ssrc", track.ssrc, "rid", track.rid);
742
766
  }
@@ -745,8 +769,9 @@ class RTCRtpSender {
745
769
  * The same sender can resume sending after `replaceTrack(track)`.
746
770
  */
747
771
  detachTrack() {
748
- this.rtpContinuityPending = false;
749
- this.discardPendingRtp();
772
+ this.continuity.cancel();
773
+ this.pendingRtp.discard();
774
+ this.invalidateQueuedSource();
750
775
  if (this.disposeTrack) {
751
776
  this.disposeTrack();
752
777
  this.disposeTrack = undefined;
@@ -760,10 +785,14 @@ class RTCRtpSender {
760
785
  for (const dispose of this.dtlsDisposer)
761
786
  dispose();
762
787
  this.dtlsDisposer = [];
763
- this.rtpContinuityPending = false;
764
- this.discardPendingRtp();
788
+ this.continuity.cancel();
789
+ this.pendingRtp.discard();
790
+ // Invalidate in-flight sendRtp / maybeInjectProbePadding before dispose
791
+ // so they cannot emit padding or revive a disposed estimator.
792
+ this.bwe.bumpGeneration();
765
793
  this.rtcpRunning = false;
766
794
  this.rtcpCancel.abort();
795
+ this.bwe.close();
767
796
  if (this.disposeTrack) {
768
797
  this.disposeTrack();
769
798
  this.disposeTrack = undefined;
@@ -771,6 +800,8 @@ class RTCRtpSender {
771
800
  if (!keepTrack) {
772
801
  this.track = null;
773
802
  }
803
+ this.dtlsDisposer.forEach((dispose) => dispose());
804
+ this.dtlsDisposer = [];
774
805
  }
775
806
  async runRtcp() {
776
807
  if (this.rtcpRunning || this.stopped)
@@ -781,19 +812,7 @@ class RTCRtpSender {
781
812
  await (0, promises_1.setTimeout)(500 + Math.random() * 1000, undefined, {
782
813
  signal: this.rtcpCancel.signal,
783
814
  });
784
- const packets = [
785
- new rtp_1.RtcpSrPacket({
786
- ssrc: this.ssrc,
787
- senderInfo: new rtp_1.RtcpSenderInfo({
788
- ntpTimestamp: this.ntpTimestamp,
789
- rtpTimestamp: this.rtpTimestamp,
790
- packetCount: this.packetCount,
791
- octetCount: this.octetCount,
792
- }),
793
- }),
794
- ];
795
- this.lastSRtimestamp = (0, utils_1.compactNtp)(this.ntpTimestamp);
796
- this.lastSentSRTimestamp = (0, utils_1.timestampSeconds)();
815
+ const packets = [this.buildSenderReport()];
797
816
  if (this.cname) {
798
817
  packets.push(new rtp_1.RtcpSourceDescriptionPacket({
799
818
  chunks: [
@@ -817,21 +836,86 @@ class RTCRtpSender {
817
836
  }
818
837
  catch (error) { }
819
838
  }
839
+ /** Sender Report for the instant `nowMonotonicMs` ({@link SenderStatistics.buildSenderReport}). */
840
+ buildSenderReport(nowMonotonicMs = performance.now()) {
841
+ return this.stats.buildSenderReport(this.ssrc, nowMonotonicMs);
842
+ }
820
843
  /**
821
- * Send an RTP packet. Pending RTP is disabled by default: the packet is
822
- * written immediately if DTLS is connected and a codec is set, otherwise
823
- * dropped.
824
- *
825
- * When pending RTP is enabled, the packet is queued until it can be sent.
826
- * The returned promise then settles for this packet only:
827
- * - resolve: DTLS send completed, or the packet was dropped by `stop()`,
828
- * `replaceTrack(null)`, or pending-queue overflow
829
- * - reject: DTLS send threw while writing this packet
830
- *
831
- * Later `sendRtp()` calls stay pending until their own packet is sent or
832
- * dropped, even if a drain is already in progress.
844
+ * Schedule RTP continuity rewrite for the next packet that is actually sent.
845
+ * The header argument is kept for API compatibility and is not used to compute
846
+ * offsets. `discontinuity` does not change sequence or timestamp mapping.
847
+ * `timestampStep` (default 1) is the only way to choose the timestamp increment
848
+ * at the source-switch boundary.
849
+ */
850
+ replaceRTP(header, discontinuity = false, timestampStep = 1) {
851
+ this.scheduleRtpContinuity(timestampStep);
852
+ log("replaceRTP", this.continuity.sequenceNumber, header.sequenceNumber, discontinuity, timestampStep);
853
+ }
854
+ /**
855
+ * Start a new source epoch and drop queued media of the previous source.
856
+ * A packet already past sequence allocation (in its DTLS write) completes;
857
+ * one still waiting on pacing/probe is dropped by {@link sendRtpInternal}.
858
+ */
859
+ invalidateQueuedSource() {
860
+ this.sourceEpoch++;
861
+ // Release the running FIFO task if it is a stale packet parked in a
862
+ // probe / pacing wait, so new-source media is not held behind it.
863
+ this.sourceEpochCancel.abort();
864
+ this.sourceEpochCancel = new AbortController();
865
+ this.outgoing.dropStaleSource(this.sourceEpoch);
866
+ this.pendingRtp.dropStaleSource(this.sourceEpoch);
867
+ }
868
+ isStaleSource(sourceEpoch) {
869
+ return sourceEpoch !== undefined && sourceEpoch !== this.sourceEpoch;
870
+ }
871
+ /**
872
+ * Abort signal for a send wait: sender stop, estimator swap, plus source
873
+ * switch for media.
874
+ */
875
+ sendWaitSignal(sourceEpoch) {
876
+ const signals = [this.rtcpCancel.signal, this.bwe.generationSignal];
877
+ if (sourceEpoch !== undefined) {
878
+ signals.push(this.sourceEpochCancel.signal);
879
+ }
880
+ return AbortSignal.any(signals);
881
+ }
882
+ /** A waiting send may still go out: not stopped, same estimator, same source. */
883
+ isSendAlive(generation, sourceEpoch) {
884
+ return (!this.stopped &&
885
+ generation === this.bwe.generation &&
886
+ !this.isStaleSource(sourceEpoch));
887
+ }
888
+ scheduleRtpContinuity(timestampStep = 1) {
889
+ this.invalidateQueuedSource();
890
+ this.continuity.schedule(timestampStep);
891
+ this.rtpCache = [];
892
+ }
893
+ dispatchMedia(packet, sourceEpoch) {
894
+ return this.dispatchOutgoing(() => this.sendRtpInternal(packet, {
895
+ injectProbePadding: true,
896
+ sourceEpoch,
897
+ }), { kind: "media", bytes: (0, rtpWire_1.estimateOutgoingBytes)(packet), sourceEpoch });
898
+ }
899
+ /**
900
+ * Lightweight / disabled estimators neither pace nor probe, so RTP is written
901
+ * straight through as before the BWE abstraction: no FIFO, no queue limit,
902
+ * and no wait before the DTLS write. Pacing estimators (GCC) go through
903
+ * {@link outgoing}. A FIFO still draining after an estimator swap
904
+ * keeps its order by queuing behind it.
905
+ */
906
+ dispatchOutgoing(task, meta) {
907
+ if (!this.outgoing.running && !(0, bandwidthEstimator_1.needsPacedSendPath)(this.bwe.estimator)) {
908
+ return task();
909
+ }
910
+ return this.outgoing.enqueue(task, meta);
911
+ }
912
+ /**
913
+ * Send immediately by default or queue until DTLS is ready when pending RTP
914
+ * is enabled. Each call settles only after its own packet is sent or dropped.
833
915
  */
834
916
  async sendRtp(rtp) {
917
+ // Drop (do not queue) while the negotiated direction does not send, so
918
+ // nothing is flushed in a burst when sending resumes.
835
919
  if (this.stopped || this.sendSuppressed) {
836
920
  return;
837
921
  }
@@ -839,127 +923,299 @@ class RTCRtpSender {
839
923
  if (!this.canSendRtp()) {
840
924
  return;
841
925
  }
842
- await this.dispatchRtp(rtp);
926
+ // Own the packet before any pacing wait: a track shared by several
927
+ // senders hands every subscriber the same RtpPacket, and header
928
+ // rewrites (SSRC/seq/extensions) must not leak across senders.
929
+ const packet = Buffer.isBuffer(rtp)
930
+ ? rtp_1.RtpPacket.deSerialize(rtp)
931
+ : rtp.clone();
932
+ await this.dispatchMedia(packet, this.sourceEpoch);
843
933
  return;
844
934
  }
845
935
  await new Promise((resolve, reject) => {
846
- this.enqueuePendingRtp(rtp, resolve, reject);
936
+ this.pendingRtp.enqueue(rtp, this.sourceEpoch, resolve, reject);
847
937
  void this.drainPendingRtp();
848
938
  });
849
939
  }
940
+ /** True when transport-wide CC header extension is negotiated. */
941
+ isTransportCcNegotiated() {
942
+ return this.headerExtensions.some((e) => e.uri === rtp_1.RTP_EXTENSION_URI.transportWideCC);
943
+ }
850
944
  /**
851
- * Schedule RTP continuity rewrite for the next packet that is actually sent.
852
- * The header argument is kept for API compatibility and is not used to compute
853
- * offsets. `discontinuity` does not change sequence or timestamp mapping.
854
- * `timestampStep` (default 1) is the only way to choose the timestamp increment
855
- * at the source-switch boundary.
945
+ * Padding needs an estimator that asks for it, TWCC so feedback can see it,
946
+ * and a negotiated RTX stream to carry it. Without RTX no padding is sent
947
+ * (see `GCC_KNOWN_DIFFERENCES`): media sequence numbers stay untouched.
856
948
  */
857
- replaceRTP(header, discontinuity = false, timestampStep = 1) {
858
- this.scheduleRtpContinuity(timestampStep);
859
- log("replaceRTP", this.sequenceNumber, header.sequenceNumber, discontinuity, timestampStep);
949
+ canSendPadding() {
950
+ return (!this.sendSuppressed &&
951
+ (0, bandwidthEstimator_1.isProbePacingController)(this.bwe.estimator) &&
952
+ this.rtxPayloadType !== undefined &&
953
+ this.isTransportCcNegotiated());
860
954
  }
861
- scheduleRtpContinuity(timestampStep = 1) {
862
- this.rtpContinuityPending = true;
863
- this.pendingTimestampStep = timestampStep;
864
- this.rtpCache = [];
955
+ /**
956
+ * Inject RTP padding packets while a GCC probe cluster is active and media
957
+ * alone has not yet filled min packets / min bitrate×duration.
958
+ *
959
+ * Responsibility split:
960
+ * - Estimator (`ProbeController` / `pendingProbePaddingPackets`) decides need
961
+ * - Sender generates padding-only RTP on the RTX SSRC with a TWCC seq +
962
+ * `isProbation` and paces them
963
+ */
964
+ async maybeInjectProbePadding() {
965
+ if (!this.canSendPadding()) {
966
+ return 0;
967
+ }
968
+ if (this.nestOutgoingPadding) {
969
+ return this.padding.drainProbe();
970
+ }
971
+ return ((await this.outgoing.enqueue(() => this.padding.drainProbe(), {
972
+ kind: "padding",
973
+ bytes: this.bwe.estimator.probePaddingPacketBytes,
974
+ })) ?? 0);
865
975
  }
866
- async dispatchRtp(rtp) {
867
- if (!this.canSendRtp()) {
868
- return;
976
+ /**
977
+ * pin padding_rate while LossBased is `kIncreaseUsingPadding`.
978
+ * Regular RTP padding (not probe/probation). Probe padding takes priority.
979
+ */
980
+ async maybeInjectLossPadding() {
981
+ if (!this.canSendPadding()) {
982
+ return 0;
869
983
  }
870
- const codec = this.codec;
871
- if (!codec) {
984
+ return ((await this.outgoing.enqueue(() => this.padding.drainLoss(), {
985
+ kind: "padding",
986
+ bytes: this.bwe.estimator.probePaddingPacketBytes,
987
+ })) ?? 0);
988
+ }
989
+ createPaddingInjector() {
990
+ const sender = this;
991
+ return new padding_1.PaddingInjector({
992
+ get estimator() {
993
+ return sender.bwe.estimator;
994
+ },
995
+ get generation() {
996
+ return sender.bwe.generation;
997
+ },
998
+ canDrain: () => !sender.stopped &&
999
+ sender.dtlsTransport?.state === "connected" &&
1000
+ !!sender.codec &&
1001
+ sender.canSendPadding(),
1002
+ isCancelled: (generation) => sender.stopped ||
1003
+ sender.sendSuppressed ||
1004
+ generation !== sender.bwe.generation,
1005
+ hasQueuedRealtimeMedia: () => sender.outgoing.hasQueuedRealtimeMedia(),
1006
+ sendPadding: (packetBytes, probe) => sender.sendRtpInternal(sender.createPaddingRtpPacket(packetBytes), {
1007
+ injectProbePadding: false,
1008
+ forceProbeTag: probe,
1009
+ isProbePadding: true,
1010
+ }),
1011
+ });
1012
+ }
1013
+ /** Padding-only RTP on the RTX SSRC / payload type ({@link createRtxPaddingPacket}). */
1014
+ createPaddingRtpPacket(paddingSize) {
1015
+ return (0, rtp_1.createRtxPaddingPacket)({
1016
+ paddingSize,
1017
+ timestamp: this.continuity.timestamp ?? 0,
1018
+ payloadType: this.rtxPayloadType,
1019
+ ssrc: this.rtxSsrc,
1020
+ });
1021
+ }
1022
+ async sendRtpInternal(rtp, opts = {}) {
1023
+ if (this.stopped)
1024
+ return;
1025
+ // Not sending in the negotiated direction: drop media and padding.
1026
+ // NACK retransmissions keep develop's behavior.
1027
+ if (this.sendSuppressed && !opts.isRetransmission)
1028
+ return;
1029
+ if (this.dtlsTransport.state !== "connected" || !this.codec) {
872
1030
  return;
873
1031
  }
874
- rtp = Buffer.isBuffer(rtp) ? rtp_1.RtpPacket.deSerialize(rtp) : rtp.clone();
1032
+ const sendClockRate = (this.sendPrimaryCodec ?? this.codec).clockRate;
1033
+ rtp = Buffer.isBuffer(rtp) ? rtp_1.RtpPacket.deSerialize(rtp) : rtp;
875
1034
  const { header, payload } = rtp;
1035
+ // Capture BWE generation at send start. After await sendRtp, only deliver
1036
+ // SentInfo when the generation is unchanged — mid-send setBandwidthEstimator
1037
+ // must not pollute the new clean estimator with packets planned under the old one.
1038
+ const sendGeneration = this.bwe.generation;
1039
+ const estimatorAtStart = this.bwe.estimator;
1040
+ const twccOn = this.isTransportCcNegotiated();
1041
+ // Lightweight / disabled: no probe reservation or pacing wait (direct path).
1042
+ const paced = (0, bandwidthEstimator_1.needsPacedSendPath)(estimatorAtStart);
1043
+ // Stale source: drop before touching probe reservation or pacing budget.
1044
+ if (this.isStaleSource(opts.sourceEpoch)) {
1045
+ return;
1046
+ }
1047
+ // pin CurrentCluster: reserve probe id **before** the async send so a
1048
+ // concurrent completion cannot re-attribute this packet to the next cluster.
1049
+ let reservedClusterId;
1050
+ const wantsProbe = opts.forceProbeTag === true || estimatorAtStart.shouldTagProbePacket();
1051
+ if (paced && twccOn && wantsProbe) {
1052
+ const reservation = estimatorAtStart.reserveOutgoingProbe((0, utils_1.milliTime)());
1053
+ if (reservation) {
1054
+ reservedClusterId = reservation.clusterId;
1055
+ if (!(await this.awaitProbeSendTime(reservation.nextSendTimeMs, sendGeneration, opts.sourceEpoch))) {
1056
+ return;
1057
+ }
1058
+ }
1059
+ else if (opts.forceProbeTag) {
1060
+ // Cluster already filled / discarded — do not emit untagged padding.
1061
+ return;
1062
+ }
1063
+ }
876
1064
  const inputSequenceNumber = header.sequenceNumber;
877
1065
  const inputTimestamp = header.timestamp;
878
- if (this.rtpContinuityPending) {
879
- if (this.sequenceNumber != undefined && this.timestamp != undefined) {
880
- const offsets = freezeRtpContinuityOffsets(this.sequenceNumber, this.timestamp, inputSequenceNumber, inputTimestamp, this.pendingTimestampStep);
881
- this.seqOffset = offsets.seqOffset;
882
- this.timestampOffset = offsets.timestampOffset;
883
- }
884
- this.rtpContinuityPending = false;
885
- this.pendingTimestampStep = 1;
1066
+ if (opts.isProbePadding) {
1067
+ // Padding is only ever sent on the negotiated RTX stream.
1068
+ if (this.rtxPayloadType === undefined)
1069
+ return;
1070
+ header.ssrc = this.rtxSsrc;
1071
+ header.payloadType = this.rtxPayloadType;
886
1072
  }
887
- header.ssrc = this.ssrc;
888
- header.payloadType = codec.payloadType;
889
- header.timestamp = (0, common_1.uint32Add)(header.timestamp, this.timestampOffset);
890
- header.sequenceNumber = (0, common_1.uint16Add)(header.sequenceNumber, this.seqOffset);
891
- this.timestamp = header.timestamp;
892
- this.sequenceNumber = header.sequenceNumber;
893
- const ntpTimestamp = (0, utils_1.ntpTime)();
894
- const originalHeaderExtensions = [...header.extensions];
895
- header.extensions = this.headerExtensions
896
- .map((extension) => {
897
- const payload = (() => {
898
- switch (extension.uri) {
899
- case rtp_1.RTP_EXTENSION_URI.sdesMid:
900
- if (this.mid) {
901
- return (0, rtp_1.serializeSdesMid)(this.mid);
902
- }
903
- return;
904
- // todo : sender simulcast unsupported now
905
- case rtp_1.RTP_EXTENSION_URI.sdesRTPStreamID:
906
- if (this.rtpStreamId) {
907
- return (0, rtp_1.serializeSdesRTPStreamID)(this.rtpStreamId);
908
- }
909
- return;
910
- // todo : sender simulcast unsupported now
911
- case rtp_1.RTP_EXTENSION_URI.repairedRtpStreamId:
912
- if (this.repairedRtpStreamId) {
913
- return (0, rtp_1.serializeRepairedRtpStreamId)(this.repairedRtpStreamId);
914
- }
915
- return;
916
- case rtp_1.RTP_EXTENSION_URI.transportWideCC:
917
- this.dtlsTransport.transportSequenceNumber = (0, common_1.uint16Add)(this.dtlsTransport.transportSequenceNumber, 1);
918
- return (0, rtp_1.serializeTransportWideCC)(this.dtlsTransport.transportSequenceNumber);
919
- case rtp_1.RTP_EXTENSION_URI.absSendTime:
920
- return (0, rtp_1.serializeAbsSendTime)(ntpTimestamp);
921
- }
922
- })();
923
- if (payload)
924
- return { id: extension.id, payload };
925
- })
926
- .filter((v) => v);
927
- for (const ext of originalHeaderExtensions) {
928
- const exist = header.extensions.find((v) => v.id === ext.id);
929
- if (exist) {
930
- exist.payload = ext.payload;
1073
+ else if (!opts.isRetransmission) {
1074
+ header.ssrc = this.ssrc;
1075
+ header.payloadType = this.codec.payloadType;
1076
+ header.timestamp = this.continuity.mapTimestamp(inputTimestamp);
1077
+ }
1078
+ header.extensions = (0, rtp_1.buildSendHeaderExtensions)(header.extensions, this.headerExtensions, {
1079
+ mid: this.mid,
1080
+ rtpStreamId: this.rtpStreamId,
1081
+ repairedRtpStreamId: this.repairedRtpStreamId,
1082
+ });
1083
+ const useRed = !!this.redRedundantPayloadType &&
1084
+ !opts.isProbePadding &&
1085
+ !opts.isRetransmission;
1086
+ const estimatedPayloadLen = useRed
1087
+ ? this.redEncoder.serializedLengthWith({
1088
+ block: payload,
1089
+ timestamp: header.timestamp,
1090
+ blockPT: this.redRedundantPayloadType,
1091
+ })
1092
+ : payload.length;
1093
+ const rfcPaddingLen = header.padding && header.paddingSize > 0 ? header.paddingSize : 0;
1094
+ const constructedBytes = header.serializeSize + estimatedPayloadLen + rfcPaddingLen;
1095
+ if (paced &&
1096
+ reservedClusterId === undefined &&
1097
+ this.mediaPacingEnabled &&
1098
+ twccOn &&
1099
+ estimatorAtStart.getPacingBitrateBps() > 0) {
1100
+ if (!(await this.awaitPacingBudget(constructedBytes, sendGeneration, opts.sourceEpoch))) {
1101
+ return;
931
1102
  }
932
- else {
933
- header.extensions.push(ext);
1103
+ }
1104
+ if (this.stopped || sendGeneration !== this.bwe.generation) {
1105
+ return;
1106
+ }
1107
+ // Direction changed to not sending while this packet waited.
1108
+ if (this.sendSuppressed && !opts.isRetransmission) {
1109
+ return;
1110
+ }
1111
+ // Accepted under a replaced/detached source: never send it, and never let
1112
+ // it consume the new source's continuity offset.
1113
+ if (this.isStaleSource(opts.sourceEpoch)) {
1114
+ return;
1115
+ }
1116
+ if (opts.isProbePadding) {
1117
+ // RTX owns its sequence space, so padding never shifts media numbers.
1118
+ header.sequenceNumber = this.rtxSequenceNumber;
1119
+ this.rtxSequenceNumber = (0, common_1.uint16Add)(this.rtxSequenceNumber, 1);
1120
+ header.timestamp = this.continuity.timestamp ?? header.timestamp;
1121
+ }
1122
+ else if (!opts.isRetransmission) {
1123
+ if (this.continuity.assign(header, inputSequenceNumber, inputTimestamp)) {
1124
+ // ソース境界を SR の RTP/NTP 基準にも反映する。
1125
+ this.stats.resetClockAnchor();
934
1126
  }
935
1127
  }
936
- header.extensions = header.extensions.sort((a, b) => a.id - b.id);
937
- this.ntpTimestamp = ntpTimestamp;
938
- this.rtpTimestamp = header.timestamp;
939
- this.octetCount += payload.length;
940
- this.headerBytesSent += header.serializeSize;
941
- this.packetCount = (0, common_1.uint32Add)(this.packetCount, 1);
942
- this.rtpCache[header.sequenceNumber % RTP_HISTORY_SIZE] = rtp;
943
1128
  let rtpPayload = payload;
944
- if (this.redRedundantPayloadType) {
1129
+ if (useRed) {
945
1130
  this.redEncoder.push({
946
1131
  block: rtpPayload,
947
1132
  timestamp: header.timestamp,
948
1133
  blockPT: this.redRedundantPayloadType,
949
1134
  });
950
- const red = this.redEncoder.build();
951
- rtpPayload = red.serialize();
1135
+ rtpPayload = this.redEncoder.build().serialize();
1136
+ }
1137
+ const payloadOctetsForSr = rtpPayload.length;
1138
+ if (header.padding && header.paddingSize > 0) {
1139
+ rtpPayload = (0, rtp_1.appendRfc3550Padding)(rtpPayload, header.paddingSize);
1140
+ }
1141
+ const packetWideSeq = (0, rtp_1.stampHopByHopExtensions)(header, this.headerExtensions, {
1142
+ twccOn,
1143
+ allocateTransportWideSequence: () => this.dtlsTransport.allocateTransportWideSequence(),
1144
+ ntpTimestamp: (0, utils_1.ntpTime)(),
1145
+ });
1146
+ if (opts.isProbePadding) {
1147
+ // RTX padding: not part of the media SSRC's SR packet / octet counts.
1148
+ }
1149
+ else if (opts.isRetransmission) {
1150
+ this.stats.recordRetransmissionSent(header.serializeSize, payload.length);
1151
+ }
1152
+ else {
1153
+ this.stats.recordMediaSent(header.serializeSize, payloadOctetsForSr);
1154
+ if (!(0, rtp_1.isPaddingOnlyRtpPacket)(rtp)) {
1155
+ this.rtpCache[header.sequenceNumber % RTP_HISTORY_SIZE] = rtp;
1156
+ }
1157
+ }
1158
+ const sendingAtMs = (0, utils_1.milliTime)();
1159
+ const { size, sendingAtMs: enqueueAtMs } = await (0, rtpWire_1.sendDtlsRtp)(this.dtlsTransport, rtpPayload, header, sendingAtMs);
1160
+ const sentAtMs = (0, utils_1.milliTime)();
1161
+ if (!opts.isProbePadding &&
1162
+ !opts.isRetransmission &&
1163
+ !(0, rtp_1.isPaddingOnlyRtpPacket)(rtp)) {
1164
+ this.stats.updateClockAnchor(header.timestamp, sendClockRate);
952
1165
  }
953
- const size = await this.dtlsTransport.sendRtp(rtpPayload, header);
954
1166
  this.runRtcp();
955
- const millitime = (0, utils_1.milliTime)();
956
- const sentInfo = {
957
- wideSeq: this.dtlsTransport.transportSequenceNumber,
958
- size,
959
- sendingAtMs: millitime,
960
- sentAtMs: millitime,
961
- };
962
- this.senderBWE.rtpPacketSent(sentInfo);
1167
+ // BWE / TWCC only when transport-cc is negotiated — otherwise wideSeq would
1168
+ // not advance and probe padding would be useless / harmful.
1169
+ // Generation match: estimator was not swapped (or reset) while this packet
1170
+ // was in flight. Mismatch → discard (do not feed disposed or new clean BWE).
1171
+ if (twccOn &&
1172
+ packetWideSeq !== undefined &&
1173
+ sendGeneration === this.bwe.generation) {
1174
+ const priorUnacked = this.pendingUntrackedBytes;
1175
+ this.pendingUntrackedBytes = 0;
1176
+ const sentInfo = {
1177
+ wideSeq: packetWideSeq,
1178
+ size,
1179
+ sendingAtMs: enqueueAtMs,
1180
+ sentAtMs,
1181
+ isProbation: reservedClusterId !== undefined,
1182
+ probeClusterId: reservedClusterId,
1183
+ priorUnackedBytes: priorUnacked,
1184
+ isRetransmission: opts.isRetransmission === true,
1185
+ };
1186
+ estimatorAtStart.rtpPacketSent(sentInfo);
1187
+ }
1188
+ else if (twccOn && sendGeneration === this.bwe.generation) {
1189
+ // Same generation but no wideSeq (should be rare). Do not fold
1190
+ // previous-generation bytes into the next estimator.
1191
+ this.pendingUntrackedBytes += size;
1192
+ }
1193
+ if (opts.injectProbePadding &&
1194
+ twccOn &&
1195
+ (0, bandwidthEstimator_1.isProbePacingController)(estimatorAtStart) &&
1196
+ sendGeneration === this.bwe.generation) {
1197
+ this.nestOutgoingPadding = true;
1198
+ try {
1199
+ await this.maybeInjectProbePadding();
1200
+ }
1201
+ finally {
1202
+ this.nestOutgoingPadding = false;
1203
+ }
1204
+ }
1205
+ }
1206
+ /** pin BitrateProber next_probe_time wait ({@link waitForProbeSendTime}). */
1207
+ awaitProbeSendTime(nextSendTimeMs, generation, sourceEpoch) {
1208
+ return (0, sendPacer_1.waitForProbeSendTime)(nextSendTimeMs, () => this.isSendAlive(generation, sourceEpoch), () => this.sendWaitSignal(sourceEpoch));
1209
+ }
1210
+ /**
1211
+ * Token-bucket wait against {@link pacingBitrateBps} for **media**.
1212
+ * Probe packets use {@link awaitProbeSendTime} instead.
1213
+ * Returns false if the sender is stopped, the estimator is swapped
1214
+ * (`generation` changes), or the packet's source is replaced/detached while
1215
+ * waiting (budget is not consumed then).
1216
+ */
1217
+ awaitPacingBudget(packetBytes, generation, sourceEpoch) {
1218
+ return this.pacer.acquire(packetBytes, this.pacingBitrateBps, () => this.isSendAlive(generation, sourceEpoch), () => this.sendWaitSignal(sourceEpoch));
963
1219
  }
964
1220
  /**
965
1221
  * @param firEntries Internal: the FCI entries of a FIR the router resolved to
@@ -975,22 +1231,12 @@ class RTCRtpSender {
975
1231
  packet.reports
976
1232
  .filter((report) => report.ssrc === this.ssrc)
977
1233
  .forEach((report) => {
978
- this.remotePacketsLost = report.packetsLost;
979
- this.remoteFractionLost = report.fractionLost / 256;
980
- if (this.lastSRtimestamp === report.lsr && report.dlsr) {
981
- if (this.lastSentSRTimestamp) {
982
- const rtt = (0, utils_1.timestampSeconds)() -
983
- this.lastSentSRTimestamp -
984
- report.dlsr / 65536;
985
- this.totalRoundTripTime += rtt;
986
- this.roundTripTimeMeasurements++;
987
- if (this.rtt === undefined) {
988
- this.rtt = rtt;
989
- }
990
- else {
991
- this.rtt = RTT_ALPHA * this.rtt + (1 - RTT_ALPHA) * rtt;
992
- }
993
- }
1234
+ const rawRttSeconds = this.stats.recordReceptionReport(report);
1235
+ // pin OnRoundTripTimeUpdate: only **unsmoothed** RTT goes to
1236
+ // AIMD (smoothed updates are discarded in GoogCc).
1237
+ // Lightweight / disabled no-op setRoundTripTime.
1238
+ if (rawRttSeconds !== undefined && rawRttSeconds > 0) {
1239
+ this.bwe.estimator.setRoundTripTime(rawRttSeconds * 1000);
994
1240
  }
995
1241
  });
996
1242
  }
@@ -1008,21 +1254,30 @@ class RTCRtpSender {
1008
1254
  case rtp_1.GenericNack.count:
1009
1255
  {
1010
1256
  const feedback = packet.feedback;
1011
- this.nackCount++;
1257
+ this.stats.nackCount++;
1012
1258
  feedback.lost.forEach(async (seqNum) => {
1013
1259
  let packet = this.rtpCache[seqNum % RTP_HISTORY_SIZE];
1014
1260
  if (packet && packet.header.sequenceNumber !== seqNum) {
1015
1261
  packet = undefined;
1016
1262
  }
1263
+ if (packet && (0, rtp_1.isPaddingOnlyRtpPacket)(packet)) {
1264
+ packet = undefined;
1265
+ }
1017
1266
  if (packet) {
1018
1267
  if (this.rtxPayloadType != undefined) {
1019
1268
  packet = (0, rtp_1.wrapRtx)(packet, this.rtxPayloadType, this.rtxSequenceNumber, this.rtxSsrc);
1020
1269
  this.rtxSequenceNumber = (0, common_1.uint16Add)(this.rtxSequenceNumber, 1);
1021
1270
  }
1022
- this.retransmittedPacketsSent++;
1023
- this.retransmittedBytesSent += packet.payload.length;
1024
- this.headerBytesSent += packet.header.serializeSize;
1025
- await this.dtlsTransport.sendRtp(packet.payload, packet.header);
1271
+ const retransmission = packet;
1272
+ // Route through sendRtpInternal: new TWCC seq, pacing,
1273
+ // BWE SentInfo. Do not reuse the original transport-wide seq.
1274
+ await this.dispatchOutgoing(() => this.sendRtpInternal(retransmission, {
1275
+ injectProbePadding: false,
1276
+ isRetransmission: true,
1277
+ }), {
1278
+ kind: "rtx",
1279
+ bytes: (0, rtpWire_1.estimateOutgoingBytes)(retransmission),
1280
+ });
1026
1281
  }
1027
1282
  });
1028
1283
  this.onGenericNack.execute(feedback);
@@ -1043,7 +1298,7 @@ class RTCRtpSender {
1043
1298
  break;
1044
1299
  case rtp_1.PictureLossIndication.count:
1045
1300
  {
1046
- this.pliCount++;
1301
+ this.stats.pliCount++;
1047
1302
  this.onPictureLossIndication.execute();
1048
1303
  this.onKeyFrameRequest.execute("pli");
1049
1304
  }
@@ -1057,7 +1312,7 @@ class RTCRtpSender {
1057
1312
  break;
1058
1313
  // W3C webrtc-stats: firCount is the number of FIR packets received,
1059
1314
  // however many FCI entries of the packet resolve to this sender
1060
- this.firCount++;
1315
+ this.stats.firCount++;
1061
1316
  // an entry with the same sequence number as the last one for its
1062
1317
  // (sender, target) pair is a retransmission (RFC 5104 4.3.1.1)
1063
1318
  let isNew = false;
@@ -1092,100 +1347,22 @@ class RTCRtpSender {
1092
1347
  this.setSendEncodings(params.encodings);
1093
1348
  }
1094
1349
  }
1095
- get outboundRtpStatsId() {
1096
- return (0, stats_1.generateStatsId)("outbound-rtp", this.trackId);
1097
- }
1098
- get mediaSourceStatsId() {
1099
- return (0, stats_1.generateStatsId)("media-source", this.trackId);
1100
- }
1101
- get remoteInboundRtpStatsId() {
1102
- return (0, stats_1.generateStatsId)("remote-inbound-rtp", this.trackId);
1103
- }
1104
1350
  getStatsRootIds() {
1105
- return [this.outboundRtpStatsId];
1351
+ return [(0, senderStats_1.senderStatsIds)(this.trackId).outboundRtp];
1106
1352
  }
1107
1353
  collectStats(timestamp) {
1108
- const stats = [];
1109
- const transportId = this.dtlsTransport
1110
- ? (0, stats_1.generateStatsId)("transport", this.dtlsTransport.id)
1111
- : undefined;
1112
- const codecId = this.codec && transportId
1113
- ? (0, stats_1.generateCodecStatsId)(transportId, this.codec.payloadType, this.trackId)
1114
- : undefined;
1115
- // Outbound RTP stats
1116
- const outboundRtpStats = {
1117
- type: "outbound-rtp",
1118
- id: this.outboundRtpStatsId,
1119
- timestamp,
1354
+ return this.stats.collect({
1355
+ trackId: this.trackId,
1120
1356
  ssrc: this.ssrc,
1121
1357
  kind: this.kind,
1122
- transportId,
1123
- codecId,
1124
1358
  mid: this.mid,
1125
- packetsSent: this.packetCount,
1126
- bytesSent: this.octetCount,
1127
- headerBytesSent: this.headerBytesSent,
1128
- retransmittedPacketsSent: this.retransmittedPacketsSent || undefined,
1129
- retransmittedBytesSent: this.retransmittedBytesSent || undefined,
1359
+ dtlsTransport: this.dtlsTransport,
1360
+ codec: this.codec,
1130
1361
  rtxSsrc: this.rtxPayloadType ? this.rtxSsrc : undefined,
1131
- mediaSourceId: this.track ? this.mediaSourceStatsId : undefined,
1132
- remoteId: this.rtt !== undefined ||
1133
- this.remotePacketsLost !== undefined ||
1134
- this.remoteFractionLost !== undefined
1135
- ? this.remoteInboundRtpStatsId
1362
+ trackIdentifier: this.track
1363
+ ? (this.track.id ?? this.trackId)
1136
1364
  : undefined,
1137
- nackCount: this.nackCount || undefined,
1138
- pliCount: this.pliCount || undefined,
1139
- firCount: this.firCount || undefined,
1140
- };
1141
- stats.push(outboundRtpStats);
1142
- // Media source stats
1143
- if (this.track) {
1144
- const mediaSourceStats = {
1145
- type: "media-source",
1146
- id: this.mediaSourceStatsId,
1147
- timestamp,
1148
- trackIdentifier: this.track.id ?? this.trackId,
1149
- kind: this.kind,
1150
- };
1151
- stats.push(mediaSourceStats);
1152
- }
1153
- if (this.codec && transportId) {
1154
- const codecStats = {
1155
- type: "codec",
1156
- id: codecId,
1157
- timestamp,
1158
- payloadType: this.codec.payloadType,
1159
- transportId,
1160
- mimeType: this.codec.mimeType,
1161
- clockRate: this.codec.clockRate,
1162
- channels: this.codec.channels,
1163
- sdpFmtpLine: this.codec.parameters,
1164
- };
1165
- stats.push(codecStats);
1166
- }
1167
- // Remote inbound RTP stats (if we have RTT)
1168
- if (this.rtt !== undefined ||
1169
- this.remotePacketsLost !== undefined ||
1170
- this.remoteFractionLost !== undefined) {
1171
- const remoteInboundStats = {
1172
- type: "remote-inbound-rtp",
1173
- id: this.remoteInboundRtpStatsId,
1174
- timestamp,
1175
- ssrc: this.ssrc,
1176
- kind: this.kind,
1177
- transportId,
1178
- codecId: outboundRtpStats.codecId,
1179
- localId: outboundRtpStats.id,
1180
- roundTripTime: this.rtt,
1181
- totalRoundTripTime: this.totalRoundTripTime,
1182
- roundTripTimeMeasurements: this.roundTripTimeMeasurements,
1183
- packetsLost: this.remotePacketsLost,
1184
- fractionLost: this.remoteFractionLost,
1185
- };
1186
- stats.push(remoteInboundStats);
1187
- }
1188
- return stats;
1365
+ }, timestamp);
1189
1366
  }
1190
1367
  async getStats() {
1191
1368
  const timestamp = (0, stats_1.getStatsTimestamp)();