]> git.tue.mpg.de Git - paraslash.git/commitdiff
fix audiod stream delay
authorAndre <maan@p133.(none)>
Sat, 17 Jun 2006 09:27:15 +0000 (11:27 +0200)
committerAndre <maan@p133.(none)>
Sat, 17 Jun 2006 09:27:15 +0000 (11:27 +0200)
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

index 66ef9c6ac3fb113f9d4e4720bf1002ace82aa46f..d4a29720340457f56af41058d19651a3f0b559e3 100644 (file)
--- 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;
                }
        }
 }