summaryrefslogtreecommitdiff
path: root/fec.h
blob: 15b6c542739917fe85ca29dddc6c9804f72ac3ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** \file fec.h Forward Error Correction: API.
 *
 * This implementation of forward error correction employs the Reed
 * Solomon error-correcting code, which is based on Galois field algebra and
 * Vandermonde matrices. The algorithm is implemented in \ref fec.c. The two
 * users are the virtual streaming system (\ref vss.h), which fec-encodes data
 * chunks before sending them over the network, and the fecdec filter (\ref
 * fecdec_filter.c), which decodes fec-encoded chunks and feeds the decoded
 * chunks to the output channel of the buffer tree node for subordinated
 * buffer tree nodes to process.
 *
 * The API is relatively simple as it contains only the few non-static
 * functions described here. Both the sending and the receiving side first
 * call \ref fec_new() to obtain a reference to an opaque fec handle. The
 * virtual streaming system calls \ref fec_encode() while the fecdec filter
 * calls \ref fec_decode().
 */

/** The FEC header starts with this magic value. */
#define FEC_MAGIC 0xFECC0DEC

/** Data that indicates an eof-condition for a fec-encoded stream.
 *
 * This is used for (multicast) udp streaming where closing the socket on the
 * sender might not give rise to an eof condition at the peer.
 */
#define FEC_EOF_PACKET "\xec\x0d\xcc\xfe\0\0\0\0" \
	"\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0"
/**
 * Each FEC slice contains a FEC header of this size.
 *
 * The value is needed by the virtual streaming system and the fec decoder
 * implemented in \ref fecdec_filter.c.
 */
#define FEC_HEADER_SIZE 32
/** The number of bytes of the \a FEC_EOF_PACKET. */
#define FEC_EOF_PACKET_LEN 32

struct fec_parms;

int fec_new(int k, int n, struct fec_parms **parms);
void fec_free(struct fec_parms *p);
void fec_encode(struct fec_parms *parms, const unsigned char * const *src,
		unsigned char *dst, int idx, int sz);
int fec_decode(struct fec_parms *parms, unsigned char **data, int *idx,
		int sz);