X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=audiod.c;h=d4a29720340457f56af41058d19651a3f0b559e3;hb=5312e9fd4550454f290a82c114bc2a2bcb66e993;hp=032b608cbc3acb32e537350fffba2a01aa27c099;hpb=786010c598f79d20280e6ea9ea458cad4a7e9af7;p=paraslash.git diff --git a/audiod.c b/audiod.c index 032b608c..d4a29720 100644 --- a/audiod.c +++ b/audiod.c @@ -79,6 +79,7 @@ static struct signal_task signal_task_struct, *sig_task = &signal_task_struct; static struct status_task status_task_struct; struct status_task *stat_task = &status_task_struct; +static struct timeval initial_delay_barrier; /** * the task for handling audiod commands @@ -92,9 +93,15 @@ struct command_task { struct task task; }; +/** + * task for signal handling + */ struct signal_task { + /** the signal pipe */ int fd; + /** the number of the most recent signal */ int signum; + /** the associated task structure */ struct task task; }; @@ -533,8 +540,18 @@ static void check_stat_line(char *line) break; case SI_STREAM_START: if (sscanf(line + ilen + 1, "%lu.%lu", &sec, &usec) == 2) { + struct timeval tmp, delay; + delay.tv_sec = conf.stream_delay_arg / 1000; + delay.tv_usec = (conf.stream_delay_arg % 1000) * 1000; stat_task->server_stream_start.tv_sec = sec; stat_task->server_stream_start.tv_usec = usec; + if (stat_task->sa_time_diff_sign < 0) + tv_add(&stat_task->server_stream_start, + &stat_task->sa_time_diff, &tmp); + else + tv_diff(&stat_task->server_stream_start, + &stat_task->sa_time_diff, &tmp); + tv_add(&tmp, &delay, &initial_delay_barrier); } break; case SI_CURRENT_TIME: @@ -597,6 +614,7 @@ static void audiod_pre_select(struct sched *s, __a_unused struct task *t) FOR_EACH_SLOT(i) { struct slot_info *sl = &slot[i]; struct audio_format_info *a; + struct timeval diff; if (sl->format < 0) continue; @@ -615,9 +633,20 @@ static void audiod_pre_select(struct sched *s, __a_unused struct task *t) s->timeout = min_delay; continue; } - if (sl->fc && *sl->fc->out_loaded && !sl->wng) { + if (!sl->fc || !*sl->fc->out_loaded || sl->wng) + continue; + if (tv_diff(now, &initial_delay_barrier, &diff) > 0) { + PARA_INFO_LOG("barrier: %lu:%lu, now: %lu, %lu\n", + initial_delay_barrier.tv_sec, + initial_delay_barrier.tv_usec, + now->tv_sec, now->tv_usec); open_writers(i); s->timeout = min_delay; + continue; + } + PARA_INFO_LOG("inital delay: %lu ms left\n", tv2ms(&diff)); + if (tv_diff(&s->timeout, &diff, NULL) > 0) { + s->timeout = diff; } } } @@ -872,7 +901,7 @@ static int audiod_get_socket(void) return fd; } -void signal_event_handler(struct task *t) +static void signal_event_handler(struct task *t) { struct signal_task *st = t->private_data; @@ -882,14 +911,14 @@ void signal_event_handler(struct task *t) handle_signal(st->signum); } -void signal_pre_select(struct sched *s, struct task *t) +static void signal_pre_select(struct sched *s, struct task *t) { struct signal_task *st = t->private_data; t->ret = 1; para_fd_set(st->fd, &s->rfds, &s->max_fileno); } -void signal_post_select(struct sched *s, struct task *t) +static void signal_post_select(struct sched *s, struct task *t) { struct signal_task *st = t->private_data; t->ret = 1; @@ -899,7 +928,7 @@ void signal_post_select(struct sched *s, struct task *t) st->signum = para_next_signal(); } -void signal_setup_default(struct signal_task *st) +static void signal_setup_default(struct signal_task *st) { st->task.pre_select = signal_pre_select; st->task.post_select = signal_post_select; @@ -991,7 +1020,7 @@ static void status_post_select(__a_unused struct sched *s, struct task *t) t->ret = 1; if (!st->pcd || !st->pcd->loaded - || st->pcd->status != CL_RECEIVING_SERVER_OUTPUT) + || st->pcd->status != CL_RECEIVING) return; st->pcd->loaded = for_each_line(st->pcd->buf, st->pcd->loaded, &check_stat_line);