comparison src/audio/pulseaudio/SDL_pulseaudio.c @ 2272:25a87553a59d

Minor PulseAudio fixes: corrected OpenDevice return code, human-readable error messages if connction to daemon fails.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 20 Aug 2007 02:08:37 +0000
parents 60b4c52a7906
children aedfcdeb69b6
comparison
equal deleted inserted replaced
2271:60b4c52a7906 2272:25a87553a59d
83 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))( 83 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))(
84 pa_channel_map *m, 84 pa_channel_map *m,
85 unsigned channels, 85 unsigned channels,
86 pa_channel_map_def_t def 86 pa_channel_map_def_t def
87 ); 87 );
88 static const char* (*SDL_NAME(pa_strerror))(int error);
88 89
89 90
90 #define SDL_PULSEAUDIO_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) } 91 #define SDL_PULSEAUDIO_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
91 static struct { 92 static struct {
92 const char *name; 93 const char *name;
96 SDL_PULSEAUDIO_SYM(pa_simple_new), 97 SDL_PULSEAUDIO_SYM(pa_simple_new),
97 SDL_PULSEAUDIO_SYM(pa_simple_free), 98 SDL_PULSEAUDIO_SYM(pa_simple_free),
98 SDL_PULSEAUDIO_SYM(pa_simple_drain), 99 SDL_PULSEAUDIO_SYM(pa_simple_drain),
99 SDL_PULSEAUDIO_SYM(pa_simple_write), 100 SDL_PULSEAUDIO_SYM(pa_simple_write),
100 SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto), 101 SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto),
102 SDL_PULSEAUDIO_SYM(pa_strerror),
101 /* *INDENT-ON* */ 103 /* *INDENT-ON* */
102 }; 104 };
103 #undef SDL_PULSEAUDIO_SYM 105 #undef SDL_PULSEAUDIO_SYM
104 106
105 static void 107 static void
251 253
252 254
253 static int 255 static int
254 PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) 256 PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
255 { 257 {
256 Uint16 test_format; 258 Uint16 test_format = 0;
257 pa_sample_spec paspec; 259 pa_sample_spec paspec;
258 pa_buffer_attr paattr; 260 pa_buffer_attr paattr;
259 pa_channel_map pacmap; 261 pa_channel_map pacmap;
262 int err = 0;
260 263
261 /* Initialize all variables that we clean on shutdown */ 264 /* Initialize all variables that we clean on shutdown */
262 this->hidden = (struct SDL_PrivateAudioData *) 265 this->hidden = (struct SDL_PrivateAudioData *)
263 SDL_malloc((sizeof *this->hidden)); 266 SDL_malloc((sizeof *this->hidden));
264 if (this->hidden == NULL) { 267 if (this->hidden == NULL) {
336 SDL_getenv("PADEVICE"), /* device on the server */ 339 SDL_getenv("PADEVICE"), /* device on the server */
337 "Simple DirectMedia Layer", /* stream description */ 340 "Simple DirectMedia Layer", /* stream description */
338 &paspec, /* sample format spec */ 341 &paspec, /* sample format spec */
339 &pacmap, /* channel map */ 342 &pacmap, /* channel map */
340 &paattr, /* buffering attributes */ 343 &paattr, /* buffering attributes */
341 NULL /* error code */ 344 &err /* error code */
342 ); 345 );
346
343 if ( this->hidden->stream == NULL ) { 347 if ( this->hidden->stream == NULL ) {
344 PULSEAUDIO_CloseDevice(this); 348 PULSEAUDIO_CloseDevice(this);
345 SDL_SetError("Could not connect to PulseAudio"); 349 SDL_SetError("Could not connect to PulseAudio: %s",
346 return(-1); 350 SDL_NAME(pa_strerror(err)));
351 return 0;
347 } 352 }
348 353
349 /* Get the parent process id (we're the parent of the audio thread) */ 354 /* Get the parent process id (we're the parent of the audio thread) */
350 this->hidden->parent = getpid(); 355 this->hidden->parent = getpid();
351 356