annotate src/sound.c @ 4458:a46c57f2d58b

[gaim-migrate @ 4733] (20:45:09) Trogdor: http://web.ics.purdue.edu/~eblanton/gaim/gaim-cvs-oscar-ssi-conv.diff (20:45:12) Trogdor: commit please (20:45:22) LSchiere: commit log? (20:45:48) Trogdor: Adds best-effort charset conversion to Oscar SSI aliases and group names. (20:45:55) Trogdor: oh (20:46:19) Trogdor: Also adds a gaim global function gaim_try_conv_to_utf8 () for attempting several logical encodings on a given string. (20:46:43) Trogdor: (which replaces the aptly named whatever_to_utf8) committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 29 Jan 2003 01:46:44 +0000
parents 801830dec409
children 3196d9044a45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
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
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 #include <stdio.h>
1057
d50d3abb9eb7 [gaim-migrate @ 1067]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1006
diff changeset
26 #include <stdlib.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <string.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
28
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
29 #ifndef _WIN32
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <sys/time.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #include <unistd.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 #include <sys/wait.h>
63
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
33 #include <unistd.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
34 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
35 #include <windows.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
36 #include <mmsystem.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
37 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
38
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
39 #include <fcntl.h>
63
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
40 #include <sys/types.h>
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
41 #include <sys/stat.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
43 #ifdef ESD_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
44 #include <esd.h>
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
45 #endif
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
46
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
47 #ifdef ARTSC_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
48 #include <artsc.h>
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
49 #endif
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
50
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
51 #ifdef NAS_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
52 #include <audio/audiolib.h>
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
53 #endif
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
54
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 #include "gaim.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
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
3a05fcb133c4 [gaim-migrate @ 3337]
Sean Egan <seanegan@gmail.com>
parents: 3284
diff changeset
61 gboolean mute_sounds = 0;
3a05fcb133c4 [gaim-migrate @ 3337]
Sean Egan <seanegan@gmail.com>
parents: 3284
diff changeset
62
4082
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
63 /* description, option bit, default sound file *
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
64 * set the option bit to 0 to have it not display in prefs *
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
65 * the order here has to match the defines in gaim.h. *
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
66 * -Robot101 */
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
67 struct sound_struct sounds[NUM_SOUNDS] = {
4013
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
68 {N_("Buddy logs in"), OPT_SOUND_LOGIN, "arrive.wav"},
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
69 {N_("Buddy logs out"), OPT_SOUND_LOGOUT, "leave.wav"},
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
70 {N_("Message received"), OPT_SOUND_RECV, "receive.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
71 {N_("Message received begins conversation"), OPT_SOUND_FIRST_RCV, "receive.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
72 {N_("Message sent"), OPT_SOUND_SEND, "send.wav"},
4013
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
73 {N_("Person enters chat"), OPT_SOUND_CHAT_JOIN, "arrive.wav"},
73853a0a1a77 [gaim-migrate @ 4213]
Sean Egan <seanegan@gmail.com>
parents: 4012
diff changeset
74 {N_("Person leaves chat"), OPT_SOUND_CHAT_PART, "leave.wav"},
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
75 {N_("You talk in chat"), OPT_SOUND_CHAT_YOU_SAY, "send.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
76 {N_("Others talk in chat"), OPT_SOUND_CHAT_SAY, "receive.wav"},
3326
03daf01a8000 [gaim-migrate @ 3344]
Jim Seymour <jseymour>
parents: 3319
diff changeset
77 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */
4012
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
78 {NULL, 0, "redalert.wav"},
ab6c48a07fd6 [gaim-migrate @ 4212]
Sean Egan <seanegan@gmail.com>
parents: 4010
diff changeset
79 {N_("Someone says your name in chat"), OPT_SOUND_CHAT_NICK, "redalert.wav"}
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
80 };
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
81
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
82 #ifndef _WIN32
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
83 static int check_dev(char *dev)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
84 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
85 struct stat stat_buf;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
86 uid_t user = getuid();
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
87 gid_t group = getgid(), other_groups[32];
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
88 int i, numgroups;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
89
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
90 if ((numgroups = getgroups(32, other_groups)) == -1)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
91 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
92 if (stat(dev, &stat_buf))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
93 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
94 if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
95 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
96 if (stat_buf.st_mode & S_IWGRP) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
97 if (group == stat_buf.st_gid)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
98 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
99 for (i = 0; i < numgroups; i++)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
100 if (other_groups[i] == stat_buf.st_gid)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
101 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
102 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
103 if (stat_buf.st_mode & S_IWOTH)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
104 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
105 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
106 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
107
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
108 static void play_audio_file(char *file)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
109 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
110 /* here we can assume that we can write to /dev/audio */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
111 char *buf;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
112 struct stat info;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
113 int fd = open(file, O_RDONLY);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
114 if (fd <= 0) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
115 return;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
116 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
117 fstat(fd, &info);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
118 if (info.st_size < 24)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
119 return;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
120 buf = malloc(info.st_size + 1);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
121 read(fd, buf, 24);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
122 read(fd, buf, info.st_size - 24);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
123 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
124
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
125 fd = open("/dev/audio", O_WRONLY | O_EXCL | O_NDELAY);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
126 if (fd < 0) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
127 free(buf);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
128 return;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
129 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
130 write(fd, buf, info.st_size - 24);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
131 free(buf);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
132 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
133 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
134
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
135 static int can_play_audio()
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
136 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
137 return check_dev("/dev/audio");
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
138 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
139
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
140 #ifdef ESD_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
141
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
142 int esd_fd;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
143
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
144 static int can_play_esd()
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
145 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
146 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
147
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
148 esd_fd = esd_play_stream(format, 8012, NULL, "gaim");
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
149
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
150 if (esd_fd < 0) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
151 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
152 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
153
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
154 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
155 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
156
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
157 #endif /* ESD_SOUND */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
158
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
159 #ifdef ARTSC_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
160
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
161 /*
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
162 ** This routine converts from ulaw to 16 bit linear.
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
163 **
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
164 ** Craig Reese: IDA/Supercomputing Research Center
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
165 ** 29 September 1989
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
166 **
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
167 ** References:
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
168 ** 1) CCITT Recommendation G.711 (very difficult to follow)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
169 ** 2) MIL-STD-188-113,"Interoperability and Performance Standards
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
170 ** for Analog-to_Digital Conversion Techniques,"
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
171 ** 17 February 1987
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
172 **
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
173 ** Input: 8 bit ulaw sample
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
174 ** Output: signed 16 bit linear sample
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
175 ** Z-note -- this is from libaudiofile. Thanks guys!
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
176 */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
177
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
178 static int _af_ulaw2linear(unsigned char ulawbyte)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
179 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
180 static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 };
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
181 int sign, exponent, mantissa, sample;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
182
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
183 ulawbyte = ~ulawbyte;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
184 sign = (ulawbyte & 0x80);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
185 exponent = (ulawbyte >> 4) & 0x07;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
186 mantissa = ulawbyte & 0x0F;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
187 sample = exp_lut[exponent] + (mantissa << (exponent + 3));
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
188 if (sign != 0)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
189 sample = -sample;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
190
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
191 return (sample);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
192 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
193
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
194 static int play_artsc(unsigned char *data, int size)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
195 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
196 arts_stream_t stream;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
197 guint16 *lineardata;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
198 int result = 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
199 int error;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
200 int i;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
201
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
202 lineardata = g_malloc(size * 2);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
203
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
204 for (i = 0; i < size; i++) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
205 lineardata[i] = _af_ulaw2linear(data[i]);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
206 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
207
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
208 stream = arts_play_stream(8012, 16, 1, "gaim");
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
209
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
210 error = arts_write(stream, lineardata, size);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
211 if (error < 0) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
212 result = 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
213 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
214
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
215 arts_close_stream(stream);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
216
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
217 g_free(lineardata);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
218
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
219 arts_free();
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
220
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
221 return result;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
222 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
223
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
224 static int can_play_artsc()
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
225 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
226 int error;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
227
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
228 error = arts_init();
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
229 if (error < 0)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
230 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
231
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
232 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
233 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
234
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
235 static int artsc_play_file(char *file)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
236 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
237 struct stat stat_buf;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
238 unsigned char *buf = NULL;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
239 int result = 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
240 int fd = -1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
241
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
242 if (!can_play_artsc())
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
243 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
244
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
245 fd = open(file, O_RDONLY);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
246 if (fd < 0)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
247 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
248
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
249 if (fstat(fd, &stat_buf)) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
250 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
251 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
252 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
253
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
254 if (!stat_buf.st_size) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
255 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
256 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
257 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
258
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
259 buf = g_malloc(stat_buf.st_size);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
260 if (!buf) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
261 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
262 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
263 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
264
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
265 if (read(fd, buf, stat_buf.st_size) < 0) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
266 g_free(buf);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
267 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
268 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
269 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
270
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
271 result = play_artsc(buf, stat_buf.st_size);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
272
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
273 g_free(buf);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
274 close(fd);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
275 return result;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
276 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
277
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
278 #endif /* ARTSC_SOUND */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
279
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
280 #ifdef NAS_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
281
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
282 char nas_server[] = "localhost";
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
283 AuServer *nas_serv = NULL;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
284
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
285 static AuBool NasEventHandler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * handler)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
286 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
287 AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
288
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
289 if (ev->type == AuEventTypeElementNotify) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
290 switch (event->kind) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
291 case AuElementNotifyKindState:
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
292 switch (event->cur_state) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
293 case AuStateStop:
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
294 _exit(0);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
295 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
296 break;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
297 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
298 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
299 return AuTrue;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
300 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
301
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
302
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
303 static int play_nas(unsigned char *data, int size)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
304 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
305 AuDeviceID device = AuNone;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
306 AuFlowID flow;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
307 AuElement elements[3];
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
308 int i, n, w;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
309
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
310 /* look for an output device */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
311 for (i = 0; i < AuServerNumDevices(nas_serv); i++) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
312 if ((AuDeviceKind(AuServerDevice(nas_serv, i)) ==
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
313 AuComponentKindPhysicalOutput) &&
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
314 AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
315 device = AuDeviceIdentifier(AuServerDevice(nas_serv, i));
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
316 break;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
317 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
318 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
319
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
320 if (device == AuNone)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
321 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
322
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
323 if (!(flow = AuCreateFlow(nas_serv, NULL)))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
324 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
325
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
326
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
327 AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, 1, AuTrue, size, size / 2, 0, NULL);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
328 AuMakeElementExportDevice(&elements[1], 0, device, 8012, AuUnlimitedSamples, 0, NULL);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
329 AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
330
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
331 AuStartFlow(nas_serv, flow, NULL);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
332
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
333 AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
334
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
335 AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, NasEventHandler, NULL);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
336
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
337 while (1) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
338 AuHandleEvents(nas_serv);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
339 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
340
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
341 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
342 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
343
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
344 static int can_play_nas()
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
345 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
346 if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL)))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
347 return 1;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
348 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
349 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
350
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
351 static int play_nas_file(char *file)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
352 {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
353 struct stat stat_buf;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
354 char *buf;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
355 int ret;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
356 int fd = open(file, O_RDONLY);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
357 if (fd <= 0)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
358 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
359
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
360 if (!can_play_nas())
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
361 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
362
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
363 if (stat(file, &stat_buf))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
364 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
365
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
366 if (!stat_buf.st_size)
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
367 return 0;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
368
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
369 buf = malloc(stat_buf.st_size);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
370 read(fd, buf, stat_buf.st_size);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
371 ret = play_nas(buf, stat_buf.st_size);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
372 free(buf);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
373 return ret;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
374 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
375
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
376 #endif /* NAS_SOUND */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
377
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
378 #endif /* !_WIN32 */
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
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
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
382 #ifndef _WIN32
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
383 int pid;
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
384 #endif
3901
7740c891537e [gaim-migrate @ 4054]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
385 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY))
7740c891537e [gaim-migrate @ 4054]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
386 return; /* check here in case a buddy pounce plays a file while away */
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
387
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
388 if (sound_options & OPT_SOUND_BEEP) {
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
389 gdk_beep();
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
390 return;
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
391 }
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
392
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
393 else if (sound_options & OPT_SOUND_NORMAL) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
394 debug_printf("attempting to play audio file with internal method -- this is unlikely to work\n");
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
395 }
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
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) {
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
402 alarm(30);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
403
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
404 if ((sound_options & OPT_SOUND_CMD) && sound_cmd[0]) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
405 char *args[4];
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
406 char command[4096];
4429
bf770f11132b [gaim-migrate @ 4704]
Luke Schierer <lschiere@pidgin.im>
parents: 4082
diff changeset
407
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
408 g_snprintf(command, sizeof(command), sound_cmd, filename);
4429
bf770f11132b [gaim-migrate @ 4704]
Luke Schierer <lschiere@pidgin.im>
parents: 4082
diff changeset
409
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
410 args[0] = "sh";
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
411 args[1] = "-c";
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
412 args[2] = command;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
413 args[3] = NULL;
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
414 execvp(args[0], args);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
415 _exit(0);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
416 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
417 #ifdef ESD_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
418 else if (sound_options & OPT_SOUND_ESD) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
419 if (esd_play_file(NULL, filename, 1))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
420 _exit(0);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
421 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
422 #endif
4429
bf770f11132b [gaim-migrate @ 4704]
Luke Schierer <lschiere@pidgin.im>
parents: 4082
diff changeset
423
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
424 #ifdef ARTSC_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
425 else if (sound_options & OPT_SOUND_ARTSC) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
426 if (artsc_play_file(filename))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
427 _exit(0);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
428 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
429 #endif
4429
bf770f11132b [gaim-migrate @ 4704]
Luke Schierer <lschiere@pidgin.im>
parents: 4082
diff changeset
430
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
431 #ifdef NAS_SOUND
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
432 else if (sound_options & OPT_SOUND_NAS) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
433 if (play_nas_file(filename))
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
434 _exit(0);
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
435 }
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
436 #endif
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
437
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
438 else if ((sound_options & OPT_SOUND_NORMAL) &&
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
439 can_play_audio()) {
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
440 play_audio_file(filename);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
441 _exit(0);
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
442 }
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
443
1006
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
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
446 #else /* _WIN32 */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
447 debug_printf("Playing %s\n", filename);
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
448 if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME))
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
449 debug_printf("Error playing sound.");
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3367
diff changeset
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
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
454
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
455 void play_sound(int sound)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
456 {
3319
3a05fcb133c4 [gaim-migrate @ 3337]
Sean Egan <seanegan@gmail.com>
parents: 3284
diff changeset
457 if (mute_sounds)
3a05fcb133c4 [gaim-migrate @ 3337]
Sean Egan <seanegan@gmail.com>
parents: 3284
diff changeset
458 return;
4430
801830dec409 [gaim-migrate @ 4705]
Luke Schierer <lschiere@pidgin.im>
parents: 4429
diff changeset
459
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
460 if ((sound == SND_BUDDY_ARRIVE) && !logins_not_muted)
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
461 return;
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
462
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
463 if (sound >= NUM_SOUNDS) {
4082
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4019
diff changeset
464 debug_printf("got request for unknown sound: %d\n", sound);
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
465 return;
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
466 }
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
467
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
468 /* check NULL for sounds that don't have an option, ie buddy pounce */
3072
359b4cd0e766 [gaim-migrate @ 3086]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
469 if ((sound_options & sounds[sound].opt) || (sounds[sound].opt == 0)) {
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
470 if (sound_file[sound]) {
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
471 play_file(sound_file[sound]);
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
472 } else {
4004
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
473 gchar *filename = NULL;
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
474
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
475 filename = g_build_filename(DATADIR, "sounds", "gaim", sounds[sound].def, NULL);
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
476 play_file(filename);
b2520034b62f [gaim-migrate @ 4204]
Sean Egan <seanegan@gmail.com>
parents: 3901
diff changeset
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
b1d7336cba85 [gaim-migrate @ 74]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 63
diff changeset
480 }