rtp

package
v0.294.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package rtp decodes RTP and RTCP packets per RFC 3550 (Real-time Transport Protocol) and the static payload type assignments of RFC 3551, plus the standard RTCP feedback extensions of RFC 4585 (RTPFB / PSFB) and RFC 3611 (XR).

Wrap-vs-native judgement

Native. RFC 3550 and 3551 are fully public; the wire
format is a small fixed-layout binary header with a
well-defined set of optional sections and a finite, small
table of payload types. RTCP composite-packet walking is
also a tight binary walker: per-packet length field is
measured in 32-bit words, no varints, no compression.
Operators paste UDP payload bytes from a Wireshark RTP
stream, a SIPp test capture, or any media-server log and
get a documented view of every field. Pure offline parser
— no transport, no hardware, no state.

What this package covers

  • Auto-detect: RTP vs RTCP. Both share V=2 in the high two bits of byte 0. The disambiguator is the payload-type byte: RTCP standard PTs are 200-207 (SR / RR / SDES / BYE / APP / RTPFB / PSFB / XR), which doesn't overlap any practical RTP PT (RTP PT is 7-bit 0-127). A non-zero high bit on byte 1 of an RTCP candidate (which would be the RTP Marker bit) and a low-half value in [72,76] are flagged as RTCP-collision-reserved per RFC 3551 §6 to make multiplexing safe.

  • RTP header (12 fixed bytes + optional CSRC list + optional X-extension): V, P, X, CC, M, PT, Sequence, Timestamp, SSRC, CSRC[CC], optional Extension (4-byte profile/length header + N×4 bytes), then payload, then optional padding (last byte is pad count when P=1).

  • Static payload-type table (RFC 3551 §6): PT 0-34 + the gaps; includes audio (PCMU / GSM / G723 / DVI4 / LPC / PCMA / G722 / L16 / QCELP / CN / MPA / G728 / G729) and video (CelB / JPEG / nv / H261 / MPV / MP2T / H263). PTs 35-71 + 77-95 are reserved/unassigned (rendered as "unassigned"); 72-76 are RTCP-conflict-reserved; 96-127 are dynamic (rendered as "dynamic" — actual codec is negotiated in SDP).

  • RTCP composite packets: one UDP datagram may carry multiple RTCP packets concatenated. We walk the chain by the (length+1)*4 bytes rule until the buffer is consumed. Each chunk is decoded by PT:

  • SR (200): SSRC + NTP timestamp + RTP timestamp + sender packet/byte count + RC × reception report block (SSRC + fraction lost + cumulative lost + extended highest seq + interarrival jitter + LSR + DLSR).

  • RR (201): SSRC + RC × reception report block.

  • SDES (202): SC × chunk (SSRC + items keyed by SDES type: 1 CNAME / 2 NAME / 3 EMAIL / 4 PHONE / 5 LOC / 6 TOOL / 7 NOTE / 8 PRIV).

  • BYE (203): SC × SSRC + optional reason string.

  • APP (204): SSRC + 4-byte name + opaque app data.

  • RTPFB (205) / PSFB (206): generic feedback envelope per RFC 4585 — sender SSRC + media SSRC + FCI blob.

  • XR (207): extended-reports envelope per RFC 3611 — sender SSRC + per-block (BT + type-specific + length).

What this package does NOT cover (deliberately out of scope)

  • DTLS-SRTP key negotiation (RFC 5764) and SRTP keying material — payload-level encryption is opaque to this decoder; encrypted RTP shows the cleartext header (which is what intermediaries see) but the payload is rendered as hex bytes.

  • SDP body parsing (RFC 4566) — that's already handled by internal/sip's body section.

  • RTP header extensions beyond the generic profile-defined length walker — RFC 5285 one-byte and two-byte extensions are surfaced as a raw blob; specific extensions (audio-level, abs-send-time, video-orientation) would belong in a sibling helper.

  • Codec-level dissection (Opus / H.264 / VP8 RTP payload framing per RFC 6184 / RFC 7741 / etc.) — payload bytes are surfaced raw.

  • RTCP-XR block-specific decoding for every block type (RFC 3611 defines 8 block types — we surface BT + length and leave the body as hex).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APPPacket

type APPPacket struct {
	SSRC    uint32 `json:"ssrc"`
	SSRCHex string `json:"ssrc_hex"`
	Name    string `json:"name"`
	DataHex string `json:"data_hex,omitempty"`
}

APPPacket is RTCP Application-Defined (PT 204).

type BYEPacket

type BYEPacket struct {
	Sources    []uint32 `json:"sources,omitempty"`
	SourcesHex []string `json:"sources_hex,omitempty"`
	Reason     string   `json:"reason,omitempty"`
}

BYEPacket is RTCP Goodbye (PT 203).

type FBPacket

type FBPacket struct {
	FormatCode    int    `json:"format_code"` // RC field reused as FMT
	FormatName    string `json:"format_name"`
	SenderSSRC    uint32 `json:"sender_ssrc"`
	SenderSSRCHex string `json:"sender_ssrc_hex"`
	MediaSSRC     uint32 `json:"media_ssrc"`
	MediaSSRCHex  string `json:"media_ssrc_hex"`
	FCIHex        string `json:"fci_hex,omitempty"`
}

FBPacket is RTCP feedback (PT 205 RTPFB / PT 206 PSFB) per RFC 4585.

type RRPacket

type RRPacket struct {
	ReporterSSRC    uint32            `json:"reporter_ssrc"`
	ReporterSSRCHex string            `json:"reporter_ssrc_hex"`
	Reports         []ReceptionReport `json:"reports,omitempty"`
}

RRPacket is RTCP Receiver Report (PT 201).

type RTCPPacket

type RTCPPacket struct {
	Version    int    `json:"version"`
	Padding    bool   `json:"padding"`
	ReportCnt  int    `json:"report_count"`
	Type       int    `json:"type"`
	TypeName   string `json:"type_name"`
	LengthW    int    `json:"length_words"`
	TotalBytes int    `json:"total_bytes"`

	SR   *SRPacket   `json:"sr,omitempty"`
	RR   *RRPacket   `json:"rr,omitempty"`
	SDES *SDESPacket `json:"sdes,omitempty"`
	BYE  *BYEPacket  `json:"bye,omitempty"`
	APP  *APPPacket  `json:"app,omitempty"`
	FB   *FBPacket   `json:"feedback,omitempty"`
	XR   *XRPacket   `json:"xr,omitempty"`
	Raw  string      `json:"raw_hex,omitempty"`
}

RTCPPacket is one decoded RTCP sub-packet inside a composite datagram. Body shape depends on PT.

type RTPPacket

type RTPPacket struct {
	Version             int      `json:"version"`
	Padding             bool     `json:"padding"`
	Extension           bool     `json:"extension"`
	CSRCCount           int      `json:"csrc_count"`
	Marker              bool     `json:"marker"`
	PayloadType         int      `json:"payload_type"`
	PayloadTypeName     string   `json:"payload_type_name"`
	SequenceNumber      int      `json:"sequence_number"`
	Timestamp           uint32   `json:"timestamp"`
	SSRC                uint32   `json:"ssrc"`
	SSRCHex             string   `json:"ssrc_hex"`
	CSRC                []uint32 `json:"csrc,omitempty"`
	ExtensionProfile    *uint16  `json:"extension_profile,omitempty"`
	ExtensionLengthW    *uint16  `json:"extension_length_words,omitempty"`
	ExtensionDataHex    string   `json:"extension_data_hex,omitempty"`
	PaddingLength       int      `json:"padding_length,omitempty"`
	PayloadLength       int      `json:"payload_length"`
	PayloadHex          string   `json:"payload_hex,omitempty"`
	PayloadHexTruncated bool     `json:"payload_hex_truncated,omitempty"`
}

RTPPacket is one decoded RTP packet.

type ReceptionReport

type ReceptionReport struct {
	SourceSSRC       uint32 `json:"source_ssrc"`
	SourceSSRCHex    string `json:"source_ssrc_hex"`
	FractionLost     int    `json:"fraction_lost"`
	CumulativeLost   int    `json:"cumulative_lost"`
	ExtendedHighSeq  uint32 `json:"extended_highest_seq"`
	InterarrivalJit  uint32 `json:"interarrival_jitter"`
	LastSRTimestamp  uint32 `json:"last_sr_ntp_middle"`
	DelaySinceLastSR uint32 `json:"delay_since_last_sr"`
}

ReceptionReport is a per-source reception block used by SR and RR.

type Result

type Result struct {
	Kind        string       `json:"kind"` // "rtp" | "rtcp"
	TotalBytes  int          `json:"total_bytes"`
	RTP         *RTPPacket   `json:"rtp,omitempty"`
	RTCP        []RTCPPacket `json:"rtcp,omitempty"`
	RTCPSummary string       `json:"rtcp_summary,omitempty"`
}

Result is the top-level decoded view.

func Decode

func Decode(hexStr string) (*Result, error)

Decode parses an RTP or RTCP datagram from hex.

type SDESChunk

type SDESChunk struct {
	SSRC    uint32     `json:"ssrc"`
	SSRCHex string     `json:"ssrc_hex"`
	Items   []SDESItem `json:"items,omitempty"`
}

SDESChunk is one source-description chunk.

type SDESItem

type SDESItem struct {
	Type     int    `json:"type"`
	TypeName string `json:"type_name"`
	Text     string `json:"text"`
}

SDESItem is one (type, text) pair.

type SDESPacket

type SDESPacket struct {
	Chunks []SDESChunk `json:"chunks,omitempty"`
}

SDESPacket is RTCP Source Description (PT 202).

type SRPacket

type SRPacket struct {
	SenderSSRC        uint32            `json:"sender_ssrc"`
	SenderSSRCHex     string            `json:"sender_ssrc_hex"`
	NTPTimestampHigh  uint32            `json:"ntp_timestamp_high"`
	NTPTimestampLow   uint32            `json:"ntp_timestamp_low"`
	RTPTimestamp      uint32            `json:"rtp_timestamp"`
	SenderPacketCount uint32            `json:"sender_packet_count"`
	SenderOctetCount  uint32            `json:"sender_octet_count"`
	Reports           []ReceptionReport `json:"reports,omitempty"`
}

SRPacket is RTCP Sender Report (PT 200).

type XRBlock

type XRBlock struct {
	BlockType    int    `json:"block_type"`
	TypeSpecific int    `json:"type_specific"`
	BlockLengthW int    `json:"block_length_words"`
	BlockBytes   int    `json:"block_bytes"`
	BodyHex      string `json:"body_hex,omitempty"`
}

XRBlock is one RTCP-XR report block.

type XRPacket

type XRPacket struct {
	SenderSSRC    uint32    `json:"sender_ssrc"`
	SenderSSRCHex string    `json:"sender_ssrc_hex"`
	Blocks        []XRBlock `json:"blocks,omitempty"`
}

XRPacket is RTCP Extended Report (PT 207) per RFC 3611.

Jump to

Keyboard shortcuts

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