annotate src/audio/pulse/SDL_pulseaudio.c @ 4396:f5d3f7fa071d SDL-1.2

1.2 pulseaudio: make some function pointers static.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 17 Jan 2010 05:17:59 +0000
parents 14f95e514408
children fe15c4e8efe6
rev   line source
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 3939
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 Lesser General Public License for more details.
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Stéphan Kochen
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 stephan@kochen.nl
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
21
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 Based on parts of the ALSA and ESounD output drivers.
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 #include "SDL_config.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 /* Allow access to an PulseAudio network stream mixing buffer */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #include <sys/types.h>
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #include <unistd.h>
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #include <signal.h>
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #include <errno.h>
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
32 #include <pulse/pulseaudio.h>
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include <pulse/simple.h>
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 #include "SDL_timer.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include "SDL_audio.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include "../SDL_audiomem.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include "../SDL_audio_c.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include "../SDL_audiodev_c.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #include "SDL_pulseaudio.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 #include "SDL_name.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include "SDL_loadso.h"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #else
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #define SDL_NAME(X) X
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #endif
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 /* The tag name used by the driver */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 #define PULSE_DRIVER_NAME "pulse"
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 /* Audio driver functions */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 static void PULSE_WaitAudio(_THIS);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 static void PULSE_PlayAudio(_THIS);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 static Uint8 *PULSE_GetAudioBuf(_THIS);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static void PULSE_CloseAudio(_THIS);
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
58 static void PULSE_WaitDone(_THIS);
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSE_DYNAMIC;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 static void *pulse_handle = NULL;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 static int pulse_loaded = 0;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 static pa_simple* (*SDL_NAME(pa_simple_new))(
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 const char *server,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 const char *name,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 pa_stream_direction_t dir,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 const char *dev,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 const char *stream_name,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 const pa_sample_spec *ss,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 const pa_channel_map *map,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 const pa_buffer_attr *attr,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 int *error
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 );
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 static void (*SDL_NAME(pa_simple_free))(pa_simple *s);
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
78
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))(
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 pa_channel_map *m,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 unsigned channels,
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 pa_channel_map_def_t def
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 );
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
84
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
85 static pa_mainloop * (*SDL_NAME(pa_mainloop_new))(void);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
86 static pa_mainloop_api * (*SDL_NAME(pa_mainloop_get_api))(pa_mainloop *m);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
87 static int (*SDL_NAME(pa_mainloop_iterate))(pa_mainloop *m, int block, int *retval);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
88 static void (*SDL_NAME(pa_mainloop_free))(pa_mainloop *m);
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
89
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
90 static pa_operation_state_t (*SDL_NAME(pa_operation_get_state))(pa_operation *o);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
91 static void (*SDL_NAME(pa_operation_cancel))(pa_operation *o);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
92 static void (*SDL_NAME(pa_operation_unref))(pa_operation *o);
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
93
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
94 static pa_context * (*SDL_NAME(pa_context_new))(
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
95 pa_mainloop_api *m, const char *name);
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
96 static int (*SDL_NAME(pa_context_connect))(
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
97 pa_context *c, const char *server,
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
98 pa_context_flags_t flags, const pa_spawn_api *api);
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
99 static pa_context_state_t (*SDL_NAME(pa_context_get_state))(pa_context *c);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
100 static void (*SDL_NAME(pa_context_disconnect))(pa_context *c);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
101 static void (*SDL_NAME(pa_context_unref))(pa_context *c);
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
102
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
103 static pa_stream * (*SDL_NAME(pa_stream_new))(pa_context *c,
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
104 const char *name, const pa_sample_spec *ss, const pa_channel_map *map);
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
105 static int (*SDL_NAME(pa_stream_connect_playback))(pa_stream *s, const char *dev,
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
106 const pa_buffer_attr *attr, pa_stream_flags_t flags,
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
107 pa_cvolume *volume, pa_stream *sync_stream);
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
108 static pa_stream_state_t (*SDL_NAME(pa_stream_get_state))(pa_stream *s);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
109 static size_t (*SDL_NAME(pa_stream_writable_size))(pa_stream *s);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
110 static int (*SDL_NAME(pa_stream_write))(pa_stream *s, const void *data, size_t nbytes,
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
111 pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek);
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
112 static pa_operation * (*SDL_NAME(pa_stream_drain))(pa_stream *s,
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
113 pa_stream_success_cb_t cb, void *userdata);
4396
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
114 static int (*SDL_NAME(pa_stream_disconnect))(pa_stream *s);
f5d3f7fa071d 1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents: 4344
diff changeset
115 static void (*SDL_NAME(pa_stream_unref))(pa_stream *s);
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 static struct {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 const char *name;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 void **func;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 } pulse_functions[] = {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 { "pa_simple_new",
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 (void **)&SDL_NAME(pa_simple_new) },
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 { "pa_simple_free",
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 (void **)&SDL_NAME(pa_simple_free) },
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 { "pa_channel_map_init_auto",
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 (void **)&SDL_NAME(pa_channel_map_init_auto) },
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
127 { "pa_mainloop_new",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
128 (void **)&SDL_NAME(pa_mainloop_new) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
129 { "pa_mainloop_get_api",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
130 (void **)&SDL_NAME(pa_mainloop_get_api) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
131 { "pa_mainloop_iterate",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
132 (void **)&SDL_NAME(pa_mainloop_iterate) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
133 { "pa_mainloop_free",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
134 (void **)&SDL_NAME(pa_mainloop_free) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
135 { "pa_operation_get_state",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
136 (void **)&SDL_NAME(pa_operation_get_state) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
137 { "pa_operation_cancel",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
138 (void **)&SDL_NAME(pa_operation_cancel) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
139 { "pa_operation_unref",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
140 (void **)&SDL_NAME(pa_operation_unref) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
141 { "pa_context_new",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
142 (void **)&SDL_NAME(pa_context_new) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
143 { "pa_context_connect",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
144 (void **)&SDL_NAME(pa_context_connect) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
145 { "pa_context_get_state",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
146 (void **)&SDL_NAME(pa_context_get_state) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
147 { "pa_context_disconnect",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
148 (void **)&SDL_NAME(pa_context_disconnect) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
149 { "pa_context_unref",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
150 (void **)&SDL_NAME(pa_context_unref) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
151 { "pa_stream_new",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
152 (void **)&SDL_NAME(pa_stream_new) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
153 { "pa_stream_connect_playback",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
154 (void **)&SDL_NAME(pa_stream_connect_playback) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
155 { "pa_stream_get_state",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
156 (void **)&SDL_NAME(pa_stream_get_state) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
157 { "pa_stream_writable_size",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
158 (void **)&SDL_NAME(pa_stream_writable_size) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
159 { "pa_stream_write",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
160 (void **)&SDL_NAME(pa_stream_write) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
161 { "pa_stream_drain",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
162 (void **)&SDL_NAME(pa_stream_drain) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
163 { "pa_stream_disconnect",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
164 (void **)&SDL_NAME(pa_stream_disconnect) },
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
165 { "pa_stream_unref",
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
166 (void **)&SDL_NAME(pa_stream_unref) },
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 };
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 static void UnloadPulseLibrary()
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 if ( pulse_loaded ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 SDL_UnloadObject(pulse_handle);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 pulse_handle = NULL;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 pulse_loaded = 0;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 static int LoadPulseLibrary(void)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 int i, retval = -1;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 pulse_handle = SDL_LoadObject(pulse_library);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 if ( pulse_handle ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 pulse_loaded = 1;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 retval = 0;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 for ( i=0; i<SDL_arraysize(pulse_functions); ++i ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 *pulse_functions[i].func = SDL_LoadFunction(pulse_handle, pulse_functions[i].name);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 if ( !*pulse_functions[i].func ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 retval = -1;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 UnloadPulseLibrary();
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 break;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 return retval;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 #else
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 static void UnloadPulseLibrary()
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 return;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 static int LoadPulseLibrary(void)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 return 0;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 #endif /* SDL_AUDIO_DRIVER_PULSE_DYNAMIC */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 /* Audio driver bootstrap functions */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 static int Audio_Available(void)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 pa_sample_spec paspec;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 pa_simple *connection;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 int available;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 available = 0;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 if ( LoadPulseLibrary() < 0 ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 return available;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 }
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
224
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 /* Connect with a dummy format. */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 paspec.format = PA_SAMPLE_U8;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 paspec.rate = 11025;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 paspec.channels = 1;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 connection = SDL_NAME(pa_simple_new)(
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
230 NULL, /* server */
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 "Test stream", /* application name */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 PA_STREAM_PLAYBACK, /* playback mode */
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
233 NULL, /* device on the server */
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 "Simple DirectMedia Layer", /* stream description */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 &paspec, /* sample format spec */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 NULL, /* channel map */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 NULL, /* buffering attributes */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 NULL /* error code */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 );
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 if ( connection != NULL ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 available = 1;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 SDL_NAME(pa_simple_free)(connection);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 }
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
244
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 UnloadPulseLibrary();
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 return(available);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 static void Audio_DeleteDevice(SDL_AudioDevice *device)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 SDL_free(device->hidden);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 SDL_free(device);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 UnloadPulseLibrary();
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 SDL_AudioDevice *this;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 /* Initialize all variables that we clean on shutdown */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 LoadPulseLibrary();
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 if ( this ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 SDL_memset(this, 0, (sizeof *this));
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 this->hidden = (struct SDL_PrivateAudioData *)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 SDL_malloc((sizeof *this->hidden));
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 if ( (this == NULL) || (this->hidden == NULL) ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 SDL_OutOfMemory();
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 if ( this ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 SDL_free(this);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 return(0);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 /* Set the function pointers */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 this->OpenAudio = PULSE_OpenAudio;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 this->WaitAudio = PULSE_WaitAudio;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 this->PlayAudio = PULSE_PlayAudio;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 this->GetAudioBuf = PULSE_GetAudioBuf;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 this->CloseAudio = PULSE_CloseAudio;
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
283 this->WaitDone = PULSE_WaitDone;
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 this->free = Audio_DeleteDevice;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 return this;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 AudioBootStrap PULSE_bootstrap = {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 PULSE_DRIVER_NAME, "PulseAudio",
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 Audio_Available, Audio_CreateDevice
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 };
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 /* This function waits until it is possible to write a full sound buffer */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 static void PULSE_WaitAudio(_THIS)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 {
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
298 int size;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
299 while(1) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
300 if (SDL_NAME(pa_context_get_state)(context) != PA_CONTEXT_READY ||
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
301 SDL_NAME(pa_stream_get_state)(stream) != PA_STREAM_READY ||
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
302 SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
303 this->enabled = 0;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
304 return;
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 }
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
306 size = SDL_NAME(pa_stream_writable_size)(stream);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
307 if (size >= mixlen)
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
308 return;
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 static void PULSE_PlayAudio(_THIS)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 /* Write the audio data */
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
315 if (SDL_NAME(pa_stream_write)(stream, mixbuf, mixlen, NULL, 0LL, PA_SEEK_RELATIVE) < 0)
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 this->enabled = 0;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 static Uint8 *PULSE_GetAudioBuf(_THIS)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 return(mixbuf);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 static void PULSE_CloseAudio(_THIS)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 if ( mixbuf != NULL ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 SDL_FreeAudioMem(mixbuf);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 mixbuf = NULL;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 if ( stream != NULL ) {
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
331 SDL_NAME(pa_stream_disconnect)(stream);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
332 SDL_NAME(pa_stream_unref)(stream);
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 stream = NULL;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 }
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
335 if (context != NULL) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
336 SDL_NAME(pa_context_disconnect)(context);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
337 SDL_NAME(pa_context_unref)(context);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
338 context = NULL;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
339 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
340 if (mainloop != NULL) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
341 SDL_NAME(pa_mainloop_free)(mainloop);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
342 mainloop = NULL;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
343 }
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 /* Try to get the name of the program */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 static char *get_progname(void)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 {
4344
14f95e514408 patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents: 4216
diff changeset
349 #ifdef __LINUX__
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 char *progname = NULL;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 FILE *fp;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 static char temp[BUFSIZ];
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354 SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 fp = fopen(temp, "r");
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 if ( fp != NULL ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 if ( fgets(temp, sizeof(temp)-1, fp) ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 progname = SDL_strrchr(temp, '/');
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 if ( progname == NULL ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 progname = temp;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 } else {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 progname = progname+1;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 fclose(fp);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 }
4344
14f95e514408 patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents: 4216
diff changeset
367 return(progname);
14f95e514408 patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents: 4216
diff changeset
368 #elif defined(__NetBSD__)
14f95e514408 patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents: 4216
diff changeset
369 return getprogname();
14f95e514408 patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents: 4216
diff changeset
370 #else
14f95e514408 patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents: 4216
diff changeset
371 return("unknown");
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 #endif
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
375 static void stream_drain_complete(pa_stream *s, int success, void *userdata) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
376 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
377
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
378 static void PULSE_WaitDone(_THIS)
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
379 {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
380 pa_operation *o;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
381
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
382 o = SDL_NAME(pa_stream_drain)(stream, stream_drain_complete, NULL);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
383 if (!o)
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
384 return;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
385
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
386 while (SDL_NAME(pa_operation_get_state)(o) != PA_OPERATION_DONE) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
387 if (SDL_NAME(pa_context_get_state)(context) != PA_CONTEXT_READY ||
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
388 SDL_NAME(pa_stream_get_state)(stream) != PA_STREAM_READY ||
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
389 SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
390 SDL_NAME(pa_operation_cancel)(o);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
391 break;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
392 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
393 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
394 SDL_NAME(pa_operation_unref)(o);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
395 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
396
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec)
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 {
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
399 int state;
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 Uint16 test_format;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 pa_sample_spec paspec;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 pa_buffer_attr paattr;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 pa_channel_map pacmap;
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
404 pa_stream_flags_t flags = 0;
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
405
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 paspec.format = PA_SAMPLE_INVALID;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 for ( test_format = SDL_FirstAudioFormat(spec->format); test_format; ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 switch ( test_format ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 case AUDIO_U8:
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 paspec.format = PA_SAMPLE_U8;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 break;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 case AUDIO_S16LSB:
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 paspec.format = PA_SAMPLE_S16LE;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 break;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 case AUDIO_S16MSB:
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 paspec.format = PA_SAMPLE_S16BE;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 break;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 if ( paspec.format != PA_SAMPLE_INVALID )
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 break;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 if (paspec.format == PA_SAMPLE_INVALID ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 SDL_SetError("Couldn't find any suitable audio formats");
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 return(-1);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 spec->format = test_format;
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
427
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 paspec.channels = spec->channels;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429 paspec.rate = spec->freq;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 /* Calculate the final parameters for this audio specification */
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
432 #ifdef PA_STREAM_ADJUST_LATENCY
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
433 spec->samples /= 2; /* Mix in smaller chunck to avoid underruns */
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
434 #endif
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 SDL_CalculateAudioSpec(spec);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437 /* Allocate mixing buffer */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 mixlen = spec->size;
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 if ( mixbuf == NULL ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441 return(-1);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 SDL_memset(mixbuf, spec->silence, spec->size);
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
444
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 /* Reduced prebuffering compared to the defaults. */
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
446 #ifdef PA_STREAM_ADJUST_LATENCY
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
447 paattr.tlength = mixlen * 4; /* 2x original requested bufsize */
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
448 paattr.prebuf = -1;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
449 paattr.maxlength = -1;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
450 paattr.minreq = mixlen; /* -1 can lead to pa_stream_writable_size()
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
451 >= mixlen never becoming true */
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
452 flags = PA_STREAM_ADJUST_LATENCY;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
453 #else
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
454 paattr.tlength = mixlen*2;
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
455 paattr.prebuf = mixlen*2;
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
456 paattr.maxlength = mixlen*2;
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
457 paattr.minreq = mixlen;
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
458 #endif
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
459
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460 /* The SDL ALSA output hints us that we use Windows' channel mapping */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
461 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 SDL_NAME(pa_channel_map_init_auto)(
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 &pacmap, spec->channels, PA_CHANNEL_MAP_WAVEEX);
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
464
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
465 /* Set up a new main loop */
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
466 if (!(mainloop = SDL_NAME(pa_mainloop_new)())) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
467 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
468 SDL_SetError("pa_mainloop_new() failed");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
469 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
470 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
471
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
472 mainloop_api = SDL_NAME(pa_mainloop_get_api)(mainloop);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
473 if (!(context = SDL_NAME(pa_context_new)(mainloop_api, get_progname()))) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
474 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
475 SDL_SetError("pa_context_new() failed");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
476 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
477 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
478
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479 /* Connect to the PulseAudio server */
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
480 if (SDL_NAME(pa_context_connect)(context, NULL, 0, NULL) < 0) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
481 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
482 SDL_SetError("Could not setup connection to PulseAudio");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
483 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
484 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
485
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
486 do {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
487 if (SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
488 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
489 SDL_SetError("pa_mainloop_iterate() failed");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
490 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
491 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
492 state = SDL_NAME(pa_context_get_state)(context);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
493 if (!PA_CONTEXT_IS_GOOD(state)) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
494 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
495 SDL_SetError("Could not connect to PulseAudio");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
496 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
497 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
498 } while (state != PA_CONTEXT_READY);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
499
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
500 stream = SDL_NAME(pa_stream_new)(
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
501 context,
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 "Simple DirectMedia Layer", /* stream description */
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 &paspec, /* sample format spec */
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
504 &pacmap /* channel map */
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 );
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 if ( stream == NULL ) {
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507 PULSE_CloseAudio(this);
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
508 SDL_SetError("Could not setup PulseAudio stream");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
509 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
510 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
511
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
512 if (SDL_NAME(pa_stream_connect_playback)(stream, NULL, &paattr, flags,
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
513 NULL, NULL) < 0) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
514 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
515 SDL_SetError("Could not connect PulseAudio stream");
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 return(-1);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 }
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518
4216
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
519 do {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
520 if (SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
521 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
522 SDL_SetError("pa_mainloop_iterate() failed");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
523 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
524 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
525 state = SDL_NAME(pa_stream_get_state)(stream);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
526 if (!PA_STREAM_IS_GOOD(state)) {
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
527 PULSE_CloseAudio(this);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
528 SDL_SetError("Could not create to PulseAudio stream");
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
529 return(-1);
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
530 }
5b99971a27b4 Fixed bug #698
Sam Lantinga <slouken@libsdl.org>
parents: 4211
diff changeset
531 } while (state != PA_STREAM_READY);
4211
3ce5bfddbaf6 Fixed bug #572
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
532
3939
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 return(0);
42e83d81224b Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 }