95.2、FEC
说明
- 使用nuget
linker.fec,或源码 https://github.com/snltty/linker/tree/master/src/linker.fec - 以下是简单使用示例
//初始化
LinkerFecOptions fecOption = new LinkerFecOptions
{
SourceSymbolsPerBlock = 10,
RepairSymbolsPerBlock = 4,
SymbolSize = 1420 + LinkerFecEncodedSymbol.HeaderSize,
RepairProfile = [
new LinkerFecRepairProfilePoint(1, 2),
new LinkerFecRepairProfilePoint(10, 4)
],
};
LinkerFecCodec fecEncoder = new LinkerFecCodec(fecOption);
LinkerFecCodec fecDecoder = new LinkerFecCodec(fecOption);
byte[] fecEncodeBuffer = new byte[fecOption.MaxEncodeBufferSize];
byte[] fecDecodeBuffer = new byte[fecOption.MaxDecodeBufferSize];
//编码
//packets [2 length][payload][2 length][payload]
if (fecEncoder.TryEncodePacket(packets, fecEncodeBuffer, out int bytesWritten, out int packetCount))
{
//[2 length][payload][2 length][payload]
var packets = fecEncodeBuffer.AsMemory(0, bytesWritten);
}
//解码
if (fecDecoder.TryDecodeFrame(packet, fecDecodeBuffer, out int bytesWritten, out int packetCount))
{
//[2 length][payload][2 length][payload]
Memory<byte> packets = fecDecodeBuffer.AsMemory(0, bytesWritten);
}