From 1f1664a9d0dd6f68be97a890bcddfc8157d00dd5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 24 Jan 2010 08:35:09 +0000 Subject: [PATCH] 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. --- src/audio/SDL_audio.c | 8 +++++++ src/audio/SDL_audio_c.h | 1 + src/audio/SDL_sysaudio.h | 2 ++ src/audio/pulse/SDL_pulseaudio.c | 38 +++++++++++++++++++++++++++++--- src/audio/pulse/SDL_pulseaudio.h | 2 ++ src/video/SDL_video.c | 5 +++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index bdeacdc4e..dc2ebd71d 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -693,3 +693,11 @@ void SDL_CalculateAudioSpec(SDL_AudioSpec *spec) spec->size *= spec->channels; spec->size *= spec->samples; } + +void SDL_Audio_SetCaption(const char *caption) +{ + if ((current_audio) && (current_audio->SetCaption)) { + current_audio->SetCaption(current_audio, caption); + } +} + diff --git a/src/audio/SDL_audio_c.h b/src/audio/SDL_audio_c.h index 3a5c10259..4c2c64eb5 100644 --- a/src/audio/SDL_audio_c.h +++ b/src/audio/SDL_audio_c.h @@ -32,3 +32,4 @@ extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec); /* The actual mixing thread function */ extern int SDLCALL SDL_RunAudio(void *audiop); + diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 50cf17985..99eb1f254 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -59,6 +59,8 @@ struct SDL_AudioDevice { void (*LockAudio)(_THIS); void (*UnlockAudio)(_THIS); + void (*SetCaption)(_THIS, const char *caption); + /* * * */ /* Data common to all devices */ diff --git a/src/audio/pulse/SDL_pulseaudio.c b/src/audio/pulse/SDL_pulseaudio.c index 5ce558cf4..98c4a5090 100644 --- a/src/audio/pulse/SDL_pulseaudio.c +++ b/src/audio/pulse/SDL_pulseaudio.c @@ -56,6 +56,7 @@ static void PULSE_PlayAudio(_THIS); static Uint8 *PULSE_GetAudioBuf(_THIS); static void PULSE_CloseAudio(_THIS); static void PULSE_WaitDone(_THIS); +static void PULSE_SetCaption(_THIS, const char *str); #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC @@ -113,6 +114,8 @@ static pa_operation * (*SDL_NAME(pa_stream_drain))(pa_stream *s, pa_stream_success_cb_t cb, void *userdata); static int (*SDL_NAME(pa_stream_disconnect))(pa_stream *s); static void (*SDL_NAME(pa_stream_unref))(pa_stream *s); +static pa_operation* (*SDL_NAME(pa_context_set_name))(pa_context *c, + const char *name, pa_context_success_cb_t cb, void *userdata); static struct { const char *name; @@ -164,6 +167,8 @@ static struct { (void **)&SDL_NAME(pa_stream_disconnect) }, { "pa_stream_unref", (void **)&SDL_NAME(pa_stream_unref) }, + { "pa_context_set_name", + (void **)&SDL_NAME(pa_context_set_name) }, }; static void UnloadPulseLibrary() @@ -248,6 +253,7 @@ static int Audio_Available(void) static void Audio_DeleteDevice(SDL_AudioDevice *device) { + SDL_free(device->hidden->caption); SDL_free(device->hidden); SDL_free(device); UnloadPulseLibrary(); @@ -281,6 +287,7 @@ static SDL_AudioDevice *Audio_CreateDevice(int devindex) this->GetAudioBuf = PULSE_GetAudioBuf; this->CloseAudio = PULSE_CloseAudio; this->WaitDone = PULSE_WaitDone; + this->SetCaption = PULSE_SetCaption; this->free = Audio_DeleteDevice; @@ -372,7 +379,27 @@ static char *get_progname(void) #endif } -static void stream_drain_complete(pa_stream *s, int success, void *userdata) { +static void caption_set_complete(pa_context *c, int success, void *userdata) +{ + /* no-op. */ +} + +static void PULSE_SetCaption(_THIS, const char *str) +{ + SDL_free(this->hidden->caption); + if ((str == NULL) || (*str == '\0')) { + str = get_progname(); /* set a default so SOMETHING shows up. */ + } + this->hidden->caption = SDL_strdup(str); + if (context != NULL) { + SDL_NAME(pa_context_set_name)(context, this->hidden->caption, + caption_set_complete, 0); + } +} + +static void stream_drain_complete(pa_stream *s, int success, void *userdata) +{ + /* no-op. */ } static void PULSE_WaitDone(_THIS) @@ -469,8 +496,13 @@ static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec) return(-1); } + if (this->hidden->caption == NULL) { + this->hidden->caption = SDL_strdup(get_progname()); + } + mainloop_api = SDL_NAME(pa_mainloop_get_api)(mainloop); - if (!(context = SDL_NAME(pa_context_new)(mainloop_api, get_progname()))) { + if (!(context = SDL_NAME(pa_context_new)(mainloop_api, + this->hidden->caption))) { PULSE_CloseAudio(this); SDL_SetError("pa_context_new() failed"); return(-1); @@ -479,7 +511,7 @@ static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec) /* Connect to the PulseAudio server */ if (SDL_NAME(pa_context_connect)(context, NULL, 0, NULL) < 0) { PULSE_CloseAudio(this); - SDL_SetError("Could not setup connection to PulseAudio"); + SDL_SetError("Could not setup connection to PulseAudio"); return(-1); } diff --git a/src/audio/pulse/SDL_pulseaudio.h b/src/audio/pulse/SDL_pulseaudio.h index 27d27c6bf..98e807dad 100644 --- a/src/audio/pulse/SDL_pulseaudio.h +++ b/src/audio/pulse/SDL_pulseaudio.h @@ -37,6 +37,8 @@ struct SDL_PrivateAudioData { pa_context *context; pa_stream *stream; + char *caption; + /* Raw mixing buffer */ Uint8 *mixbuf; int mixlen; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index e84ef358f..cd5b1fdd2 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1701,7 +1701,12 @@ void SDL_WM_SetCaption (const char *title, const char *icon) video->SetCaption(this, video->wm_title,video->wm_icon); } } + + /* PulseAudio can make use of this information. */ + extern void SDL_Audio_SetCaption(const char *caption); + SDL_Audio_SetCaption(title); } + void SDL_WM_GetCaption (char **title, char **icon) { SDL_VideoDevice *video = current_video;