X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mp3dec.c;h=0006a181aa29676cc7ae5aaf00238b99da6c3768;hp=5c6bab339e599152ccbba81d4873500fd8af7e3a;hb=97e3deb06e0dd2e63520c2dc0736e753e1276fde;hpb=471684761a2039bbc89aa1e3c33c62de6bef86cf diff --git a/mp3dec.c b/mp3dec.c index 5c6bab33..0006a181 100644 --- a/mp3dec.c +++ b/mp3dec.c @@ -1,10 +1,10 @@ /* - * Copyright (C) 2005-2007 Andre Noll + * Copyright (C) 2005-2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file mp3dec.c paraslash's mp3 decoder */ +/** \file mp3dec.c Paraslash's mp3 decoder. */ #include "para.h" #include "list.h" @@ -14,25 +14,20 @@ #include #include "string.h" -/** the output buffer size */ -#define MP3_OUTBUF_SIZE 128 * 1024 +/** The output buffer size. */ +#define MP3_OUTBUF_SIZE (128 * 1024) -/** \cond a helper macro */ +/** Convert a sample value from libmad to a signed short. */ #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 */ -/** - * data specific to the mp3dec filter - * - * \sa filter, filter_node - */ +/** Data specific to the mp3dec filter. */ struct private_mp3dec_data { - /** information on the current mp3 stream */ + /** Information on the current mp3 stream. */ struct mad_stream stream; - /** information about the frame which is currently decoded */ + /** Information about the frame which is currently decoded. */ struct mad_frame frame; - /** contains the PCM output */ + /** Contains the PCM output. */ struct mad_synth synth; }; @@ -48,15 +43,25 @@ static ssize_t mp3dec(char *inbuffer, size_t len, struct filter_node *fn) pmd->stream.error = 0; next_frame: ret = mad_header_decode(&pmd->frame.header, &pmd->stream); - if (ret < 0) + if (ret < 0) { + if (pmd->stream.error != MAD_ERROR_BUFLEN && + pmd->stream.error != MAD_ERROR_LOSTSYNC) + PARA_DEBUG_LOG("header decode: %s\n", + mad_stream_errorstr(&pmd->stream)); 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) + if (MAD_RECOVERABLE(pmd->stream.error) || + pmd->stream.error == MAD_ERROR_BUFLEN) { + PARA_DEBUG_LOG("frame decode: %s\n", + mad_stream_errorstr(&pmd->stream)); goto out; - PARA_ERROR_LOG("fatal: ret = %d, loaded = %zd\n", ret, fn->loaded); + } + PARA_ERROR_LOG("frame decode: %s\n", + mad_stream_errorstr(&pmd->stream)); return -E_MAD_FRAME_DECODE; } mad_synth_frame(&pmd->synth, &pmd->frame); @@ -103,9 +108,9 @@ static void mp3dec_close(struct filter_node *fn) static void mp3dec_open(struct filter_node *fn) { - fn->private_data = para_calloc(sizeof(struct private_mp3dec_data)); - struct private_mp3dec_data *pmd = fn->private_data; + struct private_mp3dec_data *pmd = para_calloc(sizeof(*pmd)); + fn->private_data = pmd; mad_stream_init(&pmd->stream); mad_frame_init(&pmd->frame); mad_synth_init(&pmd->synth); @@ -115,11 +120,11 @@ static void mp3dec_open(struct filter_node *fn) } /** - * the init function of the mp3dec filter + * The init function of the mp3dec filter. * - * \param f pointer to the filter struct to initialize + * \param f Pointer to the filter struct to initialize. * - * \sa filter::init + * \sa filter::init. */ void mp3dec_init(struct filter *f) {