werift 0.17.5 → 0.17.7

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 (336) hide show
  1. package/lib/common/src/binary.d.ts +1 -0
  2. package/lib/common/src/binary.js +74 -21
  3. package/lib/common/src/binary.js.map +1 -1
  4. package/lib/common/src/log.js +18 -0
  5. package/lib/common/src/log.js.map +1 -1
  6. package/lib/common/src/network.d.ts +1 -1
  7. package/lib/common/src/network.js +7 -3
  8. package/lib/common/src/network.js.map +1 -1
  9. package/lib/common/src/promise.js +22 -7
  10. package/lib/common/src/promise.js.map +1 -1
  11. package/lib/common/src/type.d.ts +1 -1
  12. package/lib/dtls/src/cipher/const.d.ts +7 -7
  13. package/lib/dtls/src/cipher/key-exchange.js +24 -1
  14. package/lib/dtls/src/cipher/key-exchange.js.map +1 -1
  15. package/lib/dtls/src/cipher/suites/abstract.d.ts +2 -2
  16. package/lib/dtls/src/cipher/suites/abstract.js +36 -2
  17. package/lib/dtls/src/cipher/suites/abstract.js.map +1 -1
  18. package/lib/dtls/src/cipher/suites/aead.js +60 -6
  19. package/lib/dtls/src/cipher/suites/aead.js.map +1 -1
  20. package/lib/dtls/src/client.js +62 -51
  21. package/lib/dtls/src/client.js.map +1 -1
  22. package/lib/dtls/src/context/cipher.js +151 -59
  23. package/lib/dtls/src/context/cipher.js.map +1 -1
  24. package/lib/dtls/src/context/dtls.js +90 -14
  25. package/lib/dtls/src/context/dtls.js.map +1 -1
  26. package/lib/dtls/src/context/srtp.d.ts +1 -1
  27. package/lib/dtls/src/context/srtp.js +8 -0
  28. package/lib/dtls/src/context/srtp.js.map +1 -1
  29. package/lib/dtls/src/context/transport.js +14 -2
  30. package/lib/dtls/src/context/transport.js.map +1 -1
  31. package/lib/dtls/src/flight/client/flight1.js +6 -1
  32. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  33. package/lib/dtls/src/flight/client/flight5.js +12 -2
  34. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  35. package/lib/dtls/src/flight/flight.d.ts +1 -1
  36. package/lib/dtls/src/flight/flight.js +42 -7
  37. package/lib/dtls/src/flight/flight.js.map +1 -1
  38. package/lib/dtls/src/flight/server/flight2.js +4 -2
  39. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  40. package/lib/dtls/src/flight/server/flight4.js +12 -2
  41. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  42. package/lib/dtls/src/flight/server/flight6.js +6 -1
  43. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  44. package/lib/dtls/src/handshake/extensions/ellipticCurves.js +27 -7
  45. package/lib/dtls/src/handshake/extensions/ellipticCurves.js.map +1 -1
  46. package/lib/dtls/src/handshake/extensions/extendedMasterSecret.js +6 -1
  47. package/lib/dtls/src/handshake/extensions/extendedMasterSecret.js.map +1 -1
  48. package/lib/dtls/src/handshake/extensions/renegotiationIndication.js +27 -7
  49. package/lib/dtls/src/handshake/extensions/renegotiationIndication.js.map +1 -1
  50. package/lib/dtls/src/handshake/extensions/signature.js +27 -7
  51. package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
  52. package/lib/dtls/src/handshake/extensions/useSrtp.js +39 -9
  53. package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
  54. package/lib/dtls/src/handshake/message/alert.js +21 -6
  55. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  56. package/lib/dtls/src/handshake/message/certificate.js +26 -5
  57. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  58. package/lib/dtls/src/handshake/message/changeCipherSpec.js +14 -4
  59. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  60. package/lib/dtls/src/handshake/message/client/certificateVerify.js +33 -7
  61. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  62. package/lib/dtls/src/handshake/message/client/hello.js +68 -18
  63. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  64. package/lib/dtls/src/handshake/message/client/keyExchange.js +26 -5
  65. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/finished.js +18 -2
  67. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/server/certificateRequest.js +40 -9
  69. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  70. package/lib/dtls/src/handshake/message/server/hello.js +60 -14
  71. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  72. package/lib/dtls/src/handshake/message/server/helloDone.js +18 -2
  73. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  74. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +33 -7
  75. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  76. package/lib/dtls/src/handshake/message/server/keyExchange.js +75 -19
  77. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  78. package/lib/dtls/src/handshake/random.js +21 -6
  79. package/lib/dtls/src/handshake/random.js.map +1 -1
  80. package/lib/dtls/src/record/builder.d.ts +1 -1
  81. package/lib/dtls/src/record/message/fragment.js +49 -14
  82. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  83. package/lib/dtls/src/record/message/header.js +84 -24
  84. package/lib/dtls/src/record/message/header.js.map +1 -1
  85. package/lib/dtls/src/record/message/plaintext.js +21 -6
  86. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  87. package/lib/dtls/src/server.js +59 -42
  88. package/lib/dtls/src/server.js.map +1 -1
  89. package/lib/dtls/src/socket.js +153 -64
  90. package/lib/dtls/src/socket.js.map +1 -1
  91. package/lib/dtls/src/transport.js +38 -11
  92. package/lib/dtls/src/transport.js.map +1 -1
  93. package/lib/dtls/src/typings/domain.d.ts +4 -4
  94. package/lib/ice/src/candidate.js +66 -11
  95. package/lib/ice/src/candidate.js.map +1 -1
  96. package/lib/ice/src/dns/lookup.js +12 -1
  97. package/lib/ice/src/dns/lookup.js.map +1 -1
  98. package/lib/ice/src/exceptions.js +27 -2
  99. package/lib/ice/src/exceptions.js.map +1 -1
  100. package/lib/ice/src/helper.d.ts +1 -1
  101. package/lib/ice/src/helper.js +12 -2
  102. package/lib/ice/src/helper.js.map +1 -1
  103. package/lib/ice/src/ice.d.ts +9 -3
  104. package/lib/ice/src/ice.js +401 -154
  105. package/lib/ice/src/ice.js.map +1 -1
  106. package/lib/ice/src/stun/attributes.d.ts +3 -3
  107. package/lib/ice/src/stun/attributes.js +6 -1
  108. package/lib/ice/src/stun/attributes.js.map +1 -1
  109. package/lib/ice/src/stun/message.d.ts +4 -0
  110. package/lib/ice/src/stun/message.js +24 -3
  111. package/lib/ice/src/stun/message.js.map +1 -1
  112. package/lib/ice/src/stun/protocol.js +64 -15
  113. package/lib/ice/src/stun/protocol.js.map +1 -1
  114. package/lib/ice/src/stun/transaction.js +99 -36
  115. package/lib/ice/src/stun/transaction.js.map +1 -1
  116. package/lib/ice/src/transport.js +57 -21
  117. package/lib/ice/src/transport.js.map +1 -1
  118. package/lib/ice/src/turn/protocol.js +176 -40
  119. package/lib/ice/src/turn/protocol.js.map +1 -1
  120. package/lib/ice/src/types/model.d.ts +1 -1
  121. package/lib/rtp/src/codec/av1.d.ts +1 -1
  122. package/lib/rtp/src/codec/av1.js +118 -30
  123. package/lib/rtp/src/codec/av1.js.map +1 -1
  124. package/lib/rtp/src/codec/base.js +8 -0
  125. package/lib/rtp/src/codec/base.js.map +1 -1
  126. package/lib/rtp/src/codec/h264.js +55 -0
  127. package/lib/rtp/src/codec/h264.js.map +1 -1
  128. package/lib/rtp/src/codec/index.d.ts +2 -0
  129. package/lib/rtp/src/codec/index.js +12 -2
  130. package/lib/rtp/src/codec/index.js.map +1 -1
  131. package/lib/rtp/src/codec/opus.js +8 -0
  132. package/lib/rtp/src/codec/opus.js.map +1 -1
  133. package/lib/rtp/src/codec/vp8.js +102 -3
  134. package/lib/rtp/src/codec/vp8.js.map +1 -1
  135. package/lib/rtp/src/codec/vp9.js +164 -7
  136. package/lib/rtp/src/codec/vp9.js.map +1 -1
  137. package/lib/rtp/src/container/ebml/ebml.js +30 -3
  138. package/lib/rtp/src/container/ebml/ebml.js.map +1 -1
  139. package/lib/rtp/src/container/webm.d.ts +1 -1
  140. package/lib/rtp/src/container/webm.js +44 -13
  141. package/lib/rtp/src/container/webm.js.map +1 -1
  142. package/lib/rtp/src/processor/depacketizer.d.ts +16 -8
  143. package/lib/rtp/src/processor/depacketizer.js +59 -22
  144. package/lib/rtp/src/processor/depacketizer.js.map +1 -1
  145. package/lib/rtp/src/processor/depacketizerCallback.js +24 -8
  146. package/lib/rtp/src/processor/depacketizerCallback.js.map +1 -1
  147. package/lib/rtp/src/processor/depacketizerTransformer.d.ts +2 -2
  148. package/lib/rtp/src/processor/depacketizerTransformer.js +6 -0
  149. package/lib/rtp/src/processor/depacketizerTransformer.js.map +1 -1
  150. package/lib/rtp/src/processor/index.d.ts +4 -2
  151. package/lib/rtp/src/processor/index.js +4 -2
  152. package/lib/rtp/src/processor/index.js.map +1 -1
  153. package/lib/rtp/src/processor/interface.d.ts +4 -0
  154. package/lib/rtp/src/processor/interface.js.map +1 -1
  155. package/lib/rtp/src/processor/jitterBuffer.d.ts +2 -1
  156. package/lib/rtp/src/processor/jitterBuffer.js +40 -8
  157. package/lib/rtp/src/processor/jitterBuffer.js.map +1 -1
  158. package/lib/rtp/src/processor/jitterBufferCallback.js +30 -9
  159. package/lib/rtp/src/processor/jitterBufferCallback.js.map +1 -1
  160. package/lib/rtp/src/processor/jitterBufferTransformer.js +12 -1
  161. package/lib/rtp/src/processor/jitterBufferTransformer.js.map +1 -1
  162. package/lib/rtp/src/processor/lipsync.d.ts +42 -0
  163. package/lib/rtp/src/processor/lipsync.js +178 -0
  164. package/lib/rtp/src/processor/lipsync.js.map +1 -0
  165. package/lib/rtp/src/processor/lipsyncCallback.d.ts +10 -0
  166. package/lib/rtp/src/processor/lipsyncCallback.js +59 -0
  167. package/lib/rtp/src/processor/lipsyncCallback.js.map +1 -0
  168. package/lib/rtp/src/processor/ntpTime.d.ts +24 -0
  169. package/lib/rtp/src/processor/ntpTime.js +91 -0
  170. package/lib/rtp/src/processor/ntpTime.js.map +1 -0
  171. package/lib/rtp/src/processor/ntpTimeCallback.d.ts +7 -0
  172. package/lib/rtp/src/processor/ntpTimeCallback.js +36 -0
  173. package/lib/rtp/src/processor/ntpTimeCallback.js.map +1 -0
  174. package/lib/rtp/src/processor/source/index.d.ts +1 -0
  175. package/lib/rtp/src/processor/source/index.js +1 -0
  176. package/lib/rtp/src/processor/source/index.js.map +1 -1
  177. package/lib/rtp/src/processor/source/rtcpCallback.d.ts +12 -0
  178. package/lib/rtp/src/processor/source/rtcpCallback.js +33 -0
  179. package/lib/rtp/src/processor/source/rtcpCallback.js.map +1 -0
  180. package/lib/rtp/src/processor/source/rtpCallback.js +28 -12
  181. package/lib/rtp/src/processor/source/rtpCallback.js.map +1 -1
  182. package/lib/rtp/src/processor/source/rtpStream.js +38 -10
  183. package/lib/rtp/src/processor/source/rtpStream.js.map +1 -1
  184. package/lib/rtp/src/processor/webm.d.ts +11 -4
  185. package/lib/rtp/src/processor/webm.js +169 -46
  186. package/lib/rtp/src/processor/webm.js.map +1 -1
  187. package/lib/rtp/src/processor/webmCallback.d.ts +5 -3
  188. package/lib/rtp/src/processor/webmCallback.js +52 -8
  189. package/lib/rtp/src/processor/webmCallback.js.map +1 -1
  190. package/lib/rtp/src/processor/webmStream.d.ts +2 -2
  191. package/lib/rtp/src/processor/webmStream.js +24 -0
  192. package/lib/rtp/src/processor/webmStream.js.map +1 -1
  193. package/lib/rtp/src/processor_old/base.d.ts +18 -0
  194. package/lib/rtp/src/processor_old/base.js +51 -0
  195. package/lib/rtp/src/processor_old/base.js.map +1 -0
  196. package/lib/rtp/src/processor_old/lipsync.d.ts +30 -0
  197. package/lib/rtp/src/processor_old/lipsync.js +119 -0
  198. package/lib/rtp/src/processor_old/lipsync.js.map +1 -0
  199. package/lib/rtp/src/rtcp/header.js +30 -5
  200. package/lib/rtp/src/rtcp/header.js.map +1 -1
  201. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +1 -1
  202. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +30 -3
  203. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  204. package/lib/rtp/src/rtcp/psfb/index.d.ts +1 -1
  205. package/lib/rtp/src/rtcp/psfb/index.js +18 -2
  206. package/lib/rtp/src/rtcp/psfb/index.js.map +1 -1
  207. package/lib/rtp/src/rtcp/psfb/pictureLossIndication.js +30 -3
  208. package/lib/rtp/src/rtcp/psfb/pictureLossIndication.js.map +1 -1
  209. package/lib/rtp/src/rtcp/psfb/remb.js +66 -5
  210. package/lib/rtp/src/rtcp/psfb/remb.js.map +1 -1
  211. package/lib/rtp/src/rtcp/rr.js +68 -4
  212. package/lib/rtp/src/rtcp/rr.js.map +1 -1
  213. package/lib/rtp/src/rtcp/rtcp.d.ts +1 -1
  214. package/lib/rtp/src/rtcp/rtpfb/index.d.ts +1 -1
  215. package/lib/rtp/src/rtcp/rtpfb/index.js +24 -2
  216. package/lib/rtp/src/rtcp/rtpfb/index.js.map +1 -1
  217. package/lib/rtp/src/rtcp/rtpfb/nack.d.ts +5 -0
  218. package/lib/rtp/src/rtcp/rtpfb/nack.js +43 -3
  219. package/lib/rtp/src/rtcp/rtpfb/nack.js.map +1 -1
  220. package/lib/rtp/src/rtcp/rtpfb/twcc.js +154 -11
  221. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  222. package/lib/rtp/src/rtcp/sdes.js +42 -4
  223. package/lib/rtp/src/rtcp/sdes.js.map +1 -1
  224. package/lib/rtp/src/rtcp/sr.js +56 -5
  225. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  226. package/lib/rtp/src/rtp/red/encoder.js +18 -3
  227. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  228. package/lib/rtp/src/rtp/red/handler.js +12 -2
  229. package/lib/rtp/src/rtp/red/handler.js.map +1 -1
  230. package/lib/rtp/src/rtp/red/packet.js +18 -2
  231. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  232. package/lib/rtp/src/rtp/rtp.d.ts +3 -3
  233. package/lib/rtp/src/rtp/rtp.js +104 -17
  234. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  235. package/lib/rtp/src/srtp/cipher/ctr.js +26 -10
  236. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  237. package/lib/rtp/src/srtp/cipher/gcm.d.ts +3 -0
  238. package/lib/rtp/src/srtp/cipher/gcm.js +40 -20
  239. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  240. package/lib/rtp/src/srtp/cipher/index.js +24 -4
  241. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  242. package/lib/rtp/src/srtp/const.d.ts +1 -1
  243. package/lib/rtp/src/srtp/context/context.d.ts +1 -1
  244. package/lib/rtp/src/srtp/context/context.js +84 -5
  245. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  246. package/lib/rtp/src/srtp/session.d.ts +2 -2
  247. package/lib/rtp/src/srtp/session.js +24 -1
  248. package/lib/rtp/src/srtp/session.js.map +1 -1
  249. package/lib/rtp/src/srtp/srtcp.js +15 -5
  250. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  251. package/lib/rtp/src/srtp/srtp.js +15 -5
  252. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  253. package/lib/sctp/src/chunk.js +349 -69
  254. package/lib/sctp/src/chunk.js.map +1 -1
  255. package/lib/sctp/src/helper.d.ts +1 -1
  256. package/lib/sctp/src/param.d.ts +3 -3
  257. package/lib/sctp/src/param.js +66 -11
  258. package/lib/sctp/src/param.js.map +1 -1
  259. package/lib/sctp/src/sctp.d.ts +1 -1
  260. package/lib/sctp/src/sctp.js +479 -138
  261. package/lib/sctp/src/sctp.js.map +1 -1
  262. package/lib/sctp/src/transport.js +31 -10
  263. package/lib/sctp/src/transport.js.map +1 -1
  264. package/lib/webrtc/src/dataChannel.d.ts +1 -1
  265. package/lib/webrtc/src/dataChannel.js +145 -15
  266. package/lib/webrtc/src/dataChannel.js.map +1 -1
  267. package/lib/webrtc/src/helper.js +37 -12
  268. package/lib/webrtc/src/helper.js.map +1 -1
  269. package/lib/webrtc/src/media/parameters.d.ts +1 -1
  270. package/lib/webrtc/src/media/parameters.js +124 -3
  271. package/lib/webrtc/src/media/parameters.js.map +1 -1
  272. package/lib/webrtc/src/media/receiver/nack.d.ts +1 -1
  273. package/lib/webrtc/src/media/receiver/nack.js +85 -33
  274. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  275. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +1 -1
  276. package/lib/webrtc/src/media/receiver/receiverTwcc.js +42 -6
  277. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  278. package/lib/webrtc/src/media/receiver/statistics.js +61 -5
  279. package/lib/webrtc/src/media/receiver/statistics.js.map +1 -1
  280. package/lib/webrtc/src/media/router.d.ts +1 -1
  281. package/lib/webrtc/src/media/router.js +108 -83
  282. package/lib/webrtc/src/media/router.js.map +1 -1
  283. package/lib/webrtc/src/media/rtpReceiver.js +188 -33
  284. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  285. package/lib/webrtc/src/media/rtpSender.js +282 -42
  286. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  287. package/lib/webrtc/src/media/rtpTransceiver.d.ts +2 -2
  288. package/lib/webrtc/src/media/rtpTransceiver.js +102 -18
  289. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  290. package/lib/webrtc/src/media/sender/cumulativeResult.js +36 -6
  291. package/lib/webrtc/src/media/sender/cumulativeResult.js.map +1 -1
  292. package/lib/webrtc/src/media/sender/senderBWE.js +57 -12
  293. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  294. package/lib/webrtc/src/media/track.js +135 -24
  295. package/lib/webrtc/src/media/track.js.map +1 -1
  296. package/lib/webrtc/src/nonstandard/recorder/index.js +30 -3
  297. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  298. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +12 -2
  299. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  300. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -0
  301. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +25 -8
  302. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  303. package/lib/webrtc/src/nonstandard/userMedia.js +158 -56
  304. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  305. package/lib/webrtc/src/peerConnection.d.ts +2 -2
  306. package/lib/webrtc/src/peerConnection.js +260 -58
  307. package/lib/webrtc/src/peerConnection.js.map +1 -1
  308. package/lib/webrtc/src/sdp.js +287 -24
  309. package/lib/webrtc/src/sdp.js.map +1 -1
  310. package/lib/webrtc/src/transport/dtls.d.ts +3 -3
  311. package/lib/webrtc/src/transport/dtls.js +185 -30
  312. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  313. package/lib/webrtc/src/transport/ice.d.ts +2 -2
  314. package/lib/webrtc/src/transport/ice.js +193 -25
  315. package/lib/webrtc/src/transport/ice.js.map +1 -1
  316. package/lib/webrtc/src/transport/sctp.js +193 -101
  317. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  318. package/lib/webrtc/src/types/domain.d.ts +3 -3
  319. package/lib/webrtc/src/types/util.d.ts +2 -2
  320. package/lib/webrtc/src/utils.js +12 -2
  321. package/lib/webrtc/src/utils.js.map +1 -1
  322. package/package.json +15 -15
  323. package/src/dataChannel.ts +3 -1
  324. package/src/media/receiver/nack.ts +20 -16
  325. package/src/media/rtpReceiver.ts +5 -0
  326. package/src/media/rtpSender.ts +25 -20
  327. package/src/nonstandard/recorder/writer/webm.ts +17 -7
  328. package/src/transport/dtls.ts +7 -3
  329. package/src/transport/ice.ts +6 -3
  330. package/src/transport/sctp.ts +3 -1
  331. package/lib/rtp/src/processor/avBuffer.d.ts +0 -36
  332. package/lib/rtp/src/processor/avBuffer.js +0 -107
  333. package/lib/rtp/src/processor/avBuffer.js.map +0 -1
  334. package/lib/rtp/src/processor/avBufferCallback.d.ts +0 -10
  335. package/lib/rtp/src/processor/avBufferCallback.js +0 -27
  336. package/lib/rtp/src/processor/avBufferCallback.js.map +0 -1
@@ -22,22 +22,10 @@ export class NackHandler {
22
22
  readonly onPacketLost = new Event<[GenericNack]>();
23
23
  mediaSourceSsrc?: number;
24
24
  retryCount = 10;
25
+ closed = false;
25
26
 
26
27
  constructor(private receiver: RTCRtpReceiver) {}
27
28
 
28
- private start() {
29
- if (this.nackLoop) {
30
- return;
31
- }
32
- this.nackLoop = setInterval(async () => {
33
- try {
34
- await this.sendNack();
35
- } catch (error) {
36
- log("failed to send nack", error);
37
- }
38
- }, 20);
39
- }
40
-
41
29
  get lostSeqNumbers() {
42
30
  return Object.keys(this._lost).map(Number).sort();
43
31
  }
@@ -48,6 +36,21 @@ export class NackHandler {
48
36
 
49
37
  setLost(seq: number, count: number) {
50
38
  this._lost[seq] = count;
39
+
40
+ if (this.nackLoop || this.closed) {
41
+ return;
42
+ }
43
+ this.nackLoop = setInterval(async () => {
44
+ try {
45
+ await this.sendNack();
46
+ if (!Object.keys(this._lost).length) {
47
+ clearInterval(this.nackLoop);
48
+ this.nackLoop = undefined;
49
+ }
50
+ } catch (error) {
51
+ log("failed to send nack", error);
52
+ }
53
+ }, 5);
51
54
  }
52
55
 
53
56
  removeLost(sequenceNumber: number) {
@@ -55,8 +58,6 @@ export class NackHandler {
55
58
  }
56
59
 
57
60
  addPacket(packet: RtpPacket) {
58
- this.start();
59
-
60
61
  const { sequenceNumber, ssrc } = packet.header;
61
62
  this.mediaSourceSsrc = ssrc;
62
63
 
@@ -66,6 +67,7 @@ export class NackHandler {
66
67
  }
67
68
 
68
69
  if (this.getLost(sequenceNumber)) {
70
+ // log("packetLoss resolved", { sequenceNumber });
69
71
  this.removeLost(sequenceNumber);
70
72
  return;
71
73
  }
@@ -77,7 +79,7 @@ export class NackHandler {
77
79
  range(uint16Add(this.newEstSeqNum, 1), sequenceNumber).forEach((seq) => {
78
80
  this.setLost(seq, 1);
79
81
  });
80
- this.receiver.sendRtcpPLI(this.mediaSourceSsrc);
82
+ // this.receiver.sendRtcpPLI(this.mediaSourceSsrc);
81
83
 
82
84
  this.newEstSeqNum = sequenceNumber;
83
85
  this.pruneLost();
@@ -96,6 +98,7 @@ export class NackHandler {
96
98
  }
97
99
 
98
100
  close() {
101
+ this.closed = true;
99
102
  clearInterval(this.nackLoop);
100
103
  this._lost = {};
101
104
  }
@@ -118,6 +121,7 @@ export class NackHandler {
118
121
  mediaSourceSsrc: this.mediaSourceSsrc,
119
122
  lost: this.lostSeqNumbers,
120
123
  });
124
+ // log("sendNack", nack.toJSON());
121
125
  const rtcp = new RtcpTransportLayerFeedback({
122
126
  feedback: nack,
123
127
  });
@@ -214,6 +214,11 @@ export class RTCRtpReceiver {
214
214
  log("pli not supported", { mediaSsrc });
215
215
  return;
216
216
  }
217
+
218
+ if (this.stopped) {
219
+ return;
220
+ }
221
+
217
222
  log("sendRtcpPLI", { mediaSsrc });
218
223
 
219
224
  const packet = new RtcpPayloadSpecificFeedback({
@@ -72,10 +72,7 @@ const RTT_ALPHA = 0.85;
72
72
 
73
73
  export class RTCRtpSender {
74
74
  readonly type = "sender";
75
- readonly kind =
76
- typeof this.trackOrKind === "string"
77
- ? this.trackOrKind
78
- : this.trackOrKind.kind;
75
+ readonly kind: Kind;
79
76
  readonly ssrc = jspack.Unpack("!L", randomBytes(4))[0];
80
77
  readonly rtxSsrc = jspack.Unpack("!L", randomBytes(4))[0];
81
78
  streamId = uuid.v4();
@@ -124,6 +121,10 @@ export class RTCRtpSender {
124
121
  private rtcpCancel = new AbortController();
125
122
 
126
123
  constructor(public trackOrKind: Kind | MediaStreamTrack) {
124
+ this.kind =
125
+ typeof this.trackOrKind === "string"
126
+ ? this.trackOrKind
127
+ : this.trackOrKind.kind;
127
128
  if (trackOrKind instanceof MediaStreamTrack) {
128
129
  if (trackOrKind.streamId) {
129
130
  this.streamId = trackOrKind.streamId;
@@ -230,7 +231,9 @@ export class RTCRtpSender {
230
231
  this.stopped = true;
231
232
  this.rtcpRunning = false;
232
233
  this.rtcpCancel.abort();
233
-
234
+ if (this.disposeTrack) {
235
+ this.disposeTrack();
236
+ }
234
237
  this.track = undefined;
235
238
  }
236
239
 
@@ -313,7 +316,7 @@ export class RTCRtpSender {
313
316
 
314
317
  rtp = Buffer.isBuffer(rtp) ? RtpPacket.deSerialize(rtp) : rtp;
315
318
 
316
- const header = rtp.header;
319
+ const { header, payload } = rtp;
317
320
  header.ssrc = this.ssrc;
318
321
  header.payloadType = this.codec.payloadType;
319
322
  header.timestamp = uint32Add(header.timestamp, this.timestampOffset);
@@ -321,6 +324,8 @@ export class RTCRtpSender {
321
324
  this.timestamp = header.timestamp;
322
325
  this.sequenceNumber = header.sequenceNumber;
323
326
 
327
+ const ntptime = ntpTime();
328
+
324
329
  header.extensions = this.headerExtensions
325
330
  .map((extension) => {
326
331
  const payload = (() => {
@@ -353,7 +358,7 @@ export class RTCRtpSender {
353
358
  );
354
359
  case RTP_EXTENSION_URI.absSendTime:
355
360
  const buf = Buffer.alloc(3);
356
- const time = (ntpTime() >> 14n) & 0x00ffffffn;
361
+ const time = (ntptime >> 14n) & 0x00ffffffn;
357
362
  buf.writeUIntBE(Number(time), 0, 3);
358
363
  return buf;
359
364
  }
@@ -363,17 +368,14 @@ export class RTCRtpSender {
363
368
  })
364
369
  .filter((v) => v) as Extension[];
365
370
 
366
- this.ntpTimestamp = ntpTime();
367
- this.rtpTimestamp = rtp.header.timestamp;
368
- this.octetCount += rtp.payload.length;
371
+ this.ntpTimestamp = ntptime;
372
+ this.rtpTimestamp = header.timestamp;
373
+ this.octetCount += payload.length;
369
374
  this.packetCount = uint32Add(this.packetCount, 1);
370
375
 
371
- rtp.header = header;
372
-
373
- this.rtpCache.push(rtp);
374
- this.rtpCache = this.rtpCache.slice(-RTP_HISTORY_SIZE);
376
+ this.rtpCache[header.sequenceNumber % RTP_HISTORY_SIZE] = rtp;
375
377
 
376
- let rtpPayload = rtp.payload;
378
+ let rtpPayload = payload;
377
379
 
378
380
  if (this.redRedundantPayloadType) {
379
381
  this.redEncoder.push({
@@ -388,11 +390,12 @@ export class RTCRtpSender {
388
390
  const size = await this.dtlsTransport.sendRtp(rtpPayload, header);
389
391
 
390
392
  this.runRtcp();
393
+ const millitime = milliTime();
391
394
  const sentInfo: SentInfo = {
392
395
  wideSeq: this.dtlsTransport.transportSequenceNumber,
393
396
  size,
394
- sendingAtMs: milliTime(),
395
- sentAtMs: milliTime(),
397
+ sendingAtMs: millitime,
398
+ sentAtMs: millitime,
396
399
  };
397
400
  this.senderBWE.rtpPacketSent(sentInfo);
398
401
  }
@@ -436,9 +439,11 @@ export class RTCRtpSender {
436
439
  {
437
440
  const feedback = packet.feedback as GenericNack;
438
441
  feedback.lost.forEach(async (seqNum) => {
439
- let packet = this.rtpCache.find(
440
- (rtp) => rtp.header.sequenceNumber === seqNum
441
- );
442
+ let packet: RtpPacket | undefined =
443
+ this.rtpCache[seqNum % RTP_HISTORY_SIZE];
444
+ if (packet && packet.header.sequenceNumber !== seqNum) {
445
+ packet = undefined;
446
+ }
442
447
  if (packet) {
443
448
  if (this.rtxPayloadType != undefined) {
444
449
  packet = wrapRtx(
@@ -1,4 +1,5 @@
1
1
  import { appendFile, open, unlink } from "fs/promises";
2
+ import { EventDisposer } from "rx.mini";
2
3
  import { ReadableStreamDefaultReadResult } from "stream/web";
3
4
 
4
5
  import { SupportedCodec } from "../../../../../rtp/src/container/webm";
@@ -18,6 +19,8 @@ const sourcePath = "packages/webrtc/src/nonstandard/recorder/writer/webm.ts";
18
19
  export class WebmFactory extends MediaWriter {
19
20
  rtpSources: RtpSourceStream[] = [];
20
21
 
22
+ unSubscribers = new EventDisposer();
23
+
21
24
  async start(tracks: MediaStreamTrack[]) {
22
25
  await unlink(this.path).catch((e) => e);
23
26
 
@@ -71,16 +74,21 @@ export class WebmFactory extends MediaWriter {
71
74
 
72
75
  this.rtpSources = inputTracks.map(({ track, clockRate, codec }) => {
73
76
  const rtpSource = new RtpSourceStream();
74
- track.onReceiveRtp.subscribe((r) => rtpSource.push(r));
75
77
 
76
- const jitterBuffer = jitterBufferTransformer(clockRate, {
77
- latency: this.options.jitterBufferLatency,
78
- bufferSize: this.options.jitterBufferSize,
79
- });
78
+ track.onReceiveRtp
79
+ .subscribe((rtp) => {
80
+ rtpSource.push(rtp.clone());
81
+ })
82
+ .disposer(this.unSubscribers);
83
+
84
+ // const jitterBuffer = jitterBufferTransformer(clockRate, {
85
+ // latency: this.options.jitterBufferLatency,
86
+ // bufferSize: this.options.jitterBufferSize,
87
+ // });
80
88
 
81
89
  if (track.kind === "video") {
82
90
  rtpSource.readable
83
- .pipeThrough(jitterBuffer)
91
+ // .pipeThrough(jitterBuffer)
84
92
  .pipeThrough(
85
93
  depacketizeTransformer(codec, {
86
94
  waitForKeyframe: this.options.waitForKeyframe,
@@ -90,7 +98,7 @@ export class WebmFactory extends MediaWriter {
90
98
  .pipeTo(webm.videoStream);
91
99
  } else {
92
100
  rtpSource.readable
93
- .pipeThrough(jitterBuffer)
101
+ // .pipeThrough(jitterBuffer)
94
102
  .pipeThrough(depacketizeTransformer(codec))
95
103
  .pipeTo(webm.audioStream);
96
104
  }
@@ -120,6 +128,8 @@ export class WebmFactory extends MediaWriter {
120
128
 
121
129
  async stop() {
122
130
  await Promise.all(this.rtpSources.map((r) => r.stop()));
131
+
132
+ this.unSubscribers.dispose();
123
133
  }
124
134
  }
125
135
 
@@ -49,7 +49,7 @@ export class RTCDtlsTransport {
49
49
 
50
50
  readonly onStateChange = new Event<[DtlsState]>();
51
51
 
52
- localCertificate?: RTCCertificate = this.certificates[0];
52
+ localCertificate?: RTCCertificate;
53
53
  private remoteParameters?: RTCDtlsParameters;
54
54
 
55
55
  constructor(
@@ -58,7 +58,9 @@ export class RTCDtlsTransport {
58
58
  readonly router: RtpRouter,
59
59
  readonly certificates: RTCCertificate[],
60
60
  private readonly srtpProfiles: Profile[] = []
61
- ) {}
61
+ ) {
62
+ this.localCertificate = this.certificates[0];
63
+ }
62
64
 
63
65
  get localParameters() {
64
66
  return new RTCDtlsParameters(
@@ -340,7 +342,9 @@ class IceTransport implements Transport {
340
342
  }
341
343
  onData?: (buf: Buffer) => void;
342
344
 
343
- readonly send = this.ice.send;
345
+ readonly send = (data: Buffer) => {
346
+ return this.ice.send(data);
347
+ };
344
348
 
345
349
  close() {
346
350
  this.ice.close();
@@ -9,7 +9,7 @@ const log = debug("werift:packages/webrtc/src/transport/ice.ts");
9
9
 
10
10
  export class RTCIceTransport {
11
11
  readonly id = v4();
12
- connection = this.gather.connection;
12
+ connection: Connection;
13
13
  state: RTCIceConnectionState = "new";
14
14
 
15
15
  readonly onStateChange = new Event<[RTCIceConnectionState]>();
@@ -17,6 +17,7 @@ export class RTCIceTransport {
17
17
  private waitStart?: Event<[]>;
18
18
 
19
19
  constructor(private gather: RTCIceGatherer) {
20
+ this.connection = this.gather.connection;
20
21
  this.connection.stateChanged.subscribe((state) => {
21
22
  this.setState(state);
22
23
  });
@@ -116,9 +117,11 @@ export class RTCIceGatherer {
116
117
  gatheringState: IceGathererState = "new";
117
118
 
118
119
  readonly onGatheringStateChange = new Event<[IceGathererState]>();
119
- readonly connection = new Connection(false, this.options);
120
+ readonly connection: Connection;
120
121
 
121
- constructor(private options: Partial<IceOptions> = {}) {}
122
+ constructor(private options: Partial<IceOptions> = {}) {
123
+ this.connection = new Connection(false, this.options);
124
+ }
122
125
 
123
126
  async gather() {
124
127
  if (this.gatheringState === "new") {
@@ -381,6 +381,8 @@ class BridgeDtls implements Transport {
381
381
  set onData(onData: (buf: Buffer) => void) {
382
382
  this.dtls.dataReceiver = onData;
383
383
  }
384
- readonly send = this.dtls.sendData;
384
+ readonly send = (data: Buffer) => {
385
+ return this.dtls.sendData(data);
386
+ };
385
387
  close() {}
386
388
  }
@@ -1,36 +0,0 @@
1
- import { DepacketizerOutput } from "./depacketizer";
2
- export declare type AVBufferInput = DepacketizerOutput;
3
- export declare type AVBufferOutput = AVBufferInput;
4
- /**
5
- * @description [japanese]
6
- * audioパケットとvideoパケットを同一のタイムラインで扱い、それぞれの
7
- * パケットのタイムスタンプが前後しないように制御する
8
- */
9
- export declare class AVBufferBase {
10
- private audioOutput;
11
- private videoOutput;
12
- private options;
13
- bufferLength: number;
14
- baseAudioTimestamp?: number;
15
- baseVideoTimestamp?: number;
16
- audioBuffer: (AVBufferInput & {
17
- elapsed: number;
18
- kind: string;
19
- })[][];
20
- videoBuffer: (AVBufferInput & {
21
- elapsed: number;
22
- kind: string;
23
- })[][];
24
- stopped: boolean;
25
- private interval;
26
- private started;
27
- constructor(audioOutput: (output: AVBufferOutput) => void, videoOutput: (output: AVBufferOutput) => void, options?: Partial<AvBufferOptions>);
28
- private start;
29
- processAudioInput: (input: AVBufferInput) => void;
30
- processVideoInput: (input: AVBufferInput) => void;
31
- private calcElapsed;
32
- }
33
- export interface AvBufferOptions {
34
- interval: number;
35
- bufferLength: number;
36
- }
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AVBufferBase = void 0;
4
- const src_1 = require("../../../common/src");
5
- const webm_1 = require("./webm");
6
- /**
7
- * @description [japanese]
8
- * audioパケットとvideoパケットを同一のタイムラインで扱い、それぞれの
9
- * パケットのタイムスタンプが前後しないように制御する
10
- */
11
- class AVBufferBase {
12
- constructor(audioOutput, videoOutput, options = {}) {
13
- this.audioOutput = audioOutput;
14
- this.videoOutput = videoOutput;
15
- this.options = options;
16
- this.bufferLength = this.options.bufferLength ?? 50;
17
- this.audioBuffer = [
18
- ...new Array(this.bufferLength),
19
- ].map(() => []);
20
- this.videoBuffer = [
21
- ...new Array(this.bufferLength),
22
- ].map(() => []);
23
- this.stopped = false;
24
- this.interval = this.options.interval ?? 500;
25
- this.started = false;
26
- this.processAudioInput = (input) => {
27
- if (!input.frame) {
28
- this.stopped = true;
29
- this.audioOutput(input);
30
- return;
31
- }
32
- if (this.stopped) {
33
- return;
34
- }
35
- if (this.baseAudioTimestamp == undefined) {
36
- this.baseAudioTimestamp = input.frame?.timestamp;
37
- }
38
- const { elapsed, rotate } = this.calcElapsed(this.baseAudioTimestamp, input.frame.timestamp, 48000);
39
- if (rotate) {
40
- this.baseAudioTimestamp = input.frame?.timestamp;
41
- }
42
- const index = (0, src_1.int)(elapsed / this.interval) % this.bufferLength;
43
- this.audioBuffer[index].push({ ...input, elapsed, kind: "audio" });
44
- this.start();
45
- };
46
- this.processVideoInput = (input) => {
47
- if (!input.frame) {
48
- this.stopped = true;
49
- this.videoOutput(input);
50
- return;
51
- }
52
- if (this.stopped) {
53
- return;
54
- }
55
- if (this.baseVideoTimestamp == undefined) {
56
- this.baseVideoTimestamp = input.frame?.timestamp;
57
- }
58
- const { elapsed, rotate } = this.calcElapsed(this.baseVideoTimestamp, input.frame.timestamp, 90000);
59
- if (rotate) {
60
- this.baseVideoTimestamp = input.frame?.timestamp;
61
- }
62
- const index = (0, src_1.int)(elapsed / this.interval) % this.bufferLength;
63
- this.videoBuffer[index].push({ ...input, elapsed, kind: "video" });
64
- this.start();
65
- };
66
- }
67
- start() {
68
- if ([...this.audioBuffer[1], ...this.videoBuffer[1]].length === 0) {
69
- return;
70
- }
71
- if (this.started) {
72
- return;
73
- }
74
- this.started = true;
75
- let index = 0;
76
- setInterval(() => {
77
- const joined = [...this.audioBuffer[index], ...this.videoBuffer[index]];
78
- const sorted = joined.sort((a, b) => a.elapsed - b.elapsed);
79
- this.audioBuffer[index] = [];
80
- this.videoBuffer[index] = [];
81
- for (const output of sorted) {
82
- if (output.kind === "audio") {
83
- this.audioOutput(output);
84
- }
85
- else {
86
- this.videoOutput(output);
87
- }
88
- }
89
- index++;
90
- if (index === this.bufferLength) {
91
- index = 0;
92
- }
93
- }, this.interval);
94
- }
95
- calcElapsed(base, timestamp, clockRate) {
96
- const rotate = Math.abs(timestamp - base) > (webm_1.Max32Uint / 4) * 3;
97
- if (rotate) {
98
- console.log(rotate);
99
- }
100
- const diff = rotate ? timestamp + webm_1.Max32Uint - base : timestamp - base;
101
- /**ms */
102
- const elapsed = (0, src_1.int)((diff / clockRate) * 1000);
103
- return { elapsed, rotate };
104
- }
105
- }
106
- exports.AVBufferBase = AVBufferBase;
107
- //# sourceMappingURL=avBuffer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"avBuffer.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/avBuffer.ts"],"names":[],"mappings":"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","sourcesContent":["import { int } from \"../../../common/src\";\nimport { DepacketizerOutput } from \"./depacketizer\";\nimport { Max32Uint } from \"./webm\";\n\nexport type AVBufferInput = DepacketizerOutput;\n\nexport type AVBufferOutput = AVBufferInput;\n\n/**\n * @description [japanese]\n * audioパケットとvideoパケットを同一のタイムラインで扱い、それぞれの\n * パケットのタイムスタンプが前後しないように制御する\n */\nexport class AVBufferBase {\n bufferLength = this.options.bufferLength ?? 50;\n baseAudioTimestamp?: number;\n baseVideoTimestamp?: number;\n audioBuffer: (AVBufferInput & { elapsed: number; kind: string })[][] = [\n ...new Array(this.bufferLength),\n ].map(() => []);\n videoBuffer: (AVBufferInput & { elapsed: number; kind: string })[][] = [\n ...new Array(this.bufferLength),\n ].map(() => []);\n stopped = false;\n private interval = this.options.interval ?? 500;\n private started = false;\n\n constructor(\n private audioOutput: (output: AVBufferOutput) => void,\n private videoOutput: (output: AVBufferOutput) => void,\n private options: Partial<AvBufferOptions> = {}\n ) {}\n\n private start() {\n if ([...this.audioBuffer[1], ...this.videoBuffer[1]].length === 0) {\n return;\n }\n\n if (this.started) {\n return;\n }\n this.started = true;\n\n let index = 0;\n setInterval(() => {\n const joined = [...this.audioBuffer[index], ...this.videoBuffer[index]];\n const sorted = joined.sort((a, b) => a.elapsed - b.elapsed);\n this.audioBuffer[index] = [];\n this.videoBuffer[index] = [];\n\n for (const output of sorted) {\n if (output.kind === \"audio\") {\n this.audioOutput(output);\n } else {\n this.videoOutput(output);\n }\n }\n\n index++;\n if (index === this.bufferLength) {\n index = 0;\n }\n }, this.interval);\n }\n\n processAudioInput = (input: AVBufferInput) => {\n if (!input.frame) {\n this.stopped = true;\n this.audioOutput(input);\n return;\n }\n if (this.stopped) {\n return;\n }\n\n if (this.baseAudioTimestamp == undefined) {\n this.baseAudioTimestamp = input.frame?.timestamp;\n }\n\n const { elapsed, rotate } = this.calcElapsed(\n this.baseAudioTimestamp,\n input.frame.timestamp,\n 48000\n );\n if (rotate) {\n this.baseAudioTimestamp = input.frame?.timestamp;\n }\n\n const index = int(elapsed / this.interval) % this.bufferLength;\n this.audioBuffer[index].push({ ...input, elapsed, kind: \"audio\" });\n\n this.start();\n };\n\n processVideoInput = (input: AVBufferInput) => {\n if (!input.frame) {\n this.stopped = true;\n this.videoOutput(input);\n return;\n }\n if (this.stopped) {\n return;\n }\n\n if (this.baseVideoTimestamp == undefined) {\n this.baseVideoTimestamp = input.frame?.timestamp;\n }\n\n const { elapsed, rotate } = this.calcElapsed(\n this.baseVideoTimestamp,\n input.frame.timestamp,\n 90000\n );\n if (rotate) {\n this.baseVideoTimestamp = input.frame?.timestamp;\n }\n\n const index = int(elapsed / this.interval) % this.bufferLength;\n this.videoBuffer[index].push({ ...input, elapsed, kind: \"video\" });\n\n this.start();\n };\n\n private calcElapsed(base: number, timestamp: number, clockRate: number) {\n const rotate = Math.abs(timestamp - base) > (Max32Uint / 4) * 3;\n if (rotate) {\n console.log(rotate);\n }\n\n const diff = rotate ? timestamp + Max32Uint - base : timestamp - base;\n /**ms */\n const elapsed = int((diff / clockRate) * 1000);\n return { elapsed, rotate };\n }\n}\n\nexport interface AvBufferOptions {\n interval: number;\n bufferLength: number;\n}\n"]}
@@ -1,10 +0,0 @@
1
- import { AVBufferBase, AvBufferOptions, AVBufferOutput } from "./avBuffer";
2
- export declare class AvBufferCallback extends AVBufferBase {
3
- private audioCb;
4
- private videoCb;
5
- constructor(options?: Partial<AvBufferOptions>);
6
- pipeAudio: (cb: (input: AVBufferOutput) => void) => void;
7
- pipeVideo: (cb: (input: AVBufferOutput) => void) => void;
8
- inputAudio: (input: import("./depacketizer").DepacketizerOutput) => void;
9
- inputVideo: (input: import("./depacketizer").DepacketizerOutput) => void;
10
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AvBufferCallback = void 0;
4
- const avBuffer_1 = require("./avBuffer");
5
- class AvBufferCallback extends avBuffer_1.AVBufferBase {
6
- constructor(options = {}) {
7
- super((output) => {
8
- if (this.audioCb) {
9
- this.audioCb(output);
10
- }
11
- }, (output) => {
12
- if (this.videoCb) {
13
- this.videoCb(output);
14
- }
15
- }, options);
16
- this.pipeAudio = (cb) => {
17
- this.audioCb = cb;
18
- };
19
- this.pipeVideo = (cb) => {
20
- this.videoCb = cb;
21
- };
22
- this.inputAudio = this.processAudioInput;
23
- this.inputVideo = this.processVideoInput;
24
- }
25
- }
26
- exports.AvBufferCallback = AvBufferCallback;
27
- //# sourceMappingURL=avBufferCallback.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"avBufferCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/avBufferCallback.ts"],"names":[],"mappings":";;;AAAA,yCAA2E;AAE3E,MAAa,gBAAiB,SAAQ,uBAAY;IAGhD,YAAY,UAAoC,EAAE;QAChD,KAAK,CACH,CAAC,MAAM,EAAE,EAAE;YACT,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACtB;QACH,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;YACT,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACtB;QACH,CAAC,EACD,OAAO,CACR,CAAC;QAGJ,cAAS,GAAG,CAAC,EAAmC,EAAE,EAAE;YAClD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC;QACF,cAAS,GAAG,CAAC,EAAmC,EAAE,EAAE;YAClD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC;QAEF,eAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC;QACpC,eAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC;IAVpC,CAAC;CAWF;AA5BD,4CA4BC","sourcesContent":["import { AVBufferBase, AvBufferOptions, AVBufferOutput } from \"./avBuffer\";\n\nexport class AvBufferCallback extends AVBufferBase {\n private audioCb!: (input: AVBufferOutput) => void;\n private videoCb!: (input: AVBufferOutput) => void;\n constructor(options: Partial<AvBufferOptions> = {}) {\n super(\n (output) => {\n if (this.audioCb) {\n this.audioCb(output);\n }\n },\n (output) => {\n if (this.videoCb) {\n this.videoCb(output);\n }\n },\n options\n );\n }\n\n pipeAudio = (cb: (input: AVBufferOutput) => void) => {\n this.audioCb = cb;\n };\n pipeVideo = (cb: (input: AVBufferOutput) => void) => {\n this.videoCb = cb;\n };\n\n inputAudio = this.processAudioInput;\n inputVideo = this.processVideoInput;\n}\n"]}