if (*wng->loaded < pad->bytes_per_frame)
return 1;
- if (tv_diff(&s->now, &pad->next_chunk, &diff) < 0) {
+ if (tv_diff(now, &pad->next_chunk, &diff) < 0) {
if (tv_diff(&s->timeout, &diff, NULL) > 0)
s->timeout = diff;
} else {
// PARA_INFO_LOG("timeout: %lu\n", tv2ms(&s->timeout));
}
-static int alsa_write_post_select(struct sched *s, struct writer_node *wn)
+static int alsa_write_post_select(__a_unused struct sched *s,
+ struct writer_node *wn)
{
struct private_alsa_data *pad = wn->private_data;
struct writer_node_group *wng = wn->wng;
- size_t frames = *wng->loaded / pad->bytes_per_frame;
+ size_t frames = (*wng->loaded - wn->written) / pad->bytes_per_frame;
snd_pcm_sframes_t ret;
- unsigned char *data = (unsigned char*)wng->buf;
+ unsigned char *data = (unsigned char*)wng->buf + wn->written;
struct timeval tv;
// PARA_INFO_LOG("%zd frames\n", frames);
if (!frames) {
if (*wng->input_eof)
- ret = *wng->loaded;
- return 0;
+ wn->written = *wng->loaded;
+ return 1;
}
- if (tv_diff(&s->now, &pad->next_chunk, NULL) < 0)
- return 0;
+ if (tv_diff(now, &pad->next_chunk, NULL) < 0)
+ return 1;
ret = snd_pcm_writei(pad->handle, data, frames);
if (ret == -EPIPE) {
PARA_WARNING_LOG("%s", "EPIPE\n");
snd_pcm_prepare(pad->handle);
- return 0;
+ return 1;
}
if (ret < 0) {
PARA_WARNING_LOG("%s", "ALSA ERROR\n");
}
ms2tv(pad->buffer_time / 4000, &tv);
// ms2tv(1, &tv);
- tv_add(&s->now, &tv, &pad->next_chunk);
- return ret * pad->bytes_per_frame;
+ tv_add(now, &tv, &pad->next_chunk);
+ wn->written += ret * pad->bytes_per_frame;
+ return 1;
}
static void alsa_close(struct writer_node *wn)