From 0565b31705e8044fa19fb749a5d58a2ed976547d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 3 Apr 2004 20:55:50 +0000 Subject: [PATCH] log ALSA errors --- stepmania/src/arch/Sound/ALSA9Helpers.cpp | 32 ++++++++++++++++++----- stepmania/src/arch/Sound/ALSA9Helpers.h | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.cpp b/stepmania/src/arch/Sound/ALSA9Helpers.cpp index 3f1f3d1714..c1634e2420 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.cpp +++ b/stepmania/src/arch/Sound/ALSA9Helpers.cpp @@ -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; diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.h b/stepmania/src/arch/Sound/ALSA9Helpers.h index d17129fd4b..aab02b8cb9 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.h +++ b/stepmania/src/arch/Sound/ALSA9Helpers.h @@ -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="" );