changeset 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 fb1fc6c9289e
children ae9c094e9200
files src/audio/SDL_audio.c src/audio/SDL_audio_c.h src/audio/SDL_sysaudio.h src/audio/pulse/SDL_pulseaudio.c src/audio/pulse/SDL_pulseaudio.h src/video/SDL_video.c
diffstat 6 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/audio/SDL_audio.c	Sun Jan 17 05:19:32 2010 +0000
+++ b/src/audio/SDL_audio.c	Sun Jan 24 08:35:09 2010 +0000
@@ -693,3 +693,11 @@
 	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);
+	}
+}
+
--- a/src/audio/SDL_audio_c.h	Sun Jan 17 05:19:32 2010 +0000
+++ b/src/audio/SDL_audio_c.h	Sun Jan 24 08:35:09 2010 +0000
@@ -32,3 +32,4 @@
 
 /* The actual mixing thread function */
 extern int SDLCALL SDL_RunAudio(void *audiop);
+
--- a/src/audio/SDL_sysaudio.h	Sun Jan 17 05:19:32 2010 +0000
+++ b/src/audio/SDL_sysaudio.h	Sun Jan 24 08:35:09 2010 +0000
@@ -59,6 +59,8 @@
 	void (*LockAudio)(_THIS);
 	void (*UnlockAudio)(_THIS);
 
+	void (*SetCaption)(_THIS, const char *caption);
+
 	/* * * */
 	/* Data common to all devices */
 
--- a/src/audio/pulse/SDL_pulseaudio.c	Sun Jan 17 05:19:32 2010 +0000
+++ b/src/audio/pulse/SDL_pulseaudio.c	Sun Jan 24 08:35:09 2010 +0000
@@ -56,6 +56,7 @@
 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 @@
 	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 @@
 		(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 void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
+	SDL_free(device->hidden->caption);
 	SDL_free(device->hidden);
 	SDL_free(device);
 	UnloadPulseLibrary();
@@ -281,6 +287,7 @@
 	this->GetAudioBuf = PULSE_GetAudioBuf;
 	this->CloseAudio = PULSE_CloseAudio;
 	this->WaitDone = PULSE_WaitDone;
+	this->SetCaption = PULSE_SetCaption;
 
 	this->free = Audio_DeleteDevice;
 
@@ -372,7 +379,27 @@
 #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 @@
 		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 @@
 	/* 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);
 	}
 
--- a/src/audio/pulse/SDL_pulseaudio.h	Sun Jan 17 05:19:32 2010 +0000
+++ b/src/audio/pulse/SDL_pulseaudio.h	Sun Jan 24 08:35:09 2010 +0000
@@ -37,6 +37,8 @@
 	pa_context *context;
 	pa_stream *stream;
 
+	char *caption;
+
 	/* Raw mixing buffer */
 	Uint8 *mixbuf;
 	int    mixlen;
--- a/src/video/SDL_video.c	Sun Jan 17 05:19:32 2010 +0000
+++ b/src/video/SDL_video.c	Sun Jan 24 08:35:09 2010 +0000
@@ -1701,7 +1701,12 @@
 			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;