log ALSA errors

This commit is contained in:
Glenn Maynard
2004-04-03 20:55:50 +00:00
parent 8eb42b9094
commit 0565b31705
2 changed files with 27 additions and 6 deletions
+26 -6
View File
@@ -118,6 +118,27 @@ bool Alsa9Buf::SetSWParams()
return true;
}
void Alsa9Buf::ErrorHandler(const char *file, int line, const char *function, int err, const char *fmt, ...)
{
va_list va;
va_start( va, fmt );
CString str = vssprintf(fmt, va);
va_end( va );
if( err )
str += ssprintf( " (%s)", dsnd_strerror(err) );
/* Annoying: these happen both normally (eg. "out of memory" when allocating too many PCM
* slots) and abnormally, and there's no way to tell which is which. I don't want to
* pollute the warning output. */
LOG->Trace( "ALSA error: %s:%i %s: %s", file, line, function, str.c_str() );
}
void Alsa9Buf::InitializeErrorHandler()
{
dsnd_lib_error_set_handler( ErrorHandler );
}
void Alsa9Buf::GetSoundCardDebugInfo()
{
static bool done = false;
@@ -125,6 +146,8 @@ void Alsa9Buf::GetSoundCardDebugInfo()
return;
done = true;
InitializeErrorHandler();
if( DoesFileExist("/proc/asound/version") )
{
const CString ver = GetRedirContents("/proc/asound/version");
@@ -184,18 +207,13 @@ void Alsa9Buf::GetSoundCardDebugInfo()
LOG->Info( "No ALSA sound cards were found.");
}
void Alsa9Buf::ErrorHandler(const char *file, int line, const char *function, int err, const char *fmt, ...)
{
/* NOP */
}
static CString DeviceName = "hw:0";
Alsa9Buf::Alsa9Buf( hw hardware, int channels_ )
{
GetSoundCardDebugInfo();
dsnd_lib_error_set_handler( ErrorHandler );
InitializeErrorHandler();
channels = channels_;
samplerate = 44100;
@@ -390,6 +408,8 @@ void Alsa9Buf::SetSampleRate(int hz)
CString Alsa9Buf::GetHardwareID( CString name )
{
InitializeErrorHandler();
if( name.empty() )
name = DeviceName;
+1
View File
@@ -27,6 +27,7 @@ private:
static void ErrorHandler(const char *file, int line, const char *function, int err, const char *fmt, ...);
public:
static void InitializeErrorHandler();
static void GetSoundCardDebugInfo();
static CString GetHardwareID( CString name="" );