Mercurial > sdl-ios-xcode
comparison src/audio/alsa/SDL_alsa_audio.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device
Removed distinction between "available" and "init" in audio backends, since
both had to be checked for success as a pair at the higher level and several
of the Available methods were just always-succeed placeholders anyhow. Now
the availability check is done in the init code, and the higher level tries
all possible drivers until one manages to initialize successfully.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 17 Oct 2006 09:09:21 +0000 |
parents | ee5dfa7f7993 |
children |
comparison
equal
deleted
inserted
replaced
3845:ee5dfa7f7993 | 3846:66fb40445587 |
---|---|
149 } | 149 } |
150 #undef SDL_ALSA_SYM | 150 #undef SDL_ALSA_SYM |
151 | 151 |
152 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC | 152 #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC |
153 | 153 |
154 static int library_load_count = 0; | |
155 | |
156 static void | 154 static void |
157 UnloadALSALibrary(void) | 155 UnloadALSALibrary(void) |
158 { | 156 { |
159 if ((alsa_handle != NULL) && (--library_load_count == 0)) { | 157 if (alsa_handle != NULL) { |
160 dlclose(alsa_handle); | 158 dlclose(alsa_handle); |
161 alsa_handle = NULL; | 159 alsa_handle = NULL; |
162 } | 160 } |
163 } | 161 } |
164 | 162 |
165 static int | 163 static int |
166 LoadALSALibrary(void) | 164 LoadALSALibrary(void) |
167 { | 165 { |
168 int retval = 0; | 166 int retval = 0; |
169 if (library_load_count++ == 0) { | 167 if (alsa_handle == NULL) { |
170 alsa_handle = dlopen(alsa_library, RTLD_NOW); | 168 alsa_handle = dlopen(alsa_library, RTLD_NOW); |
171 if (alsa_handle == NULL) { | 169 if (alsa_handle == NULL) { |
172 library_load_count--; | |
173 retval = -1; | 170 retval = -1; |
174 SDL_SetError("ALSA: dlopen('%s') failed: %s\n", | 171 SDL_SetError("ALSA: dlopen('%s') failed: %s\n", |
175 alsa_library, strerror(errno)); | 172 alsa_library, strerror(errno)); |
176 } else { | 173 } else { |
177 retval = load_alsa_syms(); | 174 retval = load_alsa_syms(); |
213 else | 210 else |
214 device = DEFAULT_DEVICE; | 211 device = DEFAULT_DEVICE; |
215 } | 212 } |
216 return device; | 213 return device; |
217 } | 214 } |
218 | |
219 | |
220 static int | |
221 ALSA_Available(void) | |
222 { | |
223 int available = 0; | |
224 | |
225 if (LoadALSALibrary() >= 0) { | |
226 available = 1; | |
227 UnloadALSALibrary(); | |
228 } | |
229 return (available); | |
230 } | |
231 | |
232 | 215 |
233 | 216 |
234 /* This function waits until it is possible to write a full sound buffer */ | 217 /* This function waits until it is possible to write a full sound buffer */ |
235 static void | 218 static void |
236 ALSA_WaitDevice(_THIS) | 219 ALSA_WaitDevice(_THIS) |
375 ALSA_snd_pcm_close(this->hidden->pcm_handle); | 358 ALSA_snd_pcm_close(this->hidden->pcm_handle); |
376 this->hidden->pcm_handle = NULL; | 359 this->hidden->pcm_handle = NULL; |
377 } | 360 } |
378 SDL_free(this->hidden); | 361 SDL_free(this->hidden); |
379 this->hidden = NULL; | 362 this->hidden = NULL; |
380 UnloadALSALibrary(); | |
381 } | 363 } |
382 } | 364 } |
383 | 365 |
384 static int | 366 static int |
385 ALSA_OpenDevice(_THIS, const char *devname, int iscapture) | 367 ALSA_OpenDevice(_THIS, const char *devname, int iscapture) |
398 if (this->hidden == NULL) { | 380 if (this->hidden == NULL) { |
399 SDL_OutOfMemory(); | 381 SDL_OutOfMemory(); |
400 return 0; | 382 return 0; |
401 } | 383 } |
402 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 384 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
403 | |
404 if (LoadALSALibrary() < 0) { | |
405 ALSA_CloseDevice(this); | |
406 return 0; | |
407 } | |
408 | 385 |
409 /* Open the audio device */ | 386 /* Open the audio device */ |
410 /* Name of device should depend on # channels in spec */ | 387 /* Name of device should depend on # channels in spec */ |
411 status = ALSA_snd_pcm_open(&pcm_handle, | 388 status = ALSA_snd_pcm_open(&pcm_handle, |
412 get_audio_device(this->spec.channels), | 389 get_audio_device(this->spec.channels), |
597 | 574 |
598 /* We're ready to rock and roll. :-) */ | 575 /* We're ready to rock and roll. :-) */ |
599 return 1; | 576 return 1; |
600 } | 577 } |
601 | 578 |
579 static void | |
580 ALSA_Deinitialize(void) | |
581 { | |
582 UnloadALSALibrary(); | |
583 } | |
584 | |
602 static int | 585 static int |
603 ALSA_Init(SDL_AudioDriverImpl *impl) | 586 ALSA_Init(SDL_AudioDriverImpl *impl) |
604 { | 587 { |
588 if (LoadALSALibrary() < 0) { | |
589 return 0; | |
590 } | |
591 | |
605 /* Set the function pointers */ | 592 /* Set the function pointers */ |
606 impl->OpenDevice = ALSA_OpenDevice; | 593 impl->OpenDevice = ALSA_OpenDevice; |
607 impl->WaitDevice = ALSA_WaitDevice; | 594 impl->WaitDevice = ALSA_WaitDevice; |
608 impl->GetDeviceBuf = ALSA_GetDeviceBuf; | 595 impl->GetDeviceBuf = ALSA_GetDeviceBuf; |
609 impl->PlayDevice = ALSA_PlayDevice; | 596 impl->PlayDevice = ALSA_PlayDevice; |
610 impl->CloseDevice = ALSA_CloseDevice; | 597 impl->CloseDevice = ALSA_CloseDevice; |
598 impl->Deinitialize = ALSA_Deinitialize; | |
611 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */ | 599 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */ |
612 | 600 |
613 return 1; | 601 return 1; |
614 } | 602 } |
615 | 603 |
616 | 604 |
617 AudioBootStrap ALSA_bootstrap = { | 605 AudioBootStrap ALSA_bootstrap = { |
618 DRIVER_NAME, "ALSA 0.9 PCM audio", | 606 DRIVER_NAME, "ALSA 0.9 PCM audio", ALSA_Init, 0 |
619 ALSA_Available, ALSA_Init, 0 | |
620 }; | 607 }; |
621 | 608 |
622 /* vi: set ts=4 sw=4 expandtab: */ | 609 /* vi: set ts=4 sw=4 expandtab: */ |