* to see before we decide we are looking at a real MP3 file
*/
#define MIN_CONSEC_GOOD_FRAMES 4
-
#define FRAME_HEADER_SIZE 4
#define MIN_FRAME_SIZE 21
struct id3tag id3;
int vbr;
long unsigned br_average;
- long unsigned seconds;
int freq;
};
static const char *mode_text[] = {"stereo", "joint stereo", "dual channel", "mono", "invalid"};
static struct mp3info mp3;
-static ssize_t num_chunks;
static int header_frequency(struct mp3header *h)
{
int v = mp3.id3_isvalid;
snprintf(afi->info_string, MMD_INFO_SIZE,
- "audio_file_info1:%d x %lums, %lu kbit/s (%cbr) %i KHz %s\n"
+ "audio_file_info1:%lu x %lums, %lu kbit/s (%cbr) %i KHz %s\n"
"audio_file_info2:%s, by %s\n"
"audio_file_info3:A: %s, Y: %s, C: %s\n",
- num_chunks,
+ afi->chunks_total,
tv2ms(&afi->chunk_tv),
mp3.br_average,
mp3.vbr? 'v' : 'c',
struct timeval total_time = {0, 0};
unsigned chunk_table_size = 1000; /* gets increased on demand */
- num_chunks = 0;
+ afi->chunks_total = 0;
afi->chunk_table = para_malloc(chunk_table_size * sizeof(size_t));
ret = mp3_get_id3(file);
if (ret < 0)
tv_add(&cct, &total_time, &tmp);
total_time = tmp;
//PARA_DEBUG_LOG("%s: br: %d, freq: %d, fl: %d, cct: %lu\n", __func__, br, freq, fl, cct.tv_usec);
- if (num_chunks >= chunk_table_size) {
+ if (afi->chunks_total >= chunk_table_size) {
chunk_table_size *= 2;
afi->chunk_table = para_realloc(afi->chunk_table,
chunk_table_size * sizeof(size_t));
}
- afi->chunk_table[num_chunks] = ftell(file);
- if (num_chunks < 10 || !(num_chunks % 1000))
- PARA_INFO_LOG("chunk #%d: %zd\n", num_chunks,
- afi->chunk_table[num_chunks]);
- num_chunks++;
- if (num_chunks == 1) {
+ afi->chunk_table[afi->chunks_total] = ftell(file);
+ if (afi->chunks_total < 10 || !(afi->chunks_total % 1000))
+ PARA_INFO_LOG("chunk #%lu: %zd\n", afi->chunks_total,
+ afi->chunk_table[afi->chunks_total]);
+ afi->chunks_total++;
+ if (afi->chunks_total == 1) {
freq_avg = freq;
br_avg = br;
old_br = br;
fl_avg = fl;
continue;
}
- freq_avg += (freq - freq_avg) / (num_chunks + 1);
- fl_avg += (fl - fl_avg) / (num_chunks + 1);
- br_avg += (br - br_avg) / (num_chunks + 1);
+ freq_avg += (freq - freq_avg) / (afi->chunks_total + 1);
+ fl_avg += (fl - fl_avg) / (afi->chunks_total + 1);
+ br_avg += (br - br_avg) / (afi->chunks_total + 1);
if (old_br != br)
mp3.vbr = 1;
old_br = br;
}
ret = -E_MP3_INFO;
- if (!num_chunks || !freq_avg || !br_avg)
+ if (!afi->chunks_total || !freq_avg || !br_avg)
goto err_out;
ret= para_fseek(file, 0, SEEK_END);
if (ret < 0)
goto err_out;
- afi->chunk_table[num_chunks] = ftell(file);
+ afi->chunk_table[afi->chunks_total] = ftell(file);
mp3.br_average = br_avg;
mp3.freq = freq_avg;
- mp3.seconds = (tv2ms(&total_time) + 500) / 1000;
- tv_divide(num_chunks, &total_time, &afi->chunk_tv);
+ afi->seconds_total = (tv2ms(&total_time) + 500) / 1000;
+ tv_divide(afi->chunks_total, &total_time, &afi->chunk_tv);
rewind(file);
- PARA_DEBUG_LOG("%zu chunks, each %lums\n", num_chunks, tv2ms(&afi->chunk_tv));
+ PARA_DEBUG_LOG("%lu chunks, each %lums\n", afi->chunks_total,
+ tv2ms(&afi->chunk_tv));
tv_scale(3, &afi->chunk_tv, &afi->eof_tv);
PARA_DEBUG_LOG("eof timeout: %lu\n", tv2ms(&afi->eof_tv));
return 1;
if (ret < 0)
return ret;
write_info_str(afi);
- afi->chunks_total = num_chunks;
- afi->seconds_total = mp3.seconds;
if (afi->seconds_total < 2 || !afi->chunks_total)
return -E_MP3_INFO;
return 1;