]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Compute the maximal chunk size only once.
authorAndre Noll <maan@systemlinux.org>
Sat, 7 Aug 2010 15:46:44 +0000 (17:46 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 31 Oct 2010 11:06:57 +0000 (12:06 +0100)
This patch adds the new field max_chunk_size to struct audio_file_data.
It is initialized in the afs process when the chunk table is saved,
just before the audio_file_data struct is passed to the server process.

The vss code benefits from this change since it can just use the
new information rather than calling afh_get_largest_chunk_size()
to recompute the maximal chunk size from scratch whenever a new
client connects.

Since vss.c was the only user of afh_get_largest_chunk_size(), we
may kill this function.

afh.h
afh_common.c
afs.h
aft.c
vss.c

diff --git a/afh.h b/afh.h
index 6dfd03ed0d89d15568fa2096ada83909531d5bab..ccfed2fbe897d368eb7e836d16074d52d5f7ccb1 100644 (file)
--- a/afh.h
+++ b/afh.h
@@ -104,5 +104,4 @@ int compute_afhi(const char *path, char *data, size_t size,
 const char *audio_format_name(int);
 void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
                void *map, const char **buf, size_t *len);
-uint32_t afh_get_largest_chunk_size(struct afh_info *afhi);
 void afh_get_header(struct afh_info *afhi, void *map, const char **buf, size_t *len);
index 4464987a61fc5172e2601cded9aac0998c9cfda2..952ef7ca2965fb3a759e6a46296f1227615d6bce 100644 (file)
@@ -245,22 +245,6 @@ void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
        *len = afhi->chunk_table[chunk_num + 1] - pos;
 }
 
-/**
- * Compute the size of the largest chunk of an audio file.
- *
- * \param afhi The audio format handler struct containing the chunk table.
- *
- * \return The number of bytes of the largest chunk.
- */
-uint32_t afh_get_largest_chunk_size(struct afh_info *afhi)
-{
-       uint32_t n, largest = 0, *ct = afhi->chunk_table;
-
-       for (n = 1; n <= afhi->chunks_total; n++)
-               largest = PARA_MAX(largest, ct[n] - ct[n - 1]);
-       return largest;
-}
-
 /**
  * Get the header of an audio file.
  *
diff --git a/afs.h b/afs.h
index 76b819058642db7ffb81acf5eaa268f3cae37f3a..ba5e134c94fcd7ac6aeb4179c611969038f285f0 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -129,6 +129,8 @@ struct audio_file_data {
        int fd;
        /** Vss needs this for streaming. */
        struct afh_info afhi;
+       /** Size of the largest chunk. */
+       uint32_t max_chunk_size;
 };
 
 /**
diff --git a/aft.c b/aft.c
index eb0f7b57911ed49fdb19a6bee1638d84ef1288a2..aa6ef08f21d1ab92afd557fc0b422cc90c7c61e4 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -434,12 +434,26 @@ static unsigned sizeof_chunk_table(struct afh_info *afhi)
        return 4 * (afhi->chunks_total + 1);
 }
 
-static void save_chunk_table(struct afh_info *afhi, char *buf)
+static uint32_t save_chunk_table(struct afh_info *afhi, char *buf)
 {
        int i;
-
-       for (i = 0; i <= afhi->chunks_total; i++)
-               write_u32(buf + 4 * i, afhi->chunk_table[i]);
+       uint32_t max = 0, old = 0;
+
+       for (i = 0; i <= afhi->chunks_total; i++) {
+               uint32_t val = afhi->chunk_table[i];
+               write_u32(buf + 4 * i, val);
+               /*
+                * If the first chunk is the header, do not consider it for the
+                * calculation of the largest chunk size.
+                */
+               if (i == 0 || (i == 1 && afhi->header_len > 0)) {
+                       old = val;
+                       continue;
+               }
+               max = PARA_MAX(max, val - old);
+               old = val;
+       }
+       return max;
 }
 
 static void load_chunk_table(struct afh_info *afhi, char *buf)
@@ -640,10 +654,10 @@ static int save_afd(struct audio_file_data *afd)
        ret = shm_attach(shmid, ATTACH_RW, &shm_afd);
        if (ret < 0)
                goto err;
-       *(struct audio_file_data *)shm_afd = *afd;
        buf = shm_afd;
        buf += sizeof(*afd);
-       save_chunk_table(&afd->afhi, buf);
+       afd->max_chunk_size = save_chunk_table(&afd->afhi, buf);
+       *(struct audio_file_data *)shm_afd = *afd;
        shm_detach(shm_afd);
        return shmid;
 err:
diff --git a/vss.c b/vss.c
index 25082834eb0160de013dd11639f3354160ee261b..383a8fda0710653c28c5853c2b8e7949b9b45b54 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -283,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;