X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mp3dec.c;h=401a03c582f418d6590a7fc27007becdfab6d73d;hp=4599df90b6fd42f712a7203069220c45bf579ec1;hb=21a0bd773519c5bd39a5293f2e66ea59add8d0a9;hpb=a8a78f935dcefa8a7fcda8dae80bca64fe39d632 diff --git a/mp3dec.c b/mp3dec.c index 4599df90..401a03c5 100644 --- a/mp3dec.c +++ b/mp3dec.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,8 +19,8 @@ /** \file mp3dec.c paraslash's mp3 decoder */ #include "para.h" - #include "list.h" +#include "sched.h" #include "filter.h" #include "error.h" #include @@ -30,7 +30,7 @@ #define MP3_OUTBUF_SIZE 128 * 1024 /** \cond a helper macro */ -#define MAD_TO_SHORT(f) (f) >= MAD_F_ONE? SHRT_MAX :\ +#define MAD_TO_SHORT(f) (f) >= MAD_F_ONE? SHRT_MAX :\ (f) <= -MAD_F_ONE? -SHRT_MAX : (signed short) ((f) >> (MAD_F_FRACBITS - 15)) /** \endcond */ @@ -59,16 +59,19 @@ 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) + goto out; + fn->fc->samplerate = pmd->frame.header.samplerate; + fn->fc->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 */ @@ -82,7 +85,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) @@ -90,8 +93,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_INFO_LOG("off: %zd, rate: %u, returning %zd\n", off, +// fn->fc->samplerate, copy - off); return copy - off; } return copy; @@ -123,9 +126,12 @@ static void mp3dec_open(struct filter_node *fn) fn->bufsize = MP3_OUTBUF_SIZE; fn->buf = para_calloc(fn->bufsize); } + /** * the init function of the mp3dec filter * + * \param f pointer to the filter struct to initialize + * * \sa filter::init */ void mp3dec_init(struct filter *f)