simplify osx_write_post_select()
authorAndre Noll <maan@congo.fml.local>
Sun, 20 Aug 2006 13:24:33 +0000 (15:24 +0200)
committerAndre Noll <maan@congo.fml.local>
Sun, 20 Aug 2006 13:24:33 +0000 (15:24 +0200)
we either use the full buffer or leave it untouched. So wn->written is always zero
or wn->loaded.

osx_writer.c

index 4b505f0..9ea7ad4 100644 (file)
@@ -284,20 +284,30 @@ static void osx_writer_close(struct writer_node *wn)
        free(powd);
 }
 
+static int need_new_buffer(struct writer_node *wn)
+{
+       struct writer_node_group *wng = wn->wng;
+       struct private_osx_writer_data *powd = wn->private_data;
+
+       if (*wng->loaded < sizeof(short))
+               return 0;
+       if (powd->to->remaining) /* Non empty buffer, must still be playing */
+               return 0;
+       return 1;
+}
+
 static int osx_write_post_select(__a_unused struct sched *s,
                struct writer_node *wn)
 {
        struct private_osx_writer_data *powd = wn->private_data;
        struct writer_node_group *wng = wn->wng;
-       short *data = (short*)wng->buf + wn->written;
+       short *data = (short*)wng->buf;
 
-       if (*wng->loaded <= wn->written)
-               return 1;
-       if (powd->to->remaining) /* Non empty buffer, must still be playing */
+       if (!need_new_buffer(wn))
                return 1;
-       fill_buffer(powd->to, data, (*wng->loaded - wn->written) / sizeof(short));
+       fill_buffer(powd->to, data, *wng->loaded / sizeof(short));
        powd->to = powd->to->next;
-       wn->written += (*wng->loaded - wn->written);
+       wn->written = *wng->loaded;
        if (!powd->play) {
                if (AudioOutputUnitStart(powd->output))
                        return -1;