Statistics
| Branch: | Revision:

root / audio / ossaudio.c @ e726fe7d

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