X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mp3dec.c;h=af9de5484a0f9f150a153500fef42fd6a2920f9e;hp=0100d04ea7d8a191a57c7264972870756d53ded4;hb=9230155e692c3a2303a267759183dd1ad264dda1;hpb=2ed89c59f0efcd0a2763f47c7d3455663241e623 diff --git a/mp3dec.c b/mp3dec.c index 0100d04e..af9de548 100644 --- a/mp3dec.c +++ b/mp3dec.c @@ -18,7 +18,6 @@ /** \file mp3dec.c paraslash's mp3 decoder */ -#include "gcc-compat.h" #include "para.h" #include "list.h" @@ -49,27 +48,35 @@ 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; struct private_mp3dec_data *pmd = fn->private_data; - size_t copy = MIN(len, 4096); + size_t copy = PARA_MIN(len, 4096); if (fn->loaded > fn->bufsize * 4 / 5) return 0; 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) goto out; - PARA_ERROR_LOG("fatal: ret = %d, loaded = %d\n", ret, fn->loaded); + PARA_ERROR_LOG("fatal: ret = %d, loaded = %zd\n", ret, fn->loaded); 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 */ @@ -83,7 +90,7 @@ next_frame: } if (fn->loaded != fn->bufsize) /* output buffer not full */ continue; - PARA_ERROR_LOG("output buffer full: %d\n", fn->loaded); + PARA_ERROR_LOG("output buffer full: %zd\n", fn->loaded); return -E_MP3DEC_OVERRUN; } if (fn->loaded <= fn->bufsize * 4 / 5) @@ -91,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 %d, %d input bytes, %d 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;