rtp.bend checks
raw source on the hub · import 0xfbc4773809086afacef84e7fba6d620c/rtp.bend as Rtp
RTP (RFC 3550) and the H.264 and H.265 payload formats (RFC 6184, RFC
7798): a packet's header and payload, and the NAL units rebuilt from
single-unit, aggregation and fragmentation packets, written out in
Annex B form (each unit after a 00 00 00 01 start code), which is what
a decoder or ffprobe reads as a raw .h264 or .h265 file.
Not done: reordering and loss. Over RTSP's interleaved TCP there is neither; over UDP a fragment lost in the middle would leave a broken unit.
2 imports
import Base import ./bytes.bend as B
Types
type Rtp source · line 15 · raw
Data
A packet: the marker bit, payload type, sequence number, timestamp, source, and the payload with any padding and extension taken off.
NoRtpRtp
Rtp@marker:Bool -> @pt:U32 -> @seq:U32 -> @ts:U32 -> @ssrc:U32 -> @payload:List<&2, U32> -> Rtp
type Dep source · line 75 · raw
Data
The fragments of the unit being rebuilt, the last one first, and whether one is open.
Dep@frags:List<&2, List<&2, U32>> -> @on:Bool -> Dep
type Out source · line 79 · raw
Data
The units a packet completed, in order, and the state after it.
Out@nals:List<&2, List<&2, U32>> -> @st:Dep -> Out
Definitions
def Rtp.ext source · line 22 · raw
@yes:Bool -> @bs:List<&2, U32> -> List<&2, U32>
def Rtp.unpad.rev source · line 33 · raw
@rev:List<&2, U32> -> List<&2, U32>
The last byte of a reversed list says how many bytes of padding the packet ends with, itself included.
def Rtp.unpad source · line 40 · raw
@yes:Bool -> @bs:List<&2, U32> -> List<&2, U32>
def Rtp.with source · line 47 · raw
@v2:Bool -> @+b0:U32 -> @+b1:U32 -> @seq:U32 -> @ts:U32 -> @ssrc:U32 -> @rest:List<&2, U32> -> Rtp
def Rtp.of source · line 61 · raw
@bs:List<&2, U32> -> Rtp
A packet from its bytes: version 2, then the CSRC list, the header extension and the padding skipped (RFC 3550 5.1). NoRtp when it is too short or another version.
def Dep.new source · line 82 · raw
Dep
def Dep.join source · line 85 · raw
@frags:List<&2, List<&2, U32>> -> @acc:List<&2, U32> -> List<&2, U32>
def Dep.end source · line 92 · raw
@done:Bool -> @+frags:List<&2, List<&2, U32>> -> @on:Bool -> Out
def Dep.frag source · line 102 · raw
@st:Dep -> @+s:Bool -> @+e:Bool -> @hdr:List<&2, U32> -> @+data:List<&2, U32> -> Out
A fragment into the state: a start opens a unit with its rebuilt header, an end closes it and gives it out; a middle or an end with no unit open is dropped (its start was lost).
def Dep.agg.cut source · line 109 · raw
@c:0xfbc4773809086afacef84e7fba6d620c/bytes.Cut -> @more:(@_:List<&2, U32> -> List<&2, List<&2, U32>>) -> List<&2, List<&2, U32>>
def Dep.agg source · line 119 · raw
@fuel:Nat -> @bs:List<&2, U32> -> List<&2, List<&2, U32>>
The units of an aggregation packet: each after its 16-bit size. Every unit takes at least its 2 size bytes, so fuel = the byte count lasts.
def Dep.units source · line 126 · raw
@+bs:List<&2, U32> -> List<&2, List<&2, U32>>
def H264.fu source · line 132 · raw
@st:Dep -> @+h:U32 -> @rest:List<&2, U32> -> Out
def H264.kind source · line 140 · raw
@single:Bool -> @stap:Bool -> @fu:Bool -> @st:Dep -> @+h:U32 -> @rest:List<&2, U32> -> Out
def H264.push source · line 155 · raw
@st:Dep -> @payload:List<&2, U32> -> Out
A payload into the state: types 1 to 23 are a unit as it is, 24 (STAP-A) several units, 28 (FU-A) a fragment of one; the others are not used by cameras and are skipped.
def H265.fu source · line 167 · raw
@st:Dep -> @+h0:U32 -> @h1:U32 -> @rest:List<&2, U32> -> Out
def H265.kind source · line 175 · raw
@single:Bool -> @ap:Bool -> @fu:Bool -> @st:Dep -> @+h0:U32 -> @+h1:U32 -> @rest:List<&2, U32> -> Out
def H265.push source · line 189 · raw
@st:Dep -> @payload:List<&2, U32> -> Out
A payload into the state: the type is 6 bits of the 2-byte header; below 48 a unit as it is, 48 an aggregation packet, 49 a fragment.
def Nal.rev source · line 200 · raw
@nals:List<&2, List<&2, U32>> -> @acc:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>
def Nal.put source · line 208 · raw
@rev:List<&2, List<&2, U32>> -> @acc:List<&2, U32> -> List<&2, U32>
def Nal.annexb source · line 216 · raw
@nals:List<&2, List<&2, U32>> -> List<&2, U32>
The units as a byte stream: each after the start code 00 00 00 01.