From: Andre Noll Date: Mon, 11 Jan 2010 00:06:39 +0000 (+0100) Subject: audiod: Timing fixes. X-Git-Tag: v0.4.2~161 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=decf72f578ef0cb7a3bc3a81834ef64c2b19c91f;p=paraslash.git audiod: Timing fixes. --- diff --git a/audiod.c b/audiod.c index f805b00e..a6408d87 100644 --- a/audiod.c +++ b/audiod.c @@ -313,6 +313,7 @@ static void close_receiver(int slot_num) { struct slot_info *s = &slot[slot_num]; struct audio_format_info *a; + struct timeval restart_delay = {0, 200 * 1000}; if (s->format < 0 || !s->receiver_node) return; @@ -323,7 +324,7 @@ static void close_receiver(int slot_num) btr_free_node(s->receiver_node->btrn); free(s->receiver_node); s->receiver_node = NULL; - stat_task->current_audio_format_num = -1; + tv_add(now, &restart_delay, &afi[s->format].restart_barrier); } static void writer_cleanup(struct writer_node *wn) @@ -586,11 +587,13 @@ static int open_current_receiver(struct sched *s) * belongs to the file just completed. */ if (stat_task->server_stream_start.tv_sec != 0) - return -1; + sched_request_timeout_ms(100, s); } if (tv_diff(now, &afi[cafn].restart_barrier, &diff) < 0) { - /* avoid busy loop */ - s->timeout = diff; + if (tv_diff(&s->timeout, &diff, NULL) > 0) + s->timeout = diff; + else + sched_min_delay(s); return -1; } /* start a new receiver */ @@ -1029,27 +1032,28 @@ static void set_stat_task_restart_barrier(unsigned seconds) tv_add(now, &delay, &stat_task->restart_barrier); } -static void try_to_close_slot(int slot_num) +static bool try_to_close_slot(int slot_num) { struct slot_info *s = &slot[slot_num]; struct audio_format_info *a = afi + s->format; int i; if (s->format < 0) - return; + return false; if (s->receiver_node && s->receiver_node->task.error != -E_TASK_UNREGISTERED) - return; + return false; for (i = 0; i < a->num_filters; i++) if (s->fns && s->fns[i].task.error != -E_TASK_UNREGISTERED) - return; + return false; for (i = 0; i < a->num_writers; i++) if (s->wns && s->wns[i].task.error != -E_TASK_UNREGISTERED) - return; + return false; PARA_INFO_LOG("closing slot %d\n", slot_num); close_writers(s); _close_filters(s); close_receiver(slot_num); clear_slot(slot_num); + return true; } /* @@ -1063,7 +1067,8 @@ static void start_stop_decoders(struct sched *s) struct audio_format_info *a; FOR_EACH_SLOT(i) - try_to_close_slot(i); + if (try_to_close_slot(i)) + sched_min_delay(s); // if (audiod_status != AUDIOD_ON || // !(stat_task->vss_status & VSS_STATUS_FLAG_PLAYING)) // return kill_all_decoders(-E_NOT_PLAYING); @@ -1077,8 +1082,7 @@ static void start_stop_decoders(struct sched *s) open_writers(sl); activate_grab_clients(); btr_log_tree(sl->receiver_node->btrn, LL_NOTICE); - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; + sched_min_delay(s); } /* restart the client task if necessary */ @@ -1129,18 +1133,20 @@ static void status_pre_select(struct sched *s, struct task *t) if (tv_diff(now, &st->restart_barrier, NULL) < 0) goto out; if (st->clock_diff_count) { /* get status only one time */ - char *argv[] = {"audiod", "--", "stat", "-p", "1", NULL}; + char *argv[] = {"audiod", "--", "stat", "-p", "-n=1", NULL}; int argc = 5; PARA_INFO_LOG("clock diff count: %d\n", st->clock_diff_count); st->clock_diff_count--; client_open(argc, argv, &st->ct, NULL); set_stat_task_restart_barrier(2); + sched_min_delay(s); } else { char *argv[] = {"audiod", "--", "stat", "-p", NULL}; int argc = 4; client_open(argc, argv, &st->ct, NULL); set_stat_task_restart_barrier(5); + sched_min_delay(s); } free(stat_item_values[SI_BASENAME]); stat_item_values[SI_BASENAME] = para_strdup(