audiod: remove bogus check_timeouts()
[paraslash.git] / audiod.c
index d78841336893c170f9da7472c717b1e70c9c45bc..0d8745d725bce902419afdd17c50a58cf51dd7fc 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -83,10 +83,6 @@ struct audio_format_info {
 struct slot_info {
        /** number of the audio format in this slot */
        int format;
-       /** time of the last successful read from the receiver */
-       struct timeval rtime;
-       /** time the last write to the write fd happend */
-       struct timeval wtime;
        /** writer start time */
        struct timeval wstime;
        /** the receiver info associated with this slot */
@@ -654,21 +650,11 @@ static struct filter_node *find_filter_node(int slot_num, int format, int filter
 
 static void wng_event_handler(struct task *t)
 {
-       struct writer_node_group *g = t->private_data;
-       int i;
-
        PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_task(t);
-       FOR_EACH_SLOT(i) {
-               if (slot[i].wng != g)
-                       continue;
-               wng_close(g);
-               wng_destroy(g);
-               slot[i].wng = NULL;
-       }
 }
 
-static void open_writer(int slot_num)
+static void open_writers(int slot_num)
 {
        int ret, i;
        struct slot_info *s = &slot[slot_num];
@@ -693,7 +679,7 @@ static void open_writer(int slot_num)
        for (i = 0; i < a->num_writers; i++) {
                s->wng->writer_nodes[i].conf = a->writer_conf[i];
                s->wng->writer_nodes[i].writer = a->writers[i];
-               sprintf(s->wng->writer_nodes[i].task.status, "writer_ node");
+               sprintf(s->wng->writer_nodes[i].task.status, "writer_node");
        }
        ret = wng_open(s->wng);
        s->wstime = *now;
@@ -720,8 +706,6 @@ static void open_receiver(int format)
                clean_exit(EXIT_FAILURE, PARA_STRERROR(-slot_num));
        s = &slot[slot_num];
        s->format = format;
-       s->rtime = *now;
-       s->wtime = s->rtime;
        s->receiver_node = para_calloc(sizeof(struct receiver_node));
        rn = s->receiver_node;
        rn->receiver = a->receiver;
@@ -737,7 +721,6 @@ static void open_receiver(int format)
        PARA_NOTICE_LOG("started %s: %s receiver in slot %d\n",
                audio_formats[s->format], a->receiver->name, slot_num);
        rn->task.private_data = s->receiver_node;
-       PARA_NOTICE_LOG("rn = %p\n", rn->task.private_data);
        rn->task.pre_select = a->receiver->pre_select;
        rn->task.post_select = a->receiver->post_select;
        rn->task.event_handler = rn_event_handler;
@@ -873,37 +856,21 @@ static void handle_signal(int sig)
        }
 }
 
-static void check_timeouts(void)
-{
-
-       int slot_num, timeout = conf.stream_timeout_arg;
-
-       FOR_EACH_SLOT(slot_num) {
-               struct slot_info *s = &slot[slot_num];
-               if (s->format < 0)
-                       continue;
-               /* check read time */
-               if (s->receiver_node &&
-                       now->tv_sec > s->rtime.tv_sec + timeout) {
-                       PARA_INFO_LOG("%s stream (slot %d) not ready\n",
-                               audio_formats[s->format], slot_num);
-                       s->receiver_node->eof = 1;
-               }
-       }
-}
-
-static void close_decoder_if_idle(int slot_num)
+static void try_to_close_slot(int slot_num)
 {
        struct slot_info *s = &slot[slot_num];
 
        if (s->format < 0)
                return;
-       if (!s->fc)
+       if (s->receiver_node && !s->receiver_node->eof)
+               return;
+       if (s->fc && !s->fc->eof)
                return;
-       if (s->wng)
+       if (s->wng && !s->wng->eof)
                return;
-       PARA_INFO_LOG("closing all filters in slot %d (filter_chain %p)\n",
-               slot_num, s->fc);
+       PARA_INFO_LOG("closing slot %d \n", slot_num);
+       wng_close(s->wng);
+       wng_destroy(s->wng);
        close_filters(s->fc);
        free(s->fc);
        close_receiver(slot_num);
@@ -919,32 +886,24 @@ static void audiod_pre_select(struct sched *s, __a_unused struct task *t)
                kill_all_decoders();
        else if (playing)
                open_current_receiver();
-       check_timeouts();
        FOR_EACH_SLOT(i) {
                struct receiver_node *rn;
 
-               close_decoder_if_idle(i);
+               try_to_close_slot(i);
                if (slot[i].format < 0)
                        continue;
                rn = slot[i].receiver_node;
                if (rn && rn->loaded && !slot[i].wng) {
                        open_filters(i);
-                       open_writer(i);
+                       open_writers(i);
                }
        }
 }
 
 static void audiod_post_select(struct sched *s, __a_unused struct task *t)
 {
-       int i;
-
+       /* only save away the current time for other users */
        now = &s->now;
-       FOR_EACH_SLOT(i) {
-               struct receiver_node *rn = slot[i].receiver_node;
-
-               if (rn && rn->loaded)
-                       slot[i].rtime = *now;
-       }
 }
 
 static void init_audiod_task(struct audiod_task *at)
@@ -1016,7 +975,7 @@ static int init_writers(void)
                        ret = writer_num;
                        goto out;
                }
-               a->writers[nw] = &writers[ret];
+               a->writers[nw] = &writers[writer_num];
                a->writer_conf[nw] = wconf;
                PARA_INFO_LOG("%s writer #%d: %s\n", audio_formats[ret],
                        nw, writer_names[writer_num]);