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