Module rtp

Module rtp 

Source
Expand description

RTP (RFC 3550) — the media framing of every SIP call.

A raw SIP/PSTN leg carries audio as RTP packets over UDP: a 12-byte fixed header (sequence number, timestamp, SSRC) followed by the codec payload — for telephone audio, G.711 μ-law (payload type 0, PCMU) or A-law (payload type 8, PCMA) at 8 kHz, conventionally 20 ms (160 samples) per packet.

This module is the pure layer: build and parse move between packet bytes and structured form (tolerating padding, CSRCs, and header extensions on the way in), and RtpSender carries the tiny amount of state a sender needs (sequence, timestamp, SSRC). No sockets — the sip feature’s media loop drives it over UDP, and tests drive it with byte arrays.

Structs§

RtpPacket
One parsed RTP packet (header fields we care about + payload bytes).
RtpSender
Sender-side RTP state: sequence, timestamp, and SSRC advance per packet.
TelephoneEvent
One parsed telephone-event (RFC 4733) payload — a DTMF keypress carried as RTP instead of audio tones.

Constants§

PT_PCMA
RTP payload type for G.711 A-law at 8 kHz (RFC 3551 static assignment).
PT_PCMU
RTP payload type for G.711 μ-law at 8 kHz (RFC 3551 static assignment).
SAMPLES_PER_PACKET
Samples per packet at the conventional 20 ms packetisation (8 kHz mono).

Functions§

build
Build an RTP packet (version 2, no padding/extension/CSRC).
parse
Parse an RTP packet, tolerating padding, CSRC entries, and a header extension. Returns None for datagrams that are not well-formed RTP v2 — a media port sees stray traffic (STUN probes, scans); dropping quietly is the correct posture.
parse_telephone_event
Parse an RFC 4733 telephone-event payload (the 4-byte named-event form).