18.104.22.168 Forward Error Correction (FEC) Algorithm
The FEC implementation is capable of detecting and correcting errors in the video payload header, as well as the video payload data. It achieves this by constructing an FEC metadata packet(s), using the video payload header and video payload data, and sending it alongside video packets. Note that only one FEC packet SHOULD be constructed if the value of DV is "00".
Assuming that a video frame is fragmented and packetized into N data packets, the RTP payload header size plus the payload data size MUST be the same for all data packets, except for the last data packet.
Each video data packet is considered an FEC data block. The size of all the FEC data blocks MUST be the same. If the size of the video frame is not the multiple of the FEC data block size, zeros MUST be padded to the end to make the total size a multiple of the FEC data block size. The padding zeros are only used for calculating the FEC metadata packet and reconstructing the lost video data packet, and are not sent over the network. The actual size of the last video data packet without padding might be smaller than the FEC data block size.
The actual size of the last video packet without padding is set in the HiLPL field and the LastPacketLengthLo field of the FEC RTP payload header. When the last video packet is reconstructed, the receiver MUST strip out the padding zeros using the HiLPL and the LastPacketLengthLo fields.
The FEC data block size MUST be smaller than the MTU size.
The process to calculate the FEC metadata packet of FEC Version 0 (DV="00")<8>.
1. For each video data packet and for each byte in the correspondent FEC data block, do a bitwise XOR with the correspondent byte in the FEC result buffer and save the result into the result buffer.
2. After completing the calculation for all the data packets, the FEC result buffer is the resulting FEC metadata.
The reconstruction of a lost video data packet is done by performing a byte-by-byte XOR operation on all the received video data packets and the FEC metadata packet. The result is the lost video data packet. If this data packet is the last data packet, only the first N bytes (N is specified by HiLPL field and LastPacketLengthLo field in the FEC RTP payload header) are actual data. The rest of the buffer is the padding and MUST be thrown away.
For FEC Version 1 (DV = "01"), the algorithm allows multiple FEC packets to protect the data packets of a video frame. All FEC packets are appended and transmitted immediately after the data packets pertaining to the video frame they protect. The first FEC packet is compatible with the default RTVideo FEC RTP Payload used when DV ="00". In this case, the FEC packet is a simple XOR packet of all the data packets pertaining to the video frame it protects, as described in the previous algorithm. The generation and use of subsequent FEC packets is dependent on the implementation on the clients.<9>