Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/audio/alsa-plugins/files/alsa-plugins.patch
16166 views
1
--- oss/ctl_oss.c.orig 2016-03-31 13:11:29 UTC
2
+++ oss/ctl_oss.c
3
@@ -362,7 +362,9 @@ SND_CTL_PLUGIN_DEFINE_FUNC(oss)
4
{
5
snd_config_iterator_t it, next;
6
const char *device = "/dev/mixer";
7
+#ifndef __FreeBSD__
8
struct mixer_info mixinfo;
9
+#endif
10
int i, err, val;
11
snd_ctl_oss_t *oss;
12
13
@@ -399,19 +401,29 @@ SND_CTL_PLUGIN_DEFINE_FUNC(oss)
14
goto error;
15
}
16
17
+#ifndef __FreeBSD__
18
if (ioctl(oss->fd, SOUND_MIXER_INFO, &mixinfo) < 0) {
19
err = -errno;
20
SNDERR("Cannot get mixer info for device %s", device);
21
goto error;
22
}
23
+#endif
24
25
oss->ext.version = SND_CTL_EXT_VERSION;
26
oss->ext.card_idx = 0; /* FIXME */
27
+#ifdef __FreeBSD__
28
+ strncpy(oss->ext.id, "fbsd", sizeof(oss->ext.id) - 1);
29
+ strcpy(oss->ext.driver, "FreeBSD/OSS plugin");
30
+ strncpy(oss->ext.name, "FreeBSD/OSS", sizeof(oss->ext.name) - 1);
31
+ strncpy(oss->ext.longname, "FreeBSD/OSS", sizeof(oss->ext.longname) - 1);
32
+ strncpy(oss->ext.mixername, "FreeBSD/OSS", sizeof(oss->ext.mixername) - 1);
33
+#else
34
strncpy(oss->ext.id, mixinfo.id, sizeof(oss->ext.id) - 1);
35
strcpy(oss->ext.driver, "OSS-Emulation");
36
strncpy(oss->ext.name, mixinfo.name, sizeof(oss->ext.name) - 1);
37
strncpy(oss->ext.longname, mixinfo.name, sizeof(oss->ext.longname) - 1);
38
strncpy(oss->ext.mixername, mixinfo.name, sizeof(oss->ext.mixername) - 1);
39
+#endif
40
oss->ext.poll_fd = -1;
41
oss->ext.callback = &oss_ext_callback;
42
oss->ext.private_data = oss;
43
--- oss/pcm_oss.c.orig 2016-03-31 13:11:29 UTC
44
+++ oss/pcm_oss.c
45
@@ -24,15 +24,39 @@
46
#include <alsa/pcm_external.h>
47
#include <linux/soundcard.h>
48
49
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
50
+
51
+#ifdef __FreeBSD__
52
+#define FREEBSD_OSS_RATE_MIN 1
53
+#define FREEBSD_OSS_RATE_MAX 384000
54
+
55
+#define FREEBSD_OSS_CHANNELS_MIN 1
56
+#define FREEBSD_OSS_CHANNELS_MAX 8
57
+
58
+#define FREEBSD_OSS_BUFSZ_MAX 131072
59
+#define FREEBSD_OSS_BLKCNT_MIN 2
60
+#define FREEBSD_OSS_BLKSZ_MIN 16 /* (FREEBSD_OSS_CHANNELS_MAX * 4) */
61
+
62
+#define FREEBSD_OSS_BUFSZ_MIN (FREEBSD_OSS_BLKCNT_MIN * FREEBSD_OSS_BLKSZ_MIN)
63
+#define FREEBSD_OSS_BLKCNT_MAX (FREEBSD_OSS_BUFSZ_MAX / FREEBSD_OSS_BUFSZ_MIN)
64
+#define FREEBSD_OSS_BLKSZ_MAX (FREEBSD_OSS_BUFSZ_MAX / FREEBSD_OSS_BLKCNT_MIN)
65
+#endif
66
+
67
typedef struct snd_pcm_oss {
68
snd_pcm_ioplug_t io;
69
char *device;
70
int fd;
71
+#ifdef __FreeBSD__
72
+ int bufsz, ptr, ptr_align, last_bytes;
73
+#else
74
int fragment_set;
75
int caps;
76
+#endif
77
int format;
78
+#ifndef __FreeBSD__
79
unsigned int period_shift;
80
unsigned int periods;
81
+#endif
82
unsigned int frame_bytes;
83
} snd_pcm_oss_t;
84
85
@@ -49,8 +73,21 @@ static snd_pcm_sframes_t oss_write(snd_pcm_ioplug_t *i
86
buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8;
87
size *= oss->frame_bytes;
88
result = write(oss->fd, buf, size);
89
- if (result <= 0)
90
- return result;
91
+#ifdef __FreeBSD__
92
+ if (result == -1) {
93
+ if (errno == EAGAIN)
94
+ return 0;
95
+ else
96
+ return -errno;
97
+ }
98
+#else
99
+ if (result <= 0) {
100
+ if (result == -EAGAIN)
101
+ return 0;
102
+ else
103
+ return result;
104
+ }
105
+#endif
106
return result / oss->frame_bytes;
107
}
108
109
@@ -67,14 +104,88 @@ static snd_pcm_sframes_t oss_read(snd_pcm_ioplug_t *io
110
buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8;
111
size *= oss->frame_bytes;
112
result = read(oss->fd, buf, size);
113
- if (result <= 0)
114
- return result;
115
+#ifdef __FreeBSD__
116
+ if (result == -1) {
117
+ if (errno == EAGAIN)
118
+ return 0;
119
+ else
120
+ return -errno;
121
+ }
122
+#else
123
+ if (result <= 0) {
124
+ if (result == -EAGAIN)
125
+ return 0;
126
+ else
127
+ return result;
128
+ }
129
+#endif
130
return result / oss->frame_bytes;
131
}
132
133
static snd_pcm_sframes_t oss_pointer(snd_pcm_ioplug_t *io)
134
{
135
+#ifdef __FreeBSD__
136
snd_pcm_oss_t *oss = io->private_data;
137
+#ifdef FREEBSD_OSS_USE_IO_PTR
138
+ struct count_info ci;
139
+#endif
140
+ audio_buf_info bi;
141
+
142
+ if (io->state != SND_PCM_STATE_RUNNING)
143
+ return 0;
144
+
145
+ if (io->state == SND_PCM_STATE_XRUN)
146
+ return -EPIPE;
147
+
148
+#ifdef FREEBSD_OSS_USE_IO_PTR
149
+ if (ioctl(oss->fd, (io->stream == SND_PCM_STREAM_PLAYBACK) ?
150
+ SNDCTL_DSP_GETOPTR : SNDCTL_DSP_GETIPTR, &ci) < 0)
151
+ return -EINVAL;
152
+
153
+ if (ci.ptr == oss->last_bytes &&
154
+ ((ioctl(oss->fd, (io->stream == SND_PCM_STREAM_PLAYBACK) ?
155
+ SNDCTL_DSP_GETOSPACE : SNDCTL_DSP_GETISPACE, &bi) < 0) ||
156
+ bi.bytes == oss->bufsz))
157
+ return -EPIPE;
158
+
159
+ if (ci.ptr < oss->last_bytes)
160
+ oss->ptr += oss->bufsz;
161
+
162
+ oss->ptr += ci.ptr;
163
+ oss->ptr -= oss->last_bytes;
164
+ oss->ptr %= oss->ptr_align;
165
+
166
+ oss->last_bytes = ci.ptr;
167
+#else /* !FREEBSD_OSS_USE_IO_PTR */
168
+ if (ioctl(oss->fd, (io->stream == SND_PCM_STREAM_PLAYBACK) ?
169
+ SNDCTL_DSP_GETOSPACE : SNDCTL_DSP_GETISPACE, &bi) < 0)
170
+ return -EINVAL;
171
+
172
+ if (bi.bytes == oss->bufsz && bi.bytes == oss->last_bytes) {
173
+#if 0
174
+#ifdef SNDCTL_DSP_GETERROR
175
+ audio_errinfo ei;
176
+ if (ioctl(oss->fd, SNDCTL_DSP_GETERROR, &ei) < 0 ||
177
+ (io->stream == SND_PCM_STREAM_PLAYBACK &&
178
+ ei.play_underruns != 0) ||
179
+ (io->stream == SND_PCM_STREAM_CAPTURE &&
180
+ ei.rec_overruns != 0))
181
+#endif
182
+#endif
183
+ return -EPIPE;
184
+ }
185
+
186
+ if (bi.bytes > oss->last_bytes) {
187
+ oss->ptr += bi.bytes - oss->last_bytes;
188
+ oss->ptr %= oss->ptr_align;
189
+ }
190
+
191
+ oss->last_bytes = bi.bytes;
192
+#endif /* FREEBSD_OSS_USE_IO_PTR */
193
+
194
+ return snd_pcm_bytes_to_frames(io->pcm, oss->ptr);
195
+#else
196
+ snd_pcm_oss_t *oss = io->private_data;
197
struct count_info info;
198
int ptr;
199
200
@@ -85,20 +196,59 @@ static snd_pcm_sframes_t oss_pointer(snd_pcm_ioplug_t
201
}
202
ptr = snd_pcm_bytes_to_frames(io->pcm, info.ptr);
203
return ptr;
204
+#endif
205
}
206
207
static int oss_start(snd_pcm_ioplug_t *io)
208
{
209
snd_pcm_oss_t *oss = io->private_data;
210
+#ifdef __FreeBSD__
211
+ audio_buf_info bi;
212
+#ifdef FREEBSD_OSS_USE_IO_PTR
213
+ struct count_info ci;
214
+#endif
215
+#endif
216
int tmp = io->stream == SND_PCM_STREAM_PLAYBACK ?
217
PCM_ENABLE_OUTPUT : PCM_ENABLE_INPUT;
218
219
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
220
+ fprintf(stderr, "%s()\n", __func__);
221
+#endif
222
+
223
if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp) < 0) {
224
fprintf(stderr, "*** OSS: trigger failed\n");
225
+#ifdef __FreeBSD__
226
+ return -EINVAL;
227
+#else
228
if (io->stream == SND_PCM_STREAM_CAPTURE)
229
/* fake read to trigger */
230
read(oss->fd, &tmp, 0);
231
+#endif
232
}
233
+
234
+#ifdef __FreeBSD__
235
+ if (ioctl(oss->fd, (io->stream == SND_PCM_STREAM_PLAYBACK) ?
236
+ SNDCTL_DSP_GETOSPACE : SNDCTL_DSP_GETISPACE, &bi) < 0)
237
+ return -EINVAL;
238
+
239
+ if (oss->bufsz != (bi.fragsize * bi.fragstotal)) {
240
+ fprintf(stderr, "%s(): WARNING - bufsz changed! %d -> %d\n",
241
+ __func__, oss->bufsz, bi.fragsize * bi.fragstotal);
242
+ oss->bufsz = bi.fragsize * bi.fragstotal;
243
+ }
244
+
245
+#ifdef FREEBSD_OSS_USE_IO_PTR
246
+ if (ioctl(oss->fd, (io->stream == SND_PCM_STREAM_PLAYBACK) ?
247
+ SNDCTL_DSP_GETOPTR : SNDCTL_DSP_GETIPTR, &ci) < 0)
248
+ return -EINVAL;
249
+
250
+ oss->last_bytes = ci.ptr;
251
+#else
252
+ oss->last_bytes = bi.bytes;
253
+#endif
254
+ oss->ptr = 0;
255
+#endif
256
+
257
return 0;
258
}
259
260
@@ -107,6 +257,10 @@ static int oss_stop(snd_pcm_ioplug_t *io)
261
snd_pcm_oss_t *oss = io->private_data;
262
int tmp = 0;
263
264
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
265
+ fprintf(stderr, "%s()\n", __func__);
266
+#endif
267
+
268
ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp);
269
return 0;
270
}
271
@@ -115,16 +269,44 @@ static int oss_drain(snd_pcm_ioplug_t *io)
272
{
273
snd_pcm_oss_t *oss = io->private_data;
274
275
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
276
+ fprintf(stderr, "%s()\n", __func__);
277
+#endif
278
+
279
if (io->stream == SND_PCM_STREAM_PLAYBACK)
280
ioctl(oss->fd, SNDCTL_DSP_SYNC);
281
return 0;
282
}
283
284
+static int oss_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp)
285
+{
286
+ snd_pcm_oss_t *oss = io->private_data;
287
+ int tmp;
288
+
289
+ if (oss->fd < 0)
290
+ return -EBADFD;
291
+
292
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
293
+ if (ioctl(oss->fd, SNDCTL_DSP_GETODELAY, &tmp) < 0 || tmp < 0)
294
+ tmp = 0;
295
+ } else {
296
+ tmp = 0;
297
+ }
298
+ *delayp = snd_pcm_bytes_to_frames(io->pcm, tmp);
299
+
300
+ return (0);
301
+}
302
+
303
+#ifndef __FreeBSD__
304
static int oss_prepare(snd_pcm_ioplug_t *io)
305
{
306
snd_pcm_oss_t *oss = io->private_data;
307
int tmp;
308
309
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
310
+ fprintf(stderr, "%s()\n", __func__);
311
+#endif
312
+
313
ioctl(oss->fd, SNDCTL_DSP_RESET);
314
315
tmp = io->channels;
316
@@ -145,16 +327,75 @@ static int oss_prepare(snd_pcm_ioplug_t *io)
317
}
318
return 0;
319
}
320
+#endif
321
322
+#ifdef __FreeBSD__
323
+static const struct {
324
+ int oss_format;
325
+ snd_pcm_format_t alsa_format;
326
+} oss_formats_tab[] = {
327
+ { AFMT_U8, SND_PCM_FORMAT_U8 },
328
+ { AFMT_S8, SND_PCM_FORMAT_S8 },
329
+ { AFMT_MU_LAW, SND_PCM_FORMAT_MU_LAW },
330
+ { AFMT_A_LAW, SND_PCM_FORMAT_A_LAW },
331
+ { AFMT_S16_LE, SND_PCM_FORMAT_S16_LE },
332
+ { AFMT_S16_BE, SND_PCM_FORMAT_S16_BE },
333
+ { AFMT_U16_LE, SND_PCM_FORMAT_U16_LE },
334
+ { AFMT_U16_BE, SND_PCM_FORMAT_U16_BE },
335
+ { AFMT_S24_LE, SND_PCM_FORMAT_S24_3LE },
336
+ { AFMT_S24_BE, SND_PCM_FORMAT_S24_3BE },
337
+ { AFMT_U24_LE, SND_PCM_FORMAT_U24_3LE },
338
+ { AFMT_U24_BE, SND_PCM_FORMAT_U24_3BE },
339
+ { AFMT_S32_LE, SND_PCM_FORMAT_S32_LE },
340
+ { AFMT_S32_BE, SND_PCM_FORMAT_S32_BE },
341
+ { AFMT_U32_LE, SND_PCM_FORMAT_U32_LE },
342
+ { AFMT_U32_BE, SND_PCM_FORMAT_U32_BE },
343
+ /* Special */
344
+ { AFMT_S24_LE, SND_PCM_FORMAT_S20_3LE },
345
+ { AFMT_S24_BE, SND_PCM_FORMAT_S20_3BE },
346
+ { AFMT_U24_LE, SND_PCM_FORMAT_U20_3LE },
347
+ { AFMT_U24_BE, SND_PCM_FORMAT_U20_3BE },
348
+ { AFMT_S24_LE, SND_PCM_FORMAT_S18_3LE },
349
+ { AFMT_S24_BE, SND_PCM_FORMAT_S18_3BE },
350
+ { AFMT_U24_LE, SND_PCM_FORMAT_U18_3LE },
351
+ { AFMT_U24_BE, SND_PCM_FORMAT_U18_3BE },
352
+ { AFMT_S32_LE, SND_PCM_FORMAT_S24_LE },
353
+ { AFMT_S32_BE, SND_PCM_FORMAT_S24_BE },
354
+ { AFMT_U32_LE, SND_PCM_FORMAT_U24_LE },
355
+ { AFMT_U32_BE, SND_PCM_FORMAT_U24_BE },
356
+};
357
+#endif
358
+
359
static int oss_hw_params(snd_pcm_ioplug_t *io,
360
snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED)
361
{
362
snd_pcm_oss_t *oss = io->private_data;
363
int i, tmp, err;
364
+#ifdef __FreeBSD__
365
+ int blksz_shift, blkcnt;
366
+ audio_buf_info bi;
367
+#else
368
unsigned int period_bytes;
369
+#endif
370
long oflags, flags;
371
372
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
373
+ fprintf(stderr, "%s()\n", __func__);
374
+#endif
375
+
376
oss->frame_bytes = (snd_pcm_format_physical_width(io->format) * io->channels) / 8;
377
+#ifdef __FreeBSD__
378
+ oss->ptr_align = io->buffer_size * oss->frame_bytes;
379
+
380
+ oss->format = 0;
381
+ for (i = 0; i < ARRAY_SIZE(oss_formats_tab); i++) {
382
+ if (oss_formats_tab[i].alsa_format == io->format) {
383
+ oss->format = oss_formats_tab[i].oss_format;
384
+ break;
385
+ }
386
+ }
387
+ if (oss->format == 0) {
388
+#else
389
switch (io->format) {
390
case SND_PCM_FORMAT_U8:
391
oss->format = AFMT_U8;
392
@@ -166,9 +407,93 @@ static int oss_hw_params(snd_pcm_ioplug_t *io,
393
oss->format = AFMT_S16_BE;
394
break;
395
default:
396
+#endif
397
fprintf(stderr, "*** OSS: unsupported format %s\n", snd_pcm_format_name(io->format));
398
return -EINVAL;
399
}
400
+#ifdef __FreeBSD__
401
+
402
+ ioctl(oss->fd, SNDCTL_DSP_RESET);
403
+
404
+ /* use a 16ms HW buffer by default */
405
+ tmp = ((16 * io->rate) / 1000) * oss->frame_bytes;
406
+
407
+ /* round up to nearest power of two */
408
+ while (tmp & (tmp - 1))
409
+ tmp += tmp & ~(tmp - 1);
410
+
411
+ /* get logarithmic value */
412
+ for (blksz_shift = 0; blksz_shift < 24; blksz_shift++) {
413
+ if (tmp == (1 << blksz_shift))
414
+ break;
415
+ }
416
+
417
+ tmp = io->buffer_size * oss->frame_bytes;
418
+
419
+ /* compute HW buffer big enough to hold SW buffer */
420
+ for (blkcnt = FREEBSD_OSS_BLKCNT_MIN; blkcnt != FREEBSD_OSS_BLKCNT_MAX; blkcnt *= 2) {
421
+ if ((blkcnt << blksz_shift) >= tmp)
422
+ break;
423
+ }
424
+
425
+ tmp = blksz_shift | (blkcnt << 16);
426
+ if (ioctl(oss->fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) {
427
+ perror("SNDCTL_DSP_SETFRAGMENTS");
428
+ return -EINVAL;
429
+ }
430
+
431
+ tmp = oss->format;
432
+ if (ioctl(oss->fd, SNDCTL_DSP_SETFMT, &tmp) < 0 ||
433
+ tmp != oss->format) {
434
+ perror("SNDCTL_DSP_SETFMT");
435
+ return -EINVAL;
436
+ }
437
+
438
+ tmp = io->channels;
439
+ if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) < 0 ||
440
+ tmp != io->channels) {
441
+ perror("SNDCTL_DSP_CHANNELS");
442
+ return -EINVAL;
443
+ }
444
+
445
+ tmp = io->rate;
446
+ if (ioctl(oss->fd, SNDCTL_DSP_SPEED, &tmp) < 0 ||
447
+ tmp > io->rate * 1.01 || tmp < io->rate * 0.99) {
448
+ perror("SNDCTL_DSP_SPEED");
449
+ return -EINVAL;
450
+ }
451
+
452
+ if (ioctl(oss->fd, (io->stream == SND_PCM_STREAM_PLAYBACK) ?
453
+ SNDCTL_DSP_GETOSPACE : SNDCTL_DSP_GETISPACE, &bi) < 0) {
454
+ perror("SNDCTL_DSP_GET[I/O]SPACE");
455
+ return -EINVAL;
456
+ }
457
+
458
+ oss->bufsz = bi.fragsize * bi.fragstotal;
459
+
460
+#ifdef SNDCTL_DSP_LOW_WATER
461
+ tmp = ((io->period_size * oss->frame_bytes) * 3) / 4;
462
+ tmp -= tmp % oss->frame_bytes;
463
+ if (tmp < oss->frame_bytes)
464
+ tmp = oss->frame_bytes;
465
+ if (tmp > bi.fragsize)
466
+ tmp = bi.fragsize;
467
+ if (ioctl(oss->fd, SNDCTL_DSP_LOW_WATER, &tmp) < 0)
468
+ perror("SNDCTL_DSP_LOW_WATER");
469
+#endif
470
+
471
+#ifdef FREEBSD_OSS_DEBUG_VERBOSE
472
+ fprintf(stderr,
473
+ "\n\n[%lu -> %d] %lu ~ %d -> %d, %lu ~ %d -> %d [d:%ld lw:%d]\n\n",
474
+ io->buffer_size / io->period_size, bi.fragstotal,
475
+ io->buffer_size * oss->frame_bytes,
476
+ (1 << blksz_shift) * blkcnt, oss->bufsz,
477
+ io->period_size * oss->frame_bytes, 1 << blksz_shift,
478
+ bi.fragsize,
479
+ (long)(io->buffer_size * oss->frame_bytes) -
480
+ oss->bufsz, tmp);
481
+#endif
482
+#else
483
period_bytes = io->period_size * oss->frame_bytes;
484
oss->period_shift = 0;
485
for (i = 31; i >= 4; i--) {
486
@@ -209,6 +534,7 @@ static int oss_hw_params(snd_pcm_ioplug_t *io,
487
goto _retry;
488
}
489
oss->fragment_set = 1;
490
+#endif
491
492
if ((flags = fcntl(oss->fd, F_GETFL)) < 0) {
493
err = -errno;
494
@@ -229,16 +555,152 @@ static int oss_hw_params(snd_pcm_ioplug_t *io,
495
return 0;
496
}
497
498
-#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0]))
499
-
500
static int oss_hw_constraint(snd_pcm_oss_t *oss)
501
{
502
+#ifdef __FreeBSD__
503
snd_pcm_ioplug_t *io = &oss->io;
504
static const snd_pcm_access_t access_list[] = {
505
SND_PCM_ACCESS_RW_INTERLEAVED,
506
SND_PCM_ACCESS_MMAP_INTERLEAVED
507
};
508
+#ifdef FREEBSD_OSS_BLKCNT_P2
509
+ unsigned int period_list[30];
510
+#endif
511
+#ifdef FREEBSD_OSS_BUFSZ_P2
512
+ unsigned int bufsz_list[30];
513
+#endif
514
unsigned int nformats;
515
+ unsigned int format[ARRAY_SIZE(oss_formats_tab)];
516
+#if 0
517
+ unsigned int nchannels;
518
+ unsigned int channel[FREEBSD_OSS_CHANNELS_MAX];
519
+#endif
520
+ int i, err, tmp;
521
+
522
+#ifdef FREEBSD_OSS_DEBUG_VERBOSE
523
+ fprintf(stderr, "%s()\n", __func__);
524
+#endif
525
+
526
+ /* check trigger */
527
+ tmp = 0;
528
+ if (ioctl(oss->fd, SNDCTL_DSP_GETCAPS, &tmp) >= 0) {
529
+ if (!(tmp & DSP_CAP_TRIGGER))
530
+ fprintf(stderr, "*** OSS: trigger is not supported!\n");
531
+ }
532
+
533
+ /* access type - interleaved only */
534
+ if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS,
535
+ ARRAY_SIZE(access_list), access_list)) < 0)
536
+ return err;
537
+
538
+ /* supported formats. */
539
+ tmp = 0;
540
+ ioctl(oss->fd, SNDCTL_DSP_GETFMTS, &tmp);
541
+ nformats = 0;
542
+ for (i = 0; i < ARRAY_SIZE(oss_formats_tab); i++) {
543
+ if (tmp & oss_formats_tab[i].oss_format)
544
+ format[nformats++] = oss_formats_tab[i].alsa_format;
545
+ }
546
+ if (! nformats)
547
+ format[nformats++] = SND_PCM_FORMAT_S16;
548
+ if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT,
549
+ nformats, format)) < 0)
550
+ return err;
551
+
552
+#if 0
553
+ /* supported channels */
554
+ nchannels = 0;
555
+ for (i = 0; i < ARRAY_SIZE(channel); i++) {
556
+ tmp = i + 1;
557
+ if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) >= 0 &&
558
+ 1 + i == tmp)
559
+ channel[nchannels++] = tmp;
560
+ }
561
+ if (! nchannels) /* assume 2ch stereo */
562
+ err = snd_pcm_ioplug_set_param_minmax(io,
563
+ SND_PCM_IOPLUG_HW_CHANNELS, 2, 2);
564
+ else
565
+ err = snd_pcm_ioplug_set_param_list(io,
566
+ SND_PCM_IOPLUG_HW_CHANNELS, nchannels, channel);
567
+ if (err < 0)
568
+ return err;
569
+#endif
570
+ err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS,
571
+ FREEBSD_OSS_CHANNELS_MIN, FREEBSD_OSS_CHANNELS_MAX);
572
+ if (err < 0)
573
+ return err;
574
+
575
+ /* supported rates */
576
+ err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE,
577
+ FREEBSD_OSS_RATE_MIN, FREEBSD_OSS_RATE_MAX);
578
+ if (err < 0)
579
+ return err;
580
+
581
+ /*
582
+ * Maximum buffer size on FreeBSD can go up to 131072 bytes without
583
+ * strict ^2 alignment so that s24le in 3bytes packing can be fed
584
+ * directly.
585
+ */
586
+
587
+#ifdef FREEBSD_OSS_BLKCNT_P2
588
+ tmp = 0;
589
+ for (i = 1; i < 31 && tmp < ARRAY_SIZE(period_list); i++) {
590
+ if ((1 << i) > FREEBSD_OSS_BLKCNT_MAX)
591
+ break;
592
+ if ((1 << i) < FREEBSD_OSS_BLKCNT_MIN)
593
+ continue;
594
+ period_list[tmp++] = 1 << i;
595
+ }
596
+
597
+ if (tmp > 0)
598
+ err = snd_pcm_ioplug_set_param_list(io,
599
+ SND_PCM_IOPLUG_HW_PERIODS, tmp, period_list);
600
+ else
601
+#endif
602
+ /* periods , not strictly ^2 but later on will be refined */
603
+ err = snd_pcm_ioplug_set_param_minmax(io,
604
+ SND_PCM_IOPLUG_HW_PERIODS, FREEBSD_OSS_BLKCNT_MIN,
605
+ FREEBSD_OSS_BLKCNT_MAX);
606
+ if (err < 0)
607
+ return err;
608
+
609
+ /* period size , not strictly ^2 */
610
+ err = snd_pcm_ioplug_set_param_minmax(io,
611
+ SND_PCM_IOPLUG_HW_PERIOD_BYTES, FREEBSD_OSS_BLKSZ_MIN,
612
+ FREEBSD_OSS_BLKSZ_MAX);
613
+ if (err < 0)
614
+ return err;
615
+
616
+#ifdef FREEBSD_OSS_BUFSZ_P2
617
+ tmp = 0;
618
+ for (i = 1; i < 31 && tmp < ARRAY_SIZE(bufsz_list); i++) {
619
+ if ((1 << i) > FREEBSD_OSS_BUFSZ_MAX)
620
+ break;
621
+ if ((1 << i) < FREEBSD_OSS_BUFSZ_MIN)
622
+ continue;
623
+ bufsz_list[tmp++] = 1 << i;
624
+ }
625
+
626
+ if (tmp > 0)
627
+ err = snd_pcm_ioplug_set_param_list(io,
628
+ SND_PCM_IOPLUG_HW_BUFFER_BYTES, tmp, bufsz_list);
629
+ else
630
+#endif
631
+ /* buffer size , not strictly ^2 */
632
+ err = snd_pcm_ioplug_set_param_minmax(io,
633
+ SND_PCM_IOPLUG_HW_BUFFER_BYTES, FREEBSD_OSS_BUFSZ_MIN,
634
+ FREEBSD_OSS_BUFSZ_MAX);
635
+ if (err < 0)
636
+ return err;
637
+
638
+ return 0;
639
+#else
640
+ snd_pcm_ioplug_t *io = &oss->io;
641
+ static const snd_pcm_access_t access_list[] = {
642
+ SND_PCM_ACCESS_RW_INTERLEAVED,
643
+ SND_PCM_ACCESS_MMAP_INTERLEAVED
644
+ };
645
+ unsigned int nformats;
646
unsigned int format[5];
647
unsigned int nchannels;
648
unsigned int channel[6];
649
@@ -317,6 +779,7 @@ static int oss_hw_constraint(snd_pcm_oss_t *oss)
650
return err;
651
652
return 0;
653
+#endif
654
}
655
656
657
@@ -324,6 +787,10 @@ static int oss_close(snd_pcm_ioplug_t *io)
658
{
659
snd_pcm_oss_t *oss = io->private_data;
660
661
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
662
+ fprintf(stderr, "%s()\n", __func__);
663
+#endif
664
+
665
close(oss->fd);
666
free(oss->device);
667
free(oss);
668
@@ -337,8 +804,11 @@ static const snd_pcm_ioplug_callback_t oss_playback_ca
669
.pointer = oss_pointer,
670
.close = oss_close,
671
.hw_params = oss_hw_params,
672
+#ifndef __FreeBSD__
673
.prepare = oss_prepare,
674
+#endif
675
.drain = oss_drain,
676
+ .delay = oss_delay,
677
};
678
679
static const snd_pcm_ioplug_callback_t oss_capture_callback = {
680
@@ -348,8 +818,11 @@ static const snd_pcm_ioplug_callback_t oss_capture_cal
681
.pointer = oss_pointer,
682
.close = oss_close,
683
.hw_params = oss_hw_params,
684
+#ifndef __FreeBSD__
685
.prepare = oss_prepare,
686
+#endif
687
.drain = oss_drain,
688
+ .delay = oss_delay,
689
};
690
691
692
@@ -360,6 +833,10 @@ SND_PCM_PLUGIN_DEFINE_FUNC(oss)
693
int err;
694
snd_pcm_oss_t *oss;
695
696
+#if defined(__FreeBSD__) && defined(FREEBSD_OSS_DEBUG_VERBOSE)
697
+ fprintf(stderr, "%s()\n", __func__);
698
+#endif
699
+
700
snd_config_for_each(i, next, conf) {
701
snd_config_t *n = snd_config_iterator_entry(i);
702
const char *id;
703
704