]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
kill the read_chunk handler of struct audio_format handler
authorAndre Noll <maan@systemlinux.org>
Sun, 4 Mar 2007 21:31:52 +0000 (22:31 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 4 Mar 2007 21:31:52 +0000 (22:31 +0100)
chunks are now read by vss_read_chunk(), i.e. the same function is
used for all audio formats.

aac_afh.c
afh.h
mp3_afh.c
ogg_afh.c
vss.c

index b017a83231bc010ed19536c80c916523ef321458..e68004b24a4648f09d624e6e428ddc7d3072b27e 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -194,45 +194,12 @@ static int aac_get_file_info(FILE *file, char *info_str, long unsigned *frames,
        return 1;
 }
 
-static char *aac_read_chunk(long unsigned current_chunk, ssize_t *len)
-{
-       int ret;
-       size_t pos;
-
-       *len = 0;
-       if (current_chunk >= num_chunks)
-               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/%zu to %zd bytes\n",
-                       current_chunk, num_chunks, *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(infile, pos, SEEK_SET);
-       if (ret < 0)
-               return NULL;
-       ret = para_fread(inbuf, *len, 1, infile);
-       if (ret != *len)
-               return NULL;
-//     PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-//             (long unsigned) inbuf[4]);
-       return (char *)inbuf;
-}
-
-
 static const char* aac_suffixes[] = {"m4a", "mp4", NULL};
 /** the init function of the aac audio format handler */
 void aac_afh_init(struct audio_format_handler *p)
 {
        af = p;
        af->get_file_info = aac_get_file_info,
-       af->read_chunk = aac_read_chunk;
        af->close_audio_file = aac_close_audio_file;
        af->get_header_info = NULL;
        af->suffixes = aac_suffixes;
diff --git a/afh.h b/afh.h
index 35b7a70e4dff72220f4550f4fbecc6dffdc48710..77874108a056c73707f2b39516168558bf1b4e80 100644 (file)
--- a/afh.h
+++ b/afh.h
@@ -103,16 +103,4 @@ struct audio_format_handler {
         * for closing the file handle. It is assumed to succeed.
        */
        void (*close_audio_file)(void);
-       /**
-        * function responsible for reading one data chunk.
-        *
-        * \a read_chunk() must return a pointer to the next chunk of data that should
-        * be sent out, or \p NULL on errors or if the end of the file was encountered.
-        *
-        * If it returns non-NULL, \a len must contain the length of the returned
-        * buffer (which may be zero if nothing has to be sent for some reason).
-        * Otherwise, \a len is used to distinguish between the eof and the error case:
-        * It must be zero in the eof case, or negative if an error occcured.
-       */
-       char * (*read_chunk)(long unsigned chunk_num, ssize_t *len);
 };
index 398a334e0f51668e2a8acfc11b5f68e7051352bb..691f1f093c302320b8877cf6588fdec246bb6c51 100644 (file)
--- a/mp3_afh.c
+++ b/mp3_afh.c
@@ -462,37 +462,6 @@ static int mp3_get_file_info(FILE *audio_file, char *info_str,
        return 1;
 }
 
-static char *mp3_read_chunk(long unsigned current_chunk, ssize_t *len)
-{
-       int ret;
-       size_t pos;
-
-       *len = 0;
-       if (current_chunk >= num_chunks)
-               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/%zu to %zd bytes\n",
-                       current_chunk, num_chunks, *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(infile, pos, SEEK_SET);
-       if (ret < 0)
-               return NULL;
-       ret = para_fread(inbuf, *len, 1, infile);
-       if (ret != *len)
-               return NULL;
-//     PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-//             (long unsigned) inbuf[4]);
-       return (char *)inbuf;
-}
-
 static void mp3_close_audio_file(void)
 {
        if (!infile)
@@ -514,7 +483,6 @@ void mp3_init(struct audio_format_handler *p)
 {
        af = p;
        af->get_file_info = mp3_get_file_info;
-       af->read_chunk = mp3_read_chunk;
        af->close_audio_file = mp3_close_audio_file;
        af->get_header_info = NULL;
        /* eof_tv gets overwritten in mp3_get_file_info() */
index 483c8365d0cc437757023e725b5a8a8d294d4953..a18c4d7efb7695584bbf0c7de89e491fdc899419 100644 (file)
--- a/ogg_afh.c
+++ b/ogg_afh.c
@@ -273,37 +273,6 @@ err:
        return ret;
 }
 
-static char *ogg_read_chunk(long unsigned current_chunk, ssize_t *len)
-{
-       int ret;
-       size_t pos;
-
-       *len = 0;
-       if (current_chunk >= num_chunks)
-               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/%zu to %zd bytes\n",
-                       current_chunk, num_chunks, *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(infile, pos, SEEK_SET);
-       if (ret < 0)
-               return NULL;
-       ret = para_fread(inbuf, *len, 1, infile);
-       if (ret != *len)
-               return NULL;
-//     PARA_DEBUG_LOG("ret: %d, inbuf[0]: %lx - %lx\n", ret, (long unsigned) inbuf[0],
-//             (long unsigned) inbuf[4]);
-       return (char *)inbuf;
-}
-
 static char *ogg_get_header_info(int *len)
 {
        *len = header_len;
@@ -321,7 +290,6 @@ void ogg_init(struct audio_format_handler *p)
 {
        af = p;
        af->get_file_info = ogg_get_file_info,
-       af->read_chunk = ogg_read_chunk;
        af->close_audio_file = ogg_close_audio_file;
        af->get_header_info = ogg_get_header_info;
        af->chunk_tv.tv_sec = 0;
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)