audiod: fix receiver restart delay
authorAndre <maan@p133.(none)>
Thu, 22 Jun 2006 17:35:15 +0000 (19:35 +0200)
committerAndre <maan@p133.(none)>
Thu, 22 Jun 2006 17:35:15 +0000 (19:35 +0200)
The current code started a new receiver node for the current format
only if the receiver_node is NULL for each slot which streams
that format. Since that pointer is only set to NULL _after_ the
writer/filters are closed, audiod did not start the new receiver
early enough.

Fix is simple: Check also the eof field in struct receiver_node.
As we're at it, rename decoder_running() to receiver_running() and
move it straight above its single caller.

As a consequence of this change, the restart_barrier has to be set
already in rn_event_handler() as this is the place where rn->eof is
set to one.

audiod.c

index ac692bc1b5468a2a0f075e8c74ffdf931f556cee..b1313d15f2570fba77657ae2e43964c53c5eb4dd 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -187,20 +187,15 @@ static void close_receiver(int slot_num)
 {
        struct slot_info *s = &slot[slot_num];
        struct audio_format_info *a;
-       const struct timeval restart_delay = {0, 200 * 1000};
 
        if (s->format < 0 || !s->receiver_node)
                return;
        a = &afi[s->format];
        PARA_NOTICE_LOG("closing %s receiver in slot %d (eof = %d)\n",
                audio_formats[s->format] , slot_num, s->receiver_node->eof);
-//     if (!s->receiver_node->eof)
-//             unregister_task(&s->receiver_node->task);
        a->receiver->close(s->receiver_node);
        free(s->receiver_node);
        s->receiver_node = NULL;
-       /* set restart barrier */
-       tv_add(now, &restart_delay, &afi[s->format].restart_barrier);
 }
 
 static void kill_all_decoders(void)
@@ -247,21 +242,6 @@ static int get_empty_slot(void)
        return -E_NO_MORE_SLOTS;
 }
 
-static int decoder_running(int format)
-{
-       int i, ret = 0;
-       struct slot_info *s;
-
-       FOR_EACH_SLOT(i) {
-               s = &slot[i];
-               if (s->format == format && s->receiver_node)
-                       ret |= 1;
-               if (s->format == format && s->wng)
-                       ret |= 2;
-       }
-       return ret;
-}
-
 static void close_stat_pipe(void)
 {
        int i;
@@ -406,10 +386,18 @@ static void open_writers(int slot_num)
 static void rn_event_handler(struct task *t)
 {
        struct receiver_node *rn = t->private_data;
+       const struct timeval restart_delay = {0, 10 * 1000};
+       int i;
 
        PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_task(t);
        rn->eof = 1;
+       /* set restart barrier */
+       FOR_EACH_SLOT(i) {
+               if (slot[i].receiver_node != rn)
+                       continue;
+               tv_add(now, &restart_delay, &afi[slot[i].format].restart_barrier);
+       }
 }
 
 static void open_receiver(int format)
@@ -446,6 +434,19 @@ static void open_receiver(int format)
        register_task(&rn->task);
 }
 
+static int receiver_running(int format)
+{
+       int i;
+
+       FOR_EACH_SLOT(i) {
+               struct slot_info *s = &slot[i];
+               if (s->format == format && s->receiver_node
+                               && !s->receiver_node->eof)
+                       return 1;
+       }
+       return 0;
+}
+
 static int open_current_receiver(struct sched *s)
 {
        int i;
@@ -456,7 +457,7 @@ static int open_current_receiver(struct sched *s)
        i = get_audio_format_num(stat_task->af_status);
        if (i < 0)
                return 0;
-       if (decoder_running(i))
+       if (receiver_running(i))
                return 0;
        if (tv_diff(now, &afi[i].restart_barrier, &diff) < 0) {
                s->timeout = diff;