Statistics
| Branch: | Revision:

root / audio / ossaudio.c @ 301901b5

History | View | Annotate | Download (22.6 kB)

1 85571bc7 bellard
/*
2 1d14ffa9 bellard
 * QEMU OSS audio driver
3 1d14ffa9 bellard
 *
4 1d14ffa9 bellard
 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 1d14ffa9 bellard
 *
6 85571bc7 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 85571bc7 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 85571bc7 bellard
 * in the Software without restriction, including without limitation the rights
9 85571bc7 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 85571bc7 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 85571bc7 bellard
 * furnished to do so, subject to the following conditions:
12 85571bc7 bellard
 *
13 85571bc7 bellard
 * The above copyright notice and this permission notice shall be included in
14 85571bc7 bellard
 * all copies or substantial portions of the Software.
15 85571bc7 bellard
 *
16 85571bc7 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 85571bc7 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 85571bc7 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 85571bc7 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 85571bc7 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 85571bc7 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 85571bc7 bellard
 * THE SOFTWARE.
23 85571bc7 bellard
 */
24 f0c757e4 ths
#include <stdlib.h>
25 85571bc7 bellard
#include <sys/mman.h>
26 85571bc7 bellard
#include <sys/types.h>
27 85571bc7 bellard
#include <sys/ioctl.h>
28 f0c757e4 ths
#ifdef __OpenBSD__
29 f0c757e4 ths
#include <soundcard.h>
30 f0c757e4 ths
#else
31 85571bc7 bellard
#include <sys/soundcard.h>
32 f0c757e4 ths
#endif
33 87ecb68b pbrook
#include "qemu-common.h"
34 057fa65c malc
#include "host-utils.h"
35 dd8a5649 malc
#include "qemu-char.h"
36 87ecb68b pbrook
#include "audio.h"
37 fb065187 bellard
38 1d14ffa9 bellard
#define AUDIO_CAP "oss"
39 1d14ffa9 bellard
#include "audio_int.h"
40 fb065187 bellard
41 1d14ffa9 bellard
typedef struct OSSVoiceOut {
42 1d14ffa9 bellard
    HWVoiceOut hw;
43 fb065187 bellard
    void *pcm_buf;
44 fb065187 bellard
    int fd;
45 9d168976 malc
    int wpos;
46 fb065187 bellard
    int nfrags;
47 fb065187 bellard
    int fragsize;
48 fb065187 bellard
    int mmapped;
49 9d168976 malc
    int pending;
50 1d14ffa9 bellard
} OSSVoiceOut;
51 85571bc7 bellard
52 1d14ffa9 bellard
typedef struct OSSVoiceIn {
53 1d14ffa9 bellard
    HWVoiceIn hw;
54 1d14ffa9 bellard
    void *pcm_buf;
55 1d14ffa9 bellard
    int fd;
56 1d14ffa9 bellard
    int nfrags;
57 1d14ffa9 bellard
    int fragsize;
58 1d14ffa9 bellard
} OSSVoiceIn;
59 85571bc7 bellard
60 85571bc7 bellard
static struct {
61 85571bc7 bellard
    int try_mmap;
62 85571bc7 bellard
    int nfrags;
63 85571bc7 bellard
    int fragsize;
64 1d14ffa9 bellard
    const char *devpath_out;
65 1d14ffa9 bellard
    const char *devpath_in;
66 8ead62cf bellard
    int debug;
67 0b3652bc malc
    int exclusive;
68 0b3652bc malc
    int policy;
69 85571bc7 bellard
} conf = {
70 85571bc7 bellard
    .try_mmap = 0,
71 85571bc7 bellard
    .nfrags = 4,
72 85571bc7 bellard
    .fragsize = 4096,
73 1d14ffa9 bellard
    .devpath_out = "/dev/dsp",
74 8ead62cf bellard
    .devpath_in = "/dev/dsp",
75 0b3652bc malc
    .debug = 0,
76 0b3652bc malc
    .exclusive = 0,
77 0b3652bc malc
    .policy = 5
78 85571bc7 bellard
};
79 85571bc7 bellard
80 85571bc7 bellard
struct oss_params {
81 85571bc7 bellard
    int freq;
82 85571bc7 bellard
    audfmt_e fmt;
83 85571bc7 bellard
    int nchannels;
84 85571bc7 bellard
    int nfrags;
85 85571bc7 bellard
    int fragsize;
86 85571bc7 bellard
};
87 85571bc7 bellard
88 1d14ffa9 bellard
static void GCC_FMT_ATTR (2, 3) oss_logerr (int err, const char *fmt, ...)
89 85571bc7 bellard
{
90 1d14ffa9 bellard
    va_list ap;
91 1d14ffa9 bellard
92 571ec3d6 bellard
    va_start (ap, fmt);
93 1d14ffa9 bellard
    AUD_vlog (AUDIO_CAP, fmt, ap);
94 571ec3d6 bellard
    va_end (ap);
95 1d14ffa9 bellard
96 1d14ffa9 bellard
    AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
97 85571bc7 bellard
}
98 85571bc7 bellard
99 1d14ffa9 bellard
static void GCC_FMT_ATTR (3, 4) oss_logerr2 (
100 1d14ffa9 bellard
    int err,
101 1d14ffa9 bellard
    const char *typ,
102 1d14ffa9 bellard
    const char *fmt,
103 1d14ffa9 bellard
    ...
104 1d14ffa9 bellard
    )
105 1d14ffa9 bellard
{
106 1d14ffa9 bellard
    va_list ap;
107 1d14ffa9 bellard
108 c0fe3827 bellard
    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
109 1d14ffa9 bellard
110 1d14ffa9 bellard
    va_start (ap, fmt);
111 1d14ffa9 bellard
    AUD_vlog (AUDIO_CAP, fmt, ap);
112 1d14ffa9 bellard
    va_end (ap);
113 1d14ffa9 bellard
114 1d14ffa9 bellard
    AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
115 1d14ffa9 bellard
}
116 1d14ffa9 bellard
117 1d14ffa9 bellard
static void oss_anal_close (int *fdp)
118 1d14ffa9 bellard
{
119 6ebfda13 malc
    int err;
120 6ebfda13 malc
121 6ebfda13 malc
    qemu_set_fd_handler (*fdp, NULL, NULL, NULL);
122 6ebfda13 malc
    err = close (*fdp);
123 1d14ffa9 bellard
    if (err) {
124 1d14ffa9 bellard
        oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
125 1d14ffa9 bellard
    }
126 1d14ffa9 bellard
    *fdp = -1;
127 1d14ffa9 bellard
}
128 1d14ffa9 bellard
129 dd8a5649 malc
static void oss_helper_poll_out (void *opaque)
130 dd8a5649 malc
{
131 dd8a5649 malc
    (void) opaque;
132 dd8a5649 malc
    audio_run ("oss_poll_out");
133 dd8a5649 malc
}
134 dd8a5649 malc
135 dd8a5649 malc
static void oss_helper_poll_in (void *opaque)
136 dd8a5649 malc
{
137 dd8a5649 malc
    (void) opaque;
138 dd8a5649 malc
    audio_run ("oss_poll_in");
139 dd8a5649 malc
}
140 dd8a5649 malc
141 dd8a5649 malc
static int oss_poll_out (HWVoiceOut *hw)
142 dd8a5649 malc
{
143 dd8a5649 malc
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
144 dd8a5649 malc
145 dd8a5649 malc
    return qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
146 dd8a5649 malc
}
147 dd8a5649 malc
148 dd8a5649 malc
static int oss_poll_in (HWVoiceIn *hw)
149 dd8a5649 malc
{
150 dd8a5649 malc
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
151 dd8a5649 malc
152 dd8a5649 malc
    return qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
153 dd8a5649 malc
}
154 dd8a5649 malc
155 1d14ffa9 bellard
static int oss_write (SWVoiceOut *sw, void *buf, int len)
156 1d14ffa9 bellard
{
157 1d14ffa9 bellard
    return audio_pcm_sw_write (sw, buf, len);
158 1d14ffa9 bellard
}
159 1d14ffa9 bellard
160 1d14ffa9 bellard
static int aud_to_ossfmt (audfmt_e fmt)
161 85571bc7 bellard
{
162 85571bc7 bellard
    switch (fmt) {
163 1d14ffa9 bellard
    case AUD_FMT_S8:
164 1d14ffa9 bellard
        return AFMT_S8;
165 1d14ffa9 bellard
166 1d14ffa9 bellard
    case AUD_FMT_U8:
167 1d14ffa9 bellard
        return AFMT_U8;
168 1d14ffa9 bellard
169 1d14ffa9 bellard
    case AUD_FMT_S16:
170 1d14ffa9 bellard
        return AFMT_S16_LE;
171 1d14ffa9 bellard
172 1d14ffa9 bellard
    case AUD_FMT_U16:
173 1d14ffa9 bellard
        return AFMT_U16_LE;
174 1d14ffa9 bellard
175 85571bc7 bellard
    default:
176 1d14ffa9 bellard
        dolog ("Internal logic error: Bad audio format %d\n", fmt);
177 1d14ffa9 bellard
#ifdef DEBUG_AUDIO
178 1d14ffa9 bellard
        abort ();
179 1d14ffa9 bellard
#endif
180 1d14ffa9 bellard
        return AFMT_U8;
181 85571bc7 bellard
    }
182 85571bc7 bellard
}
183 85571bc7 bellard
184 1d14ffa9 bellard
static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness)
185 85571bc7 bellard
{
186 1d14ffa9 bellard
    switch (ossfmt) {
187 1d14ffa9 bellard
    case AFMT_S8:
188 ca9cc28c balrog
        *endianness = 0;
189 1d14ffa9 bellard
        *fmt = AUD_FMT_S8;
190 1d14ffa9 bellard
        break;
191 1d14ffa9 bellard
192 1d14ffa9 bellard
    case AFMT_U8:
193 1d14ffa9 bellard
        *endianness = 0;
194 1d14ffa9 bellard
        *fmt = AUD_FMT_U8;
195 1d14ffa9 bellard
        break;
196 1d14ffa9 bellard
197 1d14ffa9 bellard
    case AFMT_S16_LE:
198 1d14ffa9 bellard
        *endianness = 0;
199 1d14ffa9 bellard
        *fmt = AUD_FMT_S16;
200 1d14ffa9 bellard
        break;
201 1d14ffa9 bellard
202 1d14ffa9 bellard
    case AFMT_U16_LE:
203 1d14ffa9 bellard
        *endianness = 0;
204 1d14ffa9 bellard
        *fmt = AUD_FMT_U16;
205 1d14ffa9 bellard
        break;
206 1d14ffa9 bellard
207 1d14ffa9 bellard
    case AFMT_S16_BE:
208 1d14ffa9 bellard
        *endianness = 1;
209 1d14ffa9 bellard
        *fmt = AUD_FMT_S16;
210 1d14ffa9 bellard
        break;
211 1d14ffa9 bellard
212 1d14ffa9 bellard
    case AFMT_U16_BE:
213 1d14ffa9 bellard
        *endianness = 1;
214 1d14ffa9 bellard
        *fmt = AUD_FMT_U16;
215 1d14ffa9 bellard
        break;
216 1d14ffa9 bellard
217 85571bc7 bellard
    default:
218 1d14ffa9 bellard
        dolog ("Unrecognized audio format %d\n", ossfmt);
219 1d14ffa9 bellard
        return -1;
220 85571bc7 bellard
    }
221 1d14ffa9 bellard
222 1d14ffa9 bellard
    return 0;
223 85571bc7 bellard
}
224 85571bc7 bellard
225 c0fe3827 bellard
#if defined DEBUG_MISMATCHES || defined DEBUG
226 1d14ffa9 bellard
static void oss_dump_info (struct oss_params *req, struct oss_params *obt)
227 85571bc7 bellard
{
228 85571bc7 bellard
    dolog ("parameter | requested value | obtained value\n");
229 85571bc7 bellard
    dolog ("format    |      %10d |     %10d\n", req->fmt, obt->fmt);
230 1d14ffa9 bellard
    dolog ("channels  |      %10d |     %10d\n",
231 1d14ffa9 bellard
           req->nchannels, obt->nchannels);
232 85571bc7 bellard
    dolog ("frequency |      %10d |     %10d\n", req->freq, obt->freq);
233 85571bc7 bellard
    dolog ("nfrags    |      %10d |     %10d\n", req->nfrags, obt->nfrags);
234 1d14ffa9 bellard
    dolog ("fragsize  |      %10d |     %10d\n",
235 1d14ffa9 bellard
           req->fragsize, obt->fragsize);
236 85571bc7 bellard
}
237 85571bc7 bellard
#endif
238 85571bc7 bellard
239 1d14ffa9 bellard
static int oss_open (int in, struct oss_params *req,
240 1d14ffa9 bellard
                     struct oss_params *obt, int *pfd)
241 85571bc7 bellard
{
242 85571bc7 bellard
    int fd;
243 0b3652bc malc
    int version;
244 0b3652bc malc
    int oflags = conf.exclusive ? O_EXCL : 0;
245 85571bc7 bellard
    audio_buf_info abinfo;
246 85571bc7 bellard
    int fmt, freq, nchannels;
247 1d14ffa9 bellard
    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
248 1d14ffa9 bellard
    const char *typ = in ? "ADC" : "DAC";
249 85571bc7 bellard
250 2182349d malc
    /* Kludge needed to have working mmap on Linux */
251 0b3652bc malc
    oflags |= conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
252 0b3652bc malc
253 2182349d malc
    fd = open (dspname, oflags | O_NONBLOCK);
254 85571bc7 bellard
    if (-1 == fd) {
255 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
256 85571bc7 bellard
        return -1;
257 85571bc7 bellard
    }
258 85571bc7 bellard
259 85571bc7 bellard
    freq = req->freq;
260 85571bc7 bellard
    nchannels = req->nchannels;
261 85571bc7 bellard
    fmt = req->fmt;
262 85571bc7 bellard
263 85571bc7 bellard
    if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
264 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
265 85571bc7 bellard
        goto err;
266 85571bc7 bellard
    }
267 85571bc7 bellard
268 85571bc7 bellard
    if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
269 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",
270 1d14ffa9 bellard
                     req->nchannels);
271 85571bc7 bellard
        goto err;
272 85571bc7 bellard
    }
273 85571bc7 bellard
274 85571bc7 bellard
    if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
275 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);
276 85571bc7 bellard
        goto err;
277 85571bc7 bellard
    }
278 85571bc7 bellard
279 902e2b51 malc
    if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
280 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
281 85571bc7 bellard
        goto err;
282 85571bc7 bellard
    }
283 85571bc7 bellard
284 0b3652bc malc
    if (ioctl (fd, OSS_GETVERSION, &version)) {
285 0b3652bc malc
        oss_logerr2 (errno, typ, "Failed to get OSS version\n");
286 0b3652bc malc
        version = 0;
287 0b3652bc malc
    }
288 0b3652bc malc
289 0b3652bc malc
    if (conf.debug) {
290 0b3652bc malc
        dolog ("OSS version = %#x\n", version);
291 0b3652bc malc
    }
292 0b3652bc malc
293 0b3652bc malc
#ifdef SNDCTL_DSP_POLICY
294 0b3652bc malc
    if (conf.policy >= 0 && version >= 0x040000) {
295 0b3652bc malc
        int policy = conf.policy;
296 0b3652bc malc
        if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) {
297 0b3652bc malc
            oss_logerr2 (errno, typ, "Failed to set timing policy to %d\n",
298 0b3652bc malc
                         conf.policy);
299 0b3652bc malc
            goto err;
300 0b3652bc malc
        }
301 0b3652bc malc
    }
302 0b3652bc malc
    else
303 0b3652bc malc
#endif
304 0b3652bc malc
    {
305 0b3652bc malc
        int mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
306 0b3652bc malc
        if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
307 0b3652bc malc
            oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
308 0b3652bc malc
                         req->nfrags, req->fragsize);
309 0b3652bc malc
            goto err;
310 0b3652bc malc
        }
311 85571bc7 bellard
    }
312 85571bc7 bellard
313 1d14ffa9 bellard
    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
314 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to get buffer length\n");
315 85571bc7 bellard
        goto err;
316 85571bc7 bellard
    }
317 85571bc7 bellard
318 29ddf27b malc
    if (!abinfo.fragstotal || !abinfo.fragsize) {
319 29ddf27b malc
        AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",
320 29ddf27b malc
                 abinfo.fragstotal, abinfo.fragsize, typ);
321 29ddf27b malc
        goto err;
322 29ddf27b malc
    }
323 29ddf27b malc
324 85571bc7 bellard
    obt->fmt = fmt;
325 85571bc7 bellard
    obt->nchannels = nchannels;
326 85571bc7 bellard
    obt->freq = freq;
327 85571bc7 bellard
    obt->nfrags = abinfo.fragstotal;
328 85571bc7 bellard
    obt->fragsize = abinfo.fragsize;
329 85571bc7 bellard
    *pfd = fd;
330 85571bc7 bellard
331 c0fe3827 bellard
#ifdef DEBUG_MISMATCHES
332 85571bc7 bellard
    if ((req->fmt != obt->fmt) ||
333 85571bc7 bellard
        (req->nchannels != obt->nchannels) ||
334 85571bc7 bellard
        (req->freq != obt->freq) ||
335 85571bc7 bellard
        (req->fragsize != obt->fragsize) ||
336 85571bc7 bellard
        (req->nfrags != obt->nfrags)) {
337 85571bc7 bellard
        dolog ("Audio parameters mismatch\n");
338 1d14ffa9 bellard
        oss_dump_info (req, obt);
339 85571bc7 bellard
    }
340 c0fe3827 bellard
#endif
341 85571bc7 bellard
342 1d14ffa9 bellard
#ifdef DEBUG
343 1d14ffa9 bellard
    oss_dump_info (req, obt);
344 85571bc7 bellard
#endif
345 85571bc7 bellard
    return 0;
346 85571bc7 bellard
347 1d14ffa9 bellard
 err:
348 1d14ffa9 bellard
    oss_anal_close (&fd);
349 85571bc7 bellard
    return -1;
350 85571bc7 bellard
}
351 85571bc7 bellard
352 9d168976 malc
static void oss_write_pending (OSSVoiceOut *oss)
353 9d168976 malc
{
354 9d168976 malc
    HWVoiceOut *hw = &oss->hw;
355 9d168976 malc
356 9d168976 malc
    if (oss->mmapped) {
357 9d168976 malc
        return;
358 9d168976 malc
    }
359 9d168976 malc
360 9d168976 malc
    while (oss->pending) {
361 9d168976 malc
        int samples_written;
362 9d168976 malc
        ssize_t bytes_written;
363 9d168976 malc
        int samples_till_end = hw->samples - oss->wpos;
364 9d168976 malc
        int samples_to_write = audio_MIN (oss->pending, samples_till_end);
365 9d168976 malc
        int bytes_to_write = samples_to_write << hw->info.shift;
366 9d168976 malc
        void *pcm = advance (oss->pcm_buf, oss->wpos << hw->info.shift);
367 9d168976 malc
368 9d168976 malc
        bytes_written = write (oss->fd, pcm, bytes_to_write);
369 9d168976 malc
        if (bytes_written < 0) {
370 9d168976 malc
            if (errno != EAGAIN) {
371 9d168976 malc
                oss_logerr (errno, "failed to write %d bytes\n",
372 9d168976 malc
                            bytes_to_write);
373 9d168976 malc
            }
374 9d168976 malc
            break;
375 9d168976 malc
        }
376 9d168976 malc
377 9d168976 malc
        if (bytes_written & hw->info.align) {
378 9d168976 malc
            dolog ("misaligned write asked for %d, but got %zd\n",
379 9d168976 malc
                   bytes_to_write, bytes_written);
380 9d168976 malc
            return;
381 9d168976 malc
        }
382 9d168976 malc
383 9d168976 malc
        samples_written = bytes_written >> hw->info.shift;
384 9d168976 malc
        oss->pending -= samples_written;
385 9d168976 malc
        oss->wpos = (oss->wpos + samples_written) % hw->samples;
386 9d168976 malc
        if (bytes_written - bytes_to_write) {
387 9d168976 malc
            break;
388 9d168976 malc
        }
389 9d168976 malc
    }
390 9d168976 malc
}
391 9d168976 malc
392 bdff253c malc
static int oss_run_out (HWVoiceOut *hw, int live)
393 85571bc7 bellard
{
394 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
395 bdff253c malc
    int err, decr;
396 85571bc7 bellard
    struct audio_buf_info abinfo;
397 85571bc7 bellard
    struct count_info cntinfo;
398 c0fe3827 bellard
    int bufsize;
399 85571bc7 bellard
400 c0fe3827 bellard
    bufsize = hw->samples << hw->info.shift;
401 c0fe3827 bellard
402 85571bc7 bellard
    if (oss->mmapped) {
403 54762b73 malc
        int bytes, pos;
404 85571bc7 bellard
405 85571bc7 bellard
        err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);
406 85571bc7 bellard
        if (err < 0) {
407 1d14ffa9 bellard
            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");
408 1d14ffa9 bellard
            return 0;
409 85571bc7 bellard
        }
410 85571bc7 bellard
411 54762b73 malc
        pos = hw->rpos << hw->info.shift;
412 54762b73 malc
        bytes = audio_ring_dist (cntinfo.ptr, pos, bufsize);
413 1d14ffa9 bellard
        decr = audio_MIN (bytes >> hw->info.shift, live);
414 85571bc7 bellard
    }
415 85571bc7 bellard
    else {
416 85571bc7 bellard
        err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);
417 85571bc7 bellard
        if (err < 0) {
418 1d14ffa9 bellard
            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");
419 1d14ffa9 bellard
            return 0;
420 1d14ffa9 bellard
        }
421 1d14ffa9 bellard
422 8ead62cf bellard
        if (abinfo.bytes > bufsize) {
423 8ead62cf bellard
            if (conf.debug) {
424 8ead62cf bellard
                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
425 155a8ad3 malc
                       "please report your OS/audio hw to av1474@comtv.ru\n",
426 8ead62cf bellard
                       abinfo.bytes, bufsize);
427 8ead62cf bellard
            }
428 8ead62cf bellard
            abinfo.bytes = bufsize;
429 8ead62cf bellard
        }
430 8ead62cf bellard
431 8ead62cf bellard
        if (abinfo.bytes < 0) {
432 8ead62cf bellard
            if (conf.debug) {
433 8ead62cf bellard
                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
434 8ead62cf bellard
                       abinfo.bytes, bufsize);
435 8ead62cf bellard
            }
436 1d14ffa9 bellard
            return 0;
437 85571bc7 bellard
        }
438 85571bc7 bellard
439 1d14ffa9 bellard
        decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);
440 1d14ffa9 bellard
        if (!decr) {
441 1d14ffa9 bellard
            return 0;
442 1d14ffa9 bellard
        }
443 85571bc7 bellard
    }
444 85571bc7 bellard
445 9d168976 malc
    decr = audio_pcm_hw_clip_out (hw, oss->pcm_buf, decr, oss->pending);
446 9d168976 malc
    oss->pending += decr;
447 9d168976 malc
    oss_write_pending (oss);
448 85571bc7 bellard
449 1d14ffa9 bellard
    return decr;
450 85571bc7 bellard
}
451 85571bc7 bellard
452 1d14ffa9 bellard
static void oss_fini_out (HWVoiceOut *hw)
453 85571bc7 bellard
{
454 85571bc7 bellard
    int err;
455 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
456 85571bc7 bellard
457 1d14ffa9 bellard
    ldebug ("oss_fini\n");
458 1d14ffa9 bellard
    oss_anal_close (&oss->fd);
459 85571bc7 bellard
460 85571bc7 bellard
    if (oss->pcm_buf) {
461 85571bc7 bellard
        if (oss->mmapped) {
462 c0fe3827 bellard
            err = munmap (oss->pcm_buf, hw->samples << hw->info.shift);
463 85571bc7 bellard
            if (err) {
464 1d14ffa9 bellard
                oss_logerr (errno, "Failed to unmap buffer %p, size %d\n",
465 c0fe3827 bellard
                            oss->pcm_buf, hw->samples << hw->info.shift);
466 85571bc7 bellard
            }
467 85571bc7 bellard
        }
468 85571bc7 bellard
        else {
469 85571bc7 bellard
            qemu_free (oss->pcm_buf);
470 85571bc7 bellard
        }
471 85571bc7 bellard
        oss->pcm_buf = NULL;
472 85571bc7 bellard
    }
473 85571bc7 bellard
}
474 85571bc7 bellard
475 1ea879e5 malc
static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
476 85571bc7 bellard
{
477 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
478 85571bc7 bellard
    struct oss_params req, obt;
479 1d14ffa9 bellard
    int endianness;
480 1d14ffa9 bellard
    int err;
481 1d14ffa9 bellard
    int fd;
482 1d14ffa9 bellard
    audfmt_e effective_fmt;
483 1ea879e5 malc
    struct audsettings obt_as;
484 85571bc7 bellard
485 571ec3d6 bellard
    oss->fd = -1;
486 571ec3d6 bellard
487 c0fe3827 bellard
    req.fmt = aud_to_ossfmt (as->fmt);
488 c0fe3827 bellard
    req.freq = as->freq;
489 c0fe3827 bellard
    req.nchannels = as->nchannels;
490 85571bc7 bellard
    req.fragsize = conf.fragsize;
491 85571bc7 bellard
    req.nfrags = conf.nfrags;
492 85571bc7 bellard
493 1d14ffa9 bellard
    if (oss_open (0, &req, &obt, &fd)) {
494 85571bc7 bellard
        return -1;
495 1d14ffa9 bellard
    }
496 85571bc7 bellard
497 1d14ffa9 bellard
    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
498 1d14ffa9 bellard
    if (err) {
499 1d14ffa9 bellard
        oss_anal_close (&fd);
500 1d14ffa9 bellard
        return -1;
501 1d14ffa9 bellard
    }
502 85571bc7 bellard
503 c0fe3827 bellard
    obt_as.freq = obt.freq;
504 c0fe3827 bellard
    obt_as.nchannels = obt.nchannels;
505 c0fe3827 bellard
    obt_as.fmt = effective_fmt;
506 d929eba5 bellard
    obt_as.endianness = endianness;
507 c0fe3827 bellard
508 d929eba5 bellard
    audio_pcm_init_info (&hw->info, &obt_as);
509 85571bc7 bellard
    oss->nfrags = obt.nfrags;
510 85571bc7 bellard
    oss->fragsize = obt.fragsize;
511 c0fe3827 bellard
512 c0fe3827 bellard
    if (obt.nfrags * obt.fragsize & hw->info.align) {
513 c0fe3827 bellard
        dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n",
514 c0fe3827 bellard
               obt.nfrags * obt.fragsize, hw->info.align + 1);
515 c0fe3827 bellard
    }
516 c0fe3827 bellard
517 c0fe3827 bellard
    hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
518 85571bc7 bellard
519 85571bc7 bellard
    oss->mmapped = 0;
520 85571bc7 bellard
    if (conf.try_mmap) {
521 c0fe3827 bellard
        oss->pcm_buf = mmap (
522 660f11be Blue Swirl
            NULL,
523 c0fe3827 bellard
            hw->samples << hw->info.shift,
524 c0fe3827 bellard
            PROT_READ | PROT_WRITE,
525 c0fe3827 bellard
            MAP_SHARED,
526 c0fe3827 bellard
            fd,
527 c0fe3827 bellard
            0
528 c0fe3827 bellard
            );
529 85571bc7 bellard
        if (oss->pcm_buf == MAP_FAILED) {
530 1d14ffa9 bellard
            oss_logerr (errno, "Failed to map %d bytes of DAC\n",
531 c0fe3827 bellard
                        hw->samples << hw->info.shift);
532 54762b73 malc
        }
533 54762b73 malc
        else {
534 85571bc7 bellard
            int err;
535 85571bc7 bellard
            int trig = 0;
536 1d14ffa9 bellard
            if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
537 1d14ffa9 bellard
                oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
538 85571bc7 bellard
            }
539 44a095a7 bellard
            else {
540 44a095a7 bellard
                trig = PCM_ENABLE_OUTPUT;
541 1d14ffa9 bellard
                if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
542 1d14ffa9 bellard
                    oss_logerr (
543 1d14ffa9 bellard
                        errno,
544 1d14ffa9 bellard
                        "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
545 1d14ffa9 bellard
                        );
546 44a095a7 bellard
                }
547 44a095a7 bellard
                else {
548 44a095a7 bellard
                    oss->mmapped = 1;
549 44a095a7 bellard
                }
550 85571bc7 bellard
            }
551 85571bc7 bellard
552 44a095a7 bellard
            if (!oss->mmapped) {
553 c0fe3827 bellard
                err = munmap (oss->pcm_buf, hw->samples << hw->info.shift);
554 44a095a7 bellard
                if (err) {
555 1d14ffa9 bellard
                    oss_logerr (errno, "Failed to unmap buffer %p size %d\n",
556 c0fe3827 bellard
                                oss->pcm_buf, hw->samples << hw->info.shift);
557 44a095a7 bellard
                }
558 85571bc7 bellard
            }
559 85571bc7 bellard
        }
560 85571bc7 bellard
    }
561 85571bc7 bellard
562 85571bc7 bellard
    if (!oss->mmapped) {
563 c0fe3827 bellard
        oss->pcm_buf = audio_calloc (
564 c0fe3827 bellard
            AUDIO_FUNC,
565 c0fe3827 bellard
            hw->samples,
566 c0fe3827 bellard
            1 << hw->info.shift
567 c0fe3827 bellard
            );
568 85571bc7 bellard
        if (!oss->pcm_buf) {
569 b41cffbe bellard
            dolog (
570 b41cffbe bellard
                "Could not allocate DAC buffer (%d samples, each %d bytes)\n",
571 b41cffbe bellard
                hw->samples,
572 b41cffbe bellard
                1 << hw->info.shift
573 b41cffbe bellard
                );
574 1d14ffa9 bellard
            oss_anal_close (&fd);
575 85571bc7 bellard
            return -1;
576 85571bc7 bellard
        }
577 85571bc7 bellard
    }
578 85571bc7 bellard
579 1d14ffa9 bellard
    oss->fd = fd;
580 85571bc7 bellard
    return 0;
581 85571bc7 bellard
}
582 85571bc7 bellard
583 1d14ffa9 bellard
static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
584 85571bc7 bellard
{
585 85571bc7 bellard
    int trig;
586 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
587 85571bc7 bellard
588 85571bc7 bellard
    switch (cmd) {
589 85571bc7 bellard
    case VOICE_ENABLE:
590 301901b5 malc
        {
591 301901b5 malc
            va_list ap;
592 301901b5 malc
            int poll_mode;
593 dd8a5649 malc
594 301901b5 malc
            va_start (ap, cmd);
595 301901b5 malc
            poll_mode = va_arg (ap, int);
596 301901b5 malc
            va_end (ap);
597 dd8a5649 malc
598 301901b5 malc
            ldebug ("enabling voice\n");
599 301901b5 malc
            if (poll_mode && oss_poll_out (hw)) {
600 301901b5 malc
                poll_mode = 0;
601 301901b5 malc
            }
602 301901b5 malc
            hw->poll_mode = poll_mode;
603 301901b5 malc
604 301901b5 malc
            if (!oss->mmapped) {
605 301901b5 malc
                return 0;
606 301901b5 malc
            }
607 301901b5 malc
608 301901b5 malc
            audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples);
609 301901b5 malc
            trig = PCM_ENABLE_OUTPUT;
610 301901b5 malc
            if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
611 301901b5 malc
                oss_logerr (
612 301901b5 malc
                    errno,
613 301901b5 malc
                    "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
614 301901b5 malc
                    );
615 301901b5 malc
                return -1;
616 301901b5 malc
            }
617 85571bc7 bellard
        }
618 85571bc7 bellard
        break;
619 85571bc7 bellard
620 85571bc7 bellard
    case VOICE_DISABLE:
621 dd8a5649 malc
        if (hw->poll_mode) {
622 dd8a5649 malc
            qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
623 dd8a5649 malc
            hw->poll_mode = 0;
624 dd8a5649 malc
        }
625 dd8a5649 malc
626 dd8a5649 malc
        if (!oss->mmapped) {
627 dd8a5649 malc
            return 0;
628 dd8a5649 malc
        }
629 dd8a5649 malc
630 85571bc7 bellard
        ldebug ("disabling voice\n");
631 85571bc7 bellard
        trig = 0;
632 85571bc7 bellard
        if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
633 1d14ffa9 bellard
            oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
634 85571bc7 bellard
            return -1;
635 85571bc7 bellard
        }
636 85571bc7 bellard
        break;
637 85571bc7 bellard
    }
638 85571bc7 bellard
    return 0;
639 85571bc7 bellard
}
640 85571bc7 bellard
641 1ea879e5 malc
static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
642 1d14ffa9 bellard
{
643 1d14ffa9 bellard
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
644 1d14ffa9 bellard
    struct oss_params req, obt;
645 1d14ffa9 bellard
    int endianness;
646 1d14ffa9 bellard
    int err;
647 1d14ffa9 bellard
    int fd;
648 1d14ffa9 bellard
    audfmt_e effective_fmt;
649 1ea879e5 malc
    struct audsettings obt_as;
650 1d14ffa9 bellard
651 571ec3d6 bellard
    oss->fd = -1;
652 571ec3d6 bellard
653 c0fe3827 bellard
    req.fmt = aud_to_ossfmt (as->fmt);
654 c0fe3827 bellard
    req.freq = as->freq;
655 c0fe3827 bellard
    req.nchannels = as->nchannels;
656 1d14ffa9 bellard
    req.fragsize = conf.fragsize;
657 1d14ffa9 bellard
    req.nfrags = conf.nfrags;
658 1d14ffa9 bellard
    if (oss_open (1, &req, &obt, &fd)) {
659 1d14ffa9 bellard
        return -1;
660 1d14ffa9 bellard
    }
661 1d14ffa9 bellard
662 1d14ffa9 bellard
    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
663 1d14ffa9 bellard
    if (err) {
664 1d14ffa9 bellard
        oss_anal_close (&fd);
665 1d14ffa9 bellard
        return -1;
666 1d14ffa9 bellard
    }
667 1d14ffa9 bellard
668 c0fe3827 bellard
    obt_as.freq = obt.freq;
669 c0fe3827 bellard
    obt_as.nchannels = obt.nchannels;
670 c0fe3827 bellard
    obt_as.fmt = effective_fmt;
671 d929eba5 bellard
    obt_as.endianness = endianness;
672 c0fe3827 bellard
673 d929eba5 bellard
    audio_pcm_init_info (&hw->info, &obt_as);
674 1d14ffa9 bellard
    oss->nfrags = obt.nfrags;
675 1d14ffa9 bellard
    oss->fragsize = obt.fragsize;
676 c0fe3827 bellard
677 c0fe3827 bellard
    if (obt.nfrags * obt.fragsize & hw->info.align) {
678 c0fe3827 bellard
        dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n",
679 c0fe3827 bellard
               obt.nfrags * obt.fragsize, hw->info.align + 1);
680 c0fe3827 bellard
    }
681 c0fe3827 bellard
682 c0fe3827 bellard
    hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
683 c0fe3827 bellard
    oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
684 1d14ffa9 bellard
    if (!oss->pcm_buf) {
685 b41cffbe bellard
        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
686 b41cffbe bellard
               hw->samples, 1 << hw->info.shift);
687 1d14ffa9 bellard
        oss_anal_close (&fd);
688 1d14ffa9 bellard
        return -1;
689 1d14ffa9 bellard
    }
690 1d14ffa9 bellard
691 1d14ffa9 bellard
    oss->fd = fd;
692 1d14ffa9 bellard
    return 0;
693 1d14ffa9 bellard
}
694 1d14ffa9 bellard
695 1d14ffa9 bellard
static void oss_fini_in (HWVoiceIn *hw)
696 1d14ffa9 bellard
{
697 1d14ffa9 bellard
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
698 1d14ffa9 bellard
699 1d14ffa9 bellard
    oss_anal_close (&oss->fd);
700 1d14ffa9 bellard
701 1d14ffa9 bellard
    if (oss->pcm_buf) {
702 1d14ffa9 bellard
        qemu_free (oss->pcm_buf);
703 1d14ffa9 bellard
        oss->pcm_buf = NULL;
704 1d14ffa9 bellard
    }
705 1d14ffa9 bellard
}
706 1d14ffa9 bellard
707 1d14ffa9 bellard
static int oss_run_in (HWVoiceIn *hw)
708 1d14ffa9 bellard
{
709 1d14ffa9 bellard
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
710 1d14ffa9 bellard
    int hwshift = hw->info.shift;
711 1d14ffa9 bellard
    int i;
712 1d14ffa9 bellard
    int live = audio_pcm_hw_get_live_in (hw);
713 1d14ffa9 bellard
    int dead = hw->samples - live;
714 1d14ffa9 bellard
    size_t read_samples = 0;
715 1d14ffa9 bellard
    struct {
716 1d14ffa9 bellard
        int add;
717 1d14ffa9 bellard
        int len;
718 1d14ffa9 bellard
    } bufs[2] = {
719 98f9f48c malc
        { .add = hw->wpos, .len = 0 },
720 98f9f48c malc
        { .add = 0,        .len = 0 }
721 1d14ffa9 bellard
    };
722 1d14ffa9 bellard
723 1d14ffa9 bellard
    if (!dead) {
724 1d14ffa9 bellard
        return 0;
725 1d14ffa9 bellard
    }
726 1d14ffa9 bellard
727 1d14ffa9 bellard
    if (hw->wpos + dead > hw->samples) {
728 1d14ffa9 bellard
        bufs[0].len = (hw->samples - hw->wpos) << hwshift;
729 1d14ffa9 bellard
        bufs[1].len = (dead - (hw->samples - hw->wpos)) << hwshift;
730 1d14ffa9 bellard
    }
731 1d14ffa9 bellard
    else {
732 1d14ffa9 bellard
        bufs[0].len = dead << hwshift;
733 1d14ffa9 bellard
    }
734 1d14ffa9 bellard
735 1d14ffa9 bellard
    for (i = 0; i < 2; ++i) {
736 1d14ffa9 bellard
        ssize_t nread;
737 1d14ffa9 bellard
738 1d14ffa9 bellard
        if (bufs[i].len) {
739 1d14ffa9 bellard
            void *p = advance (oss->pcm_buf, bufs[i].add << hwshift);
740 1d14ffa9 bellard
            nread = read (oss->fd, p, bufs[i].len);
741 1d14ffa9 bellard
742 1d14ffa9 bellard
            if (nread > 0) {
743 1d14ffa9 bellard
                if (nread & hw->info.align) {
744 b41cffbe bellard
                    dolog ("warning: Misaligned read %zd (requested %d), "
745 1d14ffa9 bellard
                           "alignment %d\n", nread, bufs[i].add << hwshift,
746 1d14ffa9 bellard
                           hw->info.align + 1);
747 1d14ffa9 bellard
                }
748 1d14ffa9 bellard
                read_samples += nread >> hwshift;
749 1d14ffa9 bellard
                hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift,
750 1d14ffa9 bellard
                          &nominal_volume);
751 1d14ffa9 bellard
            }
752 1d14ffa9 bellard
753 1d14ffa9 bellard
            if (bufs[i].len - nread) {
754 1d14ffa9 bellard
                if (nread == -1) {
755 1d14ffa9 bellard
                    switch (errno) {
756 1d14ffa9 bellard
                    case EINTR:
757 1d14ffa9 bellard
                    case EAGAIN:
758 1d14ffa9 bellard
                        break;
759 1d14ffa9 bellard
                    default:
760 1d14ffa9 bellard
                        oss_logerr (
761 1d14ffa9 bellard
                            errno,
762 1d14ffa9 bellard
                            "Failed to read %d bytes of audio (to %p)\n",
763 1d14ffa9 bellard
                            bufs[i].len, p
764 1d14ffa9 bellard
                            );
765 1d14ffa9 bellard
                        break;
766 1d14ffa9 bellard
                    }
767 1d14ffa9 bellard
                }
768 1d14ffa9 bellard
                break;
769 1d14ffa9 bellard
            }
770 1d14ffa9 bellard
        }
771 1d14ffa9 bellard
    }
772 1d14ffa9 bellard
773 1d14ffa9 bellard
    hw->wpos = (hw->wpos + read_samples) % hw->samples;
774 1d14ffa9 bellard
    return read_samples;
775 1d14ffa9 bellard
}
776 1d14ffa9 bellard
777 1d14ffa9 bellard
static int oss_read (SWVoiceIn *sw, void *buf, int size)
778 1d14ffa9 bellard
{
779 1d14ffa9 bellard
    return audio_pcm_sw_read (sw, buf, size);
780 1d14ffa9 bellard
}
781 1d14ffa9 bellard
782 1d14ffa9 bellard
static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
783 1d14ffa9 bellard
{
784 dd8a5649 malc
    va_list ap;
785 dd8a5649 malc
    int poll_mode;
786 dd8a5649 malc
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
787 dd8a5649 malc
788 dd8a5649 malc
    va_start (ap, cmd);
789 dd8a5649 malc
    poll_mode = va_arg (ap, int);
790 dd8a5649 malc
    va_end (ap);
791 dd8a5649 malc
792 dd8a5649 malc
    switch (cmd) {
793 dd8a5649 malc
    case VOICE_ENABLE:
794 dd8a5649 malc
        if (poll_mode && oss_poll_in (hw)) {
795 dd8a5649 malc
            poll_mode = 0;
796 dd8a5649 malc
        }
797 dd8a5649 malc
        hw->poll_mode = poll_mode;
798 dd8a5649 malc
        break;
799 dd8a5649 malc
800 dd8a5649 malc
    case VOICE_DISABLE:
801 dd8a5649 malc
        if (hw->poll_mode) {
802 dd8a5649 malc
            hw->poll_mode = 0;
803 dd8a5649 malc
            qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
804 dd8a5649 malc
        }
805 dd8a5649 malc
        break;
806 dd8a5649 malc
    }
807 1d14ffa9 bellard
    return 0;
808 1d14ffa9 bellard
}
809 1d14ffa9 bellard
810 85571bc7 bellard
static void *oss_audio_init (void)
811 85571bc7 bellard
{
812 85571bc7 bellard
    return &conf;
813 85571bc7 bellard
}
814 85571bc7 bellard
815 85571bc7 bellard
static void oss_audio_fini (void *opaque)
816 85571bc7 bellard
{
817 1d14ffa9 bellard
    (void) opaque;
818 85571bc7 bellard
}
819 85571bc7 bellard
820 1d14ffa9 bellard
static struct audio_option oss_options[] = {
821 98f9f48c malc
    {
822 98f9f48c malc
        .name  = "FRAGSIZE",
823 98f9f48c malc
        .tag   = AUD_OPT_INT,
824 98f9f48c malc
        .valp  = &conf.fragsize,
825 98f9f48c malc
        .descr = "Fragment size in bytes"
826 98f9f48c malc
    },
827 98f9f48c malc
    {
828 98f9f48c malc
        .name  = "NFRAGS",
829 98f9f48c malc
        .tag   = AUD_OPT_INT,
830 98f9f48c malc
        .valp  = &conf.nfrags,
831 98f9f48c malc
        .descr = "Number of fragments"
832 98f9f48c malc
    },
833 98f9f48c malc
    {
834 98f9f48c malc
        .name  = "MMAP",
835 98f9f48c malc
        .tag   = AUD_OPT_BOOL,
836 98f9f48c malc
        .valp  = &conf.try_mmap,
837 98f9f48c malc
        .descr = "Try using memory mapped access"
838 98f9f48c malc
    },
839 98f9f48c malc
    {
840 98f9f48c malc
        .name  = "DAC_DEV",
841 98f9f48c malc
        .tag   = AUD_OPT_STR,
842 98f9f48c malc
        .valp  = &conf.devpath_out,
843 98f9f48c malc
        .descr = "Path to DAC device"
844 98f9f48c malc
    },
845 98f9f48c malc
    {
846 98f9f48c malc
        .name  = "ADC_DEV",
847 98f9f48c malc
        .tag   = AUD_OPT_STR,
848 98f9f48c malc
        .valp  = &conf.devpath_in,
849 98f9f48c malc
        .descr = "Path to ADC device"
850 98f9f48c malc
    },
851 98f9f48c malc
    {
852 0b3652bc malc
        .name  = "EXCLUSIVE",
853 0b3652bc malc
        .tag   = AUD_OPT_BOOL,
854 0b3652bc malc
        .valp  = &conf.exclusive,
855 0b3652bc malc
        .descr = "Open device in exclusive mode (vmix wont work)"
856 0b3652bc malc
    },
857 0b3652bc malc
#ifdef SNDCTL_DSP_POLICY
858 0b3652bc malc
    {
859 0b3652bc malc
        .name  = "POLICY",
860 0b3652bc malc
        .tag   = AUD_OPT_INT,
861 0b3652bc malc
        .valp  = &conf.policy,
862 0b3652bc malc
        .descr = "Set the timing policy of the device, -1 to use fragment mode",
863 0b3652bc malc
    },
864 0b3652bc malc
#endif
865 0b3652bc malc
    {
866 98f9f48c malc
        .name  = "DEBUG",
867 98f9f48c malc
        .tag   = AUD_OPT_BOOL,
868 98f9f48c malc
        .valp  = &conf.debug,
869 98f9f48c malc
        .descr = "Turn on some debugging messages"
870 98f9f48c malc
    },
871 2700efa3 Juan Quintela
    { /* End of list */ }
872 1d14ffa9 bellard
};
873 1d14ffa9 bellard
874 35f4b58c blueswir1
static struct audio_pcm_ops oss_pcm_ops = {
875 1dd3e4d1 Juan Quintela
    .init_out = oss_init_out,
876 1dd3e4d1 Juan Quintela
    .fini_out = oss_fini_out,
877 1dd3e4d1 Juan Quintela
    .run_out  = oss_run_out,
878 1dd3e4d1 Juan Quintela
    .write    = oss_write,
879 1dd3e4d1 Juan Quintela
    .ctl_out  = oss_ctl_out,
880 1dd3e4d1 Juan Quintela
881 1dd3e4d1 Juan Quintela
    .init_in  = oss_init_in,
882 1dd3e4d1 Juan Quintela
    .fini_in  = oss_fini_in,
883 1dd3e4d1 Juan Quintela
    .run_in   = oss_run_in,
884 1dd3e4d1 Juan Quintela
    .read     = oss_read,
885 1dd3e4d1 Juan Quintela
    .ctl_in   = oss_ctl_in
886 85571bc7 bellard
};
887 85571bc7 bellard
888 1d14ffa9 bellard
struct audio_driver oss_audio_driver = {
889 bee37f32 Juan Quintela
    .name           = "oss",
890 bee37f32 Juan Quintela
    .descr          = "OSS http://www.opensound.com",
891 bee37f32 Juan Quintela
    .options        = oss_options,
892 bee37f32 Juan Quintela
    .init           = oss_audio_init,
893 bee37f32 Juan Quintela
    .fini           = oss_audio_fini,
894 bee37f32 Juan Quintela
    .pcm_ops        = &oss_pcm_ops,
895 bee37f32 Juan Quintela
    .can_be_default = 1,
896 bee37f32 Juan Quintela
    .max_voices_out = INT_MAX,
897 bee37f32 Juan Quintela
    .max_voices_in  = INT_MAX,
898 bee37f32 Juan Quintela
    .voice_size_out = sizeof (OSSVoiceOut),
899 bee37f32 Juan Quintela
    .voice_size_in  = sizeof (OSSVoiceIn)
900 85571bc7 bellard
};