]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
gui: Use variable-sized input buffer for the audiod pipe.
authorAndre Noll <maan@systemlinux.org>
Sun, 5 Jul 2009 08:44:23 +0000 (10:44 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 5 Jul 2009 08:44:23 +0000 (10:44 +0200)
The previous fixed size of 8192 might be too small if the audio file contains large
tags. OTOH, 8192 is much too large for the bulk of all audio files. So use a small
buffer that gets increased on demand.

gui.c

diff --git a/gui.c b/gui.c
index 6806cc8fcc662435cf53a3c01a7b1f6b4607386f..21770ca86a368e177b5d9923f51743fe1932999c 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -682,13 +682,20 @@ static int update_item(int item_num, char *buf)
 
 static int read_audiod_pipe(int fd)
 {
-       static char buf[8192];
-       static int loaded;
+       static char *buf;
+       static int bufsize, loaded;
        int ret;
 
-       if (loaded >= sizeof(buf)) /* overflow */
-               return 0;
-       ret = read(fd, buf + loaded, sizeof(buf) - loaded);
+       if (loaded >= bufsize) {
+               if (bufsize > 1000 * 1000) {
+                       loaded = 0;
+                       return 0;
+               }
+               bufsize += bufsize + 1000;
+               buf = para_realloc(buf, bufsize);
+       }
+       assert(loaded < bufsize);
+       ret = read(fd, buf + loaded, bufsize - loaded);
        if (ret <= 0)
                return ret;
        loaded += ret;