Improve return values for fallbacks.
This commit is contained in:
@@ -558,7 +558,7 @@ RageSoundReader_MP3::~RageSoundReader_MP3()
|
||||
delete mad;
|
||||
}
|
||||
|
||||
bool RageSoundReader_MP3::Open( CString filename_ )
|
||||
SoundReader_FileReader::OpenResult RageSoundReader_MP3::Open( CString filename_ )
|
||||
{
|
||||
filename = filename_;
|
||||
rw = fopen(filename, "rb");
|
||||
@@ -589,13 +589,13 @@ bool RageSoundReader_MP3::Open( CString filename_ )
|
||||
if( ret == 0 )
|
||||
{
|
||||
SetError( "Failed to read any data at all" );
|
||||
return false;
|
||||
return OPEN_NO_MATCH;
|
||||
}
|
||||
if( ret == -1 )
|
||||
{
|
||||
/* XXX: an error is already set */
|
||||
SetError( "Not an MP3 stream?" );
|
||||
return false;
|
||||
return OPEN_NO_MATCH;
|
||||
}
|
||||
|
||||
LOG->Trace("Accepting MP3 stream.");
|
||||
@@ -620,7 +620,7 @@ bool RageSoundReader_MP3::Open( CString filename_ )
|
||||
|
||||
SampleRate = mad->Frame.header.samplerate;
|
||||
this->Channels = mad->Frame.header.mode == MAD_MODE_SINGLE_CHANNEL? 1:2;
|
||||
return 1;
|
||||
return OPEN_OK;
|
||||
}
|
||||
|
||||
/* dst and src are buffers of 16-bit samples. len is the number of bytes
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
int GetLengthInternal( bool fast );
|
||||
|
||||
public:
|
||||
bool Open(CString filename);
|
||||
OpenResult Open(CString filename);
|
||||
void Close();
|
||||
int GetLength() const { return ((RageSoundReader_MP3*)this)->GetLengthInternal(false); }
|
||||
int GetLength_Fast() const { return ((RageSoundReader_MP3*)this)->GetLengthInternal(true); }
|
||||
|
||||
@@ -42,6 +42,7 @@ static CString ov_ssprintf( int err, const char *fmt, ...)
|
||||
CString errstr;
|
||||
switch( err )
|
||||
{
|
||||
/* XXX: In the case of OV_EREAD, can we snoop at errno? */
|
||||
case OV_EREAD: errstr = "Read error"; break;
|
||||
case OV_EFAULT: errstr = "Internal error"; break;
|
||||
case OV_EIMPL: errstr = "Feature not implemented"; break;
|
||||
@@ -59,7 +60,7 @@ static CString ov_ssprintf( int err, const char *fmt, ...)
|
||||
return s + ssprintf( " (%s)", errstr.c_str() );
|
||||
}
|
||||
|
||||
bool RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
SoundReader_FileReader::OpenResult RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
{
|
||||
filename=filename_;
|
||||
|
||||
@@ -68,7 +69,7 @@ bool RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
if(f == NULL)
|
||||
{
|
||||
SetError(ssprintf("ogg fopen(%s) failed: %s", filename.c_str(), strerror(errno)));
|
||||
return false;
|
||||
return OPEN_MATCH_BUT_FAIL;
|
||||
}
|
||||
|
||||
int ret = ov_open(f, vf, NULL, 0);
|
||||
@@ -76,12 +77,19 @@ bool RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
{
|
||||
SetError( ov_ssprintf(ret, "ov_open failed") );
|
||||
fclose(f);
|
||||
return false;
|
||||
switch( ret )
|
||||
{
|
||||
case OV_EREAD:
|
||||
case OV_ENOTVORBIS:
|
||||
return OPEN_MATCH_BUT_FAIL;
|
||||
default:
|
||||
return OPEN_NO_MATCH;
|
||||
}
|
||||
}
|
||||
|
||||
avail = 0;
|
||||
|
||||
return true;
|
||||
return OPEN_OK;
|
||||
}
|
||||
|
||||
int RageSoundReader_Vorbisfile::GetLength() const
|
||||
|
||||
@@ -13,7 +13,7 @@ class RageSoundReader_Vorbisfile: public SoundReader_FileReader {
|
||||
CString filename;
|
||||
|
||||
public:
|
||||
bool Open(CString filename);
|
||||
OpenResult Open(CString filename);
|
||||
int GetLength() const;
|
||||
int GetLength_Fast() const;
|
||||
int SetPosition_Accurate(int ms) { return SetPosition(ms, true); }
|
||||
|
||||
@@ -439,13 +439,13 @@ int RageSoundReader_WAV::find_chunk( Uint32 id, Sint32 &size )
|
||||
}
|
||||
|
||||
|
||||
bool RageSoundReader_WAV::WAV_open_internal()
|
||||
SoundReader_FileReader::OpenResult RageSoundReader_WAV::WAV_open_internal()
|
||||
{
|
||||
Uint32 magic1;
|
||||
if( !read_le32(rw, &magic1) || magic1 != riffID )
|
||||
{
|
||||
SetError( "WAV: Not a RIFF file." );
|
||||
return false;
|
||||
return OPEN_NO_MATCH;
|
||||
}
|
||||
|
||||
Uint32 ignore;
|
||||
@@ -455,18 +455,29 @@ bool RageSoundReader_WAV::WAV_open_internal()
|
||||
if( !read_le32( rw, &magic2 ) || magic2 != waveID )
|
||||
{
|
||||
SetError( "Not a WAVE file." );
|
||||
return false;
|
||||
return OPEN_NO_MATCH;
|
||||
}
|
||||
|
||||
Sint32 NextChunk;
|
||||
BAIL_IF_MACRO(!find_chunk(fmtID, NextChunk), "No format chunk.", false);
|
||||
BAIL_IF_MACRO(!find_chunk(fmtID, NextChunk), "No format chunk.", OPEN_MATCH_BUT_FAIL);
|
||||
NextChunk += ftell(rw);
|
||||
BAIL_IF_MACRO(!read_fmt_chunk(), "Can't read format chunk.", false);
|
||||
BAIL_IF_MACRO(!read_fmt_chunk(), "Can't read format chunk.", OPEN_MATCH_BUT_FAIL);
|
||||
|
||||
/* I think multi-channel WAVs are possible, but I've never even seen one. */
|
||||
Channels = (Uint8) fmt.wChannels;
|
||||
ASSERT( Channels <= 2 );
|
||||
|
||||
if( fmt.wFormatTag != FMT_NORMAL &&
|
||||
fmt.wFormatTag != FMT_ADPCM )
|
||||
{
|
||||
SetError( ssprintf("Unsupported WAV format %i", fmt.wFormatTag) );
|
||||
|
||||
/* It might be MP3 data in a WAV. (Why do people *do* that?) It's possible
|
||||
* that the MAD decoder will figure that out, so let's return OPEN_NO_MATCH
|
||||
* and keep searching for a decoder. */
|
||||
return OPEN_NO_MATCH;
|
||||
}
|
||||
|
||||
if ( fmt.wBitsPerSample == 4 && this->fmt.wFormatTag == FMT_ADPCM )
|
||||
{
|
||||
Conversion = CONV_NONE;
|
||||
@@ -485,7 +496,7 @@ bool RageSoundReader_WAV::WAV_open_internal()
|
||||
else
|
||||
{
|
||||
SetError( ssprintf("Unsupported sample size %i", fmt.wBitsPerSample) );
|
||||
return false;
|
||||
return OPEN_MATCH_BUT_FAIL;
|
||||
}
|
||||
|
||||
if( Conversion == CONV_8BIT_TO_16BIT )
|
||||
@@ -496,16 +507,16 @@ bool RageSoundReader_WAV::WAV_open_internal()
|
||||
fseek(rw, NextChunk, SEEK_SET );
|
||||
|
||||
Sint32 DataSize;
|
||||
BAIL_IF_MACRO(!find_chunk(dataID, DataSize), "No data chunk.", false);
|
||||
BAIL_IF_MACRO(!find_chunk(dataID, DataSize), "No data chunk.", OPEN_MATCH_BUT_FAIL);
|
||||
|
||||
fmt.data_starting_offset = ftell(rw);
|
||||
fmt.adpcm_sample_frame_size = BytesPerSample * Channels;
|
||||
|
||||
return true;
|
||||
return OPEN_OK;
|
||||
}
|
||||
|
||||
|
||||
bool RageSoundReader_WAV::Open( CString filename_ )
|
||||
SoundReader_FileReader::OpenResult RageSoundReader_WAV::Open( CString filename_ )
|
||||
{
|
||||
Close();
|
||||
Input_Buffer_Ratio = 1;
|
||||
@@ -514,8 +525,8 @@ bool RageSoundReader_WAV::Open( CString filename_ )
|
||||
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
|
||||
bool rc = WAV_open_internal();
|
||||
if (!rc)
|
||||
SoundReader_FileReader::OpenResult rc = WAV_open_internal();
|
||||
if ( rc != OPEN_OK )
|
||||
Close();
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -69,7 +69,7 @@ class RageSoundReader_WAV: public SoundReader_FileReader
|
||||
int seek_sample_fmt_normal( Uint32 ms );
|
||||
int get_length_fmt_normal() const;
|
||||
|
||||
bool WAV_open_internal();
|
||||
OpenResult WAV_open_internal();
|
||||
|
||||
int SetPosition(int ms);
|
||||
|
||||
@@ -79,7 +79,7 @@ class RageSoundReader_WAV: public SoundReader_FileReader
|
||||
Uint32 ConvertBytePosToMs(int BytesPerSample, int channels, Uint32 pos) const;
|
||||
|
||||
public:
|
||||
bool Open(CString filename);
|
||||
OpenResult Open(CString filename);
|
||||
void Close();
|
||||
int GetLength() const;
|
||||
int GetLength_Fast() const { return GetLength(); }
|
||||
|
||||
Reference in New Issue
Block a user