X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=vss.c;h=f1dbfb97fa45db3c79628887f0783301f218b4e9;hb=4cfbdce5e460934d4724cac63aa718ea6c7af199;hp=b34703de5bd8b8fb46a99a87587c77f86e0ca617;hpb=c85690666e2ed2327e751b819970658d58479bfb;p=paraslash.git diff --git a/vss.c b/vss.c index b34703de..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,6 +43,8 @@ static struct timeval autoplay_barrier; extern struct misc_meta_data *mmd; extern struct audio_file_selector selectors[]; extern struct sender senders[]; +static char *inbuf; +static size_t *chunk_table, inbuf_size; static FILE *audio_file = NULL; @@ -86,6 +89,8 @@ static struct audio_format_handler afl[] = { /** iterate over each supported audio format */ #define FOR_EACH_AUDIO_FORMAT(i) for (i = 0; afl[i].name; i++) + + /** * check if vss status flag \a P (playing) is set * @@ -182,7 +187,7 @@ void vss_init(void) static int get_file_info(int i) { return afl[i].get_file_info(audio_file, mmd->audio_file_info, - &mmd->chunks_total, &mmd->seconds_total); + &mmd->chunks_total, &mmd->seconds_total, &chunk_table); } /** @@ -220,7 +225,7 @@ static int get_audio_format(int omit) int i; FOR_EACH_AUDIO_FORMAT(i) { - if (i == omit || !afl[i].get_file_info) + if (i == omit) continue; rewind(audio_file); if (get_file_info(i) > 0) @@ -482,8 +487,6 @@ again: } mmd->chunks_sent = 0; } - if (af && vss_repos() && mmd->current_chunk != mmd->repos_request) - af->reposition_stream(mmd->repos_request); if (vss_repos()) { mmd->new_vss_status_flags &= ~(VSS_REPOS); mmd->current_chunk = mmd->repos_request; @@ -498,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 * @@ -510,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; @@ -531,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)