]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - vss.c
Compute the maximal chunk size only once.
[paraslash.git] / vss.c
diff --git a/vss.c b/vss.c
index 7980ccc837d2b16510ced821db04b544c23df83d..383a8fda0710653c28c5853c2b8e7949b9b45b54 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -169,6 +169,8 @@ struct fec_client {
        int num_extra_slices;
        /** Contains the FEC-encoded data. */
        unsigned char *enc_buf;
+       /** Maximal packet size. */
+       int mps;
 };
 
 /**
@@ -207,7 +209,7 @@ static void write_fec_header(struct fec_client *fc, struct vss_task *vsst)
        write_u32(buf + 14, g->bytes);
 
        write_u8(buf + 18, fc->current_slice_num);
-       write_u16(buf + 20, p->max_slice_bytes - FEC_HEADER_SIZE);
+       write_u16(buf + 20, fc->mps - FEC_HEADER_SIZE);
        write_u8(buf + 22, g->first_chunk? 0 : 1);
        write_u8(buf + 23, vsst->header_len? 1 : 0);
        memset(buf + 24, 0, 7);
@@ -236,7 +238,7 @@ static int num_slices(long unsigned bytes, int mps, int rs)
 
        assert(m > 0);
        assert(rs > 0);
-       ret = (bytes + m - 1) / m;
+       ret = DIV_ROUND_UP(bytes, m);
        if (ret + rs > 255)
                return -E_BAD_CT;
        return ret;
@@ -281,8 +283,7 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst)
        if (ret < 0)
                goto err;
        hs = ret;
-       ret = num_slices(afh_get_largest_chunk_size(&mmd->afd.afhi),
-               mps, rs);
+       ret = num_slices(mmd->afd.max_chunk_size, mps, rs);
        if (ret < 0)
                goto err;
        ds = ret;
@@ -304,7 +305,7 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst)
        fc->extra_src_buf = para_realloc(fc->extra_src_buf, mps);
        memset(fc->extra_src_buf, 0, mps);
 
-       fc->fcp->max_slice_bytes = mps;
+       fc->mps = mps;
        fc->state = FEC_STATE_READY_TO_RUN;
        fc->next_header_time.tv_sec = 0;
        fc->stream_start = *now;
@@ -324,7 +325,7 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst)
        unsigned slice_bytes;
        uint32_t max_data_size;
 
-       if (fc->first_stream_chunk < 0) {
+       if (fc->state == FEC_STATE_NONE) {
                ret = initialize_fec_client(fc, vsst);
                if (ret < 0)
                        return ret;
@@ -346,14 +347,13 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst)
                g->first_chunk += g->num_chunks;
                g->num++;
        }
-       slice_bytes = fc->fcp->max_slice_bytes - FEC_HEADER_SIZE;
+       slice_bytes = fc->mps - FEC_HEADER_SIZE;
        PARA_CRIT_LOG("slice_bytes: %d\n", slice_bytes);
        k = fc->fcp->data_slices_per_group + fc->num_extra_slices;
        n = fc->fcp->slices_per_group + fc->num_extra_slices;
        PARA_CRIT_LOG("k: %d, n: %d\n", k, n);
        if (need_audio_header(fc, vsst)) {
-               ret = num_slices(vsst->header_len, fc->fcp->max_slice_bytes,
-                       n - k);
+               ret = num_slices(vsst->header_len, slice_bytes, n - k);
                if (ret < 0)
                        return ret;
                g->num_header_slices = ret;
@@ -418,7 +418,7 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst)
 
 static int compute_next_fec_slice(struct fec_client *fc, struct vss_task *vsst)
 {
-       if (fc->first_stream_chunk < 0 || fc->current_slice_num
+       if (fc->state == FEC_STATE_NONE || fc->current_slice_num
                        == fc->fcp->slices_per_group + fc->num_extra_slices) {
                int ret = setup_next_fec_group(fc, vsst);
                if (ret == 0)
@@ -432,8 +432,7 @@ static int compute_next_fec_slice(struct fec_client *fc, struct vss_task *vsst)
        }
        write_fec_header(fc, vsst);
        fec_encode(fc->parms, fc->src_data, fc->enc_buf + FEC_HEADER_SIZE,
-               fc->current_slice_num,
-               fc->fcp->max_slice_bytes - FEC_HEADER_SIZE);
+               fc->current_slice_num, fc->mps - FEC_HEADER_SIZE);
        return 1;
 }
 
@@ -499,7 +498,7 @@ static int next_slice_is_due(struct fec_client *fc, struct timeval *diff)
        struct timeval tmp, next;
        int ret;
 
-       if (fc->first_stream_chunk < 0)
+       if (fc->state == FEC_STATE_NONE)
                return 1;
        tv_scale(fc->current_slice_num, &fc->group.slice_duration, &tmp);
        tv_add(&tmp, &fc->group.start, &next);
@@ -727,10 +726,8 @@ static void vss_pre_select(struct sched *s, struct task *t)
                for (i = 0; senders[i].name; i++)
                        if (senders[i].shutdown_clients)
                                senders[i].shutdown_clients();
-               list_for_each_entry_safe(fc, tmp, &fec_client_list, node) {
-                       fc->first_stream_chunk = -1;
+               list_for_each_entry_safe(fc, tmp, &fec_client_list, node)
                        fc->state = FEC_STATE_NONE;
-               }
                mmd->stream_start.tv_sec = 0;
                mmd->stream_start.tv_usec = 0;
        }
@@ -877,15 +874,8 @@ static void vss_send(struct vss_task *vsst)
                        &due, 1) < 0)
                return;
        list_for_each_entry_safe(fc, tmp_fc, &fec_client_list, node) {
-               switch (fc->state) {
-               case FEC_STATE_DISABLED:
+               if (fc->state == FEC_STATE_DISABLED)
                        continue;
-               case FEC_STATE_NONE:
-                       fc->first_stream_chunk = -1; /* need setup */
-                       /* fall through */
-               case FEC_STATE_READY_TO_RUN:
-                       break;
-               }
                if (!next_slice_is_due(fc, NULL)) {
                        fec_active = 1;
                        continue;
@@ -893,9 +883,8 @@ static void vss_send(struct vss_task *vsst)
                if (compute_next_fec_slice(fc, vsst) <= 0)
                        continue;
                PARA_DEBUG_LOG("sending %d:%d (%u bytes)\n", fc->group.num,
-                       fc->current_slice_num, fc->fcp->max_slice_bytes);
-               fc->fcp->send_fec(fc->sc, (char *)fc->enc_buf,
-                                 fc->fcp->max_slice_bytes);
+                       fc->current_slice_num, fc->mps);
+               fc->fcp->send_fec(fc->sc, (char *)fc->enc_buf, fc->mps);
                fc->current_slice_num++;
                fec_active = 1;
        }