Mercurial > pidgin.yaz
annotate src/sound.c @ 4019:e53d9f9969d0
[gaim-migrate @ 4219]
win32dep.h included for DATADIR
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Fri, 29 Nov 2002 19:13:12 +0000 |
parents | 63e1cc99aedb |
children | 4b04ecb3eb97 |
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 |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2048
diff
changeset
|
23 #include <config.h> |
349
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> |
3630 | 28 |
29 #ifndef _WIN32 | |
1 | 30 #include <sys/time.h> |
31 #include <unistd.h> | |
32 #include <sys/wait.h> | |
63 | 33 #include <unistd.h> |
3630 | 34 #else |
35 #include <windows.h> | |
36 #include <mmsystem.h> | |
37 #endif | |
38 | |
39 #include <fcntl.h> | |
63 | 40 #include <sys/types.h> |
41 #include <sys/stat.h> | |
1 | 42 |
43 #ifdef ESD_SOUND | |
44 #include <esd.h> | |
45 #endif | |
46 | |
4012 | 47 #ifdef ARTSC_SOUND |
48 #include <artsc.h> | |
49 #endif | |
50 | |
51 #ifdef NAS_SOUND | |
52 #include <audio/audiolib.h> | |
53 #endif | |
54 | |
1 | 55 #include "gaim.h" |
56 | |
4019
e53d9f9969d0
[gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4014
diff
changeset
|
57 #ifdef _WIN32 |
e53d9f9969d0
[gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4014
diff
changeset
|
58 #include "win32dep.h" |
e53d9f9969d0
[gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4014
diff
changeset
|
59 #endif |
e53d9f9969d0
[gaim-migrate @ 4219]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4014
diff
changeset
|
60 |
3319 | 61 gboolean mute_sounds = 0; |
62 | |
4004 | 63 /* description, option bit, default sound file * |
3326 | 64 * if you want it to get displayed in the prefs dialog, it needs * |
65 * to be added to the sound_order array in prefs.c, if not, and * | |
66 * it has no option bit, set it to 0. the order here has to match * | |
67 * the defines in gaim.h. -Robot101 */ | |
3060 | 68 struct sound_struct sounds[NUM_SOUNDS] = { |
4013 | 69 {N_("Buddy logs in"), OPT_SOUND_LOGIN, "arrive.wav"}, |
70 {N_("Buddy logs out"), OPT_SOUND_LOGOUT, "leave.wav"}, | |
4012 | 71 {N_("Message received"), OPT_SOUND_RECV, "receive.wav"}, |
72 {N_("Message received begins conversation"), OPT_SOUND_FIRST_RCV, "receive.wav"}, | |
73 {N_("Message sent"), OPT_SOUND_SEND, "send.wav"}, | |
4013 | 74 {N_("Person enters chat"), OPT_SOUND_CHAT_JOIN, "arrive.wav"}, |
75 {N_("Person leaves chat"), OPT_SOUND_CHAT_PART, "leave.wav"}, | |
4012 | 76 {N_("You talk in chat"), OPT_SOUND_CHAT_YOU_SAY, "send.wav"}, |
77 {N_("Others talk in chat"), OPT_SOUND_CHAT_SAY, "receive.wav"}, | |
3326 | 78 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */ |
4012 | 79 {NULL, 0, "redalert.wav"}, |
80 {N_("Someone says your name in chat"), OPT_SOUND_CHAT_NICK, "redalert.wav"} | |
3060 | 81 }; |
3367 | 82 int sound_order[] = { |
83 SND_BUDDY_ARRIVE, SND_BUDDY_LEAVE, | |
84 SND_FIRST_RECEIVE, SND_RECEIVE, SND_SEND, | |
85 SND_CHAT_JOIN, SND_CHAT_LEAVE, | |
86 SND_CHAT_YOU_SAY, SND_CHAT_SAY, SND_CHAT_NICK, 0 | |
87 }; | |
3060 | 88 |
3630 | 89 #ifndef _WIN32 |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
90 static int check_dev(char *dev) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
91 { |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
92 struct stat stat_buf; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
93 uid_t user = getuid(); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
94 gid_t group = getgid(), other_groups[32]; |
899
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
95 int i, numgroups; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
96 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
97 if ((numgroups = getgroups(32, other_groups)) == -1) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
98 return 0; |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
99 if (stat(dev, &stat_buf)) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
100 return 0; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
101 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
|
102 return 1; |
899
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
103 if (stat_buf.st_mode & S_IWGRP) { |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
104 if (group == stat_buf.st_gid) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
105 return 1; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
106 for (i = 0; i < numgroups; i++) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
107 if (other_groups[i] == stat_buf.st_gid) |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
108 return 1; |
88d1edcd7cd6
[gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
778
diff
changeset
|
109 } |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
110 if (stat_buf.st_mode & S_IWOTH) |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
111 return 1; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
112 return 0; |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
113 } |
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
114 |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
115 static void play_audio_file(char *file) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
116 { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
117 /* here we can assume that we can write to /dev/audio */ |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
118 char *buf; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
119 struct stat info; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
120 int fd = open(file, O_RDONLY); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
121 if (fd <= 0) { |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
122 return; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
123 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
124 fstat(fd, &info); |
1109
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
125 if (info.st_size < 24) |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
126 return; |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
127 buf = malloc(info.st_size + 1); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
128 read(fd, buf, 24); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
129 read(fd, buf, info.st_size - 24); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
130 close(fd); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
131 |
2467
cd81f1f2c896
[gaim-migrate @ 2480]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
132 fd = open("/dev/audio", O_WRONLY | O_EXCL | O_NDELAY); |
1109
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
133 if (fd < 0) { |
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
134 free(buf); |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
135 return; |
1109
c73736fa0b7c
[gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
136 } |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
137 write(fd, buf, info.st_size - 24); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
138 free(buf); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
139 close(fd); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
140 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
141 |
1 | 142 static int can_play_audio() |
143 { | |
655
6ba20a0089d8
[gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
606
diff
changeset
|
144 return check_dev("/dev/audio"); |
1 | 145 } |
146 | |
2179
64d8ef561763
[gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2158
diff
changeset
|
147 #ifdef ESD_SOUND |
1 | 148 |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
149 int esd_fd; |
1 | 150 |
151 static int can_play_esd() | |
152 { | |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
153 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
|
154 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
155 esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
156 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
157 if (esd_fd < 0) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
158 return 0; |
354
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
159 } |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
160 |
2b91e42bff70
[gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
161 return 1; |
1 | 162 } |
163 | |
4014 | 164 #endif /* ESD_SOUND */ |
165 | |
166 #ifdef ARTSC_SOUND | |
167 | |
168 /* | |
169 ** This routine converts from ulaw to 16 bit linear. | |
170 ** | |
171 ** Craig Reese: IDA/Supercomputing Research Center | |
172 ** 29 September 1989 | |
173 ** | |
174 ** References: | |
175 ** 1) CCITT Recommendation G.711 (very difficult to follow) | |
176 ** 2) MIL-STD-188-113,"Interoperability and Performance Standards | |
177 ** for Analog-to_Digital Conversion Techniques," | |
178 ** 17 February 1987 | |
179 ** | |
180 ** Input: 8 bit ulaw sample | |
181 ** Output: signed 16 bit linear sample | |
182 ** Z-note -- this is from libaudiofile. Thanks guys! | |
183 */ | |
184 | |
185 static int _af_ulaw2linear(unsigned char ulawbyte) | |
186 { | |
187 static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 }; | |
188 int sign, exponent, mantissa, sample; | |
189 | |
190 ulawbyte = ~ulawbyte; | |
191 sign = (ulawbyte & 0x80); | |
192 exponent = (ulawbyte >> 4) & 0x07; | |
193 mantissa = ulawbyte & 0x0F; | |
194 sample = exp_lut[exponent] + (mantissa << (exponent + 3)); | |
195 if (sign != 0) | |
196 sample = -sample; | |
197 | |
198 return (sample); | |
199 } | |
200 | |
201 static int play_artsc(unsigned char *data, int size) | |
202 { | |
203 arts_stream_t stream; | |
204 guint16 *lineardata; | |
205 int result = 1; | |
206 int error; | |
207 int i; | |
208 | |
209 lineardata = g_malloc(size * 2); | |
210 | |
211 for (i = 0; i < size; i++) { | |
212 lineardata[i] = _af_ulaw2linear(data[i]); | |
213 } | |
214 | |
215 stream = arts_play_stream(8012, 16, 1, "gaim"); | |
216 | |
217 error = arts_write(stream, lineardata, size); | |
218 if (error < 0) { | |
219 result = 0; | |
220 } | |
221 | |
222 arts_close_stream(stream); | |
223 | |
224 g_free(lineardata); | |
225 | |
226 arts_free(); | |
227 | |
228 return result; | |
229 } | |
230 | |
231 static int can_play_artsc() | |
232 { | |
233 int error; | |
234 | |
235 error = arts_init(); | |
236 if (error < 0) | |
237 return 0; | |
238 | |
239 return 1; | |
240 } | |
241 | |
242 static int artsc_play_file(char *file) | |
243 { | |
244 struct stat stat_buf; | |
245 unsigned char *buf = NULL; | |
246 int result = 0; | |
247 int fd = -1; | |
248 | |
249 if (!can_play_artsc()) | |
250 return 0; | |
251 | |
252 fd = open(file, O_RDONLY); | |
253 if (fd < 0) | |
254 return 0; | |
255 | |
256 if (fstat(fd, &stat_buf)) { | |
257 close(fd); | |
258 return 0; | |
259 } | |
260 | |
261 if (!stat_buf.st_size) { | |
262 close(fd); | |
263 return 0; | |
264 } | |
265 | |
266 buf = g_malloc(stat_buf.st_size); | |
267 if (!buf) { | |
268 close(fd); | |
269 return 0; | |
270 } | |
271 | |
272 if (read(fd, buf, stat_buf.st_size) < 0) { | |
273 g_free(buf); | |
274 close(fd); | |
275 return 0; | |
276 } | |
277 | |
278 result = play_artsc(buf, stat_buf.st_size); | |
279 | |
280 g_free(buf); | |
281 close(fd); | |
282 return result; | |
283 } | |
284 | |
285 #endif /* ARTSC_SOUND */ | |
286 | |
287 #ifdef NAS_SOUND | |
288 | |
289 char nas_server[] = "localhost"; | |
290 AuServer *nas_serv = NULL; | |
291 | |
292 static AuBool NasEventHandler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * handler) | |
293 { | |
294 AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev; | |
295 | |
296 if (ev->type == AuEventTypeElementNotify) { | |
297 switch (event->kind) { | |
298 case AuElementNotifyKindState: | |
299 switch (event->cur_state) { | |
300 case AuStateStop: | |
301 _exit(0); | |
302 } | |
303 break; | |
304 } | |
305 } | |
306 return AuTrue; | |
307 } | |
308 | |
309 | |
310 static int play_nas(unsigned char *data, int size) | |
311 { | |
312 AuDeviceID device = AuNone; | |
313 AuFlowID flow; | |
314 AuElement elements[3]; | |
315 int i, n, w; | |
316 | |
317 /* look for an output device */ | |
318 for (i = 0; i < AuServerNumDevices(nas_serv); i++) { | |
319 if ((AuDeviceKind(AuServerDevice(nas_serv, i)) == | |
320 AuComponentKindPhysicalOutput) && | |
321 AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) { | |
322 device = AuDeviceIdentifier(AuServerDevice(nas_serv, i)); | |
323 break; | |
324 } | |
325 } | |
326 | |
327 if (device == AuNone) | |
328 return 0; | |
329 | |
330 if (!(flow = AuCreateFlow(nas_serv, NULL))) | |
331 return 0; | |
332 | |
333 | |
334 AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, 1, AuTrue, size, size / 2, 0, NULL); | |
335 AuMakeElementExportDevice(&elements[1], 0, device, 8012, AuUnlimitedSamples, 0, NULL); | |
336 AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL); | |
337 | |
338 AuStartFlow(nas_serv, flow, NULL); | |
339 | |
340 AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL); | |
341 | |
342 AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, NasEventHandler, NULL); | |
343 | |
344 while (1) { | |
345 AuHandleEvents(nas_serv); | |
346 } | |
347 | |
348 return 1; | |
349 } | |
350 | |
351 static int can_play_nas() | |
352 { | |
353 if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) | |
354 return 1; | |
355 return 0; | |
356 } | |
357 | |
358 static int play_nas_file(char *file) | |
359 { | |
360 struct stat stat_buf; | |
361 char *buf; | |
362 int ret; | |
363 int fd = open(file, O_RDONLY); | |
364 if (fd <= 0) | |
365 return 0; | |
366 | |
367 if (!can_play_nas()) | |
368 return 0; | |
369 | |
370 if (stat(file, &stat_buf)) | |
371 return 0; | |
372 | |
373 if (!stat_buf.st_size) | |
374 return 0; | |
375 | |
376 buf = malloc(stat_buf.st_size); | |
377 read(fd, buf, stat_buf.st_size); | |
378 ret = play_nas(buf, stat_buf.st_size); | |
379 free(buf); | |
380 return ret; | |
381 } | |
382 | |
383 #endif /* NAS_SOUND */ | |
384 | |
3630 | 385 #endif /* !_WIN32 */ |
1 | 386 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
387 void play_file(char *filename) |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
388 { |
3630 | 389 #ifndef _WIN32 |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
390 int pid; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
391 #endif |
3901 | 392 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY)) |
393 return; /* check here in case a buddy pounce plays a file while away */ | |
394 | |
3004 | 395 if (sound_options & OPT_SOUND_BEEP) { |
396 gdk_beep(); | |
397 return; | |
398 } | |
399 | |
3060 | 400 else if (sound_options & OPT_SOUND_NORMAL) { |
3072 | 401 debug_printf("attempting to play audio file with internal method -- this is unlikely to work\n"); |
3060 | 402 } |
3630 | 403 #ifndef _WIN32 |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
404 pid = fork(); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
405 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
406 if (pid < 0) |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
407 return; |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
408 else if (pid == 0) { |
2601
61952dde7677
[gaim-migrate @ 2614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2580
diff
changeset
|
409 alarm(30); |
3004 | 410 |
3025 | 411 if ((sound_options & OPT_SOUND_CMD) && sound_cmd[0]) { |
1214
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
412 char *args[4]; |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
413 char command[4096]; |
2777
0899f8c99a15
[gaim-migrate @ 2790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2680
diff
changeset
|
414 |
0899f8c99a15
[gaim-migrate @ 2790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2680
diff
changeset
|
415 g_snprintf(command, sizeof(command), sound_cmd, filename); |
0899f8c99a15
[gaim-migrate @ 2790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2680
diff
changeset
|
416 |
1214
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
417 args[0] = "sh"; |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
418 args[1] = "-c"; |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
419 args[2] = command; |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
420 args[3] = NULL; |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
421 execvp(args[0], args); |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
422 _exit(0); |
0baf39dc5437
[gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1109
diff
changeset
|
423 } |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
424 #ifdef ESD_SOUND |
2580
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
425 else if (sound_options & OPT_SOUND_ESD) { |
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
426 if (esd_play_file(NULL, filename, 1)) |
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
427 _exit(0); |
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
428 } |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
429 #endif |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
430 |
4014 | 431 #ifdef ARTSC_SOUND |
2580
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
432 else if (sound_options & OPT_SOUND_ARTSC) { |
4014 | 433 if (artsc_play_file(filename)) |
434 _exit(0); | |
2580
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
435 } |
4014 | 436 #endif |
2186
08781af8e3a9
[gaim-migrate @ 2196]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2183
diff
changeset
|
437 |
4014 | 438 #ifdef NAS_SOUND |
2580
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
439 else if (sound_options & OPT_SOUND_NAS) { |
4014 | 440 if (play_nas_file(filename)) |
441 _exit(0); | |
2580
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
442 } |
4014 | 443 #endif |
444 | |
4010 | 445 else if ((sound_options & OPT_SOUND_NORMAL) && |
2580
86eaeb064e82
[gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2478
diff
changeset
|
446 can_play_audio()) { |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
447 play_audio_file(filename); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
448 _exit(0); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
449 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
450 |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
451 _exit(0); |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
452 } |
3630 | 453 #else /* _WIN32 */ |
454 debug_printf("Playing %s\n", filename); | |
455 if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME)) | |
456 debug_printf("Error playing sound."); | |
457 #endif | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
458 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
459 |
133
e277d5f0c1dd
[gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
108
diff
changeset
|
460 extern int logins_not_muted; |
1 | 461 |
462 void play_sound(int sound) | |
463 { | |
3319 | 464 if (mute_sounds) |
465 return; | |
466 | |
1235
a9cf2f61a7b1
[gaim-migrate @ 1245]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1214
diff
changeset
|
467 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY)) |
a9cf2f61a7b1
[gaim-migrate @ 1245]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1214
diff
changeset
|
468 return; |
a9cf2f61a7b1
[gaim-migrate @ 1245]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1214
diff
changeset
|
469 |
3060 | 470 if ((sound == SND_BUDDY_ARRIVE) && !logins_not_muted) |
471 return; | |
472 | |
473 if (sound >= NUM_SOUNDS) { | |
3072 | 474 debug_printf("sorry old fruit... can't say I know that sound: ", sound, "\n"); |
3060 | 475 return; |
476 } | |
477 | |
478 /* check NULL for sounds that don't have an option, ie buddy pounce */ | |
3072 | 479 if ((sound_options & sounds[sound].opt) || (sounds[sound].opt == 0)) { |
3060 | 480 if (sound_file[sound]) { |
481 play_file(sound_file[sound]); | |
482 } else { | |
4004 | 483 gchar *filename = NULL; |
484 | |
485 filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[sound].def, NULL); | |
486 play_file(filename); | |
487 g_free(filename); | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
488 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1235
diff
changeset
|
489 } |
64 | 490 } |