comparison src/audio/alsa/SDL_alsa_audio.c @ 4358:df306a61a61d SDL-1.2

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.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 19 Oct 2009 02:33:07 +0000
parents a10dac5858fe
children 4b582c04ec1d
comparison
equal deleted inserted replaced
4357:a10dac5858fe 4358:df306a61a61d
57 static int alsa_loaded = 0; 57 static int alsa_loaded = 0;
58 58
59 static int (*SDL_NAME(snd_pcm_open))(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode); 59 static int (*SDL_NAME(snd_pcm_open))(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode);
60 static int (*SDL_NAME(snd_pcm_close))(snd_pcm_t *pcm); 60 static int (*SDL_NAME(snd_pcm_close))(snd_pcm_t *pcm);
61 static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); 61 static snd_pcm_sframes_t (*SDL_NAME(snd_pcm_writei))(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
62 static int (*SDL_NAME(snd_pcm_resume))(snd_pcm_t *pcm); 62 static int (*SDL_NAME(snd_pcm_recover))(snd_pcm_t *pcm, int err, int silent);
63 static int (*SDL_NAME(snd_pcm_prepare))(snd_pcm_t *pcm); 63 static int (*SDL_NAME(snd_pcm_prepare))(snd_pcm_t *pcm);
64 static int (*SDL_NAME(snd_pcm_drain))(snd_pcm_t *pcm); 64 static int (*SDL_NAME(snd_pcm_drain))(snd_pcm_t *pcm);
65 static const char *(*SDL_NAME(snd_strerror))(int errnum); 65 static const char *(*SDL_NAME(snd_strerror))(int errnum);
66 static size_t (*SDL_NAME(snd_pcm_hw_params_sizeof))(void); 66 static size_t (*SDL_NAME(snd_pcm_hw_params_sizeof))(void);
67 static size_t (*SDL_NAME(snd_pcm_sw_params_sizeof))(void); 67 static size_t (*SDL_NAME(snd_pcm_sw_params_sizeof))(void);
94 void **func; 94 void **func;
95 } alsa_functions[] = { 95 } alsa_functions[] = {
96 { "snd_pcm_open", (void**)(char*)&SDL_NAME(snd_pcm_open) }, 96 { "snd_pcm_open", (void**)(char*)&SDL_NAME(snd_pcm_open) },
97 { "snd_pcm_close", (void**)(char*)&SDL_NAME(snd_pcm_close) }, 97 { "snd_pcm_close", (void**)(char*)&SDL_NAME(snd_pcm_close) },
98 { "snd_pcm_writei", (void**)(char*)&SDL_NAME(snd_pcm_writei) }, 98 { "snd_pcm_writei", (void**)(char*)&SDL_NAME(snd_pcm_writei) },
99 { "snd_pcm_resume", (void**)(char*)&SDL_NAME(snd_pcm_resume) }, 99 { "snd_pcm_recover", (void**)(char*)&SDL_NAME(snd_pcm_recover) },
100 { "snd_pcm_prepare", (void**)(char*)&SDL_NAME(snd_pcm_prepare) }, 100 { "snd_pcm_prepare", (void**)(char*)&SDL_NAME(snd_pcm_prepare) },
101 { "snd_pcm_drain", (void**)(char*)&SDL_NAME(snd_pcm_drain) }, 101 { "snd_pcm_drain", (void**)(char*)&SDL_NAME(snd_pcm_drain) },
102 { "snd_strerror", (void**)(char*)&SDL_NAME(snd_strerror) }, 102 { "snd_strerror", (void**)(char*)&SDL_NAME(snd_strerror) },
103 { "snd_pcm_hw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_sizeof) }, 103 { "snd_pcm_hw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_hw_params_sizeof) },
104 { "snd_pcm_sw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_sizeof) }, 104 { "snd_pcm_sw_params_sizeof", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_sizeof) },
322 frames_left = ((snd_pcm_uframes_t) this->spec.samples); 322 frames_left = ((snd_pcm_uframes_t) this->spec.samples);
323 323
324 while ( frames_left > 0 && this->enabled ) { 324 while ( frames_left > 0 && this->enabled ) {
325 status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left); 325 status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
326 if ( status < 0 ) { 326 if ( status < 0 ) {
327 if ( status == -EAGAIN ) { 327 if ( SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0) < 0 ) {
328 SDL_Delay(1);
329 continue;
330 }
331 if ( status == -ESTRPIPE ) {
332 do {
333 SDL_Delay(1);
334 status = SDL_NAME(snd_pcm_resume)(pcm_handle);
335 } while ( status == -EAGAIN );
336 }
337 if ( status < 0 ) {
338 status = SDL_NAME(snd_pcm_prepare)(pcm_handle);
339 }
340 if ( status < 0 ) {
341 /* Hmm, not much we can do - abort */ 328 /* Hmm, not much we can do - abort */
342 this->enabled = 0; 329 this->enabled = 0;
343 return; 330 return;
344 } 331 }
345 continue; 332 continue;
416 snd_pcm_hw_params_alloca(&hwparams); 403 snd_pcm_hw_params_alloca(&hwparams);
417 SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params); 404 SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params);
418 405
419 env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE"); 406 env = getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
420 if ( env ) { 407 if ( env ) {
421 override = SDL_strol(env); 408 override = SDL_atoi(env);
422 if ( override == 0 ) { 409 if ( override == 0 ) {
423 return(-1); 410 return(-1);
424 } 411 }
425 } 412 }
426 413
451 snd_pcm_hw_params_alloca(&hwparams); 438 snd_pcm_hw_params_alloca(&hwparams);
452 SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params); 439 SDL_NAME(snd_pcm_hw_params_copy)(hwparams, params);
453 440
454 env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE"); 441 env = getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
455 if ( env ) { 442 if ( env ) {
456 override = SDL_strol(env); 443 override = SDL_atoi(env);
457 if ( override == 0 ) { 444 if ( override == 0 ) {
458 return(-1); 445 return(-1);
459 } 446 }
460 } 447 }
461 448