From: Andre Noll Date: Sat, 7 Aug 2010 15:46:44 +0000 (+0200) Subject: Compute the maximal chunk size only once. X-Git-Tag: v0.4.5~17 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=12379df1a1f89645e04c393d614937c0e6439ae0;ds=sidebyside Compute the maximal chunk size only once. 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. --- diff --git a/afh.h b/afh.h index 6dfd03ed..ccfed2fb 100644 --- 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); diff --git a/afh_common.c b/afh_common.c index 4464987a..952ef7ca 100644 --- a/afh_common.c +++ b/afh_common.c @@ -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 76b81905..ba5e134c 100644 --- 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 eb0f7b57..aa6ef08f 100644 --- 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 25082834..383a8fda 100644 --- 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;