]> 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 4a395593f3aa1a6a5038b3d3c23330c6b0ea5610..f1dbfb97fa45db3c79628887f0783301f218b4e9 100644 (file)
--- a/vss.c
+++ b/vss.c
 #include "server.h"
 #include <sys/time.h> /* gettimeofday */
 #include "server.cmdline.h"
-#include "db.h"
+#include "afs.h"
 #include "afh.h"
 #include "vss.h"
 #include "send.h"
 #include "error.h"
 #include "string.h"
+#include "fd.h"
 
 extern const char *status_item_list[];
 
@@ -42,6 +43,8 @@ static struct timeval autoplay_barrier;
 extern struct misc_meta_data *mmd;
 extern struct audio_file_selector selectors[];
 extern struct sender senders[];
+static char *inbuf;
+static size_t *chunk_table, inbuf_size;
 
 static FILE *audio_file = NULL;
 
@@ -86,6 +89,8 @@ static struct audio_format_handler afl[] = {
 /** iterate over each supported audio format */
 #define FOR_EACH_AUDIO_FORMAT(i) for (i = 0; afl[i].name; i++)
 
+
+
 /**
  * check if vss status flag \a P (playing) is set
  *
@@ -182,7 +187,7 @@ void vss_init(void)
 static int get_file_info(int i)
 {
        return  afl[i].get_file_info(audio_file, mmd->audio_file_info,
-               &mmd->chunks_total, &mmd->seconds_total);
+               &mmd->chunks_total, &mmd->seconds_total, &chunk_table);
 }
 
 /**
@@ -220,7 +225,7 @@ static int get_audio_format(int omit)
        int i;
 
        FOR_EACH_AUDIO_FORMAT(i) {
-               if (i == omit || !afl[i].get_file_info)
+               if (i == omit)
                        continue;
                rewind(audio_file);
                if (get_file_info(i) > 0)
@@ -482,8 +487,6 @@ again:
                }
                mmd->chunks_sent = 0;
        }
-       if (af && vss_repos() && mmd->current_chunk != mmd->repos_request)
-               af->reposition_stream(mmd->repos_request);
        if (vss_repos()) {
                mmd->new_vss_status_flags &= ~(VSS_REPOS);
                mmd->current_chunk = mmd->repos_request;
@@ -498,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
  *
@@ -510,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;
@@ -531,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)