]> git.tue.mpg.de Git - paraslash.git/commitdiff
mp3dec: skip invalid frame headers
authorAndre <maan@p133.(none)>
Mon, 1 May 2006 03:21:06 +0000 (05:21 +0200)
committerAndre <maan@p133.(none)>
Mon, 1 May 2006 03:21:06 +0000 (05:21 +0200)
First try to decode the header, and if that fails with a recoverable
error, return FRAME_HEADER_SIZE to skip the invalid frame.

mp3dec.c

index 764fc2665efee91301611b1a0f903f3ac1bd8090..af9de5484a0f9f150a153500fef42fd6a2920f9e 100644 (file)
--- a/mp3dec.c
+++ b/mp3dec.c
@@ -48,6 +48,8 @@ struct private_mp3dec_data {
        struct mad_synth synth;
 };
 
+/* TODO: Convert all input if possible */
+#define FRAME_HEADER_SIZE 4
 static ssize_t mp3dec(char *inbuffer, size_t len, struct filter_node *fn)
 {
        int i, ret;
@@ -59,6 +61,14 @@ static ssize_t mp3dec(char *inbuffer, size_t len, struct filter_node *fn)
        mad_stream_buffer(&pmd->stream, (unsigned char *) inbuffer, copy);
        pmd->stream.error = 0;
 next_frame:
+       ret = mad_header_decode(&pmd->frame.header, &pmd->stream);
+       if (ret < 0) {
+               if (!MAD_RECOVERABLE(pmd->stream.error))
+                       goto out;
+               return FRAME_HEADER_SIZE;
+       }
+       fn->fci->samplerate = pmd->frame.header.samplerate;
+       fn->fci->channels = MAD_NCHANNELS(&pmd->frame.header);
        ret = mad_frame_decode(&pmd->frame, &pmd->stream);
        if (ret) {
                if (MAD_RECOVERABLE(pmd->stream.error) || pmd->stream.error == MAD_ERROR_BUFLEN)
@@ -67,8 +77,6 @@ next_frame:
                return -E_MAD_FRAME_DECODE;
        }
        mad_synth_frame(&pmd->synth, &pmd->frame);
-       fn->fci->samplerate = pmd->frame.header.samplerate;
-       fn->fci->channels = MAD_NCHANNELS(&pmd->frame.header);
 
        for (i = 0; i < pmd->synth.pcm.length; i++) {
                /* output format: unsigned 16 bit little endian */
@@ -90,8 +98,8 @@ next_frame:
 out:
        if (pmd->stream.next_frame) { /* we still have some data */
                size_t off = pmd->stream.bufend - pmd->stream.next_frame;
-               PARA_DEBUG_LOG("converted %zd, %zd input bytes, %zd output bytes\n",
-                       len - off, off, fn->loaded);
+               PARA_DEBUG_LOG("converted %zd, rate: %u, returning %zd\n", len - off,
+                       fn->fci->samplerate, copy - off);
                return copy - off;
        }
        return copy;