Recommendation from Lennart Poettering: SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 19 Oct 2009 02:33:07 +0000
branchSDL-1.2
changeset 4358 df306a61a61d
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
--- a/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 19 02:23:21 2009 +0000
+++ b/src/audio/alsa/SDL_alsa_audio.c	Mon Oct 19 02:33:07 2009 +0000
@@ -59,7 +59,7 @@
 static int (*SDL_NAME(snd_pcm_open))(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode);
 static int (*SDL_NAME(snd_pcm_close))(snd_pcm_t *pcm);
 static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
-static int (*SDL_NAME(snd_pcm_resume))(snd_pcm_t *pcm);
+static int (*SDL_NAME(snd_pcm_recover))(snd_pcm_t *pcm, int err, int silent);
 static int (*SDL_NAME(snd_pcm_prepare))(snd_pcm_t *pcm);
 static int (*SDL_NAME(snd_pcm_drain))(snd_pcm_t *pcm);
 static const char *(*SDL_NAME(snd_strerror))(int errnum);
@@ -96,7 +96,7 @@
 	{ "snd_pcm_open",	(void**)(char*)&SDL_NAME(snd_pcm_open)		},
 	{ "snd_pcm_close",	(void**)(char*)&SDL_NAME(snd_pcm_close)	},
 	{ "snd_pcm_writei",	(void**)(char*)&SDL_NAME(snd_pcm_writei)	},
-	{ "snd_pcm_resume",	(void**)(char*)&SDL_NAME(snd_pcm_resume)	},
+	{ "snd_pcm_recover",	(void**)(char*)&SDL_NAME(snd_pcm_recover)	},
 	{ "snd_pcm_prepare",	(void**)(char*)&SDL_NAME(snd_pcm_prepare)	},
 	{ "snd_pcm_drain",	(void**)(char*)&SDL_NAME(snd_pcm_drain)	},
 	{ "snd_strerror",	(void**)(char*)&SDL_NAME(snd_strerror)		},
@@ -324,20 +324,7 @@
 	while ( frames_left > 0 && this->enabled ) {
 		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
 		if ( status < 0 ) {
-			if ( status == -EAGAIN ) {
-				SDL_Delay(1);
-				continue;
-			}
-			if ( status == -ESTRPIPE ) {
-				do {
-					SDL_Delay(1);
-					status = SDL_NAME(snd_pcm_resume)(pcm_handle);
-				} while ( status == -EAGAIN );
-			}
-			if ( status < 0 ) {
-				status = SDL_NAME(snd_pcm_prepare)(pcm_handle);
-			}
-			if ( status < 0 ) {
+			if ( SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0) < 0 ) {
 				/* Hmm, not much we can do - abort */
 				this->enabled = 0;
 				return;
@@ -418,7 +405,7 @@
 
 	env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
 	if ( env ) {
-		override = SDL_strol(env);
+		override = SDL_atoi(env);
 		if ( override == 0 ) {
 			return(-1);
 		}
@@ -453,7 +440,7 @@
 
 	env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
 	if ( env ) {
-		override = SDL_strol(env);
+		override = SDL_atoi(env);
 		if ( override == 0 ) {
 			return(-1);
 		}