Mercurial > audlegacy
annotate Plugins/Output/esd/mixer.c @ 799:fbbd15125774 trunk
[svn] - add corrected version of Aerdan's jump to file patch
author | nenolod |
---|---|
date | Sat, 04 Mar 2006 12:17:20 -0800 |
parents | 5f46230a24f8 |
children | f12d7e208b43 |
rev | line source |
---|---|
61 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 #include <esd.h> | |
26 | |
490 | 27 #include <libaudacious/configdb.h> |
488
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
28 |
61 | 29 #include <unistd.h> |
30 #include <fcntl.h> | |
31 #include <sys/types.h> | |
32 #include <sys/ioctl.h> | |
33 #include <sys/stat.h> | |
34 | |
35 #include "esdout.h" | |
36 | |
37 #ifdef HAVE_OSS | |
668
5f46230a24f8
[svn] ESD output plugin ported to objective make by Kyoshi Aman.
chainsaw
parents:
490
diff
changeset
|
38 # include <OSS/soundcard.h> |
61 | 39 # define OSS_AVAILABLE TRUE |
40 #else | |
41 # define OSS_AVAILABLE FALSE | |
42 #endif | |
43 | |
44 #include <libaudacious/util.h> | |
45 | |
488
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
46 #define QUERY_PLAYER_ID_ATTEMPTS 5 |
61 | 47 |
48 static void esdout_get_oss_volume(int *l, int *r); | |
49 static void esdout_set_oss_volume(int l, int r); | |
50 | |
51 | |
52 static int player = -1; | |
53 static int lp = 100, rp = 100; | |
54 | |
55 /* | |
56 * Find the stream id, and set stream volume to 'persistent' value. | |
57 */ | |
58 void | |
59 esdout_mixer_init(void) | |
60 { | |
488
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
61 int i; |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
62 |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
63 /* reset player id */ |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
64 player = -1; |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
65 |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
66 /* query n-time for player id */ |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
67 for(i=0; (i<QUERY_PLAYER_ID_ATTEMPTS) && (player == (-1)) ; i++) |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
68 esdout_fetch_volume(NULL, NULL); |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
69 |
61 | 70 if (!(OSS_AVAILABLE && esd_cfg.use_oss_mixer && !esd_cfg.use_remote)) |
71 esdout_set_volume(lp, rp); | |
72 } | |
73 | |
74 /* | |
75 * Grab the stream volume from the server. The problem here is that | |
76 * ESD does not have a built-in function for finding the player ID of | |
77 * a specific player - nor does it let us know what the player ID is | |
78 * when the player is created! So, we grab 'allinfo' and scan the | |
79 * returned player list for the string which we know is our player | |
80 * name (esd_cfg.playername) This function seems to take a long time | |
81 * to run... I'm not sure where to start optimizing, however... | |
82 */ | |
83 void | |
84 esdout_fetch_volume(int *l, int *r) | |
85 { | |
86 int fd; | |
87 esd_info_t *all_info = NULL; | |
88 esd_player_info_t *info; | |
89 | |
90 fd = esd_open_sound(esd_cfg.hostname); | |
91 all_info = esd_get_all_info(fd); | |
92 | |
93 /* scan linked list for our playername */ | |
94 for (info = all_info->player_list; info != NULL; info = info->next) | |
95 if (!strcmp(esd_cfg.playername, info->name)) | |
96 break; | |
97 | |
98 if (info) { | |
99 player = info->source_id; | |
100 if (l && r) { | |
101 /* | |
102 * Sometimes we call with NULL | |
103 * args to fetch the player num | |
104 */ | |
105 *l = (info->left_vol_scale * 100) / 256; | |
106 *r = (info->right_vol_scale * 100) / 256; | |
107 } | |
108 } | |
109 else | |
110 g_warning("xmms: Couldn't find our player " | |
111 "(was looking for %s) at the server", esd_cfg.playername); | |
112 | |
113 if (all_info) | |
114 esd_free_all_info(all_info); | |
115 esd_close(fd); | |
116 } | |
117 | |
118 void | |
119 esdout_get_volume(int *l, int *r) | |
120 { | |
121 if (OSS_AVAILABLE && esd_cfg.use_oss_mixer && !esd_cfg.use_remote) { | |
122 esdout_get_oss_volume(l, r); | |
123 lp = *l; | |
124 rp = *r; | |
125 } | |
126 else { | |
127 /* | |
128 * We assume that the volume hasn't changed from the | |
129 * 'persistant' value. Constantly polling takes too | |
130 * much time/resources. Commenting this section out | |
131 * will consistently check the ESD server to see if | |
132 * someone else changed our stream volume. | |
133 */ | |
134 *l = lp; | |
135 *r = rp; | |
136 /* esdout_fetch_volume(l, r); */ | |
137 } | |
138 } | |
139 | |
140 void | |
141 esdout_set_volume(int l, int r) | |
142 { | |
488
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
143 ConfigDb *db; |
61 | 144 lp = l; |
145 rp = r; | |
146 | |
147 if (OSS_AVAILABLE && esd_cfg.use_oss_mixer && !esd_cfg.use_remote) { | |
148 esdout_set_oss_volume(l, r); | |
149 } | |
150 else if (player != -1 && esd_cfg.playername != NULL) { | |
151 int fd = esd_open_sound(esd_cfg.hostname); | |
152 if (fd >= 0) { | |
153 esd_set_stream_pan(fd, player, (l * 256) / 100, (r * 256) / 100); | |
154 esd_close(fd); | |
155 } | |
156 } | |
488
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
157 |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
158 /* save volume values in db */ |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
159 db = bmp_cfg_db_open(); |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
160 bmp_cfg_db_set_int(db, "ESD", "volume_left", lp); |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
161 bmp_cfg_db_set_int(db, "ESD", "volume_right", rp); |
cb0f36590d98
[svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents:
61
diff
changeset
|
162 bmp_cfg_db_close(db); |
61 | 163 } |
164 | |
165 #ifdef HAVE_OSS | |
166 | |
167 static void | |
168 esdout_get_oss_volume(int *l, int *r) | |
169 { | |
170 int fd, v, devs; | |
171 long cmd; | |
172 | |
173 if (esd_cfg.use_remote) | |
174 return; | |
175 | |
176 fd = open(DEV_MIXER, O_RDONLY); | |
177 if (fd != -1) { | |
178 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
179 if (devs & SOUND_MASK_PCM) | |
180 cmd = SOUND_MIXER_READ_PCM; | |
181 else if (devs & SOUND_MASK_VOLUME) | |
182 cmd = SOUND_MIXER_READ_VOLUME; | |
183 else { | |
184 close(fd); | |
185 return; | |
186 } | |
187 ioctl(fd, cmd, &v); | |
188 *r = (v & 0xFF00) >> 8; | |
189 *l = (v & 0x00FF); | |
190 close(fd); | |
191 } | |
192 } | |
193 | |
194 static void | |
195 esdout_set_oss_volume(int l, int r) | |
196 { | |
197 int fd, v, devs; | |
198 long cmd; | |
199 | |
200 if (esd_cfg.use_remote) | |
201 return; | |
202 | |
203 fd = open(DEV_MIXER, O_RDONLY); | |
204 | |
205 if (fd != -1) { | |
206 ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); | |
207 if (devs & SOUND_MASK_PCM) | |
208 cmd = SOUND_MIXER_WRITE_PCM; | |
209 else if (devs & SOUND_MASK_VOLUME) | |
210 cmd = SOUND_MIXER_WRITE_VOLUME; | |
211 else { | |
212 close(fd); | |
213 return; | |
214 } | |
215 v = (r << 8) | l; | |
216 ioctl(fd, cmd, &v); | |
217 close(fd); | |
218 } | |
219 } | |
220 | |
221 #else | |
222 | |
223 static void | |
224 esdout_get_oss_volume(int *l, int *r) | |
225 { | |
226 } | |
227 | |
228 static void | |
229 esdout_set_oss_volume(int l, int r) | |
230 { | |
231 } | |
232 | |
233 #endif |