audiod: always dump the audio status
[paraslash.git] / alsa_writer.c
index 7dab4585d46d221d46692409173d8046e9ab392d..7d7d36bfbdab04bf91ab0bc932b69c9b129d2a28 100644 (file)
@@ -155,7 +155,7 @@ static int alsa_write_pre_select(struct sched *s, struct writer_node *wn)
 
        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 {
@@ -166,28 +166,29 @@ static int alsa_write_pre_select(struct sched *s, struct writer_node *wn)
 //     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");
@@ -195,8 +196,9 @@ static int alsa_write_post_select(struct sched *s, struct writer_node *wn)
        }
        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)