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);
*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.
*
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)
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: