- size_t frames = nbytes / pad->bytes_per_frame;
- unsigned char *d = (unsigned char*)data;
- snd_pcm_sframes_t r, result = 0;
-
- while (frames > 0) {
- /* write interleaved frames */
- r = snd_pcm_writei(pad->handle, d, frames);
- if (r < 0)
- PARA_ERROR_LOG("write error: %s\n", snd_strerror(r));
- if (r == -EAGAIN || (r >= 0 && r < frames))
- snd_pcm_wait(pad->handle, 1);
- else if (r == -EPIPE)
- snd_pcm_prepare(pad->handle);
- else if (r < 0)
- return -E_ALSA_WRITE;
- if (r > 0) {
- result += r;
- frames -= r;
- d += r * pad->bytes_per_frame;
- }
+ struct writer_node_group *wng = wn->wng;
+ size_t frames = *wng->loaded / pad->bytes_per_frame;
+ snd_pcm_sframes_t ret;
+ unsigned char *data = (unsigned char*)wng->buf;
+ struct timeval tv;
+
+ t->ret = 0;
+// PARA_INFO_LOG("%zd frames\n", frames);
+ if (!frames) {
+ if (*wng->input_eof)
+ t->ret = *wng->loaded;
+ return;
+ }
+ if (tv_diff(&s->now, &pad->next_chunk, NULL) < 0)
+ return;
+ ret = snd_pcm_writei(pad->handle, data, frames);
+ if (ret == -EPIPE) {
+ PARA_WARNING_LOG("%s", "EPIPE\n");
+ snd_pcm_prepare(pad->handle);
+ return;
+ }
+ if (ret < 0) {
+ PARA_WARNING_LOG("%s", "ALSA ERROR\n");
+ t->ret = -E_ALSA_WRITE;
+ return;