werift 0.17.6 → 0.18.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.
- package/lib/common/src/binary.d.ts +1 -0
- package/lib/common/src/binary.js +74 -21
- package/lib/common/src/binary.js.map +1 -1
- package/lib/common/src/log.js +18 -0
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/network.d.ts +1 -1
- package/lib/common/src/network.js +1 -0
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/promise.js +22 -7
- package/lib/common/src/promise.js.map +1 -1
- package/lib/common/src/type.d.ts +1 -1
- package/lib/dtls/src/cipher/const.d.ts +7 -7
- package/lib/dtls/src/cipher/key-exchange.js +24 -1
- package/lib/dtls/src/cipher/key-exchange.js.map +1 -1
- package/lib/dtls/src/cipher/suites/abstract.d.ts +2 -2
- package/lib/dtls/src/cipher/suites/abstract.js +36 -2
- package/lib/dtls/src/cipher/suites/abstract.js.map +1 -1
- package/lib/dtls/src/cipher/suites/aead.js +60 -6
- package/lib/dtls/src/cipher/suites/aead.js.map +1 -1
- package/lib/dtls/src/client.js +62 -51
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/cipher.js +151 -59
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/dtls/src/context/dtls.js +90 -14
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/srtp.d.ts +1 -1
- package/lib/dtls/src/context/srtp.js +8 -0
- package/lib/dtls/src/context/srtp.js.map +1 -1
- package/lib/dtls/src/context/transport.js +14 -2
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight1.js +6 -1
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +12 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +1 -1
- package/lib/dtls/src/flight/flight.js +42 -7
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight2.js +4 -2
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +12 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +6 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/ellipticCurves.js +27 -7
- package/lib/dtls/src/handshake/extensions/ellipticCurves.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/extendedMasterSecret.js +6 -1
- package/lib/dtls/src/handshake/extensions/extendedMasterSecret.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/renegotiationIndication.js +27 -7
- package/lib/dtls/src/handshake/extensions/renegotiationIndication.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/signature.js +27 -7
- package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/useSrtp.js +39 -9
- package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +21 -6
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +26 -5
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +14 -4
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +33 -7
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +68 -18
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +26 -5
- package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/message/finished.js +18 -2
- package/lib/dtls/src/handshake/message/finished.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +40 -9
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +60 -14
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js +18 -2
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +33 -7
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +75 -19
- package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/random.js +21 -6
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/record/builder.d.ts +1 -1
- package/lib/dtls/src/record/message/fragment.js +49 -14
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +84 -24
- package/lib/dtls/src/record/message/header.js.map +1 -1
- package/lib/dtls/src/record/message/plaintext.js +21 -6
- package/lib/dtls/src/record/message/plaintext.js.map +1 -1
- package/lib/dtls/src/server.js +59 -42
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.js +153 -64
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/dtls/src/transport.js +38 -11
- package/lib/dtls/src/transport.js.map +1 -1
- package/lib/dtls/src/typings/domain.d.ts +4 -4
- package/lib/ice/src/candidate.js +66 -11
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/dns/lookup.js +12 -1
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.js +27 -2
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/helper.d.ts +1 -1
- package/lib/ice/src/helper.js +12 -2
- package/lib/ice/src/helper.js.map +1 -1
- package/lib/ice/src/ice.d.ts +9 -3
- package/lib/ice/src/ice.js +407 -155
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/stun/attributes.d.ts +3 -3
- package/lib/ice/src/stun/attributes.js +6 -1
- package/lib/ice/src/stun/attributes.js.map +1 -1
- package/lib/ice/src/stun/message.d.ts +4 -0
- package/lib/ice/src/stun/message.js +24 -3
- package/lib/ice/src/stun/message.js.map +1 -1
- package/lib/ice/src/stun/protocol.js +64 -15
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.js +99 -36
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/transport.js +57 -21
- package/lib/ice/src/transport.js.map +1 -1
- package/lib/ice/src/turn/protocol.js +176 -40
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +1 -1
- package/lib/rtp/src/codec/av1.d.ts +1 -1
- package/lib/rtp/src/codec/av1.js +118 -30
- package/lib/rtp/src/codec/av1.js.map +1 -1
- package/lib/rtp/src/codec/base.js +8 -0
- package/lib/rtp/src/codec/base.js.map +1 -1
- package/lib/rtp/src/codec/h264.js +55 -0
- package/lib/rtp/src/codec/h264.js.map +1 -1
- package/lib/rtp/src/codec/index.d.ts +2 -0
- package/lib/rtp/src/codec/index.js +12 -2
- package/lib/rtp/src/codec/index.js.map +1 -1
- package/lib/rtp/src/codec/opus.js +8 -0
- package/lib/rtp/src/codec/opus.js.map +1 -1
- package/lib/rtp/src/codec/vp8.js +102 -3
- package/lib/rtp/src/codec/vp8.js.map +1 -1
- package/lib/rtp/src/codec/vp9.js +164 -7
- package/lib/rtp/src/codec/vp9.js.map +1 -1
- package/lib/rtp/src/container/ebml/ebml.js +30 -3
- package/lib/rtp/src/container/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/container/webm.d.ts +1 -1
- package/lib/rtp/src/container/webm.js +44 -13
- package/lib/rtp/src/container/webm.js.map +1 -1
- package/lib/rtp/src/processor/depacketizer.d.ts +16 -8
- package/lib/rtp/src/processor/depacketizer.js +59 -22
- package/lib/rtp/src/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/processor/depacketizerCallback.js +24 -8
- package/lib/rtp/src/processor/depacketizerCallback.js.map +1 -1
- package/lib/rtp/src/processor/depacketizerTransformer.d.ts +2 -2
- package/lib/rtp/src/processor/depacketizerTransformer.js +6 -0
- package/lib/rtp/src/processor/depacketizerTransformer.js.map +1 -1
- package/lib/rtp/src/processor/index.d.ts +4 -2
- package/lib/rtp/src/processor/index.js +4 -2
- package/lib/rtp/src/processor/index.js.map +1 -1
- package/lib/rtp/src/processor/interface.d.ts +4 -0
- package/lib/rtp/src/processor/interface.js.map +1 -1
- package/lib/rtp/src/processor/jitterBuffer.d.ts +2 -1
- package/lib/rtp/src/processor/jitterBuffer.js +40 -8
- package/lib/rtp/src/processor/jitterBuffer.js.map +1 -1
- package/lib/rtp/src/processor/jitterBufferCallback.js +30 -9
- package/lib/rtp/src/processor/jitterBufferCallback.js.map +1 -1
- package/lib/rtp/src/processor/jitterBufferTransformer.js +12 -1
- package/lib/rtp/src/processor/jitterBufferTransformer.js.map +1 -1
- package/lib/rtp/src/processor/lipsync.d.ts +42 -0
- package/lib/rtp/src/processor/lipsync.js +178 -0
- package/lib/rtp/src/processor/lipsync.js.map +1 -0
- package/lib/rtp/src/processor/lipsyncCallback.d.ts +10 -0
- package/lib/rtp/src/processor/lipsyncCallback.js +59 -0
- package/lib/rtp/src/processor/lipsyncCallback.js.map +1 -0
- package/lib/rtp/src/processor/ntpTime.d.ts +24 -0
- package/lib/rtp/src/processor/ntpTime.js +91 -0
- package/lib/rtp/src/processor/ntpTime.js.map +1 -0
- package/lib/rtp/src/processor/ntpTimeCallback.d.ts +7 -0
- package/lib/rtp/src/processor/ntpTimeCallback.js +36 -0
- package/lib/rtp/src/processor/ntpTimeCallback.js.map +1 -0
- package/lib/rtp/src/processor/source/index.d.ts +1 -0
- package/lib/rtp/src/processor/source/index.js +1 -0
- package/lib/rtp/src/processor/source/index.js.map +1 -1
- package/lib/rtp/src/processor/source/rtcpCallback.d.ts +12 -0
- package/lib/rtp/src/processor/source/rtcpCallback.js +33 -0
- package/lib/rtp/src/processor/source/rtcpCallback.js.map +1 -0
- package/lib/rtp/src/processor/source/rtpCallback.js +28 -12
- package/lib/rtp/src/processor/source/rtpCallback.js.map +1 -1
- package/lib/rtp/src/processor/source/rtpStream.js +38 -10
- package/lib/rtp/src/processor/source/rtpStream.js.map +1 -1
- package/lib/rtp/src/processor/webm.d.ts +11 -4
- package/lib/rtp/src/processor/webm.js +169 -46
- package/lib/rtp/src/processor/webm.js.map +1 -1
- package/lib/rtp/src/processor/webmCallback.d.ts +5 -3
- package/lib/rtp/src/processor/webmCallback.js +52 -8
- package/lib/rtp/src/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/processor/webmStream.d.ts +2 -2
- package/lib/rtp/src/processor/webmStream.js +24 -0
- package/lib/rtp/src/processor/webmStream.js.map +1 -1
- package/lib/rtp/src/processor_old/base.d.ts +18 -0
- package/lib/rtp/src/processor_old/base.js +51 -0
- package/lib/rtp/src/processor_old/base.js.map +1 -0
- package/lib/rtp/src/processor_old/lipsync.d.ts +30 -0
- package/lib/rtp/src/processor_old/lipsync.js +119 -0
- package/lib/rtp/src/processor_old/lipsync.js.map +1 -0
- package/lib/rtp/src/rtcp/header.js +30 -5
- package/lib/rtp/src/rtcp/header.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +30 -3
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/index.d.ts +1 -1
- package/lib/rtp/src/rtcp/psfb/index.js +18 -2
- package/lib/rtp/src/rtcp/psfb/index.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/pictureLossIndication.js +30 -3
- package/lib/rtp/src/rtcp/psfb/pictureLossIndication.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/remb.js +66 -5
- package/lib/rtp/src/rtcp/psfb/remb.js.map +1 -1
- package/lib/rtp/src/rtcp/rr.js +68 -4
- package/lib/rtp/src/rtcp/rr.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.d.ts +1 -1
- package/lib/rtp/src/rtcp/rtpfb/index.d.ts +1 -1
- package/lib/rtp/src/rtcp/rtpfb/index.js +24 -2
- package/lib/rtp/src/rtcp/rtpfb/index.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/nack.d.ts +5 -0
- package/lib/rtp/src/rtcp/rtpfb/nack.js +43 -3
- package/lib/rtp/src/rtcp/rtpfb/nack.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/twcc.js +154 -11
- package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
- package/lib/rtp/src/rtcp/sdes.js +42 -4
- package/lib/rtp/src/rtcp/sdes.js.map +1 -1
- package/lib/rtp/src/rtcp/sr.js +56 -5
- package/lib/rtp/src/rtcp/sr.js.map +1 -1
- package/lib/rtp/src/rtp/red/encoder.js +18 -3
- package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
- package/lib/rtp/src/rtp/red/handler.js +12 -2
- package/lib/rtp/src/rtp/red/handler.js.map +1 -1
- package/lib/rtp/src/rtp/red/packet.js +18 -2
- package/lib/rtp/src/rtp/red/packet.js.map +1 -1
- package/lib/rtp/src/rtp/rtp.d.ts +3 -3
- package/lib/rtp/src/rtp/rtp.js +104 -17
- package/lib/rtp/src/rtp/rtp.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/ctr.js +26 -10
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.d.ts +3 -0
- package/lib/rtp/src/srtp/cipher/gcm.js +40 -20
- package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/index.js +24 -4
- package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
- package/lib/rtp/src/srtp/const.d.ts +1 -1
- package/lib/rtp/src/srtp/context/context.d.ts +1 -1
- package/lib/rtp/src/srtp/context/context.js +84 -5
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/rtp/src/srtp/session.d.ts +2 -2
- package/lib/rtp/src/srtp/session.js +24 -1
- package/lib/rtp/src/srtp/session.js.map +1 -1
- package/lib/rtp/src/srtp/srtcp.js +15 -5
- package/lib/rtp/src/srtp/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/srtp.js +15 -5
- package/lib/rtp/src/srtp/srtp.js.map +1 -1
- package/lib/sctp/src/chunk.js +349 -69
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/helper.d.ts +1 -1
- package/lib/sctp/src/param.d.ts +3 -3
- package/lib/sctp/src/param.js +66 -11
- package/lib/sctp/src/param.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +1 -1
- package/lib/sctp/src/sctp.js +479 -138
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/sctp/src/transport.js +31 -10
- package/lib/sctp/src/transport.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +1 -1
- package/lib/webrtc/src/dataChannel.js +145 -15
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.js +37 -12
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/parameters.d.ts +1 -1
- package/lib/webrtc/src/media/parameters.js +124 -3
- package/lib/webrtc/src/media/parameters.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +4 -4
- package/lib/webrtc/src/media/receiver/nack.js +85 -33
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +42 -6
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/receiver/statistics.js +61 -5
- package/lib/webrtc/src/media/receiver/statistics.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +1 -1
- package/lib/webrtc/src/media/router.js +108 -83
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.js +188 -33
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.js +279 -42
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +2 -2
- package/lib/webrtc/src/media/rtpTransceiver.js +102 -18
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/cumulativeResult.js +36 -6
- package/lib/webrtc/src/media/sender/cumulativeResult.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderBWE.js +57 -12
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/track.js +135 -24
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +7 -4
- package/lib/webrtc/src/nonstandard/recorder/index.js +50 -6
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js +12 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +39 -35
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +158 -56
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +2 -2
- package/lib/webrtc/src/peerConnection.js +260 -58
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sdp.js +287 -24
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +3 -3
- package/lib/webrtc/src/transport/dtls.js +185 -30
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +2 -2
- package/lib/webrtc/src/transport/ice.js +193 -25
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.js +193 -101
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/types/domain.d.ts +3 -3
- package/lib/webrtc/src/types/util.d.ts +2 -2
- package/lib/webrtc/src/utils.js +12 -2
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +15 -15
- package/src/dataChannel.ts +3 -1
- package/src/media/receiver/nack.ts +23 -19
- package/src/media/rtpReceiver.ts +5 -0
- package/src/media/rtpSender.ts +22 -19
- package/src/nonstandard/recorder/index.ts +12 -4
- package/src/nonstandard/recorder/writer/webm.ts +42 -50
- package/src/transport/dtls.ts +7 -3
- package/src/transport/ice.ts +6 -3
- package/src/transport/sctp.ts +3 -1
- package/lib/rtp/src/processor/avBuffer.d.ts +0 -36
- package/lib/rtp/src/processor/avBuffer.js +0 -107
- package/lib/rtp/src/processor/avBuffer.js.map +0 -1
- package/lib/rtp/src/processor/avBufferCallback.d.ts +0 -10
- package/lib/rtp/src/processor/avBufferCallback.js +0 -27
- package/lib/rtp/src/processor/avBufferCallback.js.map +0 -1
|
@@ -22,41 +22,42 @@ 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
|
}
|
|
44
32
|
|
|
45
|
-
getLost(seq: number) {
|
|
33
|
+
private getLost(seq: number) {
|
|
46
34
|
return this._lost[seq];
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
setLost(seq: number, count: number) {
|
|
37
|
+
private 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
|
-
removeLost(sequenceNumber: number) {
|
|
56
|
+
private removeLost(sequenceNumber: number) {
|
|
54
57
|
delete this._lost[sequenceNumber];
|
|
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
|
});
|
package/src/media/rtpReceiver.ts
CHANGED
package/src/media/rtpSender.ts
CHANGED
|
@@ -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;
|
|
@@ -315,7 +316,7 @@ export class RTCRtpSender {
|
|
|
315
316
|
|
|
316
317
|
rtp = Buffer.isBuffer(rtp) ? RtpPacket.deSerialize(rtp) : rtp;
|
|
317
318
|
|
|
318
|
-
const header = rtp
|
|
319
|
+
const { header, payload } = rtp;
|
|
319
320
|
header.ssrc = this.ssrc;
|
|
320
321
|
header.payloadType = this.codec.payloadType;
|
|
321
322
|
header.timestamp = uint32Add(header.timestamp, this.timestampOffset);
|
|
@@ -323,6 +324,8 @@ export class RTCRtpSender {
|
|
|
323
324
|
this.timestamp = header.timestamp;
|
|
324
325
|
this.sequenceNumber = header.sequenceNumber;
|
|
325
326
|
|
|
327
|
+
const ntptime = ntpTime();
|
|
328
|
+
|
|
326
329
|
header.extensions = this.headerExtensions
|
|
327
330
|
.map((extension) => {
|
|
328
331
|
const payload = (() => {
|
|
@@ -355,7 +358,7 @@ export class RTCRtpSender {
|
|
|
355
358
|
);
|
|
356
359
|
case RTP_EXTENSION_URI.absSendTime:
|
|
357
360
|
const buf = Buffer.alloc(3);
|
|
358
|
-
const time = (
|
|
361
|
+
const time = (ntptime >> 14n) & 0x00ffffffn;
|
|
359
362
|
buf.writeUIntBE(Number(time), 0, 3);
|
|
360
363
|
return buf;
|
|
361
364
|
}
|
|
@@ -365,17 +368,14 @@ export class RTCRtpSender {
|
|
|
365
368
|
})
|
|
366
369
|
.filter((v) => v) as Extension[];
|
|
367
370
|
|
|
368
|
-
this.ntpTimestamp =
|
|
369
|
-
this.rtpTimestamp =
|
|
370
|
-
this.octetCount +=
|
|
371
|
+
this.ntpTimestamp = ntptime;
|
|
372
|
+
this.rtpTimestamp = header.timestamp;
|
|
373
|
+
this.octetCount += payload.length;
|
|
371
374
|
this.packetCount = uint32Add(this.packetCount, 1);
|
|
372
375
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.rtpCache.push(rtp);
|
|
376
|
-
this.rtpCache = this.rtpCache.slice(-RTP_HISTORY_SIZE);
|
|
376
|
+
this.rtpCache[header.sequenceNumber % RTP_HISTORY_SIZE] = rtp;
|
|
377
377
|
|
|
378
|
-
let rtpPayload =
|
|
378
|
+
let rtpPayload = payload;
|
|
379
379
|
|
|
380
380
|
if (this.redRedundantPayloadType) {
|
|
381
381
|
this.redEncoder.push({
|
|
@@ -390,11 +390,12 @@ export class RTCRtpSender {
|
|
|
390
390
|
const size = await this.dtlsTransport.sendRtp(rtpPayload, header);
|
|
391
391
|
|
|
392
392
|
this.runRtcp();
|
|
393
|
+
const millitime = milliTime();
|
|
393
394
|
const sentInfo: SentInfo = {
|
|
394
395
|
wideSeq: this.dtlsTransport.transportSequenceNumber,
|
|
395
396
|
size,
|
|
396
|
-
sendingAtMs:
|
|
397
|
-
sentAtMs:
|
|
397
|
+
sendingAtMs: millitime,
|
|
398
|
+
sentAtMs: millitime,
|
|
398
399
|
};
|
|
399
400
|
this.senderBWE.rtpPacketSent(sentInfo);
|
|
400
401
|
}
|
|
@@ -438,9 +439,11 @@ export class RTCRtpSender {
|
|
|
438
439
|
{
|
|
439
440
|
const feedback = packet.feedback as GenericNack;
|
|
440
441
|
feedback.lost.forEach(async (seqNum) => {
|
|
441
|
-
let packet =
|
|
442
|
-
|
|
443
|
-
)
|
|
442
|
+
let packet: RtpPacket | undefined =
|
|
443
|
+
this.rtpCache[seqNum % RTP_HISTORY_SIZE];
|
|
444
|
+
if (packet && packet.header.sequenceNumber !== seqNum) {
|
|
445
|
+
packet = undefined;
|
|
446
|
+
}
|
|
444
447
|
if (packet) {
|
|
445
448
|
if (this.rtxPayloadType != undefined) {
|
|
446
449
|
packet = wrapRtx(
|
|
@@ -5,10 +5,12 @@ import { WebmFactory } from "./writer/webm";
|
|
|
5
5
|
export class MediaRecorder {
|
|
6
6
|
writer: MediaWriter;
|
|
7
7
|
ext: string;
|
|
8
|
+
tracks: MediaStreamTrack[] = [];
|
|
9
|
+
started = false;
|
|
8
10
|
|
|
9
11
|
constructor(
|
|
10
|
-
public tracks: MediaStreamTrack[],
|
|
11
12
|
public path: string,
|
|
13
|
+
public numOfTracks = 1,
|
|
12
14
|
public options: Partial<MediaRecorderOptions> = {}
|
|
13
15
|
) {
|
|
14
16
|
this.ext = path.split(".").slice(-1)[0];
|
|
@@ -20,14 +22,19 @@ export class MediaRecorder {
|
|
|
20
22
|
throw new Error();
|
|
21
23
|
}
|
|
22
24
|
})();
|
|
25
|
+
this.tracks = options.tracks ?? this.tracks;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
addTrack(track: MediaStreamTrack) {
|
|
28
|
+
async addTrack(track: MediaStreamTrack) {
|
|
26
29
|
this.tracks.push(track);
|
|
30
|
+
await this.start();
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
async start() {
|
|
30
|
-
|
|
33
|
+
private async start() {
|
|
34
|
+
if (this.tracks.length === this.numOfTracks && this.started === false) {
|
|
35
|
+
this.started = true;
|
|
36
|
+
await this.writer.start(this.tracks);
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
async stop() {
|
|
@@ -42,4 +49,5 @@ export interface MediaRecorderOptions {
|
|
|
42
49
|
jitterBufferSize: number;
|
|
43
50
|
waitForKeyframe: boolean;
|
|
44
51
|
defaultDuration: number;
|
|
52
|
+
tracks: MediaStreamTrack[];
|
|
45
53
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { unlink } from "fs/promises";
|
|
2
2
|
import { EventDisposer } from "rx.mini";
|
|
3
|
-
import { ReadableStreamDefaultReadResult } from "stream/web";
|
|
4
3
|
|
|
5
4
|
import { SupportedCodec } from "../../../../../rtp/src/container/webm";
|
|
6
5
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
DepacketizeCallback,
|
|
7
|
+
JitterBufferCallback,
|
|
8
|
+
LipsyncCallback,
|
|
9
9
|
MediaStreamTrack,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
NtpTimeCallback,
|
|
11
|
+
RtcpSourceCallback,
|
|
12
|
+
RtpSourceCallback,
|
|
13
|
+
saveToFileSystem,
|
|
14
|
+
WebmCallback,
|
|
13
15
|
WeriftError,
|
|
14
16
|
} from "../../..";
|
|
15
17
|
import { MediaWriter } from ".";
|
|
@@ -17,7 +19,7 @@ import { MediaWriter } from ".";
|
|
|
17
19
|
const sourcePath = "packages/webrtc/src/nonstandard/recorder/writer/webm.ts";
|
|
18
20
|
|
|
19
21
|
export class WebmFactory extends MediaWriter {
|
|
20
|
-
rtpSources:
|
|
22
|
+
rtpSources: RtpSourceCallback[] = [];
|
|
21
23
|
|
|
22
24
|
unSubscribers = new EventDisposer();
|
|
23
25
|
|
|
@@ -68,67 +70,57 @@ export class WebmFactory extends MediaWriter {
|
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
|
|
71
|
-
const webm = new
|
|
73
|
+
const webm = new WebmCallback(inputTracks, {
|
|
72
74
|
duration: this.options.defaultDuration ?? 1000 * 60 * 60 * 24,
|
|
73
75
|
});
|
|
76
|
+
const lipsync = new LipsyncCallback();
|
|
74
77
|
|
|
75
78
|
this.rtpSources = inputTracks.map(({ track, clockRate, codec }) => {
|
|
76
|
-
const rtpSource = new
|
|
77
|
-
|
|
79
|
+
const rtpSource = new RtpSourceCallback();
|
|
80
|
+
const rtcpSource = new RtcpSourceCallback();
|
|
78
81
|
track.onReceiveRtp
|
|
79
82
|
.subscribe((rtp) => {
|
|
80
|
-
rtpSource.
|
|
83
|
+
rtpSource.input(rtp.clone());
|
|
81
84
|
})
|
|
82
85
|
.disposer(this.unSubscribers);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
track.onReceiveRtcp
|
|
87
|
+
.subscribe((rtcp) => {
|
|
88
|
+
rtcpSource.input(rtcp);
|
|
89
|
+
})
|
|
90
|
+
.disposer(this.unSubscribers);
|
|
91
|
+
const ntpTime = new NtpTimeCallback(clockRate);
|
|
88
92
|
|
|
89
93
|
if (track.kind === "video") {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
const depacketizer = new DepacketizeCallback(codec, {
|
|
95
|
+
isFinalPacketInSequence: (h) => h.marker,
|
|
96
|
+
});
|
|
97
|
+
const jitterBuffer = new JitterBufferCallback(clockRate);
|
|
98
|
+
|
|
99
|
+
rtpSource.pipe(jitterBuffer.input);
|
|
100
|
+
rtcpSource.pipe(ntpTime.input);
|
|
101
|
+
|
|
102
|
+
jitterBuffer.pipe(ntpTime.input);
|
|
103
|
+
ntpTime.pipe(depacketizer.input);
|
|
104
|
+
depacketizer.pipe(lipsync.inputVideo);
|
|
105
|
+
lipsync.pipeVideo(webm.inputVideo);
|
|
99
106
|
} else {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
const depacketizer = new DepacketizeCallback(codec);
|
|
108
|
+
|
|
109
|
+
rtpSource.pipe(ntpTime.input);
|
|
110
|
+
rtcpSource.pipe(ntpTime.input);
|
|
111
|
+
|
|
112
|
+
ntpTime.pipe(depacketizer.input);
|
|
113
|
+
depacketizer.pipe(lipsync.inputAudio);
|
|
114
|
+
lipsync.pipeAudio(webm.inputAudio);
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
return rtpSource;
|
|
107
118
|
});
|
|
108
|
-
|
|
109
|
-
const reader = webm.webmStream.getReader();
|
|
110
|
-
const readChunk = async ({
|
|
111
|
-
value,
|
|
112
|
-
done,
|
|
113
|
-
}: ReadableStreamDefaultReadResult<WebmStreamOutput>) => {
|
|
114
|
-
if (done) return;
|
|
115
|
-
|
|
116
|
-
if (value.saveToFile) {
|
|
117
|
-
await appendFile(this.path, value.saveToFile);
|
|
118
|
-
} else if (value.eol) {
|
|
119
|
-
const { durationElement } = value.eol;
|
|
120
|
-
const handler = await open(this.path, "r+");
|
|
121
|
-
await handler.write(durationElement, 0, durationElement.length, 83);
|
|
122
|
-
await handler.close();
|
|
123
|
-
}
|
|
124
|
-
reader.read().then(readChunk);
|
|
125
|
-
};
|
|
126
|
-
reader.read().then(readChunk);
|
|
119
|
+
webm.pipe(saveToFileSystem(this.path));
|
|
127
120
|
}
|
|
128
121
|
|
|
129
122
|
async stop() {
|
|
130
123
|
await Promise.all(this.rtpSources.map((r) => r.stop()));
|
|
131
|
-
|
|
132
124
|
this.unSubscribers.dispose();
|
|
133
125
|
}
|
|
134
126
|
}
|
package/src/transport/dtls.ts
CHANGED
|
@@ -49,7 +49,7 @@ export class RTCDtlsTransport {
|
|
|
49
49
|
|
|
50
50
|
readonly onStateChange = new Event<[DtlsState]>();
|
|
51
51
|
|
|
52
|
-
localCertificate?: RTCCertificate
|
|
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 =
|
|
345
|
+
readonly send = (data: Buffer) => {
|
|
346
|
+
return this.ice.send(data);
|
|
347
|
+
};
|
|
344
348
|
|
|
345
349
|
close() {
|
|
346
350
|
this.ice.close();
|
package/src/transport/ice.ts
CHANGED
|
@@ -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
|
|
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
|
|
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") {
|
package/src/transport/sctp.ts
CHANGED
|
@@ -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 =
|
|
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"]}
|