comparison src/audio/alsa/SDL_alsa_audio.c @ 4363:028d26915548 SDL-1.2

Added an untested code path for snd_pcm_wait()
author Sam Lantinga <slouken@libsdl.org>
date Mon, 19 Oct 2009 05:59:07 +0000
parents e48a66bed093
children ae3d564e2716
comparison
equal deleted inserted replaced
4362:e48a66bed093 4363:028d26915548
83 */ 83 */
84 static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams); 84 static int (*SDL_NAME(snd_pcm_sw_params_current))(snd_pcm_t *pcm, snd_pcm_sw_params_t *swparams);
85 static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val); 85 static int (*SDL_NAME(snd_pcm_sw_params_set_start_threshold))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
86 static int (*SDL_NAME(snd_pcm_sw_params))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params); 86 static int (*SDL_NAME(snd_pcm_sw_params))(snd_pcm_t *pcm, snd_pcm_sw_params_t *params);
87 static int (*SDL_NAME(snd_pcm_nonblock))(snd_pcm_t *pcm, int nonblock); 87 static int (*SDL_NAME(snd_pcm_nonblock))(snd_pcm_t *pcm, int nonblock);
88 static int (*SDL_NAME(snd_pcm_wait))(snd_pcm_t *pcm, int timeout);
88 #define snd_pcm_hw_params_sizeof SDL_NAME(snd_pcm_hw_params_sizeof) 89 #define snd_pcm_hw_params_sizeof SDL_NAME(snd_pcm_hw_params_sizeof)
89 #define snd_pcm_sw_params_sizeof SDL_NAME(snd_pcm_sw_params_sizeof) 90 #define snd_pcm_sw_params_sizeof SDL_NAME(snd_pcm_sw_params_sizeof)
90 91
91 /* cast funcs to char* first, to please GCC's strict aliasing rules. */ 92 /* cast funcs to char* first, to please GCC's strict aliasing rules. */
92 static struct { 93 static struct {
118 { "snd_pcm_hw_params", (void**)(char*)&SDL_NAME(snd_pcm_hw_params) }, 119 { "snd_pcm_hw_params", (void**)(char*)&SDL_NAME(snd_pcm_hw_params) },
119 { "snd_pcm_sw_params_current", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_current) }, 120 { "snd_pcm_sw_params_current", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_current) },
120 { "snd_pcm_sw_params_set_start_threshold", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold) }, 121 { "snd_pcm_sw_params_set_start_threshold", (void**)(char*)&SDL_NAME(snd_pcm_sw_params_set_start_threshold) },
121 { "snd_pcm_sw_params", (void**)(char*)&SDL_NAME(snd_pcm_sw_params) }, 122 { "snd_pcm_sw_params", (void**)(char*)&SDL_NAME(snd_pcm_sw_params) },
122 { "snd_pcm_nonblock", (void**)(char*)&SDL_NAME(snd_pcm_nonblock) }, 123 { "snd_pcm_nonblock", (void**)(char*)&SDL_NAME(snd_pcm_nonblock) },
124 { "snd_pcm_wait", (void**)(char*)&SDL_NAME(snd_pcm_wait) },
123 }; 125 };
124 126
125 static void UnloadALSALibrary(void) { 127 static void UnloadALSALibrary(void) {
126 if (alsa_loaded) { 128 if (alsa_loaded) {
127 SDL_UnloadObject(alsa_handle); 129 SDL_UnloadObject(alsa_handle);
310 swizzle_alsa_channels(this); 312 swizzle_alsa_channels(this);
311 313
312 frames_left = ((snd_pcm_uframes_t) this->spec.samples); 314 frames_left = ((snd_pcm_uframes_t) this->spec.samples);
313 315
314 while ( frames_left > 0 && this->enabled ) { 316 while ( frames_left > 0 && this->enabled ) {
317 /* This works, but needs more testing before going live */
318 /*SDL_NAME(snd_pcm_wait)(pcm_handle, -1);*/
319
315 status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left); 320 status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, frames_left);
316 if ( status < 0 ) { 321 if ( status < 0 ) {
317 if ( status == -EAGAIN ) { 322 if ( status == -EAGAIN ) {
318 /* Apparently snd_pcm_recover() doesn't handle this. Foo. */ 323 /* Apparently snd_pcm_recover() doesn't handle this case - does it assume snd_pcm_wait() above? */
319 SDL_Delay(1); 324 SDL_Delay(1);
320 continue; 325 continue;
321 } 326 }
322 status = SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0); 327 status = SDL_NAME(snd_pcm_recover)(pcm_handle, status, 0);
323 if ( status < 0 ) { 328 if ( status < 0 ) {