]> git.tue.mpg.de Git - paraslash.git/commitdiff
wav: Only create wav header if there is output available.
authorAndre Noll <maan@systemlinux.org>
Sun, 30 Nov 2008 14:13:35 +0000 (15:13 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 30 Nov 2008 14:13:35 +0000 (15:13 +0100)
Due to recent changes to filter_chain.c, the convert functions of all
activated filters are called even if there is no output availabe since
the ogg vorbis decoder needs this.

However, this change broke the wav filter: wav_convert() is now called
even if the previous filter (e.g. oggdec) has not yet determined the
format of the input stream.

This caused the wav filter to write out an invalid wav header with 0
channels. Fix it by not doing anything unless wav_convert() gets called
with non-empty input.

wav.c

diff --git a/wav.c b/wav.c
index 4933afd49443c006e4fd3d219d51cfd75856bf71..c03c21dc4db47ea51b44ab352570a5e7e0bc08cf 100644 (file)
--- a/wav.c
+++ b/wav.c
@@ -48,6 +48,7 @@ static void make_wav_header(unsigned int channels, unsigned int samplerate,
        int bytespersec = channels * samplerate * BITS / 8;
        int align = channels * BITS / 8;
 
+       assert(channels);
        PARA_DEBUG_LOG("writing wave header: %d channels, %d KHz\n", channels, samplerate);
        memset(headbuf, 0, WAV_HEADER_LEN);
        memcpy(headbuf, "RIFF", 4);
@@ -71,6 +72,8 @@ static ssize_t wav_convert(char *inbuf, size_t len, struct filter_node *fn)
        int *bof = fn->private_data;
 
        if (*bof) {
+               if (!len)
+                       return 0;
                make_wav_header(fn->fc->channels, fn->fc->samplerate, fn);
                fn->loaded = WAV_HEADER_LEN;
                *bof = 0;