werift 0.27.0 → 0.28.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 (224) hide show
  1. package/README.md +119 -8
  2. package/lib/common/src/event.d.ts +26 -0
  3. package/lib/common/src/event.js +87 -2
  4. package/lib/common/src/event.js.map +1 -1
  5. package/lib/common/src/network.d.ts +6 -1
  6. package/lib/common/src/network.js +8 -2
  7. package/lib/common/src/network.js.map +1 -1
  8. package/lib/common/src/transport.d.ts +12 -5
  9. package/lib/common/src/transport.js +3 -2
  10. package/lib/common/src/transport.js.map +1 -1
  11. package/lib/dtls/src/alert.d.ts +49 -0
  12. package/lib/dtls/src/alert.js +103 -0
  13. package/lib/dtls/src/alert.js.map +1 -0
  14. package/lib/dtls/src/client.js +15 -1
  15. package/lib/dtls/src/client.js.map +1 -1
  16. package/lib/dtls/src/context/dtls.d.ts +2 -0
  17. package/lib/dtls/src/context/dtls.js +7 -0
  18. package/lib/dtls/src/context/dtls.js.map +1 -1
  19. package/lib/dtls/src/context/transport.d.ts +17 -1
  20. package/lib/dtls/src/context/transport.js +38 -2
  21. package/lib/dtls/src/context/transport.js.map +1 -1
  22. package/lib/dtls/src/flight/client/flight5.js +4 -1
  23. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  24. package/lib/dtls/src/flight/flight.d.ts +5 -0
  25. package/lib/dtls/src/flight/flight.js +10 -1
  26. package/lib/dtls/src/flight/flight.js.map +1 -1
  27. package/lib/dtls/src/flight/server/flight6.js +4 -1
  28. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  29. package/lib/dtls/src/index.d.ts +3 -1
  30. package/lib/dtls/src/index.js +10 -1
  31. package/lib/dtls/src/index.js.map +1 -1
  32. package/lib/dtls/src/record/const.d.ts +9 -0
  33. package/lib/dtls/src/record/const.js +9 -1
  34. package/lib/dtls/src/record/const.js.map +1 -1
  35. package/lib/dtls/src/record/receive.d.ts +6 -0
  36. package/lib/dtls/src/record/receive.js +50 -19
  37. package/lib/dtls/src/record/receive.js.map +1 -1
  38. package/lib/dtls/src/server.js +19 -1
  39. package/lib/dtls/src/server.js.map +1 -1
  40. package/lib/dtls/src/socket.d.ts +134 -2
  41. package/lib/dtls/src/socket.js +322 -6
  42. package/lib/dtls/src/socket.js.map +1 -1
  43. package/lib/ice/src/candidateError.d.ts +155 -0
  44. package/lib/ice/src/candidateError.js +246 -0
  45. package/lib/ice/src/candidateError.js.map +1 -0
  46. package/lib/ice/src/candidateGatherer.d.ts +127 -0
  47. package/lib/ice/src/candidateGatherer.js +745 -0
  48. package/lib/ice/src/candidateGatherer.js.map +1 -0
  49. package/lib/ice/src/consent.d.ts +49 -0
  50. package/lib/ice/src/consent.js +258 -0
  51. package/lib/ice/src/consent.js.map +1 -0
  52. package/lib/ice/src/ice.d.ts +223 -71
  53. package/lib/ice/src/ice.js +873 -975
  54. package/lib/ice/src/ice.js.map +1 -1
  55. package/lib/ice/src/iceBase.d.ts +207 -8
  56. package/lib/ice/src/iceBase.js +94 -31
  57. package/lib/ice/src/iceBase.js.map +1 -1
  58. package/lib/ice/src/index.d.ts +1 -0
  59. package/lib/ice/src/index.js +1 -0
  60. package/lib/ice/src/index.js.map +1 -1
  61. package/lib/ice/src/internal/checkMessages.d.ts +41 -0
  62. package/lib/ice/src/internal/checkMessages.js +63 -0
  63. package/lib/ice/src/internal/checkMessages.js.map +1 -0
  64. package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
  65. package/lib/ice/src/internal/defaultRoute.js +134 -0
  66. package/lib/ice/src/internal/defaultRoute.js.map +1 -0
  67. package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
  68. package/lib/ice/src/internal/hostInterfaces.js +77 -0
  69. package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
  70. package/lib/ice/src/internal/hostPreference.d.ts +24 -0
  71. package/lib/ice/src/internal/hostPreference.js +38 -0
  72. package/lib/ice/src/internal/hostPreference.js.map +1 -0
  73. package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
  74. package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
  75. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
  76. package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
  77. package/lib/ice/src/internal/selectAddresses.js +37 -18
  78. package/lib/ice/src/internal/selectAddresses.js.map +1 -1
  79. package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
  80. package/lib/ice/src/nomination/regularNomination.js +311 -0
  81. package/lib/ice/src/nomination/regularNomination.js.map +1 -0
  82. package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
  83. package/lib/ice/src/nomination/selectionReplacement.js +371 -0
  84. package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
  85. package/lib/ice/src/provisional.d.ts +139 -0
  86. package/lib/ice/src/provisional.js +468 -0
  87. package/lib/ice/src/provisional.js.map +1 -0
  88. package/lib/ice/src/stun/protocol.d.ts +9 -2
  89. package/lib/ice/src/stun/protocol.js +16 -17
  90. package/lib/ice/src/stun/protocol.js.map +1 -1
  91. package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
  92. package/lib/ice/src/stun/tcpProtocol.js +7 -7
  93. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  94. package/lib/ice/src/stun/transaction.js +4 -2
  95. package/lib/ice/src/stun/transaction.js.map +1 -1
  96. package/lib/ice/src/turn/protocol.d.ts +2 -2
  97. package/lib/ice/src/turn/protocol.js +6 -3
  98. package/lib/ice/src/turn/protocol.js.map +1 -1
  99. package/lib/ice/src/types/model.d.ts +16 -5
  100. package/lib/ice/src/types/model.js.map +1 -1
  101. package/lib/ice-server/src/stun/attributes.js +4 -0
  102. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  103. package/lib/ice-server/src/stun/const.d.ts +20 -1
  104. package/lib/ice-server/src/stun/const.js +9 -1
  105. package/lib/ice-server/src/stun/const.js.map +1 -1
  106. package/lib/ice-server/src/stun/message.d.ts +28 -1
  107. package/lib/ice-server/src/stun/message.js +102 -15
  108. package/lib/ice-server/src/stun/message.js.map +1 -1
  109. package/lib/index.mjs +13394 -7732
  110. package/lib/nonstandard/index.mjs +680 -286
  111. package/lib/polyfill/dom.mjs +19605 -14243
  112. package/lib/polyfill/index.mjs +19605 -14243
  113. package/lib/rtp/src/index.d.ts +1 -0
  114. package/lib/rtp/src/index.js +1 -0
  115. package/lib/rtp/src/index.js.map +1 -1
  116. package/lib/rtp/src/rtp/continuity.d.ts +14 -1
  117. package/lib/rtp/src/rtp/continuity.js +24 -4
  118. package/lib/rtp/src/rtp/continuity.js.map +1 -1
  119. package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
  120. package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
  121. package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
  122. package/lib/sctp/src/sctp.d.ts +5 -0
  123. package/lib/sctp/src/sctp.js +81 -47
  124. package/lib/sctp/src/sctp.js.map +1 -1
  125. package/lib/webrtc/src/api/compatibilityOptions.d.ts +33 -0
  126. package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
  127. package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
  128. package/lib/webrtc/src/api/peerConfig.d.ts +348 -34
  129. package/lib/webrtc/src/api/peerConfig.js +90 -24
  130. package/lib/webrtc/src/api/peerConfig.js.map +1 -1
  131. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
  132. package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
  133. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
  134. package/lib/webrtc/src/helper.d.ts +8 -0
  135. package/lib/webrtc/src/helper.js +40 -4
  136. package/lib/webrtc/src/helper.js.map +1 -1
  137. package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
  138. package/lib/webrtc/src/media/codecCompatibility.js +338 -12
  139. package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
  140. package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
  141. package/lib/webrtc/src/media/receiver/nack.js +245 -88
  142. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  143. package/lib/webrtc/src/media/router.d.ts +239 -51
  144. package/lib/webrtc/src/media/router.js +664 -237
  145. package/lib/webrtc/src/media/router.js.map +1 -1
  146. package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
  147. package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
  148. package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
  149. package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
  150. package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
  151. package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
  152. package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
  153. package/lib/webrtc/src/media/routing/routeTable.js +95 -0
  154. package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
  155. package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
  156. package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
  157. package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
  158. package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
  159. package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
  160. package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
  161. package/lib/webrtc/src/media/rtpReceiver.d.ts +222 -0
  162. package/lib/webrtc/src/media/rtpReceiver.js +668 -28
  163. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  164. package/lib/webrtc/src/media/rtpSender.d.ts +7 -0
  165. package/lib/webrtc/src/media/rtpSender.js +9 -3
  166. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  167. package/lib/webrtc/src/media/rtpTransceiver.d.ts +18 -0
  168. package/lib/webrtc/src/media/rtpTransceiver.js +64 -2
  169. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  170. package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
  171. package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
  172. package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
  173. package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
  174. package/lib/webrtc/src/media/sender/senderStats.js +14 -19
  175. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
  176. package/lib/webrtc/src/media/track.d.ts +9 -0
  177. package/lib/webrtc/src/media/track.js +9 -0
  178. package/lib/webrtc/src/media/track.js.map +1 -1
  179. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
  180. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
  181. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
  182. package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
  183. package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
  184. package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
  185. package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
  186. package/lib/webrtc/src/negotiation/transportActivation.js +21 -0
  187. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
  188. package/lib/webrtc/src/negotiationTransaction.d.ts +35 -4
  189. package/lib/webrtc/src/negotiationTransaction.js +111 -8
  190. package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
  191. package/lib/webrtc/src/peerConnection.d.ts +65 -6
  192. package/lib/webrtc/src/peerConnection.js +283 -28
  193. package/lib/webrtc/src/peerConnection.js.map +1 -1
  194. package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
  195. package/lib/webrtc/src/polyfill/globals.js.map +1 -1
  196. package/lib/webrtc/src/polyfill/install.js +2 -0
  197. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  198. package/lib/webrtc/src/sctpManager.js +4 -0
  199. package/lib/webrtc/src/sctpManager.js.map +1 -1
  200. package/lib/webrtc/src/sdp.d.ts +69 -0
  201. package/lib/webrtc/src/sdp.js +139 -14
  202. package/lib/webrtc/src/sdp.js.map +1 -1
  203. package/lib/webrtc/src/sdpManager.d.ts +85 -4
  204. package/lib/webrtc/src/sdpManager.js +214 -14
  205. package/lib/webrtc/src/sdpManager.js.map +1 -1
  206. package/lib/webrtc/src/secureTransportManager.d.ts +38 -1
  207. package/lib/webrtc/src/secureTransportManager.js +82 -7
  208. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  209. package/lib/webrtc/src/transceiverManager.d.ts +82 -4
  210. package/lib/webrtc/src/transceiverManager.js +231 -38
  211. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  212. package/lib/webrtc/src/transport/dtls.d.ts +95 -1
  213. package/lib/webrtc/src/transport/dtls.js +324 -28
  214. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  215. package/lib/webrtc/src/transport/ice.d.ts +61 -4
  216. package/lib/webrtc/src/transport/ice.js +180 -11
  217. package/lib/webrtc/src/transport/ice.js.map +1 -1
  218. package/lib/webrtc/src/transport/sctp.d.ts +23 -0
  219. package/lib/webrtc/src/transport/sctp.js +87 -2
  220. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  221. package/lib/webrtc/src/utils.d.ts +33 -0
  222. package/lib/webrtc/src/utils.js +52 -3
  223. package/lib/webrtc/src/utils.js.map +1 -1
  224. package/package.json +2 -1
@@ -27,6 +27,7 @@ export * from "./rtp/red/packet";
27
27
  export * from "./rtp/rtp";
28
28
  export * from "./rtp/rtx";
29
29
  export * from "./rtp/sendHeaderExtensions";
30
+ export * from "./rtp/timelineRewriter";
30
31
  export * from "./srtp/const";
31
32
  export * from "./srtp/error";
32
33
  export * from "./srtp/replay";
@@ -43,6 +43,7 @@ __exportStar(require("./rtp/red/packet"), exports);
43
43
  __exportStar(require("./rtp/rtp"), exports);
44
44
  __exportStar(require("./rtp/rtx"), exports);
45
45
  __exportStar(require("./rtp/sendHeaderExtensions"), exports);
46
+ __exportStar(require("./rtp/timelineRewriter"), exports);
46
47
  __exportStar(require("./srtp/const"), exports);
47
48
  __exportStar(require("./srtp/error"), exports);
48
49
  __exportStar(require("./srtp/replay"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../rtp/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kBAAgB;AAEhB,mDAAiC;AACjC,0CAAwB;AACxB,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,+DAA6C;AAC7C,oEAAkD;AAClD,mDAAiC;AACjC,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,oDAAkC;AAClC,qEAAmD;AACnD,oDAAkC;AAClC,iEAA+C;AAC/C,iEAA+C;AAC/C,8CAA4B;AAC5B,4CAA0B;AAC1B,mDAAiC;AACjC,wDAAsC;AACtC,mDAAiC;AACjC,gDAA8B;AAC9B,oDAAkC;AAClC,oDAAkC;AAClC,mDAAiC;AACjC,4CAA0B;AAC1B,4CAA0B;AAC1B,6DAA2C;AAC3C,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,+CAA6B;AAC7B,8CAA4B;AAC5B,yCAAuB","sourcesContent":["import \"buffer\";\n\nexport * from \"../../common/src\";\nexport * from \"./codec\";\nexport * from \"./helper\";\nexport * from \"./rtcp/header\";\nexport * from \"./rtcp/psfb\";\nexport * from \"./rtcp/psfb/fullIntraRequest\";\nexport * from \"./rtcp/psfb/pictureLossIndication\";\nexport * from \"./rtcp/psfb/remb\";\nexport * from \"./rtcp/rr\";\nexport * from \"./rtcp/rtcp\";\nexport * from \"./rtcp/rtpfb\";\nexport * from \"./rtcp/rtpfb/nack\";\nexport * from \"./rtcp/rtpfb/transportWideSequence\";\nexport * from \"./rtcp/rtpfb/twcc\";\nexport * from \"./rtcp/rtpfb/twccReceiveTiming\";\nexport * from \"./rtcp/rtpfb/twccReferenceTime\";\nexport * from \"./rtcp/sdes\";\nexport * from \"./rtcp/sr\";\nexport * from \"./rtp/continuity\";\nexport * from \"./rtp/headerExtension\";\nexport * from \"./rtp/mediaClock\";\nexport * from \"./rtp/padding\";\nexport * from \"./rtp/red/encoder\";\nexport * from \"./rtp/red/handler\";\nexport * from \"./rtp/red/packet\";\nexport * from \"./rtp/rtp\";\nexport * from \"./rtp/rtx\";\nexport * from \"./rtp/sendHeaderExtensions\";\nexport * from \"./srtp/const\";\nexport * from \"./srtp/error\";\nexport * from \"./srtp/replay\";\nexport * from \"./srtp/srtcp\";\nexport * from \"./srtp/srtp\";\nexport * from \"./util\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../rtp/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kBAAgB;AAEhB,mDAAiC;AACjC,0CAAwB;AACxB,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,+DAA6C;AAC7C,oEAAkD;AAClD,mDAAiC;AACjC,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,oDAAkC;AAClC,qEAAmD;AACnD,oDAAkC;AAClC,iEAA+C;AAC/C,iEAA+C;AAC/C,8CAA4B;AAC5B,4CAA0B;AAC1B,mDAAiC;AACjC,wDAAsC;AACtC,mDAAiC;AACjC,gDAA8B;AAC9B,oDAAkC;AAClC,oDAAkC;AAClC,mDAAiC;AACjC,4CAA0B;AAC1B,4CAA0B;AAC1B,6DAA2C;AAC3C,yDAAuC;AACvC,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B;AAC9B,+CAA6B;AAC7B,8CAA4B;AAC5B,yCAAuB","sourcesContent":["import \"buffer\";\n\nexport * from \"../../common/src\";\nexport * from \"./codec\";\nexport * from \"./helper\";\nexport * from \"./rtcp/header\";\nexport * from \"./rtcp/psfb\";\nexport * from \"./rtcp/psfb/fullIntraRequest\";\nexport * from \"./rtcp/psfb/pictureLossIndication\";\nexport * from \"./rtcp/psfb/remb\";\nexport * from \"./rtcp/rr\";\nexport * from \"./rtcp/rtcp\";\nexport * from \"./rtcp/rtpfb\";\nexport * from \"./rtcp/rtpfb/nack\";\nexport * from \"./rtcp/rtpfb/transportWideSequence\";\nexport * from \"./rtcp/rtpfb/twcc\";\nexport * from \"./rtcp/rtpfb/twccReceiveTiming\";\nexport * from \"./rtcp/rtpfb/twccReferenceTime\";\nexport * from \"./rtcp/sdes\";\nexport * from \"./rtcp/sr\";\nexport * from \"./rtp/continuity\";\nexport * from \"./rtp/headerExtension\";\nexport * from \"./rtp/mediaClock\";\nexport * from \"./rtp/padding\";\nexport * from \"./rtp/red/encoder\";\nexport * from \"./rtp/red/handler\";\nexport * from \"./rtp/red/packet\";\nexport * from \"./rtp/rtp\";\nexport * from \"./rtp/rtx\";\nexport * from \"./rtp/sendHeaderExtensions\";\nexport * from \"./rtp/timelineRewriter\";\nexport * from \"./srtp/const\";\nexport * from \"./srtp/error\";\nexport * from \"./srtp/replay\";\nexport * from \"./srtp/srtcp\";\nexport * from \"./srtp/srtp\";\nexport * from \"./util\";\n"]}
@@ -6,6 +6,12 @@ import type { RtpHeader } from "./rtp";
6
6
  * switch (`replaceTrack`, `onSourceChanged`): the first packet actually sent
7
7
  * after it continues from the last output (`seq + 1`, `timestamp + step`).
8
8
  * RTX and padding use their own numbering and never go through this.
9
+ *
10
+ * This is the low-level piece used by `RTCRtpSender`: the caller detects the
11
+ * source switch, chooses the timestamp step and drops late packets of the old
12
+ * source itself. Applications that forward RTP (SFU / relay, RTP-to-SRTP
13
+ * gateways, replay) should use {@link RtpTimelineRewriter}, which does all of
14
+ * that on top of this class.
9
15
  */
10
16
  export declare class RtpContinuity {
11
17
  private _sequenceNumber?;
@@ -14,6 +20,7 @@ export declare class RtpContinuity {
14
20
  private seqOffset;
15
21
  private pending;
16
22
  private pendingTimestampStep;
23
+ private pendingFrom?;
17
24
  /** Last sent output sequence number; undefined before the first packet. */
18
25
  get sequenceNumber(): number | undefined;
19
26
  /** Last sent output timestamp; undefined before the first packet. */
@@ -21,8 +28,14 @@ export declare class RtpContinuity {
21
28
  /**
22
29
  * Rewrite offsets on the next sent packet.
23
30
  * @param timestampStep Timestamp increment across the source boundary.
31
+ * @param from Output to continue from instead of the last assigned one
32
+ * (for example the highest output when the last assigned packet was a
33
+ * reordered older one). Omitted: the last assigned output.
24
34
  */
25
- schedule(timestampStep?: number): void;
35
+ schedule(timestampStep?: number, from?: {
36
+ sequenceNumber: number;
37
+ timestamp: number;
38
+ }): void;
26
39
  /** Forget a scheduled rewrite (track detached / sender stopped). */
27
40
  cancel(): void;
28
41
  /** Output timestamp of `inputTimestamp` with the current offset (before send). */
@@ -9,6 +9,12 @@ const src_1 = require("../../../common/src");
9
9
  * switch (`replaceTrack`, `onSourceChanged`): the first packet actually sent
10
10
  * after it continues from the last output (`seq + 1`, `timestamp + step`).
11
11
  * RTX and padding use their own numbering and never go through this.
12
+ *
13
+ * This is the low-level piece used by `RTCRtpSender`: the caller detects the
14
+ * source switch, chooses the timestamp step and drops late packets of the old
15
+ * source itself. Applications that forward RTP (SFU / relay, RTP-to-SRTP
16
+ * gateways, replay) should use {@link RtpTimelineRewriter}, which does all of
17
+ * that on top of this class.
12
18
  */
13
19
  class RtpContinuity {
14
20
  constructor() {
@@ -48,6 +54,12 @@ class RtpContinuity {
48
54
  writable: true,
49
55
  value: 1
50
56
  });
57
+ Object.defineProperty(this, "pendingFrom", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
51
63
  }
52
64
  /** Last sent output sequence number; undefined before the first packet. */
53
65
  get sequenceNumber() {
@@ -60,14 +72,19 @@ class RtpContinuity {
60
72
  /**
61
73
  * Rewrite offsets on the next sent packet.
62
74
  * @param timestampStep Timestamp increment across the source boundary.
75
+ * @param from Output to continue from instead of the last assigned one
76
+ * (for example the highest output when the last assigned packet was a
77
+ * reordered older one). Omitted: the last assigned output.
63
78
  */
64
- schedule(timestampStep = 1) {
79
+ schedule(timestampStep = 1, from) {
65
80
  this.pending = true;
66
81
  this.pendingTimestampStep = timestampStep;
82
+ this.pendingFrom = from;
67
83
  }
68
84
  /** Forget a scheduled rewrite (track detached / sender stopped). */
69
85
  cancel() {
70
86
  this.pending = false;
87
+ this.pendingFrom = undefined;
71
88
  }
72
89
  /** Output timestamp of `inputTimestamp` with the current offset (before send). */
73
90
  mapTimestamp(inputTimestamp) {
@@ -81,13 +98,16 @@ class RtpContinuity {
81
98
  assign(header, inputSequenceNumber, inputTimestamp) {
82
99
  let rewritten = false;
83
100
  if (this.pending) {
84
- if (this._sequenceNumber != undefined && this._timestamp != undefined) {
85
- this.seqOffset = (0, src_1.uint16Add)((0, src_1.uint16Add)(this._sequenceNumber, 1), -inputSequenceNumber);
86
- this.timestampOffset = (0, src_1.uint32Add)((0, src_1.uint32Add)(this._timestamp, this.pendingTimestampStep), -inputTimestamp);
101
+ const lastSequenceNumber = this.pendingFrom?.sequenceNumber ?? this._sequenceNumber;
102
+ const lastTimestamp = this.pendingFrom?.timestamp ?? this._timestamp;
103
+ if (lastSequenceNumber != undefined && lastTimestamp != undefined) {
104
+ this.seqOffset = (0, src_1.uint16Add)((0, src_1.uint16Add)(lastSequenceNumber, 1), -inputSequenceNumber);
105
+ this.timestampOffset = (0, src_1.uint32Add)((0, src_1.uint32Add)(lastTimestamp, this.pendingTimestampStep), -inputTimestamp);
87
106
  rewritten = true;
88
107
  }
89
108
  this.pending = false;
90
109
  this.pendingTimestampStep = 1;
110
+ this.pendingFrom = undefined;
91
111
  }
92
112
  header.timestamp = (0, src_1.uint32Add)(inputTimestamp, this.timestampOffset);
93
113
  header.sequenceNumber = (0, src_1.uint16Add)(inputSequenceNumber, this.seqOffset);
@@ -1 +1 @@
1
- {"version":3,"file":"continuity.js","sourceRoot":"","sources":["../../../../../rtp/src/rtp/continuity.ts"],"names":[],"mappings":";;;AAAA,6CAA2D;AAG3D;;;;;;;GAOG;AACH,MAAa,aAAa;IAA1B;QACU;;;;;WAAyB;QACzB;;;;;WAAoB;QACpB;;;;mBAAkB,CAAC;WAAC;QACpB;;;;mBAAY,CAAC;WAAC;QACd;;;;mBAAU,KAAK;WAAC;QAChB;;;;mBAAuB,CAAC;WAAC;IAgEnC,CAAC;IA9DC,2EAA2E;IAC3E,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,qEAAqE;IACrE,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,aAAa,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,oBAAoB,GAAG,aAAa,CAAC;IAC5C,CAAC;IAED,oEAAoE;IACpE,MAAM;QACJ,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,kFAAkF;IAClF,YAAY,CAAC,cAAsB;QACjC,OAAO,IAAA,eAAS,EAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACH,MAAM,CACJ,MAAiB,EACjB,mBAA2B,EAC3B,cAAsB;QAEtB,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,IAAI,CAAC,eAAe,IAAI,SAAS,IAAI,IAAI,CAAC,UAAU,IAAI,SAAS,EAAE,CAAC;gBACtE,IAAI,CAAC,SAAS,GAAG,IAAA,eAAS,EACxB,IAAA,eAAS,EAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,EAClC,CAAC,mBAAmB,CACrB,CAAC;gBACF,IAAI,CAAC,eAAe,GAAG,IAAA,eAAS,EAC9B,IAAA,eAAS,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,oBAAoB,CAAC,EACrD,CAAC,cAAc,CAChB,CAAC;gBACF,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,CAAC,SAAS,GAAG,IAAA,eAAS,EAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACnE,MAAM,CAAC,cAAc,GAAG,IAAA,eAAS,EAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACvE,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAtED,sCAsEC","sourcesContent":["import { uint16Add, uint32Add } from \"../../../common/src\";\nimport type { RtpHeader } from \"./rtp\";\n\n/**\n * Output sequence number / timestamp of one sender's media stream.\n *\n * Output = input + offset. The offsets change only at a scheduled source\n * switch (`replaceTrack`, `onSourceChanged`): the first packet actually sent\n * after it continues from the last output (`seq + 1`, `timestamp + step`).\n * RTX and padding use their own numbering and never go through this.\n */\nexport class RtpContinuity {\n private _sequenceNumber?: number;\n private _timestamp?: number;\n private timestampOffset = 0;\n private seqOffset = 0;\n private pending = false;\n private pendingTimestampStep = 1;\n\n /** Last sent output sequence number; undefined before the first packet. */\n get sequenceNumber() {\n return this._sequenceNumber;\n }\n\n /** Last sent output timestamp; undefined before the first packet. */\n get timestamp() {\n return this._timestamp;\n }\n\n /**\n * Rewrite offsets on the next sent packet.\n * @param timestampStep Timestamp increment across the source boundary.\n */\n schedule(timestampStep = 1) {\n this.pending = true;\n this.pendingTimestampStep = timestampStep;\n }\n\n /** Forget a scheduled rewrite (track detached / sender stopped). */\n cancel() {\n this.pending = false;\n }\n\n /** Output timestamp of `inputTimestamp` with the current offset (before send). */\n mapTimestamp(inputTimestamp: number) {\n return uint32Add(inputTimestamp, this.timestampOffset);\n }\n\n /**\n * Assign the output sequence number / timestamp of a media packet that is\n * about to be written, applying a scheduled rewrite first.\n * @returns true when a rewrite moved the offsets (a new RTP clock origin).\n */\n assign(\n header: RtpHeader,\n inputSequenceNumber: number,\n inputTimestamp: number,\n ): boolean {\n let rewritten = false;\n if (this.pending) {\n if (this._sequenceNumber != undefined && this._timestamp != undefined) {\n this.seqOffset = uint16Add(\n uint16Add(this._sequenceNumber, 1),\n -inputSequenceNumber,\n );\n this.timestampOffset = uint32Add(\n uint32Add(this._timestamp, this.pendingTimestampStep),\n -inputTimestamp,\n );\n rewritten = true;\n }\n this.pending = false;\n this.pendingTimestampStep = 1;\n }\n\n header.timestamp = uint32Add(inputTimestamp, this.timestampOffset);\n header.sequenceNumber = uint16Add(inputSequenceNumber, this.seqOffset);\n this._timestamp = header.timestamp;\n this._sequenceNumber = header.sequenceNumber;\n return rewritten;\n }\n}\n"]}
1
+ {"version":3,"file":"continuity.js","sourceRoot":"","sources":["../../../../../rtp/src/rtp/continuity.ts"],"names":[],"mappings":";;;AAAA,6CAA2D;AAG3D;;;;;;;;;;;;;GAaG;AACH,MAAa,aAAa;IAA1B;QACU;;;;;WAAyB;QACzB;;;;;WAAoB;QACpB;;;;mBAAkB,CAAC;WAAC;QACpB;;;;mBAAY,CAAC;WAAC;QACd;;;;mBAAU,KAAK;WAAC;QAChB;;;;mBAAuB,CAAC;WAAC;QACzB;;;;;WAA4D;IA4EtE,CAAC;IA1EC,2EAA2E;IAC3E,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,qEAAqE;IACrE,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CACN,aAAa,GAAG,CAAC,EACjB,IAAoD;QAEpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,oBAAoB,GAAG,aAAa,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,oEAAoE;IACpE,MAAM;QACJ,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,kFAAkF;IAClF,YAAY,CAAC,cAAsB;QACjC,OAAO,IAAA,eAAS,EAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACH,MAAM,CACJ,MAAiB,EACjB,mBAA2B,EAC3B,cAAsB;QAEtB,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,kBAAkB,GACtB,IAAI,CAAC,WAAW,EAAE,cAAc,IAAI,IAAI,CAAC,eAAe,CAAC;YAC3D,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC;YACrE,IAAI,kBAAkB,IAAI,SAAS,IAAI,aAAa,IAAI,SAAS,EAAE,CAAC;gBAClE,IAAI,CAAC,SAAS,GAAG,IAAA,eAAS,EACxB,IAAA,eAAS,EAAC,kBAAkB,EAAE,CAAC,CAAC,EAChC,CAAC,mBAAmB,CACrB,CAAC;gBACF,IAAI,CAAC,eAAe,GAAG,IAAA,eAAS,EAC9B,IAAA,eAAS,EAAC,aAAa,EAAE,IAAI,CAAC,oBAAoB,CAAC,EACnD,CAAC,cAAc,CAChB,CAAC;gBACF,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;YAC9B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC/B,CAAC;QAED,MAAM,CAAC,SAAS,GAAG,IAAA,eAAS,EAAC,cAAc,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACnE,MAAM,CAAC,cAAc,GAAG,IAAA,eAAS,EAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACvE,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAnFD,sCAmFC","sourcesContent":["import { uint16Add, uint32Add } from \"../../../common/src\";\nimport type { RtpHeader } from \"./rtp\";\n\n/**\n * Output sequence number / timestamp of one sender's media stream.\n *\n * Output = input + offset. The offsets change only at a scheduled source\n * switch (`replaceTrack`, `onSourceChanged`): the first packet actually sent\n * after it continues from the last output (`seq + 1`, `timestamp + step`).\n * RTX and padding use their own numbering and never go through this.\n *\n * This is the low-level piece used by `RTCRtpSender`: the caller detects the\n * source switch, chooses the timestamp step and drops late packets of the old\n * source itself. Applications that forward RTP (SFU / relay, RTP-to-SRTP\n * gateways, replay) should use {@link RtpTimelineRewriter}, which does all of\n * that on top of this class.\n */\nexport class RtpContinuity {\n private _sequenceNumber?: number;\n private _timestamp?: number;\n private timestampOffset = 0;\n private seqOffset = 0;\n private pending = false;\n private pendingTimestampStep = 1;\n private pendingFrom?: { sequenceNumber: number; timestamp: number };\n\n /** Last sent output sequence number; undefined before the first packet. */\n get sequenceNumber() {\n return this._sequenceNumber;\n }\n\n /** Last sent output timestamp; undefined before the first packet. */\n get timestamp() {\n return this._timestamp;\n }\n\n /**\n * Rewrite offsets on the next sent packet.\n * @param timestampStep Timestamp increment across the source boundary.\n * @param from Output to continue from instead of the last assigned one\n * (for example the highest output when the last assigned packet was a\n * reordered older one). Omitted: the last assigned output.\n */\n schedule(\n timestampStep = 1,\n from?: { sequenceNumber: number; timestamp: number },\n ) {\n this.pending = true;\n this.pendingTimestampStep = timestampStep;\n this.pendingFrom = from;\n }\n\n /** Forget a scheduled rewrite (track detached / sender stopped). */\n cancel() {\n this.pending = false;\n this.pendingFrom = undefined;\n }\n\n /** Output timestamp of `inputTimestamp` with the current offset (before send). */\n mapTimestamp(inputTimestamp: number) {\n return uint32Add(inputTimestamp, this.timestampOffset);\n }\n\n /**\n * Assign the output sequence number / timestamp of a media packet that is\n * about to be written, applying a scheduled rewrite first.\n * @returns true when a rewrite moved the offsets (a new RTP clock origin).\n */\n assign(\n header: RtpHeader,\n inputSequenceNumber: number,\n inputTimestamp: number,\n ): boolean {\n let rewritten = false;\n if (this.pending) {\n const lastSequenceNumber =\n this.pendingFrom?.sequenceNumber ?? this._sequenceNumber;\n const lastTimestamp = this.pendingFrom?.timestamp ?? this._timestamp;\n if (lastSequenceNumber != undefined && lastTimestamp != undefined) {\n this.seqOffset = uint16Add(\n uint16Add(lastSequenceNumber, 1),\n -inputSequenceNumber,\n );\n this.timestampOffset = uint32Add(\n uint32Add(lastTimestamp, this.pendingTimestampStep),\n -inputTimestamp,\n );\n rewritten = true;\n }\n this.pending = false;\n this.pendingTimestampStep = 1;\n this.pendingFrom = undefined;\n }\n\n header.timestamp = uint32Add(inputTimestamp, this.timestampOffset);\n header.sequenceNumber = uint16Add(inputSequenceNumber, this.seqOffset);\n this._timestamp = header.timestamp;\n this._sequenceNumber = header.sequenceNumber;\n return rewritten;\n }\n}\n"]}
@@ -0,0 +1,178 @@
1
+ import { Event } from "../../../common/src";
2
+ import { type RtpPacket } from "./rtp";
3
+ /**
4
+ * How {@link RtpTimelineRewriter} chooses the output timestamp increment
5
+ * between the last packet of the old source and the first packet of the new one.
6
+ *
7
+ * - `number`: that fixed increment (for example `3000` for 30 fps video at 90 kHz).
8
+ * - `"lastDelta"`: the last positive timestamp increment seen on the stream
9
+ * (the frame / packet interval of the old source), or
10
+ * {@link RtpTimelineRewriterOptions.defaultTimestampStep} when none was seen yet.
11
+ * - `"wallClock"`: the time between the last packet of the old source and the
12
+ * first packet of the new one, times `clockRate / 1000`
13
+ * (requires {@link RtpTimelineRewriterOptions.clockRate}). The reconnect time
14
+ * becomes media time, so separate audio / video rewriters keep their relative
15
+ * position (A/V sync). `"lastDelta"` / a fixed number advance audio and video
16
+ * by different amounts, so their relative offset can change at each switch.
17
+ * - `"auto"` (default): `"wallClock"` when `clockRate` is set, otherwise `"lastDelta"`.
18
+ *
19
+ * Every mode advances the timestamp by at least 1.
20
+ */
21
+ export type RtpTimestampStepMode = number | "lastDelta" | "wallClock" | "auto";
22
+ export interface RtpTimelineRewriterOptions {
23
+ /** RTP clock rate of the stream in Hz (90000 for video). Needed by `"wallClock"`. */
24
+ clockRate?: number;
25
+ /** Timestamp increment at a source switch. Default `"auto"`. */
26
+ timestampStep?: RtpTimestampStepMode;
27
+ /** Increment used by `"lastDelta"` before any increment was seen. Default 1. */
28
+ defaultTimestampStep?: number;
29
+ /** Fixed output SSRC (for example the downstream SRTP SSRC). Default: keep the input SSRC. */
30
+ ssrc?: number;
31
+ /** Fixed output payload type. Default: keep the input payload type. */
32
+ payloadType?: number;
33
+ /**
34
+ * Treat a change of the input SSRC as a source switch, like a new `source`
35
+ * key. Late packets of the previous SSRC are then dropped. Default true.
36
+ * Set false only when the input SSRC changes without a timeline change.
37
+ */
38
+ switchOnSsrcChange?: boolean;
39
+ /**
40
+ * Rewrite the header of the given packet instead of a clone. Default false:
41
+ * received packets (`MediaStreamTrack.onReceiveRtp`) are shared by every
42
+ * subscriber and must not be changed.
43
+ */
44
+ inPlace?: boolean;
45
+ /** Monotonic clock in milliseconds. Default `performance.now()`. For tests. */
46
+ now?: () => number;
47
+ }
48
+ /** Notified when output continues from a previous source. */
49
+ export interface RtpTimelineSwitch {
50
+ /** `source` key of the new source (undefined when keys are not used). */
51
+ source: unknown;
52
+ /** Input SSRC of the new source. */
53
+ inputSsrc: number;
54
+ /** Output sequence number of the first packet of the new source. */
55
+ sequenceNumber: number;
56
+ /** Output timestamp of the first packet of the new source. */
57
+ timestamp: number;
58
+ /** Timestamp increment applied across the switch. */
59
+ timestampStep: number;
60
+ }
61
+ /**
62
+ * Why {@link RtpTimelineRewriter.rewrite} dropped a packet.
63
+ * - `staleSource`: the packet belongs to a source that was already replaced.
64
+ * - `beforeSourceStart`: the packet is older (by sequence number) than the
65
+ * first packet of the current source, so its output would go back to or
66
+ * before the output of the previous source.
67
+ * @enum
68
+ */
69
+ export declare const RtpTimelineDropReason: {
70
+ readonly staleSource: "staleSource";
71
+ readonly beforeSourceStart: "beforeSourceStart";
72
+ };
73
+ /** @enum */
74
+ export type RtpTimelineDropReason = (typeof RtpTimelineDropReason)[keyof typeof RtpTimelineDropReason];
75
+ /**
76
+ * Keeps one continuous downstream RTP timeline (sequence number / timestamp,
77
+ * optionally SSRC / payload type) while the upstream RTP source is replaced,
78
+ * for example when an upstream WebRTC connection is recreated and its RTP is
79
+ * forwarded to a long-lived downstream RTP / SRTP session.
80
+ *
81
+ * - The first source is output unchanged (except the fixed `ssrc` / `payloadType`).
82
+ * - Within one source, output = input + offset, so reordering, loss and
83
+ * duplicates keep their relation.
84
+ * - The first packet of a new source continues from the highest output so far:
85
+ * `sequenceNumber + 1`, `timestamp + step` (see {@link RtpTimestampStepMode}).
86
+ * 16-bit sequence numbers and 32-bit timestamps wrap around.
87
+ * - A new source starts when the `source` key passed to {@link rewrite}
88
+ * changes, when the input SSRC changes (`switchOnSsrcChange`, default on) or
89
+ * at the next packet after {@link switchSource}.
90
+ * - Late packets of a replaced source (its `source` key, or its SSRC with
91
+ * `switchOnSsrcChange`) are dropped (`staleSource`). Without keys and SSRC
92
+ * changes, old and new packets cannot be told apart after {@link switchSource};
93
+ * pass a `source` key per upstream connection to drop them.
94
+ * - Packets of a new source that are older (signed 16-bit sequence distance
95
+ * below 0, tracked across wraps) than its first packet are dropped
96
+ * (`beforeSourceStart`): their output would be at or before the previous
97
+ * source's output, which a downstream SRTP receiver rejects as a replay. The
98
+ * first packet and everything after it is accepted. This does not apply to
99
+ * the first source, which has nothing before it.
100
+ *
101
+ * So the output sequence number never goes back to or repeats a number of an
102
+ * earlier source, which keeps the downstream SRTP rollover counter estimation
103
+ * and replay window intact.
104
+ *
105
+ * Padding-only packets are in the media sequence space and are rewritten like
106
+ * media (dropping them would leave sequence gaps), but they do not count as a
107
+ * timestamp increment for `"lastDelta"`. RTX packets have their own SSRC and
108
+ * sequence space: do not pass them to the same instance (restore them to the
109
+ * media stream first, as werift's receiver does, or use a separate instance).
110
+ * Use one instance per downstream stream (audio and video separately).
111
+ *
112
+ * Not handled here: a decoder downstream needs a key frame of the new source,
113
+ * so request one upstream (PLI / FIR, for example
114
+ * `RTCRtpReceiver.sendRtcpPLI`) after a switch. Upstream RTCP Sender Reports
115
+ * carry the upstream SSRC / RTP timestamps; rewrite their RTP timestamp with
116
+ * {@link mapTimestamp} and their SSRC, or generate downstream SRs yourself.
117
+ */
118
+ export declare class RtpTimelineRewriter {
119
+ /** A new source started on the output ({@link RtpTimelineSwitch}). */
120
+ readonly onSourceSwitch: Event<[RtpTimelineSwitch]>;
121
+ /** A packet was dropped. Receives the input packet. */
122
+ readonly onDrop: Event<[RtpPacket, RtpTimelineDropReason]>;
123
+ private readonly continuity;
124
+ private readonly options;
125
+ private readonly now;
126
+ private started;
127
+ private currentSource;
128
+ private currentSsrc?;
129
+ private readonly retired;
130
+ /** A switch is waiting for the first packet of the new source. */
131
+ private pendingSwitch;
132
+ private pendingTimestampStep?;
133
+ /** The current source continues an earlier one (start check applies). */
134
+ private guardSourceStart;
135
+ private sourceHasPacket;
136
+ private sourceHighestSeq;
137
+ /** Highest input sequence number of the source, relative to its first packet. */
138
+ private sourceHighestExtended;
139
+ private highestSequenceNumber?;
140
+ private highestTimestamp?;
141
+ private lastTimestampDelta?;
142
+ /** Arrival time of the packet that set `highestTimestamp`. */
143
+ private lastPacketTime?;
144
+ constructor(options?: RtpTimelineRewriterOptions);
145
+ /** Last output sequence number; undefined before the first packet. */
146
+ get sequenceNumber(): number | undefined;
147
+ /** Last output timestamp; undefined before the first packet. */
148
+ get timestamp(): number | undefined;
149
+ /**
150
+ * Output timestamp of an input timestamp of the current source (for example
151
+ * to rewrite the RTP timestamp of an upstream Sender Report). Until the first
152
+ * packet of a new source is rewritten, this still uses the previous source's offset.
153
+ */
154
+ mapTimestamp(inputTimestamp: number): number;
155
+ /**
156
+ * Start a new source at the next packet.
157
+ * @param options.source `source` key of the new source. When given, packets
158
+ * with the current key are dropped from now on; packets must then carry this key.
159
+ * @param options.timestampStep Timestamp increment for this switch only,
160
+ * instead of {@link RtpTimelineRewriterOptions.timestampStep}.
161
+ */
162
+ switchSource(options?: {
163
+ source?: unknown;
164
+ timestampStep?: number;
165
+ }): void;
166
+ /**
167
+ * Rewrite one packet onto the output timeline.
168
+ * @param options.source Identity of the upstream source (for example a
169
+ * connection generation number). A new key starts a new source.
170
+ * @returns the rewritten packet (a clone unless `inPlace`), or undefined when
171
+ * the packet is dropped ({@link RtpTimelineDropReason}).
172
+ */
173
+ rewrite(packet: RtpPacket, options?: {
174
+ source?: unknown;
175
+ }): RtpPacket | undefined;
176
+ private observeOutput;
177
+ private timestampStepFor;
178
+ }