1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/* $OpenBSD: linux_audio.c,v 1.3 1996/09/16 15:34:27 mickey Exp $ */
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/audioio.h>
#include <sys/syscallargs.h>
#include <compat/linux/linux_types.h>
#include <compat/linux/linux_ioctl.h>
#include <compat/linux/linux_signal.h>
#include <compat/linux/linux_syscallargs.h>
#include <compat/linux/linux_audio.h>
int
linux_ioctl_audio(p, uap, retval)
register struct proc *p;
register struct linux_sys_ioctl_args /* {
syscallarg(int) fd;
syscallarg(u_long) com;
syscallarg(caddr_t) data;
} */ *uap;
register_t *retval;
{
register struct file *fp;
register struct filedesc *fdp;
u_long com;
struct audio_info tmpinfo;
int idat;
int error;
fdp = p->p_fd;
if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
(fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
return (EBADF);
if ((fp->f_flag & (FREAD | FWRITE)) == 0)
return (EBADF);
com = SCARG(uap, com);
retval[0] = 0;
switch (com) {
case LINUX_SNDCTL_DSP_RESET:
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_FLUSH, (caddr_t)0, p);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_SYNC:
case LINUX_SNDCTL_DSP_POST:
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_DRAIN, (caddr_t)0, p);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_SPEED:
AUDIO_INITINFO(&tmpinfo);
error = copyin(SCARG(uap, data), &idat, sizeof idat);
if (error)
return error;
tmpinfo.play.sample_rate =
tmpinfo.record.sample_rate = idat;
(void) (*fp->f_ops->fo_ioctl)(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, p);
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
if (error)
return error;
idat = tmpinfo.play.sample_rate;
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_WRITE_CHANNELS:
AUDIO_INITINFO(&tmpinfo);
error = copyin(SCARG(uap, data), &idat, sizeof idat);
if (error)
return error;
tmpinfo.play.channels = idat;
(void) (*fp->f_ops->fo_ioctl)(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, p);
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
if (error)
return error;
idat = tmpinfo.play.channels;
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_STEREO:
AUDIO_INITINFO(&tmpinfo);
error = copyin(SCARG(uap, data), &idat, sizeof idat);
if (error)
return error;
tmpinfo.play.channels =
tmpinfo.record.channels = idat ? 2 : 1;
(void) (*fp->f_ops->fo_ioctl)(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, p);
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
if (error)
return error;
idat = tmpinfo.play.channels - 1;
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_GETBLKSIZE:
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
if (error)
return error;
idat = tmpinfo.blocksize;
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_SETFMT:
AUDIO_INITINFO(&tmpinfo);
error = copyin(SCARG(uap, data), &idat, sizeof idat);
if (error)
return error;
switch (idat) {
case LINUX_AFMT_MU_LAW:
tmpinfo.play.precision =
tmpinfo.record.precision = 8;
tmpinfo.play.encoding =
tmpinfo.record.encoding = AUDIO_ENCODING_ULAW;
break;
case LINUX_AFMT_A_LAW:
tmpinfo.play.precision =
tmpinfo.record.precision = 8;
tmpinfo.play.encoding =
tmpinfo.record.encoding = AUDIO_ENCODING_ALAW;
break;
case LINUX_AFMT_U8:
tmpinfo.play.precision =
tmpinfo.record.precision = 8;
tmpinfo.play.encoding =
tmpinfo.record.encoding = AUDIO_ENCODING_LINEAR;
break;
case LINUX_AFMT_S16_LE:
tmpinfo.play.precision =
tmpinfo.record.precision = 16;
tmpinfo.play.encoding =
tmpinfo.record.encoding = AUDIO_ENCODING_LINEAR;
break;
default:
return EINVAL;
}
(void) (*fp->f_ops->fo_ioctl)(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, p);
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
if (error)
return error;
switch(tmpinfo.play.encoding) {
case AUDIO_ENCODING_LINEAR:
if (tmpinfo.play.precision == 8)
idat = LINUX_AFMT_U8;
else if (tmpinfo.play.precision == 16)
idat = LINUX_AFMT_S16_LE;
else return EINVAL;
break;
case AUDIO_ENCODING_ULAW:
idat = LINUX_AFMT_MU_LAW;
break;
case AUDIO_ENCODING_ALAW:
idat = LINUX_AFMT_A_LAW;
break;
default:
return EINVAL;
}
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_SETFRAGMENT:
AUDIO_INITINFO(&tmpinfo);
error = copyin(SCARG(uap, data), &idat, sizeof idat);
if (error)
return error;
if ((idat & 0xffff) < 4 || (idat & 0xffff) > 17)
return EINVAL;
tmpinfo.blocksize = 1 << (idat & 0xffff);
tmpinfo.hiwat = (idat >> 16) & 0xffff;
(void) (*fp->f_ops->fo_ioctl)(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, p);
error = (*fp->f_ops->fo_ioctl)(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
if (error)
return error;
idat = tmpinfo.blocksize;
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
case LINUX_SNDCTL_DSP_GETFMTS:
idat = LINUX_AFMT_MU_LAW | LINUX_AFMT_U8 | LINUX_AFMT_S16_LE;
error = copyout(&idat, SCARG(uap, data), sizeof idat);
if (error)
return error;
break;
default:
return EINVAL;
}
return 0;
}
|