From a2b6583db6da3e044f3718f660c7f9a1adf2bb10 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 18 May 2004 14:58:47 +0000 Subject: fix some wackiness due to attempted search table git-svn-id: https://svn.musicpd.org/mpd/trunk@1065 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/mp3_decode.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/mp3_decode.c b/src/mp3_decode.c index 0658f3d41..116083eb5 100644 --- a/src/mp3_decode.c +++ b/src/mp3_decode.c @@ -181,8 +181,8 @@ int fillMp3InputBuffer(mp3DecodeData * data, long offset) { readed = 0; while(readed == 0 && !inputStreamAtEOF(data->inStream)) { - readed = readFromInputStream(data->inStream, readStart, 1, - readSize); + readed = readFromInputStream(data->inStream, readStart, + (size_t)1, readSize); } if(readed<=0) return -1; @@ -362,10 +362,16 @@ int decodeFirstFrame(mp3DecodeData * data) { else { offset-= data->stream.bufend-data->stream.buffer; } - data->totalTime = ((data->inStream->size-offset)*8.0)/ + if(data->inStream->size >= offset) { + data->totalTime = ((data->inStream->size-offset)*8.0)/ (data->frame).header.bitrate; - if(data->totalTime < 0) data->totalTime = 0; - data->maxFrames = data->totalTime/frameTime+FRAMES_CUSHION; + data->maxFrames = + data->totalTime/frameTime+FRAMES_CUSHION; + } + else { + data->maxFrames = FRAMES_CUSHION; + data->totalTime = 0; + } } data->frameOffset = malloc(sizeof(long)*data->maxFrames); @@ -415,11 +421,13 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) { static struct audio_dither dither; static int skip; - if(data->currentFrame>=data->highestFrame && - data->highestFramemaxFrames) - { + if(data->currentFrame>=data->highestFrame) { mad_timer_add(&data->timer,(data->frame).header.duration); data->bitRate = (data->frame).header.bitrate; + if(data->currentFrame>=data->maxFrames) { + data->currentFrame = data->maxFrames - 1; + } + else data->highestFrame++; data->frameOffset[data->currentFrame] = data->inStream->offset; if(data->stream.this_frame!=NULL) { data->frameOffset[data->currentFrame]-= @@ -431,7 +439,6 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) { data->stream.bufend-data->stream.buffer; } data->times[data->currentFrame] = data->timer; - data->highestFrame++; } else data->timer = data->times[data->currentFrame]; data->currentFrame++; -- cgit v1.2.3