From: Andre Noll Date: Mon, 22 Oct 2007 21:55:50 +0000 (+0200) Subject: vss.c: Small simplifications. X-Git-Tag: v0.3.0~268 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=45eb409116552cd186054b73b7ca6a34b304d169;p=paraslash.git vss.c: Small simplifications. --- diff --git a/vss.c b/vss.c index 82dff47e..70b54f64 100644 --- a/vss.c +++ b/vss.c @@ -337,6 +337,7 @@ static void vss_eof(void) int i; char *tmp; + PARA_NOTICE_LOG("EOF\n"); if (!map) { for (i = 0; senders[i].name; i++) senders[i].shutdown_clients(); @@ -418,7 +419,7 @@ enum afs_socket_status { static enum afs_socket_status afsss; /** - * compute the timeout for para_server's main select-loop + * Compute the timeout for para_server's main select-loop. * * This function gets called from para_server to determine the timeout value * for its main select loop. @@ -427,36 +428,32 @@ static enum afs_socket_status afsss; * and acted upon by calling appropriate functions from the lower layers. * Possible actions include * - * - request a new file list from the current audio file selector - * - shutdown of all senders (stop/pause command) - * - reposition the stream (ff/jmp command) + * - request a new audio file from afs, + * - shutdown of all senders (stop/pause command), + * - reposition the stream (ff/jmp command). * * \return A pointer to a struct timeval containing the timeout for the next * chunk of data to be sent, or NULL if we're not sending right now. */ struct timeval *vss_preselect(fd_set *rfds, fd_set *wfds, int *max_fileno) { - struct audio_format_handler *af = NULL; - int i, format; - struct timeval *ret; + int i; + struct timeval *tv; para_fd_set(afs_socket, rfds, max_fileno); - -//again: - format = mmd->audio_format; - if (format >= 0) - af = afl + format; - else + if (!map) for (i = 0; senders[i].name; i++) senders[i].shutdown_clients(); - if (vss_next() && af) { - vss_eof(); - return vss_compute_timeout(); + else { + if (vss_next()) { + vss_eof(); + return vss_compute_timeout(); + } } if (vss_paused() || vss_repos()) { for (i = 0; senders[i].name; i++) senders[i].shutdown_clients(); - if (af) { + if (map) { struct timeval now; gettimeofday(&now, NULL); if (!vss_paused() || mmd->chunks_sent) @@ -472,18 +469,18 @@ struct timeval *vss_preselect(fd_set *rfds, fd_set *wfds, int *max_fileno) mmd->new_vss_status_flags &= ~(VSS_REPOS); mmd->current_chunk = mmd->repos_request; } - ret = vss_compute_timeout(); - if (!ret && !map && vss_playing() && + tv = vss_compute_timeout(); + if (tv) + return tv; + if (!map && vss_playing() && !(mmd->new_vss_status_flags & VSS_NOMORE)) { PARA_DEBUG_LOG("%s", "ready and playing, but no audio file\n"); - //vss_get_audio_file(); if (afsss == AFS_SOCKET_READY) { para_fd_set(afs_socket, wfds, max_fileno); afsss = AFS_SOCKET_CHECK_FOR_WRITE; } -// goto again; } - return ret; + return tv; } static int recv_afs_msg(int *fd, uint32_t *code, uint32_t *data) @@ -527,6 +524,7 @@ static void recv_afs_result(void) struct stat statbuf; struct timeval now; + PARA_NOTICE_LOG("recv\n"); ret = recv_afs_msg(&passed_fd, &afs_code, &afs_data); if (ret < 0) goto err; @@ -579,6 +577,7 @@ void vss_post_select(fd_set *rfds, fd_set *wfds) recv_afs_result(); if (afsss != AFS_SOCKET_CHECK_FOR_WRITE || !FD_ISSET(afs_socket, wfds)) return; + PARA_NOTICE_LOG("requesting new socket\n"); ret = send_buffer(afs_socket, "new"); afsss = AFS_SOCKET_AFD_PENDING; } @@ -588,6 +587,10 @@ static void get_chunk(long unsigned chunk_num, char **buf, size_t *len) size_t pos = mmd->afi.chunk_table[chunk_num]; *buf = map + pos; *len = mmd->afi.chunk_table[chunk_num + 1] - pos; + + if (chunk_num + 5 > mmd->afd.afhi.chunks_total) + PARA_NOTICE_LOG("chunk %lu/%lu\n, len: %zu\n", chunk_num, + mmd->afd.afhi.chunks_total, *len); } /** @@ -623,6 +626,8 @@ void vss_send_chunk(void) int i; struct audio_format_handler *af; struct timeval now, due; + char *buf; + size_t len; if (mmd->audio_format < 0 || !map || !vss_playing()) return; @@ -652,12 +657,9 @@ void vss_send_chunk(void) mmd->offset = tv2ms(&tmp); mmd->events++; } - for (i = 0; senders[i].name; i++) { - char *buf; - size_t len; - get_chunk(mmd->current_chunk, &buf, &len); + get_chunk(mmd->current_chunk, &buf, &len); + for (i = 0; senders[i].name; i++) senders[i].send(mmd->current_chunk, mmd->chunks_sent, buf, len); - } mmd->new_vss_status_flags |= VSS_PLAYING; mmd->chunks_sent++; mmd->current_chunk++;