annotate src/audio/pulseaudio/SDL_pulseaudio.c @ 3673:c9d5bd1b4e18

Attempt to clean up PulseAudio dynamic loading support.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 17 Jan 2010 06:43:28 +0000
parents 878d8adf2fde
children 7b597182d06b
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 #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
49
60b4c52a7906 Ported 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 /* 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
51 #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
52
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
53 #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
54 /** 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
55 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
56 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
57 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
58 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
59 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
60 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
61 }
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_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
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_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
66 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
67 }
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 #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
69
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
70
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
71 static pa_simple *(*PULSEAUDIO_pa_simple_new) (const char *, const char *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
72 pa_stream_direction_t, const char *, const char *, const pa_sample_spec *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
73 const pa_channel_map *, const pa_buffer_attr *, int *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
74 static void (*PULSEAUDIO_pa_simple_free) (pa_simple *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
75 static pa_channel_map *(*PULSEAUDIO_pa_channel_map_init_auto) (
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
76 pa_channel_map *, unsigned, pa_channel_map_def_t);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
77 static const char * (*PULSEAUDIO_pa_strerror) (int);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
78 static pa_mainloop * (*PULSEAUDIO_pa_mainloop_new) (void);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
79 static pa_mainloop_api * (*PULSEAUDIO_pa_mainloop_get_api) (pa_mainloop *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
80 static int (*PULSEAUDIO_pa_mainloop_iterate) (pa_mainloop *, int, int *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
81 static void (*PULSEAUDIO_pa_mainloop_free) (pa_mainloop *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
82
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
83 static pa_operation_state_t (*PULSEAUDIO_pa_operation_get_state) (
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
84 pa_operation *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
85 static void (*PULSEAUDIO_pa_operation_cancel) (pa_operation *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
86 static void (*PULSEAUDIO_pa_operation_unref) (pa_operation *);
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
87
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
88 static pa_context * (*PULSEAUDIO_pa_context_new) (pa_mainloop_api *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
89 const char *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
90 static int (*PULSEAUDIO_pa_context_connect) (pa_context *, const char *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
91 pa_context_flags_t, const pa_spawn_api *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
92 static pa_context_state_t (*PULSEAUDIO_pa_context_get_state) (pa_context *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
93 static void (*PULSEAUDIO_pa_context_disconnect) (pa_context *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
94 static void (*PULSEAUDIO_pa_context_unref) (pa_context *);
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
95
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
96 static pa_stream * (*PULSEAUDIO_pa_stream_new) (pa_context *, const char *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
97 const pa_sample_spec *, const pa_channel_map *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
98 static int (*PULSEAUDIO_pa_stream_connect_playback) (pa_stream *, const char *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
99 const pa_buffer_attr *, pa_stream_flags_t, pa_cvolume *, pa_stream *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
100 static pa_stream_state_t (*PULSEAUDIO_pa_stream_get_state) (pa_stream *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
101 static size_t (*PULSEAUDIO_pa_stream_writable_size) (pa_stream *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
102 static int (*PULSEAUDIO_pa_stream_write) (pa_stream *, const void *, size_t,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
103 pa_free_cb_t, int64_t, pa_seek_mode_t);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
104 static pa_operation * (*PULSEAUDIO_pa_stream_drain) (pa_stream *,
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
105 pa_stream_success_cb_t, void *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
106 static int (*PULSEAUDIO_pa_stream_disconnect) (pa_stream *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
107 static void (*PULSEAUDIO_pa_stream_unref) (pa_stream *);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
108
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
109 static int load_pulseaudio_syms(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
110
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
112 #ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
113
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
114 static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
115 static void *pulseaudio_handle = NULL;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
116
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
117 static int
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
118 load_pulseaudio_sym(const char *fn, void **addr)
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
119 {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
120 *addr = SDL_LoadFunction(pulseaudio_handle, fn);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
121 if (*addr == NULL) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
122 /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
123 return 0;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
124 }
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
125
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
126 return 1;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
127 }
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
128
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
129 /* cast funcs to char* first, to please GCC's strict aliasing rules. */
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
130 #define SDL_PULSEAUDIO_SYM(x) \
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
131 if (!load_pulseaudio_sym(#x, (void **) (char *) &PULSEAUDIO_##x)) return -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
132
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 static void
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
134 UnloadPulseAudioLibrary(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
135 {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
136 if (pulseaudio_handle != NULL) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
137 SDL_UnloadObject(pulseaudio_handle);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
138 pulseaudio_handle = 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
139 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 static int
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
143 LoadPulseAudioLibrary(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
144 {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
145 int retval = 0;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
146 if (pulseaudio_handle == NULL) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
147 pulseaudio_handle = SDL_LoadObject(pulseaudio_library);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
148 if (pulseaudio_handle == NULL) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
149 retval = -1;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
150 /* Don't call SDL_SetError(): SDL_LoadObject already did. */
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
151 } else {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
152 retval = load_pulseaudio_syms();
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
153 if (retval < 0) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
154 UnloadPulseAudioLibrary();
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
155 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 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
159 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
60b4c52a7906 Ported 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 #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
162
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
163 #define SDL_PULSEAUDIO_SYM(x) PULSEAUDIO_##x = x
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
164
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
165 static void
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
166 UnloadPulseAudioLibrary(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
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 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 static int
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
171 LoadPulseAudioLibrary(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
172 {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
173 load_pulseaudio_syms();
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
174 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
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 #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
178
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
179
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
180 static int
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
181 load_pulseaudio_syms(void)
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
182 {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
183 SDL_PULSEAUDIO_SYM(pa_simple_new);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
184 SDL_PULSEAUDIO_SYM(pa_simple_free);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
185 SDL_PULSEAUDIO_SYM(pa_mainloop_new);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
186 SDL_PULSEAUDIO_SYM(pa_mainloop_get_api);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
187 SDL_PULSEAUDIO_SYM(pa_mainloop_iterate);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
188 SDL_PULSEAUDIO_SYM(pa_mainloop_free);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
189 SDL_PULSEAUDIO_SYM(pa_operation_get_state);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
190 SDL_PULSEAUDIO_SYM(pa_operation_cancel);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
191 SDL_PULSEAUDIO_SYM(pa_operation_unref);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
192 SDL_PULSEAUDIO_SYM(pa_context_new);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
193 SDL_PULSEAUDIO_SYM(pa_context_connect);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
194 SDL_PULSEAUDIO_SYM(pa_context_get_state);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
195 SDL_PULSEAUDIO_SYM(pa_context_disconnect);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
196 SDL_PULSEAUDIO_SYM(pa_context_unref);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
197 SDL_PULSEAUDIO_SYM(pa_stream_new);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
198 SDL_PULSEAUDIO_SYM(pa_stream_connect_playback);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
199 SDL_PULSEAUDIO_SYM(pa_stream_get_state);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
200 SDL_PULSEAUDIO_SYM(pa_stream_writable_size);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
201 SDL_PULSEAUDIO_SYM(pa_stream_write);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
202 SDL_PULSEAUDIO_SYM(pa_stream_drain);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
203 SDL_PULSEAUDIO_SYM(pa_stream_disconnect);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
204 SDL_PULSEAUDIO_SYM(pa_stream_unref);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
205 SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
206 SDL_PULSEAUDIO_SYM(pa_strerror);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
207 return 0;
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
208 }
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
209
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
210
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
211 /* 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
212 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
213 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
214 {
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
215 while(1) {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
216 if (PULSEAUDIO_pa_context_get_state(this->hidden->context) != PA_CONTEXT_READY ||
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
217 PULSEAUDIO_pa_stream_get_state(this->hidden->stream) != PA_STREAM_READY ||
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
218 PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
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
219 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
220 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
221 }
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
222 if (PULSEAUDIO_pa_stream_writable_size(this->hidden->stream) >= 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
223 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
224 }
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
225 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 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
229 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
230 {
60b4c52a7906 Ported 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 /* Write the audio data */
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
232 if (PULSEAUDIO_pa_stream_write(this->hidden->stream, this->hidden->mixbuf,
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
233 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
234 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
235 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
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 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 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
240 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
241 {
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
242 /* 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
243 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
244
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
245 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
246 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
247 {
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
248 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
249
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
250 o = PULSEAUDIO_pa_stream_drain(this->hidden->stream, stream_drain_complete, NULL);
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
251 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
252 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
253 }
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
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
255 while (PULSEAUDIO_pa_operation_get_state(o) != PA_OPERATION_DONE) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
256 if (PULSEAUDIO_pa_context_get_state(this->hidden->context) != PA_CONTEXT_READY ||
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
257 PULSEAUDIO_pa_stream_get_state(this->hidden->stream) != PA_STREAM_READY ||
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
258 PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
259 PULSEAUDIO_pa_operation_cancel(o);
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
260 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
261 }
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 }
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
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
264 PULSEAUDIO_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
265 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267
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
268
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
269 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
270 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
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 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
273 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275
60b4c52a7906 Ported 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 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
277 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
278 {
60b4c52a7906 Ported 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 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
280 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
281 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
282 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
283 }
60b4c52a7906 Ported 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 if (this->hidden->stream) {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
285 PULSEAUDIO_pa_stream_disconnect(this->hidden->stream);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
286 PULSEAUDIO_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
287 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
288 }
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
289 if (this->hidden->context != NULL) {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
290 PULSEAUDIO_pa_context_disconnect(this->hidden->context);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
291 PULSEAUDIO_pa_context_unref(this->hidden->context);
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
292 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
293 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
294 if (this->hidden->mainloop != NULL) {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
295 PULSEAUDIO_pa_mainloop_free(this->hidden->mainloop);
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
296 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
297 }
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
298 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
299 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
300 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 /* !!! 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
305 /* Try to get the name of the program */
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
306 static char *
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
307 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
308 {
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
309 #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
310 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
311 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
312 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
313
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 SDL_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
315 fp = fopen(temp, "r");
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
316 if (fp != NULL) {
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
317 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
318 progname = SDL_strrchr(temp, '/');
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
319 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
320 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
321 } else {
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
322 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
323 }
60b4c52a7906 Ported 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 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 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
326 }
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
327 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
328 #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
329 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
330 #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
331 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
332 #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
333 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336 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
337 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
338 {
2272
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
339 Uint16 test_format = 0;
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
340 pa_sample_spec paspec;
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
341 pa_buffer_attr paattr;
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
342 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
343 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
344 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
345
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 /* 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
347 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
348 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
349 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
350 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
351 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
352 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 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
354
60b4c52a7906 Ported 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 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
356
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 /* 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
358 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
359 (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
360 #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
361 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
362 #endif
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
363 switch (test_format) {
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
364 case AUDIO_U8:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
365 paspec.format = PA_SAMPLE_U8;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
366 break;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
367 case AUDIO_S16LSB:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
368 paspec.format = PA_SAMPLE_S16LE;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
369 break;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
370 case AUDIO_S16MSB:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
371 paspec.format = PA_SAMPLE_S16BE;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
372 break;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
373 default:
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
374 paspec.format = PA_SAMPLE_INVALID;
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
375 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
376 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 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
378 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
379 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 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
382 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
383 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
384 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
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 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
387
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 /* 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
389 #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
390 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
391 #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
392 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
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 /* 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
395 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
396 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
397 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
398 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
399 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
400 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
401 }
60b4c52a7906 Ported 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 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
403
60b4c52a7906 Ported 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 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
405 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
406
60b4c52a7906 Ported 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 /* 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
408 #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
409 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
410 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
411 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
412 /* -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
413 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
414 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
415 #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
416 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
417 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
418 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
419 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
420 #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
421
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 /* 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
423 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
424 PULSEAUDIO_pa_channel_map_init_auto(&pacmap, this->spec.channels,
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
425 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
426
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
427 /* Set up a new main loop */
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
428 if (!(this->hidden->mainloop = PULSEAUDIO_pa_mainloop_new())) {
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
429 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
430 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
431 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
432 }
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
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
434 this->hidden->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(this->hidden->mainloop);
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
435 if (!(this->hidden->context = PULSEAUDIO_pa_context_new(this->hidden->mainloop_api, get_progname()))) {
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
436 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
437 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
438 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
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
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
441 /* Connect to the PulseAudio server */
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
442 if (PULSEAUDIO_pa_context_connect(this->hidden->context, NULL, 0, NULL) < 0) {
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
443 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
444 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
445 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
446 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
447
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 do {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
449 if (PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
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
450 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
451 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
452 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
453 }
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
454 state = PULSEAUDIO_pa_context_get_state(this->hidden->context);
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
455 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
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("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
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 } 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
461
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
462 this->hidden->stream = PULSEAUDIO_pa_stream_new(
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
463 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
464 "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
465 &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
466 &pacmap /* channel map */
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
467 );
2272
25a87553a59d Minor PulseAudio fixes: corrected OpenDevice return code, human-readable
Ryan C. Gordon <icculus@icculus.org>
parents: 2271
diff changeset
468
2274
Sam Lantinga <slouken@libsdl.org>
parents: 2272
diff changeset
469 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
470 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
471 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
472 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
473 }
878d8adf2fde Merged r4210:5510 from branches/SDL-1.2/src/audio/pulse: PulseAudio updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 3068
diff changeset
474
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
475 if (PULSEAUDIO_pa_stream_connect_playback(this->hidden->stream, NULL, &paattr, flags,
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
476 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
477 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
478 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
479 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
480 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481
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
482 do {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
483 if (PULSEAUDIO_pa_mainloop_iterate(this->hidden->mainloop, 1, NULL) < 0) {
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
484 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
485 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
486 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
487 }
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
488 state = PULSEAUDIO_pa_stream_get_state(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
489 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
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("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
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 } 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
495
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 /* 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
497 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
498 }
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499
60b4c52a7906 Ported PulseAudio target from 1.2 to 1.3 interfaces, and added it to the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500
60b4c52a7906 Ported 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 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
502 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
503 {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
504 UnloadPulseAudioLibrary();
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
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
60b4c52a7906 Ported 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 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
509 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
510 {
3673
c9d5bd1b4e18 Attempt to clean up PulseAudio dynamic loading support.
Ryan C. Gordon <icculus@icculus.org>
parents: 3672
diff changeset
511 if (LoadPulseAudioLibrary() < 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
512 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
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
60b4c52a7906 Ported 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 /* 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
516 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
517 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
518 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
519 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
520 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
521 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
522 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
523 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
524
2938
2929ed239d2a Adjusted default choice of audio driver.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
525 /* !!! 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
526 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
527 }
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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
60b4c52a7906 Ported 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 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
531 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
532 };
60b4c52a7906 Ported 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 /* vi: set ts=4 sw=4 expandtab: */