add RageSoundReader::RetriedRead

This commit is contained in:
Glenn Maynard
2006-12-22 06:08:40 +00:00
parent a7d3a539ee
commit a844c8b1c9
2 changed files with 31 additions and 0 deletions
+30
View File
@@ -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.
+1
View File
@@ -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; }