Recommendation from Lennart Poettering: SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 19 Oct 2009 02:33:07 +0000
branchSDL-1.2
changeset 4358df306a61a61d
parent 4357 a10dac5858fe
child 4359 4b582c04ec1d
Recommendation from Lennart Poettering:

In ALSA_PlayAudio() it is a good idea to use snd_pcm_recover() instead
of checking for the error codes yourself.
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 19 02:23:21 2009 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 19 02:33:07 2009 +0000
     1.3 @@ -59,7 +59,7 @@
     1.4  static int (*SDL_NAME(snd_pcm_open))(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode);
     1.5  static int (*SDL_NAME(snd_pcm_close))(snd_pcm_t *pcm);
     1.6  static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
     1.7 -static int (*SDL_NAME(snd_pcm_resume))(snd_pcm_t *pcm);
     1.8 +static int (*SDL_NAME(snd_pcm_recover))(snd_pcm_t *pcm, int err, int silent);
     1.9  static int (*SDL_NAME(snd_pcm_prepare))(snd_pcm_t *pcm);
    1.10  static int (*SDL_NAME(snd_pcm_drain))(snd_pcm_t *pcm);
    1.11  static const char *(*SDL_NAME(snd_strerror))(int errnum);
    1.12 @@ -96,7 +96,7 @@
    1.13  	{ "snd_pcm_open",	(void**)(char*)&SDL_NAME(snd_pcm_open)		},
    1.14  	{ "snd_pcm_close",	(void**)(char*)&SDL_NAME(snd_pcm_close)	},
    1.15  	{ "snd_pcm_writei",	(void**)(char*)&SDL_NAME(snd_pcm_writei)	},
    1.16 -	{ "snd_pcm_resume",	(void**)(char*)&SDL_NAME(snd_pcm_resume)	},
    1.17 +	{ "snd_pcm_recover",	(void**)(char*)&SDL_NAME(snd_pcm_recover)	},
    1.18  	{ "snd_pcm_prepare",	(void**)(char*)&SDL_NAME(snd_pcm_prepare)	},
    1.19  	{ "snd_pcm_drain",	(void**)(char*)&SDL_NAME(snd_pcm_drain)	},
    1.20  	{ "snd_strerror",	(void**)(char*)&SDL_NAME(snd_strerror)		},
    1.21 @@ -324,20 +324,7 @@
    1.22  	while ( frames_left > 0 && this->enabled ) {
    1.23  		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
    1.24  		if ( status < 0 ) {
    1.25 -			if ( status == -EAGAIN ) {
    1.26 -				SDL_Delay(1);
    1.27 -				continue;
    1.28 -			}
    1.29 -			if ( status == -ESTRPIPE ) {
    1.30 -				do {
    1.31 -					SDL_Delay(1);
    1.32 -					status = SDL_NAME(snd_pcm_resume)(pcm_handle);
    1.33 -				} while ( status == -EAGAIN );
    1.34 -			}
    1.35 -			if ( status < 0 ) {
    1.36 -				status = SDL_NAME(snd_pcm_prepare)(pcm_handle);
    1.37 -			}
    1.38 -			if ( status < 0 ) {
    1.39 +			if ( SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0) < 0 ) {
    1.40  				/* Hmm, not much we can do - abort */
    1.41  				this->enabled = 0;
    1.42  				return;
    1.43 @@ -418,7 +405,7 @@
    1.44  
    1.45  	env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
    1.46  	if ( env ) {
    1.47 -		override = SDL_strol(env);
    1.48 +		override = SDL_atoi(env);
    1.49  		if ( override == 0 ) {
    1.50  			return(-1);
    1.51  		}
    1.52 @@ -453,7 +440,7 @@
    1.53  
    1.54  	env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
    1.55  	if ( env ) {
    1.56 -		override = SDL_strol(env);
    1.57 +		override = SDL_atoi(env);
    1.58  		if ( override == 0 ) {
    1.59  			return(-1);
    1.60  		}