Mercurial > sdl-ios-xcode
annotate src/audio/nas/SDL_nasaudio.c @ 4396:f5d3f7fa071d SDL-1.2
1.2 pulseaudio: make some function pointers static.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 17 Jan 2010 05:17:59 +0000 |
parents | 2f5e884f0a9d |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 |
22 This driver was written by: | |
23 Erik Inge Bolsų | |
24 knan@mo.himolde.no | |
25 */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
26 #include "SDL_config.h" |
0 | 27 |
28 /* Allow access to a raw mixing buffer */ | |
29 | |
30 #include <signal.h> | |
31 #include <unistd.h> | |
32 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
33 #include "SDL_timer.h" |
0 | 34 #include "SDL_audio.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
35 #include "../SDL_audiomem.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
36 #include "../SDL_audio_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
37 #include "../SDL_audiodev_c.h" |
0 | 38 #include "SDL_nasaudio.h" |
39 | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
40 #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
41 #include "SDL_loadso.h" |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
42 #endif |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
43 |
0 | 44 /* The tag name used by artsc audio */ |
45 #define NAS_DRIVER_NAME "nas" | |
46 | |
47 static struct SDL_PrivateAudioData *this2 = NULL; | |
48 | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
49 static void (*NAS_AuCloseServer) (AuServer *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
50 static void (*NAS_AuNextEvent) (AuServer *, AuBool, AuEvent *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
51 static AuBool(*NAS_AuDispatchEvent) (AuServer *, AuEvent *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
52 static AuFlowID(*NAS_AuCreateFlow) (AuServer *, AuStatus *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
53 static void (*NAS_AuStartFlow) (AuServer *, AuFlowID, AuStatus *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
54 static void (*NAS_AuSetElements) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
55 (AuServer *, AuFlowID, AuBool, int, AuElement *, AuStatus *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
56 static void (*NAS_AuWriteElement) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
57 (AuServer *, AuFlowID, int, AuUint32, AuPointer, AuBool, AuStatus *); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
58 static AuServer *(*NAS_AuOpenServer) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
59 (_AuConst char *, int, _AuConst char *, int, _AuConst char *, char **); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
60 static AuEventHandlerRec *(*NAS_AuRegisterEventHandler) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
61 (AuServer *, AuMask, int, AuID, AuEventHandlerCallback, AuPointer); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
62 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
63 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
64 #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
65 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
66 static const char *nas_library = SDL_AUDIO_DRIVER_NAS_DYNAMIC; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
67 static void *nas_handle = NULL; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
68 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
69 static int |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
70 load_nas_sym(const char *fn, void **addr) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
71 { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
72 *addr = SDL_LoadFunction(nas_handle, fn); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
73 if (*addr == NULL) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
74 return 0; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
75 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
76 return 1; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
77 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
78 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
79 /* cast funcs to char* first, to please GCC's strict aliasing rules. */ |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
80 #define SDL_NAS_SYM(x) \ |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
81 if (!load_nas_sym(#x, (void **) (char *) &NAS_##x)) return -1 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
82 #else |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
83 #define SDL_NAS_SYM(x) NAS_##x = x |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
84 #endif |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
85 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
86 static int |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
87 load_nas_syms(void) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
88 { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
89 SDL_NAS_SYM(AuCloseServer); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
90 SDL_NAS_SYM(AuNextEvent); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
91 SDL_NAS_SYM(AuDispatchEvent); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
92 SDL_NAS_SYM(AuCreateFlow); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
93 SDL_NAS_SYM(AuStartFlow); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
94 SDL_NAS_SYM(AuSetElements); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
95 SDL_NAS_SYM(AuWriteElement); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
96 SDL_NAS_SYM(AuOpenServer); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
97 SDL_NAS_SYM(AuRegisterEventHandler); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
98 return 0; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
99 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
100 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
101 #undef SDL_NAS_SYM |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
102 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
103 #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
104 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
105 static void |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
106 UnloadNASLibrary(void) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
107 { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
108 if (nas_handle != NULL) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
109 SDL_UnloadObject(nas_handle); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
110 nas_handle = NULL; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
111 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
112 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
113 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
114 static int |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
115 LoadNASLibrary(void) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
116 { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
117 int retval = 0; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
118 if (nas_handle == NULL) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
119 nas_handle = SDL_LoadObject(nas_library); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
120 if (nas_handle == NULL) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
121 /* Copy error string so we can use it in a new SDL_SetError(). */ |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
122 char *origerr = SDL_GetError(); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
123 size_t len = SDL_strlen(origerr) + 1; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
124 char *err = (char *) alloca(len); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
125 SDL_strlcpy(err, origerr, len); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
126 retval = -1; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
127 SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s\n", |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
128 nas_library, err); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
129 } else { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
130 retval = load_nas_syms(); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
131 if (retval < 0) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
132 UnloadNASLibrary(); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
133 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
134 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
135 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
136 return retval; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
137 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
138 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
139 #else |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
140 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
141 static void |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
142 UnloadNASLibrary(void) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
143 { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
144 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
145 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
146 static int |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
147 LoadNASLibrary(void) |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
148 { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
149 load_nas_syms(); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
150 return 0; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
151 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
152 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
153 #endif /* SDL_AUDIO_DRIVER_NAS_DYNAMIC */ |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
154 |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
155 |
0 | 156 /* Audio driver functions */ |
157 static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
158 static void NAS_WaitAudio(_THIS); | |
159 static void NAS_PlayAudio(_THIS); | |
160 static Uint8 *NAS_GetAudioBuf(_THIS); | |
161 static void NAS_CloseAudio(_THIS); | |
162 | |
163 /* Audio driver bootstrap functions */ | |
164 | |
165 static int Audio_Available(void) | |
166 { | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
167 if (LoadNASLibrary() == 0) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
168 AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
169 if (!aud) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
170 UnloadNASLibrary(); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
171 return 0; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
172 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
173 NAS_AuCloseServer(aud); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
174 UnloadNASLibrary(); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
175 return 1; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
176 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
177 return 0; |
0 | 178 } |
179 | |
180 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
181 { | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
182 UnloadNASLibrary(); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
183 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
184 SDL_free(device); |
0 | 185 } |
186 | |
187 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
188 { | |
189 SDL_AudioDevice *this; | |
190 | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
191 if (LoadNASLibrary() < 0) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
192 return NULL; |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
193 } |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
194 |
0 | 195 /* Initialize all variables that we clean on shutdown */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
196 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
0 | 197 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
198 SDL_memset(this, 0, (sizeof *this)); |
0 | 199 this->hidden = (struct SDL_PrivateAudioData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
200 SDL_malloc((sizeof *this->hidden)); |
0 | 201 } |
202 if ( (this == NULL) || (this->hidden == NULL) ) { | |
203 SDL_OutOfMemory(); | |
204 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
205 SDL_free(this); |
0 | 206 } |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
207 return NULL; |
0 | 208 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
209 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 210 |
211 /* Set the function pointers */ | |
212 this->OpenAudio = NAS_OpenAudio; | |
213 this->WaitAudio = NAS_WaitAudio; | |
214 this->PlayAudio = NAS_PlayAudio; | |
215 this->GetAudioBuf = NAS_GetAudioBuf; | |
216 this->CloseAudio = NAS_CloseAudio; | |
217 | |
218 this->free = Audio_DeleteDevice; | |
219 | |
220 return this; | |
221 } | |
222 | |
223 AudioBootStrap NAS_bootstrap = { | |
224 NAS_DRIVER_NAME, "Network Audio System", | |
225 Audio_Available, Audio_CreateDevice | |
226 }; | |
227 | |
228 /* This function waits until it is possible to write a full sound buffer */ | |
229 static void NAS_WaitAudio(_THIS) | |
230 { | |
231 while ( this->hidden->buf_free < this->hidden->mixlen ) { | |
232 AuEvent ev; | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
233 NAS_AuNextEvent(this->hidden->aud, AuTrue, &ev); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
234 NAS_AuDispatchEvent(this->hidden->aud, &ev); |
0 | 235 } |
236 } | |
237 | |
238 static void NAS_PlayAudio(_THIS) | |
239 { | |
240 while (this->hidden->mixlen > this->hidden->buf_free) { /* We think the buffer is full? Yikes! Ask the server for events, | |
241 in the hope that some of them is LowWater events telling us more | |
242 of the buffer is free now than what we think. */ | |
243 AuEvent ev; | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
244 NAS_AuNextEvent(this->hidden->aud, AuTrue, &ev); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
245 NAS_AuDispatchEvent(this->hidden->aud, &ev); |
0 | 246 } |
247 this->hidden->buf_free -= this->hidden->mixlen; | |
248 | |
249 /* Write the audio data */ | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
250 NAS_AuWriteElement(this->hidden->aud, this->hidden->flow, 0, this->hidden->mixlen, this->hidden->mixbuf, AuFalse, NULL); |
0 | 251 |
252 this->hidden->written += this->hidden->mixlen; | |
253 | |
254 #ifdef DEBUG_AUDIO | |
255 fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen); | |
256 #endif | |
257 } | |
258 | |
259 static Uint8 *NAS_GetAudioBuf(_THIS) | |
260 { | |
261 return(this->hidden->mixbuf); | |
262 } | |
263 | |
264 static void NAS_CloseAudio(_THIS) | |
265 { | |
266 if ( this->hidden->mixbuf != NULL ) { | |
267 SDL_FreeAudioMem(this->hidden->mixbuf); | |
268 this->hidden->mixbuf = NULL; | |
269 } | |
270 if ( this->hidden->aud ) { | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
271 NAS_AuCloseServer(this->hidden->aud); |
0 | 272 this->hidden->aud = 0; |
273 } | |
274 } | |
275 | |
276 static unsigned char sdlformat_to_auformat(unsigned int fmt) | |
277 { | |
278 switch (fmt) | |
279 { | |
280 case AUDIO_U8: | |
281 return AuFormatLinearUnsigned8; | |
282 case AUDIO_S8: | |
283 return AuFormatLinearSigned8; | |
284 case AUDIO_U16LSB: | |
285 return AuFormatLinearUnsigned16LSB; | |
286 case AUDIO_U16MSB: | |
287 return AuFormatLinearUnsigned16MSB; | |
288 case AUDIO_S16LSB: | |
289 return AuFormatLinearSigned16LSB; | |
290 case AUDIO_S16MSB: | |
291 return AuFormatLinearSigned16MSB; | |
292 } | |
293 return AuNone; | |
294 } | |
295 | |
296 static AuBool | |
297 event_handler(AuServer* aud, AuEvent* ev, AuEventHandlerRec* hnd) | |
298 { | |
299 switch (ev->type) { | |
300 case AuEventTypeElementNotify: { | |
301 AuElementNotifyEvent* event = (AuElementNotifyEvent *)ev; | |
302 | |
303 switch (event->kind) { | |
304 case AuElementNotifyKindLowWater: | |
305 if (this2->buf_free >= 0) { | |
306 this2->really += event->num_bytes; | |
307 gettimeofday(&this2->last_tv, 0); | |
308 this2->buf_free += event->num_bytes; | |
309 } else { | |
310 this2->buf_free = event->num_bytes; | |
311 } | |
312 break; | |
313 case AuElementNotifyKindState: | |
314 switch (event->cur_state) { | |
315 case AuStatePause: | |
316 if (event->reason != AuReasonUser) { | |
317 if (this2->buf_free >= 0) { | |
318 this2->really += event->num_bytes; | |
319 gettimeofday(&this2->last_tv, 0); | |
320 this2->buf_free += event->num_bytes; | |
321 } else { | |
322 this2->buf_free = event->num_bytes; | |
323 } | |
324 } | |
325 break; | |
326 } | |
327 } | |
328 } | |
329 } | |
330 return AuTrue; | |
331 } | |
332 | |
333 static AuDeviceID | |
334 find_device(_THIS, int nch) | |
335 { | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
336 /* These "Au" things are all macros, not functions... */ |
0 | 337 int i; |
338 for (i = 0; i < AuServerNumDevices(this->hidden->aud); i++) { | |
339 if ((AuDeviceKind(AuServerDevice(this->hidden->aud, i)) == | |
340 AuComponentKindPhysicalOutput) && | |
341 AuDeviceNumTracks(AuServerDevice(this->hidden->aud, i)) == nch) { | |
342 return AuDeviceIdentifier(AuServerDevice(this->hidden->aud, i)); | |
343 } | |
344 } | |
345 return AuNone; | |
346 } | |
347 | |
348 static int NAS_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
349 { | |
350 AuElement elms[3]; | |
351 int buffer_size; | |
352 Uint16 test_format, format; | |
353 | |
354 this->hidden->mixbuf = NULL; | |
355 | |
356 /* Try for a closest match on audio format */ | |
357 format = 0; | |
358 for ( test_format = SDL_FirstAudioFormat(spec->format); | |
359 ! format && test_format; ) { | |
360 format = sdlformat_to_auformat(test_format); | |
361 | |
362 if (format == AuNone) { | |
363 test_format = SDL_NextAudioFormat(); | |
364 } | |
365 } | |
366 if ( format == 0 ) { | |
367 SDL_SetError("Couldn't find any hardware audio formats"); | |
368 return(-1); | |
369 } | |
370 spec->format = test_format; | |
371 | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
372 this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL); |
0 | 373 if (this->hidden->aud == 0) |
374 { | |
375 SDL_SetError("Couldn't open connection to NAS server"); | |
376 return (-1); | |
377 } | |
378 | |
379 this->hidden->dev = find_device(this, spec->channels); | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
380 if ((this->hidden->dev == AuNone) || (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, NULL)))) { |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
381 NAS_AuCloseServer(this->hidden->aud); |
0 | 382 this->hidden->aud = 0; |
383 SDL_SetError("Couldn't find a fitting playback device on NAS server"); | |
384 return (-1); | |
385 } | |
386 | |
387 buffer_size = spec->freq; | |
388 if (buffer_size < 4096) | |
389 buffer_size = 4096; | |
390 | |
391 if (buffer_size > 32768) | |
392 buffer_size = 32768; /* So that the buffer won't get unmanageably big. */ | |
393 | |
394 /* Calculate the final parameters for this audio specification */ | |
395 SDL_CalculateAudioSpec(spec); | |
396 | |
397 this2 = this->hidden; | |
398 | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
399 /* These "Au" things without a NAS_ prefix are macros, not functions... */ |
0 | 400 AuMakeElementImportClient(elms, spec->freq, format, spec->channels, AuTrue, |
401 buffer_size, buffer_size / 4, 0, NULL); | |
402 AuMakeElementExportDevice(elms+1, 0, this->hidden->dev, spec->freq, | |
403 AuUnlimitedSamples, 0, NULL); | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
404 NAS_AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms, NULL); |
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
405 NAS_AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0, this->hidden->flow, |
0 | 406 event_handler, (AuPointer) NULL); |
407 | |
4192
2f5e884f0a9d
Made NAS target dynamic, so you can safely include it in shipping binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
4159
diff
changeset
|
408 NAS_AuStartFlow(this->hidden->aud, this->hidden->flow, NULL); |
0 | 409 |
410 /* Allocate mixing buffer */ | |
411 this->hidden->mixlen = spec->size; | |
412 this->hidden->mixbuf = (Uint8 *)SDL_AllocAudioMem(this->hidden->mixlen); | |
413 if ( this->hidden->mixbuf == NULL ) { | |
414 return(-1); | |
415 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
416 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); |
0 | 417 |
418 /* Get the parent process id (we're the parent of the audio thread) */ | |
419 this->hidden->parent = getpid(); | |
420 | |
421 /* We're ready to rock and roll. :-) */ | |
422 return(0); | |
423 } |