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.
static int read_audiod_pipe(int fd)
{
static int read_audiod_pipe(int fd)
{
- static char buf[8192];
- static int loaded;
+ static char *buf;
+ static int bufsize, loaded;
- 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;
if (ret <= 0)
return ret;
loaded += ret;