audio: fix handling of sample_rate and channels count.
[paraslash.git] / audiod.c
index 12e8f7bb4345df416f2cdc0bc4c615fa7609129f..56014cad0e832931613abc6ac879dcde5c67c9b7 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -632,8 +632,6 @@ static void open_filters(int slot_num)
                s->fc->out_loaded = &fn->loaded;
        }
        register_task(&s->fc->task);
-//     PARA_DEBUG_LOG("output loaded for filter chain %p: %p\n", s->fc,
-//             s->fc->out_loaded);
 }
 
 static struct filter_node *find_filter_node(int slot_num, int format, int filternum)
@@ -682,7 +680,10 @@ static void open_writers(int slot_num)
                s->wng->buf = s->fc->outbuf;
                s->wng->loaded = s->fc->out_loaded;
                s->wng->input_eof = &s->fc->eof;
+               s->wng->channels = &s->fc->channels;
+               s->wng->samplerate = &s->fc->samplerate;
                s->fc->output_eof = &s->wng->eof;
+               PARA_INFO_LOG("samplerate: %d\n", *s->wng->samplerate);
        } else {
                s->wng->buf = s->receiver_node->buf;
                s->wng->loaded = &s->receiver_node->loaded;
@@ -694,7 +695,7 @@ static void open_writers(int slot_num)
                s->wng->writer_nodes[i].writer = a->writers[i];
                sprintf(s->wng->writer_nodes[i].task.status, "writer_node");
        }
-       ret = wng_open(s->wng);
+       ret = wng_open(s->wng); /* FIXME */
        s->wstime = *now;
        current_decoder = slot_num;
        activate_inactive_grab_clients(slot_num, s->format, &s->fc->filters);
@@ -702,7 +703,7 @@ static void open_writers(int slot_num)
 
 static void rn_event_handler(struct task *t)
 {
-       struct receiver_node *rn = t->private_data;
+//     struct receiver_node *rn = t->private_data;
        PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret));
        unregister_task(t);
 }
@@ -894,22 +895,33 @@ static void audiod_pre_select(struct sched *s, __a_unused struct task *t)
 {
        int i;
 
+       t->ret = 1;
        now = &s->now;
        if (audiod_status != AUDIOD_ON)
                kill_all_decoders();
        else if (playing)
                open_current_receiver();
        FOR_EACH_SLOT(i) {
-               struct receiver_node *rn;
+               struct slot_info *s = &slot[i];
+               struct audio_format_info *a;
 
                try_to_close_slot(i);
-               if (slot[i].format < 0)
+               if (s->format < 0)
+                       continue;
+               a = &afi[s->format];
+               if (!s->receiver_node)
                        continue;
-               rn = slot[i].receiver_node;
-               if (rn && rn->loaded && !slot[i].wng) {
+               if (!a->num_filters) {
+                       if (s->receiver_node->loaded && !s->wng)
+                               open_writers(i);
+                       continue;
+               }
+               if (s->receiver_node->loaded && !s->fc) {
                        open_filters(i);
-                       open_writers(i);
+                       continue;
                }
+               if (s->fc && *s->fc->out_loaded && !s->wng)
+                       open_writers(i);
        }
 }
 
@@ -917,6 +929,7 @@ static void audiod_post_select(struct sched *s, __a_unused struct task *t)
 {
        /* only save away the current time for other users */
        now = &s->now;
+       t->ret = 1;
 }
 
 static void init_audiod_task(struct task *t)
@@ -1485,6 +1498,7 @@ void signal_setup_default(struct signal_task *st)
 static void command_pre_select(struct sched *s, struct task *t)
 {
        struct command_task *ct = t->private_data;
+       t->ret = 1;
        para_fd_set(ct->fd, &s->rfds, &s->max_fileno);
 
 }
@@ -1494,9 +1508,9 @@ static void command_post_select(struct sched *s, struct task *t)
        int ret;
        struct command_task *ct = t->private_data;
 
+       t->ret = 1; /* always successful */
        if (audiod_status != AUDIOD_OFF)
                audiod_status_dump();
-       t->ret = 1; /* always successful */
        if (!FD_ISSET(ct->fd, &s->rfds))
                return;
        ret = handle_connect(ct->fd);