X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=3b2a4aa0789fb31406ac470ed799415b607109d4;hp=709cdfe1c5f5eff0ae72ccb4b04a76054603c252;hb=c266213e180046c3d49387f8cf052253fcde8ba3;hpb=20786ba9597d62efbeef87c44870dc19a13e3bb4 diff --git a/audiod.c b/audiod.c index 709cdfe1..3b2a4aa0 100644 --- a/audiod.c +++ b/audiod.c @@ -654,7 +654,6 @@ static void open_filters(int slot_num) s->fc->task.pre_select = filter_pre_select; s->fc->task.event_handler = filter_event_handler; s->fc->task.private_data = s->fc; - s->fc->task.flags = 0; s->fc->eof = 0; s->receiver_node->output_eof = &s->fc->eof; @@ -738,7 +737,6 @@ static void open_writers(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"); } ret = wng_open(s->wng); if (ret < 0) { @@ -789,37 +787,28 @@ static void open_receiver(int format) rn->task.pre_select = a->receiver->pre_select; rn->task.post_select = a->receiver->post_select; rn->task.event_handler = rn_event_handler; - rn->task.flags = 0; sprintf(rn->task.status, "%s receiver node", rn->receiver->name); register_task(&rn->task); } -static int is_frozen(int format) -{ - struct audio_format_info *a = &afi[format]; - - return (tv_diff(now, &a->restart_barrier, NULL) > 0)? 0 : 1; -} - -static void open_current_receiver(struct sched *s) +static int open_current_receiver(struct sched *s) { int i; + struct timeval diff; if (!af_status) - return; + return 0; i = get_audio_format_num(af_status); if (i < 0) - return; - if (decoder_running(i) || is_frozen(i)) - return; + return 0; + if (decoder_running(i)) + return 0; + if (tv_diff(now, &afi[i].restart_barrier, &diff) < 0) { + s->timeout = diff; + return 0; + } open_receiver(i); - /* - * the receiver didn't get a chance to put his fd to the fd set. - * Make the upcoming select() return immediately to avoid a long - * timeout. - */ - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; + return 1; } static void compute_time_diff(const struct timeval *status_time) @@ -948,36 +937,48 @@ static void try_to_close_slot(int 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; now = &s->now; if (audiod_status != AUDIOD_ON || !playing) - kill_all_decoders(); - else if (playing) - open_current_receiver(s); + return kill_all_decoders(); + if (open_current_receiver(s)) + s->timeout = min_delay; FOR_EACH_SLOT(i) { - struct slot_info *s = &slot[i]; + struct slot_info *sl = &slot[i]; struct audio_format_info *a; - if (s->format < 0) + if (sl->format < 0) continue; - a = &afi[s->format]; - if (!s->receiver_node) + a = &afi[sl->format]; + if (!sl->receiver_node) continue; if (!a->num_filters) { - if (s->receiver_node->loaded && !s->wng) + if (sl->receiver_node->loaded && !sl->wng) { open_writers(i); + s->timeout = min_delay; + } continue; } - if (s->receiver_node->loaded && !s->fc) { + if (sl->receiver_node->loaded && !sl->fc) { open_filters(i); + s->timeout = min_delay; continue; } - if (s->fc && *s->fc->out_loaded && !s->wng) + if (sl->fc && *sl->fc->out_loaded && !sl->wng) { open_writers(i); + s->timeout = min_delay; + } } } @@ -998,7 +999,6 @@ static void init_audiod_task(struct task *t) t->post_select = audiod_post_select; t->event_handler = NULL; t->private_data = t; - t->flags = 0; sprintf(t->status, "audiod task"); } @@ -1582,7 +1582,6 @@ void signal_setup_default(struct signal_task *st) st->task.pre_select = signal_pre_select; st->task.post_select = signal_post_select; st->task.private_data = st; - st->task.flags = 0; sprintf(st->task.status, "signal task"); } @@ -1615,7 +1614,6 @@ static void init_command_task(struct command_task *ct) ct->task.post_select = command_post_select; ct->task.event_handler = NULL; ct->task.private_data = ct; - ct->task.flags = 0; ct->fd = audiod_get_socket(); /* doesn't return on errors */ sprintf(ct->task.status, "command task"); }