From c9b3498a2df280d112cf575b38af767540f033b3 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Mon, 15 May 2006 13:48:47 +0000 Subject: Work around a stupid bug in libmad so VBR MP3s with CRC protection have the correct length. git-svn-id: https://svn.musicpd.org/mpd/trunk@4184 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/inputPlugins/mp3_plugin.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/inputPlugins/mp3_plugin.c') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 8a73ed85d..6fe9f3849 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -154,7 +154,7 @@ void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) { memset(&(data->dither), 0, sizeof(struct audio_dither)); mad_stream_init(&data->stream); - data->stream.options |= MAD_OPTION_IGNORECRC; + mad_stream_options(&data->stream, MAD_OPTION_IGNORECRC); mad_frame_init(&data->frame); mad_synth_init(&data->synth); mad_timer_reset(&data->timer); @@ -397,7 +397,8 @@ int decodeNextFrame(mp3DecodeData * data) { } /* xing stuff stolen from alsaplayer */ -# define XING_MAGIC (('X' << 24) | ('i' << 16) | ('n' << 8) | 'g') +#define XI_MAGIC (('X' << 8) | 'i') +#define NG_MAGIC (('n' << 8) | 'g') struct xing { long flags; /* valid fields (see below) */ @@ -416,10 +417,22 @@ enum { int parse_xing(struct xing *xing, struct mad_bitptr ptr, unsigned int bitlen) { - if (bitlen < 64 || mad_bit_read(&ptr, 32) != XING_MAGIC) goto fail; + unsigned long bits; + if (bitlen < 16) goto fail; + bits = mad_bit_read(&ptr, 16); + bitlen -= 16; + + if (bits == XI_MAGIC) { + if (bitlen < 16) goto fail; + if (mad_bit_read(&ptr, 16) != NG_MAGIC) goto fail; + bitlen -= 16; + } + else if (bits != NG_MAGIC) goto fail; + + if (bitlen < 32) goto fail; xing->flags = mad_bit_read(&ptr, 32); - bitlen -= 64; + bitlen -= 32; if (xing->flags & XING_FRAMES) { if (bitlen < 32) goto fail; -- cgit v1.2.3