]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fecdec_filter.c
fecdec_filter.c: Kill useless UNUSED_GROUP_NUM.
[paraslash.git] / fecdec_filter.c
index 6bb827c83fde8f9bf12a393324af909d9205037f..6b6716a115c18c26429d12d49f38a40981314574 100644 (file)
@@ -27,8 +27,6 @@
  */
 #define NUM_FEC_GROUPS 3
 
-#define INPUT_BUFFER_SIZE 16384
-
 /** Size of the output buffer of the fecdec filter. */
 #define FECDEC_OUTBUF_SIZE 81920
 
@@ -50,38 +48,47 @@ struct fec_header {
        uint16_t slice_bytes;
 };
 
-struct fec_group {
+/**
+ * The status of one partially received FEC group.
+ */
+struct fecdec_group {
+       /** The header read from the last slice. */
        struct fec_header h;
+       /** How many slices received so far. */
        int num_received_slices;
+       /** The size of the \a idx and the \a data arrays below. */
        int num_slices;
+       /** Array of indices of the received slices. */
        int *idx;
+       /** Content of the received slices. */
        unsigned char **data;
 };
 
+/**
+ * Data private to the fecdec filter.
+ */
 struct private_fecdec_data {
+       /** Used by the fec core code. */
        struct fec_parms *fec;
-       struct fec_group groups[NUM_FEC_GROUPS];
+       /** Keeps track of what was received so far. */
+       struct fecdec_group groups[NUM_FEC_GROUPS];
 };
 
-#define FOR_EACH_FEC_GROUP(g, d) for (g = (d)->groups; \
+/** Iterate over all fecdec groups. */
+#define FOR_EACH_FECDEC_GROUP(g, d) for (g = (d)->groups; \
        (g) - (d)->groups < NUM_FEC_GROUPS; (g)++)
 
-#define UNUSED_GROUP_NUM 0xffffffff
-
-static int group_complete(struct fec_group *fg)
+static int group_complete(struct fecdec_group *fg)
 {
-       if (fg->h.group_num == UNUSED_GROUP_NUM)
-               return 0;
-       //PARA_INFO_LOG("received slices: %u, slices per group: %u\n", fg->num_received_slices, fg->h.data_slices_per_group);
        return fg->num_received_slices >= fg->h.data_slices_per_group;
 }
 
-static int group_empty(struct fec_group *fg)
+static int group_empty(struct fecdec_group *fg)
 {
        return fg->num_received_slices == 0;
 }
 
-static void clear_group(struct fec_group *fg)
+static void clear_group(struct fecdec_group *fg)
 {
        int i;
 
@@ -99,39 +106,39 @@ static void clear_group(struct fec_group *fg)
        fg->num_slices = 0;
        memset(&fg->h, 0, sizeof(struct fec_header));
        fg->num_received_slices = 0;
-       fg->h.group_num = UNUSED_GROUP_NUM;
 }
 
 static int find_group(struct fec_header *h,
-               struct private_fecdec_data *pfd, struct fec_group **result)
+               struct private_fecdec_data *pfd, struct fecdec_group **result)
 {
-       struct fec_group *fg;
+       struct fecdec_group *fg;
 
-       FOR_EACH_FEC_GROUP(fg, pfd) {
+       FOR_EACH_FECDEC_GROUP(fg, pfd) {
                if (fg->h.group_num != h->group_num)
                        continue;
+               /* FIXME: Add some more sanity checks here */
                *result = fg;
                return 1;
        }
        return 0;
 }
 
-static struct fec_group *find_unused_group(struct private_fecdec_data *pfd)
+static struct fecdec_group *find_unused_group(struct private_fecdec_data *pfd)
 {
-       struct fec_group *fg;
+       struct fecdec_group *fg;
 
-       FOR_EACH_FEC_GROUP(fg, pfd) {
+       FOR_EACH_FECDEC_GROUP(fg, pfd) {
                if (fg->num_received_slices == 0)
                        return fg;
        }
        return NULL;
 }
 
-static struct fec_group *try_to_free_group(struct private_fecdec_data *pfd)
+static struct fecdec_group *try_to_free_group(struct private_fecdec_data *pfd)
 {
-       struct fec_group *fg;
+       struct fecdec_group *fg;
 
-       FOR_EACH_FEC_GROUP(fg, pfd) {
+       FOR_EACH_FECDEC_GROUP(fg, pfd) {
                if (!group_complete(fg))
                        continue;
                clear_group(fg);
@@ -140,11 +147,11 @@ static struct fec_group *try_to_free_group(struct private_fecdec_data *pfd)
        return NULL;
 }
 
-static struct fec_group *free_oldest_group(struct private_fecdec_data *pfd)
+static struct fecdec_group *free_oldest_group(struct private_fecdec_data *pfd)
 {
-       struct fec_group *fg, *oldest = NULL;
+       struct fecdec_group *fg, *oldest = NULL;
 
-       FOR_EACH_FEC_GROUP(fg, pfd) {
+       FOR_EACH_FECDEC_GROUP(fg, pfd) {
                if (!oldest || oldest->h.group_num > fg->h.group_num)
                        oldest = fg;
        }
@@ -153,9 +160,9 @@ static struct fec_group *free_oldest_group(struct private_fecdec_data *pfd)
 }
 
 static int get_group(struct fec_header *h, struct private_fecdec_data *pfd,
-               struct fec_group **result)
+               struct fecdec_group **result)
 {
-       struct fec_group *fg;
+       struct fecdec_group *fg;
        int ret = find_group(h, pfd, &fg);
 
        if (ret < 0)
@@ -177,7 +184,7 @@ success:
        return 1;
 }
 
-static int add_slice(char *buf, struct fec_group *fg)
+static int add_slice(char *buf, struct fecdec_group *fg)
 {
        int r, slice_num;
 
@@ -198,7 +205,7 @@ static int add_slice(char *buf, struct fec_group *fg)
        return 1;
 }
 
-static int decode_group(struct fec_group *fg, struct filter_node *fn)
+static int decode_group(struct fecdec_group *fg, struct filter_node *fn)
 {
        int i, ret, sb = fg->h.slice_bytes;
        size_t written = 0;
@@ -257,7 +264,7 @@ static int read_fec_header(char *buf, size_t len, struct fec_header *h)
 static int dispatch_slice(char *buf, size_t len, struct fec_header *h,
                struct filter_node *fn)
 {
-       struct fec_group *fg;
+       struct fecdec_group *fg;
        int ret;
        struct private_fecdec_data *pfd = fn->private_data;
 
@@ -298,7 +305,7 @@ static int fecdec(char *buf, size_t len, struct filter_node *fn)
        ret = read_fec_header(buf, len, &h);
        if (ret <= 0)
                return ret;
-       if (h.slice_bytes > INPUT_BUFFER_SIZE)
+       if (h.slice_bytes > fn->bufsize)
                return -E_BAD_SLICE_SIZE;
        if (h.slice_num > h.slices_per_group)
                return -E_BAD_SLICE_NUM;
@@ -313,9 +320,9 @@ static int fecdec(char *buf, size_t len, struct filter_node *fn)
 static void fecdec_close(struct filter_node *fn)
 {
        struct private_fecdec_data *pfd = fn->private_data;
-       struct fec_group *fg;
+       struct fecdec_group *fg;
 
-       FOR_EACH_FEC_GROUP(fg, pfd)
+       FOR_EACH_FECDEC_GROUP(fg, pfd)
                clear_group(fg);
        free(fn->buf);
        fn->buf = NULL;