- 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)
+ struct writer_node_group *wng = wn->wng;
+ size_t frames = *wng->loaded / pad->bytes_per_frame;
+ snd_pcm_sframes_t ret, result = 0;
+ unsigned char *data = (unsigned char*)wng->buf;
+
+ t->ret = 0;
+ if (!frames) {
+ if (*wng->input_eof)
+ t->ret = *wng->loaded;
+ return;
+ }
+ if (tv_diff(&s->now, &pad->next_chunk, NULL) < 0)
+ return;
+// PARA_INFO_LOG("%zd frames\n", frames);
+// while (frames > 0) {
+ ret = snd_pcm_writei(pad->handle, data, frames);
+ if (ret == -EAGAIN || (ret >= 0 && ret < frames)) {
+ struct timeval tv = {0, 1000 * 10};
+ PARA_INFO_LOG("EAGAIN. frames: %d, ret: %lu\n", frames, ret);
+ tv_add(&s->now, &tv, &pad->next_chunk);
+// snd_pcm_wait(pad->handle, 1);
+ } else if (ret == -EPIPE) {
+ PARA_INFO_LOG("%s", "EPIPE\n");