]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fecdec_filter.c
Recognize the eof packet also in the udp receiver.
[paraslash.git] / fecdec_filter.c
index 6aa9071e6ea1bbabcf5d874f07b67da71a06db20..d5593f25d02c5cde248e0c775a1d3235a279ef8f 100644 (file)
@@ -162,6 +162,7 @@ static struct fecdec_group *free_oldest_group(struct private_fecdec_data *pfd)
        return oldest;
 }
 
+/* returns 1 if the group was found, 0 if not, negative on errors */
 static int get_group(struct fec_header *h, struct private_fecdec_data *pfd,
                struct fecdec_group **result)
 {
@@ -175,24 +176,33 @@ static int get_group(struct fec_header *h, struct private_fecdec_data *pfd,
        /* group not found */
        fg = find_unused_group(pfd);
        if (fg)
-               goto update_header;
+               goto success;
        fg = try_to_free_group(pfd);
        if (fg)
-               goto update_header;
+               goto success;
        fg = free_oldest_group(pfd);
-update_header:
-       fg->h = *h;
+       ret = 0;
 success:
+       fg->h = *h;
        *result = fg;
-       return 1;
+       return ret;
 }
 
+/*
+ * returns 1 if slice was added, zero otherwise (because the group was already
+ * complete). In any case the number of received slices is being increased by
+ * one.
+ */
 static int add_slice(char *buf, struct fecdec_group *fg)
 {
        int r, slice_num;
 
-       if (group_complete(fg))
+       if (group_complete(fg)) {
+               PARA_DEBUG_LOG("group complete, ignoring slice %d\n",
+                       fg->h.slice_num);
+               fg->num_received_slices++;
                return 0;
+       }
        slice_num = fg->h.slice_num;
        if (fg->num_slices == 0) {
                fg->num_slices = fg->h.slices_per_group;
@@ -257,13 +267,14 @@ static int read_fec_header(char *buf, size_t len, struct fec_header *h)
 
        h->slice_num = read_u8(buf + 18);
        h->slice_bytes = read_u16(buf + 20);
-       if (!h->group_bytes && & h->slice_bytes)
+       if (!memcmp(buf, FEC_EOF_PACKET, FEC_EOF_PACKET_LEN))
                return -E_FECDEC_EOF;
 //     PARA_DEBUG_LOG("group %u, slize %u, slices per group: %u\n",
 //             h->group_num, h->slice_num, h->slices_per_group);
        return 1;
 }
 
+/* returns 1 if we used the buffer, 0 if we didn't, negative on errors */
 static int dispatch_slice(char *buf, size_t len, struct fec_header *h,
                struct filter_node *fn)
 {
@@ -276,15 +287,8 @@ static int dispatch_slice(char *buf, size_t len, struct fec_header *h,
        ret = get_group(h, pfd, &fg);
        if (ret < 0)
                return ret;
-       if (group_complete(fg)) {
-               PARA_DEBUG_LOG("group complete, ignoring slice %d\n",
-                       h->slice_num);
+       if (!add_slice(buf, fg))
                return 1;
-       }
-       fg->h = *h;
-       ret = add_slice(buf, fg);
-       if (ret < 0)
-               return ret;
        if (group_complete(fg)) {
                if (!pfd->fec) {
                        int k = h->data_slices_per_group, n = h->slices_per_group;
@@ -300,7 +304,7 @@ static int dispatch_slice(char *buf, size_t len, struct fec_header *h,
        return 1;
 }
 
-static int fecdec(char *buf, size_t len, struct filter_node *fn)
+static ssize_t fecdec(char *buf, size_t len, struct filter_node *fn)
 {
        int ret;
        struct fec_header h;