From 66512edb6caaffa78727bfd43b0dbe540d06ce21 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Sun, 13 Aug 2006 02:53:20 +0000 Subject: Presume that the Xing frame count is accurate, and stop decoding when we hit the last frame git-svn-id: https://svn.musicpd.org/mpd/trunk@4618 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/inputPlugins/mp3_plugin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 29a0c43d9..6211ce085 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -138,6 +138,7 @@ typedef struct _mp3DecodeData { int dropFramesAtEnd; int dropSamplesAtStart; int dropSamplesAtEnd; + int foundXing; int foundFirstFrame; int decodedFirstFrame; int flush; @@ -161,6 +162,7 @@ static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) data->dropFramesAtEnd = 0; data->dropSamplesAtStart = 0; data->dropSamplesAtEnd = 0; + data->foundXing = 0; data->foundFirstFrame = 0; data->decodedFirstFrame = 0; data->flush = 1; @@ -640,6 +642,7 @@ static int decodeFirstFrame(mp3DecodeData * data, DecoderControl * dc, bitlen = data->stream.anc_bitlen; if (parse_xing(&xing, &ptr, &bitlen)) { + data->foundXing = 1; data->muteFrame = MUTEFRAME_SKIP; if (parse_lame(&lame, &ptr, &bitlen)) { @@ -737,9 +740,12 @@ static int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc, mad_timer_add(&data->timer, (data->frame).header.duration); data->bitRate = (data->frame).header.bitrate; if (data->currentFrame >= data->maxFrames) { + /* stop decoding, since Xing maxFrames is accurate */ + if (data->foundXing) return DECODE_BREAK; data->currentFrame = data->maxFrames - 1; - } else + } else { data->highestFrame++; + } data->frameOffset[data->currentFrame] = data->inStream->offset; if (data->stream.this_frame != NULL) { data->frameOffset[data->currentFrame] -= @@ -749,8 +755,9 @@ static int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc, data->stream.bufend - data->stream.buffer; } data->times[data->currentFrame] = data->timer; - } else + } else { data->timer = data->times[data->currentFrame]; + } data->currentFrame++; data->elapsedTime = ((float)mad_timer_count(data->timer, MAD_UNITS_MILLISECONDS)) / -- cgit v1.2.3