diff --git a/stepmania/src/RageSoundReader.cpp b/stepmania/src/RageSoundReader.cpp index 74a35a0629..8b1087e72d 100644 --- a/stepmania/src/RageSoundReader.cpp +++ b/stepmania/src/RageSoundReader.cpp @@ -1,9 +1,39 @@ #include "global.h" #include "RageSoundReader.h" +#include "RageLog.h" #include "RageUtil_AutoPtr.h" REGISTER_CLASS_TRAITS( RageSoundReader, pCopy->Copy() ); +/* Read(), handling the empty return case. */ +int RageSoundReader::RetriedRead( char *pBuffer, int iFrames, int *iSourceFrame, float *fRate ) +{ + if( iFrames == 0 ) + return 0; + + /* pReader may return 0, which means "try again immediately". As a failsafe, + * only try this a finite number of times. Use a high number, because in + * principle each filter in the stack may cause this. */ + int iTries = 100; + while( --iTries ) + { + if( fRate ) + *fRate = this->GetStreamToSourceRatio(); + if( iSourceFrame ) + *iSourceFrame = this->GetNextSourceFrame(); + + int iGotFrames = this->Read( pBuffer, iFrames ); + + if( iGotFrames != 0 ) + return iGotFrames; + } + + LOG->Warn( "Read() busy looping" ); + + /* Pretend we got EOF. */ + return RageSoundReader::END_OF_FILE; +} + /* * Copyright (c) 2006 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/RageSoundReader.h b/stepmania/src/RageSoundReader.h index a50b916176..8e274ef574 100644 --- a/stepmania/src/RageSoundReader.h +++ b/stepmania/src/RageSoundReader.h @@ -32,6 +32,7 @@ public: virtual float GetStreamToSourceRatio() const = 0; RString GetError() const { return m_sError; } + int RetriedRead( char *pBuffer, int iFrames, int *iSourceFrame = NULL, float *fRate = NULL ); protected: void SetError( RString sError ) const { m_sError = sError; }