]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - vss.c
vss.c: Introduce get_audio_file_info().
[paraslash.git] / vss.c
diff --git a/vss.c b/vss.c
index 7892fb14656317453304b37d4c09dcb8bcc40006..e0c0b584dbe4819f392d02c1d33076e4751af492 100644 (file)
--- a/vss.c
+++ b/vss.c
  * senders.
  */
 
+#include "para.h"
+#include "afh.h"
 #include "server.h"
 #include <sys/mman.h> /* mmap */
 #include <sys/time.h> /* gettimeofday */
 #include "server.cmdline.h"
-#include "afs.h"
+#include "afs_common.h"
 #include "vss.h"
 #include "send.h"
 #include "error.h"
@@ -224,6 +226,26 @@ static int get_audio_format(int omit)
        return -E_AUDIO_FORMAT;
 }
 
+int get_audio_file_info(const char *path, char *data, size_t size,
+               struct audio_format_info *afhi)
+{
+       int ret, i, format = guess_audio_format(path);
+       if (format >= 0) {
+               ret = afl[format].get_file_info(data, size, afhi);
+               if (ret >= 0)
+                       return ret;
+       }
+       FOR_EACH_AUDIO_FORMAT(i) {
+               if (i == format) /* we already tried this one to no avail */
+                       continue;
+               ret = afl[i].get_file_info(data, size, afhi);
+               if (ret >= 0)
+                       return ret;
+       }
+       return -E_AUDIO_FORMAT;
+
+}
+
 /*
  * upddate shared mem
  */
@@ -400,7 +422,7 @@ static void vss_eof(void)
  * treamtment.
  *
  */
-char *vss_get_header(unsigned *header_len)
+char *vss_get_header(size_t *header_len)
 {
        if (mmd->audio_format < 0 || !map || !mmd->afi.header_len)
                return NULL;
@@ -495,6 +517,32 @@ again:
        return ret;
 }
 
+static void get_chunk(long unsigned chunk_num, char **buf, size_t *len)
+{
+       size_t pos = mmd->afi.chunk_table[chunk_num];
+       *buf = map + pos;
+       *len = mmd->afi.chunk_table[chunk_num + 1] - pos;
+}
+
+/**
+ * Get the data of the given chunk.
+ *
+ * \param chunk_num The number of the desired chunk.
+ * \param buf Chunk data.
+ * \param len Chunk length in bytes.
+ *
+ * \return Positive on success, negative on errors.
+ */
+int vss_get_chunk(long unsigned chunk_num, char **buf, size_t *len)
+{
+       if (mmd->audio_format < 0 || !map || !vss_playing())
+               return -E_CHUNK;
+       if (chunk_num >= mmd->afi.chunks_total)
+               return -E_CHUNK;
+       get_chunk(chunk_num, buf, len);
+       return 1;
+}
+
 /**
  * main sending function
  *
@@ -508,8 +556,6 @@ void vss_send_chunk(void)
 {
        int i;
        struct audio_format_handler *af;
-       ssize_t pos;
-       size_t len;
        struct timeval now, due;
 
        if (mmd->audio_format < 0 || !map || !vss_playing())
@@ -529,8 +575,6 @@ void vss_send_chunk(void)
                mmd->new_vss_status_flags |= VSS_NEXT;
                return vss_eof();
        }
-       pos = mmd->afi.chunk_table[mmd->current_chunk];
-       len = mmd->afi.chunk_table[mmd->current_chunk + 1] - pos;
        /*
         * We call the send function also in case of empty chunks as they
         * might have still some data queued which can be sent in this case.
@@ -542,9 +586,12 @@ void vss_send_chunk(void)
                mmd->offset = tv2ms(&tmp);
                mmd->events++;
        }
-       for (i = 0; senders[i].name; i++)
-               senders[i].send(mmd->current_chunk, mmd->chunks_sent,
-                       map + pos, len);
+       for (i = 0; senders[i].name; i++) {
+               char *buf;
+               size_t len;
+               get_chunk(mmd->current_chunk, &buf, &len);
+               senders[i].send(mmd->current_chunk, mmd->chunks_sent, buf, len);
+       }
        mmd->new_vss_status_flags |= VSS_PLAYING;
        mmd->chunks_sent++;
        mmd->current_chunk++;