]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - vss.c
audiod: Simplify two log messages.
[paraslash.git] / vss.c
diff --git a/vss.c b/vss.c
index e1e4ead542519ade73e2e5122a54cd4ba44fc7a4..c15fbd7e6898537f2c9e6a26ee067c61ab7455da 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -1,19 +1,7 @@
 /*
  * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
  *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file vss.c the virtual streaming system
@@ -412,7 +400,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;
@@ -507,6 +495,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
  *
@@ -520,8 +534,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())
@@ -541,8 +553,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.
@@ -554,9 +564,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++;