-}
-
-static void handle_signal(int sig)
-{
- switch (sig) {
- case SIGCHLD:
- return check_sigchld();
- 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 check_timeouts(void)
-{
- struct timeval now;
- int slot_num, timeout = conf.stream_timeout_arg;
-
- gettimeofday(&now, NULL);
- 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)
-{
- struct slot_info *s = &slot[slot_num];
-
- if (s->format < 0)
- return;
- if (!s->fc)
- return;
- if (s->wng)
- return;
- PARA_INFO_LOG("closing all filters in slot %d (filter_chain %p)\n",
- slot_num, s->fc);
- close_filters(s->fc);
- free(s->fc);
- close_receiver(slot_num);
- clear_slot(slot_num);
-}
-
-static void audiod_pre_select(__a_unused struct sched *s, __a_unused struct task *t)
-{
- int i;
-
- if (audiod_status != AUDIOD_ON)
- kill_all_decoders();
- else if (playing)
- start_current_receiver();
- check_timeouts();
- FOR_EACH_SLOT(i) {
- struct receiver_node *rn;
-
- close_decoder_if_idle(i);
- if (slot[i].format < 0)
- continue;
- rn = slot[i].receiver_node;
- if (rn && rn->loaded && !slot[i].wng) {
- PARA_INFO_LOG("no writer in slot %d\n", i);
- start_stream_writer(i, &s->now);
- }
- }
-}
-
-#if 0
-static int write_audio_data(int slot_num)
-{
- struct slot_info *s = &slot[slot_num];
- struct audio_format_info *a = &afi[s->format];
- struct receiver_node *rn = s->receiver_node;
- int ret;
- char **buf;
- size_t *len;
-
- if (a->num_filters) {
- buf = &s->fc->outbuf;
- len = s->fc->out_loaded;
- } else {
- buf = &rn->buf;
- len = &rn->loaded;
- }
- PARA_DEBUG_LOG("writing %p (%zd bytes)\n", *buf, *len);
- ret = write(s->write_fd, *buf, *len);
- PARA_DEBUG_LOG("wrote %d/%zd\n", ret, *len);
- if (ret < 0) {
- PARA_WARNING_LOG("write error in slot %d (fd %d): %s\n",
- slot_num, s->write_fd, strerror(errno));
- *len = 0;
- close_writer(slot_num);
-// s->fc->error = E_WRITE_AUDIO_DATA;
- } else if (ret != *len) {
- PARA_DEBUG_LOG("partial %s write (%i/%zd) for slot %d\n",
- audio_formats[s->format], ret, *len, slot_num);
- *len -= ret;
- memmove(*buf, *buf + ret, *len);
- } else
- *len = 0;
- if (ret > 0)
- gettimeofday(&s->wtime, NULL);
- return ret;
-}
-#endif
-
-
-static void audiod_post_select(struct sched *s, __a_unused struct task *t)
-{
- int i;
-
- FOR_EACH_SLOT(i) {
- struct receiver_node *rn = slot[i].receiver_node;
-
- if (rn && rn->loaded)
- slot[i].rtime = s->now;
-// if (slot[i].write_fd <= 0 || !slot[i].wcheck
-// || !FD_ISSET(slot[i].write_fd, &s->wfds))
-// continue;
-// ret = write_audio_data(i);
- }
-}
-
-static void init_audiod_task(struct audiod_task *at)
-{
- at->task.pre_select = audiod_pre_select;
- at->task.post_select = audiod_post_select;
- at->task.private_data = at;
- at->task.flags = 0;
- sprintf(at->task.status, "audiod task");