From: Andre Noll Date: Sun, 4 Mar 2007 21:31:52 +0000 (+0100) Subject: kill the read_chunk handler of struct audio_format handler X-Git-Tag: v0.2.16~63 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=4cfbdce5e460934d4724cac63aa718ea6c7af199;hp=aee7bc654a67f45556ad2c6dc0e98a06bc95c8ff kill the read_chunk handler of struct audio_format handler chunks are now read by vss_read_chunk(), i.e. the same function is used for all audio formats. --- diff --git a/aac_afh.c b/aac_afh.c index b017a832..e68004b2 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -194,45 +194,12 @@ static int aac_get_file_info(FILE *file, char *info_str, long unsigned *frames, return 1; } -static char *aac_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 const char* aac_suffixes[] = {"m4a", "mp4", NULL}; /** the init function of the aac audio format handler */ void aac_afh_init(struct audio_format_handler *p) { af = p; af->get_file_info = aac_get_file_info, - af->read_chunk = aac_read_chunk; af->close_audio_file = aac_close_audio_file; af->get_header_info = NULL; af->suffixes = aac_suffixes; diff --git a/afh.h b/afh.h index 35b7a70e..77874108 100644 --- a/afh.h +++ b/afh.h @@ -103,16 +103,4 @@ struct audio_format_handler { * for closing the file handle. It is assumed to succeed. */ void (*close_audio_file)(void); - /** - * function responsible for reading one data chunk. - * - * \a read_chunk() must return a pointer to the next chunk of data that should - * be sent out, or \p NULL on errors or if the end of the file was encountered. - * - * If it returns non-NULL, \a len must contain the length of the returned - * buffer (which may be zero if nothing has to be sent for some reason). - * Otherwise, \a len is used to distinguish between the eof and the error case: - * It must be zero in the eof case, or negative if an error occcured. - */ - char * (*read_chunk)(long unsigned chunk_num, ssize_t *len); }; diff --git a/mp3_afh.c b/mp3_afh.c index 398a334e..691f1f09 100644 --- a/mp3_afh.c +++ b/mp3_afh.c @@ -462,37 +462,6 @@ static int mp3_get_file_info(FILE *audio_file, char *info_str, return 1; } -static char *mp3_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 void mp3_close_audio_file(void) { if (!infile) @@ -514,7 +483,6 @@ void mp3_init(struct audio_format_handler *p) { af = p; af->get_file_info = mp3_get_file_info; - af->read_chunk = mp3_read_chunk; af->close_audio_file = mp3_close_audio_file; af->get_header_info = NULL; /* eof_tv gets overwritten in mp3_get_file_info() */ diff --git a/ogg_afh.c b/ogg_afh.c index 483c8365..a18c4d7e 100644 --- a/ogg_afh.c +++ b/ogg_afh.c @@ -273,37 +273,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; @@ -321,7 +290,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; diff --git a/vss.c b/vss.c index ea647254..f1dbfb97 100644 --- a/vss.c +++ b/vss.c @@ -31,6 +31,7 @@ #include "send.h" #include "error.h" #include "string.h" +#include "fd.h" extern const char *status_item_list[]; @@ -42,7 +43,8 @@ static struct timeval autoplay_barrier; extern struct misc_meta_data *mmd; extern struct audio_file_selector selectors[]; extern struct sender senders[]; -static size_t *chunk_table; +static char *inbuf; +static size_t *chunk_table, inbuf_size; static FILE *audio_file = NULL; @@ -499,6 +501,35 @@ again: return ret; } +static char *vss_read_chunk(long unsigned current_chunk, ssize_t *len) +{ + int ret; + size_t pos; + + *len = 0; + if (current_chunk >= mmd->chunks_total) + 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/%lu to %zd bytes\n", + current_chunk, mmd->chunks_total, *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(audio_file, pos, SEEK_SET); + if (ret < 0) + return NULL; + ret = para_fread(inbuf, *len, 1, audio_file); + if (ret != *len) + return NULL; + return inbuf; +} + /** * main sending function * @@ -511,7 +542,6 @@ again: * Return value: Positive return value on success, zero on eof and negative * on errors. */ - void vss_send_chunk(void) { int i; @@ -532,7 +562,7 @@ void vss_send_chunk(void) if (chk_barrier("data send", &now, &data_send_barrier, &due, 1) < 0) return; - buf = af->read_chunk(mmd->current_chunk, &ret); + buf = vss_read_chunk(mmd->current_chunk, &ret); mmd->new_vss_status_flags &= ~VSS_REPOS; if (!buf) { if (ret < 0)