X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=ogg_afh.c;h=6ca31a58c063eaeee9f1bd057e5857d7f2e169dd;hp=b5ecc4b0f3ebc96ec5459d3e7a7e59c3ce5326f9;hb=ec48b7d6022f59f509cedcbdd635979e37671d4e;hpb=c0067c4d103b41d1f80b83170719d4afa999be54 diff --git a/ogg_afh.c b/ogg_afh.c index b5ecc4b0..6ca31a58 100644 --- a/ogg_afh.c +++ b/ogg_afh.c @@ -35,16 +35,15 @@ static double chunk_time = 0.25; static OggVorbis_File *oggvorbis_file; -static FILE *infile; -static int header_len, inbuf_size, vi_channels; -static char *header, *inbuf; +static int header_len; +static char *header; static ssize_t *chunk_table, max_chunk_len, num_chunks; static struct audio_format_handler *af; static long vi_sampling_rate, vi_bitrate, vi_bitrate_nominal; -static int ogg_compute_header_len(void) +static int ogg_compute_header_len(FILE *file) { - int ret, len, in = fileno(infile); + int ret, len, in = fileno(file); unsigned int serial; char *buf; ogg_page page; @@ -146,7 +145,7 @@ static void tunetable(void) /* * Alloc and fill array table of byte offsets. chunk_table[i] is the - * offset in the current infile at which the sample containing time i * + * offset in the current input file at which the sample containing time i * * CHUNK_TIME begins. */ static void ogg_compute_chunk_table(double time_total) @@ -162,7 +161,6 @@ static void ogg_compute_chunk_table(double time_total) chunk_table = para_malloc(num * sizeof(size_t)); chunk_table[0] = 0; max_chunk_len = 0; - rewind(infile); for (i = 1; ret == 0; i++) { ogg_int64_t diff; ret = ov_time_seek(oggvorbis_file, i * chunk_time); @@ -184,7 +182,6 @@ static void ogg_compute_chunk_table(double time_total) tunetable(); PARA_INFO_LOG("%zu chunks (%fs), max chunk: %zd, min chunk: %zd\n", num_chunks, chunk_time, max_chunk_len, min); - rewind(infile); } static void ogg_close_audio_file(void) @@ -201,9 +198,6 @@ static void ogg_close_audio_file(void) free(chunk_table); chunk_table = NULL; num_chunks = 0; - free(inbuf); - inbuf = NULL; - inbuf_size = 0; } static int ogg_save_header(FILE *file, int len) @@ -222,17 +216,16 @@ static int ogg_save_header(FILE *file, int len) * Init oggvorbis file and write some tech data to given pointers. */ static int ogg_get_file_info(FILE *file, char *info_str, long unsigned *frames, - int *seconds) + int *seconds, size_t **vss_chunk_table) { int ret; double time_total; vorbis_info *vi; ogg_int64_t raw_total; - infile = file; if (!file) return -E_OGG_NO_FILE; - ret = ogg_compute_header_len(); + ret = ogg_compute_header_len(file); if (ret < 0) return ret; ret = ogg_save_header(file, header_len); @@ -256,14 +249,16 @@ static int ogg_get_file_info(FILE *file, char *info_str, long unsigned *frames, vi_sampling_rate = vi->rate; vi_bitrate = ov_bitrate(oggvorbis_file, 0); vi_bitrate_nominal = vi->bitrate_nominal; - vi_channels = vi->channels; + rewind(file); ogg_compute_chunk_table(time_total); + rewind(file); *frames = num_chunks; + *vss_chunk_table = chunk_table; sprintf(info_str, "audio_file_info1:%zu x %lu, %ldkHz, %d channels, %ldkbps\n" "audio_file_info2: \n" "audio_file_info3: \n", num_chunks, (long unsigned) (chunk_time * 1000 * 1000), - vi_sampling_rate / 1000, vi_channels, vi_bitrate / 1000 + vi_sampling_rate / 1000, vi->channels, vi_bitrate / 1000 ); rewind(file); return 1; @@ -272,37 +267,6 @@ err: return ret; } -static char *ogg_read_chunk(long unsigned current_chunk, ssize_t *len) -{ - int ret; - size_t pos; - - *len = 0; - if (current_chunk >= num_chunks) - return NULL; - *len = chunk_table[current_chunk + 1] - chunk_table[current_chunk]; - if (!*len) /* nothing to send for this run */ - return inbuf; - pos = chunk_table[current_chunk]; - if (inbuf_size < *len) { - PARA_INFO_LOG("increasing inbuf for chunk #%lu/%zu to %zd bytes\n", - current_chunk, num_chunks, *len); - inbuf = para_realloc(inbuf, *len); - inbuf_size = *len; - } -// PARA_DEBUG_LOG("reading chunk #%lu@%zd (%zd bytes)\n", current_chunk, -// pos, *len); - ret = fseek(infile, pos, SEEK_SET); - if (ret < 0) - return NULL; - ret = para_fread(inbuf, *len, 1, infile); - if (ret != *len) - return NULL; -// PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0], -// (long unsigned) inbuf[4]); - return (char *)inbuf; -} - static char *ogg_get_header_info(int *len) { *len = header_len; @@ -320,7 +284,6 @@ void ogg_init(struct audio_format_handler *p) { af = p; af->get_file_info = ogg_get_file_info, - af->read_chunk = ogg_read_chunk; af->close_audio_file = ogg_close_audio_file; af->get_header_info = ogg_get_header_info; af->chunk_tv.tv_sec = 0;