]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - vss.c
kill the read_chunk handler of struct audio_format handler
[paraslash.git] / vss.c
diff --git a/vss.c b/vss.c
index ea647254e497ac9ffa7eb3963a6a11759719d67b..f1dbfb97fa45db3c79628887f0783301f218b4e9 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -31,6 +31,7 @@
 #include "send.h"
 #include "error.h"
 #include "string.h"
+#include "fd.h"
 
 extern const char *status_item_list[];
 
@@ -42,7 +43,8 @@ static struct timeval autoplay_barrier;
 extern struct misc_meta_data *mmd;
 extern struct audio_file_selector selectors[];
 extern struct sender senders[];
-static size_t *chunk_table;
+static char *inbuf;
+static size_t *chunk_table, inbuf_size;
 
 static FILE *audio_file = NULL;
 
@@ -499,6 +501,35 @@ again:
        return ret;
 }
 
+static char *vss_read_chunk(long unsigned current_chunk, ssize_t *len)
+{
+       int ret;
+       size_t pos;
+
+       *len = 0;
+       if (current_chunk >= mmd->chunks_total)
+               return NULL;
+       *len = chunk_table[current_chunk + 1] - chunk_table[current_chunk];
+       if (!*len) /* nothing to send for this run */
+               return inbuf;
+       pos = chunk_table[current_chunk];
+       if (inbuf_size < *len) {
+               PARA_INFO_LOG("increasing inbuf for chunk #%lu/%lu to %zd bytes\n",
+                       current_chunk, mmd->chunks_total, *len);
+               inbuf = para_realloc(inbuf, *len);
+               inbuf_size = *len;
+       }
+//     PARA_DEBUG_LOG("reading chunk #%lu@%zd (%zd bytes)\n", current_chunk,
+//             pos, *len);
+       ret = fseek(audio_file, pos, SEEK_SET);
+       if (ret < 0)
+               return NULL;
+       ret = para_fread(inbuf, *len, 1, audio_file);
+       if (ret != *len)
+               return NULL;
+       return inbuf;
+}
+
 /**
  * main sending function
  *
@@ -511,7 +542,6 @@ again:
  * Return value: Positive return value on success, zero on eof and negative
  * on errors.
  */
-
 void vss_send_chunk(void)
 {
        int i;
@@ -532,7 +562,7 @@ void vss_send_chunk(void)
        if (chk_barrier("data send", &now, &data_send_barrier,
                        &due, 1) < 0)
                return;
-       buf = af->read_chunk(mmd->current_chunk, &ret);
+       buf = vss_read_chunk(mmd->current_chunk, &ret);
        mmd->new_vss_status_flags &= ~VSS_REPOS;
        if (!buf) {
                if (ret < 0)