Mercurial > sdl-ios-xcode
comparison src/audio/pulseaudio/SDL_pulseaudio.c @ 2274:aedfcdeb69b6
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Sep 2007 12:11:40 +0000 |
parents | 25a87553a59d |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
2273:a25bc0f79557 | 2274:aedfcdeb69b6 |
---|---|
59 | 59 |
60 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC; | 60 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC; |
61 static void *pulse_handle = NULL; | 61 static void *pulse_handle = NULL; |
62 | 62 |
63 /* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */ | 63 /* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */ |
64 static pa_simple* (*SDL_NAME(pa_simple_new))( | 64 static pa_simple *(*SDL_NAME(pa_simple_new)) (const char *server, |
65 const char *server, | 65 const char *name, |
66 const char *name, | 66 pa_stream_direction_t dir, |
67 pa_stream_direction_t dir, | 67 const char *dev, |
68 const char *dev, | 68 const char *stream_name, |
69 const char *stream_name, | 69 const pa_sample_spec * ss, |
70 const pa_sample_spec *ss, | 70 const pa_channel_map * map, |
71 const pa_channel_map *map, | 71 const pa_buffer_attr * attr, |
72 const pa_buffer_attr *attr, | 72 int *error); |
73 int *error | 73 static void (*SDL_NAME(pa_simple_free)) (pa_simple * s); |
74 ); | 74 static int (*SDL_NAME(pa_simple_drain)) (pa_simple * s, int *error); |
75 static void (*SDL_NAME(pa_simple_free))(pa_simple *s); | 75 static int (*SDL_NAME(pa_simple_write)) (pa_simple * s, |
76 static int (*SDL_NAME(pa_simple_drain))(pa_simple *s, int *error); | 76 const void *data, |
77 static int (*SDL_NAME(pa_simple_write))( | 77 size_t length, int *error); |
78 pa_simple *s, | 78 static pa_channel_map *(*SDL_NAME(pa_channel_map_init_auto)) (pa_channel_map * |
79 const void *data, | 79 m, |
80 size_t length, | 80 unsigned |
81 int *error | 81 channels, |
82 ); | 82 pa_channel_map_def_t |
83 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))( | 83 def); |
84 pa_channel_map *m, | 84 static const char *(*SDL_NAME(pa_strerror)) (int error); |
85 unsigned channels, | |
86 pa_channel_map_def_t def | |
87 ); | |
88 static const char* (*SDL_NAME(pa_strerror))(int error); | |
89 | 85 |
90 | 86 |
91 #define SDL_PULSEAUDIO_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) } | 87 #define SDL_PULSEAUDIO_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) } |
92 static struct { | 88 static struct |
89 { | |
93 const char *name; | 90 const char *name; |
94 void **func; | 91 void **func; |
95 } pulse_functions[] = { | 92 } pulse_functions[] = { |
96 /* *INDENT-OFF* */ | 93 /* *INDENT-OFF* */ |
97 SDL_PULSEAUDIO_SYM(pa_simple_new), | 94 SDL_PULSEAUDIO_SYM(pa_simple_new), |
100 SDL_PULSEAUDIO_SYM(pa_simple_write), | 97 SDL_PULSEAUDIO_SYM(pa_simple_write), |
101 SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto), | 98 SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto), |
102 SDL_PULSEAUDIO_SYM(pa_strerror), | 99 SDL_PULSEAUDIO_SYM(pa_strerror), |
103 /* *INDENT-ON* */ | 100 /* *INDENT-ON* */ |
104 }; | 101 }; |
102 | |
105 #undef SDL_PULSEAUDIO_SYM | 103 #undef SDL_PULSEAUDIO_SYM |
106 | 104 |
107 static void | 105 static void |
108 UnloadPulseLibrary() | 106 UnloadPulseLibrary() |
109 { | 107 { |
183 | 181 |
184 static void | 182 static void |
185 PULSEAUDIO_PlayDevice(_THIS) | 183 PULSEAUDIO_PlayDevice(_THIS) |
186 { | 184 { |
187 /* Write the audio data */ | 185 /* Write the audio data */ |
188 if ( SDL_NAME(pa_simple_write)(this->hidden->stream, this->hidden->mixbuf, | 186 if (SDL_NAME(pa_simple_write) (this->hidden->stream, this->hidden->mixbuf, |
189 this->hidden->mixlen, NULL) != 0 ) | 187 this->hidden->mixlen, NULL) != 0) { |
190 { | |
191 this->enabled = 0; | 188 this->enabled = 0; |
192 } | 189 } |
193 } | 190 } |
194 | 191 |
195 static void | 192 static void |
196 PULSEAUDIO_WaitDone(_THIS) | 193 PULSEAUDIO_WaitDone(_THIS) |
197 { | 194 { |
198 SDL_NAME(pa_simple_drain)(this->hidden->stream, NULL); | 195 SDL_NAME(pa_simple_drain) (this->hidden->stream, NULL); |
199 } | 196 } |
200 | 197 |
201 | 198 |
202 static Uint8 * | 199 static Uint8 * |
203 PULSEAUDIO_GetDeviceBuf(_THIS) | 200 PULSEAUDIO_GetDeviceBuf(_THIS) |
213 if (this->hidden->mixbuf != NULL) { | 210 if (this->hidden->mixbuf != NULL) { |
214 SDL_FreeAudioMem(this->hidden->mixbuf); | 211 SDL_FreeAudioMem(this->hidden->mixbuf); |
215 this->hidden->mixbuf = NULL; | 212 this->hidden->mixbuf = NULL; |
216 } | 213 } |
217 if (this->hidden->stream) { | 214 if (this->hidden->stream) { |
218 SDL_NAME(pa_simple_drain)(this->hidden->stream, NULL); | 215 SDL_NAME(pa_simple_drain) (this->hidden->stream, NULL); |
219 SDL_NAME(pa_simple_free)(this->hidden->stream); | 216 SDL_NAME(pa_simple_free) (this->hidden->stream); |
220 this->hidden->stream = NULL; | 217 this->hidden->stream = NULL; |
221 } | 218 } |
222 SDL_free(this->hidden); | 219 SDL_free(this->hidden); |
223 this->hidden = NULL; | 220 this->hidden = NULL; |
224 } | 221 } |
225 } | 222 } |
226 | 223 |
227 | 224 |
228 /* !!! FIXME: this could probably be expanded. */ | 225 /* !!! FIXME: this could probably be expanded. */ |
229 /* Try to get the name of the program */ | 226 /* Try to get the name of the program */ |
230 static char *get_progname(void) | 227 static char * |
228 get_progname(void) | |
231 { | 229 { |
232 char *progname = NULL; | 230 char *progname = NULL; |
233 #ifdef __LINUX__ | 231 #ifdef __LINUX__ |
234 FILE *fp; | 232 FILE *fp; |
235 static char temp[BUFSIZ]; | 233 static char temp[BUFSIZ]; |
236 | 234 |
237 SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid()); | 235 SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid()); |
238 fp = fopen(temp, "r"); | 236 fp = fopen(temp, "r"); |
239 if ( fp != NULL ) { | 237 if (fp != NULL) { |
240 if ( fgets(temp, sizeof(temp)-1, fp) ) { | 238 if (fgets(temp, sizeof(temp) - 1, fp)) { |
241 progname = SDL_strrchr(temp, '/'); | 239 progname = SDL_strrchr(temp, '/'); |
242 if ( progname == NULL ) { | 240 if (progname == NULL) { |
243 progname = temp; | 241 progname = temp; |
244 } else { | 242 } else { |
245 progname = progname+1; | 243 progname = progname + 1; |
246 } | 244 } |
247 } | 245 } |
248 fclose(fp); | 246 fclose(fp); |
249 } | 247 } |
250 #endif | 248 #endif |
251 return(progname); | 249 return (progname); |
252 } | 250 } |
253 | 251 |
254 | 252 |
255 static int | 253 static int |
256 PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) | 254 PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) |
276 for (test_format = SDL_FirstAudioFormat(this->spec.format); | 274 for (test_format = SDL_FirstAudioFormat(this->spec.format); |
277 (paspec.format == PA_SAMPLE_INVALID) && test_format;) { | 275 (paspec.format == PA_SAMPLE_INVALID) && test_format;) { |
278 #ifdef DEBUG_AUDIO | 276 #ifdef DEBUG_AUDIO |
279 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); | 277 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
280 #endif | 278 #endif |
281 switch ( test_format ) { | 279 switch (test_format) { |
282 case AUDIO_U8: | 280 case AUDIO_U8: |
283 paspec.format = PA_SAMPLE_U8; | 281 paspec.format = PA_SAMPLE_U8; |
284 break; | 282 break; |
285 case AUDIO_S16LSB: | 283 case AUDIO_S16LSB: |
286 paspec.format = PA_SAMPLE_S16LE; | 284 paspec.format = PA_SAMPLE_S16LE; |
287 break; | 285 break; |
288 case AUDIO_S16MSB: | 286 case AUDIO_S16MSB: |
289 paspec.format = PA_SAMPLE_S16BE; | 287 paspec.format = PA_SAMPLE_S16BE; |
290 break; | 288 break; |
291 default: | 289 default: |
292 paspec.format = PA_SAMPLE_INVALID; | 290 paspec.format = PA_SAMPLE_INVALID; |
293 break; | 291 break; |
294 } | 292 } |
295 if (paspec.format == PA_SAMPLE_INVALID) { | 293 if (paspec.format == PA_SAMPLE_INVALID) { |
296 test_format = SDL_NextAudioFormat(); | 294 test_format = SDL_NextAudioFormat(); |
297 } | 295 } |
298 } | 296 } |
326 paattr.prebuf = this->hidden->mixlen; | 324 paattr.prebuf = this->hidden->mixlen; |
327 paattr.maxlength = this->hidden->mixlen * 4; | 325 paattr.maxlength = this->hidden->mixlen * 4; |
328 | 326 |
329 /* The SDL ALSA output hints us that we use Windows' channel mapping */ | 327 /* The SDL ALSA output hints us that we use Windows' channel mapping */ |
330 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */ | 328 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */ |
331 SDL_NAME(pa_channel_map_init_auto)( | 329 SDL_NAME(pa_channel_map_init_auto) (&pacmap, this->spec.channels, |
332 &pacmap, this->spec.channels, PA_CHANNEL_MAP_WAVEEX); | 330 PA_CHANNEL_MAP_WAVEEX); |
333 | 331 |
334 /* Connect to the PulseAudio server */ | 332 /* Connect to the PulseAudio server */ |
335 this->hidden->stream = SDL_NAME(pa_simple_new)( | 333 this->hidden->stream = SDL_NAME(pa_simple_new) (SDL_getenv("PASERVER"), /* server */ |
336 SDL_getenv("PASERVER"), /* server */ | 334 get_progname(), /* application name */ |
337 get_progname(), /* application name */ | 335 PA_STREAM_PLAYBACK, /* playback mode */ |
338 PA_STREAM_PLAYBACK, /* playback mode */ | 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 &err /* error code */ |
344 &err /* error code */ | 342 ); |
345 ); | 343 |
346 | 344 if (this->hidden->stream == NULL) { |
347 if ( this->hidden->stream == NULL ) { | |
348 PULSEAUDIO_CloseDevice(this); | 345 PULSEAUDIO_CloseDevice(this); |
349 SDL_SetError("Could not connect to PulseAudio: %s", | 346 SDL_SetError("Could not connect to PulseAudio: %s", |
350 SDL_NAME(pa_strerror(err))); | 347 SDL_NAME(pa_strerror(err))); |
351 return 0; | 348 return 0; |
352 } | 349 } |