summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e56d454)
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.
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);
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);
void afh_get_header(struct afh_info *afhi, void *map, const char **buf, size_t *len);
*len = afhi->chunk_table[chunk_num + 1] - pos;
}
*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.
*
/**
* Get the header of an audio file.
*
int fd;
/** Vss needs this for streaming. */
struct afh_info afhi;
int fd;
/** Vss needs this for streaming. */
struct afh_info afhi;
+ /** Size of the largest chunk. */
+ uint32_t max_chunk_size;
return 4 * (afhi->chunks_total + 1);
}
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)
-
- 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)
}
static void load_chunk_table(struct afh_info *afhi, char *buf)
ret = shm_attach(shmid, ATTACH_RW, &shm_afd);
if (ret < 0)
goto err;
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);
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:
shm_detach(shm_afd);
return shmid;
err:
if (ret < 0)
goto err;
hs = ret;
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;
if (ret < 0)
goto err;
ds = ret;