rtp

package
v0.0.0-...-0f1265d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RtcpPtSr         uint8 = 200
	RtcpPtWaCompact  uint8 = 208
	RtcpPtWaCompact2 uint8 = 209
	RtcpHeaderLen    int   = 8
	SrtcpTrailerLen  int   = 14
)
View Source
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
)
View Source
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

View Source
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).

View Source
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).

View Source
var OpusPrimingFrame2 = [5]byte{0x90, 0xb8, 0x14, 0x14, 0xc4}

OpusPrimingFrame2 is the second priming frame (5 bytes).

View Source
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

func BuildCompactRtcp208(localSsrc, remoteSsrc uint32, log ...zerolog.Logger) [12]byte

BuildCompactRtcp208 builds the 12-byte compact RTCP (PT 208, RC=1).

func BuildCompactRtcp209

func BuildCompactRtcp209(localSsrc uint32, log ...zerolog.Logger) [8]byte

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

func DeriveWasmRelayStreamSsrcs(callID, lid string, log ...zerolog.Logger) ([9]uint32, error)

DeriveWasmRelayStreamSsrcs derives all 9 relay-stream SSRCs in slot order.

func E2EParticipantIDVariants

func E2EParticipantIDVariants(jid string, log ...zerolog.Logger) []string

E2EParticipantIDVariants lists the device-qualified LID variants the recv path tries as HKDF info (peer sender LIDs), deduplicated in insertion order.

func EncodeRtpHeader

func EncodeRtpHeader(header *RtpHeader, log ...zerolog.Logger) []byte

EncodeRtpHeader encodes the RTP header (16 or 20 bytes with the 0xdebe extension).

func EstimateSrtpRtpWireBytes

func EstimateSrtpRtpWireBytes(opusPayload []byte) int

EstimateSrtpRtpWireBytes estimates the on-wire SRTP size (header + opus + tag).

func FormatE2ESrtpParticipantID

func FormatE2ESrtpParticipantID(jid string) string

FormatE2ESrtpParticipantID formats the device-qualified LID for E2E-SRTP HKDF info.

func IsOpusDtxPayload

func IsOpusDtxPayload(payload []byte) bool

IsOpusDtxPayload reports DTX / comfort-noise frames (RFC 0x10, mlow 0x90, warmup).

func IsOpusMlowSpeechPayload

func IsOpusMlowSpeechPayload(payload []byte) bool

IsOpusMlowSpeechPayload reports mlow speech frames (20ms 0x48..0x4f or 60ms 0x50..0x57).

func IsOpusPrimingPayload

func IsOpusPrimingPayload(payload []byte) bool

IsOpusPrimingPayload reports whether the payload equals a priming frame.

func IsRtcpPacket

func IsRtcpPacket(data []byte) bool

IsRtcpPacket reports whether data is an RTCP packet (vs a WhatsApp RTP packet).

func IsRtpVersion2

func IsRtpVersion2(data []byte) bool

IsRtpVersion2 reports a version-2 RTP packet.

func IsWhatsappOpusRtpPayload

func IsWhatsappOpusRtpPayload(payloadType uint8) bool

IsWhatsappOpusRtpPayload reports whether the payload type is WhatsApp Opus.

func PackageH264NALU

func PackageH264NALU(nalu []byte) [][]byte

PackageH264NALU splits one NAL unit into RTP payloads: a single payload when it fits the MTU budget, else FU-A fragments.

func PackageH264STAPA

func PackageH264STAPA(nalus [][]byte) []byte

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

func ParseRtcpSenderSsrc(data []byte, log ...zerolog.Logger) (uint32, bool)

ParseRtcpSenderSsrc returns the sender SSRC (bytes 4-7); ok=false if malformed.

func RtcpPayloadType

func RtcpPayloadType(data []byte) (uint8, bool)

RtcpPayloadType returns the RTCP payload type; ok=false if not an RTCP packet.

func RtpHeaderByteLength

func RtpHeaderByteLength(data []byte, log ...zerolog.Logger) (int, bool)

RtpHeaderByteLength returns the full on-wire header size (12 + CSRC + ext); ok=false if malformed.

func SplitAnnexB

func SplitAnnexB(data []byte) [][]byte

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

func WithLogger(l zerolog.Logger) Option

WithLogger sets the zerolog logger for debug/trace diagnostics; default is silent.

type RtcpSenderStats

type RtcpSenderStats struct {
	PacketsSent  uint32
	OctetsSent   uint32
	RtpTimestamp uint32
}

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

func ParseRtpHeader(data []byte, log ...zerolog.Logger) (RtpHeader, bool)

ParseRtpHeader parses the fixed RTP header fields (the extension word is not decoded).

func (*RtpHeader) ByteSize

func (h *RtpHeader) ByteSize() int

ByteSize is the on-wire header size (16, or 20 with an extension word).

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

func NewRtpStream(ssrc, samplesPerPacket uint32, warpPiggyback bool, opts ...Option) *RtpStream

NewRtpStream builds a sequencer for ssrc with samplesPerPacket per packet.

func (*RtpStream) NextPacket

func (s *RtpStream) NextPacket(payload []byte, marker bool) RtpHeader

NextPacket builds the next RTP header for payload, latching the marker on the first speech frame.

func (*RtpStream) NextPreSpeechPacket

func (s *RtpStream) NextPreSpeechPacket() RtpHeader

NextPreSpeechPacket builds a pre-speech ladder packet (advances seq/timestamp, no marker/latch).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL