annotate src/audio/pulseaudio/SDL_pulseaudio.c @ 3672:878d8adf2fde

Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates. This pulls all the PulseAudio reworking that was done for 1.2.14 into 1.3. Fixes Bugzilla #801.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 17 Jan 2010 06:14:04 +0000
parents b21348d47cab
children c9d5bd1b4e18
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
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2274
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
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
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>
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
40 #include <pulse/pulseaudio.h>
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
41 #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
42
60b4c52a7906 Ported 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_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
44 #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
45 #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
46 #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
47 #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
48
60b4c52a7906 Ported 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 #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
50 #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
51 #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
52 #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
53 #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
54 #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
55
60b4c52a7906 Ported 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 /* 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
57 #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
58
60b4c52a7906 Ported 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 #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
60
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
61 #if (PA_API_VERSION < 12)
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
62 /** Return non-zero if the passed state is one of the connected states */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
63 static inline int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
64 return
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
65 x == PA_CONTEXT_CONNECTING ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
66 x == PA_CONTEXT_AUTHORIZING ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
67 x == PA_CONTEXT_SETTING_NAME ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
68 x == PA_CONTEXT_READY;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
69 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
70 /** Return non-zero if the passed state is one of the connected states */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
71 static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
72 return
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
73 x == PA_STREAM_CREATING ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
74 x == PA_STREAM_READY;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
75 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
76 #endif /* pulseaudio <= 0.9.10 */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
77
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
78 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
79 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
80
60b4c52a7906 Ported 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 /* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
82 static pa_simple *(*SDL_NAME(pa_simple_new)) (const char *server,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
83 const char *name,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
84 pa_stream_direction_t dir,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
85 const char *dev,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
86 const char *stream_name,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
87 const pa_sample_spec * ss,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
88 const pa_channel_map * map,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
89 const pa_buffer_attr * attr,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
90 int *error);
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
91 static void (*SDL_NAME(pa_simple_free)) (pa_simple * s);
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
92 static pa_channel_map *(*SDL_NAME(pa_channel_map_init_auto)) (pa_channel_map *
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
93 m,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
94 unsigned
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
95 channels,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
96 pa_channel_map_def_t
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
97 def);
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
98 static const char *(*SDL_NAME(pa_strerror)) (int error);
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
99 static pa_mainloop * (*SDL_NAME(pa_mainloop_new))(void);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
100 static pa_mainloop_api * (*SDL_NAME(pa_mainloop_get_api))(pa_mainloop *m);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
101 static int (*SDL_NAME(pa_mainloop_iterate))(pa_mainloop *m, int block, int *retval);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
102 static void (*SDL_NAME(pa_mainloop_free))(pa_mainloop *m);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
103
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
104 static pa_operation_state_t (*SDL_NAME(pa_operation_get_state))(pa_operation *o);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
105 static void (*SDL_NAME(pa_operation_cancel))(pa_operation *o);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
106 static void (*SDL_NAME(pa_operation_unref))(pa_operation *o);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
107
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
108 static pa_context * (*SDL_NAME(pa_context_new))(
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
109 pa_mainloop_api *m, const char *name);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
110 static int (*SDL_NAME(pa_context_connect))(
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
111 pa_context *c, const char *server,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
112 pa_context_flags_t flags, const pa_spawn_api *api);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
113 static pa_context_state_t (*SDL_NAME(pa_context_get_state))(pa_context *c);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
114 static void (*SDL_NAME(pa_context_disconnect))(pa_context *c);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
115 static void (*SDL_NAME(pa_context_unref))(pa_context *c);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
116
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
117 static pa_stream * (*SDL_NAME(pa_stream_new))(pa_context *c,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
118 const char *name, const pa_sample_spec *ss, const pa_channel_map *map);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
119 static int (*SDL_NAME(pa_stream_connect_playback))(pa_stream *s, const char *dev,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
120 const pa_buffer_attr *attr, pa_stream_flags_t flags,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
121 pa_cvolume *volume, pa_stream *sync_stream);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
122 static pa_stream_state_t (*SDL_NAME(pa_stream_get_state))(pa_stream *s);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
123 static size_t (*SDL_NAME(pa_stream_writable_size))(pa_stream *s);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
124 static int (*SDL_NAME(pa_stream_write))(pa_stream *s, const void *data, size_t nbytes,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
125 pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
126 static pa_operation * (*SDL_NAME(pa_stream_drain))(pa_stream *s,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
127 pa_stream_success_cb_t cb, void *userdata);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
128 static int (*SDL_NAME(pa_stream_disconnect))(pa_stream *s);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
129 static void (*SDL_NAME(pa_stream_unref))(pa_stream *s);
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
130
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 #define SDL_PULSEAUDIO_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
133 static struct
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
134 {
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
135 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
136 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
137 } 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
138 /* *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
139 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
140 SDL_PULSEAUDIO_SYM(pa_simple_free),
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
141 SDL_PULSEAUDIO_SYM(pa_mainloop_new),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
142 SDL_PULSEAUDIO_SYM(pa_mainloop_get_api),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
143 SDL_PULSEAUDIO_SYM(pa_mainloop_iterate),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
144 SDL_PULSEAUDIO_SYM(pa_mainloop_free),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
145 SDL_PULSEAUDIO_SYM(pa_operation_get_state),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
146 SDL_PULSEAUDIO_SYM(pa_operation_cancel),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
147 SDL_PULSEAUDIO_SYM(pa_operation_unref),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
148 SDL_PULSEAUDIO_SYM(pa_context_new),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
149 SDL_PULSEAUDIO_SYM(pa_context_connect),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
150 SDL_PULSEAUDIO_SYM(pa_context_get_state),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
151 SDL_PULSEAUDIO_SYM(pa_context_disconnect),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
152 SDL_PULSEAUDIO_SYM(pa_context_unref),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
153 SDL_PULSEAUDIO_SYM(pa_stream_new),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
154 SDL_PULSEAUDIO_SYM(pa_stream_connect_playback),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
155 SDL_PULSEAUDIO_SYM(pa_stream_get_state),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
156 SDL_PULSEAUDIO_SYM(pa_stream_writable_size),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
157 SDL_PULSEAUDIO_SYM(pa_stream_write),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
158 SDL_PULSEAUDIO_SYM(pa_stream_drain),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
159 SDL_PULSEAUDIO_SYM(pa_stream_disconnect),
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
160 SDL_PULSEAUDIO_SYM(pa_stream_unref),
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
161 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
162 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
163 /* *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
164 };
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
165
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
166 #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
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 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
169 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
170 {
60b4c52a7906 Ported 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 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
172 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
173 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
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
60b4c52a7906 Ported 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 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
178 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
179 {
60b4c52a7906 Ported 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 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
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 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
183 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
184 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
185 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
186 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
187 *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
188 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
189 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
190 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
191 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
192 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
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 }
60b4c52a7906 Ported 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 }
60b4c52a7906 Ported 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 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
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 #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
202
60b4c52a7906 Ported 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 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
204 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
205 {
60b4c52a7906 Ported 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 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
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 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
210 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
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 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
213 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 #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
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 /* 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
218 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
219 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
220 {
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
221 while(1) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
222 if (SDL_NAME(pa_context_get_state)(this->hidden->context) != PA_CONTEXT_READY ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
223 SDL_NAME(pa_stream_get_state)(this->hidden->stream) != PA_STREAM_READY ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
224 SDL_NAME(pa_mainloop_iterate)(this->hidden->mainloop, 1, NULL) < 0) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
225 this->enabled = 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
226 return;
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
227 }
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
228 if (SDL_NAME(pa_stream_writable_size)(this->hidden->stream) >= this->hidden->mixlen) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
229 return;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
230 }
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
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 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 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
235 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
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 /* Write the audio data */
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
238 if (SDL_NAME(pa_stream_write) (this->hidden->stream, this->hidden->mixbuf,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
239 this->hidden->mixlen, NULL, 0LL,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
240 PA_SEEK_RELATIVE) < 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
241 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
242 }
60b4c52a7906 Ported 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 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 static void
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
246 stream_drain_complete(pa_stream *s, int success, void *userdata)
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
247 {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
248 /* no-op for pa_stream_drain() to use for callback. */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
249 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
250
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
251 static void
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
252 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
253 {
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
254 pa_operation *o;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
255
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
256 o = SDL_NAME(pa_stream_drain)(this->hidden->stream, stream_drain_complete, NULL);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
257 if (!o) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
258 return;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
259 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
260
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
261 while (SDL_NAME(pa_operation_get_state)(o) != PA_OPERATION_DONE) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
262 if (SDL_NAME(pa_context_get_state)(this->hidden->context) != PA_CONTEXT_READY ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
263 SDL_NAME(pa_stream_get_state)(this->hidden->stream) != PA_STREAM_READY ||
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
264 SDL_NAME(pa_mainloop_iterate)(this->hidden->mainloop, 1, NULL) < 0) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
265 SDL_NAME(pa_operation_cancel)(o);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
266 break;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
267 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
268 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
269
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
270 SDL_NAME(pa_operation_unref)(o);
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
271 }
60b4c52a7906 Ported 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
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
274
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
275 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
276 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
277 {
60b4c52a7906 Ported 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 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
279 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 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
283 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
284 {
60b4c52a7906 Ported 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 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
286 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
287 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
288 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
289 }
60b4c52a7906 Ported 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 if (this->hidden->stream) {
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
291 SDL_NAME(pa_stream_disconnect)(this->hidden->stream);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
292 SDL_NAME(pa_stream_unref)(this->hidden->stream);
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
293 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
294 }
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
295 if (this->hidden->context != NULL) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
296 SDL_NAME(pa_context_disconnect)(this->hidden->context);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
297 SDL_NAME(pa_context_unref)(this->hidden->context);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
298 this->hidden->context = NULL;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
299 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
300 if (this->hidden->mainloop != NULL) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
301 SDL_NAME(pa_mainloop_free)(this->hidden->mainloop);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
302 this->hidden->mainloop = NULL;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
303 }
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
304 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
305 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
306 }
60b4c52a7906 Ported 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 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 /* !!! 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
311 /* Try to get the name of the program */
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
312 static char *
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
313 get_progname(void)
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
314 {
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
315 #ifdef __LINUX__
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
316 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
317 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
318 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
319
60b4c52a7906 Ported 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 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
321 fp = fopen(temp, "r");
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
322 if (fp != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
323 if (fgets(temp, sizeof(temp) - 1, fp)) {
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
324 progname = SDL_strrchr(temp, '/');
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
325 if (progname == NULL) {
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
326 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
327 } else {
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
328 progname = progname + 1;
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
329 }
60b4c52a7906 Ported 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 }
60b4c52a7906 Ported 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 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
332 }
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
333 return(progname);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
334 #elif defined(__NetBSD__)
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
335 return getprogname();
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
336 #else
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
337 return("unknown");
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
338 #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
339 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 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
343 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
344 {
2272
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
345 Uint16 test_format = 0;
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
346 pa_sample_spec paspec;
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
347 pa_buffer_attr paattr;
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
348 pa_channel_map pacmap;
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
349 pa_stream_flags_t flags = 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
350 int state = 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
351
60b4c52a7906 Ported 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 /* 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
353 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
354 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
355 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
356 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
357 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
358 }
60b4c52a7906 Ported 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 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
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 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
362
60b4c52a7906 Ported 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 /* 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
364 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
365 (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
366 #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
367 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
368 #endif
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
369 switch (test_format) {
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
370 case AUDIO_U8:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
371 paspec.format = PA_SAMPLE_U8;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
372 break;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
373 case AUDIO_S16LSB:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
374 paspec.format = PA_SAMPLE_S16LE;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
375 break;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
376 case AUDIO_S16MSB:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
377 paspec.format = PA_SAMPLE_S16BE;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
378 break;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
379 default:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
380 paspec.format = PA_SAMPLE_INVALID;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
381 break;
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
382 }
60b4c52a7906 Ported 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 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
384 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
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 }
60b4c52a7906 Ported 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 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
388 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
389 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
390 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
391 }
60b4c52a7906 Ported 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 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
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 /* Calculate the final parameters for this audio specification */
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
395 #ifdef PA_STREAM_ADJUST_LATENCY
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
396 this->spec.samples /= 2; /* Mix in smaller chunck to avoid underruns */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
397 #endif
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
398 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
399
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 /* 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
401 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
402 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
403 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
404 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
405 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
406 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
407 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 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
409
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 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
411 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
412
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 /* Reduced prebuffering compared to the defaults. */
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
414 #ifdef PA_STREAM_ADJUST_LATENCY
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
415 paattr.tlength = this->hidden->mixlen * 4; /* 2x original requested bufsize */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
416 paattr.prebuf = -1;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
417 paattr.maxlength = -1;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
418 /* -1 can lead to pa_stream_writable_size() >= this->hidden->mixlen never being true */
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
419 paattr.minreq = this->hidden->mixlen;
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
420 flags = PA_STREAM_ADJUST_LATENCY;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
421 #else
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
422 paattr.tlength = this->hidden->mixlen*2;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
423 paattr.prebuf = this->hidden->mixlen*2;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
424 paattr.maxlength = this->hidden->mixlen*2;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
425 paattr.minreq = this->hidden->mixlen;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
426 #endif
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
427
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 /* 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
429 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
430 SDL_NAME(pa_channel_map_init_auto) (&pacmap, this->spec.channels,
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
431 PA_CHANNEL_MAP_WAVEEX);
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
432
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
433 /* Set up a new main loop */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
434 if (!(this->hidden->mainloop = SDL_NAME(pa_mainloop_new)())) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
435 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
436 SDL_SetError("pa_mainloop_new() failed");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
437 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
438 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
439
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
440 this->hidden->mainloop_api = SDL_NAME(pa_mainloop_get_api)(this->hidden->mainloop);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
441 if (!(this->hidden->context = SDL_NAME(pa_context_new)(this->hidden->mainloop_api, get_progname()))) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
442 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
443 SDL_SetError("pa_context_new() failed");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
444 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
445 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
446
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
447 /* Connect to the PulseAudio server */
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
448 if (SDL_NAME(pa_context_connect)(this->hidden->context, NULL, 0, NULL) < 0) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
449 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
450 SDL_SetError("Could not setup connection to PulseAudio");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
451 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
452 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
453
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
454 do {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
455 if (SDL_NAME(pa_mainloop_iterate)(this->hidden->mainloop, 1, NULL) < 0) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
456 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
457 SDL_SetError("pa_mainloop_iterate() failed");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
458 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
459 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
460 state = SDL_NAME(pa_context_get_state)(this->hidden->context);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
461 if (!PA_CONTEXT_IS_GOOD(state)) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
462 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
463 SDL_SetError("Could not connect to PulseAudio");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
464 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
465 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
466 } while (state != PA_CONTEXT_READY);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
467
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
468 this->hidden->stream = SDL_NAME(pa_stream_new)(
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
469 this->hidden->context,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
470 "Simple DirectMedia Layer", /* stream description */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
471 &paspec, /* sample format spec */
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
472 &pacmap /* channel map */
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
473 );
2272
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
474
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
475 if (this->hidden->stream == NULL) {
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
476 PULSEAUDIO_CloseDevice(this);
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
477 SDL_SetError("Could not set up PulseAudio stream");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
478 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
479 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
480
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
481 if (SDL_NAME(pa_stream_connect_playback)(this->hidden->stream, NULL, &paattr, flags,
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
482 NULL, NULL) < 0) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
483 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
484 SDL_SetError("Could not connect PulseAudio stream");
2272
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
485 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
486 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487
3672
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
488 do {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
489 if (SDL_NAME(pa_mainloop_iterate)(this->hidden->mainloop, 1, NULL) < 0) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
490 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
491 SDL_SetError("pa_mainloop_iterate() failed");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
492 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
493 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
494 state = SDL_NAME(pa_stream_get_state)(this->hidden->stream);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
495 if (!PA_STREAM_IS_GOOD(state)) {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
496 PULSEAUDIO_CloseDevice(this);
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
497 SDL_SetError("Could not create to PulseAudio stream");
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
498 return 0;
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
499 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
500 } while (state != PA_STREAM_READY);
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
501
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 /* 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
503 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
504 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507 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
508 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
509 {
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 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
511 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514 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
515 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
516 {
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 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
518 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
519 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 /* 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
522 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
523 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
524 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
525 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
526 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
527 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
528 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
529 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
530
2938
2929ed239d2a Adjusted default choice of audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
531 /* !!! FIXME: should test if server is available here, return 2 if so. */
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
532 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
533 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 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
537 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
538 };
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540 /* vi: set ts=4 sw=4 expandtab: */