It consists of an encoder and a decoder. The encoder is fed a stream of data which it breaks up into packets. These packets can then be sent over an unreliable transport mechanism, typically UDP. The decoder can then reconstruct lost packets from redundant packets sent by the encoder.
Like other implementations, the encoder groups n packets of payload together and then adds k redundant packets to it. The receiver can only start to reconstruct any of the lost payload once it has received at least n packets in total.
I wanted everything to be as clean as possible, with no fancy features. Since it's open source, anyone is free to improve things as they see fit. Contributions should start with the to do list at the end of this document.
My intention was that it can be used in those cases where there is no back channel e.g. one-way satellite link. So, if the library has been properly configured, all data will be recovered, even if many megabytes is lost due to external events like thunder storms.
Maybe someone will write a function that uses probability models to work out the smallest suitable value of k...
fecEncoder *NewFecEncoder (void *userData, size_t (*userSend)(void *buf, size_t size, size_t count, void *userData), char **errorMessage, int s, int n, int k, int w, int g, int b);If it returns NULL, an error has occured. If you passed a non-NULL value in errorMessage, *errorMessage will point to a string describing to you what went wrong.
void FecEncode (fecPayload *buf, fecEncoder *f);FecEncode must be called n times (or a multiple thereof), otherwise the redundant data will not be sent.
void DeleteFecEncoder (fecEncoder *f); typedef struct fecDecoder; fecDecoder *NewFecDecoder (void *userData, void (*userReceive)(void *userData, __int64_t position, fecPayload *buf, int len) ); size_t FecDecode (void *buf, size_t size, size_t count, fecDecoder *f); void FlushFecDecoder (fecDecoder *f);The error correction works best if the decoder has the largest possible amount of data. So you should call the flush command to signify that no more data is expected e.g. after a timeout.
void DeleteFecDecoder (fecDecoder *f);
It consumes less bandwidth to implement a sub channel to send the 20 odd bytes of control information : Now the header is e.g. 2 bytes. The first bytes sends would be a simple modulo 28 counter. The second byte would contain 1 byte of control data if the first byte is less than 20, and would be a checksum byte otherwise. This checksum scheme can also use Galois Fields and Gaussian elimination, but it's parameters must chosen so that it will still function under the worst possible error rates.
Copyright (c) 2002 Nic Roets. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgment: "This product includes software developed by Nic Roets" 4. Redistributions of any form whatsoever must retain the following acknowledgment: "This product includes software developed by Nic Roets" THIS SOFTWARE IS PROVIDED BY NIC ROETS `AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NIC ROETS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.