X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=vss.c;h=d205349370f69a9445ff1db7bb1c269b2d6431a7;hp=48bfa7d75c60049b87f3bdd09906cfcb17527aac;hb=26d662890f5e1c29c0b09d1cac94b8b4acb065ed;hpb=933eed80c988c0d242cb724143f82a4484a830fb diff --git a/vss.c b/vss.c index 48bfa7d7..d2053493 100644 --- a/vss.c +++ b/vss.c @@ -65,15 +65,25 @@ enum afs_socket_status { /** The task structure for the virtual streaming system. */ struct vss_task { + /** Copied from the -announce_time command line option. */ struct timeval announce_tv; + /** End of the announcing interval. */ struct timeval data_send_barrier; + /** End of the EOF interval. */ struct timeval eof_barrier; + /** Only used if --autoplay_delay was given. */ struct timeval autoplay_barrier; + /** Used for afs-server communication. */ int afs_socket; + /** The current state of \a afs_socket. */ enum afs_socket_status afsss; + /** The memory mapped audio file. */ char *map; + /** Used by the scheduler. */ struct task task; + /** Pointer to the header of the mapped audio file. */ const char *header_buf; + /** Length of the audio file header. */ size_t header_len; }; @@ -236,6 +246,8 @@ struct timeval *vss_chunk_time(void) static int need_to_request_new_audio_file(struct vss_task *vsst) { + struct timeval diff; + if (vsst->map) /* have audio file */ return 0; if (!vss_playing()) /* don't need one */ @@ -244,6 +256,9 @@ static int need_to_request_new_audio_file(struct vss_task *vsst) return 0; if (vsst->afsss == AFS_SOCKET_AFD_PENDING) /* already requested one */ return 0; + if (chk_barrier("autoplay_delay", &vsst->autoplay_barrier, + &diff, 1) < 0) + return 0; return 1; } @@ -280,6 +295,7 @@ static void vss_pre_select(struct sched *s, struct task *t) tv_add(&mmd->afd.afhi.eof_tv, now, &vsst->eof_barrier); mmd->chunks_sent = 0; } else if (vss_repos()) { + tv_add(now, &vsst->announce_tv, &vsst->data_send_barrier); tv_add(&mmd->afd.afhi.eof_tv, now, &vsst->eof_barrier); mmd->chunks_sent = 0; mmd->current_chunk = mmd->repos_request; @@ -366,8 +382,10 @@ static void recv_afs_result(struct vss_task *vsst) } mmd->size = statbuf.st_size; mmd->mtime = statbuf.st_mtime; - vsst->map = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE, - passed_fd, 0); + ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE, passed_fd, + 0, &vsst->map); + if (ret < 0) + goto err; close(passed_fd); mmd->chunks_sent = 0; mmd->current_chunk = 0; @@ -463,7 +481,8 @@ static void vss_post_select(struct sched *s, struct task *t) continue; senders[i].post_select(&s->rfds, &s->wfds); } - if (vss_playing() && !(mmd->vss_status_flags & VSS_PLAYING)) + if ((vss_playing() && !(mmd->vss_status_flags & VSS_PLAYING)) || + (vss_next() && vss_playing())) tv_add(now, &vsst->announce_tv, &vsst->data_send_barrier); vss_send_chunk(vsst); } @@ -505,6 +524,8 @@ void init_vss_task(int afs_socket) mmd->new_vss_status_flags |= VSS_PLAYING; ms2tv(autoplay_delay, &tmp); tv_add(now, &tmp, &vsst->autoplay_barrier); + tv_add(&vsst->autoplay_barrier, &vsst->announce_tv, + &vsst->data_send_barrier); } register_task(&vsst->task); }