webrtc_ulpfec (webrtc v0.1.0)
View SourceULPFEC (RFC 5109): generic forward error correction of RTP packets by XOR, as WebRTC sends it inside video RED (RFC 8854 §5.2).
An FEC payload is the FEC header (§7.3: E, L, the P, X, CC, M and PT bits, SN base, TS and length recovery fields), one level 0 header (§7.4: protection length and a 16 or 48 bit mask) and the XOR of the protected packets past their 12 byte RTP header. Only level 0 is generated, with the protection length of the longest packet, so a single missing packet is recovered whole.
protect/2 makes FEC payloads for packets of one SSRC; the packets are the bytes protected, as sent before RED encapsulation. The receiver keeps the last packets and FEC payloads (new/0, media/3, fec/2): an FEC payload with exactly one of its packets missing gives that packet back.
Summary
Functions
Parse an FEC payload: SN base, the protected offsets and the recovery fields.
An FEC payload received, with the SSRC of the packet that carried it: the SSRC of the packets it recovers.
A media packet received (its bytes as protected). Returns the packets it lets FEC recover.
K FEC payloads protecting Packets ([{Seq, Bin}], in sequence order, at most 48), packet I in payload I rem K: an interleaved mask, so a burst of up to K losses is recovered.
A repair packet already read (FlexFEC, RFC 8627, see webrtc_flexfec): SN base and offsets of the packets of Ssrc it protects, the recovery fields and the repair payload, and its size.
Types
Functions
Parse an FEC payload: SN base, the protected offsets and the recovery fields.
-spec fec({non_neg_integer(), binary()}, receiver()) -> {[binary()], receiver()}.
An FEC payload received, with the SSRC of the packet that carried it: the SSRC of the packets it recovers.
A media packet received (its bytes as protected). Returns the packets it lets FEC recover.
-spec new() -> receiver().
-spec protect([{0..65535, binary()}], pos_integer()) -> [binary()].
K FEC payloads protecting Packets ([{Seq, Bin}], in sequence order, at most 48), packet I in payload I rem K: an interleaved mask, so a burst of up to K losses is recovered.
-spec repair({non_neg_integer(), {0..65535, [non_neg_integer()]}, map(), non_neg_integer()}, receiver()) -> {[binary()], receiver()}.
A repair packet already read (FlexFEC, RFC 8627, see webrtc_flexfec): SN base and offsets of the packets of Ssrc it protects, the recovery fields and the repair payload, and its size.