struct afh_info *afhi)
{
uint64_t freq_sum = 0, br_sum = 0;
- int ret, len = 0, old_br = -1, vbr = 0;
+ int fl = 0, ret, len = 0, old_br = -1, vbr = 0;
struct timeval total_time = {0, 0};
unsigned chunk_table_size = 1000; /* gets increased on demand */
off_t fpos = 0;
afhi->chunk_table = para_malloc(chunk_table_size * sizeof(uint32_t));
taginfo = mp3_get_id3(map, numbytes, fd);
while (1) {
- int freq, br, fl;
+ int freq, br;
struct timeval tmp, cct; /* current chunk time */
fpos += len;
len = find_valid_start(map, numbytes, &fpos, &header);
- if (len <= 0)
+ if (len <= 0) {
+ uint32_t end;
+ ret = -E_MP3_INFO;
+ if (!afhi->chunks_total)
+ goto err_out;
+ end = afhi->chunk_table[afhi->chunks_total - 1] + fl;
+ afhi->chunk_table[afhi->chunks_total]
+ = PARA_MIN(end, numbytes);
break;
+ }
ret = header_frequency(&header);
if (ret < 0)
continue;
old_br = br;
}
ret = -E_MP3_INFO;
- if (!afhi->chunks_total || !freq_sum || !br_sum)
+ if (!freq_sum || !br_sum)
goto err_out;
- afhi->chunk_table[afhi->chunks_total] = numbytes - 1;
afhi->bitrate = br_sum / afhi->chunks_total;
afhi->frequency = freq_sum / afhi->chunks_total;
afhi->channels = header_channels(&header);