Statistics
| Branch: | Revision:

root / audio / ossaudio.c @ 0b3652bc

History | View | Annotate | Download (23.1 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 fb065187 bellard
    int nfrags;
46 fb065187 bellard
    int fragsize;
47 fb065187 bellard
    int mmapped;
48 fb065187 bellard
    int old_optr;
49 1d14ffa9 bellard
} OSSVoiceOut;
50 85571bc7 bellard
51 1d14ffa9 bellard
typedef struct OSSVoiceIn {
52 1d14ffa9 bellard
    HWVoiceIn hw;
53 1d14ffa9 bellard
    void *pcm_buf;
54 1d14ffa9 bellard
    int fd;
55 1d14ffa9 bellard
    int nfrags;
56 1d14ffa9 bellard
    int fragsize;
57 1d14ffa9 bellard
    int old_optr;
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 1d14ffa9 bellard
    int err = close (*fdp);
120 1d14ffa9 bellard
    if (err) {
121 1d14ffa9 bellard
        oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
122 1d14ffa9 bellard
    }
123 dd8a5649 malc
    qemu_set_fd_handler (*fdp, NULL, NULL, NULL);
124 1d14ffa9 bellard
    *fdp = -1;
125 1d14ffa9 bellard
}
126 1d14ffa9 bellard
127 dd8a5649 malc
static void oss_helper_poll_out (void *opaque)
128 dd8a5649 malc
{
129 dd8a5649 malc
    (void) opaque;
130 dd8a5649 malc
    audio_run ("oss_poll_out");
131 dd8a5649 malc
}
132 dd8a5649 malc
133 dd8a5649 malc
static void oss_helper_poll_in (void *opaque)
134 dd8a5649 malc
{
135 dd8a5649 malc
    (void) opaque;
136 dd8a5649 malc
    audio_run ("oss_poll_in");
137 dd8a5649 malc
}
138 dd8a5649 malc
139 dd8a5649 malc
static int oss_poll_out (HWVoiceOut *hw)
140 dd8a5649 malc
{
141 dd8a5649 malc
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
142 dd8a5649 malc
143 dd8a5649 malc
    return qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
144 dd8a5649 malc
}
145 dd8a5649 malc
146 dd8a5649 malc
static int oss_poll_in (HWVoiceIn *hw)
147 dd8a5649 malc
{
148 dd8a5649 malc
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
149 dd8a5649 malc
150 dd8a5649 malc
    return qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
151 dd8a5649 malc
}
152 dd8a5649 malc
153 1d14ffa9 bellard
static int oss_write (SWVoiceOut *sw, void *buf, int len)
154 1d14ffa9 bellard
{
155 1d14ffa9 bellard
    return audio_pcm_sw_write (sw, buf, len);
156 1d14ffa9 bellard
}
157 1d14ffa9 bellard
158 1d14ffa9 bellard
static int aud_to_ossfmt (audfmt_e fmt)
159 85571bc7 bellard
{
160 85571bc7 bellard
    switch (fmt) {
161 1d14ffa9 bellard
    case AUD_FMT_S8:
162 1d14ffa9 bellard
        return AFMT_S8;
163 1d14ffa9 bellard
164 1d14ffa9 bellard
    case AUD_FMT_U8:
165 1d14ffa9 bellard
        return AFMT_U8;
166 1d14ffa9 bellard
167 1d14ffa9 bellard
    case AUD_FMT_S16:
168 1d14ffa9 bellard
        return AFMT_S16_LE;
169 1d14ffa9 bellard
170 1d14ffa9 bellard
    case AUD_FMT_U16:
171 1d14ffa9 bellard
        return AFMT_U16_LE;
172 1d14ffa9 bellard
173 85571bc7 bellard
    default:
174 1d14ffa9 bellard
        dolog ("Internal logic error: Bad audio format %d\n", fmt);
175 1d14ffa9 bellard
#ifdef DEBUG_AUDIO
176 1d14ffa9 bellard
        abort ();
177 1d14ffa9 bellard
#endif
178 1d14ffa9 bellard
        return AFMT_U8;
179 85571bc7 bellard
    }
180 85571bc7 bellard
}
181 85571bc7 bellard
182 1d14ffa9 bellard
static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness)
183 85571bc7 bellard
{
184 1d14ffa9 bellard
    switch (ossfmt) {
185 1d14ffa9 bellard
    case AFMT_S8:
186 ca9cc28c balrog
        *endianness = 0;
187 1d14ffa9 bellard
        *fmt = AUD_FMT_S8;
188 1d14ffa9 bellard
        break;
189 1d14ffa9 bellard
190 1d14ffa9 bellard
    case AFMT_U8:
191 1d14ffa9 bellard
        *endianness = 0;
192 1d14ffa9 bellard
        *fmt = AUD_FMT_U8;
193 1d14ffa9 bellard
        break;
194 1d14ffa9 bellard
195 1d14ffa9 bellard
    case AFMT_S16_LE:
196 1d14ffa9 bellard
        *endianness = 0;
197 1d14ffa9 bellard
        *fmt = AUD_FMT_S16;
198 1d14ffa9 bellard
        break;
199 1d14ffa9 bellard
200 1d14ffa9 bellard
    case AFMT_U16_LE:
201 1d14ffa9 bellard
        *endianness = 0;
202 1d14ffa9 bellard
        *fmt = AUD_FMT_U16;
203 1d14ffa9 bellard
        break;
204 1d14ffa9 bellard
205 1d14ffa9 bellard
    case AFMT_S16_BE:
206 1d14ffa9 bellard
        *endianness = 1;
207 1d14ffa9 bellard
        *fmt = AUD_FMT_S16;
208 1d14ffa9 bellard
        break;
209 1d14ffa9 bellard
210 1d14ffa9 bellard
    case AFMT_U16_BE:
211 1d14ffa9 bellard
        *endianness = 1;
212 1d14ffa9 bellard
        *fmt = AUD_FMT_U16;
213 1d14ffa9 bellard
        break;
214 1d14ffa9 bellard
215 85571bc7 bellard
    default:
216 1d14ffa9 bellard
        dolog ("Unrecognized audio format %d\n", ossfmt);
217 1d14ffa9 bellard
        return -1;
218 85571bc7 bellard
    }
219 1d14ffa9 bellard
220 1d14ffa9 bellard
    return 0;
221 85571bc7 bellard
}
222 85571bc7 bellard
223 c0fe3827 bellard
#if defined DEBUG_MISMATCHES || defined DEBUG
224 1d14ffa9 bellard
static void oss_dump_info (struct oss_params *req, struct oss_params *obt)
225 85571bc7 bellard
{
226 85571bc7 bellard
    dolog ("parameter | requested value | obtained value\n");
227 85571bc7 bellard
    dolog ("format    |      %10d |     %10d\n", req->fmt, obt->fmt);
228 1d14ffa9 bellard
    dolog ("channels  |      %10d |     %10d\n",
229 1d14ffa9 bellard
           req->nchannels, obt->nchannels);
230 85571bc7 bellard
    dolog ("frequency |      %10d |     %10d\n", req->freq, obt->freq);
231 85571bc7 bellard
    dolog ("nfrags    |      %10d |     %10d\n", req->nfrags, obt->nfrags);
232 1d14ffa9 bellard
    dolog ("fragsize  |      %10d |     %10d\n",
233 1d14ffa9 bellard
           req->fragsize, obt->fragsize);
234 85571bc7 bellard
}
235 85571bc7 bellard
#endif
236 85571bc7 bellard
237 1d14ffa9 bellard
static int oss_open (int in, struct oss_params *req,
238 1d14ffa9 bellard
                     struct oss_params *obt, int *pfd)
239 85571bc7 bellard
{
240 85571bc7 bellard
    int fd;
241 0b3652bc malc
    int version;
242 0b3652bc malc
    int oflags = conf.exclusive ? O_EXCL : 0;
243 85571bc7 bellard
    audio_buf_info abinfo;
244 85571bc7 bellard
    int fmt, freq, nchannels;
245 1d14ffa9 bellard
    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
246 1d14ffa9 bellard
    const char *typ = in ? "ADC" : "DAC";
247 85571bc7 bellard
248 2182349d malc
    /* Kludge needed to have working mmap on Linux */
249 0b3652bc malc
    oflags |= conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
250 0b3652bc malc
251 2182349d malc
    fd = open (dspname, oflags | O_NONBLOCK);
252 85571bc7 bellard
    if (-1 == fd) {
253 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
254 85571bc7 bellard
        return -1;
255 85571bc7 bellard
    }
256 85571bc7 bellard
257 85571bc7 bellard
    freq = req->freq;
258 85571bc7 bellard
    nchannels = req->nchannels;
259 85571bc7 bellard
    fmt = req->fmt;
260 85571bc7 bellard
261 85571bc7 bellard
    if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
262 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
263 85571bc7 bellard
        goto err;
264 85571bc7 bellard
    }
265 85571bc7 bellard
266 85571bc7 bellard
    if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
267 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",
268 1d14ffa9 bellard
                     req->nchannels);
269 85571bc7 bellard
        goto err;
270 85571bc7 bellard
    }
271 85571bc7 bellard
272 85571bc7 bellard
    if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
273 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);
274 85571bc7 bellard
        goto err;
275 85571bc7 bellard
    }
276 85571bc7 bellard
277 902e2b51 malc
    if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
278 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
279 85571bc7 bellard
        goto err;
280 85571bc7 bellard
    }
281 85571bc7 bellard
282 0b3652bc malc
    if (ioctl (fd, OSS_GETVERSION, &version)) {
283 0b3652bc malc
        oss_logerr2 (errno, typ, "Failed to get OSS version\n");
284 0b3652bc malc
        version = 0;
285 0b3652bc malc
    }
286 0b3652bc malc
287 0b3652bc malc
    if (conf.debug) {
288 0b3652bc malc
        dolog ("OSS version = %#x\n", version);
289 0b3652bc malc
    }
290 0b3652bc malc
291 0b3652bc malc
#ifdef SNDCTL_DSP_POLICY
292 0b3652bc malc
    if (conf.policy >= 0 && version >= 0x040000) {
293 0b3652bc malc
        int policy = conf.policy;
294 0b3652bc malc
        if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) {
295 0b3652bc malc
            oss_logerr2 (errno, typ, "Failed to set timing policy to %d\n",
296 0b3652bc malc
                         conf.policy);
297 0b3652bc malc
            goto err;
298 0b3652bc malc
        }
299 0b3652bc malc
    }
300 0b3652bc malc
    else
301 0b3652bc malc
#endif
302 0b3652bc malc
    {
303 0b3652bc malc
        int mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
304 0b3652bc malc
        if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
305 0b3652bc malc
            oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
306 0b3652bc malc
                         req->nfrags, req->fragsize);
307 0b3652bc malc
            goto err;
308 0b3652bc malc
        }
309 85571bc7 bellard
    }
310 85571bc7 bellard
311 1d14ffa9 bellard
    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
312 1d14ffa9 bellard
        oss_logerr2 (errno, typ, "Failed to get buffer length\n");
313 85571bc7 bellard
        goto err;
314 85571bc7 bellard
    }
315 85571bc7 bellard
316 29ddf27b malc
    if (!abinfo.fragstotal || !abinfo.fragsize) {
317 29ddf27b malc
        AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",
318 29ddf27b malc
                 abinfo.fragstotal, abinfo.fragsize, typ);
319 29ddf27b malc
        goto err;
320 29ddf27b malc
    }
321 29ddf27b malc
322 85571bc7 bellard
    obt->fmt = fmt;
323 85571bc7 bellard
    obt->nchannels = nchannels;
324 85571bc7 bellard
    obt->freq = freq;
325 85571bc7 bellard
    obt->nfrags = abinfo.fragstotal;
326 85571bc7 bellard
    obt->fragsize = abinfo.fragsize;
327 85571bc7 bellard
    *pfd = fd;
328 85571bc7 bellard
329 c0fe3827 bellard
#ifdef DEBUG_MISMATCHES
330 85571bc7 bellard
    if ((req->fmt != obt->fmt) ||
331 85571bc7 bellard
        (req->nchannels != obt->nchannels) ||
332 85571bc7 bellard
        (req->freq != obt->freq) ||
333 85571bc7 bellard
        (req->fragsize != obt->fragsize) ||
334 85571bc7 bellard
        (req->nfrags != obt->nfrags)) {
335 85571bc7 bellard
        dolog ("Audio parameters mismatch\n");
336 1d14ffa9 bellard
        oss_dump_info (req, obt);
337 85571bc7 bellard
    }
338 c0fe3827 bellard
#endif
339 85571bc7 bellard
340 1d14ffa9 bellard
#ifdef DEBUG
341 1d14ffa9 bellard
    oss_dump_info (req, obt);
342 85571bc7 bellard
#endif
343 85571bc7 bellard
    return 0;
344 85571bc7 bellard
345 1d14ffa9 bellard
 err:
346 1d14ffa9 bellard
    oss_anal_close (&fd);
347 85571bc7 bellard
    return -1;
348 85571bc7 bellard
}
349 85571bc7 bellard
350 1d14ffa9 bellard
static int oss_run_out (HWVoiceOut *hw)
351 85571bc7 bellard
{
352 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
353 85571bc7 bellard
    int err, rpos, live, decr;
354 85571bc7 bellard
    int samples;
355 85571bc7 bellard
    uint8_t *dst;
356 1ea879e5 malc
    struct st_sample *src;
357 85571bc7 bellard
    struct audio_buf_info abinfo;
358 85571bc7 bellard
    struct count_info cntinfo;
359 c0fe3827 bellard
    int bufsize;
360 85571bc7 bellard
361 1d14ffa9 bellard
    live = audio_pcm_hw_get_live_out (hw);
362 1d14ffa9 bellard
    if (!live) {
363 1d14ffa9 bellard
        return 0;
364 1d14ffa9 bellard
    }
365 85571bc7 bellard
366 c0fe3827 bellard
    bufsize = hw->samples << hw->info.shift;
367 c0fe3827 bellard
368 85571bc7 bellard
    if (oss->mmapped) {
369 85571bc7 bellard
        int bytes;
370 85571bc7 bellard
371 85571bc7 bellard
        err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);
372 85571bc7 bellard
        if (err < 0) {
373 1d14ffa9 bellard
            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");
374 1d14ffa9 bellard
            return 0;
375 85571bc7 bellard
        }
376 85571bc7 bellard
377 85571bc7 bellard
        if (cntinfo.ptr == oss->old_optr) {
378 1d14ffa9 bellard
            if (abs (hw->samples - live) < 64) {
379 c0fe3827 bellard
                dolog ("warning: Overrun\n");
380 1d14ffa9 bellard
            }
381 1d14ffa9 bellard
            return 0;
382 85571bc7 bellard
        }
383 85571bc7 bellard
384 85571bc7 bellard
        if (cntinfo.ptr > oss->old_optr) {
385 85571bc7 bellard
            bytes = cntinfo.ptr - oss->old_optr;
386 85571bc7 bellard
        }
387 85571bc7 bellard
        else {
388 c0fe3827 bellard
            bytes = bufsize + cntinfo.ptr - oss->old_optr;
389 85571bc7 bellard
        }
390 85571bc7 bellard
391 1d14ffa9 bellard
        decr = audio_MIN (bytes >> hw->info.shift, live);
392 85571bc7 bellard
    }
393 85571bc7 bellard
    else {
394 85571bc7 bellard
        err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);
395 85571bc7 bellard
        if (err < 0) {
396 1d14ffa9 bellard
            oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");
397 1d14ffa9 bellard
            return 0;
398 1d14ffa9 bellard
        }
399 1d14ffa9 bellard
400 8ead62cf bellard
        if (abinfo.bytes > bufsize) {
401 8ead62cf bellard
            if (conf.debug) {
402 8ead62cf bellard
                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
403 8ead62cf bellard
                       "please report your OS/audio hw to malc@pulsesoft.com\n",
404 8ead62cf bellard
                       abinfo.bytes, bufsize);
405 8ead62cf bellard
            }
406 8ead62cf bellard
            abinfo.bytes = bufsize;
407 8ead62cf bellard
        }
408 8ead62cf bellard
409 8ead62cf bellard
        if (abinfo.bytes < 0) {
410 8ead62cf bellard
            if (conf.debug) {
411 8ead62cf bellard
                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
412 8ead62cf bellard
                       abinfo.bytes, bufsize);
413 8ead62cf bellard
            }
414 1d14ffa9 bellard
            return 0;
415 85571bc7 bellard
        }
416 85571bc7 bellard
417 1d14ffa9 bellard
        decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);
418 1d14ffa9 bellard
        if (!decr) {
419 1d14ffa9 bellard
            return 0;
420 1d14ffa9 bellard
        }
421 85571bc7 bellard
    }
422 85571bc7 bellard
423 85571bc7 bellard
    samples = decr;
424 85571bc7 bellard
    rpos = hw->rpos;
425 85571bc7 bellard
    while (samples) {
426 85571bc7 bellard
        int left_till_end_samples = hw->samples - rpos;
427 85571bc7 bellard
        int convert_samples = audio_MIN (samples, left_till_end_samples);
428 85571bc7 bellard
429 1d14ffa9 bellard
        src = hw->mix_buf + rpos;
430 1d14ffa9 bellard
        dst = advance (oss->pcm_buf, rpos << hw->info.shift);
431 85571bc7 bellard
432 85571bc7 bellard
        hw->clip (dst, src, convert_samples);
433 85571bc7 bellard
        if (!oss->mmapped) {
434 85571bc7 bellard
            int written;
435 85571bc7 bellard
436 1d14ffa9 bellard
            written = write (oss->fd, dst, convert_samples << hw->info.shift);
437 85571bc7 bellard
            /* XXX: follow errno recommendations ? */
438 85571bc7 bellard
            if (written == -1) {
439 1d14ffa9 bellard
                oss_logerr (
440 1d14ffa9 bellard
                    errno,
441 1d14ffa9 bellard
                    "Failed to write %d bytes of audio data from %p\n",
442 1d14ffa9 bellard
                    convert_samples << hw->info.shift,
443 1d14ffa9 bellard
                    dst
444 1d14ffa9 bellard
                    );
445 85571bc7 bellard
                continue;
446 85571bc7 bellard
            }
447 85571bc7 bellard
448 1d14ffa9 bellard
            if (written != convert_samples << hw->info.shift) {
449 1d14ffa9 bellard
                int wsamples = written >> hw->info.shift;
450 1d14ffa9 bellard
                int wbytes = wsamples << hw->info.shift;
451 85571bc7 bellard
                if (wbytes != written) {
452 c0fe3827 bellard
                    dolog ("warning: Misaligned write %d (requested %d), "
453 1d14ffa9 bellard
                           "alignment %d\n",
454 1d14ffa9 bellard
                           wbytes, written, hw->info.align + 1);
455 85571bc7 bellard
                }
456 1d14ffa9 bellard
                decr -= wsamples;
457 85571bc7 bellard
                rpos = (rpos + wsamples) % hw->samples;
458 85571bc7 bellard
                break;
459 85571bc7 bellard
            }
460 85571bc7 bellard
        }
461 1d14ffa9 bellard
462 85571bc7 bellard
        rpos = (rpos + convert_samples) % hw->samples;
463 85571bc7 bellard
        samples -= convert_samples;
464 85571bc7 bellard
    }
465 85571bc7 bellard
    if (oss->mmapped) {
466 85571bc7 bellard
        oss->old_optr = cntinfo.ptr;
467 85571bc7 bellard
    }
468 85571bc7 bellard
469 85571bc7 bellard
    hw->rpos = rpos;
470 1d14ffa9 bellard
    return decr;
471 85571bc7 bellard
}
472 85571bc7 bellard
473 1d14ffa9 bellard
static void oss_fini_out (HWVoiceOut *hw)
474 85571bc7 bellard
{
475 85571bc7 bellard
    int err;
476 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
477 85571bc7 bellard
478 1d14ffa9 bellard
    ldebug ("oss_fini\n");
479 1d14ffa9 bellard
    oss_anal_close (&oss->fd);
480 85571bc7 bellard
481 85571bc7 bellard
    if (oss->pcm_buf) {
482 85571bc7 bellard
        if (oss->mmapped) {
483 c0fe3827 bellard
            err = munmap (oss->pcm_buf, hw->samples << hw->info.shift);
484 85571bc7 bellard
            if (err) {
485 1d14ffa9 bellard
                oss_logerr (errno, "Failed to unmap buffer %p, size %d\n",
486 c0fe3827 bellard
                            oss->pcm_buf, hw->samples << hw->info.shift);
487 85571bc7 bellard
            }
488 85571bc7 bellard
        }
489 85571bc7 bellard
        else {
490 85571bc7 bellard
            qemu_free (oss->pcm_buf);
491 85571bc7 bellard
        }
492 85571bc7 bellard
        oss->pcm_buf = NULL;
493 85571bc7 bellard
    }
494 85571bc7 bellard
}
495 85571bc7 bellard
496 1ea879e5 malc
static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
497 85571bc7 bellard
{
498 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
499 85571bc7 bellard
    struct oss_params req, obt;
500 1d14ffa9 bellard
    int endianness;
501 1d14ffa9 bellard
    int err;
502 1d14ffa9 bellard
    int fd;
503 1d14ffa9 bellard
    audfmt_e effective_fmt;
504 1ea879e5 malc
    struct audsettings obt_as;
505 85571bc7 bellard
506 571ec3d6 bellard
    oss->fd = -1;
507 571ec3d6 bellard
508 c0fe3827 bellard
    req.fmt = aud_to_ossfmt (as->fmt);
509 c0fe3827 bellard
    req.freq = as->freq;
510 c0fe3827 bellard
    req.nchannels = as->nchannels;
511 85571bc7 bellard
    req.fragsize = conf.fragsize;
512 85571bc7 bellard
    req.nfrags = conf.nfrags;
513 85571bc7 bellard
514 1d14ffa9 bellard
    if (oss_open (0, &req, &obt, &fd)) {
515 85571bc7 bellard
        return -1;
516 1d14ffa9 bellard
    }
517 85571bc7 bellard
518 1d14ffa9 bellard
    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
519 1d14ffa9 bellard
    if (err) {
520 1d14ffa9 bellard
        oss_anal_close (&fd);
521 1d14ffa9 bellard
        return -1;
522 1d14ffa9 bellard
    }
523 85571bc7 bellard
524 c0fe3827 bellard
    obt_as.freq = obt.freq;
525 c0fe3827 bellard
    obt_as.nchannels = obt.nchannels;
526 c0fe3827 bellard
    obt_as.fmt = effective_fmt;
527 d929eba5 bellard
    obt_as.endianness = endianness;
528 c0fe3827 bellard
529 d929eba5 bellard
    audio_pcm_init_info (&hw->info, &obt_as);
530 85571bc7 bellard
    oss->nfrags = obt.nfrags;
531 85571bc7 bellard
    oss->fragsize = obt.fragsize;
532 c0fe3827 bellard
533 c0fe3827 bellard
    if (obt.nfrags * obt.fragsize & hw->info.align) {
534 c0fe3827 bellard
        dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n",
535 c0fe3827 bellard
               obt.nfrags * obt.fragsize, hw->info.align + 1);
536 c0fe3827 bellard
    }
537 c0fe3827 bellard
538 c0fe3827 bellard
    hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
539 85571bc7 bellard
540 85571bc7 bellard
    oss->mmapped = 0;
541 85571bc7 bellard
    if (conf.try_mmap) {
542 c0fe3827 bellard
        oss->pcm_buf = mmap (
543 660f11be Blue Swirl
            NULL,
544 c0fe3827 bellard
            hw->samples << hw->info.shift,
545 c0fe3827 bellard
            PROT_READ | PROT_WRITE,
546 c0fe3827 bellard
            MAP_SHARED,
547 c0fe3827 bellard
            fd,
548 c0fe3827 bellard
            0
549 c0fe3827 bellard
            );
550 85571bc7 bellard
        if (oss->pcm_buf == MAP_FAILED) {
551 1d14ffa9 bellard
            oss_logerr (errno, "Failed to map %d bytes of DAC\n",
552 c0fe3827 bellard
                        hw->samples << hw->info.shift);
553 44a095a7 bellard
        } else {
554 85571bc7 bellard
            int err;
555 85571bc7 bellard
            int trig = 0;
556 1d14ffa9 bellard
            if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
557 1d14ffa9 bellard
                oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
558 85571bc7 bellard
            }
559 44a095a7 bellard
            else {
560 44a095a7 bellard
                trig = PCM_ENABLE_OUTPUT;
561 1d14ffa9 bellard
                if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
562 1d14ffa9 bellard
                    oss_logerr (
563 1d14ffa9 bellard
                        errno,
564 1d14ffa9 bellard
                        "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
565 1d14ffa9 bellard
                        );
566 44a095a7 bellard
                }
567 44a095a7 bellard
                else {
568 44a095a7 bellard
                    oss->mmapped = 1;
569 44a095a7 bellard
                }
570 85571bc7 bellard
            }
571 85571bc7 bellard
572 44a095a7 bellard
            if (!oss->mmapped) {
573 c0fe3827 bellard
                err = munmap (oss->pcm_buf, hw->samples << hw->info.shift);
574 44a095a7 bellard
                if (err) {
575 1d14ffa9 bellard
                    oss_logerr (errno, "Failed to unmap buffer %p size %d\n",
576 c0fe3827 bellard
                                oss->pcm_buf, hw->samples << hw->info.shift);
577 44a095a7 bellard
                }
578 85571bc7 bellard
            }
579 85571bc7 bellard
        }
580 85571bc7 bellard
    }
581 85571bc7 bellard
582 85571bc7 bellard
    if (!oss->mmapped) {
583 c0fe3827 bellard
        oss->pcm_buf = audio_calloc (
584 c0fe3827 bellard
            AUDIO_FUNC,
585 c0fe3827 bellard
            hw->samples,
586 c0fe3827 bellard
            1 << hw->info.shift
587 c0fe3827 bellard
            );
588 85571bc7 bellard
        if (!oss->pcm_buf) {
589 b41cffbe bellard
            dolog (
590 b41cffbe bellard
                "Could not allocate DAC buffer (%d samples, each %d bytes)\n",
591 b41cffbe bellard
                hw->samples,
592 b41cffbe bellard
                1 << hw->info.shift
593 b41cffbe bellard
                );
594 1d14ffa9 bellard
            oss_anal_close (&fd);
595 85571bc7 bellard
            return -1;
596 85571bc7 bellard
        }
597 85571bc7 bellard
    }
598 85571bc7 bellard
599 1d14ffa9 bellard
    oss->fd = fd;
600 85571bc7 bellard
    return 0;
601 85571bc7 bellard
}
602 85571bc7 bellard
603 1d14ffa9 bellard
static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
604 85571bc7 bellard
{
605 85571bc7 bellard
    int trig;
606 dd8a5649 malc
    va_list ap;
607 dd8a5649 malc
    int poll_mode;
608 1d14ffa9 bellard
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
609 85571bc7 bellard
610 dd8a5649 malc
    va_start (ap, cmd);
611 dd8a5649 malc
    poll_mode = va_arg (ap, int);
612 dd8a5649 malc
    va_end (ap);
613 85571bc7 bellard
614 85571bc7 bellard
    switch (cmd) {
615 85571bc7 bellard
    case VOICE_ENABLE:
616 85571bc7 bellard
        ldebug ("enabling voice\n");
617 dd8a5649 malc
        if (poll_mode && oss_poll_out (hw)) {
618 dd8a5649 malc
            poll_mode = 0;
619 dd8a5649 malc
        }
620 dd8a5649 malc
        hw->poll_mode = poll_mode;
621 dd8a5649 malc
622 dd8a5649 malc
        if (!oss->mmapped) {
623 dd8a5649 malc
            return 0;
624 dd8a5649 malc
        }
625 dd8a5649 malc
626 1d14ffa9 bellard
        audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples);
627 85571bc7 bellard
        trig = PCM_ENABLE_OUTPUT;
628 85571bc7 bellard
        if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
629 1d14ffa9 bellard
            oss_logerr (
630 1d14ffa9 bellard
                errno,
631 1d14ffa9 bellard
                "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
632 1d14ffa9 bellard
                );
633 85571bc7 bellard
            return -1;
634 85571bc7 bellard
        }
635 85571bc7 bellard
        break;
636 85571bc7 bellard
637 85571bc7 bellard
    case VOICE_DISABLE:
638 dd8a5649 malc
        if (hw->poll_mode) {
639 dd8a5649 malc
            qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
640 dd8a5649 malc
            hw->poll_mode = 0;
641 dd8a5649 malc
        }
642 dd8a5649 malc
643 dd8a5649 malc
        if (!oss->mmapped) {
644 dd8a5649 malc
            return 0;
645 dd8a5649 malc
        }
646 dd8a5649 malc
647 85571bc7 bellard
        ldebug ("disabling voice\n");
648 85571bc7 bellard
        trig = 0;
649 85571bc7 bellard
        if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
650 1d14ffa9 bellard
            oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
651 85571bc7 bellard
            return -1;
652 85571bc7 bellard
        }
653 85571bc7 bellard
        break;
654 85571bc7 bellard
    }
655 85571bc7 bellard
    return 0;
656 85571bc7 bellard
}
657 85571bc7 bellard
658 1ea879e5 malc
static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
659 1d14ffa9 bellard
{
660 1d14ffa9 bellard
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
661 1d14ffa9 bellard
    struct oss_params req, obt;
662 1d14ffa9 bellard
    int endianness;
663 1d14ffa9 bellard
    int err;
664 1d14ffa9 bellard
    int fd;
665 1d14ffa9 bellard
    audfmt_e effective_fmt;
666 1ea879e5 malc
    struct audsettings obt_as;
667 1d14ffa9 bellard
668 571ec3d6 bellard
    oss->fd = -1;
669 571ec3d6 bellard
670 c0fe3827 bellard
    req.fmt = aud_to_ossfmt (as->fmt);
671 c0fe3827 bellard
    req.freq = as->freq;
672 c0fe3827 bellard
    req.nchannels = as->nchannels;
673 1d14ffa9 bellard
    req.fragsize = conf.fragsize;
674 1d14ffa9 bellard
    req.nfrags = conf.nfrags;
675 1d14ffa9 bellard
    if (oss_open (1, &req, &obt, &fd)) {
676 1d14ffa9 bellard
        return -1;
677 1d14ffa9 bellard
    }
678 1d14ffa9 bellard
679 1d14ffa9 bellard
    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
680 1d14ffa9 bellard
    if (err) {
681 1d14ffa9 bellard
        oss_anal_close (&fd);
682 1d14ffa9 bellard
        return -1;
683 1d14ffa9 bellard
    }
684 1d14ffa9 bellard
685 c0fe3827 bellard
    obt_as.freq = obt.freq;
686 c0fe3827 bellard
    obt_as.nchannels = obt.nchannels;
687 c0fe3827 bellard
    obt_as.fmt = effective_fmt;
688 d929eba5 bellard
    obt_as.endianness = endianness;
689 c0fe3827 bellard
690 d929eba5 bellard
    audio_pcm_init_info (&hw->info, &obt_as);
691 1d14ffa9 bellard
    oss->nfrags = obt.nfrags;
692 1d14ffa9 bellard
    oss->fragsize = obt.fragsize;
693 c0fe3827 bellard
694 c0fe3827 bellard
    if (obt.nfrags * obt.fragsize & hw->info.align) {
695 c0fe3827 bellard
        dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n",
696 c0fe3827 bellard
               obt.nfrags * obt.fragsize, hw->info.align + 1);
697 c0fe3827 bellard
    }
698 c0fe3827 bellard
699 c0fe3827 bellard
    hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
700 c0fe3827 bellard
    oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
701 1d14ffa9 bellard
    if (!oss->pcm_buf) {
702 b41cffbe bellard
        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
703 b41cffbe bellard
               hw->samples, 1 << hw->info.shift);
704 1d14ffa9 bellard
        oss_anal_close (&fd);
705 1d14ffa9 bellard
        return -1;
706 1d14ffa9 bellard
    }
707 1d14ffa9 bellard
708 1d14ffa9 bellard
    oss->fd = fd;
709 1d14ffa9 bellard
    return 0;
710 1d14ffa9 bellard
}
711 1d14ffa9 bellard
712 1d14ffa9 bellard
static void oss_fini_in (HWVoiceIn *hw)
713 1d14ffa9 bellard
{
714 1d14ffa9 bellard
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
715 1d14ffa9 bellard
716 1d14ffa9 bellard
    oss_anal_close (&oss->fd);
717 1d14ffa9 bellard
718 1d14ffa9 bellard
    if (oss->pcm_buf) {
719 1d14ffa9 bellard
        qemu_free (oss->pcm_buf);
720 1d14ffa9 bellard
        oss->pcm_buf = NULL;
721 1d14ffa9 bellard
    }
722 1d14ffa9 bellard
}
723 1d14ffa9 bellard
724 1d14ffa9 bellard
static int oss_run_in (HWVoiceIn *hw)
725 1d14ffa9 bellard
{
726 1d14ffa9 bellard
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
727 1d14ffa9 bellard
    int hwshift = hw->info.shift;
728 1d14ffa9 bellard
    int i;
729 1d14ffa9 bellard
    int live = audio_pcm_hw_get_live_in (hw);
730 1d14ffa9 bellard
    int dead = hw->samples - live;
731 1d14ffa9 bellard
    size_t read_samples = 0;
732 1d14ffa9 bellard
    struct {
733 1d14ffa9 bellard
        int add;
734 1d14ffa9 bellard
        int len;
735 1d14ffa9 bellard
    } bufs[2] = {
736 98f9f48c malc
        { .add = hw->wpos, .len = 0 },
737 98f9f48c malc
        { .add = 0,        .len = 0 }
738 1d14ffa9 bellard
    };
739 1d14ffa9 bellard
740 1d14ffa9 bellard
    if (!dead) {
741 1d14ffa9 bellard
        return 0;
742 1d14ffa9 bellard
    }
743 1d14ffa9 bellard
744 1d14ffa9 bellard
    if (hw->wpos + dead > hw->samples) {
745 1d14ffa9 bellard
        bufs[0].len = (hw->samples - hw->wpos) << hwshift;
746 1d14ffa9 bellard
        bufs[1].len = (dead - (hw->samples - hw->wpos)) << hwshift;
747 1d14ffa9 bellard
    }
748 1d14ffa9 bellard
    else {
749 1d14ffa9 bellard
        bufs[0].len = dead << hwshift;
750 1d14ffa9 bellard
    }
751 1d14ffa9 bellard
752 1d14ffa9 bellard
753 1d14ffa9 bellard
    for (i = 0; i < 2; ++i) {
754 1d14ffa9 bellard
        ssize_t nread;
755 1d14ffa9 bellard
756 1d14ffa9 bellard
        if (bufs[i].len) {
757 1d14ffa9 bellard
            void *p = advance (oss->pcm_buf, bufs[i].add << hwshift);
758 1d14ffa9 bellard
            nread = read (oss->fd, p, bufs[i].len);
759 1d14ffa9 bellard
760 1d14ffa9 bellard
            if (nread > 0) {
761 1d14ffa9 bellard
                if (nread & hw->info.align) {
762 b41cffbe bellard
                    dolog ("warning: Misaligned read %zd (requested %d), "
763 1d14ffa9 bellard
                           "alignment %d\n", nread, bufs[i].add << hwshift,
764 1d14ffa9 bellard
                           hw->info.align + 1);
765 1d14ffa9 bellard
                }
766 1d14ffa9 bellard
                read_samples += nread >> hwshift;
767 1d14ffa9 bellard
                hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift,
768 1d14ffa9 bellard
                          &nominal_volume);
769 1d14ffa9 bellard
            }
770 1d14ffa9 bellard
771 1d14ffa9 bellard
            if (bufs[i].len - nread) {
772 1d14ffa9 bellard
                if (nread == -1) {
773 1d14ffa9 bellard
                    switch (errno) {
774 1d14ffa9 bellard
                    case EINTR:
775 1d14ffa9 bellard
                    case EAGAIN:
776 1d14ffa9 bellard
                        break;
777 1d14ffa9 bellard
                    default:
778 1d14ffa9 bellard
                        oss_logerr (
779 1d14ffa9 bellard
                            errno,
780 1d14ffa9 bellard
                            "Failed to read %d bytes of audio (to %p)\n",
781 1d14ffa9 bellard
                            bufs[i].len, p
782 1d14ffa9 bellard
                            );
783 1d14ffa9 bellard
                        break;
784 1d14ffa9 bellard
                    }
785 1d14ffa9 bellard
                }
786 1d14ffa9 bellard
                break;
787 1d14ffa9 bellard
            }
788 1d14ffa9 bellard
        }
789 1d14ffa9 bellard
    }
790 1d14ffa9 bellard
791 1d14ffa9 bellard
    hw->wpos = (hw->wpos + read_samples) % hw->samples;
792 1d14ffa9 bellard
    return read_samples;
793 1d14ffa9 bellard
}
794 1d14ffa9 bellard
795 1d14ffa9 bellard
static int oss_read (SWVoiceIn *sw, void *buf, int size)
796 1d14ffa9 bellard
{
797 1d14ffa9 bellard
    return audio_pcm_sw_read (sw, buf, size);
798 1d14ffa9 bellard
}
799 1d14ffa9 bellard
800 1d14ffa9 bellard
static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
801 1d14ffa9 bellard
{
802 dd8a5649 malc
    va_list ap;
803 dd8a5649 malc
    int poll_mode;
804 dd8a5649 malc
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
805 dd8a5649 malc
806 dd8a5649 malc
    va_start (ap, cmd);
807 dd8a5649 malc
    poll_mode = va_arg (ap, int);
808 dd8a5649 malc
    va_end (ap);
809 dd8a5649 malc
810 dd8a5649 malc
    switch (cmd) {
811 dd8a5649 malc
    case VOICE_ENABLE:
812 dd8a5649 malc
        if (poll_mode && oss_poll_in (hw)) {
813 dd8a5649 malc
            poll_mode = 0;
814 dd8a5649 malc
        }
815 dd8a5649 malc
        hw->poll_mode = poll_mode;
816 dd8a5649 malc
        break;
817 dd8a5649 malc
818 dd8a5649 malc
    case VOICE_DISABLE:
819 dd8a5649 malc
        if (hw->poll_mode) {
820 dd8a5649 malc
            hw->poll_mode = 0;
821 dd8a5649 malc
            qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
822 dd8a5649 malc
        }
823 dd8a5649 malc
        break;
824 dd8a5649 malc
    }
825 1d14ffa9 bellard
    return 0;
826 1d14ffa9 bellard
}
827 1d14ffa9 bellard
828 85571bc7 bellard
static void *oss_audio_init (void)
829 85571bc7 bellard
{
830 85571bc7 bellard
    return &conf;
831 85571bc7 bellard
}
832 85571bc7 bellard
833 85571bc7 bellard
static void oss_audio_fini (void *opaque)
834 85571bc7 bellard
{
835 1d14ffa9 bellard
    (void) opaque;
836 85571bc7 bellard
}
837 85571bc7 bellard
838 1d14ffa9 bellard
static struct audio_option oss_options[] = {
839 98f9f48c malc
    {
840 98f9f48c malc
        .name  = "FRAGSIZE",
841 98f9f48c malc
        .tag   = AUD_OPT_INT,
842 98f9f48c malc
        .valp  = &conf.fragsize,
843 98f9f48c malc
        .descr = "Fragment size in bytes"
844 98f9f48c malc
    },
845 98f9f48c malc
    {
846 98f9f48c malc
        .name  = "NFRAGS",
847 98f9f48c malc
        .tag   = AUD_OPT_INT,
848 98f9f48c malc
        .valp  = &conf.nfrags,
849 98f9f48c malc
        .descr = "Number of fragments"
850 98f9f48c malc
    },
851 98f9f48c malc
    {
852 98f9f48c malc
        .name  = "MMAP",
853 98f9f48c malc
        .tag   = AUD_OPT_BOOL,
854 98f9f48c malc
        .valp  = &conf.try_mmap,
855 98f9f48c malc
        .descr = "Try using memory mapped access"
856 98f9f48c malc
    },
857 98f9f48c malc
    {
858 98f9f48c malc
        .name  = "DAC_DEV",
859 98f9f48c malc
        .tag   = AUD_OPT_STR,
860 98f9f48c malc
        .valp  = &conf.devpath_out,
861 98f9f48c malc
        .descr = "Path to DAC device"
862 98f9f48c malc
    },
863 98f9f48c malc
    {
864 98f9f48c malc
        .name  = "ADC_DEV",
865 98f9f48c malc
        .tag   = AUD_OPT_STR,
866 98f9f48c malc
        .valp  = &conf.devpath_in,
867 98f9f48c malc
        .descr = "Path to ADC device"
868 98f9f48c malc
    },
869 98f9f48c malc
    {
870 0b3652bc malc
        .name  = "EXCLUSIVE",
871 0b3652bc malc
        .tag   = AUD_OPT_BOOL,
872 0b3652bc malc
        .valp  = &conf.exclusive,
873 0b3652bc malc
        .descr = "Open device in exclusive mode (vmix wont work)"
874 0b3652bc malc
    },
875 0b3652bc malc
#ifdef SNDCTL_DSP_POLICY
876 0b3652bc malc
    {
877 0b3652bc malc
        .name  = "POLICY",
878 0b3652bc malc
        .tag   = AUD_OPT_INT,
879 0b3652bc malc
        .valp  = &conf.policy,
880 0b3652bc malc
        .descr = "Set the timing policy of the device, -1 to use fragment mode",
881 0b3652bc malc
    },
882 0b3652bc malc
#endif
883 0b3652bc malc
    {
884 98f9f48c malc
        .name  = "DEBUG",
885 98f9f48c malc
        .tag   = AUD_OPT_BOOL,
886 98f9f48c malc
        .valp  = &conf.debug,
887 98f9f48c malc
        .descr = "Turn on some debugging messages"
888 98f9f48c malc
    },
889 2700efa3 Juan Quintela
    { /* End of list */ }
890 1d14ffa9 bellard
};
891 1d14ffa9 bellard
892 35f4b58c blueswir1
static struct audio_pcm_ops oss_pcm_ops = {
893 1dd3e4d1 Juan Quintela
    .init_out = oss_init_out,
894 1dd3e4d1 Juan Quintela
    .fini_out = oss_fini_out,
895 1dd3e4d1 Juan Quintela
    .run_out  = oss_run_out,
896 1dd3e4d1 Juan Quintela
    .write    = oss_write,
897 1dd3e4d1 Juan Quintela
    .ctl_out  = oss_ctl_out,
898 1dd3e4d1 Juan Quintela
899 1dd3e4d1 Juan Quintela
    .init_in  = oss_init_in,
900 1dd3e4d1 Juan Quintela
    .fini_in  = oss_fini_in,
901 1dd3e4d1 Juan Quintela
    .run_in   = oss_run_in,
902 1dd3e4d1 Juan Quintela
    .read     = oss_read,
903 1dd3e4d1 Juan Quintela
    .ctl_in   = oss_ctl_in
904 85571bc7 bellard
};
905 85571bc7 bellard
906 1d14ffa9 bellard
struct audio_driver oss_audio_driver = {
907 bee37f32 Juan Quintela
    .name           = "oss",
908 bee37f32 Juan Quintela
    .descr          = "OSS http://www.opensound.com",
909 bee37f32 Juan Quintela
    .options        = oss_options,
910 bee37f32 Juan Quintela
    .init           = oss_audio_init,
911 bee37f32 Juan Quintela
    .fini           = oss_audio_fini,
912 bee37f32 Juan Quintela
    .pcm_ops        = &oss_pcm_ops,
913 bee37f32 Juan Quintela
    .can_be_default = 1,
914 bee37f32 Juan Quintela
    .max_voices_out = INT_MAX,
915 bee37f32 Juan Quintela
    .max_voices_in  = INT_MAX,
916 bee37f32 Juan Quintela
    .voice_size_out = sizeof (OSSVoiceOut),
917 bee37f32 Juan Quintela
    .voice_size_in  = sizeof (OSSVoiceIn)
918 85571bc7 bellard
};