From: Andre Noll Date: Fri, 5 Nov 2010 07:45:20 +0000 (+0100) Subject: writers: Unify ->pre_select(). X-Git-Tag: v0.4.5~4^2~5 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=2ef39ae4d1e6b0d95991d2b980621fb152211444;ds=sidebyside writers: Unify ->pre_select(). Always treat the easy cases "nothing to do", "error", and "not yet initialized" first. For the alsa writer, this change fixes two minor bugs: First, if data is available but alsa has not yet been initialized, we return from ->pre_select() without setting a delay. This is wrong, we should init the alsa handle ASAP in this case. Second, on errors we wait 20ms which is both ugly and unnecessary. Requesting a minimal delay is the right thing to do here as well. --- diff --git a/alsa_write.c b/alsa_write.c index b685e4f7..3428def8 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -154,15 +154,12 @@ static void alsa_write_pre_select(struct sched *s, struct task *t) struct private_alsa_write_data *pad = wn->private_data; struct timeval tv; snd_pcm_sframes_t avail, underrun; - int ret; + int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); - if (!pad->handle) - return; - ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); - if (ret < 0) - sched_request_timeout_ms(20, s); - if (ret <= 0) + if (ret == 0) return; + if (ret < 0 || !pad->handle) + return sched_min_delay(s); /* * Data is available to be written to the alsa handle. Compute number * of milliseconds until next buffer underrun would occur. diff --git a/file_write.c b/file_write.c index 7bc1e437..e6a3229e 100644 --- a/file_write.c +++ b/file_write.c @@ -88,14 +88,13 @@ static void file_write_pre_select(struct sched *s, struct task *t) { struct writer_node *wn = container_of(t, struct writer_node, task); struct private_file_write_data *pfwd = wn->private_data; - int ret; + int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); - t->error = 0; - ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); - if (ret > 0 && pfwd->fd >= 0) - para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno); - else if (ret != 0) /* error or bos and fd not yet open */ - sched_min_delay(s); + if (ret == 0) + return; + if (ret < 0 || pfwd->fd < 0) + return sched_min_delay(s); + para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno); } static void file_write_close(struct writer_node *wn) diff --git a/oss_write.c b/oss_write.c index 2d820d33..687275f3 100644 --- a/oss_write.c +++ b/oss_write.c @@ -52,11 +52,11 @@ static void oss_pre_select(struct sched *s, struct task *t) struct private_oss_write_data *powd = wn->private_data; int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); - t->error = 0; - if (ret < 0) - sched_min_delay(s); - else if (ret > 0) - para_fd_set(powd->fd, &s->wfds, &s->max_fileno); + if (ret == 0) + return; + if (ret < 0 || powd->fd < 0) + return sched_min_delay(s); + para_fd_set(powd->fd, &s->wfds, &s->max_fileno); } static void oss_close(struct writer_node *wn) diff --git a/osx_write.c b/osx_write.c index c2b7b2f4..551748a4 100644 --- a/osx_write.c +++ b/osx_write.c @@ -347,13 +347,15 @@ static void osx_write_pre_select(struct sched *s, struct task *t) struct private_osx_write_data *powd = wn->private_data; struct timeval tmp = {.tv_sec = 1, .tv_usec = 0}, delay = tmp; unsigned long divisor; - size_t numbytes = powd->to->remaining * sizeof(short); + size_t numbytes; int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); - if (ret < 0) - sched_min_delay(s); - if (ret <= 0 || numbytes < wn->min_iqs) + if (ret == 0) return; + if (ret < 0 || !powd->audio_unit) + return sched_min_delay(s); + numbytes = powd->to->remaining * sizeof(short); + assert(numbytes > 0); divisor = powd->sample_rate * wn->min_iqs / numbytes; if (divisor) tv_divide(divisor, &tmp, &delay);