X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=vss.c;h=9aeff44fd77e508d7c842a386a115ef5f72330cf;hp=f1dbfb97fa45db3c79628887f0783301f218b4e9;hb=d61d4f3dc0d2e0a59e221add150bf971c0f03c65;hpb=4cfbdce5e460934d4724cac63aa718ea6c7af199 diff --git a/vss.c b/vss.c index f1dbfb97..9aeff44f 100644 --- a/vss.c +++ b/vss.c @@ -501,33 +501,38 @@ again: return ret; } -static char *vss_read_chunk(long unsigned current_chunk, ssize_t *len) +/** + * read a chunk of data from the current audio file + * + * \param current_chunk the chunk number to read + * + * \return The length of the chunk on success, zero on end of file, negative on + * errors. Note: If the current chunk is of length zero, but the end of the + * file is not yet reached, this function returns -E_EMPTY_CHUNK. + * */ +ssize_t vss_read_chunk(void) { - int ret; + ssize_t len; 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; + int ret; + long unsigned cc = mmd->current_chunk; + + if (cc >= mmd->chunks_total) /* eof */ + return 0; + len = chunk_table[cc + 1] - chunk_table[cc]; + if (!len) /* nothing to send for this run */ + return -E_EMPTY_CHUNK; + pos = chunk_table[cc]; + if (inbuf_size < len) { + PARA_INFO_LOG("increasing inbuf for chunk #%lu/%lu to %zu bytes\n", + cc, 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); + ret = para_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; + return ret; + return para_fread(inbuf, len, 1, audio_file); } /** @@ -546,7 +551,6 @@ void vss_send_chunk(void) { int i; struct audio_format_handler *af; - char *buf; ssize_t ret; struct timeval now, due; @@ -562,16 +566,23 @@ void vss_send_chunk(void) if (chk_barrier("data send", &now, &data_send_barrier, &due, 1) < 0) return; - buf = vss_read_chunk(mmd->current_chunk, &ret); + ret= vss_read_chunk(); mmd->new_vss_status_flags &= ~VSS_REPOS; - if (!buf) { - if (ret < 0) + if (!ret || (ret < 0 && ret != -E_EMPTY_CHUNK)) { + if (ret < 0) { mmd->new_vss_status_flags = VSS_NEXT; - else + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + } else mmd->new_vss_status_flags |= VSS_NEXT; vss_eof(af); return; } + /* + * We call the send function also in case of empty chunks as they + * might have still some data queued which can be sent in this case. + */ + if (ret < 0) + ret = 0; if (!mmd->chunks_sent) { struct timeval tmp; gettimeofday(&mmd->stream_start, NULL); @@ -580,7 +591,7 @@ void vss_send_chunk(void) mmd->events++; } for (i = 0; senders[i].name; i++) - senders[i].send(mmd->current_chunk, mmd->chunks_sent, buf, ret); + senders[i].send(mmd->current_chunk, mmd->chunks_sent, inbuf, ret); mmd->new_vss_status_flags |= VSS_PLAYING; mmd->chunks_sent++; mmd->current_chunk++;