1.2: let PulseAudio hook into SDL_WM_SetCaption(). SDL-1.2
authorRyan C. Gordon
Sun, 24 Jan 2010 08:35:09 +0000
branchSDL-1.2
changeset 4398fe15c4e8efe6
parent 4397 fb1fc6c9289e
child 4399 ae9c094e9200
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
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
     1.1 --- a/src/audio/SDL_audio.c	Sun Jan 17 05:19:32 2010 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Sun Jan 24 08:35:09 2010 +0000
     1.3 @@ -693,3 +693,11 @@
     1.4  	spec->size *= spec->channels;
     1.5  	spec->size *= spec->samples;
     1.6  }
     1.7 +
     1.8 +void SDL_Audio_SetCaption(const char *caption)
     1.9 +{
    1.10 +	if ((current_audio) && (current_audio->SetCaption)) {
    1.11 +		current_audio->SetCaption(current_audio, caption);
    1.12 +	}
    1.13 +}
    1.14 +
     2.1 --- a/src/audio/SDL_audio_c.h	Sun Jan 17 05:19:32 2010 +0000
     2.2 +++ b/src/audio/SDL_audio_c.h	Sun Jan 24 08:35:09 2010 +0000
     2.3 @@ -32,3 +32,4 @@
     2.4  
     2.5  /* The actual mixing thread function */
     2.6  extern int SDLCALL SDL_RunAudio(void *audiop);
     2.7 +
     3.1 --- a/src/audio/SDL_sysaudio.h	Sun Jan 17 05:19:32 2010 +0000
     3.2 +++ b/src/audio/SDL_sysaudio.h	Sun Jan 24 08:35:09 2010 +0000
     3.3 @@ -59,6 +59,8 @@
     3.4  	void (*LockAudio)(_THIS);
     3.5  	void (*UnlockAudio)(_THIS);
     3.6  
     3.7 +	void (*SetCaption)(_THIS, const char *caption);
     3.8 +
     3.9  	/* * * */
    3.10  	/* Data common to all devices */
    3.11  
     4.1 --- a/src/audio/pulse/SDL_pulseaudio.c	Sun Jan 17 05:19:32 2010 +0000
     4.2 +++ b/src/audio/pulse/SDL_pulseaudio.c	Sun Jan 24 08:35:09 2010 +0000
     4.3 @@ -56,6 +56,7 @@
     4.4  static Uint8 *PULSE_GetAudioBuf(_THIS);
     4.5  static void PULSE_CloseAudio(_THIS);
     4.6  static void PULSE_WaitDone(_THIS);
     4.7 +static void PULSE_SetCaption(_THIS, const char *str);
     4.8  
     4.9  #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC
    4.10  
    4.11 @@ -113,6 +114,8 @@
    4.12  	pa_stream_success_cb_t cb, void *userdata);
    4.13  static int (*SDL_NAME(pa_stream_disconnect))(pa_stream *s);
    4.14  static void (*SDL_NAME(pa_stream_unref))(pa_stream *s);
    4.15 +static pa_operation* (*SDL_NAME(pa_context_set_name))(pa_context *c,
    4.16 +	const char *name, pa_context_success_cb_t cb, void *userdata);
    4.17  
    4.18  static struct {
    4.19  	const char *name;
    4.20 @@ -164,6 +167,8 @@
    4.21  		(void **)&SDL_NAME(pa_stream_disconnect)	},
    4.22  	{ "pa_stream_unref",
    4.23  		(void **)&SDL_NAME(pa_stream_unref)		},
    4.24 +	{ "pa_context_set_name",
    4.25 +		(void **)&SDL_NAME(pa_context_set_name)		},
    4.26  };
    4.27  
    4.28  static void UnloadPulseLibrary()
    4.29 @@ -248,6 +253,7 @@
    4.30  
    4.31  static void Audio_DeleteDevice(SDL_AudioDevice *device)
    4.32  {
    4.33 +	SDL_free(device->hidden->caption);
    4.34  	SDL_free(device->hidden);
    4.35  	SDL_free(device);
    4.36  	UnloadPulseLibrary();
    4.37 @@ -281,6 +287,7 @@
    4.38  	this->GetAudioBuf = PULSE_GetAudioBuf;
    4.39  	this->CloseAudio = PULSE_CloseAudio;
    4.40  	this->WaitDone = PULSE_WaitDone;
    4.41 +	this->SetCaption = PULSE_SetCaption;
    4.42  
    4.43  	this->free = Audio_DeleteDevice;
    4.44  
    4.45 @@ -372,7 +379,27 @@
    4.46  #endif
    4.47  }
    4.48  
    4.49 -static void stream_drain_complete(pa_stream *s, int success, void *userdata) {
    4.50 +static void caption_set_complete(pa_context *c, int success, void *userdata)
    4.51 +{
    4.52 +	/* no-op. */
    4.53 +}
    4.54 +
    4.55 +static void PULSE_SetCaption(_THIS, const char *str)
    4.56 +{
    4.57 +	SDL_free(this->hidden->caption);
    4.58 +	if ((str == NULL) || (*str == '\0')) {
    4.59 +		str = get_progname();  /* set a default so SOMETHING shows up. */
    4.60 +	}
    4.61 +	this->hidden->caption = SDL_strdup(str);
    4.62 +	if (context != NULL) {
    4.63 +		SDL_NAME(pa_context_set_name)(context, this->hidden->caption,
    4.64 +		                              caption_set_complete, 0);
    4.65 +	}
    4.66 +}
    4.67 +
    4.68 +static void stream_drain_complete(pa_stream *s, int success, void *userdata)
    4.69 +{
    4.70 +	/* no-op. */
    4.71  }
    4.72  
    4.73  static void PULSE_WaitDone(_THIS)
    4.74 @@ -469,8 +496,13 @@
    4.75  		return(-1);
    4.76  	}
    4.77  
    4.78 +	if (this->hidden->caption == NULL) {
    4.79 +		this->hidden->caption = SDL_strdup(get_progname());
    4.80 +	}
    4.81 +
    4.82  	mainloop_api = SDL_NAME(pa_mainloop_get_api)(mainloop);
    4.83 -	if (!(context = SDL_NAME(pa_context_new)(mainloop_api, get_progname()))) {
    4.84 +	if (!(context = SDL_NAME(pa_context_new)(mainloop_api,
    4.85 +	                                         this->hidden->caption))) {
    4.86  		PULSE_CloseAudio(this);
    4.87  		SDL_SetError("pa_context_new() failed");
    4.88  		return(-1);
    4.89 @@ -479,7 +511,7 @@
    4.90  	/* Connect to the PulseAudio server */
    4.91  	if (SDL_NAME(pa_context_connect)(context, NULL, 0, NULL) < 0) {
    4.92  		PULSE_CloseAudio(this);
    4.93 -	        SDL_SetError("Could not setup connection to PulseAudio");
    4.94 +		SDL_SetError("Could not setup connection to PulseAudio");
    4.95  		return(-1);
    4.96  	}
    4.97  
     5.1 --- a/src/audio/pulse/SDL_pulseaudio.h	Sun Jan 17 05:19:32 2010 +0000
     5.2 +++ b/src/audio/pulse/SDL_pulseaudio.h	Sun Jan 24 08:35:09 2010 +0000
     5.3 @@ -37,6 +37,8 @@
     5.4  	pa_context *context;
     5.5  	pa_stream *stream;
     5.6  
     5.7 +	char *caption;
     5.8 +
     5.9  	/* Raw mixing buffer */
    5.10  	Uint8 *mixbuf;
    5.11  	int    mixlen;
     6.1 --- a/src/video/SDL_video.c	Sun Jan 17 05:19:32 2010 +0000
     6.2 +++ b/src/video/SDL_video.c	Sun Jan 24 08:35:09 2010 +0000
     6.3 @@ -1701,7 +1701,12 @@
     6.4  			video->SetCaption(this, video->wm_title,video->wm_icon);
     6.5  		}
     6.6  	}
     6.7 +
     6.8 +	/* PulseAudio can make use of this information. */
     6.9 +	extern void SDL_Audio_SetCaption(const char *caption);
    6.10 +	SDL_Audio_SetCaption(title);
    6.11  }
    6.12 +
    6.13  void SDL_WM_GetCaption (char **title, char **icon)
    6.14  {
    6.15  	SDL_VideoDevice *video = current_video;