Mercurial > sdl-ios-xcode
annotate src/audio/pulse/SDL_pulseaudio.c @ 4557:4aa31b9207f2 SDL-1.2
Finally fixed bug 894 without breaking bug 716. Yay! :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 20 Jul 2010 00:01:26 -0700 |
parents | 9134017bac3a |
children |
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 | 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 | 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 | 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 | 58 static void PULSE_WaitDone(_THIS); |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
59 static void PULSE_SetCaption(_THIS, const char *str); |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 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
|
64 static void *pulse_handle = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 static int pulse_loaded = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 static pa_simple* (*SDL_NAME(pa_simple_new))( |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 const char *server, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 const char *name, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 pa_stream_direction_t dir, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 const char *dev, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 const char *stream_name, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 const pa_sample_spec *ss, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 const pa_channel_map *map, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 const pa_buffer_attr *attr, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 int *error |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 static void (*SDL_NAME(pa_simple_free))(pa_simple *s); |
4216 | 79 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 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
|
81 pa_channel_map *m, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 unsigned channels, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 pa_channel_map_def_t def |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 ); |
4211 | 85 |
4396
f5d3f7fa071d
1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents:
4344
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 static void (*SDL_NAME(pa_mainloop_free))(pa_mainloop *m); |
4216 | 90 |
4396
f5d3f7fa071d
1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents:
4344
diff
changeset
|
91 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
|
92 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
|
93 static void (*SDL_NAME(pa_operation_unref))(pa_operation *o); |
4216 | 94 |
4396
f5d3f7fa071d
1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents:
4344
diff
changeset
|
95 static pa_context * (*SDL_NAME(pa_context_new))( |
4216 | 96 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
|
97 static int (*SDL_NAME(pa_context_connect))( |
4216 | 98 pa_context *c, const char *server, |
99 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
|
100 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
|
101 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
|
102 static void (*SDL_NAME(pa_context_unref))(pa_context *c); |
4216 | 103 |
4396
f5d3f7fa071d
1.2 pulseaudio: make some function pointers static.
Ryan C. Gordon <icculus@icculus.org>
parents:
4344
diff
changeset
|
104 static pa_stream * (*SDL_NAME(pa_stream_new))(pa_context *c, |
4216 | 105 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
|
106 static int (*SDL_NAME(pa_stream_connect_playback))(pa_stream *s, const char *dev, |
4216 | 107 const pa_buffer_attr *attr, pa_stream_flags_t flags, |
108 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
|
109 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
|
110 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
|
111 static int (*SDL_NAME(pa_stream_write))(pa_stream *s, const void *data, size_t nbytes, |
4216 | 112 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
|
113 static pa_operation * (*SDL_NAME(pa_stream_drain))(pa_stream *s, |
4216 | 114 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
|
115 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
|
116 static void (*SDL_NAME(pa_stream_unref))(pa_stream *s); |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
117 static pa_operation* (*SDL_NAME(pa_context_set_name))(pa_context *c, |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
118 const char *name, pa_context_success_cb_t cb, void *userdata); |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 static struct { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 const char *name; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 void **func; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 } pulse_functions[] = { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 { "pa_simple_new", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 (void **)&SDL_NAME(pa_simple_new) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 { "pa_simple_free", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 (void **)&SDL_NAME(pa_simple_free) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 { "pa_channel_map_init_auto", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 (void **)&SDL_NAME(pa_channel_map_init_auto) }, |
4216 | 130 { "pa_mainloop_new", |
131 (void **)&SDL_NAME(pa_mainloop_new) }, | |
132 { "pa_mainloop_get_api", | |
133 (void **)&SDL_NAME(pa_mainloop_get_api) }, | |
134 { "pa_mainloop_iterate", | |
135 (void **)&SDL_NAME(pa_mainloop_iterate) }, | |
136 { "pa_mainloop_free", | |
137 (void **)&SDL_NAME(pa_mainloop_free) }, | |
138 { "pa_operation_get_state", | |
139 (void **)&SDL_NAME(pa_operation_get_state) }, | |
140 { "pa_operation_cancel", | |
141 (void **)&SDL_NAME(pa_operation_cancel) }, | |
142 { "pa_operation_unref", | |
143 (void **)&SDL_NAME(pa_operation_unref) }, | |
144 { "pa_context_new", | |
145 (void **)&SDL_NAME(pa_context_new) }, | |
146 { "pa_context_connect", | |
147 (void **)&SDL_NAME(pa_context_connect) }, | |
148 { "pa_context_get_state", | |
149 (void **)&SDL_NAME(pa_context_get_state) }, | |
150 { "pa_context_disconnect", | |
151 (void **)&SDL_NAME(pa_context_disconnect) }, | |
152 { "pa_context_unref", | |
153 (void **)&SDL_NAME(pa_context_unref) }, | |
154 { "pa_stream_new", | |
155 (void **)&SDL_NAME(pa_stream_new) }, | |
156 { "pa_stream_connect_playback", | |
157 (void **)&SDL_NAME(pa_stream_connect_playback) }, | |
158 { "pa_stream_get_state", | |
159 (void **)&SDL_NAME(pa_stream_get_state) }, | |
160 { "pa_stream_writable_size", | |
161 (void **)&SDL_NAME(pa_stream_writable_size) }, | |
162 { "pa_stream_write", | |
163 (void **)&SDL_NAME(pa_stream_write) }, | |
164 { "pa_stream_drain", | |
165 (void **)&SDL_NAME(pa_stream_drain) }, | |
166 { "pa_stream_disconnect", | |
167 (void **)&SDL_NAME(pa_stream_disconnect) }, | |
168 { "pa_stream_unref", | |
169 (void **)&SDL_NAME(pa_stream_unref) }, | |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
170 { "pa_context_set_name", |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
171 (void **)&SDL_NAME(pa_context_set_name) }, |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 }; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 static void UnloadPulseLibrary() |
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 if ( pulse_loaded ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 SDL_UnloadObject(pulse_handle); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 pulse_handle = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 pulse_loaded = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 } |
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 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 static int LoadPulseLibrary(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 int i, retval = -1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 pulse_handle = SDL_LoadObject(pulse_library); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 if ( pulse_handle ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 pulse_loaded = 1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 retval = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 for ( i=0; i<SDL_arraysize(pulse_functions); ++i ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 *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
|
193 if ( !*pulse_functions[i].func ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 retval = -1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 UnloadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 break; |
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 } |
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 return retval; |
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 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 #else |
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 void UnloadPulseLibrary() |
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; |
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 static int LoadPulseLibrary(void) |
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 return 0; |
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 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 #endif /* SDL_AUDIO_DRIVER_PULSE_DYNAMIC */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 /* Audio driver bootstrap functions */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 static int Audio_Available(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 pa_sample_spec paspec; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 pa_simple *connection; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 int available; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 available = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 if ( LoadPulseLibrary() < 0 ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 return available; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 } |
4211 | 229 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 /* Connect with a dummy format. */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 paspec.format = PA_SAMPLE_U8; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 paspec.rate = 11025; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 paspec.channels = 1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 connection = SDL_NAME(pa_simple_new)( |
4211 | 235 NULL, /* server */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 "Test stream", /* application name */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 PA_STREAM_PLAYBACK, /* playback mode */ |
4211 | 238 NULL, /* device on the server */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 "Simple DirectMedia Layer", /* stream description */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 &paspec, /* sample format spec */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 NULL, /* channel map */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 NULL, /* buffering attributes */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 NULL /* error code */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 if ( connection != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 available = 1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 SDL_NAME(pa_simple_free)(connection); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 } |
4211 | 249 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 UnloadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 return(available); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 static void Audio_DeleteDevice(SDL_AudioDevice *device) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 { |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
256 SDL_free(device->hidden->caption); |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 SDL_free(device->hidden); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 SDL_free(device); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 UnloadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 static SDL_AudioDevice *Audio_CreateDevice(int devindex) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 SDL_AudioDevice *this; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 /* Initialize all variables that we clean on shutdown */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 LoadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 if ( this ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 SDL_memset(this, 0, (sizeof *this)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 this->hidden = (struct SDL_PrivateAudioData *) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 SDL_malloc((sizeof *this->hidden)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 if ( (this == NULL) || (this->hidden == NULL) ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 SDL_OutOfMemory(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 if ( this ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 SDL_free(this); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 return(0); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 /* Set the function pointers */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 this->OpenAudio = PULSE_OpenAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 this->WaitAudio = PULSE_WaitAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 this->PlayAudio = PULSE_PlayAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 this->GetAudioBuf = PULSE_GetAudioBuf; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 this->CloseAudio = PULSE_CloseAudio; |
4216 | 289 this->WaitDone = PULSE_WaitDone; |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
290 this->SetCaption = PULSE_SetCaption; |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 this->free = Audio_DeleteDevice; |
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 return this; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 AudioBootStrap PULSE_bootstrap = { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 PULSE_DRIVER_NAME, "PulseAudio", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 Audio_Available, Audio_CreateDevice |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 }; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 /* 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
|
303 static void PULSE_WaitAudio(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 { |
4216 | 305 int size; |
306 while(1) { | |
307 if (SDL_NAME(pa_context_get_state)(context) != PA_CONTEXT_READY || | |
308 SDL_NAME(pa_stream_get_state)(stream) != PA_STREAM_READY || | |
309 SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { | |
310 this->enabled = 0; | |
311 return; | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 } |
4216 | 313 size = SDL_NAME(pa_stream_writable_size)(stream); |
314 if (size >= mixlen) | |
315 return; | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 } |
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 void PULSE_PlayAudio(_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 /* Write the audio data */ |
4216 | 322 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
|
323 this->enabled = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 } |
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 static Uint8 *PULSE_GetAudioBuf(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 return(mixbuf); |
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 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 static void PULSE_CloseAudio(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 if ( mixbuf != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 SDL_FreeAudioMem(mixbuf); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 mixbuf = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 if ( stream != NULL ) { |
4216 | 338 SDL_NAME(pa_stream_disconnect)(stream); |
339 SDL_NAME(pa_stream_unref)(stream); | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 stream = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 } |
4216 | 342 if (context != NULL) { |
343 SDL_NAME(pa_context_disconnect)(context); | |
344 SDL_NAME(pa_context_unref)(context); | |
345 context = NULL; | |
346 } | |
347 if (mainloop != NULL) { | |
348 SDL_NAME(pa_mainloop_free)(mainloop); | |
349 mainloop = NULL; | |
350 } | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 /* Try to get the name of the program */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 static char *get_progname(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 { |
4344
14f95e514408
patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents:
4216
diff
changeset
|
356 #ifdef __LINUX__ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 char *progname = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 FILE *fp; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 static char temp[BUFSIZ]; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 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
|
362 fp = fopen(temp, "r"); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 if ( fp != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 if ( fgets(temp, sizeof(temp)-1, fp) ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 progname = SDL_strrchr(temp, '/'); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 if ( progname == NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 progname = temp; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 } else { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 progname = progname+1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 fclose(fp); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 } |
4344
14f95e514408
patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents:
4216
diff
changeset
|
374 return(progname); |
14f95e514408
patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents:
4216
diff
changeset
|
375 #elif defined(__NetBSD__) |
14f95e514408
patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents:
4216
diff
changeset
|
376 return getprogname(); |
14f95e514408
patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents:
4216
diff
changeset
|
377 #else |
14f95e514408
patch-pulse (from ahoka@NetBSD.org):
Sam Lantinga <slouken@libsdl.org>
parents:
4216
diff
changeset
|
378 return("unknown"); |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 #endif |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
382 static void caption_set_complete(pa_context *c, int success, void *userdata) |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
383 { |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
384 /* no-op. */ |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
385 } |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
386 |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
387 static void PULSE_SetCaption(_THIS, const char *str) |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
388 { |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
389 SDL_free(this->hidden->caption); |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
390 if ((str == NULL) || (*str == '\0')) { |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
391 str = get_progname(); /* set a default so SOMETHING shows up. */ |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
392 } |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
393 this->hidden->caption = SDL_strdup(str); |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
394 if (context != NULL) { |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
395 SDL_NAME(pa_context_set_name)(context, this->hidden->caption, |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
396 caption_set_complete, 0); |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
397 } |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
398 } |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
399 |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
400 static void stream_drain_complete(pa_stream *s, int success, void *userdata) |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
401 { |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
402 /* no-op. */ |
4216 | 403 } |
404 | |
405 static void PULSE_WaitDone(_THIS) | |
406 { | |
407 pa_operation *o; | |
408 | |
409 o = SDL_NAME(pa_stream_drain)(stream, stream_drain_complete, NULL); | |
410 if (!o) | |
411 return; | |
412 | |
413 while (SDL_NAME(pa_operation_get_state)(o) != PA_OPERATION_DONE) { | |
414 if (SDL_NAME(pa_context_get_state)(context) != PA_CONTEXT_READY || | |
415 SDL_NAME(pa_stream_get_state)(stream) != PA_STREAM_READY || | |
416 SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { | |
417 SDL_NAME(pa_operation_cancel)(o); | |
418 break; | |
419 } | |
420 } | |
421 SDL_NAME(pa_operation_unref)(o); | |
422 } | |
423 | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 { |
4216 | 426 int state; |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 Uint16 test_format; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 pa_sample_spec paspec; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 pa_buffer_attr paattr; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
430 pa_channel_map pacmap; |
4216 | 431 pa_stream_flags_t flags = 0; |
4211 | 432 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
433 paspec.format = PA_SAMPLE_INVALID; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
434 for ( test_format = SDL_FirstAudioFormat(spec->format); test_format; ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
435 switch ( test_format ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
436 case AUDIO_U8: |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 paspec.format = PA_SAMPLE_U8; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 case AUDIO_S16LSB: |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
440 paspec.format = PA_SAMPLE_S16LE; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 case AUDIO_S16MSB: |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 paspec.format = PA_SAMPLE_S16BE; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 if ( paspec.format != PA_SAMPLE_INVALID ) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 if (paspec.format == PA_SAMPLE_INVALID ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 SDL_SetError("Couldn't find any suitable audio formats"); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 return(-1); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
452 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
453 spec->format = test_format; |
4211 | 454 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 paspec.channels = spec->channels; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 paspec.rate = spec->freq; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 /* Calculate the final parameters for this audio specification */ |
4216 | 459 #ifdef PA_STREAM_ADJUST_LATENCY |
460 spec->samples /= 2; /* Mix in smaller chunck to avoid underruns */ | |
461 #endif | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 SDL_CalculateAudioSpec(spec); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
463 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
464 /* Allocate mixing buffer */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
465 mixlen = spec->size; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
467 if ( mixbuf == NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 return(-1); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
469 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
470 SDL_memset(mixbuf, spec->silence, spec->size); |
4211 | 471 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
472 /* Reduced prebuffering compared to the defaults. */ |
4216 | 473 #ifdef PA_STREAM_ADJUST_LATENCY |
474 paattr.tlength = mixlen * 4; /* 2x original requested bufsize */ | |
475 paattr.prebuf = -1; | |
476 paattr.maxlength = -1; | |
477 paattr.minreq = mixlen; /* -1 can lead to pa_stream_writable_size() | |
478 >= mixlen never becoming true */ | |
479 flags = PA_STREAM_ADJUST_LATENCY; | |
480 #else | |
4211 | 481 paattr.tlength = mixlen*2; |
482 paattr.prebuf = mixlen*2; | |
483 paattr.maxlength = mixlen*2; | |
4216 | 484 paattr.minreq = mixlen; |
485 #endif | |
4211 | 486 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
487 /* 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
|
488 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
489 SDL_NAME(pa_channel_map_init_auto)( |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
490 &pacmap, spec->channels, PA_CHANNEL_MAP_WAVEEX); |
4211 | 491 |
4216 | 492 /* Set up a new main loop */ |
493 if (!(mainloop = SDL_NAME(pa_mainloop_new)())) { | |
494 PULSE_CloseAudio(this); | |
495 SDL_SetError("pa_mainloop_new() failed"); | |
496 return(-1); | |
497 } | |
498 | |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
499 if (this->hidden->caption == NULL) { |
4400
9134017bac3a
PulseAudio: get the window title for the context name if it wasn't set already.
Ryan C. Gordon <icculus@icculus.org>
parents:
4398
diff
changeset
|
500 char *title = NULL; |
9134017bac3a
PulseAudio: get the window title for the context name if it wasn't set already.
Ryan C. Gordon <icculus@icculus.org>
parents:
4398
diff
changeset
|
501 SDL_WM_GetCaption(&title, NULL); |
9134017bac3a
PulseAudio: get the window title for the context name if it wasn't set already.
Ryan C. Gordon <icculus@icculus.org>
parents:
4398
diff
changeset
|
502 PULSE_SetCaption(this, title); |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
503 } |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
504 |
4216 | 505 mainloop_api = SDL_NAME(pa_mainloop_get_api)(mainloop); |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
506 if (!(context = SDL_NAME(pa_context_new)(mainloop_api, |
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
507 this->hidden->caption))) { |
4216 | 508 PULSE_CloseAudio(this); |
509 SDL_SetError("pa_context_new() failed"); | |
510 return(-1); | |
511 } | |
512 | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
513 /* Connect to the PulseAudio server */ |
4216 | 514 if (SDL_NAME(pa_context_connect)(context, NULL, 0, NULL) < 0) { |
515 PULSE_CloseAudio(this); | |
4398
fe15c4e8efe6
1.2: let PulseAudio hook into SDL_WM_SetCaption().
Ryan C. Gordon <icculus@icculus.org>
parents:
4396
diff
changeset
|
516 SDL_SetError("Could not setup connection to PulseAudio"); |
4216 | 517 return(-1); |
518 } | |
519 | |
520 do { | |
521 if (SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { | |
522 PULSE_CloseAudio(this); | |
523 SDL_SetError("pa_mainloop_iterate() failed"); | |
524 return(-1); | |
525 } | |
526 state = SDL_NAME(pa_context_get_state)(context); | |
527 if (!PA_CONTEXT_IS_GOOD(state)) { | |
528 PULSE_CloseAudio(this); | |
529 SDL_SetError("Could not connect to PulseAudio"); | |
530 return(-1); | |
531 } | |
532 } while (state != PA_CONTEXT_READY); | |
533 | |
534 stream = SDL_NAME(pa_stream_new)( | |
535 context, | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
536 "Simple DirectMedia Layer", /* stream description */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 &paspec, /* sample format spec */ |
4216 | 538 &pacmap /* channel map */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
540 if ( stream == NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 PULSE_CloseAudio(this); |
4216 | 542 SDL_SetError("Could not setup PulseAudio stream"); |
543 return(-1); | |
544 } | |
545 | |
546 if (SDL_NAME(pa_stream_connect_playback)(stream, NULL, &paattr, flags, | |
547 NULL, NULL) < 0) { | |
548 PULSE_CloseAudio(this); | |
549 SDL_SetError("Could not connect PulseAudio stream"); | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
550 return(-1); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
551 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
552 |
4216 | 553 do { |
554 if (SDL_NAME(pa_mainloop_iterate)(mainloop, 1, NULL) < 0) { | |
555 PULSE_CloseAudio(this); | |
556 SDL_SetError("pa_mainloop_iterate() failed"); | |
557 return(-1); | |
558 } | |
559 state = SDL_NAME(pa_stream_get_state)(stream); | |
560 if (!PA_STREAM_IS_GOOD(state)) { | |
561 PULSE_CloseAudio(this); | |
562 SDL_SetError("Could not create to PulseAudio stream"); | |
563 return(-1); | |
564 } | |
565 } while (state != PA_STREAM_READY); | |
4211 | 566 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
567 return(0); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
568 } |