From 5312e9fd4550454f290a82c114bc2a2bcb66e993 Mon Sep 17 00:00:00 2001 From: Andre Date: Sat, 17 Jun 2006 11:27:15 +0200 Subject: [PATCH] fix audiod stream delay This was known to be broken by the sched conversion. It was also the last remaining missing feature of the new audiod. Let's beat on it for a while. --- audiod.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/audiod.c b/audiod.c index 66ef9c6a..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 @@ -539,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: @@ -603,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; @@ -621,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; } } } -- 2.39.5