From: Andre Noll Date: Sun, 11 Mar 2007 17:56:01 +0000 (+0100) Subject: mp3_afh.c: Kill global variable num_chunks and seconds. X-Git-Tag: v0.2.16~32 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=7e002af5ee72f6ac95a760959a4bc1435271dcae;p=paraslash.git mp3_afh.c: Kill global variable num_chunks and seconds. num_chunks has the same meaning as chunks_total in struct audio format. Similarly, mp3.seconds has the same meaning as afi->seconds. So use these. --- diff --git a/mp3_afh.c b/mp3_afh.c index 605aac25..a5f8d740 100644 --- a/mp3_afh.c +++ b/mp3_afh.c @@ -42,7 +42,6 @@ * 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 @@ -74,7 +73,6 @@ struct mp3info { struct id3tag id3; int vbr; long unsigned br_average; - long unsigned seconds; int freq; }; @@ -103,7 +101,6 @@ static const int frame_size_index[] = {24000, 72000, 72000}; 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) { @@ -146,10 +143,10 @@ static void write_info_str(struct audio_format_info *afi) 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', @@ -356,7 +353,7 @@ static int mp3_read_info(FILE *file, struct audio_format_info *afi) 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) @@ -386,43 +383,44 @@ static int mp3_read_info(FILE *file, struct audio_format_info *afi) 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; @@ -443,8 +441,6 @@ static int mp3_get_file_info(FILE *file, struct audio_format_info *afi) 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;