mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
- Cleanup code for FlacInputStream::getTotalPlayTime
- Reset input stream position in MP3InputStream after calculating total play time svn-id: r32323
This commit is contained in:
parent
e82295daa3
commit
9d13d90d4f
@ -90,7 +90,6 @@ protected:
|
||||
bool _disposeAfterUse;
|
||||
|
||||
uint _numLoops;
|
||||
const uint _totalNumLoops;
|
||||
|
||||
::FLAC__SeekableStreamDecoder *_decoder;
|
||||
|
||||
@ -103,6 +102,9 @@ protected:
|
||||
/** index + 1(!) of the last sample to be played - 0 is end of stream */
|
||||
FLAC__uint64 _lastSample;
|
||||
|
||||
/** total play time */
|
||||
int32 _totalPlayTime;
|
||||
|
||||
/** true if the last sample was decoded from the FLAC-API - there might still be data in the buffer */
|
||||
bool _lastSampleWritten;
|
||||
|
||||
@ -142,28 +144,7 @@ public:
|
||||
return _streaminfo.channels == 0 || (_lastSampleWritten && _sampleCache.bufFill == 0);
|
||||
}
|
||||
|
||||
int32 getTotalPlayTime() const {
|
||||
if (!_totalNumLoops)
|
||||
return AudioStream::kUnknownPlayTime;
|
||||
|
||||
int32 samples = 0;
|
||||
|
||||
if (!_lastSample) {
|
||||
if (!_streaminfo.total_samples)
|
||||
return AudioStream::kUnknownPlayTime;
|
||||
|
||||
samples = _streaminfo.total_samples - _firstSample;
|
||||
} else {
|
||||
samples = _lastSample - _firstSample - 1;
|
||||
}
|
||||
|
||||
const int32 rate = _streaminfo.sample_rate;
|
||||
|
||||
int32 seconds = samples / rate;
|
||||
int32 milliseconds = (1000 * (samples % rate)) / rate;
|
||||
|
||||
return (seconds * 1000 + milliseconds) * _totalNumLoops;
|
||||
}
|
||||
int32 getTotalPlayTime() const { return _totalPlayTime; }
|
||||
|
||||
bool isStreamDecoderReady() const { return getStreamDecoderState() == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC ; }
|
||||
|
||||
@ -214,7 +195,6 @@ FlacInputStream::FlacInputStream(Common::SeekableReadStream *inStream, bool disp
|
||||
_inStream(inStream),
|
||||
_disposeAfterUse(dispose),
|
||||
_numLoops(numLoops),
|
||||
_totalNumLoops(numLoops),
|
||||
_firstSample(0), _lastSample(0),
|
||||
_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(false),
|
||||
_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric)
|
||||
@ -260,7 +240,28 @@ FlacInputStream::FlacInputStream(Common::SeekableReadStream *inStream, bool disp
|
||||
// avoid overflows).
|
||||
_firstSample = (FLAC__uint64)(startTime * (_streaminfo.sample_rate / 1000.0));
|
||||
_lastSample = (FLAC__uint64)(endTime * (_streaminfo.sample_rate / 1000.0));
|
||||
|
||||
if (_firstSample == 0 || seekAbsolute(_firstSample)) {
|
||||
int32 samples = kUnknownPlayTime;
|
||||
|
||||
if (!_lastSample) {
|
||||
if (_streaminfo.total_samples)
|
||||
samples = _streaminfo.total_samples - _firstSample;
|
||||
} else {
|
||||
samples = _lastSample - _firstSample - 1;
|
||||
}
|
||||
|
||||
if (samples != kUnknownPlayTime && samples >= 0 && numLoops) {
|
||||
const int32 rate = _streaminfo.sample_rate;
|
||||
|
||||
int32 seconds = samples / rate;
|
||||
int32 milliseconds = (1000 * (samples % rate)) / rate;
|
||||
|
||||
_totalPlayTime = (seconds * 1000 + milliseconds) * numLoops;
|
||||
} else {
|
||||
_totalPlayTime = kUnknownPlayTime;
|
||||
}
|
||||
|
||||
return; // no error occured
|
||||
}
|
||||
}
|
||||
|
@ -169,11 +169,14 @@ MP3InputStream::MP3InputStream(Common::SeekableReadStream *inStream, bool dispos
|
||||
|
||||
// Reinit stream
|
||||
_state = MP3_STATE_INIT;
|
||||
|
||||
// Reset the stream data
|
||||
_inStream->seek(0, SEEK_SET);
|
||||
}
|
||||
|
||||
_totalPlayTime = mad_timer_count(length, MAD_UNITS_MILLISECONDS);
|
||||
|
||||
if (numLoops)
|
||||
if (numLoops && mad_timer_sign(length) >= 0)
|
||||
_totalPlayTime *= numLoops;
|
||||
else
|
||||
_totalPlayTime = kUnknownPlayTime;
|
||||
|
Loading…
Reference in New Issue
Block a user