]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
vss: Introduce extra_header_buf.
authorAndre Noll <maan@systemlinux.org>
Sun, 24 Oct 2010 17:27:55 +0000 (19:27 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 29 Jan 2011 10:43:34 +0000 (11:43 +0100)
For the same reasons the extra data buffer is necessary, we also need to reserve
an extra buffer for the header in order to not read-overflow the header buffer
provided by the new get_header() function.

vss.c

diff --git a/vss.c b/vss.c
index 8b3745218fe057bd237eb85b1d3e89d39275ae06..2dab278dfff9c20983e3353e9a86a7147904262a 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -167,6 +167,8 @@ struct fec_client {
        struct timeval next_header_time;
        /** Used for the last source pointer of an audio file. */
        unsigned char *extra_src_buf;
+       /** Needed for the last slice of the audio file header. */
+       unsigned char *extra_header_buf;
        /** Extra slices needed to store largest chunk + header. */
        int num_extra_slices;
        /** Contains the FEC-encoded data. */
@@ -327,6 +329,7 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst)
        fc->src_data = para_realloc(fc->src_data, k * sizeof(char *));
        fc->enc_buf = para_realloc(fc->enc_buf, fc->mps);
        fc->extra_src_buf = para_realloc(fc->extra_src_buf, fc->mps);
+       fc->extra_header_buf = para_realloc(fc->extra_header_buf, fc->mps);
 
        fc->state = FEC_STATE_READY_TO_RUN;
        fc->next_header_time.tv_sec = 0;
@@ -516,12 +519,27 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst)
        fc->current_slice_num = 0;
        if (g->num == 0)
                set_group_timing(fc, vsst);
-
        /* setup header slices */
        buf = vsst->header_buf;
        for (i = 0; i < g->num_header_slices; i++) {
-               fc->src_data[i] = (const unsigned char *)buf;
-               buf += g->slice_bytes;
+               if (buf + g->slice_bytes <= vsst->header_buf + vsst->header_len) {
+                       fc->src_data[i] = (const unsigned char *)buf;
+                       buf += g->slice_bytes;
+                       continue;
+               }
+               /*
+                * Can not use vss->header_buf for this slice as it
+                * goes beyond the buffer. This slice will not be fully
+                * used.
+                */
+               uint32_t payload_size = vsst->header_buf
+                       + vsst->header_len - buf;
+               memcpy(fc->extra_header_buf, buf, payload_size);
+               if (payload_size < g->slice_bytes)
+                       memset(fc->extra_header_buf + payload_size, 0,
+                               g->slice_bytes - payload_size);
+               fc->src_data[i] = fc->extra_header_buf;
+               assert(i == g->num_header_slices - 1);
        }
 
        /* setup data slices */
@@ -530,8 +548,7 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst)
                if (buf + g->slice_bytes > vsst->map + mmd->size) {
                        /*
                         * Can not use the memory mapped audio file for this
-                        * slice as it goes beyond the map. This slice will not
-                        * be fully used.
+                        * slice as it goes beyond the map.
                         */
                        uint32_t payload_size = vsst->map + mmd->size - buf;
                        memcpy(fc->extra_src_buf, buf, payload_size);
@@ -627,6 +644,7 @@ void vss_del_fec_client(struct fec_client *fc)
        free(fc->src_data);
        free(fc->enc_buf);
        free(fc->extra_src_buf);
+       free(fc->extra_header_buf);
        fec_free(fc->parms);
        free(fc);
 }