Documentation
¶
Index ¶
- Constants
- Variables
- func BuildCompactRtcp208(localSsrc, remoteSsrc uint32, log ...zerolog.Logger) [12]byte
- func BuildCompactRtcp209(localSsrc uint32, log ...zerolog.Logger) [8]byte
- func BuildSenderReport(localSsrc uint32, stats *RtcpSenderStats, nowMs uint64, log ...zerolog.Logger) [28]byte
- func DeriveWasmParticipantSsrc(callID, lid string, slotWord uint32, log ...zerolog.Logger) (uint32, error)
- func DeriveWasmRelayStreamSsrcs(callID, lid string, log ...zerolog.Logger) ([9]uint32, error)
- func E2EParticipantIDVariants(jid string, log ...zerolog.Logger) []string
- func EncodeRtpHeader(header *RtpHeader, log ...zerolog.Logger) []byte
- func EstimateSrtpRtpWireBytes(opusPayload []byte) int
- func FormatE2ESrtpParticipantID(jid string) string
- func IsOpusDtxPayload(payload []byte) bool
- func IsOpusMlowSpeechPayload(payload []byte) bool
- func IsOpusPrimingPayload(payload []byte) bool
- func IsRtcpPacket(data []byte) bool
- func IsRtpVersion2(data []byte) bool
- func IsWhatsappOpusRtpPayload(payloadType uint8) bool
- func PackageH264NALU(nalu []byte) [][]byte
- func PackageH264STAPA(nalus [][]byte) []byte
- func ParseRtcpSenderSsrc(data []byte, log ...zerolog.Logger) (uint32, bool)
- func RtcpPayloadType(data []byte) (uint8, bool)
- func RtpHeaderByteLength(data []byte, log ...zerolog.Logger) (int, bool)
- func SplitAnnexB(data []byte) [][]byte
- type H264Depacketizer
- type Option
- type RtcpSenderStats
- type RtpHeader
- type RtpStream
Constants ¶
const ( RtcpPtSr uint8 = 200 RtcpPtWaCompact uint8 = 208 RtcpPtWaCompact2 uint8 = 209 RtcpHeaderLen int = 8 SrtcpTrailerLen int = 14 )
const ( RtpPayloadTypeOpus uint8 = 120 // RtpPayloadTypeH264 is the WhatsApp video (H.264) RTP payload type, used to demux // video off the relay. Source of truth: https://github.com/JotaDev66/WaCalls/blob/2d6a1f666426049a89ef9541414e771acdcf8a16/internal/voip/core/types.go#L44 RtpPayloadTypeH264 uint8 = 97 WhatsappRtpExtensionProfile uint16 = 0xdebe WhatsappRtpHeaderSize int = 16 WhatsappRtpHeaderDtxSize int = 20 WhatsappRtpExtensionDtxWord uint32 = 0x30010000 )
const VideoSlotWord uint32 = 2
VideoSlotWord is the relay stream slot for a participant's video SSRC (audio is slot 0). Source of truth: https://github.com/JotaDev66/WaCalls/blob/2d6a1f666426049a89ef9541414e771acdcf8a16/internal/voip/call/callmanager_video.go#L13
Variables ¶
var OpusPrimingFrame1 = [18]byte{
0x12, 0x36, 0x26, 0x2b, 0x4a, 0xc8, 0x2b, 0x09, 0xc9, 0x1f, 0x34, 0xc2, 0xd6, 0x7a, 0x01, 0x73,
0x1b, 0x2e,
}
OpusPrimingFrame1 is the Android first priming frame (18 bytes).
var OpusPrimingFrame1Wasm = [24]byte{
0x32, 0x36, 0x26, 0x2b, 0x4a, 0xcb, 0x1b, 0x5f, 0xba, 0x91, 0x68, 0x7e, 0xb8, 0x50, 0x93, 0x58,
0xe6, 0xd0, 0xa3, 0xa9, 0xd7, 0x1d, 0x81, 0x8c,
}
OpusPrimingFrame1Wasm is the WASM/Web caller priming frame (24 bytes).
var OpusPrimingFrame2 = [5]byte{0x90, 0xb8, 0x14, 0x14, 0xc4}
OpusPrimingFrame2 is the second priming frame (5 bytes).
var WasmRelayStreamSlotWords = [9]uint32{0, 1, 4, 2, 3, 5, 7, 8, 6}
WasmRelayStreamSlotWords are the slot words for the 9-stream relay allocate plan.
Functions ¶
func BuildCompactRtcp208 ¶
BuildCompactRtcp208 builds the 12-byte compact RTCP (PT 208, RC=1).
func BuildCompactRtcp209 ¶
BuildCompactRtcp209 builds the 8-byte compact RTCP (PT 209, RC=1).
func BuildSenderReport ¶
func BuildSenderReport(localSsrc uint32, stats *RtcpSenderStats, nowMs uint64, log ...zerolog.Logger) [28]byte
BuildSenderReport builds the 28-byte Sender Report (PT 200, RC=0); nowMs is wall-clock ms.
func DeriveWasmParticipantSsrc ¶
func DeriveWasmParticipantSsrc(callID, lid string, slotWord uint32, log ...zerolog.Logger) (uint32, error)
DeriveWasmParticipantSsrc derives a participant/stream SSRC: HKDF-SHA256(salt=slotWord LE32, ikm=callID, info=lid, 4), read back as LE u32.
func DeriveWasmRelayStreamSsrcs ¶
DeriveWasmRelayStreamSsrcs derives all 9 relay-stream SSRCs in slot order.
func E2EParticipantIDVariants ¶
E2EParticipantIDVariants lists the device-qualified LID variants the recv path tries as HKDF info (peer sender LIDs), deduplicated in insertion order.
func EncodeRtpHeader ¶
EncodeRtpHeader encodes the RTP header (16 or 20 bytes with the 0xdebe extension).
func EstimateSrtpRtpWireBytes ¶
EstimateSrtpRtpWireBytes estimates the on-wire SRTP size (header + opus + tag).
func FormatE2ESrtpParticipantID ¶
FormatE2ESrtpParticipantID formats the device-qualified LID for E2E-SRTP HKDF info.
func IsOpusDtxPayload ¶
IsOpusDtxPayload reports DTX / comfort-noise frames (RFC 0x10, mlow 0x90, warmup).
func IsOpusMlowSpeechPayload ¶
IsOpusMlowSpeechPayload reports mlow speech frames (20ms 0x48..0x4f or 60ms 0x50..0x57).
func IsOpusPrimingPayload ¶
IsOpusPrimingPayload reports whether the payload equals a priming frame.
func IsRtcpPacket ¶
IsRtcpPacket reports whether data is an RTCP packet (vs a WhatsApp RTP packet).
func IsRtpVersion2 ¶
IsRtpVersion2 reports a version-2 RTP packet.
func IsWhatsappOpusRtpPayload ¶
IsWhatsappOpusRtpPayload reports whether the payload type is WhatsApp Opus.
func PackageH264NALU ¶
PackageH264NALU splits one NAL unit into RTP payloads: a single payload when it fits the MTU budget, else FU-A fragments.
func PackageH264STAPA ¶
PackageH264STAPA aggregates several small NAL units into one STAP-A payload, or nil when there are fewer than two or the aggregate would exceed the MTU budget.
func ParseRtcpSenderSsrc ¶
ParseRtcpSenderSsrc returns the sender SSRC (bytes 4-7); ok=false if malformed.
func RtcpPayloadType ¶
RtcpPayloadType returns the RTCP payload type; ok=false if not an RTCP packet.
func RtpHeaderByteLength ¶
RtpHeaderByteLength returns the full on-wire header size (12 + CSRC + ext); ok=false if malformed.
func SplitAnnexB ¶
SplitAnnexB splits an Annex-B byte stream (00 00 01 / 00 00 00 01 start codes) into its constituent NAL units, trimming trailing zero bytes before each start code.
Types ¶
type H264Depacketizer ¶
type H264Depacketizer struct {
// contains filtered or unexported fields
}
H264Depacketizer reassembles H.264 NAL units from RFC 6184 RTP payloads (single NAL, STAP-A, FU-A), carrying FU-A fragment state across packets.
func (*H264Depacketizer) Depacketize ¶
func (d *H264Depacketizer) Depacketize(payload []byte) [][]byte
Depacketize consumes one RTP payload and returns the NAL units it produced (zero for a mid-fragment, one for single/FU-A completion, many for STAP-A).
type Option ¶
type Option func(*config)
Option configures optional, non-behavioral aspects (currently the diagnostic logger).
func WithLogger ¶
WithLogger sets the zerolog logger for debug/trace diagnostics; default is silent.
type RtcpSenderStats ¶
RtcpSenderStats are the Sender Report counters.
type RtpHeader ¶
type RtpHeader struct {
Marker bool
PayloadType uint8
SequenceNumber uint16
Timestamp uint32
Ssrc uint32
ExtensionWord *uint32 // nil = no 0xdebe extension word
}
RtpHeader is the fixed RTP header plus an optional 0xdebe extension word.
func ParseRtpHeader ¶
ParseRtpHeader parses the fixed RTP header fields (the extension word is not decoded).
type RtpStream ¶
type RtpStream struct {
Ssrc uint32
// contains filtered or unexported fields
}
RtpStream is the send-side RTP sequencer: seq starts at 1, timestamp advances per packet.
func NewRtpStream ¶
NewRtpStream builds a sequencer for ssrc with samplesPerPacket per packet.
func (*RtpStream) NextPacket ¶
NextPacket builds the next RTP header for payload, latching the marker on the first speech frame.
func (*RtpStream) NextPreSpeechPacket ¶
NextPreSpeechPacket builds a pre-speech ladder packet (advances seq/timestamp, no marker/latch).