Revision 0b3652bc audio/ossaudio.c

b/audio/ossaudio.c
64 64
    const char *devpath_out;
65 65
    const char *devpath_in;
66 66
    int debug;
67
    int exclusive;
68
    int policy;
67 69
} conf = {
68 70
    .try_mmap = 0,
69 71
    .nfrags = 4,
70 72
    .fragsize = 4096,
71 73
    .devpath_out = "/dev/dsp",
72 74
    .devpath_in = "/dev/dsp",
73
    .debug = 0
75
    .debug = 0,
76
    .exclusive = 0,
77
    .policy = 5
74 78
};
75 79

  
76 80
struct oss_params {
......
234 238
                     struct oss_params *obt, int *pfd)
235 239
{
236 240
    int fd;
237
    int oflags;
238
    int mmmmssss;
241
    int version;
242
    int oflags = conf.exclusive ? O_EXCL : 0;
239 243
    audio_buf_info abinfo;
240 244
    int fmt, freq, nchannels;
241 245
    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
242 246
    const char *typ = in ? "ADC" : "DAC";
243 247

  
244 248
    /* Kludge needed to have working mmap on Linux */
245
    oflags = conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
249
    oflags |= conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
250

  
246 251
    fd = open (dspname, oflags | O_NONBLOCK);
247 252
    if (-1 == fd) {
248 253
        oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
......
274 279
        goto err;
275 280
    }
276 281

  
277
    mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
278
    if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
279
        oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
280
                     req->nfrags, req->fragsize);
281
        goto err;
282
    if (ioctl (fd, OSS_GETVERSION, &version)) {
283
        oss_logerr2 (errno, typ, "Failed to get OSS version\n");
284
        version = 0;
285
    }
286

  
287
    if (conf.debug) {
288
        dolog ("OSS version = %#x\n", version);
289
    }
290

  
291
#ifdef SNDCTL_DSP_POLICY
292
    if (conf.policy >= 0 && version >= 0x040000) {
293
        int policy = conf.policy;
294
        if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) {
295
            oss_logerr2 (errno, typ, "Failed to set timing policy to %d\n",
296
                         conf.policy);
297
            goto err;
298
        }
299
    }
300
    else
301
#endif
302
    {
303
        int mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
304
        if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
305
            oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
306
                         req->nfrags, req->fragsize);
307
            goto err;
308
        }
282 309
    }
283 310

  
284 311
    if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
......
840 867
        .descr = "Path to ADC device"
841 868
    },
842 869
    {
870
        .name  = "EXCLUSIVE",
871
        .tag   = AUD_OPT_BOOL,
872
        .valp  = &conf.exclusive,
873
        .descr = "Open device in exclusive mode (vmix wont work)"
874
    },
875
#ifdef SNDCTL_DSP_POLICY
876
    {
877
        .name  = "POLICY",
878
        .tag   = AUD_OPT_INT,
879
        .valp  = &conf.policy,
880
        .descr = "Set the timing policy of the device, -1 to use fragment mode",
881
    },
882
#endif
883
    {
843 884
        .name  = "DEBUG",
844 885
        .tag   = AUD_OPT_BOOL,
845 886
        .valp  = &conf.debug,

Also available in: Unified diff