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 6806cc8..21770ca 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;