Debian Codegraph @

devrplay/devrplay.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /* $Id: devrplay.c,v 1.4 1999/03/21 00:44:48 boyns Exp $ */
2
3 /*
4 * Copyright (C) 1993-99 Mark R. Boyns <[email protected]>
5 *
6 * This file is part of rplay.
7 *
8 * rplay is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * rplay is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with rplay; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 /*
25 * based on esddsp.c
26 * Copyright (C) 1998, 1999 Manish Singh <[email protected]>
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <fcntl.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/time.h>
40 #include <stdio.h>
41 #include "rplay.h"
42
43 #define DEVRPLAY_SOUND "devrplay"
44
45 #ifdef linux
46
47 #include <sys/soundcard.h>
48 #include <dlfcn.h>
49 #define REAL_LIBC RTLD_NEXT
50
51 static int rplay_fd = -1;
52 static int spool_id = -1;
53 static int dsp_fmt;
54 static int dsp_speed;
55 static int dsp_channels;
56 static int dsp_speed;
57 static int dsp_blksize;
58 static int streaming;
59
60 static char *
61 getsound()
62 {
63 char *p = getenv("DEVRPLAY_SOUND");
64 return p ? p : DEVRPLAY_SOUND;
65 }
66
67 static char *
68 getinfo()
69 {
70 char *p = getenv("DEVRPLAY_INFO");
71 return p ? p : 0;
72 }
73
74 static char *
75 getopts()
76 {
77 char *p = getenv("DEVRPLAY_OPTS");
78 return p ? p : 0;
79 }
80
81 int
82 open(const char *pathname, int flags,...)
83 {
84 static int (*func)(const char *, int, mode_t) = NULL;
85 va_list args;
86 mode_t mode;
87 char response[RPTP_MAX_LINE];
88
89 if (!func)
90 func = (int (*)(const char *, int, mode_t)) dlsym(REAL_LIBC, "open");
91
92 va_start(args, flags);
93 mode = va_arg(args, mode_t);
94 va_end(args);
95
96 if (strcmp(pathname, "/dev/dsp") == 0)
97 {
98 rplay_fd = rptp_open(rplay_default_host(), RPTP_PORT, response,
99 sizeof(response));
100 if (rplay_fd < 0)
101 {
102 rptp_perror(rplay_default_host());
103 }
104 return rplay_fd;
105 }
106 else
107 {
108 return (*func)(pathname, flags, mode);
109 }
110 }
111
112 static int
113 dspctl(int fd, int request, void *argp)
114 {
115 int *arg = (int *) argp;
116
117 switch (request)
118 {
119 case SNDCTL_DSP_SETFMT:
120 dsp_fmt = *arg;
121 break;
122
123 case SNDCTL_DSP_SPEED:
124 dsp_speed = *arg;
125 break;
126
127 case SNDCTL_DSP_STEREO:
128 dsp_channels = *arg ? 2 : 1;
129 break;
130
131 case SNDCTL_DSP_CHANNELS:
132 dsp_channels = *arg;
133 break;
134
135 case SNDCTL_DSP_GETBLKSIZE:
136 *arg = 65535;
137 break;
138
139 case SNDCTL_DSP_GETFMTS:
140 *arg = 0x38;
141 break;
142
143 case SNDCTL_DSP_GETCAPS:
144 *arg = 0;
145 break;
146
147 case SNDCTL_DSP_GETOSPACE:
148 {
149 audio_buf_info *info = (audio_buf_info *) argp;
150 info->fragments = 16;
151 info->fragstotal = 16;
152 info->fragsize = 4096;
153 info->bytes = 44100;
154 }
155 break;
156
157 default:
158 break;
159 }
160
161 if (spool_id == -1 && dsp_fmt && dsp_speed && dsp_channels)
162 {
163 char response[RPTP_MAX_LINE];
164
165 streaming = 1;
166 rptp_putline(rplay_fd,
167 "play input=flow input-info=%s,%d,%d,%d,%s %s sound=\"%s\"",
168 dsp_fmt == 16 ? "linear16" : "ulinear8",
169 dsp_speed,
170 dsp_fmt,
171 dsp_channels,
172 "little-endian",
173 getopts(),
174 getsound());
175 rptp_getline(rplay_fd, response, sizeof(response));
176
177 spool_id = atoi(1 + rptp_parse(response, "id"));
178
179 rptp_putline(rplay_fd, "put id=#%d size=0", spool_id);
180 rptp_getline(rplay_fd, response, sizeof(response));
181 }
182
183 return 0;
184 }
185
186 int
187 ioctl(int fd, int request,...)
188 {
189 static int (*func)(int, int, void *) = NULL;
190 va_list args;
191 void *argp;
192
193 if (!func)
194 func = (int (*)(int, int, void *)) dlsym(REAL_LIBC, "ioctl");
195 va_start(args, request);
196 argp = va_arg(args, void *);
197 va_end(args);
198
199 if (fd != rplay_fd)
200 {
201 return (*func)(fd, request, argp);
202 }
203 else if (fd == rplay_fd)
204 {
205 return dspctl(fd, request, argp);
206 }
207 }
208
209 ssize_t
210 write(int fd, const void *buf, size_t count)
211 {
212 static int (*func)(int, const void *, size_t) = NULL;
213
214 if (!func)
215 func = (int (*)(int, const void *, size_t)) dlsym(REAL_LIBC, "write");
216
217 if (fd == rplay_fd && !streaming)
218 {
219 char info[64];
220 char response[RPTP_MAX_LINE];
221
222 info[0] = '\0';
223
224 /* use dsp defaults if something was specified */
225 if (dsp_speed || dsp_fmt || dsp_channels)
226 {
227 if (!dsp_speed) dsp_speed = 8000;
228 if (!dsp_fmt) dsp_fmt = 8;
229 if (!dsp_channels) dsp_channels = 1;
230 sprintf(info, "input-info=%s,%d,%d,%d,%s",
231 dsp_fmt == 16 ? "linear16" : "ulinear8",
232 dsp_speed,
233 dsp_fmt,
234 dsp_channels,
235 "little-endian");
236 }
237 /* try user specified sound info */
238 else if (getinfo())
239 {
240 strncpy(info, getinfo(), sizeof(info)-1);
241 }
242 /* otherwise let rplayd figure out the format using
243 the sound header and/or name. */
244
245 streaming = 1;
246 rptp_putline(rplay_fd, "play input=flow %s sound=\"%s\"",
247 info, getsound());
248 rptp_getline(rplay_fd, response, sizeof(response));
249
250 spool_id = atoi(1 + rptp_parse(response, "id"));
251
252 rptp_putline(rplay_fd, "put id=#%d size=0", spool_id);
253 rptp_getline(rplay_fd, response, sizeof(response));
254 }
255
256 return (*func)(fd, buf, count);
257 }
258
259 int
260 close(int fd)
261 {
262 static int (*func)(int) = NULL;
263
264 if (!func)
265 func = (int (*)(int)) dlsym(REAL_LIBC, "close");
266
267 if (fd == rplay_fd)
268 {
269 rplay_fd = -1;
270 spool_id = -1;
271 streaming = 0;
272 dsp_fmt = dsp_speed = dsp_channels = dsp_speed = dsp_blksize = 0;
273 }
274
275 return (*func)(fd);
276 }
277
278 #endif /* linux */