werift 0.26.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.
- package/README.md +182 -8
- package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
- package/lib/common/src/binary.d.ts +1 -3
- package/lib/common/src/binary.js +8 -6
- package/lib/common/src/binary.js.map +1 -1
- package/lib/common/src/binaryData.js +2 -1
- package/lib/common/src/binaryData.js.map +1 -1
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/log.js +5 -7
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +12 -5
- package/lib/common/src/transport.js +13 -7
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/client.js +15 -1
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/cipher.d.ts +1 -1
- package/lib/dtls/src/context/cipher.js +6 -3
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +2 -0
- package/lib/dtls/src/context/dtls.js +11 -2
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +17 -1
- package/lib/dtls/src/context/transport.js +40 -3
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight1.js +2 -1
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +8 -3
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +6 -1
- package/lib/dtls/src/flight/flight.js +18 -5
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +4 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +6 -2
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +17 -13
- package/lib/dtls/src/handshake/const.js +16 -14
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +4 -2
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +2 -1
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +14 -7
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/message/finished.js +2 -1
- package/lib/dtls/src/handshake/message/finished.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +12 -6
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
- package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/random.d.ts +2 -2
- package/lib/dtls/src/handshake/random.js +5 -2
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/index.d.ts +3 -1
- package/lib/dtls/src/index.js +10 -1
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/const.d.ts +52 -33
- package/lib/dtls/src/record/const.js +51 -36
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.js +12 -6
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +10 -5
- package/lib/dtls/src/record/message/header.js.map +1 -1
- package/lib/dtls/src/record/message/plaintext.js +4 -2
- package/lib/dtls/src/record/message/plaintext.js.map +1 -1
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +50 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/server.js +19 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +134 -2
- package/lib/dtls/src/socket.js +326 -8
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidate.d.ts +1 -1
- package/lib/ice/src/candidate.js +24 -12
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +49 -0
- package/lib/ice/src/consent.js +258 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/dns/lookup.d.ts +10 -1
- package/lib/ice/src/dns/lookup.js +42 -7
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +21 -5
- package/lib/ice/src/exceptions.js +58 -13
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/ice.d.ts +254 -58
- package/lib/ice/src/ice.js +979 -945
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +328 -14
- package/lib/ice/src/iceBase.js +254 -38
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +1 -0
- package/lib/ice/src/index.js +1 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
- package/lib/ice/src/internal/hostInterfaces.js +77 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
- package/lib/ice/src/nomination/selectionReplacement.js +371 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +9 -2
- package/lib/ice/src/stun/protocol.js +16 -17
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
- package/lib/ice/src/stun/tcpProtocol.js +7 -7
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +30 -1
- package/lib/ice/src/stun/transaction.js +90 -19
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/credential.d.ts +49 -0
- package/lib/ice/src/turn/credential.js +78 -0
- package/lib/ice/src/turn/credential.js.map +1 -0
- package/lib/ice/src/turn/protocol.d.ts +31 -10
- package/lib/ice/src/turn/protocol.js +127 -51
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +16 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.d.ts +2 -0
- package/lib/ice-server/src/stun/attributes.js +11 -1
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +44 -17
- package/lib/ice-server/src/stun/const.js +31 -19
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +29 -4
- package/lib/ice-server/src/stun/message.js +115 -24
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/index.mjs +35121 -22337
- package/lib/nonstandard/index.mjs +3169 -1399
- package/lib/polyfill/dom.mjs +24650 -12365
- package/lib/polyfill/index.mjs +24650 -12365
- package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
- package/lib/rtp/src/codec/assertPayload.js +12 -0
- package/lib/rtp/src/codec/assertPayload.js.map +1 -0
- package/lib/rtp/src/codec/av1.js +2 -0
- package/lib/rtp/src/codec/av1.js.map +1 -1
- package/lib/rtp/src/codec/h264.js +35 -43
- package/lib/rtp/src/codec/h264.js.map +1 -1
- package/lib/rtp/src/codec/vp8.js +11 -5
- package/lib/rtp/src/codec/vp8.js.map +1 -1
- package/lib/rtp/src/codec/vp9.js +12 -0
- package/lib/rtp/src/codec/vp9.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/container.js +2 -1
- package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
- package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
- package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
- package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
- package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
- package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/dtx.js +4 -2
- package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
- package/lib/rtp/src/extra/processor/index.d.ts +2 -0
- package/lib/rtp/src/extra/processor/index.js +2 -0
- package/lib/rtp/src/extra/processor/index.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
- package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
- package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
- package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
- package/lib/rtp/src/extra/processor/lipsync.js +202 -51
- package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
- package/lib/rtp/src/extra/processor/mp4.js +6 -3
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/mute.js +4 -2
- package/lib/rtp/src/extra/processor/mute.js.map +1 -1
- package/lib/rtp/src/extra/processor/nack.js +4 -2
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
- package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
- package/lib/rtp/src/extra/processor/ogg.js +221 -0
- package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
- package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
- package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
- package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
- package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
- package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
- package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/webm.js +14 -7
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/index.d.ts +8 -0
- package/lib/rtp/src/index.js +8 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.js +8 -4
- package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
- package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
- package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
- package/lib/rtp/src/rtcp/sr.js +1 -0
- package/lib/rtp/src/rtcp/sr.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +49 -0
- package/lib/rtp/src/rtp/continuity.js +120 -0
- package/lib/rtp/src/rtp/continuity.js.map +1 -0
- package/lib/rtp/src/rtp/headerExtension.js +41 -21
- package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
- package/lib/rtp/src/rtp/padding.d.ts +17 -0
- package/lib/rtp/src/rtp/padding.js +37 -0
- package/lib/rtp/src/rtp/padding.js.map +1 -0
- package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
- package/lib/rtp/src/rtp/red/encoder.js +14 -1
- package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
- package/lib/rtp/src/rtp/red/packet.js +24 -8
- package/lib/rtp/src/rtp/red/packet.js.map +1 -1
- package/lib/rtp/src/rtp/rtp.d.ts +24 -1
- package/lib/rtp/src/rtp/rtp.js +70 -29
- package/lib/rtp/src/rtp/rtp.js.map +1 -1
- package/lib/rtp/src/rtp/rtx.js +3 -0
- package/lib/rtp/src/rtp/rtx.js.map +1 -1
- package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
- package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
- package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/index.js +8 -4
- package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
- package/lib/rtp/src/srtp/context/context.js +6 -3
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtcp.js +33 -0
- package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtp.js +34 -10
- package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
- package/lib/rtp/src/srtp/error.d.ts +8 -0
- package/lib/rtp/src/srtp/error.js +13 -1
- package/lib/rtp/src/srtp/error.js.map +1 -1
- package/lib/rtp/src/srtp/packet.js +4 -1
- package/lib/rtp/src/srtp/packet.js.map +1 -1
- package/lib/rtp/src/srtp/replay.d.ts +24 -0
- package/lib/rtp/src/srtp/replay.js +75 -0
- package/lib/rtp/src/srtp/replay.js.map +1 -0
- package/lib/rtp/src/srtp/session.js +2 -1
- package/lib/rtp/src/srtp/session.js.map +1 -1
- package/lib/rtp/src/srtp/srtcp.js +2 -1
- package/lib/rtp/src/srtp/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/srtp.js +2 -1
- package/lib/rtp/src/srtp/srtp.js.map +1 -1
- package/lib/rtp/src/util.js +2 -1
- package/lib/rtp/src/util.js.map +1 -1
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +31 -8
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/const.d.ts +25 -17
- package/lib/sctp/src/const.js +23 -19
- package/lib/sctp/src/const.js.map +1 -1
- package/lib/sctp/src/param.d.ts +6 -2
- package/lib/sctp/src/param.js +22 -8
- package/lib/sctp/src/param.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +85 -0
- package/lib/sctp/src/sctp.js +707 -126
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/sctp/src/transport.js +4 -2
- package/lib/sctp/src/transport.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +385 -28
- package/lib/webrtc/src/api/peerConfig.js +121 -14
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +10 -0
- package/lib/webrtc/src/dataChannel.js +24 -4
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/index.d.ts +10 -0
- package/lib/webrtc/src/media/index.js +70 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +246 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +241 -40
- package/lib/webrtc/src/media/router.js +676 -205
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +252 -2
- package/lib/webrtc/src/media/rtpReceiver.js +833 -44
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +191 -70
- package/lib/webrtc/src/media/rtpSender.js +631 -448
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +19 -3
- package/lib/webrtc/src/media/rtpTransceiver.js +74 -9
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
- package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
- package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
- package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
- package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
- package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
- package/lib/webrtc/src/media/sender/padding.js +134 -0
- package/lib/webrtc/src/media/sender/padding.js.map +1 -0
- package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
- package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
- package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
- package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
- package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
- package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
- package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
- package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
- package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -33
- package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +101 -0
- package/lib/webrtc/src/media/sender/senderStats.js +317 -0
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
- package/lib/webrtc/src/media/track.d.ts +29 -2
- package/lib/webrtc/src/media/track.js +32 -5
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
- package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
- package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
- package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
- package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +24 -7
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +67 -27
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +40 -8
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +43 -5
- package/lib/webrtc/src/negotiationTransaction.js +129 -13
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.js +4 -3
- package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
- package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +108 -6
- package/lib/webrtc/src/peerConnection.js +357 -36
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.js +2 -0
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +46 -14
- package/lib/webrtc/src/sctpManager.js +92 -25
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +69 -0
- package/lib/webrtc/src/sdp.js +151 -20
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +85 -4
- package/lib/webrtc/src/sdpManager.js +214 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +89 -4
- package/lib/webrtc/src/secureTransportManager.js +184 -26
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +82 -4
- package/lib/webrtc/src/transceiverManager.js +239 -41
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +147 -1
- package/lib/webrtc/src/transport/dtls.js +446 -50
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +71 -90
- package/lib/webrtc/src/transport/ice.js +250 -42
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +25 -0
- package/lib/webrtc/src/transport/sctp.js +153 -22
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +69 -3
- package/lib/webrtc/src/utils.js +105 -16
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +9 -6
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RtpTimelineRewriter = exports.RtpTimelineDropReason = void 0;
|
|
4
|
+
const src_1 = require("../../../common/src");
|
|
5
|
+
const continuity_1 = require("./continuity");
|
|
6
|
+
const rtp_1 = require("./rtp");
|
|
7
|
+
/**
|
|
8
|
+
* Why {@link RtpTimelineRewriter.rewrite} dropped a packet.
|
|
9
|
+
* - `staleSource`: the packet belongs to a source that was already replaced.
|
|
10
|
+
* - `beforeSourceStart`: the packet is older (by sequence number) than the
|
|
11
|
+
* first packet of the current source, so its output would go back to or
|
|
12
|
+
* before the output of the previous source.
|
|
13
|
+
* @enum
|
|
14
|
+
*/
|
|
15
|
+
exports.RtpTimelineDropReason = {
|
|
16
|
+
staleSource: "staleSource",
|
|
17
|
+
beforeSourceStart: "beforeSourceStart",
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Replaced sources. Entries are never evicted, so a very old packet can never
|
|
21
|
+
* be mistaken for a new source and retire the current one. Object keys are held
|
|
22
|
+
* weakly; primitive keys cost a few bytes per switch.
|
|
23
|
+
*/
|
|
24
|
+
class RetiredSources {
|
|
25
|
+
constructor() {
|
|
26
|
+
Object.defineProperty(this, "primitive", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: new Map()
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "objects", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: new WeakMap()
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static isObject(key) {
|
|
40
|
+
return ((typeof key === "object" && key !== null) || typeof key === "function");
|
|
41
|
+
}
|
|
42
|
+
get(key) {
|
|
43
|
+
return RetiredSources.isObject(key)
|
|
44
|
+
? this.objects.get(key)
|
|
45
|
+
: this.primitive.get(key);
|
|
46
|
+
}
|
|
47
|
+
add(key, ssrc) {
|
|
48
|
+
let entry = this.get(key);
|
|
49
|
+
if (!entry) {
|
|
50
|
+
entry = { all: false, ssrcs: new Set() };
|
|
51
|
+
if (RetiredSources.isObject(key))
|
|
52
|
+
this.objects.set(key, entry);
|
|
53
|
+
else
|
|
54
|
+
this.primitive.set(key, entry);
|
|
55
|
+
}
|
|
56
|
+
if (ssrc === undefined)
|
|
57
|
+
entry.all = true;
|
|
58
|
+
else
|
|
59
|
+
entry.ssrcs.add(ssrc);
|
|
60
|
+
}
|
|
61
|
+
has(key, ssrc, switchOnSsrc) {
|
|
62
|
+
const entry = this.get(key);
|
|
63
|
+
if (!entry)
|
|
64
|
+
return false;
|
|
65
|
+
return entry.all || (switchOnSsrc && entry.ssrcs.has(ssrc));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Signed distance a - b of two 16-bit sequence numbers. */
|
|
69
|
+
const seqDiff = (a, b) => ((a - b) << 16) >> 16;
|
|
70
|
+
/** Signed distance a - b of two 32-bit timestamps. */
|
|
71
|
+
const tsDiff = (a, b) => (a - b) | 0;
|
|
72
|
+
/**
|
|
73
|
+
* Keeps one continuous downstream RTP timeline (sequence number / timestamp,
|
|
74
|
+
* optionally SSRC / payload type) while the upstream RTP source is replaced,
|
|
75
|
+
* for example when an upstream WebRTC connection is recreated and its RTP is
|
|
76
|
+
* forwarded to a long-lived downstream RTP / SRTP session.
|
|
77
|
+
*
|
|
78
|
+
* - The first source is output unchanged (except the fixed `ssrc` / `payloadType`).
|
|
79
|
+
* - Within one source, output = input + offset, so reordering, loss and
|
|
80
|
+
* duplicates keep their relation.
|
|
81
|
+
* - The first packet of a new source continues from the highest output so far:
|
|
82
|
+
* `sequenceNumber + 1`, `timestamp + step` (see {@link RtpTimestampStepMode}).
|
|
83
|
+
* 16-bit sequence numbers and 32-bit timestamps wrap around.
|
|
84
|
+
* - A new source starts when the `source` key passed to {@link rewrite}
|
|
85
|
+
* changes, when the input SSRC changes (`switchOnSsrcChange`, default on) or
|
|
86
|
+
* at the next packet after {@link switchSource}.
|
|
87
|
+
* - Late packets of a replaced source (its `source` key, or its SSRC with
|
|
88
|
+
* `switchOnSsrcChange`) are dropped (`staleSource`). Without keys and SSRC
|
|
89
|
+
* changes, old and new packets cannot be told apart after {@link switchSource};
|
|
90
|
+
* pass a `source` key per upstream connection to drop them.
|
|
91
|
+
* - Packets of a new source that are older (signed 16-bit sequence distance
|
|
92
|
+
* below 0, tracked across wraps) than its first packet are dropped
|
|
93
|
+
* (`beforeSourceStart`): their output would be at or before the previous
|
|
94
|
+
* source's output, which a downstream SRTP receiver rejects as a replay. The
|
|
95
|
+
* first packet and everything after it is accepted. This does not apply to
|
|
96
|
+
* the first source, which has nothing before it.
|
|
97
|
+
*
|
|
98
|
+
* So the output sequence number never goes back to or repeats a number of an
|
|
99
|
+
* earlier source, which keeps the downstream SRTP rollover counter estimation
|
|
100
|
+
* and replay window intact.
|
|
101
|
+
*
|
|
102
|
+
* Padding-only packets are in the media sequence space and are rewritten like
|
|
103
|
+
* media (dropping them would leave sequence gaps), but they do not count as a
|
|
104
|
+
* timestamp increment for `"lastDelta"`. RTX packets have their own SSRC and
|
|
105
|
+
* sequence space: do not pass them to the same instance (restore them to the
|
|
106
|
+
* media stream first, as werift's receiver does, or use a separate instance).
|
|
107
|
+
* Use one instance per downstream stream (audio and video separately).
|
|
108
|
+
*
|
|
109
|
+
* Not handled here: a decoder downstream needs a key frame of the new source,
|
|
110
|
+
* so request one upstream (PLI / FIR, for example
|
|
111
|
+
* `RTCRtpReceiver.sendRtcpPLI`) after a switch. Upstream RTCP Sender Reports
|
|
112
|
+
* carry the upstream SSRC / RTP timestamps; rewrite their RTP timestamp with
|
|
113
|
+
* {@link mapTimestamp} and their SSRC, or generate downstream SRs yourself.
|
|
114
|
+
*/
|
|
115
|
+
class RtpTimelineRewriter {
|
|
116
|
+
constructor(options = {}) {
|
|
117
|
+
/** A new source started on the output ({@link RtpTimelineSwitch}). */
|
|
118
|
+
Object.defineProperty(this, "onSourceSwitch", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: new src_1.Event()
|
|
123
|
+
});
|
|
124
|
+
/** A packet was dropped. Receives the input packet. */
|
|
125
|
+
Object.defineProperty(this, "onDrop", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: new src_1.Event()
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(this, "continuity", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
configurable: true,
|
|
134
|
+
writable: true,
|
|
135
|
+
value: new continuity_1.RtpContinuity()
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(this, "options", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
configurable: true,
|
|
140
|
+
writable: true,
|
|
141
|
+
value: void 0
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(this, "now", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: void 0
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(this, "started", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: false
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(this, "currentSource", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true,
|
|
159
|
+
value: undefined
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(this, "currentSsrc", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
configurable: true,
|
|
164
|
+
writable: true,
|
|
165
|
+
value: void 0
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(this, "retired", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
configurable: true,
|
|
170
|
+
writable: true,
|
|
171
|
+
value: new RetiredSources()
|
|
172
|
+
});
|
|
173
|
+
/** A switch is waiting for the first packet of the new source. */
|
|
174
|
+
Object.defineProperty(this, "pendingSwitch", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: true,
|
|
177
|
+
writable: true,
|
|
178
|
+
value: false
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(this, "pendingTimestampStep", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
configurable: true,
|
|
183
|
+
writable: true,
|
|
184
|
+
value: void 0
|
|
185
|
+
});
|
|
186
|
+
/** The current source continues an earlier one (start check applies). */
|
|
187
|
+
Object.defineProperty(this, "guardSourceStart", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
configurable: true,
|
|
190
|
+
writable: true,
|
|
191
|
+
value: false
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(this, "sourceHasPacket", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: true,
|
|
197
|
+
value: false
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(this, "sourceHighestSeq", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
configurable: true,
|
|
202
|
+
writable: true,
|
|
203
|
+
value: 0
|
|
204
|
+
});
|
|
205
|
+
/** Highest input sequence number of the source, relative to its first packet. */
|
|
206
|
+
Object.defineProperty(this, "sourceHighestExtended", {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
configurable: true,
|
|
209
|
+
writable: true,
|
|
210
|
+
value: 0
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(this, "highestSequenceNumber", {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
configurable: true,
|
|
215
|
+
writable: true,
|
|
216
|
+
value: void 0
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(this, "highestTimestamp", {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true,
|
|
221
|
+
writable: true,
|
|
222
|
+
value: void 0
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(this, "lastTimestampDelta", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
configurable: true,
|
|
227
|
+
writable: true,
|
|
228
|
+
value: void 0
|
|
229
|
+
});
|
|
230
|
+
/** Arrival time of the packet that set `highestTimestamp`. */
|
|
231
|
+
Object.defineProperty(this, "lastPacketTime", {
|
|
232
|
+
enumerable: true,
|
|
233
|
+
configurable: true,
|
|
234
|
+
writable: true,
|
|
235
|
+
value: void 0
|
|
236
|
+
});
|
|
237
|
+
this.options = options;
|
|
238
|
+
this.now = options.now ?? (() => performance.now());
|
|
239
|
+
}
|
|
240
|
+
/** Last output sequence number; undefined before the first packet. */
|
|
241
|
+
get sequenceNumber() {
|
|
242
|
+
return this.continuity.sequenceNumber;
|
|
243
|
+
}
|
|
244
|
+
/** Last output timestamp; undefined before the first packet. */
|
|
245
|
+
get timestamp() {
|
|
246
|
+
return this.continuity.timestamp;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Output timestamp of an input timestamp of the current source (for example
|
|
250
|
+
* to rewrite the RTP timestamp of an upstream Sender Report). Until the first
|
|
251
|
+
* packet of a new source is rewritten, this still uses the previous source's offset.
|
|
252
|
+
*/
|
|
253
|
+
mapTimestamp(inputTimestamp) {
|
|
254
|
+
return this.continuity.mapTimestamp(inputTimestamp);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Start a new source at the next packet.
|
|
258
|
+
* @param options.source `source` key of the new source. When given, packets
|
|
259
|
+
* with the current key are dropped from now on; packets must then carry this key.
|
|
260
|
+
* @param options.timestampStep Timestamp increment for this switch only,
|
|
261
|
+
* instead of {@link RtpTimelineRewriterOptions.timestampStep}.
|
|
262
|
+
*/
|
|
263
|
+
switchSource(options = {}) {
|
|
264
|
+
if ("source" in options && !Object.is(options.source, this.currentSource)) {
|
|
265
|
+
if (this.started) {
|
|
266
|
+
this.retired.add(this.currentSource);
|
|
267
|
+
}
|
|
268
|
+
this.started = true;
|
|
269
|
+
this.currentSource = options.source;
|
|
270
|
+
// The old source's SSRC must not be taken as an SSRC change of the new key.
|
|
271
|
+
this.currentSsrc = undefined;
|
|
272
|
+
}
|
|
273
|
+
this.pendingSwitch = true;
|
|
274
|
+
this.pendingTimestampStep = options.timestampStep;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Rewrite one packet onto the output timeline.
|
|
278
|
+
* @param options.source Identity of the upstream source (for example a
|
|
279
|
+
* connection generation number). A new key starts a new source.
|
|
280
|
+
* @returns the rewritten packet (a clone unless `inPlace`), or undefined when
|
|
281
|
+
* the packet is dropped ({@link RtpTimelineDropReason}).
|
|
282
|
+
*/
|
|
283
|
+
rewrite(packet, options = {}) {
|
|
284
|
+
const source = options.source;
|
|
285
|
+
const ssrc = packet.header.ssrc;
|
|
286
|
+
const switchOnSsrc = this.options.switchOnSsrcChange ?? true;
|
|
287
|
+
if (this.retired.has(source, ssrc, switchOnSsrc)) {
|
|
288
|
+
this.onDrop.execute(packet, exports.RtpTimelineDropReason.staleSource);
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
if (!this.started) {
|
|
292
|
+
this.started = true;
|
|
293
|
+
this.currentSource = source;
|
|
294
|
+
}
|
|
295
|
+
else if (!Object.is(source, this.currentSource)) {
|
|
296
|
+
this.retired.add(this.currentSource);
|
|
297
|
+
this.currentSource = source;
|
|
298
|
+
this.pendingSwitch = true;
|
|
299
|
+
}
|
|
300
|
+
else if (switchOnSsrc &&
|
|
301
|
+
this.currentSsrc !== undefined &&
|
|
302
|
+
ssrc !== this.currentSsrc) {
|
|
303
|
+
this.retired.add(this.currentSource, this.currentSsrc);
|
|
304
|
+
this.pendingSwitch = true;
|
|
305
|
+
}
|
|
306
|
+
const sequenceNumber = packet.header.sequenceNumber;
|
|
307
|
+
const timestamp = packet.header.timestamp;
|
|
308
|
+
const now = this.now();
|
|
309
|
+
let timestampStep;
|
|
310
|
+
if (this.pendingSwitch) {
|
|
311
|
+
this.pendingSwitch = false;
|
|
312
|
+
this.sourceHasPacket = false;
|
|
313
|
+
this.currentSsrc = undefined;
|
|
314
|
+
if (this.highestSequenceNumber !== undefined) {
|
|
315
|
+
timestampStep = this.timestampStepFor(now);
|
|
316
|
+
this.continuity.schedule(timestampStep, {
|
|
317
|
+
sequenceNumber: this.highestSequenceNumber,
|
|
318
|
+
timestamp: this.highestTimestamp,
|
|
319
|
+
});
|
|
320
|
+
this.guardSourceStart = true;
|
|
321
|
+
}
|
|
322
|
+
this.pendingTimestampStep = undefined;
|
|
323
|
+
}
|
|
324
|
+
if (!this.sourceHasPacket) {
|
|
325
|
+
this.sourceHasPacket = true;
|
|
326
|
+
this.currentSsrc = ssrc;
|
|
327
|
+
this.sourceHighestSeq = sequenceNumber;
|
|
328
|
+
this.sourceHighestExtended = 0;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
const diff = seqDiff(sequenceNumber, this.sourceHighestSeq);
|
|
332
|
+
const extended = this.sourceHighestExtended + diff;
|
|
333
|
+
if (this.guardSourceStart && extended < 0) {
|
|
334
|
+
this.onDrop.execute(packet, exports.RtpTimelineDropReason.beforeSourceStart);
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
if (diff > 0) {
|
|
338
|
+
this.sourceHighestSeq = sequenceNumber;
|
|
339
|
+
this.sourceHighestExtended = extended;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const out = this.options.inPlace ? packet : packet.clone();
|
|
343
|
+
const rewritten = this.continuity.assign(out.header, sequenceNumber, timestamp);
|
|
344
|
+
if (this.options.ssrc !== undefined) {
|
|
345
|
+
out.header.ssrc = this.options.ssrc;
|
|
346
|
+
}
|
|
347
|
+
if (this.options.payloadType !== undefined) {
|
|
348
|
+
out.header.payloadType = this.options.payloadType;
|
|
349
|
+
}
|
|
350
|
+
this.observeOutput(out, rewritten, now);
|
|
351
|
+
if (rewritten) {
|
|
352
|
+
this.onSourceSwitch.execute({
|
|
353
|
+
source: this.currentSource,
|
|
354
|
+
inputSsrc: ssrc,
|
|
355
|
+
sequenceNumber: out.header.sequenceNumber,
|
|
356
|
+
timestamp: out.header.timestamp,
|
|
357
|
+
timestampStep: timestampStep,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return out;
|
|
361
|
+
}
|
|
362
|
+
observeOutput(out, rewritten, now) {
|
|
363
|
+
const { sequenceNumber, timestamp } = out.header;
|
|
364
|
+
if (this.highestSequenceNumber === undefined ||
|
|
365
|
+
seqDiff(sequenceNumber, this.highestSequenceNumber) > 0) {
|
|
366
|
+
this.highestSequenceNumber = sequenceNumber;
|
|
367
|
+
}
|
|
368
|
+
// The wall-clock reference is the arrival time of the packet that carries
|
|
369
|
+
// the highest timestamp. Padding (same timestamp) and late packets (older
|
|
370
|
+
// timestamp) must not move it, or the elapsed time added at a switch would
|
|
371
|
+
// differ between streams (audio / video) switched at the same moment.
|
|
372
|
+
if (this.highestTimestamp === undefined) {
|
|
373
|
+
this.highestTimestamp = timestamp;
|
|
374
|
+
this.lastPacketTime = now;
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
const delta = tsDiff(timestamp, this.highestTimestamp);
|
|
378
|
+
if (delta > 0) {
|
|
379
|
+
// The switch increment is synthetic and padding reuses timestamps:
|
|
380
|
+
// neither is an interval of the media itself.
|
|
381
|
+
if (!rewritten && !(0, rtp_1.isPaddingOnlyRtpPacket)(out)) {
|
|
382
|
+
this.lastTimestampDelta = delta;
|
|
383
|
+
}
|
|
384
|
+
this.highestTimestamp = timestamp;
|
|
385
|
+
this.lastPacketTime = now;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
timestampStepFor(now) {
|
|
390
|
+
const fallback = this.options.defaultTimestampStep ?? 1;
|
|
391
|
+
let step;
|
|
392
|
+
if (this.pendingTimestampStep !== undefined) {
|
|
393
|
+
step = this.pendingTimestampStep;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
const mode = this.options.timestampStep ?? "auto";
|
|
397
|
+
if (typeof mode === "number") {
|
|
398
|
+
step = mode;
|
|
399
|
+
}
|
|
400
|
+
else if ((mode === "wallClock" || mode === "auto") &&
|
|
401
|
+
this.options.clockRate !== undefined &&
|
|
402
|
+
this.lastPacketTime !== undefined) {
|
|
403
|
+
step = Math.round(((now - this.lastPacketTime) * this.options.clockRate) / 1000);
|
|
404
|
+
}
|
|
405
|
+
else if (mode === "wallClock") {
|
|
406
|
+
step = fallback;
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
step = this.lastTimestampDelta ?? fallback;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// Keep the new timestamp ahead of the old one in 32-bit signed distance.
|
|
413
|
+
return Math.min(Math.max(1, Math.trunc(step)), 0x7fffffff);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
exports.RtpTimelineRewriter = RtpTimelineRewriter;
|
|
417
|
+
//# sourceMappingURL=timelineRewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timelineRewriter.js","sourceRoot":"","sources":["../../../../../rtp/src/rtp/timelineRewriter.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAC5C,6CAA6C;AAC7C,+BAA+D;AA+D/D;;;;;;;GAOG;AACU,QAAA,qBAAqB,GAAG;IACnC,WAAW,EAAE,aAAa;IAC1B,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC;AAWX;;;;GAIG;AACH,MAAM,cAAc;IAApB;QACmB;;;;mBAAY,IAAI,GAAG,EAAyB;WAAC;QAC7C;;;;mBAAU,IAAI,OAAO,EAAwB;WAAC;IA8BjE,CAAC;IA5BS,MAAM,CAAC,QAAQ,CAAC,GAAY;QAClC,OAAO,CACL,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,OAAO,GAAG,KAAK,UAAU,CACvE,CAAC;IACJ,CAAC;IAEO,GAAG,CAAC,GAAY;QACtB,OAAO,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC;YACjC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;YACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,GAAG,CAAC,GAAY,EAAE,IAAa;QAC7B,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;YACzC,IAAI,cAAc,CAAC,QA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AAC;YAC5C,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,MAAM,CAAC;YAClD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,IAAI,GAAG,IAAI,CAAC;YACd,CAAC;iBAAM,IACL,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,MAAM,CAAC;gBACzC,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS;gBACpC,IAAI,CAAC,cAAc,KAAK,SAAS,EACjC,CAAC;gBACD,IAAI,GAAG,IAAI,CAAC,KAAK,CACf,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,CAC9D,CAAC;YACJ,CAAC;iBAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;gBAChC,IAAI,GAAG,QAAQ,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,IAAI,CAAC,kBAAkB,IAAI,QAAQ,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,yEAAyE;QACzE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;CACF;AAzOD,kDAyOC","sourcesContent":["import { Event } from \"../../../common/src\";\nimport { RtpContinuity } from \"./continuity\";\nimport { isPaddingOnlyRtpPacket, type RtpPacket } from \"./rtp\";\n\n/**\n * How {@link RtpTimelineRewriter} chooses the output timestamp increment\n * between the last packet of the old source and the first packet of the new one.\n *\n * - `number`: that fixed increment (for example `3000` for 30 fps video at 90 kHz).\n * - `\"lastDelta\"`: the last positive timestamp increment seen on the stream\n * (the frame / packet interval of the old source), or\n * {@link RtpTimelineRewriterOptions.defaultTimestampStep} when none was seen yet.\n * - `\"wallClock\"`: the time between the last packet of the old source and the\n * first packet of the new one, times `clockRate / 1000`\n * (requires {@link RtpTimelineRewriterOptions.clockRate}). The reconnect time\n * becomes media time, so separate audio / video rewriters keep their relative\n * position (A/V sync). `\"lastDelta\"` / a fixed number advance audio and video\n * by different amounts, so their relative offset can change at each switch.\n * - `\"auto\"` (default): `\"wallClock\"` when `clockRate` is set, otherwise `\"lastDelta\"`.\n *\n * Every mode advances the timestamp by at least 1.\n */\nexport type RtpTimestampStepMode = number | \"lastDelta\" | \"wallClock\" | \"auto\";\n\nexport interface RtpTimelineRewriterOptions {\n /** RTP clock rate of the stream in Hz (90000 for video). Needed by `\"wallClock\"`. */\n clockRate?: number;\n /** Timestamp increment at a source switch. Default `\"auto\"`. */\n timestampStep?: RtpTimestampStepMode;\n /** Increment used by `\"lastDelta\"` before any increment was seen. Default 1. */\n defaultTimestampStep?: number;\n /** Fixed output SSRC (for example the downstream SRTP SSRC). Default: keep the input SSRC. */\n ssrc?: number;\n /** Fixed output payload type. Default: keep the input payload type. */\n payloadType?: number;\n /**\n * Treat a change of the input SSRC as a source switch, like a new `source`\n * key. Late packets of the previous SSRC are then dropped. Default true.\n * Set false only when the input SSRC changes without a timeline change.\n */\n switchOnSsrcChange?: boolean;\n /**\n * Rewrite the header of the given packet instead of a clone. Default false:\n * received packets (`MediaStreamTrack.onReceiveRtp`) are shared by every\n * subscriber and must not be changed.\n */\n inPlace?: boolean;\n /** Monotonic clock in milliseconds. Default `performance.now()`. For tests. */\n now?: () => number;\n}\n\n/** Notified when output continues from a previous source. */\nexport interface RtpTimelineSwitch {\n /** `source` key of the new source (undefined when keys are not used). */\n source: unknown;\n /** Input SSRC of the new source. */\n inputSsrc: number;\n /** Output sequence number of the first packet of the new source. */\n sequenceNumber: number;\n /** Output timestamp of the first packet of the new source. */\n timestamp: number;\n /** Timestamp increment applied across the switch. */\n timestampStep: number;\n}\n\n/**\n * Why {@link RtpTimelineRewriter.rewrite} dropped a packet.\n * - `staleSource`: the packet belongs to a source that was already replaced.\n * - `beforeSourceStart`: the packet is older (by sequence number) than the\n * first packet of the current source, so its output would go back to or\n * before the output of the previous source.\n * @enum\n */\nexport const RtpTimelineDropReason = {\n staleSource: \"staleSource\",\n beforeSourceStart: \"beforeSourceStart\",\n} as const;\n/** @enum */\nexport type RtpTimelineDropReason =\n (typeof RtpTimelineDropReason)[keyof typeof RtpTimelineDropReason];\n\ninterface RetiredEntry {\n /** every SSRC of the source key is retired. */\n all: boolean;\n ssrcs: Set<number>;\n}\n\n/**\n * Replaced sources. Entries are never evicted, so a very old packet can never\n * be mistaken for a new source and retire the current one. Object keys are held\n * weakly; primitive keys cost a few bytes per switch.\n */\nclass RetiredSources {\n private readonly primitive = new Map<unknown, RetiredEntry>();\n private readonly objects = new WeakMap<object, RetiredEntry>();\n\n private static isObject(key: unknown): key is object {\n return (\n (typeof key === \"object\" && key !== null) || typeof key === \"function\"\n );\n }\n\n private get(key: unknown) {\n return RetiredSources.isObject(key)\n ? this.objects.get(key)\n : this.primitive.get(key);\n }\n\n add(key: unknown, ssrc?: number) {\n let entry = this.get(key);\n if (!entry) {\n entry = { all: false, ssrcs: new Set() };\n if (RetiredSources.isObject(key)) this.objects.set(key, entry);\n else this.primitive.set(key, entry);\n }\n if (ssrc === undefined) entry.all = true;\n else entry.ssrcs.add(ssrc);\n }\n\n has(key: unknown, ssrc: number, switchOnSsrc: boolean) {\n const entry = this.get(key);\n if (!entry) return false;\n return entry.all || (switchOnSsrc && entry.ssrcs.has(ssrc));\n }\n}\n\n/** Signed distance a - b of two 16-bit sequence numbers. */\nconst seqDiff = (a: number, b: number) => ((a - b) << 16) >> 16;\n/** Signed distance a - b of two 32-bit timestamps. */\nconst tsDiff = (a: number, b: number) => (a - b) | 0;\n\n/**\n * Keeps one continuous downstream RTP timeline (sequence number / timestamp,\n * optionally SSRC / payload type) while the upstream RTP source is replaced,\n * for example when an upstream WebRTC connection is recreated and its RTP is\n * forwarded to a long-lived downstream RTP / SRTP session.\n *\n * - The first source is output unchanged (except the fixed `ssrc` / `payloadType`).\n * - Within one source, output = input + offset, so reordering, loss and\n * duplicates keep their relation.\n * - The first packet of a new source continues from the highest output so far:\n * `sequenceNumber + 1`, `timestamp + step` (see {@link RtpTimestampStepMode}).\n * 16-bit sequence numbers and 32-bit timestamps wrap around.\n * - A new source starts when the `source` key passed to {@link rewrite}\n * changes, when the input SSRC changes (`switchOnSsrcChange`, default on) or\n * at the next packet after {@link switchSource}.\n * - Late packets of a replaced source (its `source` key, or its SSRC with\n * `switchOnSsrcChange`) are dropped (`staleSource`). Without keys and SSRC\n * changes, old and new packets cannot be told apart after {@link switchSource};\n * pass a `source` key per upstream connection to drop them.\n * - Packets of a new source that are older (signed 16-bit sequence distance\n * below 0, tracked across wraps) than its first packet are dropped\n * (`beforeSourceStart`): their output would be at or before the previous\n * source's output, which a downstream SRTP receiver rejects as a replay. The\n * first packet and everything after it is accepted. This does not apply to\n * the first source, which has nothing before it.\n *\n * So the output sequence number never goes back to or repeats a number of an\n * earlier source, which keeps the downstream SRTP rollover counter estimation\n * and replay window intact.\n *\n * Padding-only packets are in the media sequence space and are rewritten like\n * media (dropping them would leave sequence gaps), but they do not count as a\n * timestamp increment for `\"lastDelta\"`. RTX packets have their own SSRC and\n * sequence space: do not pass them to the same instance (restore them to the\n * media stream first, as werift's receiver does, or use a separate instance).\n * Use one instance per downstream stream (audio and video separately).\n *\n * Not handled here: a decoder downstream needs a key frame of the new source,\n * so request one upstream (PLI / FIR, for example\n * `RTCRtpReceiver.sendRtcpPLI`) after a switch. Upstream RTCP Sender Reports\n * carry the upstream SSRC / RTP timestamps; rewrite their RTP timestamp with\n * {@link mapTimestamp} and their SSRC, or generate downstream SRs yourself.\n */\nexport class RtpTimelineRewriter {\n /** A new source started on the output ({@link RtpTimelineSwitch}). */\n readonly onSourceSwitch = new Event<[RtpTimelineSwitch]>();\n /** A packet was dropped. Receives the input packet. */\n readonly onDrop = new Event<[RtpPacket, RtpTimelineDropReason]>();\n\n private readonly continuity = new RtpContinuity();\n private readonly options: RtpTimelineRewriterOptions;\n private readonly now: () => number;\n\n private started = false;\n private currentSource: unknown = undefined;\n private currentSsrc?: number;\n private readonly retired = new RetiredSources();\n\n /** A switch is waiting for the first packet of the new source. */\n private pendingSwitch = false;\n private pendingTimestampStep?: number;\n\n /** The current source continues an earlier one (start check applies). */\n private guardSourceStart = false;\n private sourceHasPacket = false;\n private sourceHighestSeq = 0;\n /** Highest input sequence number of the source, relative to its first packet. */\n private sourceHighestExtended = 0;\n\n private highestSequenceNumber?: number;\n private highestTimestamp?: number;\n private lastTimestampDelta?: number;\n /** Arrival time of the packet that set `highestTimestamp`. */\n private lastPacketTime?: number;\n\n constructor(options: RtpTimelineRewriterOptions = {}) {\n this.options = options;\n this.now = options.now ?? (() => performance.now());\n }\n\n /** Last output sequence number; undefined before the first packet. */\n get sequenceNumber() {\n return this.continuity.sequenceNumber;\n }\n\n /** Last output timestamp; undefined before the first packet. */\n get timestamp() {\n return this.continuity.timestamp;\n }\n\n /**\n * Output timestamp of an input timestamp of the current source (for example\n * to rewrite the RTP timestamp of an upstream Sender Report). Until the first\n * packet of a new source is rewritten, this still uses the previous source's offset.\n */\n mapTimestamp(inputTimestamp: number) {\n return this.continuity.mapTimestamp(inputTimestamp);\n }\n\n /**\n * Start a new source at the next packet.\n * @param options.source `source` key of the new source. When given, packets\n * with the current key are dropped from now on; packets must then carry this key.\n * @param options.timestampStep Timestamp increment for this switch only,\n * instead of {@link RtpTimelineRewriterOptions.timestampStep}.\n */\n switchSource(options: { source?: unknown; timestampStep?: number } = {}) {\n if (\"source\" in options && !Object.is(options.source, this.currentSource)) {\n if (this.started) {\n this.retired.add(this.currentSource);\n }\n this.started = true;\n this.currentSource = options.source;\n // The old source's SSRC must not be taken as an SSRC change of the new key.\n this.currentSsrc = undefined;\n }\n this.pendingSwitch = true;\n this.pendingTimestampStep = options.timestampStep;\n }\n\n /**\n * Rewrite one packet onto the output timeline.\n * @param options.source Identity of the upstream source (for example a\n * connection generation number). A new key starts a new source.\n * @returns the rewritten packet (a clone unless `inPlace`), or undefined when\n * the packet is dropped ({@link RtpTimelineDropReason}).\n */\n rewrite(\n packet: RtpPacket,\n options: { source?: unknown } = {},\n ): RtpPacket | undefined {\n const source = options.source;\n const ssrc = packet.header.ssrc;\n const switchOnSsrc = this.options.switchOnSsrcChange ?? true;\n\n if (this.retired.has(source, ssrc, switchOnSsrc)) {\n this.onDrop.execute(packet, RtpTimelineDropReason.staleSource);\n return undefined;\n }\n\n if (!this.started) {\n this.started = true;\n this.currentSource = source;\n } else if (!Object.is(source, this.currentSource)) {\n this.retired.add(this.currentSource);\n this.currentSource = source;\n this.pendingSwitch = true;\n } else if (\n switchOnSsrc &&\n this.currentSsrc !== undefined &&\n ssrc !== this.currentSsrc\n ) {\n this.retired.add(this.currentSource, this.currentSsrc);\n this.pendingSwitch = true;\n }\n\n const sequenceNumber = packet.header.sequenceNumber;\n const timestamp = packet.header.timestamp;\n const now = this.now();\n let timestampStep: number | undefined;\n\n if (this.pendingSwitch) {\n this.pendingSwitch = false;\n this.sourceHasPacket = false;\n this.currentSsrc = undefined;\n if (this.highestSequenceNumber !== undefined) {\n timestampStep = this.timestampStepFor(now);\n this.continuity.schedule(timestampStep, {\n sequenceNumber: this.highestSequenceNumber,\n timestamp: this.highestTimestamp!,\n });\n this.guardSourceStart = true;\n }\n this.pendingTimestampStep = undefined;\n }\n\n if (!this.sourceHasPacket) {\n this.sourceHasPacket = true;\n this.currentSsrc = ssrc;\n this.sourceHighestSeq = sequenceNumber;\n this.sourceHighestExtended = 0;\n } else {\n const diff = seqDiff(sequenceNumber, this.sourceHighestSeq);\n const extended = this.sourceHighestExtended + diff;\n if (this.guardSourceStart && extended < 0) {\n this.onDrop.execute(packet, RtpTimelineDropReason.beforeSourceStart);\n return undefined;\n }\n if (diff > 0) {\n this.sourceHighestSeq = sequenceNumber;\n this.sourceHighestExtended = extended;\n }\n }\n\n const out = this.options.inPlace ? packet : packet.clone();\n const rewritten = this.continuity.assign(\n out.header,\n sequenceNumber,\n timestamp,\n );\n if (this.options.ssrc !== undefined) {\n out.header.ssrc = this.options.ssrc;\n }\n if (this.options.payloadType !== undefined) {\n out.header.payloadType = this.options.payloadType;\n }\n\n this.observeOutput(out, rewritten, now);\n\n if (rewritten) {\n this.onSourceSwitch.execute({\n source: this.currentSource,\n inputSsrc: ssrc,\n sequenceNumber: out.header.sequenceNumber,\n timestamp: out.header.timestamp,\n timestampStep: timestampStep!,\n });\n }\n return out;\n }\n\n private observeOutput(out: RtpPacket, rewritten: boolean, now: number) {\n const { sequenceNumber, timestamp } = out.header;\n if (\n this.highestSequenceNumber === undefined ||\n seqDiff(sequenceNumber, this.highestSequenceNumber) > 0\n ) {\n this.highestSequenceNumber = sequenceNumber;\n }\n // The wall-clock reference is the arrival time of the packet that carries\n // the highest timestamp. Padding (same timestamp) and late packets (older\n // timestamp) must not move it, or the elapsed time added at a switch would\n // differ between streams (audio / video) switched at the same moment.\n if (this.highestTimestamp === undefined) {\n this.highestTimestamp = timestamp;\n this.lastPacketTime = now;\n } else {\n const delta = tsDiff(timestamp, this.highestTimestamp);\n if (delta > 0) {\n // The switch increment is synthetic and padding reuses timestamps:\n // neither is an interval of the media itself.\n if (!rewritten && !isPaddingOnlyRtpPacket(out)) {\n this.lastTimestampDelta = delta;\n }\n this.highestTimestamp = timestamp;\n this.lastPacketTime = now;\n }\n }\n }\n\n private timestampStepFor(now: number): number {\n const fallback = this.options.defaultTimestampStep ?? 1;\n let step: number;\n if (this.pendingTimestampStep !== undefined) {\n step = this.pendingTimestampStep;\n } else {\n const mode = this.options.timestampStep ?? \"auto\";\n if (typeof mode === \"number\") {\n step = mode;\n } else if (\n (mode === \"wallClock\" || mode === \"auto\") &&\n this.options.clockRate !== undefined &&\n this.lastPacketTime !== undefined\n ) {\n step = Math.round(\n ((now - this.lastPacketTime) * this.options.clockRate) / 1000,\n );\n } else if (mode === \"wallClock\") {\n step = fallback;\n } else {\n step = this.lastTimestampDelta ?? fallback;\n }\n }\n // Keep the new timestamp ahead of the old one in 32-bit signed distance.\n return Math.min(Math.max(1, Math.trunc(step)), 0x7fffffff);\n }\n}\n"]}
|
|
@@ -12,13 +12,13 @@ class CipherAesCtr extends _1.CipherAesBase {
|
|
|
12
12
|
enumerable: true,
|
|
13
13
|
configurable: true,
|
|
14
14
|
writable: true,
|
|
15
|
-
value:
|
|
15
|
+
value: void 0
|
|
16
16
|
});
|
|
17
17
|
Object.defineProperty(this, "srtcpSessionAuthTag", {
|
|
18
18
|
enumerable: true,
|
|
19
19
|
configurable: true,
|
|
20
20
|
writable: true,
|
|
21
|
-
value:
|
|
21
|
+
value: void 0
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(this, "authTagLength", {
|
|
24
24
|
enumerable: true,
|
|
@@ -26,6 +26,8 @@ class CipherAesCtr extends _1.CipherAesBase {
|
|
|
26
26
|
writable: true,
|
|
27
27
|
value: 10
|
|
28
28
|
});
|
|
29
|
+
this.srtpSessionAuthTag = srtpSessionAuthTag;
|
|
30
|
+
this.srtcpSessionAuthTag = srtcpSessionAuthTag;
|
|
29
31
|
}
|
|
30
32
|
encryptRtp(header, payload, rolloverCounter) {
|
|
31
33
|
const headerBuffer = header.serialize(header.serializeSize);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctr.js","sourceRoot":"","sources":["../../../../../../rtp/src/srtp/cipher/ctr.ts"],"names":[],"mappings":";;;AAAA,mCAKgB;AAGhB,oCAAmD;AACnD,sCAImB;AACnB,wBAAkC;AAElC,MAAa,YAAa,SAAQ,gBAAa;IAG7C,YACE,cAAsB,EACtB,eAAuB,EACvB,eAAuB,EACvB,gBAAwB,EAChB,kBAA0B,EAC1B,mBAA2B;QAEnC,KAAK,CAAC,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,CAAC,CAAC;QAH1E;;;;mBAAQ,kBAAkB;WAAQ;Q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header\";\nimport type { RtpHeader } from \"../../rtp/rtp\";\nimport { SrtpAuthenticationError } from \"../error\";\nimport {\n finalizeSrtpRtpHeader,\n parseSrtcpHeader,\n parseSrtpRtpHeader,\n} from \"../packet\";\nimport { CipherAesBase } from \".\";\n\nexport class CipherAesCtr extends CipherAesBase {\n readonly authTagLength = 10;\n\n constructor(\n srtpSessionKey: Buffer,\n srtpSessionSalt: Buffer,\n srtcpSessionKey: Buffer,\n srtcpSessionSalt: Buffer,\n private srtpSessionAuthTag: Buffer,\n private srtcpSessionAuthTag: Buffer,\n ) {\n super(srtpSessionKey, srtpSessionSalt, srtcpSessionKey, srtcpSessionSalt);\n }\n\n encryptRtp(header: RtpHeader, payload: Buffer, rolloverCounter: number) {\n const headerBuffer = header.serialize(header.serializeSize);\n\n const counter = this.generateCounter(\n header.sequenceNumber,\n rolloverCounter,\n header.ssrc,\n this.srtpSessionSalt,\n );\n\n const cipher = createCipheriv(\"aes-128-ctr\", this.srtpSessionKey, counter);\n const enc = cipher.update(payload);\n\n const authTag = this.generateSrtpAuthTag(\n rolloverCounter,\n headerBuffer,\n enc,\n );\n return Buffer.concat([headerBuffer, enc, authTag]);\n }\n\n decryptRtp(\n cipherText: Buffer,\n rolloverCounter: number,\n header = parseSrtpRtpHeader(cipherText, this.authTagLength),\n ): [Buffer, RtpHeader] {\n const authTagOffset = cipherText.length - this.authTagLength;\n const encryptedPacket = cipherText.subarray(0, authTagOffset);\n const actualAuthTag = cipherText.subarray(authTagOffset);\n\n const expectedAuthTag = this.generateSrtpAuthTag(\n rolloverCounter,\n encryptedPacket.subarray(0, header.payloadOffset),\n encryptedPacket.subarray(header.payloadOffset),\n );\n assertAuthTag(\n actualAuthTag,\n expectedAuthTag,\n \"Failed to authenticate SRTP packet\",\n );\n\n const counter = this.generateCounter(\n header.sequenceNumber,\n rolloverCounter,\n header.ssrc,\n this.srtpSessionSalt,\n );\n const cipher = createDecipheriv(\n \"aes-128-ctr\",\n this.srtpSessionKey,\n counter,\n );\n const payload = encryptedPacket.subarray(header.payloadOffset);\n const buf = cipher.update(payload);\n\n const dst = Buffer.concat([\n encryptedPacket.subarray(0, header.payloadOffset),\n buf,\n ]);\n\n return [\n dst,\n finalizeSrtpRtpHeader(header, dst, \"Failed to authenticate SRTP packet\"),\n ];\n }\n\n encryptRTCP(rtcpPacket: Buffer, srtcpIndex: number): Buffer {\n let out = Buffer.from(rtcpPacket);\n const ssrc = out.readUInt32BE(4);\n\n const counter = this.generateCounter(\n srtcpIndex & 0xffff,\n srtcpIndex >> 16,\n ssrc,\n this.srtcpSessionSalt,\n );\n const cipher = createCipheriv(\"aes-128-ctr\", this.srtcpSessionKey, counter);\n // Encrypt everything after header\n const buf = cipher.update(out.slice(8));\n buf.copy(out, 8);\n out = Buffer.concat([out, Buffer.alloc(4)]);\n out.writeUInt32BE(srtcpIndex, out.length - 4);\n out[out.length - 4] |= 0x80;\n const authTag = this.generateSrtcpAuthTag(out);\n out = Buffer.concat([out, authTag]);\n\n return out;\n }\n\n decryptRTCP(encrypted: Buffer): [Buffer, RtcpHeader] {\n const header = parseSrtcpHeader(\n encrypted,\n this.authTagLength,\n srtcpIndexSize,\n );\n\n const tailOffset = encrypted.length - (this.authTagLength + srtcpIndexSize);\n const authenticatedPortion = encrypted.subarray(\n 0,\n encrypted.length - this.authTagLength,\n );\n const actualTag = encrypted.subarray(encrypted.length - this.authTagLength);\n const expectedTag = this.generateSrtcpAuthTag(authenticatedPortion);\n assertAuthTag(\n actualTag,\n expectedTag,\n \"Failed to authenticate SRTCP packet\",\n );\n\n const out = Buffer.from(encrypted).slice(0, tailOffset);\n\n const isEncrypted = encrypted[tailOffset] >>> 7;\n if (isEncrypted === 0) return [out, header];\n\n let srtcpIndex = encrypted.readUInt32BE(tailOffset);\n srtcpIndex &= ~(1 << 31);\n\n const ssrc = encrypted.readUInt32BE(4);\n\n const counter = this.generateCounter(\n srtcpIndex & 0xffff,\n srtcpIndex >> 16,\n ssrc,\n this.srtcpSessionSalt,\n );\n const cipher = createDecipheriv(\n \"aes-128-ctr\",\n this.srtcpSessionKey,\n counter,\n );\n const buf = cipher.update(out.subarray(8));\n buf.copy(out, 8);\n return [out, header];\n }\n\n generateSrtcpAuthTag(buf: Buffer) {\n const srtcpSessionAuth = createHmac(\"sha1\", this.srtcpSessionAuthTag);\n return srtcpSessionAuth.update(buf).digest().slice(0, 10);\n }\n\n generateCounter(\n sequenceNumber: number,\n rolloverCounter: number,\n ssrc: number,\n sessionSalt: Buffer,\n ) {\n const counter = Buffer.alloc(16);\n counter.writeUInt32BE(ssrc, 4);\n counter.writeUInt32BE(rolloverCounter, 8);\n counter.writeUInt32BE(Number(BigInt(sequenceNumber) << 16n), 12);\n\n for (let i = 0; i < sessionSalt.length; i++) {\n counter[i] ^= sessionSalt[i];\n }\n return counter;\n }\n\n generateSrtpAuthTag(roc: number, ...buffers: Buffer[]) {\n const srtpSessionAuth = createHmac(\"sha1\", this.srtpSessionAuthTag);\n const rocRaw = Buffer.alloc(4);\n rocRaw.writeUInt32BE(roc);\n\n for (const buf of buffers) {\n srtpSessionAuth.update(buf);\n }\n return srtpSessionAuth.update(rocRaw).digest().subarray(0, 10);\n }\n}\n\nconst srtcpIndexSize = 4;\n\nfunction assertAuthTag(actual: Buffer, expected: Buffer, message: string) {\n if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) {\n throw new SrtpAuthenticationError(message);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ctr.js","sourceRoot":"","sources":["../../../../../../rtp/src/srtp/cipher/ctr.ts"],"names":[],"mappings":";;;AAAA,mCAKgB;AAGhB,oCAAmD;AACnD,sCAImB;AACnB,wBAAkC;AAElC,MAAa,YAAa,SAAQ,gBAAa;IAM7C,YACE,cAAsB,EACtB,eAAuB,EACvB,eAAuB,EACvB,gBAAwB,EACxB,kBAA0B,EAC1B,mBAA2B;QAE3B,KAAK,CAAC,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,CAAC,CAAC;QAbpE;;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Content":["import {\n createCipheriv,\n createDecipheriv,\n createHmac,\n timingSafeEqual,\n} from \"crypto\";\nimport type { RtcpHeader } from \"../../rtcp/header\";\nimport type { RtpHeader } from \"../../rtp/rtp\";\nimport { SrtpAuthenticationError } from \"../error\";\nimport {\n finalizeSrtpRtpHeader,\n parseSrtcpHeader,\n parseSrtpRtpHeader,\n} from \"../packet\";\nimport { CipherAesBase } from \".\";\n\nexport class CipherAesCtr extends CipherAesBase {\n private srtpSessionAuthTag: Buffer;\n private srtcpSessionAuthTag: Buffer;\n\n readonly authTagLength = 10;\n\n constructor(\n srtpSessionKey: Buffer,\n srtpSessionSalt: Buffer,\n srtcpSessionKey: Buffer,\n srtcpSessionSalt: Buffer,\n srtpSessionAuthTag: Buffer,\n srtcpSessionAuthTag: Buffer,\n ) {\n super(srtpSessionKey, srtpSessionSalt, srtcpSessionKey, srtcpSessionSalt);\n this.srtpSessionAuthTag = srtpSessionAuthTag;\n this.srtcpSessionAuthTag = srtcpSessionAuthTag;\n }\n\n encryptRtp(header: RtpHeader, payload: Buffer, rolloverCounter: number) {\n const headerBuffer = header.serialize(header.serializeSize);\n\n const counter = this.generateCounter(\n header.sequenceNumber,\n rolloverCounter,\n header.ssrc,\n this.srtpSessionSalt,\n );\n\n const cipher = createCipheriv(\"aes-128-ctr\", this.srtpSessionKey, counter);\n const enc = cipher.update(payload);\n\n const authTag = this.generateSrtpAuthTag(\n rolloverCounter,\n headerBuffer,\n enc,\n );\n return Buffer.concat([headerBuffer, enc, authTag]);\n }\n\n decryptRtp(\n cipherText: Buffer,\n rolloverCounter: number,\n header = parseSrtpRtpHeader(cipherText, this.authTagLength),\n ): [Buffer, RtpHeader] {\n const authTagOffset = cipherText.length - this.authTagLength;\n const encryptedPacket = cipherText.subarray(0, authTagOffset);\n const actualAuthTag = cipherText.subarray(authTagOffset);\n\n const expectedAuthTag = this.generateSrtpAuthTag(\n rolloverCounter,\n encryptedPacket.subarray(0, header.payloadOffset),\n encryptedPacket.subarray(header.payloadOffset),\n );\n assertAuthTag(\n actualAuthTag,\n expectedAuthTag,\n \"Failed to authenticate SRTP packet\",\n );\n\n const counter = this.generateCounter(\n header.sequenceNumber,\n rolloverCounter,\n header.ssrc,\n this.srtpSessionSalt,\n );\n const cipher = createDecipheriv(\n \"aes-128-ctr\",\n this.srtpSessionKey,\n counter,\n );\n const payload = encryptedPacket.subarray(header.payloadOffset);\n const buf = cipher.update(payload);\n\n const dst = Buffer.concat([\n encryptedPacket.subarray(0, header.payloadOffset),\n buf,\n ]);\n\n return [\n dst,\n finalizeSrtpRtpHeader(header, dst, \"Failed to authenticate SRTP packet\"),\n ];\n }\n\n encryptRTCP(rtcpPacket: Buffer, srtcpIndex: number): Buffer {\n let out = Buffer.from(rtcpPacket);\n const ssrc = out.readUInt32BE(4);\n\n const counter = this.generateCounter(\n srtcpIndex & 0xffff,\n srtcpIndex >> 16,\n ssrc,\n this.srtcpSessionSalt,\n );\n const cipher = createCipheriv(\"aes-128-ctr\", this.srtcpSessionKey, counter);\n // Encrypt everything after header\n const buf = cipher.update(out.slice(8));\n buf.copy(out, 8);\n out = Buffer.concat([out, Buffer.alloc(4)]);\n out.writeUInt32BE(srtcpIndex, out.length - 4);\n out[out.length - 4] |= 0x80;\n const authTag = this.generateSrtcpAuthTag(out);\n out = Buffer.concat([out, authTag]);\n\n return out;\n }\n\n decryptRTCP(encrypted: Buffer): [Buffer, RtcpHeader] {\n const header = parseSrtcpHeader(\n encrypted,\n this.authTagLength,\n srtcpIndexSize,\n );\n\n const tailOffset = encrypted.length - (this.authTagLength + srtcpIndexSize);\n const authenticatedPortion = encrypted.subarray(\n 0,\n encrypted.length - this.authTagLength,\n );\n const actualTag = encrypted.subarray(encrypted.length - this.authTagLength);\n const expectedTag = this.generateSrtcpAuthTag(authenticatedPortion);\n assertAuthTag(\n actualTag,\n expectedTag,\n \"Failed to authenticate SRTCP packet\",\n );\n\n const out = Buffer.from(encrypted).slice(0, tailOffset);\n\n const isEncrypted = encrypted[tailOffset] >>> 7;\n if (isEncrypted === 0) return [out, header];\n\n let srtcpIndex = encrypted.readUInt32BE(tailOffset);\n srtcpIndex &= ~(1 << 31);\n\n const ssrc = encrypted.readUInt32BE(4);\n\n const counter = this.generateCounter(\n srtcpIndex & 0xffff,\n srtcpIndex >> 16,\n ssrc,\n this.srtcpSessionSalt,\n );\n const cipher = createDecipheriv(\n \"aes-128-ctr\",\n this.srtcpSessionKey,\n counter,\n );\n const buf = cipher.update(out.subarray(8));\n buf.copy(out, 8);\n return [out, header];\n }\n\n generateSrtcpAuthTag(buf: Buffer) {\n const srtcpSessionAuth = createHmac(\"sha1\", this.srtcpSessionAuthTag);\n return srtcpSessionAuth.update(buf).digest().slice(0, 10);\n }\n\n generateCounter(\n sequenceNumber: number,\n rolloverCounter: number,\n ssrc: number,\n sessionSalt: Buffer,\n ) {\n const counter = Buffer.alloc(16);\n counter.writeUInt32BE(ssrc, 4);\n counter.writeUInt32BE(rolloverCounter, 8);\n counter.writeUInt32BE(Number(BigInt(sequenceNumber) << 16n), 12);\n\n for (let i = 0; i < sessionSalt.length; i++) {\n counter[i] ^= sessionSalt[i];\n }\n return counter;\n }\n\n generateSrtpAuthTag(roc: number, ...buffers: Buffer[]) {\n const srtpSessionAuth = createHmac(\"sha1\", this.srtpSessionAuthTag);\n const rocRaw = Buffer.alloc(4);\n rocRaw.writeUInt32BE(roc);\n\n for (const buf of buffers) {\n srtpSessionAuth.update(buf);\n }\n return srtpSessionAuth.update(rocRaw).digest().subarray(0, 10);\n }\n}\n\nconst srtcpIndexSize = 4;\n\nfunction assertAuthTag(actual: Buffer, expected: Buffer, message: string) {\n if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) {\n throw new SrtpAuthenticationError(message);\n }\n}\n"]}
|
|
@@ -7,26 +7,30 @@ class CipherAesBase {
|
|
|
7
7
|
enumerable: true,
|
|
8
8
|
configurable: true,
|
|
9
9
|
writable: true,
|
|
10
|
-
value:
|
|
10
|
+
value: void 0
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(this, "srtpSessionSalt", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
configurable: true,
|
|
15
15
|
writable: true,
|
|
16
|
-
value:
|
|
16
|
+
value: void 0
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(this, "srtcpSessionKey", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
configurable: true,
|
|
21
21
|
writable: true,
|
|
22
|
-
value:
|
|
22
|
+
value: void 0
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(this, "srtcpSessionSalt", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
configurable: true,
|
|
27
27
|
writable: true,
|
|
28
|
-
value:
|
|
28
|
+
value: void 0
|
|
29
29
|
});
|
|
30
|
+
this.srtpSessionKey = srtpSessionKey;
|
|
31
|
+
this.srtpSessionSalt = srtpSessionSalt;
|
|
32
|
+
this.srtcpSessionKey = srtcpSessionKey;
|
|
33
|
+
this.srtcpSessionSalt = srtcpSessionSalt;
|
|
30
34
|
}
|
|
31
35
|
encryptRtp(header, payload, rolloverCounter) {
|
|
32
36
|
return Buffer.from([]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../rtp/src/srtp/cipher/index.ts"],"names":[],"mappings":";;;AAGA,MAAsB,aAAa;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../rtp/src/srtp/cipher/index.ts"],"names":[],"mappings":";;;AAGA,MAAsB,aAAa;IAMjC,YACE,cAAsB,EACtB,eAAuB,EACvB,eAAuB,EACvB,gBAAwB;QATnB;;;;;WAAuB;QACvB;;;;;WAAwB;QACxB;;;;;WAAwB;QACxB;;;;;WAAyB;QAQ9B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IAED,UAAU,CACR,MAAiB,EACjB,OAAe,EACf,eAAuB;QAEvB,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAED,UAAU,CACR,UAAkB,EAClB,eAAuB,EACvB,MAAkB;QAElB,OAAO,EAAS,CAAC;IACnB,CAAC;IAED,WAAW,CAAC,OAAe,EAAE,UAAkB;QAC7C,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAED,WAAW,CAAC,SAAiB;QAC3B,OAAO,EAAS,CAAC;IACnB,CAAC;CACF;AAzCD,sCAyCC","sourcesContent":["import type { RtcpHeader } from \"../../rtcp/header\";\nimport type { RtpHeader } from \"../../rtp/rtp\";\n\nexport abstract class CipherAesBase {\n public srtpSessionKey: Buffer;\n public srtpSessionSalt: Buffer;\n public srtcpSessionKey: Buffer;\n public srtcpSessionSalt: Buffer;\n\n constructor(\n srtpSessionKey: Buffer,\n srtpSessionSalt: Buffer,\n srtcpSessionKey: Buffer,\n srtcpSessionSalt: Buffer,\n ) {\n this.srtpSessionKey = srtpSessionKey;\n this.srtpSessionSalt = srtpSessionSalt;\n this.srtcpSessionKey = srtcpSessionKey;\n this.srtcpSessionSalt = srtcpSessionSalt;\n }\n\n encryptRtp(\n header: RtpHeader,\n payload: Buffer,\n rolloverCounter: number,\n ): Buffer {\n return Buffer.from([]);\n }\n\n decryptRtp(\n cipherText: Buffer,\n rolloverCounter: number,\n header?: RtpHeader,\n ): [Buffer, RtpHeader] {\n return [] as any;\n }\n\n encryptRTCP(rawRtcp: Buffer, srtcpIndex: number): Buffer {\n return Buffer.from([]);\n }\n\n decryptRTCP(encrypted: Buffer): [Buffer, RtcpHeader] {\n return [] as any;\n }\n}\n"]}
|
|
@@ -18,19 +18,19 @@ class Context {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
configurable: true,
|
|
20
20
|
writable: true,
|
|
21
|
-
value:
|
|
21
|
+
value: void 0
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(this, "masterSalt", {
|
|
24
24
|
enumerable: true,
|
|
25
25
|
configurable: true,
|
|
26
26
|
writable: true,
|
|
27
|
-
value:
|
|
27
|
+
value: void 0
|
|
28
28
|
});
|
|
29
29
|
Object.defineProperty(this, "profile", {
|
|
30
30
|
enumerable: true,
|
|
31
31
|
configurable: true,
|
|
32
32
|
writable: true,
|
|
33
|
-
value:
|
|
33
|
+
value: void 0
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(this, "srtpSSRCStates", {
|
|
36
36
|
enumerable: true,
|
|
@@ -98,6 +98,9 @@ class Context {
|
|
|
98
98
|
writable: true,
|
|
99
99
|
value: void 0
|
|
100
100
|
});
|
|
101
|
+
this.masterKey = masterKey;
|
|
102
|
+
this.masterSalt = masterSalt;
|
|
103
|
+
this.profile = profile;
|
|
101
104
|
{
|
|
102
105
|
// AES-ECB plaintext require 16byte
|
|
103
106
|
// so need to padding to 14 byte
|