Mercurial > sdl-ios-xcode
annotate src/audio/pulseaudio/SDL_pulseaudio.c @ 2272:25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
error messages if connction to daemon fails.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 20 Aug 2007 02:08:37 +0000 |
parents | 60b4c52a7906 |
children | aedfcdeb69b6 |
rev | line source |
---|---|
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 Sam Lantinga |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 /* |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 The PulseAudio target for SDL 1.3 is based on the 1.3 arts target, with |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 the appropriate parts replaced with the 1.2 PulseAudio target code. This |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 was the cleanest way to move it to 1.3. The 1.2 target was written by |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 Stéphan Kochen: stephan .a.t. kochen.nl |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #include "SDL_config.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 /* Allow access to a raw mixing buffer */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 #ifdef HAVE_SIGNAL_H |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 #include <signal.h> |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 #endif |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 #include <unistd.h> |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 #include <sys/types.h> |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 #include <errno.h> |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 #include <pulse/simple.h> |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 #include "SDL_timer.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 #include "SDL_audio.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 #include "../SDL_audiomem.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 #include "../SDL_audio_c.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 #include "SDL_pulseaudio.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 #ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 #include "SDL_name.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 #include "SDL_loadso.h" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 #else |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 #define SDL_NAME(X) X |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 #endif |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 /* The tag name used by pulse audio */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 #define PULSEAUDIO_DRIVER_NAME "pulseaudio" |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 #ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 static void *pulse_handle = NULL; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 /* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 static pa_simple* (*SDL_NAME(pa_simple_new))( |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 const char *server, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 const char *name, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 pa_stream_direction_t dir, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 const char *dev, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 const char *stream_name, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 const pa_sample_spec *ss, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 const pa_channel_map *map, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 const pa_buffer_attr *attr, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 int *error |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 ); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 static void (*SDL_NAME(pa_simple_free))(pa_simple *s); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 static int (*SDL_NAME(pa_simple_drain))(pa_simple *s, int *error); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 static int (*SDL_NAME(pa_simple_write))( |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 pa_simple *s, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 const void *data, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 size_t length, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 int *error |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 ); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))( |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 pa_channel_map *m, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 unsigned channels, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 pa_channel_map_def_t def |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 ); |
2272
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
88 static const char* (*SDL_NAME(pa_strerror))(int error); |
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 #define SDL_PULSEAUDIO_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 static struct { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 const char *name; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 void **func; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 } pulse_functions[] = { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 /* *INDENT-OFF* */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 SDL_PULSEAUDIO_SYM(pa_simple_new), |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 SDL_PULSEAUDIO_SYM(pa_simple_free), |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 SDL_PULSEAUDIO_SYM(pa_simple_drain), |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 SDL_PULSEAUDIO_SYM(pa_simple_write), |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto), |
2272
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
102 SDL_PULSEAUDIO_SYM(pa_strerror), |
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 /* *INDENT-ON* */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 }; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 #undef SDL_PULSEAUDIO_SYM |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 UnloadPulseLibrary() |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 if (pulse_handle != NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 SDL_UnloadObject(pulse_handle); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 pulse_handle = NULL; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 static int |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 LoadPulseLibrary(void) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 int i, retval = -1; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 if (pulse_handle == NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 pulse_handle = SDL_LoadObject(pulse_library); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 if (pulse_handle != NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 retval = 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 for (i = 0; i < SDL_arraysize(pulse_functions); ++i) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 *pulse_functions[i].func = |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 SDL_LoadFunction(pulse_handle, pulse_functions[i].name); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 if (!*pulse_functions[i].func) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 retval = -1; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 UnloadPulseLibrary(); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 break; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 return retval; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 #else |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 UnloadPulseLibrary() |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 return; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 static int |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 LoadPulseLibrary(void) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 return 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 #endif /* SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 /* This function waits until it is possible to write a full sound buffer */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 PULSEAUDIO_WaitDevice(_THIS) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 Sint32 ticks; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 /* Check to see if the thread-parent process is still alive */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 static int cnt = 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 /* Note that this only works with thread implementations |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 that use a different process id for each thread. |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 /* Check every 10 loops */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 if (this->hidden->parent && (((++cnt) % 10) == 0)) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 if (kill(this->hidden->parent, 0) < 0) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 this->enabled = 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 /* Use timer for general audio synchronization */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 ticks = |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 if (ticks > 0) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 SDL_Delay(ticks); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 PULSEAUDIO_PlayDevice(_THIS) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 /* Write the audio data */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 if ( SDL_NAME(pa_simple_write)(this->hidden->stream, this->hidden->mixbuf, |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 this->hidden->mixlen, NULL) != 0 ) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 this->enabled = 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 PULSEAUDIO_WaitDone(_THIS) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 SDL_NAME(pa_simple_drain)(this->hidden->stream, NULL); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 static Uint8 * |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 PULSEAUDIO_GetDeviceBuf(_THIS) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 return (this->hidden->mixbuf); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 PULSEAUDIO_CloseDevice(_THIS) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 if (this->hidden != NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 if (this->hidden->mixbuf != NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 SDL_FreeAudioMem(this->hidden->mixbuf); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 this->hidden->mixbuf = NULL; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 if (this->hidden->stream) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 SDL_NAME(pa_simple_drain)(this->hidden->stream, NULL); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 SDL_NAME(pa_simple_free)(this->hidden->stream); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 this->hidden->stream = NULL; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 SDL_free(this->hidden); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 this->hidden = NULL; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 /* !!! FIXME: this could probably be expanded. */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 /* Try to get the name of the program */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 static char *get_progname(void) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 char *progname = NULL; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 #ifdef __LINUX__ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 FILE *fp; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 static char temp[BUFSIZ]; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid()); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 fp = fopen(temp, "r"); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 if ( fp != NULL ) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 if ( fgets(temp, sizeof(temp)-1, fp) ) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 progname = SDL_strrchr(temp, '/'); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 if ( progname == NULL ) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 progname = temp; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 } else { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 progname = progname+1; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 fclose(fp); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 #endif |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 return(progname); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 static int |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 { |
2272
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
258 Uint16 test_format = 0; |
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
259 pa_sample_spec paspec; |
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
260 pa_buffer_attr paattr; |
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
261 pa_channel_map pacmap; |
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
262 int err = 0; |
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 /* Initialize all variables that we clean on shutdown */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 this->hidden = (struct SDL_PrivateAudioData *) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 SDL_malloc((sizeof *this->hidden)); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 if (this->hidden == NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 SDL_OutOfMemory(); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 return 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 paspec.format = PA_SAMPLE_INVALID; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 /* Try for a closest match on audio format */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 for (test_format = SDL_FirstAudioFormat(this->spec.format); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 (paspec.format == PA_SAMPLE_INVALID) && test_format;) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 #ifdef DEBUG_AUDIO |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 fprintf(stderr, "Trying format 0x%4.4x\n", test_format); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 #endif |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 switch ( test_format ) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 case AUDIO_U8: |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 paspec.format = PA_SAMPLE_U8; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 break; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 case AUDIO_S16LSB: |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 paspec.format = PA_SAMPLE_S16LE; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 break; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 case AUDIO_S16MSB: |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 paspec.format = PA_SAMPLE_S16BE; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 break; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 default: |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 paspec.format = PA_SAMPLE_INVALID; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 break; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 if (paspec.format == PA_SAMPLE_INVALID) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 test_format = SDL_NextAudioFormat(); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 if (paspec.format == PA_SAMPLE_INVALID) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 PULSEAUDIO_CloseDevice(this); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 SDL_SetError("Couldn't find any hardware audio formats"); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 return 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 this->spec.format = test_format; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 /* Calculate the final parameters for this audio specification */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 SDL_CalculateAudioSpec(&this->spec); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 /* Allocate mixing buffer */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 this->hidden->mixlen = this->spec.size; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 if (this->hidden->mixbuf == NULL) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 PULSEAUDIO_CloseDevice(this); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 SDL_OutOfMemory(); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 return 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 paspec.channels = this->spec.channels; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 paspec.rate = this->spec.freq; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 /* Reduced prebuffering compared to the defaults. */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 paattr.tlength = this->hidden->mixlen; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 paattr.minreq = this->hidden->mixlen; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 paattr.fragsize = this->hidden->mixlen; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 paattr.prebuf = this->hidden->mixlen; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 paattr.maxlength = this->hidden->mixlen * 4; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 /* The SDL ALSA output hints us that we use Windows' channel mapping */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 SDL_NAME(pa_channel_map_init_auto)( |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 &pacmap, this->spec.channels, PA_CHANNEL_MAP_WAVEEX); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 /* Connect to the PulseAudio server */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 this->hidden->stream = SDL_NAME(pa_simple_new)( |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 SDL_getenv("PASERVER"), /* server */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 get_progname(), /* application name */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 PA_STREAM_PLAYBACK, /* playback mode */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 SDL_getenv("PADEVICE"), /* device on the server */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 "Simple DirectMedia Layer", /* stream description */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 &paspec, /* sample format spec */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 &pacmap, /* channel map */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 &paattr, /* buffering attributes */ |
2272
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
344 &err /* error code */ |
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 ); |
2272
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
346 |
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 if ( this->hidden->stream == NULL ) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
348 PULSEAUDIO_CloseDevice(this); |
2272
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
349 SDL_SetError("Could not connect to PulseAudio: %s", |
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
350 SDL_NAME(pa_strerror(err))); |
25a87553a59d
Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents:
2271
diff
changeset
|
351 return 0; |
2271
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 /* Get the parent process id (we're the parent of the audio thread) */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 this->hidden->parent = getpid(); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
356 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 /* We're ready to rock and roll. :-) */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 return 1; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 static void |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 PULSEAUDIO_Deinitialize(void) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 UnloadPulseLibrary(); |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 static int |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 PULSEAUDIO_Init(SDL_AudioDriverImpl * impl) |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 if (LoadPulseLibrary() < 0) { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 return 0; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 /* Set the function pointers */ |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 impl->OpenDevice = PULSEAUDIO_OpenDevice; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 impl->PlayDevice = PULSEAUDIO_PlayDevice; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 impl->WaitDevice = PULSEAUDIO_WaitDevice; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 impl->GetDeviceBuf = PULSEAUDIO_GetDeviceBuf; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 impl->CloseDevice = PULSEAUDIO_CloseDevice; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 impl->WaitDone = PULSEAUDIO_WaitDone; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 impl->Deinitialize = PULSEAUDIO_Deinitialize; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 impl->OnlyHasDefaultOutputDevice = 1; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 return 1; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 } |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 AudioBootStrap PULSEAUDIO_bootstrap = { |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 PULSEAUDIO_DRIVER_NAME, "PulseAudio", PULSEAUDIO_Init, 0 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 }; |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
60b4c52a7906
Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
394 /* vi: set ts=4 sw=4 expandtab: */ |