add RageSoundReader::RetriedRead
This commit is contained in:
@@ -1,9 +1,39 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "RageSoundReader.h"
|
#include "RageSoundReader.h"
|
||||||
|
#include "RageLog.h"
|
||||||
#include "RageUtil_AutoPtr.h"
|
#include "RageUtil_AutoPtr.h"
|
||||||
|
|
||||||
REGISTER_CLASS_TRAITS( RageSoundReader, pCopy->Copy() );
|
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
|
* Copyright (c) 2006 Glenn Maynard
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
virtual float GetStreamToSourceRatio() const = 0;
|
virtual float GetStreamToSourceRatio() const = 0;
|
||||||
|
|
||||||
RString GetError() const { return m_sError; }
|
RString GetError() const { return m_sError; }
|
||||||
|
int RetriedRead( char *pBuffer, int iFrames, int *iSourceFrame = NULL, float *fRate = NULL );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetError( RString sError ) const { m_sError = sError; }
|
void SetError( RString sError ) const { m_sError = sError; }
|
||||||
|
|||||||
Reference in New Issue
Block a user