diff --git a/include/pa_linux_alsa.h b/include/pa_linux_alsa.h index dcf011e..45b6c77 100644 --- a/include/pa_linux_alsa.h +++ b/include/pa_linux_alsa.h @@ -87,6 +87,11 @@ PaError PaAlsa_GetStreamOutputCard( PaStream *s, int *card ); */ PaError PaAlsa_SetNumPeriods( int numPeriods ); +/** Set the maximum number of times to retry opening busy device (sleeping for a + * short interval inbetween). + */ +PaError PaAlsa_SetRetriesBusy( int retries ); + #ifdef __cplusplus } #endif diff --git a/src/hostapi/alsa/pa_linux_alsa.c b/src/hostapi/alsa/pa_linux_alsa.c index 359d099..18e246e 100644 --- a/src/hostapi/alsa/pa_linux_alsa.c +++ b/src/hostapi/alsa/pa_linux_alsa.c @@ -100,6 +100,7 @@ static int aErr_; /* Used with ENSURE_ */ static int numPeriods_ = 4; +static int busyRetries_ = 100; int PaAlsa_SetNumPeriods( int numPeriods ) { @@ -539,7 +540,7 @@ static int IgnorePlugin( const char *pluginId ) **/ static int OpenPcm( snd_pcm_t **pcmp, const char *name, snd_pcm_stream_t stream, int mode, int waitOnBusy ) { - int tries = 0, maxTries = waitOnBusy ? 100 : 0; + int tries = 0, maxTries = waitOnBusy ? busyRetries_ : 0; int ret = snd_pcm_open( pcmp, name, stream, mode ); for( tries = 0; tries < maxTries && -EBUSY == ret; ++tries ) { @@ -3670,3 +3671,9 @@ PaError PaAlsa_GetStreamOutputCard(PaStream* s, int* card) { error: return result; } + +PaError PaAlsa_SetRetriesBusy( int retries ) +{ + busyRetries_ = retries; + return paNoError; +}