werift 0.25.2 → 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 (568) hide show
  1. package/README.md +63 -0
  2. package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
  3. package/lib/common/src/asn1.d.ts +42 -0
  4. package/lib/common/src/asn1.js +163 -0
  5. package/lib/common/src/asn1.js.map +1 -0
  6. package/lib/common/src/binary.d.ts +1 -3
  7. package/lib/common/src/binary.js +8 -6
  8. package/lib/common/src/binary.js.map +1 -1
  9. package/lib/common/src/binaryData.js +2 -1
  10. package/lib/common/src/binaryData.js.map +1 -1
  11. package/lib/common/src/index.d.ts +6 -5
  12. package/lib/common/src/index.js +6 -5
  13. package/lib/common/src/index.js.map +1 -1
  14. package/lib/common/src/log.d.ts +12 -1
  15. package/lib/common/src/log.js +142 -12
  16. package/lib/common/src/log.js.map +1 -1
  17. package/lib/common/src/network.js.map +1 -1
  18. package/lib/common/src/queue.d.ts +41 -0
  19. package/lib/common/src/queue.js +146 -0
  20. package/lib/common/src/queue.js.map +1 -0
  21. package/lib/common/src/transport.d.ts +15 -2
  22. package/lib/common/src/transport.js +108 -19
  23. package/lib/common/src/transport.js.map +1 -1
  24. package/lib/dtls/src/cipher/create.js.map +1 -1
  25. package/lib/dtls/src/cipher/ec.js +8 -8
  26. package/lib/dtls/src/cipher/ec.js.map +1 -1
  27. package/lib/dtls/src/cipher/namedCurve.js +6 -7
  28. package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
  29. package/lib/dtls/src/cipher/prf.d.ts +2 -2
  30. package/lib/dtls/src/cipher/prf.js +29 -8
  31. package/lib/dtls/src/cipher/prf.js.map +1 -1
  32. package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
  33. package/lib/dtls/src/context/certificate.d.ts +32 -0
  34. package/lib/dtls/src/context/certificate.js +54 -0
  35. package/lib/dtls/src/context/certificate.js.map +1 -0
  36. package/lib/dtls/src/context/cipher.d.ts +13 -7
  37. package/lib/dtls/src/context/cipher.js +58 -106
  38. package/lib/dtls/src/context/cipher.js.map +1 -1
  39. package/lib/dtls/src/context/dtls.js +4 -2
  40. package/lib/dtls/src/context/dtls.js.map +1 -1
  41. package/lib/dtls/src/context/transport.d.ts +4 -0
  42. package/lib/dtls/src/context/transport.js +16 -1
  43. package/lib/dtls/src/context/transport.js.map +1 -1
  44. package/lib/dtls/src/flight/client/flight1.js +2 -1
  45. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  46. package/lib/dtls/src/flight/client/flight5.js +4 -2
  47. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  48. package/lib/dtls/src/flight/flight.d.ts +1 -1
  49. package/lib/dtls/src/flight/flight.js +16 -5
  50. package/lib/dtls/src/flight/flight.js.map +1 -1
  51. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  52. package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
  53. package/lib/dtls/src/flight/server/flight4.js +12 -4
  54. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  55. package/lib/dtls/src/flight/server/flight6.js +2 -1
  56. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  57. package/lib/dtls/src/handshake/const.d.ts +17 -13
  58. package/lib/dtls/src/handshake/const.js +16 -14
  59. package/lib/dtls/src/handshake/const.js.map +1 -1
  60. package/lib/dtls/src/handshake/extensions/signature.d.ts +1 -1
  61. package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
  62. package/lib/dtls/src/handshake/message/alert.js +5 -3
  63. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  64. package/lib/dtls/src/handshake/message/certificate.js +3 -2
  65. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/changeCipherSpec.js +4 -4
  67. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
  69. package/lib/dtls/src/handshake/message/client/certificateVerify.js +5 -3
  70. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  71. package/lib/dtls/src/handshake/message/client/hello.js +15 -8
  72. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  73. package/lib/dtls/src/handshake/message/client/keyExchange.js +3 -2
  74. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  75. package/lib/dtls/src/handshake/message/finished.js +2 -1
  76. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  77. package/lib/dtls/src/handshake/message/server/certificateRequest.d.ts +1 -1
  78. package/lib/dtls/src/handshake/message/server/certificateRequest.js +7 -4
  79. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  80. package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
  81. package/lib/dtls/src/handshake/message/server/hello.js +14 -8
  82. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  83. package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
  84. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  85. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +5 -3
  86. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  87. package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
  88. package/lib/dtls/src/handshake/message/server/keyExchange.js +17 -9
  89. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  90. package/lib/dtls/src/handshake/random.d.ts +1 -1
  91. package/lib/dtls/src/handshake/random.js +7 -4
  92. package/lib/dtls/src/handshake/random.js.map +1 -1
  93. package/lib/dtls/src/imports/common.d.ts +1 -0
  94. package/lib/dtls/src/imports/common.js +1 -0
  95. package/lib/dtls/src/imports/common.js.map +1 -1
  96. package/lib/dtls/src/index.d.ts +2 -2
  97. package/lib/dtls/src/index.js +2 -2
  98. package/lib/dtls/src/index.js.map +1 -1
  99. package/lib/dtls/src/record/const.d.ts +43 -33
  100. package/lib/dtls/src/record/const.js +43 -36
  101. package/lib/dtls/src/record/const.js.map +1 -1
  102. package/lib/dtls/src/record/message/fragment.d.ts +1 -1
  103. package/lib/dtls/src/record/message/fragment.js +15 -9
  104. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  105. package/lib/dtls/src/record/message/header.js +12 -7
  106. package/lib/dtls/src/record/message/header.js.map +1 -1
  107. package/lib/dtls/src/record/message/plaintext.js +4 -2
  108. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  109. package/lib/dtls/src/record/receive.js +2 -2
  110. package/lib/dtls/src/record/receive.js.map +1 -1
  111. package/lib/dtls/src/server.js +1 -1
  112. package/lib/dtls/src/server.js.map +1 -1
  113. package/lib/dtls/src/socket.d.ts +2 -2
  114. package/lib/dtls/src/socket.js +6 -4
  115. package/lib/dtls/src/socket.js.map +1 -1
  116. package/lib/ice/src/candidate.d.ts +1 -1
  117. package/lib/ice/src/candidate.js +24 -12
  118. package/lib/ice/src/candidate.js.map +1 -1
  119. package/lib/ice/src/dns/lookup.d.ts +10 -1
  120. package/lib/ice/src/dns/lookup.js +42 -7
  121. package/lib/ice/src/dns/lookup.js.map +1 -1
  122. package/lib/ice/src/exceptions.d.ts +46 -0
  123. package/lib/ice/src/exceptions.js +92 -5
  124. package/lib/ice/src/exceptions.js.map +1 -1
  125. package/lib/ice/src/helper.d.ts +1 -1
  126. package/lib/ice/src/ice.d.ts +191 -5
  127. package/lib/ice/src/ice.js +1048 -156
  128. package/lib/ice/src/ice.js.map +1 -1
  129. package/lib/ice/src/iceBase.d.ts +174 -10
  130. package/lib/ice/src/iceBase.js +165 -12
  131. package/lib/ice/src/iceBase.js.map +1 -1
  132. package/lib/ice/src/index.d.ts +5 -5
  133. package/lib/ice/src/index.js +5 -5
  134. package/lib/ice/src/index.js.map +1 -1
  135. package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
  136. package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
  137. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
  138. package/lib/ice/src/stun/protocol.d.ts +3 -1
  139. package/lib/ice/src/stun/protocol.js +16 -0
  140. package/lib/ice/src/stun/protocol.js.map +1 -1
  141. package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
  142. package/lib/ice/src/stun/tcpProtocol.js +16 -1
  143. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  144. package/lib/ice/src/stun/transaction.d.ts +35 -1
  145. package/lib/ice/src/stun/transaction.js +93 -18
  146. package/lib/ice/src/stun/transaction.js.map +1 -1
  147. package/lib/ice/src/turn/credential.d.ts +49 -0
  148. package/lib/ice/src/turn/credential.js +78 -0
  149. package/lib/ice/src/turn/credential.js.map +1 -0
  150. package/lib/ice/src/turn/protocol.d.ts +97 -7
  151. package/lib/ice/src/turn/protocol.js +357 -55
  152. package/lib/ice/src/turn/protocol.js.map +1 -1
  153. package/lib/ice/src/utils.js.map +1 -1
  154. package/lib/ice-server/src/stun/attributes.d.ts +2 -0
  155. package/lib/ice-server/src/stun/attributes.js +7 -1
  156. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  157. package/lib/ice-server/src/stun/const.d.ts +24 -16
  158. package/lib/ice-server/src/stun/const.js +22 -18
  159. package/lib/ice-server/src/stun/const.js.map +1 -1
  160. package/lib/ice-server/src/stun/message.d.ts +3 -1
  161. package/lib/ice-server/src/stun/message.js +41 -6
  162. package/lib/ice-server/src/stun/message.js.map +1 -1
  163. package/lib/ice-server/src/turn/auth.d.ts +1 -1
  164. package/lib/index.mjs +25252 -12664
  165. package/lib/nonstandard/index.mjs +11015 -8906
  166. package/lib/polyfill/dom.mjs +30779 -18386
  167. package/lib/polyfill/index.mjs +30779 -18386
  168. package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
  169. package/lib/rtp/src/codec/assertPayload.js +12 -0
  170. package/lib/rtp/src/codec/assertPayload.js.map +1 -0
  171. package/lib/rtp/src/codec/av1.js +2 -0
  172. package/lib/rtp/src/codec/av1.js.map +1 -1
  173. package/lib/rtp/src/codec/h264.d.ts +1 -1
  174. package/lib/rtp/src/codec/h264.js +35 -43
  175. package/lib/rtp/src/codec/h264.js.map +1 -1
  176. package/lib/rtp/src/codec/vp8.js +11 -5
  177. package/lib/rtp/src/codec/vp8.js.map +1 -1
  178. package/lib/rtp/src/codec/vp9.js +12 -0
  179. package/lib/rtp/src/codec/vp9.js.map +1 -1
  180. package/lib/rtp/src/extra/container/mp4/container.js +2 -1
  181. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  182. package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
  183. package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
  184. package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
  185. package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
  186. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  187. package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
  188. package/lib/rtp/src/extra/container/ogg/index.js +1 -0
  189. package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
  190. package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
  191. package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
  192. package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
  193. package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
  194. package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
  195. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +26 -4
  196. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  197. package/lib/rtp/src/extra/processor/depacketizer.d.ts +6 -1
  198. package/lib/rtp/src/extra/processor/depacketizer.js +29 -3
  199. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  200. package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
  201. package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
  202. package/lib/rtp/src/extra/processor/dtx.js +4 -2
  203. package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
  204. package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
  205. package/lib/rtp/src/extra/processor/index.d.ts +2 -0
  206. package/lib/rtp/src/extra/processor/index.js +2 -0
  207. package/lib/rtp/src/extra/processor/index.js.map +1 -1
  208. package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
  209. package/lib/rtp/src/extra/processor/interface.js.map +1 -1
  210. package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
  211. package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
  212. package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
  213. package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
  214. package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
  215. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
  216. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
  217. package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
  218. package/lib/rtp/src/extra/processor/lipsync.js +202 -51
  219. package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
  220. package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
  221. package/lib/rtp/src/extra/processor/mp4.js +7 -4
  222. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  223. package/lib/rtp/src/extra/processor/mute.js +4 -2
  224. package/lib/rtp/src/extra/processor/mute.js.map +1 -1
  225. package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
  226. package/lib/rtp/src/extra/processor/nack.js +5 -3
  227. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  228. package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
  229. package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
  230. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  231. package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
  232. package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
  233. package/lib/rtp/src/extra/processor/ogg.js +221 -0
  234. package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
  235. package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
  236. package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
  237. package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
  238. package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
  239. package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
  240. package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
  241. package/lib/rtp/src/extra/processor/rtpCallback.js +3 -2
  242. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  243. package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
  244. package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
  245. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  246. package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
  247. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  248. package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
  249. package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
  250. package/lib/rtp/src/extra/processor/webm.js +57 -23
  251. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  252. package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
  253. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  254. package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
  255. package/lib/rtp/src/helper.d.ts +2 -2
  256. package/lib/rtp/src/helper.js +2 -6
  257. package/lib/rtp/src/helper.js.map +1 -1
  258. package/lib/rtp/src/index.d.ts +10 -2
  259. package/lib/rtp/src/index.js +10 -2
  260. package/lib/rtp/src/index.js.map +1 -1
  261. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
  262. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +6 -1
  263. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  264. package/lib/rtp/src/rtcp/rtcp.js +9 -4
  265. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  266. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
  267. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
  268. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
  269. package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
  270. package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
  271. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  272. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
  273. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
  274. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
  275. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
  276. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
  277. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
  278. package/lib/rtp/src/rtcp/sr.d.ts +4 -3
  279. package/lib/rtp/src/rtcp/sr.js +4 -2
  280. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  281. package/lib/rtp/src/rtp/continuity.d.ts +36 -0
  282. package/lib/rtp/src/rtp/continuity.js +100 -0
  283. package/lib/rtp/src/rtp/continuity.js.map +1 -0
  284. package/lib/rtp/src/rtp/headerExtension.js +41 -21
  285. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  286. package/lib/rtp/src/rtp/padding.d.ts +17 -0
  287. package/lib/rtp/src/rtp/padding.js +37 -0
  288. package/lib/rtp/src/rtp/padding.js.map +1 -0
  289. package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
  290. package/lib/rtp/src/rtp/red/encoder.js +14 -1
  291. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  292. package/lib/rtp/src/rtp/red/packet.js +24 -8
  293. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  294. package/lib/rtp/src/rtp/rtp.d.ts +24 -1
  295. package/lib/rtp/src/rtp/rtp.js +70 -29
  296. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  297. package/lib/rtp/src/rtp/rtx.js +3 -0
  298. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  299. package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
  300. package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
  301. package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
  302. package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
  303. package/lib/rtp/src/srtp/cipher/ctr.js +5 -3
  304. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  305. package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
  306. package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
  307. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  308. package/lib/rtp/src/srtp/cipher/index.js +8 -4
  309. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  310. package/lib/rtp/src/srtp/context/context.d.ts +29 -1
  311. package/lib/rtp/src/srtp/context/context.js +84 -27
  312. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  313. package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
  314. package/lib/rtp/src/srtp/context/srtcp.js +33 -0
  315. package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
  316. package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
  317. package/lib/rtp/src/srtp/context/srtp.js +36 -4
  318. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  319. package/lib/rtp/src/srtp/error.d.ts +8 -0
  320. package/lib/rtp/src/srtp/error.js +13 -1
  321. package/lib/rtp/src/srtp/error.js.map +1 -1
  322. package/lib/rtp/src/srtp/packet.js +4 -1
  323. package/lib/rtp/src/srtp/packet.js.map +1 -1
  324. package/lib/rtp/src/srtp/replay.d.ts +24 -0
  325. package/lib/rtp/src/srtp/replay.js +75 -0
  326. package/lib/rtp/src/srtp/replay.js.map +1 -0
  327. package/lib/rtp/src/srtp/session.js +2 -1
  328. package/lib/rtp/src/srtp/session.js.map +1 -1
  329. package/lib/rtp/src/srtp/srtcp.js +2 -1
  330. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  331. package/lib/rtp/src/srtp/srtp.js +2 -1
  332. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  333. package/lib/rtp/src/util.js +2 -1
  334. package/lib/rtp/src/util.js.map +1 -1
  335. package/lib/sctp/src/chunk.d.ts +5 -0
  336. package/lib/sctp/src/chunk.js +31 -8
  337. package/lib/sctp/src/chunk.js.map +1 -1
  338. package/lib/sctp/src/const.d.ts +25 -17
  339. package/lib/sctp/src/const.js +23 -19
  340. package/lib/sctp/src/const.js.map +1 -1
  341. package/lib/sctp/src/index.d.ts +4 -3
  342. package/lib/sctp/src/index.js +10 -8
  343. package/lib/sctp/src/index.js.map +1 -1
  344. package/lib/sctp/src/param.d.ts +6 -2
  345. package/lib/sctp/src/param.js +22 -8
  346. package/lib/sctp/src/param.js.map +1 -1
  347. package/lib/sctp/src/sctp.d.ts +91 -2
  348. package/lib/sctp/src/sctp.js +700 -134
  349. package/lib/sctp/src/sctp.js.map +1 -1
  350. package/lib/sctp/src/transport.js +4 -2
  351. package/lib/sctp/src/transport.js.map +1 -1
  352. package/lib/webrtc/src/api/peerConfig.d.ts +307 -0
  353. package/lib/webrtc/src/api/peerConfig.js +291 -0
  354. package/lib/webrtc/src/api/peerConfig.js.map +1 -0
  355. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
  356. package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
  357. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
  358. package/lib/webrtc/src/dataChannel.d.ts +11 -1
  359. package/lib/webrtc/src/dataChannel.js +25 -5
  360. package/lib/webrtc/src/dataChannel.js.map +1 -1
  361. package/lib/webrtc/src/index.d.ts +2 -2
  362. package/lib/webrtc/src/index.js +2 -2
  363. package/lib/webrtc/src/index.js.map +1 -1
  364. package/lib/webrtc/src/media/index.d.ts +11 -1
  365. package/lib/webrtc/src/media/index.js +71 -1
  366. package/lib/webrtc/src/media/index.js.map +1 -1
  367. package/lib/webrtc/src/media/receiver/nack.js +5 -5
  368. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  369. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
  370. package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
  371. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  372. package/lib/webrtc/src/media/router.d.ts +130 -6
  373. package/lib/webrtc/src/media/router.js +325 -29
  374. package/lib/webrtc/src/media/router.js.map +1 -1
  375. package/lib/webrtc/src/media/rtpReceiver.d.ts +137 -14
  376. package/lib/webrtc/src/media/rtpReceiver.js +420 -44
  377. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  378. package/lib/webrtc/src/media/rtpSender.d.ts +232 -65
  379. package/lib/webrtc/src/media/rtpSender.js +784 -448
  380. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  381. package/lib/webrtc/src/media/rtpTransceiver.d.ts +95 -4
  382. package/lib/webrtc/src/media/rtpTransceiver.js +121 -9
  383. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  384. package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
  385. package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
  386. package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
  387. package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
  388. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
  389. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
  390. package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
  391. package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
  392. package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
  393. package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
  394. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
  395. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
  396. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
  397. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
  398. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
  399. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
  400. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
  401. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
  402. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
  403. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
  404. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
  405. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
  406. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
  407. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
  408. package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
  409. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
  410. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
  411. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
  412. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
  413. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
  414. package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
  415. package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
  416. package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
  417. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
  418. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
  419. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
  420. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
  421. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
  422. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
  423. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
  424. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
  425. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
  426. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
  427. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
  428. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
  429. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
  430. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
  431. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
  432. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
  433. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
  434. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
  435. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
  436. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
  437. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
  438. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
  439. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
  440. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
  441. package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
  442. package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
  443. package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
  444. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
  445. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
  446. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
  447. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
  448. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
  449. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
  450. package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
  451. package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
  452. package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
  453. package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
  454. package/lib/webrtc/src/media/sender/padding.js +134 -0
  455. package/lib/webrtc/src/media/sender/padding.js.map +1 -0
  456. package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
  457. package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
  458. package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
  459. package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
  460. package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
  461. package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
  462. package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
  463. package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
  464. package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
  465. package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -32
  466. package/lib/webrtc/src/media/sender/senderBWE.js +5 -142
  467. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  468. package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
  469. package/lib/webrtc/src/media/sender/senderStats.js +322 -0
  470. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
  471. package/lib/webrtc/src/media/track.d.ts +21 -3
  472. package/lib/webrtc/src/media/track.js +24 -6
  473. package/lib/webrtc/src/media/track.js.map +1 -1
  474. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +103 -0
  475. package/lib/webrtc/src/negotiation/bundleTopology.js +384 -0
  476. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
  477. package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
  478. package/lib/webrtc/src/negotiation/descriptionValidation.js +267 -0
  479. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
  480. package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
  481. package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
  482. package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
  483. package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
  484. package/lib/webrtc/src/negotiation/internalState.js +21 -0
  485. package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
  486. package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
  487. package/lib/webrtc/src/negotiation/negotiationNeeded.js +119 -0
  488. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
  489. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
  490. package/lib/webrtc/src/negotiation/remoteCandidates.js +349 -0
  491. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
  492. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
  493. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +414 -0
  494. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
  495. package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
  496. package/lib/webrtc/src/negotiation/transportActivation.js +356 -0
  497. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
  498. package/lib/webrtc/src/negotiationTransaction.d.ts +240 -0
  499. package/lib/webrtc/src/negotiationTransaction.js +604 -0
  500. package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
  501. package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
  502. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  503. package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
  504. package/lib/webrtc/src/nonstandard/index.js +1 -1
  505. package/lib/webrtc/src/nonstandard/index.js.map +1 -1
  506. package/lib/webrtc/src/nonstandard/navigator.js +4 -3
  507. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  508. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
  509. package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
  510. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  511. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +10 -8
  512. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
  513. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  514. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
  515. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
  516. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
  517. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
  518. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +10 -3
  519. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  520. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
  521. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  522. package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
  523. package/lib/webrtc/src/nonstandard/userMedia.js +4 -3
  524. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  525. package/lib/webrtc/src/peerConnection.d.ts +176 -238
  526. package/lib/webrtc/src/peerConnection.js +1042 -913
  527. package/lib/webrtc/src/peerConnection.js.map +1 -1
  528. package/lib/webrtc/src/polyfill/api.d.ts +5 -5
  529. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  530. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  531. package/lib/webrtc/src/polyfill/install.js +1 -1
  532. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  533. package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
  534. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  535. package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
  536. package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
  537. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  538. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  539. package/lib/webrtc/src/sctpManager.d.ts +97 -1
  540. package/lib/webrtc/src/sctpManager.js +189 -9
  541. package/lib/webrtc/src/sctpManager.js.map +1 -1
  542. package/lib/webrtc/src/sdp.js +12 -6
  543. package/lib/webrtc/src/sdp.js.map +1 -1
  544. package/lib/webrtc/src/sdpManager.d.ts +55 -11
  545. package/lib/webrtc/src/sdpManager.js +364 -87
  546. package/lib/webrtc/src/sdpManager.js.map +1 -1
  547. package/lib/webrtc/src/secureTransportManager.d.ts +89 -28
  548. package/lib/webrtc/src/secureTransportManager.js +232 -53
  549. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  550. package/lib/webrtc/src/transceiverManager.d.ts +62 -18
  551. package/lib/webrtc/src/transceiverManager.js +272 -107
  552. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  553. package/lib/webrtc/src/transport/dtls.d.ts +64 -3
  554. package/lib/webrtc/src/transport/dtls.js +166 -42
  555. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  556. package/lib/webrtc/src/transport/ice.d.ts +199 -28
  557. package/lib/webrtc/src/transport/ice.js +666 -71
  558. package/lib/webrtc/src/transport/ice.js.map +1 -1
  559. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
  560. package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
  561. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
  562. package/lib/webrtc/src/transport/sctp.d.ts +6 -1
  563. package/lib/webrtc/src/transport/sctp.js +149 -37
  564. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  565. package/lib/webrtc/src/utils.d.ts +39 -6
  566. package/lib/webrtc/src/utils.js +57 -17
  567. package/lib/webrtc/src/utils.js.map +1 -1
  568. package/package.json +16 -15
@@ -0,0 +1,429 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AimdRateControl = void 0;
4
+ /*!
5
+ * Portions of this file are ported from libwebrtc
6
+ * (https://webrtc.googlesource.com/src, commit 0fda16159e33adf59c71a7ad1173dcbe5a632102).
7
+ * Copyright (c) 2011, The WebRTC project authors. All rights reserved.
8
+ * Use of that source is governed by a BSD-style license and an additional
9
+ * patent grant; both are reproduced in THIRD_PARTY_LICENSES_LIBWEBRTC.txt
10
+ * (shipped with this package).
11
+ */
12
+ const constants_1 = require("./constants");
13
+ const linkCapacityEstimator_1 = require("./linkCapacityEstimator");
14
+ /**
15
+ * AIMD rate controller for the delay-based estimate (pin
16
+ * `modules/remote_bitrate_estimator/aimd_rate_control.{h,cc}`).
17
+ *
18
+ * Ports ChangeState / ChangeBitrate / MultiplicativeRateIncrease /
19
+ * AdditiveRateIncrease / TimeToReduceFurther / GetNearMaxIncreaseRate.
20
+ *
21
+ * RTT is **only** via {@link setRtt} (RTCP / OnRoundTripTimeUpdate path) —
22
+ * never from TWCC propagation RTT / RttBasedBackoff.
23
+ */
24
+ class AimdRateControl {
25
+ constructor() {
26
+ Object.defineProperty(this, "minConfiguredBps", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: constants_1.kMinBitrateBps
31
+ });
32
+ Object.defineProperty(this, "maxConfiguredBps", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: constants_1.kMaxBitrateBps
37
+ });
38
+ Object.defineProperty(this, "currentBitrateBps", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: constants_1.kDefaultStartBitrateBps
43
+ });
44
+ Object.defineProperty(this, "latestEstimatedThroughputBps", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: constants_1.kDefaultStartBitrateBps
49
+ });
50
+ Object.defineProperty(this, "linkCapacity", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: new linkCapacityEstimator_1.LinkCapacityEstimator()
55
+ });
56
+ Object.defineProperty(this, "rateControlState", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: "hold"
61
+ });
62
+ /** Pin `time_last_bitrate_change_` — used by TimeToReduceFurther. */
63
+ Object.defineProperty(this, "timeLastBitrateChangeMs", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: Number.NEGATIVE_INFINITY
68
+ });
69
+ Object.defineProperty(this, "timeLastBitrateDecreaseMs", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: Number.NEGATIVE_INFINITY
74
+ });
75
+ Object.defineProperty(this, "timeFirstThroughputEstimateMs", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: Number.NEGATIVE_INFINITY
80
+ });
81
+ Object.defineProperty(this, "bitrateIsInitialized", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: false
86
+ });
87
+ Object.defineProperty(this, "beta", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: constants_1.kBeta
92
+ });
93
+ Object.defineProperty(this, "inAlr", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: false
98
+ });
99
+ /** Default 200ms (pin kDefaultRtt). Updated only via {@link setRtt}. */
100
+ Object.defineProperty(this, "rttMs", {
101
+ enumerable: true,
102
+ configurable: true,
103
+ writable: true,
104
+ value: constants_1.kDefaultRttMs
105
+ });
106
+ /** send_side AIMD (GoogCc uses send-side). */
107
+ Object.defineProperty(this, "sendSide", {
108
+ enumerable: true,
109
+ configurable: true,
110
+ writable: true,
111
+ value: true
112
+ });
113
+ Object.defineProperty(this, "noBitrateIncreaseInAlr", {
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true,
117
+ value: false
118
+ });
119
+ /**
120
+ * pin `network_estimate_` (optional). Unset → ClampBitrate ignores NSE.
121
+ * `use_current_estimate_as_min_upper_bound_` default true (`c_upper`).
122
+ */
123
+ Object.defineProperty(this, "networkUpperBps", {
124
+ enumerable: true,
125
+ configurable: true,
126
+ writable: true,
127
+ value: void 0
128
+ });
129
+ Object.defineProperty(this, "networkLowerBps", {
130
+ enumerable: true,
131
+ configurable: true,
132
+ writable: true,
133
+ value: void 0
134
+ });
135
+ Object.defineProperty(this, "useCurrentEstimateAsMinUpperBound", {
136
+ enumerable: true,
137
+ configurable: true,
138
+ writable: true,
139
+ value: true
140
+ });
141
+ }
142
+ reset(startBps = constants_1.kDefaultStartBitrateBps) {
143
+ this.minConfiguredBps = constants_1.kMinBitrateBps;
144
+ this.maxConfiguredBps = constants_1.kMaxBitrateBps;
145
+ this.currentBitrateBps = clamp(startBps, this.minConfiguredBps, this.maxConfiguredBps);
146
+ this.latestEstimatedThroughputBps = this.currentBitrateBps;
147
+ // Full re-init (not pin Reset which only clears estimate).
148
+ this.linkCapacity.resetAll();
149
+ this.rateControlState = "hold";
150
+ this.timeLastBitrateChangeMs = Number.NEGATIVE_INFINITY;
151
+ this.timeLastBitrateDecreaseMs = Number.NEGATIVE_INFINITY;
152
+ this.timeFirstThroughputEstimateMs = Number.NEGATIVE_INFINITY;
153
+ this.bitrateIsInitialized = startBps > 0;
154
+ this.inAlr = false;
155
+ this.rttMs = constants_1.kDefaultRttMs;
156
+ this.networkUpperBps = undefined;
157
+ this.networkLowerBps = undefined;
158
+ }
159
+ setStartBitrate(startBps) {
160
+ this.currentBitrateBps = clamp(startBps, this.minConfiguredBps, this.maxConfiguredBps);
161
+ this.latestEstimatedThroughputBps = this.currentBitrateBps;
162
+ this.bitrateIsInitialized = true;
163
+ }
164
+ setMinBitrate(minBps) {
165
+ this.minConfiguredBps = Math.max(0, minBps);
166
+ this.currentBitrateBps = Math.max(this.minConfiguredBps, this.currentBitrateBps);
167
+ }
168
+ /**
169
+ * State-preserving estimate update (pin `AimdRateControl::SetEstimate`).
170
+ * Used for valid probe results — does not wipe RTT or link-capacity history.
171
+ */
172
+ setEstimate(bitrateBps, atTimeMs) {
173
+ this.bitrateIsInitialized = true;
174
+ const prev = this.currentBitrateBps;
175
+ this.currentBitrateBps = this.clampBitrate(bitrateBps);
176
+ this.timeLastBitrateChangeMs = atTimeMs;
177
+ if (this.currentBitrateBps < prev) {
178
+ this.timeLastBitrateDecreaseMs = atTimeMs;
179
+ }
180
+ }
181
+ /**
182
+ * pin `AimdRateControl::SetRtt` — RTCP / network-controller RTT only.
183
+ * No clamp to 2000ms; TimeToReduceFurther clamps to [10, 200] ms internally.
184
+ */
185
+ setRtt(rttMs) {
186
+ if (Number.isFinite(rttMs) && rttMs > 0) {
187
+ this.rttMs = rttMs;
188
+ }
189
+ }
190
+ get rtt() {
191
+ return this.rttMs;
192
+ }
193
+ get targetBitrateBps() {
194
+ return this.currentBitrateBps;
195
+ }
196
+ get controlState() {
197
+ return this.rateControlState;
198
+ }
199
+ setInApplicationLimitedRegion(inAlr) {
200
+ this.inAlr = inAlr;
201
+ }
202
+ /**
203
+ * pin `AimdRateControl::SetNetworkStateEstimate`.
204
+ * Non-finite / non-positive upper clears the estimate.
205
+ */
206
+ setNetworkStateEstimate(linkCapacityUpperBps, linkCapacityLowerBps = 0) {
207
+ if (!Number.isFinite(linkCapacityUpperBps) || linkCapacityUpperBps <= 0) {
208
+ this.networkUpperBps = undefined;
209
+ this.networkLowerBps = undefined;
210
+ return;
211
+ }
212
+ this.networkUpperBps = linkCapacityUpperBps;
213
+ this.networkLowerBps =
214
+ Number.isFinite(linkCapacityLowerBps) && linkCapacityLowerBps > 0
215
+ ? linkCapacityLowerBps
216
+ : undefined;
217
+ }
218
+ validEstimate() {
219
+ return this.bitrateIsInitialized;
220
+ }
221
+ /**
222
+ * @param usage overuse detector state
223
+ * @param acknowledgedBitrateBps estimated throughput R_hat (acked bitrate)
224
+ * @param nowMs feedback / wall clock ms
225
+ */
226
+ update(usage, acknowledgedBitrateBps, nowMs) {
227
+ // pin: initialize from throughput after 5s of samples (we still accept
228
+ // explicit setStartBitrate / setEstimate earlier).
229
+ if (!this.bitrateIsInitialized) {
230
+ const kInitializationTimeMs = 5000;
231
+ if (!Number.isFinite(this.timeFirstThroughputEstimateMs) ||
232
+ this.timeFirstThroughputEstimateMs < 0) {
233
+ if (acknowledgedBitrateBps > 0) {
234
+ this.timeFirstThroughputEstimateMs = nowMs;
235
+ }
236
+ }
237
+ else if (nowMs - this.timeFirstThroughputEstimateMs > kInitializationTimeMs &&
238
+ acknowledgedBitrateBps > 0) {
239
+ this.currentBitrateBps = acknowledgedBitrateBps;
240
+ this.bitrateIsInitialized = true;
241
+ }
242
+ }
243
+ // pin DelayBasedBwe::MaybeUpdateEstimate gates overuse updates with
244
+ // TimeToReduceFurther / InitialTimeToReduceFurther before calling Update.
245
+ if (usage === "overuse") {
246
+ if (acknowledgedBitrateBps > 0) {
247
+ if (this.bitrateIsInitialized &&
248
+ !this.timeToReduceFurther(nowMs, acknowledgedBitrateBps)) {
249
+ return this.currentBitrateBps;
250
+ }
251
+ }
252
+ else if (this.bitrateIsInitialized) {
253
+ if (!this.initialTimeToReduceFurther(nowMs)) {
254
+ return this.currentBitrateBps;
255
+ }
256
+ // No throughput yet: reduce by 50% (pin InitialTimeToReduceFurther path).
257
+ this.setEstimate(this.currentBitrateBps / 2, nowMs);
258
+ return this.currentBitrateBps;
259
+ }
260
+ }
261
+ this.changeBitrate(usage, acknowledgedBitrateBps, nowMs);
262
+ return this.currentBitrateBps;
263
+ }
264
+ /**
265
+ * pin `TimeToReduceFurther`:
266
+ * - allow after clamp(rtt, 10ms, 200ms) since last bitrate **change**
267
+ * - or when estimated_throughput < 0.5 * LatestEstimate
268
+ */
269
+ timeToReduceFurther(nowMs, estimatedThroughputBps) {
270
+ const reductionIntervalMs = Math.min(200, Math.max(10, this.rttMs));
271
+ // pin: time_last_bitrate_change_ starts MinusInfinity → first reduce always OK
272
+ if (!Number.isFinite(this.timeLastBitrateChangeMs) ||
273
+ nowMs - this.timeLastBitrateChangeMs >= reductionIntervalMs) {
274
+ return true;
275
+ }
276
+ if (this.bitrateIsInitialized) {
277
+ const threshold = this.currentBitrateBps * constants_1.kThroughputLowerFraction;
278
+ return estimatedThroughputBps > 0 && estimatedThroughputBps < threshold;
279
+ }
280
+ return false;
281
+ }
282
+ /** pin `InitialTimeToReduceFurther`. */
283
+ initialTimeToReduceFurther(nowMs) {
284
+ return (this.bitrateIsInitialized &&
285
+ this.timeToReduceFurther(nowMs, this.currentBitrateBps / 2 - 1));
286
+ }
287
+ /**
288
+ * pin `GetNearMaxIncreaseRateBpsPerSecond`:
289
+ * response_time = (rtt + 100ms) * 2; min increase 4000 bps/s.
290
+ */
291
+ getNearMaxIncreaseRateBpsPerSecond() {
292
+ const frameIntervalSec = 1 / 30;
293
+ const frameSizeBits = this.currentBitrateBps * frameIntervalSec;
294
+ const packetSizeBits = 1200 * 8;
295
+ const packetsPerFrame = Math.max(1, Math.ceil(frameSizeBits / packetSizeBits));
296
+ const avgPacketSizeBits = frameSizeBits / packetsPerFrame;
297
+ // Approximate over-use estimator delay to 100 ms; double for response time.
298
+ const responseTimeSec = ((this.rttMs + constants_1.kReactionTimeMs) * 2) / 1000;
299
+ const increaseRate = responseTimeSec > 0 ? avgPacketSizeBits / responseTimeSec : 4000;
300
+ return Math.max(4000, increaseRate);
301
+ }
302
+ changeBitrate(usage, estimatedThroughputBps, nowMs) {
303
+ let newBitrate;
304
+ let estimatedThroughput = estimatedThroughputBps > 0
305
+ ? estimatedThroughputBps
306
+ : this.latestEstimatedThroughputBps;
307
+ if (estimatedThroughputBps > 0) {
308
+ this.latestEstimatedThroughputBps = estimatedThroughputBps;
309
+ estimatedThroughput = estimatedThroughputBps;
310
+ }
311
+ // An over-use always triggers a reduce path even before first estimate.
312
+ if (!this.bitrateIsInitialized && usage !== "overuse") {
313
+ return;
314
+ }
315
+ this.changeState(usage, nowMs);
316
+ switch (this.rateControlState) {
317
+ case "hold":
318
+ break;
319
+ case "increase": {
320
+ if (estimatedThroughput > this.linkCapacity.upperBoundBps()) {
321
+ this.linkCapacity.reset();
322
+ }
323
+ // pin: 1.5 * throughput + 10 kbps
324
+ let increaseLimit = 1.5 * estimatedThroughput + 10000;
325
+ if (this.sendSide && this.inAlr && this.noBitrateIncreaseInAlr) {
326
+ increaseLimit = this.currentBitrateBps;
327
+ }
328
+ if (this.currentBitrateBps < increaseLimit) {
329
+ let increased;
330
+ if (this.linkCapacity.hasEstimate()) {
331
+ const additive = this.additiveRateIncrease(nowMs, this.timeLastBitrateChangeMs);
332
+ increased = this.currentBitrateBps + additive;
333
+ }
334
+ else {
335
+ const multi = this.multiplicativeRateIncrease(nowMs, this.timeLastBitrateChangeMs, this.currentBitrateBps);
336
+ increased = this.currentBitrateBps + multi;
337
+ }
338
+ newBitrate = Math.min(increased, increaseLimit);
339
+ }
340
+ this.timeLastBitrateChangeMs = nowMs;
341
+ break;
342
+ }
343
+ case "decrease": {
344
+ // pin: estimated_throughput * beta, then −5 kbps if above 5 kbps
345
+ let decreased = estimatedThroughput * this.beta;
346
+ if (decreased > 5000) {
347
+ decreased -= 5000;
348
+ }
349
+ if (decreased > this.currentBitrateBps) {
350
+ if (this.linkCapacity.hasEstimate()) {
351
+ decreased = this.beta * this.linkCapacity.estimateBps();
352
+ }
353
+ }
354
+ if (decreased < this.currentBitrateBps) {
355
+ newBitrate = decreased;
356
+ }
357
+ if (this.bitrateIsInitialized &&
358
+ estimatedThroughput < this.currentBitrateBps) {
359
+ // last_decrease_ tracked in pin; not required for external API
360
+ }
361
+ if (estimatedThroughput < this.linkCapacity.lowerBoundBps()) {
362
+ this.linkCapacity.reset();
363
+ }
364
+ this.bitrateIsInitialized = true;
365
+ this.linkCapacity.onOveruseDetected(estimatedThroughput);
366
+ // Stay on hold until the pipes are cleared.
367
+ this.rateControlState = "hold";
368
+ this.timeLastBitrateChangeMs = nowMs;
369
+ this.timeLastBitrateDecreaseMs = nowMs;
370
+ break;
371
+ }
372
+ }
373
+ this.currentBitrateBps = this.clampBitrate(newBitrate !== undefined ? newBitrate : this.currentBitrateBps);
374
+ }
375
+ changeState(usage, nowMs) {
376
+ switch (usage) {
377
+ case "normal":
378
+ if (this.rateControlState === "hold") {
379
+ this.timeLastBitrateChangeMs = nowMs;
380
+ this.rateControlState = "increase";
381
+ }
382
+ break;
383
+ case "overuse":
384
+ if (this.rateControlState !== "decrease") {
385
+ this.rateControlState = "decrease";
386
+ }
387
+ break;
388
+ case "underuse":
389
+ this.rateControlState = "hold";
390
+ break;
391
+ }
392
+ }
393
+ multiplicativeRateIncrease(atTimeMs, lastTimeMs, currentBitrateBps) {
394
+ let alpha = constants_1.kMultiplicativeIncreaseFactor;
395
+ if (Number.isFinite(lastTimeMs) && lastTimeMs > Number.NEGATIVE_INFINITY) {
396
+ const timeSinceSec = Math.max(0, (atTimeMs - lastTimeMs) / 1000);
397
+ alpha = constants_1.kMultiplicativeIncreaseFactor ** Math.min(timeSinceSec, 1.0);
398
+ }
399
+ // max(current * (alpha - 1), 1000 bps)
400
+ return Math.max(currentBitrateBps * (alpha - 1.0), 1000);
401
+ }
402
+ additiveRateIncrease(atTimeMs, lastTimeMs) {
403
+ const timePeriodSec = Number.isFinite(lastTimeMs) && lastTimeMs > Number.NEGATIVE_INFINITY
404
+ ? Math.max(0, (atTimeMs - lastTimeMs) / 1000)
405
+ : 0;
406
+ return this.getNearMaxIncreaseRateBpsPerSecond() * timePeriodSec;
407
+ }
408
+ clampBitrate(newBitrateBps) {
409
+ let next = newBitrateBps;
410
+ // pin ClampBitrate: disable_estimate_bounded_increase_ default off.
411
+ if (this.networkUpperBps !== undefined && this.networkUpperBps > 0) {
412
+ const upper = this.useCurrentEstimateAsMinUpperBound
413
+ ? Math.max(this.networkUpperBps, this.currentBitrateBps)
414
+ : this.networkUpperBps;
415
+ next = Math.min(upper, next);
416
+ }
417
+ if (this.networkLowerBps !== undefined &&
418
+ this.networkLowerBps > 0 &&
419
+ next < this.currentBitrateBps) {
420
+ next = Math.min(this.currentBitrateBps, Math.max(next, this.networkLowerBps * this.beta));
421
+ }
422
+ return Math.max(next, this.minConfiguredBps);
423
+ }
424
+ }
425
+ exports.AimdRateControl = AimdRateControl;
426
+ function clamp(bps, minBps, maxBps) {
427
+ return Math.min(Math.max(Math.round(bps), minBps), maxBps);
428
+ }
429
+ //# sourceMappingURL=aimdRateControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aimdRateControl.js","sourceRoot":"","sources":["../../../../../../../src/media/sender/estimators/gcc/aimdRateControl.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,2CASqB;AACrB,mEAAgE;AAKhE;;;;;;;;;GASG;AACH,MAAa,eAAe;IAA5B;QACU;;;;mBAAmB,0BAAc;WAAC;QAClC;;;;mBAAmB,0BAAc;WAAC;QAClC;;;;mBAAoB,mCAAuB;WAAC;QAC5C;;;;mBAA+B,mCAAuB;WAAC;QAC9C;;;;mBAAe,IAAI,6CAAqB,EAAE;WAAC;QACpD;;;;mBAAqC,MAAM;WAAC;QACpD,qEAAqE;QAC7D;;;;mBAA0B,MAAM,CAAC,iBAAiB;WAAC;QACnD;;;;mBAA4B,MAAM,CAAC,iBAAiB;WAAC;QACrD;;;;mBAAgC,MAAM,CAAC,iBAAiB;WAAC;QACzD;;;;mB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Ac,EAAE,MAAc;IACxD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["/*!\n * Portions of this file are ported from libwebrtc\n * (https://webrtc.googlesource.com/src, commit 0fda16159e33adf59c71a7ad1173dcbe5a632102).\n * Copyright (c) 2011, The WebRTC project authors. All rights reserved.\n * Use of that source is governed by a BSD-style license and an additional\n * patent grant; both are reproduced in THIRD_PARTY_LICENSES_LIBWEBRTC.txt\n * (shipped with this package).\n */\nimport {\n kBeta,\n kDefaultRttMs,\n kDefaultStartBitrateBps,\n kMaxBitrateBps,\n kMinBitrateBps,\n kMultiplicativeIncreaseFactor,\n kReactionTimeMs,\n kThroughputLowerFraction,\n} from \"./constants\";\nimport { LinkCapacityEstimator } from \"./linkCapacityEstimator\";\nimport type { BandwidthUsage } from \"./overuseDetector\";\n\ntype RateControlState = \"hold\" | \"increase\" | \"decrease\";\n\n/**\n * AIMD rate controller for the delay-based estimate (pin\n * `modules/remote_bitrate_estimator/aimd_rate_control.{h,cc}`).\n *\n * Ports ChangeState / ChangeBitrate / MultiplicativeRateIncrease /\n * AdditiveRateIncrease / TimeToReduceFurther / GetNearMaxIncreaseRate.\n *\n * RTT is **only** via {@link setRtt} (RTCP / OnRoundTripTimeUpdate path) —\n * never from TWCC propagation RTT / RttBasedBackoff.\n */\nexport class AimdRateControl {\n private minConfiguredBps = kMinBitrateBps;\n private maxConfiguredBps = kMaxBitrateBps;\n private currentBitrateBps = kDefaultStartBitrateBps;\n private latestEstimatedThroughputBps = kDefaultStartBitrateBps;\n private readonly linkCapacity = new LinkCapacityEstimator();\n private rateControlState: RateControlState = \"hold\";\n /** Pin `time_last_bitrate_change_` — used by TimeToReduceFurther. */\n private timeLastBitrateChangeMs = Number.NEGATIVE_INFINITY;\n private timeLastBitrateDecreaseMs = Number.NEGATIVE_INFINITY;\n private timeFirstThroughputEstimateMs = Number.NEGATIVE_INFINITY;\n private bitrateIsInitialized = false;\n private readonly beta = kBeta;\n private inAlr = false;\n /** Default 200ms (pin kDefaultRtt). Updated only via {@link setRtt}. */\n private rttMs = kDefaultRttMs;\n /** send_side AIMD (GoogCc uses send-side). */\n private readonly sendSide = true;\n private readonly noBitrateIncreaseInAlr = false;\n /**\n * pin `network_estimate_` (optional). Unset → ClampBitrate ignores NSE.\n * `use_current_estimate_as_min_upper_bound_` default true (`c_upper`).\n */\n private networkUpperBps: number | undefined;\n private networkLowerBps: number | undefined;\n private readonly useCurrentEstimateAsMinUpperBound = true;\n\n reset(startBps = kDefaultStartBitrateBps) {\n this.minConfiguredBps = kMinBitrateBps;\n this.maxConfiguredBps = kMaxBitrateBps;\n this.currentBitrateBps = clamp(\n startBps,\n this.minConfiguredBps,\n this.maxConfiguredBps,\n );\n this.latestEstimatedThroughputBps = this.currentBitrateBps;\n // Full re-init (not pin Reset which only clears estimate).\n this.linkCapacity.resetAll();\n this.rateControlState = \"hold\";\n this.timeLastBitrateChangeMs = Number.NEGATIVE_INFINITY;\n this.timeLastBitrateDecreaseMs = Number.NEGATIVE_INFINITY;\n this.timeFirstThroughputEstimateMs = Number.NEGATIVE_INFINITY;\n this.bitrateIsInitialized = startBps > 0;\n this.inAlr = false;\n this.rttMs = kDefaultRttMs;\n this.networkUpperBps = undefined;\n this.networkLowerBps = undefined;\n }\n\n setStartBitrate(startBps: number) {\n this.currentBitrateBps = clamp(\n startBps,\n this.minConfiguredBps,\n this.maxConfiguredBps,\n );\n this.latestEstimatedThroughputBps = this.currentBitrateBps;\n this.bitrateIsInitialized = true;\n }\n\n setMinBitrate(minBps: number) {\n this.minConfiguredBps = Math.max(0, minBps);\n this.currentBitrateBps = Math.max(\n this.minConfiguredBps,\n this.currentBitrateBps,\n );\n }\n\n /**\n * State-preserving estimate update (pin `AimdRateControl::SetEstimate`).\n * Used for valid probe results — does not wipe RTT or link-capacity history.\n */\n setEstimate(bitrateBps: number, atTimeMs: number) {\n this.bitrateIsInitialized = true;\n const prev = this.currentBitrateBps;\n this.currentBitrateBps = this.clampBitrate(bitrateBps);\n this.timeLastBitrateChangeMs = atTimeMs;\n if (this.currentBitrateBps < prev) {\n this.timeLastBitrateDecreaseMs = atTimeMs;\n }\n }\n\n /**\n * pin `AimdRateControl::SetRtt` — RTCP / network-controller RTT only.\n * No clamp to 2000ms; TimeToReduceFurther clamps to [10, 200] ms internally.\n */\n setRtt(rttMs: number) {\n if (Number.isFinite(rttMs) && rttMs > 0) {\n this.rttMs = rttMs;\n }\n }\n\n get rtt(): number {\n return this.rttMs;\n }\n\n get targetBitrateBps() {\n return this.currentBitrateBps;\n }\n\n get controlState(): RateControlState {\n return this.rateControlState;\n }\n\n setInApplicationLimitedRegion(inAlr: boolean) {\n this.inAlr = inAlr;\n }\n\n /**\n * pin `AimdRateControl::SetNetworkStateEstimate`.\n * Non-finite / non-positive upper clears the estimate.\n */\n setNetworkStateEstimate(\n linkCapacityUpperBps: number,\n linkCapacityLowerBps = 0,\n ): void {\n if (!Number.isFinite(linkCapacityUpperBps) || linkCapacityUpperBps <= 0) {\n this.networkUpperBps = undefined;\n this.networkLowerBps = undefined;\n return;\n }\n this.networkUpperBps = linkCapacityUpperBps;\n this.networkLowerBps =\n Number.isFinite(linkCapacityLowerBps) && linkCapacityLowerBps > 0\n ? linkCapacityLowerBps\n : undefined;\n }\n\n validEstimate(): boolean {\n return this.bitrateIsInitialized;\n }\n\n /**\n * @param usage overuse detector state\n * @param acknowledgedBitrateBps estimated throughput R_hat (acked bitrate)\n * @param nowMs feedback / wall clock ms\n */\n update(\n usage: BandwidthUsage,\n acknowledgedBitrateBps: number,\n nowMs: number,\n ): number {\n // pin: initialize from throughput after 5s of samples (we still accept\n // explicit setStartBitrate / setEstimate earlier).\n if (!this.bitrateIsInitialized) {\n const kInitializationTimeMs = 5_000;\n if (\n !Number.isFinite(this.timeFirstThroughputEstimateMs) ||\n this.timeFirstThroughputEstimateMs < 0\n ) {\n if (acknowledgedBitrateBps > 0) {\n this.timeFirstThroughputEstimateMs = nowMs;\n }\n } else if (\n nowMs - this.timeFirstThroughputEstimateMs > kInitializationTimeMs &&\n acknowledgedBitrateBps > 0\n ) {\n this.currentBitrateBps = acknowledgedBitrateBps;\n this.bitrateIsInitialized = true;\n }\n }\n\n // pin DelayBasedBwe::MaybeUpdateEstimate gates overuse updates with\n // TimeToReduceFurther / InitialTimeToReduceFurther before calling Update.\n if (usage === \"overuse\") {\n if (acknowledgedBitrateBps > 0) {\n if (\n this.bitrateIsInitialized &&\n !this.timeToReduceFurther(nowMs, acknowledgedBitrateBps)\n ) {\n return this.currentBitrateBps;\n }\n } else if (this.bitrateIsInitialized) {\n if (!this.initialTimeToReduceFurther(nowMs)) {\n return this.currentBitrateBps;\n }\n // No throughput yet: reduce by 50% (pin InitialTimeToReduceFurther path).\n this.setEstimate(this.currentBitrateBps / 2, nowMs);\n return this.currentBitrateBps;\n }\n }\n\n this.changeBitrate(usage, acknowledgedBitrateBps, nowMs);\n return this.currentBitrateBps;\n }\n\n /**\n * pin `TimeToReduceFurther`:\n * - allow after clamp(rtt, 10ms, 200ms) since last bitrate **change**\n * - or when estimated_throughput < 0.5 * LatestEstimate\n */\n timeToReduceFurther(nowMs: number, estimatedThroughputBps: number): boolean {\n const reductionIntervalMs = Math.min(200, Math.max(10, this.rttMs));\n // pin: time_last_bitrate_change_ starts MinusInfinity → first reduce always OK\n if (\n !Number.isFinite(this.timeLastBitrateChangeMs) ||\n nowMs - this.timeLastBitrateChangeMs >= reductionIntervalMs\n ) {\n return true;\n }\n if (this.bitrateIsInitialized) {\n const threshold = this.currentBitrateBps * kThroughputLowerFraction;\n return estimatedThroughputBps > 0 && estimatedThroughputBps < threshold;\n }\n return false;\n }\n\n /** pin `InitialTimeToReduceFurther`. */\n initialTimeToReduceFurther(nowMs: number): boolean {\n return (\n this.bitrateIsInitialized &&\n this.timeToReduceFurther(nowMs, this.currentBitrateBps / 2 - 1)\n );\n }\n\n /**\n * pin `GetNearMaxIncreaseRateBpsPerSecond`:\n * response_time = (rtt + 100ms) * 2; min increase 4000 bps/s.\n */\n getNearMaxIncreaseRateBpsPerSecond(): number {\n const frameIntervalSec = 1 / 30;\n const frameSizeBits = this.currentBitrateBps * frameIntervalSec;\n const packetSizeBits = 1200 * 8;\n const packetsPerFrame = Math.max(\n 1,\n Math.ceil(frameSizeBits / packetSizeBits),\n );\n const avgPacketSizeBits = frameSizeBits / packetsPerFrame;\n // Approximate over-use estimator delay to 100 ms; double for response time.\n const responseTimeSec = ((this.rttMs + kReactionTimeMs) * 2) / 1000;\n const increaseRate =\n responseTimeSec > 0 ? avgPacketSizeBits / responseTimeSec : 4000;\n return Math.max(4000, increaseRate);\n }\n\n private changeBitrate(\n usage: BandwidthUsage,\n estimatedThroughputBps: number,\n nowMs: number,\n ) {\n let newBitrate: number | undefined;\n let estimatedThroughput =\n estimatedThroughputBps > 0\n ? estimatedThroughputBps\n : this.latestEstimatedThroughputBps;\n if (estimatedThroughputBps > 0) {\n this.latestEstimatedThroughputBps = estimatedThroughputBps;\n estimatedThroughput = estimatedThroughputBps;\n }\n\n // An over-use always triggers a reduce path even before first estimate.\n if (!this.bitrateIsInitialized && usage !== \"overuse\") {\n return;\n }\n\n this.changeState(usage, nowMs);\n\n switch (this.rateControlState) {\n case \"hold\":\n break;\n\n case \"increase\": {\n if (estimatedThroughput > this.linkCapacity.upperBoundBps()) {\n this.linkCapacity.reset();\n }\n\n // pin: 1.5 * throughput + 10 kbps\n let increaseLimit = 1.5 * estimatedThroughput + 10_000;\n if (this.sendSide && this.inAlr && this.noBitrateIncreaseInAlr) {\n increaseLimit = this.currentBitrateBps;\n }\n\n if (this.currentBitrateBps < increaseLimit) {\n let increased: number;\n if (this.linkCapacity.hasEstimate()) {\n const additive = this.additiveRateIncrease(\n nowMs,\n this.timeLastBitrateChangeMs,\n );\n increased = this.currentBitrateBps + additive;\n } else {\n const multi = this.multiplicativeRateIncrease(\n nowMs,\n this.timeLastBitrateChangeMs,\n this.currentBitrateBps,\n );\n increased = this.currentBitrateBps + multi;\n }\n newBitrate = Math.min(increased, increaseLimit);\n }\n this.timeLastBitrateChangeMs = nowMs;\n break;\n }\n\n case \"decrease\": {\n // pin: estimated_throughput * beta, then −5 kbps if above 5 kbps\n let decreased = estimatedThroughput * this.beta;\n if (decreased > 5_000) {\n decreased -= 5_000;\n }\n\n if (decreased > this.currentBitrateBps) {\n if (this.linkCapacity.hasEstimate()) {\n decreased = this.beta * this.linkCapacity.estimateBps();\n }\n }\n\n if (decreased < this.currentBitrateBps) {\n newBitrate = decreased;\n }\n\n if (\n this.bitrateIsInitialized &&\n estimatedThroughput < this.currentBitrateBps\n ) {\n // last_decrease_ tracked in pin; not required for external API\n }\n if (estimatedThroughput < this.linkCapacity.lowerBoundBps()) {\n this.linkCapacity.reset();\n }\n\n this.bitrateIsInitialized = true;\n this.linkCapacity.onOveruseDetected(estimatedThroughput);\n // Stay on hold until the pipes are cleared.\n this.rateControlState = \"hold\";\n this.timeLastBitrateChangeMs = nowMs;\n this.timeLastBitrateDecreaseMs = nowMs;\n break;\n }\n }\n\n this.currentBitrateBps = this.clampBitrate(\n newBitrate !== undefined ? newBitrate : this.currentBitrateBps,\n );\n }\n\n private changeState(usage: BandwidthUsage, nowMs: number) {\n switch (usage) {\n case \"normal\":\n if (this.rateControlState === \"hold\") {\n this.timeLastBitrateChangeMs = nowMs;\n this.rateControlState = \"increase\";\n }\n break;\n case \"overuse\":\n if (this.rateControlState !== \"decrease\") {\n this.rateControlState = \"decrease\";\n }\n break;\n case \"underuse\":\n this.rateControlState = \"hold\";\n break;\n }\n }\n\n private multiplicativeRateIncrease(\n atTimeMs: number,\n lastTimeMs: number,\n currentBitrateBps: number,\n ): number {\n let alpha = kMultiplicativeIncreaseFactor;\n if (Number.isFinite(lastTimeMs) && lastTimeMs > Number.NEGATIVE_INFINITY) {\n const timeSinceSec = Math.max(0, (atTimeMs - lastTimeMs) / 1000);\n alpha = kMultiplicativeIncreaseFactor ** Math.min(timeSinceSec, 1.0);\n }\n // max(current * (alpha - 1), 1000 bps)\n return Math.max(currentBitrateBps * (alpha - 1.0), 1000);\n }\n\n private additiveRateIncrease(atTimeMs: number, lastTimeMs: number): number {\n const timePeriodSec =\n Number.isFinite(lastTimeMs) && lastTimeMs > Number.NEGATIVE_INFINITY\n ? Math.max(0, (atTimeMs - lastTimeMs) / 1000)\n : 0;\n return this.getNearMaxIncreaseRateBpsPerSecond() * timePeriodSec;\n }\n\n private clampBitrate(newBitrateBps: number): number {\n let next = newBitrateBps;\n // pin ClampBitrate: disable_estimate_bounded_increase_ default off.\n if (this.networkUpperBps !== undefined && this.networkUpperBps > 0) {\n const upper = this.useCurrentEstimateAsMinUpperBound\n ? Math.max(this.networkUpperBps, this.currentBitrateBps)\n : this.networkUpperBps;\n next = Math.min(upper, next);\n }\n if (\n this.networkLowerBps !== undefined &&\n this.networkLowerBps > 0 &&\n next < this.currentBitrateBps\n ) {\n next = Math.min(\n this.currentBitrateBps,\n Math.max(next, this.networkLowerBps * this.beta),\n );\n }\n return Math.max(next, this.minConfiguredBps);\n }\n}\n\nfunction clamp(bps: number, minBps: number, maxBps: number) {\n return Math.min(Math.max(Math.round(bps), minBps), maxBps);\n}\n"]}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * pin `modules/congestion_controller/goog_cc/alr_detector`.
3
+ *
4
+ * ALR starts when the send budget ratio exceeds
5
+ * {@link kAlrStartBudgetLevelRatio} (underusing) and ends when it falls below
6
+ * {@link kAlrStopBudgetLevelRatio}. Budget target is estimate ×
7
+ * {@link kAlrBandwidthUsageRatio}.
8
+ *
9
+ * Start time uses the sender clock (`sendMs`), matching pin Timestamp domain.
10
+ */
11
+ export declare class AlrDetector {
12
+ private lastSendMs;
13
+ private startedMs;
14
+ private readonly budget;
15
+ reset(): void;
16
+ onBytesSent(bytes: number, sendMs: number): void;
17
+ setEstimatedBitrate(bps: number): void;
18
+ get inAlr(): boolean;
19
+ /** Sender-clock time when the current ALR region started, if any. */
20
+ get startMs(): number | undefined;
21
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlrDetector = void 0;
4
+ /*!
5
+ * Portions of this file are ported from libwebrtc
6
+ * (https://webrtc.googlesource.com/src, commit 0fda16159e33adf59c71a7ad1173dcbe5a632102).
7
+ * Copyright (c) 2011, The WebRTC project authors. All rights reserved.
8
+ * Use of that source is governed by a BSD-style license and an additional
9
+ * patent grant; both are reproduced in THIRD_PARTY_LICENSES_LIBWEBRTC.txt
10
+ * (shipped with this package).
11
+ */
12
+ const constants_1 = require("./constants");
13
+ const intervalBudget_1 = require("./intervalBudget");
14
+ /**
15
+ * pin `modules/congestion_controller/goog_cc/alr_detector`.
16
+ *
17
+ * ALR starts when the send budget ratio exceeds
18
+ * {@link kAlrStartBudgetLevelRatio} (underusing) and ends when it falls below
19
+ * {@link kAlrStopBudgetLevelRatio}. Budget target is estimate ×
20
+ * {@link kAlrBandwidthUsageRatio}.
21
+ *
22
+ * Start time uses the sender clock (`sendMs`), matching pin Timestamp domain.
23
+ */
24
+ class AlrDetector {
25
+ constructor() {
26
+ Object.defineProperty(this, "lastSendMs", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ Object.defineProperty(this, "startedMs", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "budget", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: new intervalBudget_1.IntervalBudget(true)
43
+ });
44
+ }
45
+ reset() {
46
+ this.lastSendMs = undefined;
47
+ this.startedMs = undefined;
48
+ this.budget.reset();
49
+ }
50
+ onBytesSent(bytes, sendMs) {
51
+ if (!Number.isFinite(sendMs) || bytes < 0)
52
+ return;
53
+ if (this.lastSendMs === undefined) {
54
+ this.lastSendMs = sendMs;
55
+ return;
56
+ }
57
+ const deltaMs = sendMs - this.lastSendMs;
58
+ this.lastSendMs = sendMs;
59
+ this.budget.useBudget(bytes);
60
+ this.budget.increaseBudget(deltaMs);
61
+ const ratio = this.budget.budgetRatio();
62
+ if (ratio > constants_1.kAlrStartBudgetLevelRatio && this.startedMs === undefined) {
63
+ this.startedMs = sendMs;
64
+ }
65
+ else if (ratio < constants_1.kAlrStopBudgetLevelRatio &&
66
+ this.startedMs !== undefined) {
67
+ this.startedMs = undefined;
68
+ }
69
+ }
70
+ setEstimatedBitrate(bps) {
71
+ if (!(bps > 0) || !Number.isFinite(bps))
72
+ return;
73
+ this.budget.setTargetRateKbps((bps * constants_1.kAlrBandwidthUsageRatio) / 1000);
74
+ }
75
+ get inAlr() {
76
+ return this.startedMs !== undefined;
77
+ }
78
+ /** Sender-clock time when the current ALR region started, if any. */
79
+ get startMs() {
80
+ return this.startedMs;
81
+ }
82
+ }
83
+ exports.AlrDetector = AlrDetector;
84
+ //# sourceMappingURL=alrDetector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alrDetector.js","sourceRoot":"","sources":["../../../../../../../src/media/sender/estimators/gcc/alrDetector.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,2CAIqB;AACrB,qDAAkD;AAElD;;;;;;;;;GASG;AACH,MAAa,WAAW;IAAxB;QACU;;;;;WAA+B;QAC/B;;;;;WAA8B;QACrB;;;;mBAAS,IAAI,+BAAc,CAAC,IAAI,CAAC;WAAC;IA0CrD,CAAC;IAxCC,KAAK;QACH,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,WAAW,CAAC,KAAa,EAAE,MAAc;QACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,GAAG,CAAC;YAAE,OAAO;QAClD,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;YACzB,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACxC,IAAI,KAAK,GAAG,qCAAyB,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACtE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QAC1B,CAAC;aAAM,IACL,KAAK,GAAG,oCAAwB;YAChC,IAAI,CAAC,SAAS,KAAK,SAAS,EAC5B,CAAC;YACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,GAAW;QAC7B,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO;QAChD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,GAAG,mCAAuB,CAAC,GAAG,IAAI,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC;IACtC,CAAC;IAED,qEAAqE;IACrE,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AA7CD,kCA6CC","sourcesContent":["/*!\n * Portions of this file are ported from libwebrtc\n * (https://webrtc.googlesource.com/src, commit 0fda16159e33adf59c71a7ad1173dcbe5a632102).\n * Copyright (c) 2011, The WebRTC project authors. All rights reserved.\n * Use of that source is governed by a BSD-style license and an additional\n * patent grant; both are reproduced in THIRD_PARTY_LICENSES_LIBWEBRTC.txt\n * (shipped with this package).\n */\nimport {\n kAlrBandwidthUsageRatio,\n kAlrStartBudgetLevelRatio,\n kAlrStopBudgetLevelRatio,\n} from \"./constants\";\nimport { IntervalBudget } from \"./intervalBudget\";\n\n/**\n * pin `modules/congestion_controller/goog_cc/alr_detector`.\n *\n * ALR starts when the send budget ratio exceeds\n * {@link kAlrStartBudgetLevelRatio} (underusing) and ends when it falls below\n * {@link kAlrStopBudgetLevelRatio}. Budget target is estimate ×\n * {@link kAlrBandwidthUsageRatio}.\n *\n * Start time uses the sender clock (`sendMs`), matching pin Timestamp domain.\n */\nexport class AlrDetector {\n private lastSendMs: number | undefined;\n private startedMs: number | undefined;\n private readonly budget = new IntervalBudget(true);\n\n reset() {\n this.lastSendMs = undefined;\n this.startedMs = undefined;\n this.budget.reset();\n }\n\n onBytesSent(bytes: number, sendMs: number) {\n if (!Number.isFinite(sendMs) || bytes < 0) return;\n if (this.lastSendMs === undefined) {\n this.lastSendMs = sendMs;\n return;\n }\n const deltaMs = sendMs - this.lastSendMs;\n this.lastSendMs = sendMs;\n this.budget.useBudget(bytes);\n this.budget.increaseBudget(deltaMs);\n const ratio = this.budget.budgetRatio();\n if (ratio > kAlrStartBudgetLevelRatio && this.startedMs === undefined) {\n this.startedMs = sendMs;\n } else if (\n ratio < kAlrStopBudgetLevelRatio &&\n this.startedMs !== undefined\n ) {\n this.startedMs = undefined;\n }\n }\n\n setEstimatedBitrate(bps: number) {\n if (!(bps > 0) || !Number.isFinite(bps)) return;\n this.budget.setTargetRateKbps((bps * kAlrBandwidthUsageRatio) / 1000);\n }\n\n get inAlr(): boolean {\n return this.startedMs !== undefined;\n }\n\n /** Sender-clock time when the current ALR region started, if any. */\n get startMs(): number | undefined {\n return this.startedMs;\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import type { LossBasedState } from "./lossBasedBwe";
2
+ import type { BandwidthUsage } from "./overuseDetector";
3
+ /**
4
+ * libwebrtc `BandwidthLimitedCause` (probe_controller.h) — reason the BWE
5
+ * estimate is limited. ProbeController::InitiateProbing uses this to decide
6
+ * whether new probes are forbidden or allowed with a scale cap.
7
+ */
8
+ export type BandwidthLimitedCause = "loss_limited_bwe_increasing" | "loss_limited_bwe" | "delay_based_limited" | "delay_based_limited_delay_increased" | "rtt_based_back_off_high_rtt";
9
+ /**
10
+ * libwebrtc `GetBandwidthLimitedCause` (goog_cc_network_control.cc).
11
+ *
12
+ * | Delay usage | RTT high? | LossBasedState | Cause |
13
+ * | overuse/underuse | * | * | delay_based_limited_delay_increased |
14
+ * | normal | yes | * | rtt_based_back_off_high_rtt |
15
+ * | normal | no | decreasing / increase_using_padding | loss_limited_bwe |
16
+ * | normal | no | increasing | loss_limited_bwe_increasing |
17
+ * | normal | no | delay_based | delay_based_limited |
18
+ *
19
+ * pin maps `kIncreaseUsingPadding` to `kLossLimitedBwe` (probes forbidden).
20
+ * There is no `kHold` state — HOLD is `kDecreasing` + `last_hold_info_`.
21
+ */
22
+ export declare function getBandwidthLimitedCause(usage: BandwidthUsage, isRttAboveLimit: boolean, lossState: LossBasedState): BandwidthLimitedCause;
23
+ /** True when InitiateProbing would return a non-empty cluster list. */
24
+ export declare function isProbeInitiationAllowed(cause: BandwidthLimitedCause): boolean;
25
+ /**
26
+ * Max probe target bitrate for this cause (libwebrtc InitiateProbing switch).
27
+ * - kLossLimitedBweIncreasing → estimated × loss_limited_probe_scale (1.5)
28
+ * - kDelayBasedLimited → no extra cap (only configured max)
29
+ * - forbid causes → 0 (caller should not probe)
30
+ */
31
+ export declare function maxProbeBitrateBps(cause: BandwidthLimitedCause, estimatedBitrateBps: number, configuredMaxBps?: number): number;
32
+ /**
33
+ * RTT above libwebrtc RttBasedBackoff default limit (3s).
34
+ * Call with **CorrectedRtt / propagation RTT** (not raw max feedback RTT).
35
+ * Prefer {@link RttBasedBackoff.isRttAboveLimit} when the helper is available.
36
+ */
37
+ export declare function isRttAboveLimit(rttMs: number, limitMs?: number): boolean;