Mercurial > sdl-ios-xcode
annotate src/audio/pulse/SDL_pulseaudio.c @ 4211:3ce5bfddbaf6 SDL-1.2
Fixed bug #572
Please merge this patch for the PA driver in SDL.
http://0pointer.de/public/sdl-pulse-rework.patch
This patch:
- fixes buffering (i.e. reduces number of "fragments" to 2, doesn't defer
filling up of the buffer until the entire buffer ran completely empty.)
- drops $PASERVER and $PADEVICE env var support, since this is a duplication of
$PULSE_SERVER and $PULSE_SINK which the PA libs honor anyway.
This fixes the sound issues in all games I tested.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 21 Sep 2009 08:03:00 +0000 |
parents | a1b03ba2fcd0 |
children | 5b99971a27b4 |
rev | line source |
---|---|
4211 | 1 /* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*- */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 /* |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 SDL - Simple DirectMedia Layer |
4159 | 4 Copyright (C) 1997-2009 Sam Lantinga |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 This library is free software; you can redistribute it and/or |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 modify it under the terms of the GNU Lesser General Public |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 License as published by the Free Software Foundation; either |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 version 2.1 of the License, or (at your option) any later version. |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 This library is distributed in the hope that it will be useful, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 Lesser General Public License for more details. |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 You should have received a copy of the GNU Lesser General Public |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 License along with this library; if not, write to the Free Software |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 Stéphan Kochen |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 stephan@kochen.nl |
4211 | 22 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 Based on parts of the ALSA and ESounD output drivers. |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 #include "SDL_config.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 /* Allow access to an PulseAudio network stream mixing buffer */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 #include <sys/types.h> |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #include <unistd.h> |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 #include <signal.h> |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 #include <errno.h> |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 #include <pulse/simple.h> |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 #include "SDL_timer.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 #include "SDL_audio.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 #include "../SDL_audiomem.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 #include "../SDL_audio_c.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 #include "../SDL_audiodev_c.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 #include "SDL_pulseaudio.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 #include "SDL_name.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 #include "SDL_loadso.h" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 #else |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 #define SDL_NAME(X) X |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 #endif |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 /* The tag name used by the driver */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 #define PULSE_DRIVER_NAME "pulse" |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 /* Audio driver functions */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 static void PULSE_WaitAudio(_THIS); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 static void PULSE_PlayAudio(_THIS); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 static Uint8 *PULSE_GetAudioBuf(_THIS); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 static void PULSE_CloseAudio(_THIS); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 #ifdef SDL_AUDIO_DRIVER_PULSE_DYNAMIC |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 static const char *pulse_library = SDL_AUDIO_DRIVER_PULSE_DYNAMIC; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 static void *pulse_handle = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 static int pulse_loaded = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 static pa_simple* (*SDL_NAME(pa_simple_new))( |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 const char *server, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 const char *name, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 pa_stream_direction_t dir, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 const char *dev, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 const char *stream_name, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 const pa_sample_spec *ss, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 const pa_channel_map *map, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 const pa_buffer_attr *attr, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 int *error |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 static void (*SDL_NAME(pa_simple_free))(pa_simple *s); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 static int (*SDL_NAME(pa_simple_drain))(pa_simple *s, int *error); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 static int (*SDL_NAME(pa_simple_write))( |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 pa_simple *s, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 const void *data, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 size_t length, |
4211 | 82 int *error |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))( |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 pa_channel_map *m, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 unsigned channels, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 pa_channel_map_def_t def |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 ); |
4211 | 89 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 static struct { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 const char *name; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 void **func; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 } pulse_functions[] = { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 { "pa_simple_new", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 (void **)&SDL_NAME(pa_simple_new) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 { "pa_simple_free", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 (void **)&SDL_NAME(pa_simple_free) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 { "pa_simple_drain", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 (void **)&SDL_NAME(pa_simple_drain) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 { "pa_simple_write", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 (void **)&SDL_NAME(pa_simple_write) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 { "pa_channel_map_init_auto", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 (void **)&SDL_NAME(pa_channel_map_init_auto) }, |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 }; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 static void UnloadPulseLibrary() |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 if ( pulse_loaded ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 SDL_UnloadObject(pulse_handle); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 pulse_handle = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 pulse_loaded = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 static int LoadPulseLibrary(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 int i, retval = -1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 pulse_handle = SDL_LoadObject(pulse_library); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 if ( pulse_handle ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 pulse_loaded = 1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 retval = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 for ( i=0; i<SDL_arraysize(pulse_functions); ++i ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 *pulse_functions[i].func = SDL_LoadFunction(pulse_handle, pulse_functions[i].name); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 if ( !*pulse_functions[i].func ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 retval = -1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 UnloadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 return retval; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 #else |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 static void UnloadPulseLibrary() |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 return; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 static int LoadPulseLibrary(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 return 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 #endif /* SDL_AUDIO_DRIVER_PULSE_DYNAMIC */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 /* Audio driver bootstrap functions */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 static int Audio_Available(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 pa_sample_spec paspec; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 pa_simple *connection; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 int available; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 available = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 if ( LoadPulseLibrary() < 0 ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 return available; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 } |
4211 | 162 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 /* Connect with a dummy format. */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 paspec.format = PA_SAMPLE_U8; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 paspec.rate = 11025; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 paspec.channels = 1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 connection = SDL_NAME(pa_simple_new)( |
4211 | 168 NULL, /* server */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 "Test stream", /* application name */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 PA_STREAM_PLAYBACK, /* playback mode */ |
4211 | 171 NULL, /* device on the server */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 "Simple DirectMedia Layer", /* stream description */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 &paspec, /* sample format spec */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 NULL, /* channel map */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 NULL, /* buffering attributes */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 NULL /* error code */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 if ( connection != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 available = 1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 SDL_NAME(pa_simple_free)(connection); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 } |
4211 | 182 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 UnloadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 return(available); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 static void Audio_DeleteDevice(SDL_AudioDevice *device) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 SDL_free(device->hidden); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 SDL_free(device); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 UnloadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 static SDL_AudioDevice *Audio_CreateDevice(int devindex) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 SDL_AudioDevice *this; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 /* Initialize all variables that we clean on shutdown */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 LoadPulseLibrary(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 if ( this ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 SDL_memset(this, 0, (sizeof *this)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 this->hidden = (struct SDL_PrivateAudioData *) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 SDL_malloc((sizeof *this->hidden)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 if ( (this == NULL) || (this->hidden == NULL) ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 SDL_OutOfMemory(); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 if ( this ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 SDL_free(this); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 return(0); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 /* Set the function pointers */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 this->OpenAudio = PULSE_OpenAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 this->WaitAudio = PULSE_WaitAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 this->PlayAudio = PULSE_PlayAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 this->GetAudioBuf = PULSE_GetAudioBuf; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 this->CloseAudio = PULSE_CloseAudio; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 this->free = Audio_DeleteDevice; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 return this; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 AudioBootStrap PULSE_bootstrap = { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 PULSE_DRIVER_NAME, "PulseAudio", |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 Audio_Available, Audio_CreateDevice |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 }; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 /* This function waits until it is possible to write a full sound buffer */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 static void PULSE_WaitAudio(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 /* Check to see if the thread-parent process is still alive */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 { static int cnt = 0; |
4211 | 237 /* Note that this only works with thread implementations |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 that use a different process id for each thread. |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 if ( kill(parent, 0) < 0 ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 this->enabled = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 static void PULSE_PlayAudio(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 /* Write the audio data */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 if ( SDL_NAME(pa_simple_write)(stream, mixbuf, mixlen, NULL) != 0 ) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 this->enabled = 0; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 static Uint8 *PULSE_GetAudioBuf(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 return(mixbuf); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 static void PULSE_CloseAudio(_THIS) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 if ( mixbuf != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 SDL_FreeAudioMem(mixbuf); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 mixbuf = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 if ( stream != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 SDL_NAME(pa_simple_drain)(stream, NULL); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 SDL_NAME(pa_simple_free)(stream); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 stream = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 /* Try to get the name of the program */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 static char *get_progname(void) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 char *progname = NULL; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 #ifdef __LINUX__ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 FILE *fp; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 static char temp[BUFSIZ]; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid()); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 fp = fopen(temp, "r"); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 if ( fp != NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 if ( fgets(temp, sizeof(temp)-1, fp) ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 progname = SDL_strrchr(temp, '/'); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 if ( progname == NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 progname = temp; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 } else { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 progname = progname+1; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 fclose(fp); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 #endif |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 return(progname); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 static int PULSE_OpenAudio(_THIS, SDL_AudioSpec *spec) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 Uint16 test_format; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 pa_sample_spec paspec; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 pa_buffer_attr paattr; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 pa_channel_map pacmap; |
4211 | 306 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 paspec.format = PA_SAMPLE_INVALID; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 for ( test_format = SDL_FirstAudioFormat(spec->format); test_format; ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 switch ( test_format ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 case AUDIO_U8: |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 paspec.format = PA_SAMPLE_U8; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 case AUDIO_S16LSB: |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 paspec.format = PA_SAMPLE_S16LE; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 case AUDIO_S16MSB: |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 paspec.format = PA_SAMPLE_S16BE; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 if ( paspec.format != PA_SAMPLE_INVALID ) |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 break; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 if (paspec.format == PA_SAMPLE_INVALID ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 SDL_SetError("Couldn't find any suitable audio formats"); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 return(-1); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 spec->format = test_format; |
4211 | 328 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 paspec.channels = spec->channels; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 paspec.rate = spec->freq; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 /* Calculate the final parameters for this audio specification */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 SDL_CalculateAudioSpec(spec); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 /* Allocate mixing buffer */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 mixlen = spec->size; |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 mixbuf = (Uint8 *)SDL_AllocAudioMem(mixlen); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 if ( mixbuf == NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 return(-1); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 SDL_memset(mixbuf, spec->silence, spec->size); |
4211 | 342 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 /* Reduced prebuffering compared to the defaults. */ |
4211 | 344 paattr.tlength = mixlen*2; |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 paattr.minreq = mixlen; |
4211 | 346 paattr.prebuf = mixlen*2; |
347 paattr.maxlength = mixlen*2; | |
348 | |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 /* The SDL ALSA output hints us that we use Windows' channel mapping */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 SDL_NAME(pa_channel_map_init_auto)( |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 &pacmap, spec->channels, PA_CHANNEL_MAP_WAVEEX); |
4211 | 353 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 /* Connect to the PulseAudio server */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 stream = SDL_NAME(pa_simple_new)( |
4211 | 356 NULL, /* server */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 get_progname(), /* application name */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 PA_STREAM_PLAYBACK, /* playback mode */ |
4211 | 359 NULL, /* device on the server */ |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 "Simple DirectMedia Layer", /* stream description */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 &paspec, /* sample format spec */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 &pacmap, /* channel map */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 &paattr, /* buffering attributes */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 NULL /* error code */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 ); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 if ( stream == NULL ) { |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 PULSE_CloseAudio(this); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 SDL_SetError("Could not connect to PulseAudio"); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 return(-1); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 } |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 /* Get the parent process id (we're the parent of the audio thread) */ |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 parent = getpid(); |
4211 | 374 |
3939
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 return(0); |
42e83d81224b
Committed PulseAudio driver. Thanks, Stephan!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 } |