Mercurial > pidgin.yaz
annotate src/sound.c @ 1057:d50d3abb9eb7
[gaim-migrate @ 1067]
attempting to pass -Wall (at least for app)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 03 Nov 2000 10:46:58 +0000 |
parents | 0a4d0ed65e17 |
children | c73736fa0b7c |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
23 #include "../config.h" |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
338
diff
changeset
|
24 #endif |
1 | 25 #include <stdio.h> |
1057
d50d3abb9eb7
[gaim-migrate @ 1067]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1006
diff
changeset
|
26 #include <stdlib.h> |
1 | 27 #include <string.h> |
28 #include <sys/time.h> | |
29 #include <unistd.h> | |
30 #include <gtk/gtk.h> | |
31 #include <fcntl.h> | |
32 #include <sys/wait.h> | |
33 #include <sys/signal.h> | |
63 | 34 #include <unistd.h> |
35 #include <sys/types.h> | |
36 #include <sys/stat.h> | |
1 | 37 |
38 #ifdef ESD_SOUND | |
39 #include <esd.h> | |
40 #endif | |
41 | |
42 #ifdef NAS_SOUND | |
43 #include <audio/audiolib.h> | |
44 #endif | |
45 | |
46 #include "gaim.h" | |
47 #include "sounds/BuddyArrive.h" | |
48 #include "sounds/BuddyLeave.h" | |
49 #include "sounds/Send.h" | |
50 #include "sounds/Receive.h" | |
51 | |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
52 static int check_dev(char *dev) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
53 { |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
54 struct stat stat_buf; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
55 uid_t user = getuid(); |
899
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
56 gid_t group = getgid(), |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
57 other_groups[32]; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
58 int i, numgroups; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
59 |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
60 if ((numgroups = getgroups (32, other_groups)) == -1) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
61 return 0; |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
62 if (stat(dev, &stat_buf)) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
63 return 0; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
64 if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
65 return 1; |
899
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
66 if (stat_buf.st_mode & S_IWGRP) { |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
67 if (group == stat_buf.st_gid) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
68 return 1; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
69 for (i = 0; i < numgroups; i++) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
70 if (other_groups[i] == stat_buf.st_gid) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
71 return 1; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
72 } |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
73 if (stat_buf.st_mode & S_IWOTH) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
74 return 1; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
75 return 0; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
76 } |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
77 |
1 | 78 |
79 static void play_audio(char *data, int size) | |
80 { | |
81 int fd; | |
82 | |
83 fd = open("/dev/audio", O_WRONLY | O_EXCL); | |
84 if (fd < 0) | |
85 return; | |
86 write(fd, data, size); | |
87 close(fd); | |
88 } | |
89 | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
90 static void play_audio_file(char *file) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
91 { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
92 /* here we can assume that we can write to /dev/audio */ |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
93 char *buf; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
94 struct stat info; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
95 int fd = open(file, O_RDONLY); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
96 if (fd <= 0) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
97 return; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
98 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
99 fstat(fd, &info); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
100 buf = malloc(info.st_size + 1); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
101 read(fd, buf, 24); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
102 read(fd, buf, info.st_size - 24); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
103 close(fd); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
104 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
105 fd = open("/dev/audio", O_WRONLY | O_EXCL); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
106 if (fd < 0) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
107 return; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
108 write(fd, buf, info.st_size - 24); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
109 free(buf); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
110 close(fd); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
111 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
112 |
1 | 113 static int can_play_audio() |
114 { | |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
115 return check_dev("/dev/audio"); |
1 | 116 } |
117 | |
118 | |
119 #ifdef ESD_SOUND | |
120 /* | |
121 ** This routine converts from ulaw to 16 bit linear. | |
122 ** | |
123 ** Craig Reese: IDA/Supercomputing Research Center | |
124 ** 29 September 1989 | |
125 ** | |
126 ** References: | |
127 ** 1) CCITT Recommendation G.711 (very difficult to follow) | |
128 ** 2) MIL-STD-188-113,"Interoperability and Performance Standards | |
129 ** for Analog-to_Digital Conversion Techniques," | |
130 ** 17 February 1987 | |
131 ** | |
132 ** Input: 8 bit ulaw sample | |
133 ** Output: signed 16 bit linear sample | |
134 ** Z-note -- this is from libaudiofile. Thanks guys! | |
135 */ | |
136 | |
137 int _af_ulaw2linear (unsigned char ulawbyte) | |
138 { | |
139 static int exp_lut[8] = {0,132,396,924,1980,4092,8316,16764}; | |
140 int sign, exponent, mantissa, sample; | |
141 | |
142 ulawbyte = ~ulawbyte; | |
143 sign = (ulawbyte & 0x80); | |
144 exponent = (ulawbyte >> 4) & 0x07; | |
145 mantissa = ulawbyte & 0x0F; | |
146 sample = exp_lut[exponent] + (mantissa << (exponent + 3)); | |
147 if (sign != 0) sample = -sample; | |
148 | |
149 return(sample); | |
150 } | |
151 | |
152 | |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
153 int esd_fd; |
1 | 154 |
155 static int play_esd(unsigned char *data, int size) | |
156 { | |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
157 int i; |
79 | 158 guint16 *lineardata; |
1 | 159 |
79 | 160 lineardata = g_malloc(size * 2); |
1 | 161 |
162 for (i=0; i<size; i++) | |
163 lineardata[i] = _af_ulaw2linear(data[i]); | |
164 | |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
165 write(esd_fd, lineardata, size * 2); |
1 | 166 |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
167 close(esd_fd); |
1 | 168 g_free(lineardata); |
169 | |
170 return 1; | |
171 | |
172 } | |
173 | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
174 static int play_esd_file(char *file) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
175 { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
176 int esd_stat; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
177 int fd = open(file, O_RDONLY); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
178 if (fd <= 0) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
179 return 0; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
180 esd_stat = esd_play_file(NULL, file, 1); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
181 return esd_stat; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
182 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
183 |
1 | 184 static int can_play_esd() |
185 { | |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
186 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
187 |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
188 esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
189 |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
190 if (esd_fd < 0) { |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
191 return 0; |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
192 } |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
193 |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
194 return 1; |
1 | 195 } |
196 | |
197 #endif | |
198 | |
199 #ifdef NAS_SOUND | |
200 | |
201 char nas_server[] = "localhost"; | |
202 AuServer *nas_serv = NULL; | |
203 | |
204 static AuBool | |
205 NasEventHandler(AuServer *aud, AuEvent *ev, AuEventHandlerRec *handler) | |
206 { | |
207 AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev; | |
208 | |
209 if (ev->type == AuEventTypeElementNotify) { | |
210 switch (event->kind) { | |
211 case AuElementNotifyKindState: | |
212 switch (event->cur_state) { | |
213 case AuStateStop: | |
214 _exit(0); | |
215 } | |
216 break; | |
217 } | |
218 } | |
219 return AuTrue; | |
220 } | |
221 | |
222 | |
223 static int play_nas(unsigned char *data, int size) | |
224 { | |
225 AuDeviceID device = AuNone; | |
226 AuFlowID flow; | |
227 AuElement elements[3]; | |
228 int i, n, w; | |
229 | |
230 /* look for an output device */ | |
231 for (i = 0; i < AuServerNumDevices(nas_serv); i++) { | |
232 if ((AuDeviceKind(AuServerDevice(nas_serv, i)) == | |
233 AuComponentKindPhysicalOutput) && | |
234 AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) { | |
235 device = AuDeviceIdentifier(AuServerDevice(nas_serv, i)); | |
236 break; | |
237 } | |
238 } | |
239 | |
240 if (device == AuNone) | |
241 return 0; | |
242 | |
243 if (!(flow = AuCreateFlow(nas_serv, NULL))) | |
244 return 0; | |
245 | |
246 | |
247 AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, | |
248 1, AuTrue, size, size/2, 0, NULL); | |
249 AuMakeElementExportDevice(&elements[1], 0, device, 8012, | |
250 AuUnlimitedSamples, 0, NULL); | |
251 AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL); | |
252 | |
253 AuStartFlow(nas_serv, flow, NULL); | |
254 | |
255 AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL); | |
256 | |
257 AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, | |
258 NasEventHandler, NULL); | |
259 | |
260 while(1) { | |
261 AuHandleEvents(nas_serv); | |
262 } | |
263 | |
264 return 1; | |
265 } | |
266 | |
267 static int can_play_nas() | |
268 { | |
269 if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) | |
270 return 1; | |
271 return 0; | |
272 } | |
273 | |
274 #endif | |
275 | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
276 void play_file(char *filename) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
277 int pid; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
278 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
279 #ifdef _WIN32 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
280 return; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
281 #endif |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
282 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
283 pid = fork(); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
284 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
285 if (pid < 0) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
286 return; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
287 else if (pid == 0) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
288 if (sound_options & OPT_SOUND_BEEP) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
289 printf("\a"); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
290 fflush(stdout); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
291 _exit(0); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
292 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
293 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
294 #ifdef ESD_SOUND |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
295 if (play_esd_file(filename)) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
296 _exit(0); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
297 #endif |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
298 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
299 /* FIXME : NAS (does anyone use this?) */ |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
300 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
301 if (can_play_audio()) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
302 play_audio_file(filename); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
303 _exit(0); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
304 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
305 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
306 _exit(0); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
307 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
308 gtk_timeout_add(100, (GtkFunction)clean_pid, NULL); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
309 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
310 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
311 |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
108
diff
changeset
|
312 void play(unsigned char *data, int size) |
1 | 313 { |
314 int pid; | |
315 | |
316 #ifdef _WIN32 | |
317 return; | |
318 #endif | |
319 | |
320 pid = fork(); | |
321 | |
322 if (pid < 0) | |
323 return; | |
324 else if (pid == 0) { | |
775
9614e69f68ca
[gaim-migrate @ 785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
668
diff
changeset
|
325 if (sound_options & OPT_SOUND_BEEP) { |
777
1d60fb2c3b3b
[gaim-migrate @ 787]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
775
diff
changeset
|
326 printf("\a"); |
778
035d3115c6fe
[gaim-migrate @ 788]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
777
diff
changeset
|
327 fflush(stdout); |
775
9614e69f68ca
[gaim-migrate @ 785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
668
diff
changeset
|
328 _exit(0); |
9614e69f68ca
[gaim-migrate @ 785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
668
diff
changeset
|
329 } |
9614e69f68ca
[gaim-migrate @ 785]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
668
diff
changeset
|
330 |
1 | 331 #ifdef ESD_SOUND |
332 /* ESD is our player of choice. Are we OK to | |
333 * go there? */ | |
334 if (can_play_esd()) { | |
335 if (play_esd(data, size)) | |
336 _exit(0); | |
337 } | |
338 #endif | |
339 | |
340 #ifdef NAS_SOUND | |
341 /* NAS is our second choice setup. */ | |
342 if (can_play_nas()) { | |
343 if (play_nas(data, size)) | |
344 _exit(0); | |
345 } | |
346 #endif | |
347 | |
348 /* Lastly, we can try just plain old /dev/audio */ | |
349 if (can_play_audio()) { | |
350 play_audio(data, size); | |
351 _exit(0); | |
352 } | |
668
c9b66c710283
[gaim-migrate @ 678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
655
diff
changeset
|
353 |
c9b66c710283
[gaim-migrate @ 678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
655
diff
changeset
|
354 _exit(0); |
1 | 355 } else { |
356 gtk_timeout_add(100, (GtkFunction)clean_pid, NULL); | |
357 } | |
358 } | |
359 | |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
108
diff
changeset
|
360 extern int logins_not_muted; |
1 | 361 |
362 void play_sound(int sound) | |
363 { | |
364 | |
365 switch(sound) { | |
366 case BUDDY_ARRIVE: | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
367 if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
368 if (sound_file[BUDDY_ARRIVE]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
369 play_file(sound_file[BUDDY_ARRIVE]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
370 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
371 play(BuddyArrive, sizeof(BuddyArrive)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
372 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
373 } |
1 | 374 break; |
375 case BUDDY_LEAVE: | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
376 if (sound_options & OPT_SOUND_LOGOUT) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
377 if (sound_file[BUDDY_LEAVE]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
378 play_file(sound_file[BUDDY_LEAVE]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
379 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
380 play(BuddyLeave, sizeof(BuddyLeave)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
381 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
382 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
383 break; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
384 case FIRST_RECEIVE: |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
385 if (sound_options & OPT_SOUND_FIRST_RCV) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
386 if (sound_file[FIRST_RECEIVE]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
387 play_file(sound_file[FIRST_RECEIVE]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
388 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
389 play(Receive, sizeof(Receive)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
390 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
391 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
392 break; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
393 case RECEIVE: |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
394 if (sound_options & OPT_SOUND_RECV) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
395 if (sound_file[RECEIVE]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
396 play_file(sound_file[RECEIVE]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
397 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
398 play(Receive, sizeof(Receive)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
399 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
400 } |
1 | 401 break; |
402 case SEND: | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
403 if (sound_options & OPT_SOUND_SEND) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
404 if (sound_file[SEND]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
405 play_file(sound_file[SEND]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
406 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
407 play(Send, sizeof(Send)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
408 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
409 } |
1 | 410 break; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
411 case CHAT_JOIN: |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
412 if (sound_options & OPT_SOUND_CHAT_JOIN) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
413 if (sound_file[CHAT_JOIN]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
414 play_file(sound_file[CHAT_JOIN]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
415 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
416 play(BuddyArrive, sizeof(BuddyArrive)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
417 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
418 } |
1 | 419 break; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
420 case CHAT_LEAVE: |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
421 if (sound_options & OPT_SOUND_CHAT_PART) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
422 if (sound_file[CHAT_LEAVE]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
423 play_file(sound_file[CHAT_LEAVE]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
424 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
425 play(BuddyLeave, sizeof(BuddyLeave)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
426 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
427 } |
1 | 428 break; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
429 case CHAT_YOU_SAY: |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
430 if (sound_options & OPT_SOUND_CHAT_YOU_SAY) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
431 if (sound_file[CHAT_YOU_SAY]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
432 play_file(sound_file[CHAT_YOU_SAY]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
433 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
434 play(Send, sizeof(Send)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
435 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
436 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
437 break; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
438 case CHAT_SAY: |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
439 if (sound_options & OPT_SOUND_CHAT_SAY) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
440 if (sound_file[CHAT_SAY]) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
441 play_file(sound_file[CHAT_SAY]); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
442 } else { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
443 play(Receive, sizeof(Receive)); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
444 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
445 } |
1 | 446 break; |
447 } | |
64 | 448 } |
1 | 449 |