webrtc_rtp_h264 (webrtc v0.1.0)
View SourceH.264 RTP payload format (RFC 6184): packetization-mode 1 (non-interleaved: single NAL unit packets, STAP-A and FU-A) and packetization-mode 2 (interleaved: STAP-B, MTAP16, MTAP24, FU-A and FU-B with decoding order numbers).
packetize/2 turns the NAL units of one access unit into RTP payloads of at most Mtu bytes: consecutive small NAL units are aggregated into STAP-A packets (§5.7.1), NAL units larger than the MTU are fragmented into FU-A packets (§5.8), others are sent as single NAL unit packets (§5.6). The caller sets the marker bit on the last payload of the access unit.
depacketize/1 returns the NAL units of one payload, or a fragment for FU-A. depacketizer_new/0 and depacketizer_push/3 reassemble FU-A fragments across packets, dropping a fragmented NAL unit when a sequence number is missing.
depacketize/1 rejects the interleaved types with {error, {unsupported, Type}}; use the interleaved functions for them:
packetize_interleaved/3packs NAL units in decoding order, numbered from a DON, into STAP-B packets and FU-B / FU-A fragments (§5.7.1, §5.8, §6.4);mtap/2builds one MTAP16 or MTAP24 packet (§5.7.2);depacketize_interleaved/1reads one interleaved payload;deinterleaver_new/1,deinterleaver_push/3anddeinterleaver_flush/1reassemble fragments and give the NAL units back in decoding order (§7.2), holding sprop-interleaving-depth + 1 VCL NAL units.
split_annexb/1 extracts NAL units from an Annex B byte stream. Nothing here decodes video; key frame detection looks for an IDR slice (NAL type 5). sps_size/1 reads the picture size from a sequence parameter set.
Summary
Functions
Everything left, in decoding order (end of the stream).
A de-interleaving buffer for sprop-interleaving-depth Depth (§7.2; 0 when not signaled).
Push one payload with its RTP sequence number. Returns the NAL units that leave the buffer, in decoding order. A malformed payload or a lost fragment drops what it carried.
NAL units carried by one payload, or a FU-A fragment.
The NAL units of one interleaved payload with their DON, or a fragment: the FU-B start carries the DON, the FU-A fragments that follow continue it. STAP-A and single NAL unit packets are not allowed in this mode (§6.4).
Push one payload with its RTP sequence number. Returns the complete NAL units it yields. A malformed payload, or a fragment that does not continue the NAL unit being reassembled, drops that NAL unit.
True when the payload carries (the start of) an IDR slice.
One MTAP16 (16) or MTAP24 (24) payload (§5.7.2) from units in transmission order with their DON and their timestamp offset from the packet's RTP timestamp. DONB is the smallest DON in decoding order; every DON must lie within 255 of it and the offsets within 16 or 24 bits.
NAL unit type of a NAL unit or payload (low 5 bits of byte 0).
NAL unit types present in a payload. For FU-A only the start fragment reports its type.
Packetize NAL units given in decoding order, the first with decoding order number Don. Small units are aggregated in STAP-B packets (a unit alone too: single NAL unit packets are not allowed in this mode, §6.4); larger ones become an FU-B then FU-A fragments. Returns the payloads and the DON of the next NAL unit.
Split an Annex B byte stream on 3 and 4 byte start codes. Bytes before the first start code are ignored.
Width and height of the pictures of a sequence parameter set NAL unit (ITU-T H.264 §7.3.2.1.1), cropping applied (§7.4.2.1.1).
Types
-opaque deinterleaver()
-opaque depacketizer()
-type unit() :: #{nal := binary(), don := 0..65535, ts_offset := non_neg_integer()}.
Functions
-spec deinterleaver_flush(deinterleaver()) -> {[binary()], deinterleaver()}.
Everything left, in decoding order (end of the stream).
-spec deinterleaver_new(non_neg_integer()) -> deinterleaver().
A de-interleaving buffer for sprop-interleaving-depth Depth (§7.2; 0 when not signaled).
-spec deinterleaver_push(0..65535, binary(), deinterleaver()) -> {ok, [binary()], deinterleaver()} | {error, term(), deinterleaver()}.
Push one payload with its RTP sequence number. Returns the NAL units that leave the buffer, in decoding order. A malformed payload or a lost fragment drops what it carried.
NAL units carried by one payload, or a FU-A fragment.
-spec depacketize_interleaved(binary()) -> {ok, [unit()]} | {fragment, start, byte(), 0..65535, binary()} | {fragment, middle | 'end', byte(), binary()} | {error, term()}.
The NAL units of one interleaved payload with their DON, or a fragment: the FU-B start carries the DON, the FU-A fragments that follow continue it. STAP-A and single NAL unit packets are not allowed in this mode (§6.4).
-spec depacketizer_new() -> depacketizer().
-spec depacketizer_push(0..65535, binary(), depacketizer()) -> {ok, [binary()], depacketizer()} | {error, term(), depacketizer()}.
Push one payload with its RTP sequence number. Returns the complete NAL units it yields. A malformed payload, or a fragment that does not continue the NAL unit being reassembled, drops that NAL unit.
True when the payload carries (the start of) an IDR slice.
-spec mtap([{binary(), 0..65535, non_neg_integer()}], 16 | 24) -> {ok, binary()} | {error, term()}.
One MTAP16 (16) or MTAP24 (24) payload (§5.7.2) from units in transmission order with their DON and their timestamp offset from the packet's RTP timestamp. DONB is the smallest DON in decoding order; every DON must lie within 255 of it and the offsets within 16 or 24 bits.
-spec nal_type(binary()) -> 0..31.
NAL unit type of a NAL unit or payload (low 5 bits of byte 0).
-spec nal_types(binary()) -> [0..31].
NAL unit types present in a payload. For FU-A only the start fragment reports its type.
-spec packetize([binary()], pos_integer()) -> [binary()].
-spec packetize_interleaved([binary()], pos_integer(), 0..65535) -> {[binary()], 0..65535}.
Packetize NAL units given in decoding order, the first with decoding order number Don. Small units are aggregated in STAP-B packets (a unit alone too: single NAL unit packets are not allowed in this mode, §6.4); larger ones become an FU-B then FU-A fragments. Returns the payloads and the DON of the next NAL unit.
Split an Annex B byte stream on 3 and 4 byte start codes. Bytes before the first start code are ignored.
-spec sps_size(binary()) -> {ok, {pos_integer(), pos_integer()}} | error.
Width and height of the pictures of a sequence parameter set NAL unit (ITU-T H.264 §7.3.2.1.1), cropping applied (§7.4.2.1.1).