Mercurial > sdl-ios-xcode
comparison src/audio/pulse/SDL_pulseaudio.c @ 4398:fe15c4e8efe6 SDL-1.2
1.2: let PulseAudio hook into SDL_WM_SetCaption().
This lets Pulse's system-wide list of currently playing sources have accurate
names for SDL applications.
DO NOT MERGE WITH 1.3...we'll design a more formal API there.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 24 Jan 2010 08:35:09 +0000 |
parents | f5d3f7fa071d |
children | 9134017bac3a |
comparison
equal
deleted
inserted
replaced
4397:fb1fc6c9289e | 4398:fe15c4e8efe6 |
---|---|
54 static void PULSE_WaitAudio(_THIS); | 54 static void PULSE_WaitAudio(_THIS); |
55 static void PULSE_PlayAudio(_THIS); | 55 static void PULSE_PlayAudio(_THIS); |
56 static Uint8 *PULSE_GetAudioBuf(_THIS); | 56 static Uint8 *PULSE_GetAudioBuf(_THIS); |
57 static void PULSE_CloseAudio(_THIS); | 57 static void PULSE_CloseAudio(_THIS); |
58 static void PULSE_WaitDone(_THIS); | 58 static void PULSE_WaitDone(_THIS); |
59 static void PULSE_SetCaption(_THIS, const char *str); | |
59 | 60 |
60 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC | 61 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC |
61 | 62 |
62 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSE_DYNAMIC; | 63 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSE_DYNAMIC; |
63 static void *pulse_handle = NULL; | 64 static void *pulse_handle = NULL; |
111 pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek); | 112 pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek); |
112 static pa_operation * (*SDL_NAME(pa_stream_drain))(pa_stream *s, | 113 static pa_operation * (*SDL_NAME(pa_stream_drain))(pa_stream *s, |
113 pa_stream_success_cb_t cb, void *userdata); | 114 pa_stream_success_cb_t cb, void *userdata); |
114 static int (*SDL_NAME(pa_stream_disconnect))(pa_stream *s); | 115 static int (*SDL_NAME(pa_stream_disconnect))(pa_stream *s); |
115 static void (*SDL_NAME(pa_stream_unref))(pa_stream *s); | 116 static void (*SDL_NAME(pa_stream_unref))(pa_stream *s); |
117 static pa_operation* (*SDL_NAME(pa_context_set_name))(pa_context *c, | |
118 const char *name, pa_context_success_cb_t cb, void *userdata); | |
116 | 119 |
117 static struct { | 120 static struct { |
118 const char *name; | 121 const char *name; |
119 void **func; | 122 void **func; |
120 } pulse_functions[] = { | 123 } pulse_functions[] = { |
162 (void **)&SDL_NAME(pa_stream_drain) }, | 165 (void **)&SDL_NAME(pa_stream_drain) }, |
163 { "pa_stream_disconnect", | 166 { "pa_stream_disconnect", |
164 (void **)&SDL_NAME(pa_stream_disconnect) }, | 167 (void **)&SDL_NAME(pa_stream_disconnect) }, |
165 { "pa_stream_unref", | 168 { "pa_stream_unref", |
166 (void **)&SDL_NAME(pa_stream_unref) }, | 169 (void **)&SDL_NAME(pa_stream_unref) }, |
170 { "pa_context_set_name", | |
171 (void **)&SDL_NAME(pa_context_set_name) }, | |
167 }; | 172 }; |
168 | 173 |
169 static void UnloadPulseLibrary() | 174 static void UnloadPulseLibrary() |
170 { | 175 { |
171 if ( pulse_loaded ) { | 176 if ( pulse_loaded ) { |
246 return(available); | 251 return(available); |
247 } | 252 } |
248 | 253 |
249 static void Audio_DeleteDevice(SDL_AudioDevice *device) | 254 static void Audio_DeleteDevice(SDL_AudioDevice *device) |
250 { | 255 { |
256 SDL_free(device->hidden->caption); | |
251 SDL_free(device->hidden); | 257 SDL_free(device->hidden); |
252 SDL_free(device); | 258 SDL_free(device); |
253 UnloadPulseLibrary(); | 259 UnloadPulseLibrary(); |
254 } | 260 } |
255 | 261 |
279 this->WaitAudio = PULSE_WaitAudio; | 285 this->WaitAudio = PULSE_WaitAudio; |
280 this->PlayAudio = PULSE_PlayAudio; | 286 this->PlayAudio = PULSE_PlayAudio; |
281 this->GetAudioBuf = PULSE_GetAudioBuf; | 287 this->GetAudioBuf = PULSE_GetAudioBuf; |
282 this->CloseAudio = PULSE_CloseAudio; | 288 this->CloseAudio = PULSE_CloseAudio; |
283 this->WaitDone = PULSE_WaitDone; | 289 this->WaitDone = PULSE_WaitDone; |
290 this->SetCaption = PULSE_SetCaption; | |
284 | 291 |
285 this->free = Audio_DeleteDevice; | 292 this->free = Audio_DeleteDevice; |
286 | 293 |
287 return this; | 294 return this; |
288 } | 295 } |
370 #else | 377 #else |
371 return("unknown"); | 378 return("unknown"); |
372 #endif | 379 #endif |
373 } | 380 } |
374 | 381 |
375 static void stream_drain_complete(pa_stream *s, int success, void *userdata) { | 382 static void caption_set_complete(pa_context *c, int success, void *userdata) |
383 { | |
384 /* no-op. */ | |
385 } | |
386 | |
387 static void PULSE_SetCaption(_THIS, const char *str) | |
388 { | |
389 SDL_free(this->hidden->caption); | |
390 if ((str == NULL) || (*str == '\0')) { | |
391 str = get_progname(); /* set a default so SOMETHING shows up. */ | |
392 } | |
393 this->hidden->caption = SDL_strdup(str); | |
394 if (context != NULL) { | |
395 SDL_NAME(pa_context_set_name)(context, this->hidden->caption, | |
396 caption_set_complete, 0); | |
397 } | |
398 } | |
399 | |
400 static void stream_drain_complete(pa_stream *s, int success, void *userdata) | |
401 { | |
402 /* no-op. */ | |
376 } | 403 } |
377 | 404 |
378 static void PULSE_WaitDone(_THIS) | 405 static void PULSE_WaitDone(_THIS) |
379 { | 406 { |
380 pa_operation *o; | 407 pa_operation *o; |
467 PULSE_CloseAudio(this); | 494 PULSE_CloseAudio(this); |
468 SDL_SetError("pa_mainloop_new() failed"); | 495 SDL_SetError("pa_mainloop_new() failed"); |
469 return(-1); | 496 return(-1); |
470 } | 497 } |
471 | 498 |
499 if (this->hidden->caption == NULL) { | |
500 this->hidden->caption = SDL_strdup(get_progname()); | |
501 } | |
502 | |
472 mainloop_api = SDL_NAME(pa_mainloop_get_api)(mainloop); | 503 mainloop_api = SDL_NAME(pa_mainloop_get_api)(mainloop); |
473 if (!(context = SDL_NAME(pa_context_new)(mainloop_api, get_progname()))) { | 504 if (!(context = SDL_NAME(pa_context_new)(mainloop_api, |
505 this->hidden->caption))) { | |
474 PULSE_CloseAudio(this); | 506 PULSE_CloseAudio(this); |
475 SDL_SetError("pa_context_new() failed"); | 507 SDL_SetError("pa_context_new() failed"); |
476 return(-1); | 508 return(-1); |
477 } | 509 } |
478 | 510 |
479 /* Connect to the PulseAudio server */ | 511 /* Connect to the PulseAudio server */ |
480 if (SDL_NAME(pa_context_connect)(context, NULL, 0, NULL) < 0) { | 512 if (SDL_NAME(pa_context_connect)(context, NULL, 0, NULL) < 0) { |
481 PULSE_CloseAudio(this); | 513 PULSE_CloseAudio(this); |
482 SDL_SetError("Could not setup connection to PulseAudio"); | 514 SDL_SetError("Could not setup connection to PulseAudio"); |
483 return(-1); | 515 return(-1); |
484 } | 516 } |
485 | 517 |
486 do { | 518 do { |
487 if (SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { | 519 if (SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { |