-
Notifications
You must be signed in to change notification settings - Fork 13
/
virtual_ctl.c
617 lines (581 loc) · 19.3 KB
/
virtual_ctl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*-
* Copyright (c) 2012-2022 Hans Petter Selasky
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <cuse.h>
#include "virtual_int.h"
#include "virtual_oss.h"
int64_t voss_output_peak[VMAX_CHAN];
int64_t voss_input_peak[VMAX_CHAN];
static int
vctl_open(struct cuse_dev *pdev, int fflags)
{
return (0);
}
static int
vctl_close(struct cuse_dev *pdev, int fflags)
{
return (0);
}
static vprofile_t *
vprofile_by_index(const vprofile_head_t *phead, int index)
{
vprofile_t *pvp;
TAILQ_FOREACH(pvp, phead, entry) {
if (!index--)
return (pvp);
}
return (NULL);
}
static vmonitor_t *
vmonitor_by_index(int index, vmonitor_head_t *phead)
{
vmonitor_t *pvm;
TAILQ_FOREACH(pvm, phead, entry) {
if (!index--)
return (pvm);
}
return (NULL);
}
static int
vctl_ioctl(struct cuse_dev *pdev, int fflags,
unsigned long cmd, void *peer_data)
{
union {
int val;
struct virtual_oss_io_info io_info;
struct virtual_oss_mon_info mon_info;
struct virtual_oss_io_peak io_peak;
struct virtual_oss_mon_peak mon_peak;
struct virtual_oss_compressor out_lim;
struct virtual_oss_io_limit io_lim;
struct virtual_oss_master_peak master_peak;
struct virtual_oss_audio_delay_locator ad_locator;
struct virtual_oss_fir_filter fir_filter;
struct virtual_oss_system_info sys_info;
char options[VIRTUAL_OSS_OPTIONS_MAX];
} data;
vprofile_t *pvp;
vclient_t *pvc;
vmonitor_t *pvm;
int chan;
int len;
int error;
len = IOCPARM_LEN(cmd);
if (len < 0 || len > (int)sizeof(data))
return (CUSE_ERR_INVALID);
if (cmd & IOC_IN) {
error = cuse_copy_in(peer_data, &data, len);
if (error)
return (error);
} else {
error = 0;
}
atomic_lock();
switch (cmd) {
case VIRTUAL_OSS_GET_DEV_INFO:
case VIRTUAL_OSS_SET_DEV_INFO:
case VIRTUAL_OSS_GET_DEV_PEAK:
case VIRTUAL_OSS_SET_DEV_LIMIT:
case VIRTUAL_OSS_GET_DEV_LIMIT:
case VIRTUAL_OSS_SET_RX_DEV_FIR_FILTER:
case VIRTUAL_OSS_GET_RX_DEV_FIR_FILTER:
case VIRTUAL_OSS_SET_TX_DEV_FIR_FILTER:
case VIRTUAL_OSS_GET_TX_DEV_FIR_FILTER:
pvp = vprofile_by_index(&virtual_profile_client_head, data.val);
break;
case VIRTUAL_OSS_GET_LOOP_INFO:
case VIRTUAL_OSS_SET_LOOP_INFO:
case VIRTUAL_OSS_GET_LOOP_PEAK:
case VIRTUAL_OSS_SET_LOOP_LIMIT:
case VIRTUAL_OSS_GET_LOOP_LIMIT:
case VIRTUAL_OSS_SET_RX_LOOP_FIR_FILTER:
case VIRTUAL_OSS_GET_RX_LOOP_FIR_FILTER:
case VIRTUAL_OSS_SET_TX_LOOP_FIR_FILTER:
case VIRTUAL_OSS_GET_TX_LOOP_FIR_FILTER:
pvp = vprofile_by_index(&virtual_profile_loopback_head, data.val);
break;
default:
pvp = NULL;
break;
}
switch (cmd) {
case VIRTUAL_OSS_GET_VERSION:
data.val = VIRTUAL_OSS_VERSION;
break;
case VIRTUAL_OSS_GET_DEV_INFO:
case VIRTUAL_OSS_GET_LOOP_INFO:
if (pvp == NULL ||
data.io_info.channel < 0 ||
data.io_info.channel >= (int)pvp->channels) {
error = CUSE_ERR_INVALID;
break;
}
strlcpy(data.io_info.name, pvp->oss_name, sizeof(data.io_info.name));
chan = data.io_info.channel;
data.io_info.rx_amp = pvp->rx_shift[chan];
data.io_info.tx_amp = pvp->tx_shift[chan];
data.io_info.rx_chan = pvp->rx_src[chan];
data.io_info.tx_chan = pvp->tx_dst[chan];
data.io_info.rx_mute = pvp->rx_mute[chan] ? 1 : 0;
data.io_info.tx_mute = pvp->tx_mute[chan] ? 1 : 0;
data.io_info.rx_pol = pvp->rx_pol[chan] ? 1 : 0;
data.io_info.tx_pol = pvp->tx_pol[chan] ? 1 : 0;
data.io_info.bits = pvp->bits;
data.io_info.rx_delay = pvp->rec_delay;
data.io_info.rx_delay_limit = voss_dsp_sample_rate;
break;
case VIRTUAL_OSS_SET_DEV_INFO:
case VIRTUAL_OSS_SET_LOOP_INFO:
if (pvp == NULL ||
data.io_info.channel < 0 ||
data.io_info.channel >= (int)pvp->channels ||
data.io_info.rx_amp < -31 || data.io_info.rx_amp > 31 ||
data.io_info.tx_amp < -31 || data.io_info.tx_amp > 31 ||
data.io_info.rx_delay < 0 ||
data.io_info.rx_delay > (int)voss_dsp_sample_rate) {
error = CUSE_ERR_INVALID;
break;
}
chan = data.io_info.channel;
pvp->rx_shift[chan] = data.io_info.rx_amp;
pvp->tx_shift[chan] = data.io_info.tx_amp;
pvp->rx_src[chan] = data.io_info.rx_chan;
pvp->tx_dst[chan] = data.io_info.tx_chan;
pvp->rx_mute[chan] = data.io_info.rx_mute ? 1 : 0;
pvp->tx_mute[chan] = data.io_info.tx_mute ? 1 : 0;
pvp->rx_pol[chan] = data.io_info.rx_pol ? 1 : 0;
pvp->tx_pol[chan] = data.io_info.tx_pol ? 1 : 0;
pvp->rec_delay = data.io_info.rx_delay;
break;
case VIRTUAL_OSS_GET_INPUT_MON_INFO:
pvm = vmonitor_by_index(data.mon_info.number,
&virtual_monitor_input);
if (pvm == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.mon_info.src_chan = pvm->src_chan;
data.mon_info.dst_chan = pvm->dst_chan;
data.mon_info.pol = pvm->pol;
data.mon_info.mute = pvm->mute;
data.mon_info.amp = pvm->shift;
data.mon_info.bits = voss_dsp_bits;
break;
case VIRTUAL_OSS_SET_INPUT_MON_INFO:
pvm = vmonitor_by_index(data.mon_info.number,
&virtual_monitor_input);
if (pvm == NULL ||
data.mon_info.amp < -31 ||
data.mon_info.amp > 31) {
error = CUSE_ERR_INVALID;
break;
}
pvm->src_chan = data.mon_info.src_chan;
pvm->dst_chan = data.mon_info.dst_chan;
pvm->pol = data.mon_info.pol ? 1 : 0;
pvm->mute = data.mon_info.mute ? 1 : 0;
pvm->shift = data.mon_info.amp;
break;
case VIRTUAL_OSS_GET_OUTPUT_MON_INFO:
pvm = vmonitor_by_index(data.mon_info.number,
&virtual_monitor_output);
if (pvm == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.mon_info.src_chan = pvm->src_chan;
data.mon_info.dst_chan = pvm->dst_chan;
data.mon_info.pol = pvm->pol;
data.mon_info.mute = pvm->mute;
data.mon_info.amp = pvm->shift;
data.mon_info.bits = voss_dsp_bits;
break;
case VIRTUAL_OSS_SET_OUTPUT_MON_INFO:
pvm = vmonitor_by_index(data.mon_info.number,
&virtual_monitor_output);
if (pvm == NULL ||
data.mon_info.amp < -31 ||
data.mon_info.amp > 31) {
error = CUSE_ERR_INVALID;
break;
}
pvm->src_chan = data.mon_info.src_chan;
pvm->dst_chan = data.mon_info.dst_chan;
pvm->pol = data.mon_info.pol ? 1 : 0;
pvm->mute = data.mon_info.mute ? 1 : 0;
pvm->shift = data.mon_info.amp;
break;
case VIRTUAL_OSS_GET_LOCAL_MON_INFO:
pvm = vmonitor_by_index(data.mon_info.number,
&virtual_monitor_local);
if (pvm == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.mon_info.src_chan = pvm->src_chan;
data.mon_info.dst_chan = pvm->dst_chan;
data.mon_info.pol = pvm->pol;
data.mon_info.mute = pvm->mute;
data.mon_info.amp = pvm->shift;
data.mon_info.bits = voss_dsp_bits;
break;
case VIRTUAL_OSS_SET_LOCAL_MON_INFO:
pvm = vmonitor_by_index(data.mon_info.number,
&virtual_monitor_local);
if (pvm == NULL ||
data.mon_info.amp < -31 ||
data.mon_info.amp > 31) {
error = CUSE_ERR_INVALID;
break;
}
pvm->src_chan = data.mon_info.src_chan;
pvm->dst_chan = data.mon_info.dst_chan;
pvm->pol = data.mon_info.pol ? 1 : 0;
pvm->mute = data.mon_info.mute ? 1 : 0;
pvm->shift = data.mon_info.amp;
break;
case VIRTUAL_OSS_GET_DEV_PEAK:
case VIRTUAL_OSS_GET_LOOP_PEAK:
if (pvp == NULL ||
data.io_peak.channel < 0 ||
data.io_peak.channel >= (int)pvp->channels) {
error = CUSE_ERR_INVALID;
break;
}
strlcpy(data.io_peak.name, pvp->oss_name, sizeof(data.io_peak.name));
chan = data.io_peak.channel;
data.io_peak.rx_peak_value = pvp->rx_peak_value[chan];
pvp->rx_peak_value[chan] = 0;
data.io_peak.tx_peak_value = pvp->tx_peak_value[chan];
pvp->tx_peak_value[chan] = 0;
data.io_peak.bits = pvp->bits;
break;
case VIRTUAL_OSS_GET_INPUT_MON_PEAK:
pvm = vmonitor_by_index(data.mon_peak.number,
&virtual_monitor_input);
if (pvm == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.mon_peak.peak_value = pvm->peak_value;
data.mon_peak.bits = voss_dsp_bits;
pvm->peak_value = 0;
break;
case VIRTUAL_OSS_GET_OUTPUT_MON_PEAK:
pvm = vmonitor_by_index(data.mon_peak.number,
&virtual_monitor_output);
if (pvm == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.mon_peak.peak_value = pvm->peak_value;
data.mon_peak.bits = voss_dsp_bits;
pvm->peak_value = 0;
break;
case VIRTUAL_OSS_GET_LOCAL_MON_PEAK:
pvm = vmonitor_by_index(data.mon_peak.number,
&virtual_monitor_local);
if (pvm == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.mon_peak.peak_value = pvm->peak_value;
data.mon_peak.bits = voss_dsp_bits;
pvm->peak_value = 0;
break;
case VIRTUAL_OSS_ADD_INPUT_MON:
pvm = vmonitor_alloc(&data.val,
&virtual_monitor_input);
if (pvm == NULL)
error = CUSE_ERR_INVALID;
break;
case VIRTUAL_OSS_ADD_OUTPUT_MON:
pvm = vmonitor_alloc(&data.val,
&virtual_monitor_output);
if (pvm == NULL)
error = CUSE_ERR_INVALID;
break;
case VIRTUAL_OSS_ADD_LOCAL_MON:
pvm = vmonitor_alloc(&data.val,
&virtual_monitor_local);
if (pvm == NULL)
error = CUSE_ERR_INVALID;
break;
case VIRTUAL_OSS_SET_OUTPUT_LIMIT:
if (data.out_lim.enabled < 0 ||
data.out_lim.enabled > 1 ||
data.out_lim.knee < VIRTUAL_OSS_KNEE_MIN ||
data.out_lim.knee > VIRTUAL_OSS_KNEE_MAX ||
data.out_lim.attack < VIRTUAL_OSS_ATTACK_MIN ||
data.out_lim.attack > VIRTUAL_OSS_ATTACK_MAX ||
data.out_lim.decay < VIRTUAL_OSS_DECAY_MIN ||
data.out_lim.decay > VIRTUAL_OSS_DECAY_MAX ||
data.out_lim.gain != 0) {
error = CUSE_ERR_INVALID;
break;
}
voss_output_compressor_param.enabled = data.out_lim.enabled;
voss_output_compressor_param.knee = data.out_lim.knee;
voss_output_compressor_param.attack = data.out_lim.attack;
voss_output_compressor_param.decay = data.out_lim.decay;
break;
case VIRTUAL_OSS_GET_OUTPUT_LIMIT:
data.out_lim.enabled = voss_output_compressor_param.enabled;
data.out_lim.knee = voss_output_compressor_param.knee;
data.out_lim.attack = voss_output_compressor_param.attack;
data.out_lim.decay = voss_output_compressor_param.decay;
data.out_lim.gain = 1000;
for (chan = 0; chan != VMAX_CHAN; chan++) {
int gain = voss_output_compressor_gain[chan] * 1000.0;
if (data.out_lim.gain > gain)
data.out_lim.gain = gain;
}
break;
case VIRTUAL_OSS_SET_DEV_LIMIT:
case VIRTUAL_OSS_SET_LOOP_LIMIT:
if (pvp == NULL ||
data.io_lim.param.enabled < 0 ||
data.io_lim.param.enabled > 1 ||
data.io_lim.param.knee < VIRTUAL_OSS_KNEE_MIN ||
data.io_lim.param.knee > VIRTUAL_OSS_KNEE_MAX ||
data.io_lim.param.attack < VIRTUAL_OSS_ATTACK_MIN ||
data.io_lim.param.attack > VIRTUAL_OSS_ATTACK_MAX ||
data.io_lim.param.decay < VIRTUAL_OSS_DECAY_MIN ||
data.io_lim.param.decay > VIRTUAL_OSS_DECAY_MAX ||
data.io_lim.param.gain != 0) {
error = CUSE_ERR_INVALID;
break;
}
pvp->rx_compressor_param.enabled = data.io_lim.param.enabled;
pvp->rx_compressor_param.knee = data.io_lim.param.knee;
pvp->rx_compressor_param.attack = data.io_lim.param.attack;
pvp->rx_compressor_param.decay = data.io_lim.param.decay;
break;
case VIRTUAL_OSS_GET_DEV_LIMIT:
case VIRTUAL_OSS_GET_LOOP_LIMIT:
if (pvp == NULL) {
error = CUSE_ERR_INVALID;
break;
}
data.io_lim.param.enabled = pvp->rx_compressor_param.enabled;
data.io_lim.param.knee = pvp->rx_compressor_param.knee;
data.io_lim.param.attack = pvp->rx_compressor_param.attack;
data.io_lim.param.decay = pvp->rx_compressor_param.decay;
data.io_lim.param.gain = 1000;
for (chan = 0; chan != VMAX_CHAN; chan++) {
int gain = pvp->rx_compressor_gain[chan] * 1000.0;
if (data.io_lim.param.gain > gain)
data.io_lim.param.gain = gain;
}
break;
case VIRTUAL_OSS_GET_OUTPUT_PEAK:
chan = data.master_peak.channel;
if (chan < 0 ||
chan >= (int)voss_max_channels) {
error = CUSE_ERR_INVALID;
break;
}
data.master_peak.bits = voss_dsp_bits;
data.master_peak.peak_value = voss_output_peak[chan];
voss_output_peak[chan] = 0;
break;
case VIRTUAL_OSS_GET_INPUT_PEAK:
chan = data.master_peak.channel;
if (chan < 0 ||
chan >= (int)voss_dsp_max_channels) {
error = CUSE_ERR_INVALID;
break;
}
data.master_peak.bits = voss_dsp_bits;
data.master_peak.peak_value = voss_input_peak[chan];
voss_input_peak[chan] = 0;
break;
case VIRTUAL_OSS_SET_RECORDING:
voss_is_recording = data.val ? 1 : 0;
break;
case VIRTUAL_OSS_GET_RECORDING:
data.val = voss_is_recording;
break;
case VIRTUAL_OSS_SET_AUDIO_DELAY_LOCATOR:
if (data.ad_locator.channel_output < 0 ||
data.ad_locator.channel_output >= (int)voss_mix_channels) {
error = CUSE_ERR_INVALID;
break;
}
if (data.ad_locator.channel_input < 0 ||
data.ad_locator.channel_input >= (int)voss_mix_channels) {
error = CUSE_ERR_INVALID;
break;
}
if (data.ad_locator.signal_output_level < 0 ||
data.ad_locator.signal_output_level >= 64) {
error = CUSE_ERR_INVALID;
break;
}
voss_ad_enabled = (data.ad_locator.locator_enabled != 0);
voss_ad_output_signal = data.ad_locator.signal_output_level;
voss_ad_output_channel = data.ad_locator.channel_output;
voss_ad_input_channel = data.ad_locator.channel_input;
break;
case VIRTUAL_OSS_GET_AUDIO_DELAY_LOCATOR:
data.ad_locator.locator_enabled = voss_ad_enabled;
data.ad_locator.signal_output_level = voss_ad_output_signal;
data.ad_locator.channel_output = voss_ad_output_channel;
data.ad_locator.channel_input = voss_ad_input_channel;
data.ad_locator.channel_last = voss_mix_channels - 1;
data.ad_locator.signal_input_delay = voss_ad_last_delay;
data.ad_locator.signal_delay_hz = voss_dsp_sample_rate;
break;
case VIRTUAL_OSS_RST_AUDIO_DELAY_LOCATOR:
voss_ad_reset();
break;
case VIRTUAL_OSS_ADD_OPTIONS:
data.options[VIRTUAL_OSS_OPTIONS_MAX - 1] = 0;
voss_add_options(data.options);
break;
case VIRTUAL_OSS_GET_RX_DEV_FIR_FILTER:
case VIRTUAL_OSS_GET_RX_LOOP_FIR_FILTER:
if (pvp == NULL ||
data.fir_filter.channel < 0 ||
data.fir_filter.channel >= (int)pvp->channels) {
error = CUSE_ERR_INVALID;
} else if (data.fir_filter.filter_data == NULL) {
data.fir_filter.filter_size = pvp->rx_filter_size;
} else if (data.fir_filter.filter_size != (int)pvp->rx_filter_size) {
error = CUSE_ERR_INVALID;
} else if (pvp->rx_filter_data[data.fir_filter.channel] == NULL) {
error = CUSE_ERR_NO_MEMORY; /* filter disabled */
} else {
error = cuse_copy_out(pvp->rx_filter_data[data.fir_filter.channel],
data.fir_filter.filter_data,
sizeof(pvp->rx_filter_data[0][0]) *
data.fir_filter.filter_size);
}
break;
case VIRTUAL_OSS_GET_TX_DEV_FIR_FILTER:
case VIRTUAL_OSS_GET_TX_LOOP_FIR_FILTER:
if (pvp == NULL ||
data.fir_filter.channel < 0 ||
data.fir_filter.channel >= (int)pvp->channels) {
error = CUSE_ERR_INVALID;
} else if (data.fir_filter.filter_data == NULL) {
data.fir_filter.filter_size = pvp->tx_filter_size;
} else if (data.fir_filter.filter_size != (int)pvp->tx_filter_size) {
error = CUSE_ERR_INVALID;
} else if (pvp->tx_filter_data[data.fir_filter.channel] == NULL) {
error = CUSE_ERR_NO_MEMORY; /* filter disabled */
} else {
error = cuse_copy_out(pvp->tx_filter_data[data.fir_filter.channel],
data.fir_filter.filter_data,
sizeof(pvp->tx_filter_data[0][0]) *
data.fir_filter.filter_size);
}
break;
case VIRTUAL_OSS_SET_RX_DEV_FIR_FILTER:
case VIRTUAL_OSS_SET_RX_LOOP_FIR_FILTER:
if (pvp == NULL ||
data.fir_filter.channel < 0 ||
data.fir_filter.channel >= (int)pvp->channels) {
error = CUSE_ERR_INVALID;
} else if (data.fir_filter.filter_data == NULL) {
free(pvp->rx_filter_data[data.fir_filter.channel]);
pvp->rx_filter_data[data.fir_filter.channel] = NULL; /* disable filter */
} else if (data.fir_filter.filter_size != (int)pvp->rx_filter_size) {
error = CUSE_ERR_INVALID;
} else if (pvp->rx_filter_size != 0) {
size_t size = sizeof(pvp->rx_filter_data[0][0]) * pvp->rx_filter_size;
if (pvp->rx_filter_data[data.fir_filter.channel] == NULL) {
pvp->rx_filter_data[data.fir_filter.channel] = malloc(size);
if (pvp->rx_filter_data[data.fir_filter.channel] == NULL)
error = CUSE_ERR_NO_MEMORY;
else
memset(pvp->rx_filter_data[data.fir_filter.channel], 0, size);
}
if (pvp->rx_filter_data[data.fir_filter.channel] != NULL) {
error = cuse_copy_in(data.fir_filter.filter_data,
pvp->rx_filter_data[data.fir_filter.channel], size);
}
}
break;
case VIRTUAL_OSS_SET_TX_DEV_FIR_FILTER:
case VIRTUAL_OSS_SET_TX_LOOP_FIR_FILTER:
if (pvp == NULL ||
data.fir_filter.channel < 0 ||
data.fir_filter.channel >= (int)pvp->channels) {
error = CUSE_ERR_INVALID;
} else if (data.fir_filter.filter_data == NULL) {
free(pvp->tx_filter_data[data.fir_filter.channel]);
pvp->tx_filter_data[data.fir_filter.channel] = NULL; /* disable filter */
} else if (data.fir_filter.filter_size != (int)pvp->tx_filter_size) {
error = CUSE_ERR_INVALID;
} else if (pvp->tx_filter_size != 0) {
size_t size = sizeof(pvp->tx_filter_data[0][0]) * pvp->tx_filter_size;
if (pvp->tx_filter_data[data.fir_filter.channel] == NULL) {
pvp->tx_filter_data[data.fir_filter.channel] = malloc(size);
if (pvp->tx_filter_data[data.fir_filter.channel] == NULL)
error = CUSE_ERR_NO_MEMORY;
else
memset(pvp->tx_filter_data[data.fir_filter.channel], 0, size);
}
if (pvp->tx_filter_data[data.fir_filter.channel] != NULL) {
error = cuse_copy_in(data.fir_filter.filter_data,
pvp->tx_filter_data[data.fir_filter.channel], size);
}
}
break;
case VIRTUAL_OSS_GET_SAMPLE_RATE:
data.val = voss_dsp_sample_rate;
break;
case VIRTUAL_OSS_GET_SYSTEM_INFO:
data.sys_info.tx_jitter_up = voss_jitter_up;
data.sys_info.tx_jitter_down = voss_jitter_down;
data.sys_info.sample_rate = voss_dsp_sample_rate;
data.sys_info.sample_bits = voss_dsp_bits;
data.sys_info.sample_channels = voss_mix_channels;
strlcpy(data.sys_info.rx_device_name, voss_dsp_rx_device,
sizeof(data.sys_info.rx_device_name));
strlcpy(data.sys_info.tx_device_name, voss_dsp_tx_device,
sizeof(data.sys_info.tx_device_name));
break;
default:
error = CUSE_ERR_INVALID;
break;
}
atomic_unlock();
if (error == 0) {
if (cmd & IOC_OUT)
error = cuse_copy_out(&data, peer_data, len);
}
return (error);
}
const struct cuse_methods vctl_methods = {
.cm_open = vctl_open,
.cm_close = vctl_close,
.cm_ioctl = vctl_ioctl,
};