-}
-
-static void handle_signal(int sig)
-{
- switch (sig) {
- case SIGINT:
- case SIGTERM:
- case SIGHUP:
- PARA_EMERG_LOG("terminating on signal %d\n", sig);
- clean_exit(EXIT_FAILURE, "caught deadly signal");
- return;
- }
-}
-
-static void try_to_close_slot(int slot_num)
-{
- struct slot_info *s = &slot[slot_num];
-
- if (s->format < 0)
- return;
- if (s->receiver_node && !s->receiver_node->eof)
- return;
- if (s->fc && !s->fc->eof)
- return;
- if (s->wng && !s->wng->eof)
- return;
- PARA_INFO_LOG("closing slot %d \n", slot_num);
- wng_close(s->wng);
- close_filters(s->fc);
- free(s->fc);
- close_receiver(slot_num);
- clear_slot(slot_num);
-}
-
-/*
- * Check if any receivers/filters/writers need to be started and do so if
- * neccessary. Since the pre_select function didn't have a chance yet to put
- * file descriptors into the fd sets given by s, make the upcoming select()
- * return immediately to avoid a long timeout in case we started something.
- */
-static void audiod_pre_select(struct sched *s, __a_unused struct task *t)
-{
- int i;
- struct timeval min_delay = {0, 1};
-
- t->ret = 1;
- if (audiod_status != AUDIOD_ON || !stat_task->playing)
- return kill_all_decoders();
- if (open_current_receiver(s))
- s->timeout = min_delay;
- FOR_EACH_SLOT(i) {
- struct slot_info *sl = &slot[i];
- struct audio_format_info *a;
- struct timeval diff;
-
- if (sl->format < 0)
- continue;
- a = &afi[sl->format];
- if (!sl->receiver_node)
- continue;
- if (!a->num_filters) {
- if (sl->receiver_node->loaded && !sl->wng) {
- open_writers(i);
- s->timeout = min_delay;
- }
- continue;
- }
- if (sl->receiver_node->loaded && !sl->fc) {
- open_filters(i);
- s->timeout = min_delay;
- continue;
- }
- if (!sl->fc || !*sl->fc->out_loaded || sl->wng)
- continue;
- if (tv_diff(now, &initial_delay_barrier, &diff) > 0) {
- 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;
- }
- }
-}
-
-static void audiod_post_select(__a_unused struct sched *s,
- __a_unused struct task *t)
-{
- int i;
-
- t->ret = 1;
- FOR_EACH_SLOT(i)
- try_to_close_slot(i);
-}
-
-static void init_audiod_task(struct task *t)
-{
- t->pre_select = audiod_pre_select;
- t->post_select = audiod_post_select;
- t->event_handler = NULL;
- t->private_data = t;
- sprintf(t->status, "audiod task");