exceptions
This commit is contained in:
@@ -232,40 +232,46 @@ void Alsa9Buf::GetSoundCardDebugInfo()
|
|||||||
LOG->Info( "ALSA device overridden to \"%s\"", PREFSMAN->m_iSoundDevice.c_str() );
|
LOG->Info( "ALSA device overridden to \"%s\"", PREFSMAN->m_iSoundDevice.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Alsa9Buf::Alsa9Buf( hw hardware, int channels_ )
|
Alsa9Buf::Alsa9Buf()
|
||||||
{
|
{
|
||||||
GetSoundCardDebugInfo();
|
|
||||||
|
|
||||||
InitializeErrorHandler();
|
|
||||||
|
|
||||||
channels = channels_;
|
|
||||||
samplerate = 44100;
|
samplerate = 44100;
|
||||||
samplebits = 16;
|
samplebits = 16;
|
||||||
last_cursor_pos = 0;
|
last_cursor_pos = 0;
|
||||||
samplerate_set_explicitly = false;
|
samplerate_set_explicitly = false;
|
||||||
preferred_writeahead = 8192;
|
preferred_writeahead = 8192;
|
||||||
preferred_chunksize = 1024;
|
preferred_chunksize = 1024;
|
||||||
|
pcm = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString Alsa9Buf::Init( hw hardware, int channels_ )
|
||||||
|
{
|
||||||
|
channels = channels_;
|
||||||
|
|
||||||
|
GetSoundCardDebugInfo();
|
||||||
|
|
||||||
|
InitializeErrorHandler();
|
||||||
|
|
||||||
/* Open the device. */
|
/* Open the device. */
|
||||||
int err;
|
int err;
|
||||||
err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
|
err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
|
||||||
if (err < 0)
|
if( err < 0 )
|
||||||
RageException::ThrowNonfatal("dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err));
|
return ssprintf( "dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err) );
|
||||||
|
|
||||||
if( !SetHWParams() )
|
if( !SetHWParams() )
|
||||||
{
|
{
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
dsnd_pcm_close(pcm);
|
return "SetHWParams failed";
|
||||||
CHECKPOINT;
|
|
||||||
RageException::ThrowNonfatal( "SetHWParams failed" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSWParams();
|
SetSWParams();
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Alsa9Buf::~Alsa9Buf()
|
Alsa9Buf::~Alsa9Buf()
|
||||||
{
|
{
|
||||||
dsnd_pcm_close(pcm);
|
if( pcm != NULL )
|
||||||
|
dsnd_pcm_close( pcm );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ public:
|
|||||||
enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
|
enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
|
||||||
|
|
||||||
/* Call SetSampleRate before you use the sample. */
|
/* Call SetSampleRate before you use the sample. */
|
||||||
Alsa9Buf( hw hardware, int channels );
|
Alsa9Buf();
|
||||||
|
CString Init( hw hardware, int channels );
|
||||||
~Alsa9Buf();
|
~Alsa9Buf();
|
||||||
|
|
||||||
int GetNumFramesToFill();
|
int GetNumFramesToFill();
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ int RageSound_ALSA9::GetSampleRate( int rate ) const
|
|||||||
return str->pcm->FindSampleRate( rate );
|
return str->pcm->FindSampleRate( rate );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckMixingBlacklist()
|
static CString CheckMixingBlacklist()
|
||||||
{
|
{
|
||||||
CString sID = Alsa9Buf::GetHardwareID();
|
CString sID = Alsa9Buf::GetHardwareID();
|
||||||
const CString blacklist[] = {
|
const CString blacklist[] = {
|
||||||
@@ -278,41 +278,46 @@ static void CheckMixingBlacklist()
|
|||||||
}, *blacklist_end = blacklist+ARRAYSIZE(blacklist);
|
}, *blacklist_end = blacklist+ARRAYSIZE(blacklist);
|
||||||
|
|
||||||
if( find( &blacklist[0], blacklist_end, sID ) != blacklist_end )
|
if( find( &blacklist[0], blacklist_end, sID ) != blacklist_end )
|
||||||
RageException::ThrowNonfatal( "ALSA driver \"%s\" not using hardware mixing", sID.c_str() );
|
return ssprintf( "ALSA driver \"%s\" not using hardware mixing", sID.c_str() );
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound_ALSA9::RageSound_ALSA9():
|
RageSound_ALSA9::RageSound_ALSA9():
|
||||||
m_Mutex("ALSAMutex"),
|
m_Mutex("ALSAMutex"),
|
||||||
m_InactiveSoundMutex("InactiveSoundMutex")
|
m_InactiveSoundMutex("InactiveSoundMutex")
|
||||||
{
|
{
|
||||||
CString err = LoadALSA();
|
|
||||||
if( err != "" )
|
|
||||||
RageException::ThrowNonfatal("Driver unusable: %s", err.c_str());
|
|
||||||
try {
|
|
||||||
CheckMixingBlacklist();
|
|
||||||
|
|
||||||
shutdown = false;
|
shutdown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString RageSound_ALSA9::Init()
|
||||||
|
{
|
||||||
|
CString sError = LoadALSA();
|
||||||
|
if( sError != "" )
|
||||||
|
return ssprintf( "Driver unusable: %s", sError.c_str() );
|
||||||
|
|
||||||
|
sError = CheckMixingBlacklist();
|
||||||
|
if( sError != "" )
|
||||||
|
return sError;
|
||||||
|
|
||||||
/* Create a bunch of streams and put them into the stream pool. */
|
/* Create a bunch of streams and put them into the stream pool. */
|
||||||
for( int i = 0; i < 32; ++i )
|
for( int i = 0; i < 32; ++i )
|
||||||
{
|
{
|
||||||
Alsa9Buf *newbuf;
|
Alsa9Buf *newbuf = new Alsa9Buf;
|
||||||
try {
|
sError = newbuf->Init( Alsa9Buf::HW_HARDWARE, channels );
|
||||||
newbuf = new Alsa9Buf( Alsa9Buf::HW_HARDWARE, channels );
|
if( sError != "" )
|
||||||
} catch(const RageException &e) {
|
{
|
||||||
|
delete newbuf;
|
||||||
|
|
||||||
/* If we didn't get at least 8, fail. */
|
/* If we didn't get at least 8, fail. */
|
||||||
if(i >= 8) break; /* OK */
|
if( i >= 8 )
|
||||||
|
break; /* OK */
|
||||||
|
|
||||||
/* Clean up; the dtor won't be called. */
|
if( i == 0 )
|
||||||
for(int n = 0; n < i; ++n)
|
return sError;
|
||||||
delete stream_pool[n];
|
|
||||||
|
|
||||||
if( !i )
|
|
||||||
RageException::ThrowNonfatal( "%s", e.what() );
|
|
||||||
|
|
||||||
/* We created at least one hardware buffer. */
|
/* We created at least one hardware buffer. */
|
||||||
LOG->Trace("Could only create %i buffers; need at least 8 (failed with %s). Hardware ALSA driver can't be used.", i, e.what());
|
LOG->Trace( "Could only create %i buffers; need at least 8 (failed with %s). Hardware ALSA driver can't be used.", i, sError.c_str() );
|
||||||
RageException::ThrowNonfatal("Not enough substreams for hardware mixing, using software mixing");
|
return "Not enough substreams for hardware mixing, using software mixing";
|
||||||
}
|
}
|
||||||
|
|
||||||
stream *s = new stream;
|
stream *s = new stream;
|
||||||
@@ -320,23 +325,24 @@ try {
|
|||||||
stream_pool.push_back(s);
|
stream_pool.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG->Info("ALSA: Got %i hardware buffers", stream_pool.size());
|
LOG->Info( "ALSA: Got %i hardware buffers", stream_pool.size() );
|
||||||
|
|
||||||
MixingThread.SetName( "RageSound_ALSA9" );
|
MixingThread.SetName( "RageSound_ALSA9" );
|
||||||
MixingThread.Create( MixerThread_start, this );
|
MixingThread.Create( MixerThread_start, this );
|
||||||
} catch(...) {
|
|
||||||
UnloadALSA();
|
return "";
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound_ALSA9::~RageSound_ALSA9()
|
RageSound_ALSA9::~RageSound_ALSA9()
|
||||||
{
|
{
|
||||||
|
if( MixingThread.IsCreated() )
|
||||||
|
{
|
||||||
/* Signal the mixing thread to quit. */
|
/* Signal the mixing thread to quit. */
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
LOG->Trace("Shutting down mixer thread ...");
|
LOG->Trace("Shutting down mixer thread ...");
|
||||||
MixingThread.Wait();
|
MixingThread.Wait();
|
||||||
LOG->Trace("Mixer thread shut down.");
|
LOG->Trace("Mixer thread shut down.");
|
||||||
|
}
|
||||||
|
|
||||||
for(unsigned i = 0; i < stream_pool.size(); ++i)
|
for(unsigned i = 0; i < stream_pool.size(); ++i)
|
||||||
delete stream_pool[i];
|
delete stream_pool[i];
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public:
|
|||||||
void Update(float delta);
|
void Update(float delta);
|
||||||
|
|
||||||
RageSound_ALSA9();
|
RageSound_ALSA9();
|
||||||
|
CString Init();
|
||||||
~RageSound_ALSA9();
|
~RageSound_ALSA9();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -80,11 +80,15 @@ void RageSound_ALSA9_Software::SetupDecodingThread()
|
|||||||
|
|
||||||
RageSound_ALSA9_Software::RageSound_ALSA9_Software()
|
RageSound_ALSA9_Software::RageSound_ALSA9_Software()
|
||||||
{
|
{
|
||||||
CString err = LoadALSA();
|
pcm = NULL;
|
||||||
if( err != "" )
|
|
||||||
RageException::ThrowNonfatal("Driver unusable: %s", err.c_str());
|
|
||||||
try {
|
|
||||||
shutdown = false;
|
shutdown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString RageSound_ALSA9_Software::Init()
|
||||||
|
{
|
||||||
|
CString sError = LoadALSA();
|
||||||
|
if( sError != "" )
|
||||||
|
return ssprintf( "Driver unusable: %s", sError.c_str() );
|
||||||
|
|
||||||
max_writeahead = safe_writeahead;
|
max_writeahead = safe_writeahead;
|
||||||
CString sys;
|
CString sys;
|
||||||
@@ -97,7 +101,10 @@ try {
|
|||||||
if( PREFSMAN->m_iSoundWriteAhead )
|
if( PREFSMAN->m_iSoundWriteAhead )
|
||||||
max_writeahead = PREFSMAN->m_iSoundWriteAhead;
|
max_writeahead = PREFSMAN->m_iSoundWriteAhead;
|
||||||
|
|
||||||
pcm = new Alsa9Buf( Alsa9Buf::HW_DONT_CARE, channels );
|
pcm = new Alsa9Buf();
|
||||||
|
sError = pcm->Init( Alsa9Buf::HW_DONT_CARE, channels );
|
||||||
|
if( sError != "" )
|
||||||
|
return sError;
|
||||||
|
|
||||||
samplerate = pcm->FindSampleRate( samplerate );
|
samplerate = pcm->FindSampleRate( samplerate );
|
||||||
pcm->SetSampleRate( samplerate );
|
pcm->SetSampleRate( samplerate );
|
||||||
@@ -111,20 +118,20 @@ try {
|
|||||||
|
|
||||||
MixingThread.SetName( "RageSound_ALSA9_Software" );
|
MixingThread.SetName( "RageSound_ALSA9_Software" );
|
||||||
MixingThread.Create( MixerThread_start, this );
|
MixingThread.Create( MixerThread_start, this );
|
||||||
} catch(...) {
|
|
||||||
UnloadALSA();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound_ALSA9_Software::~RageSound_ALSA9_Software()
|
RageSound_ALSA9_Software::~RageSound_ALSA9_Software()
|
||||||
{
|
{
|
||||||
|
if( MixingThread.IsCreated() )
|
||||||
|
{
|
||||||
/* Signal the mixing thread to quit. */
|
/* Signal the mixing thread to quit. */
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
LOG->Trace("Shutting down mixer thread ...");
|
LOG->Trace("Shutting down mixer thread ...");
|
||||||
MixingThread.Wait();
|
MixingThread.Wait();
|
||||||
LOG->Trace("Mixer thread shut down.");
|
LOG->Trace("Mixer thread shut down.");
|
||||||
|
}
|
||||||
|
|
||||||
delete pcm;
|
delete pcm;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
RageSound_ALSA9_Software();
|
RageSound_ALSA9_Software();
|
||||||
|
CString Init();
|
||||||
~RageSound_ALSA9_Software();
|
~RageSound_ALSA9_Software();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user