1 /*-
2 * Copyright (c) 2015-2022 Hans Petter Selasky
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26 #include <sys/queue.h>
27 #include <sys/filio.h>
28 #include <sys/soundcard.h>
29
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <err.h>
36 #include <time.h>
37
38 #include "backend.h"
39 #include "int.h"
40
41 static void
null_close(struct voss_backend * pbe __unused)42 null_close(struct voss_backend *pbe __unused)
43 {
44 }
45
46 static int
null_open(struct voss_backend * pbe __unused,const char * devname __unused,int samplerate __unused,int bufsize __unused,int * pchannels __unused,int * pformat)47 null_open(struct voss_backend *pbe __unused, const char *devname __unused,
48 int samplerate __unused, int bufsize __unused, int *pchannels __unused,
49 int *pformat)
50 {
51 int value[3];
52 int i;
53
54 value[0] = *pformat & VPREFERRED_SNE_AFMT;
55 value[1] = *pformat & VPREFERRED_SLE_AFMT;
56 value[2] = *pformat & VPREFERRED_SBE_AFMT;
57
58 for (i = 0; i != 3; i++) {
59 if (value[i] == 0)
60 continue;
61 *pformat = value[i];
62 return (0);
63 }
64 return (-1);
65 }
66
67 static int
null_rec_transfer(struct voss_backend * pbe __unused,void * ptr,int len)68 null_rec_transfer(struct voss_backend *pbe __unused, void *ptr, int len)
69 {
70
71 if (voss_has_synchronization == 0)
72 virtual_oss_wait();
73 memset(ptr, 0, len);
74 return (len);
75 }
76
77 static int
null_play_transfer(struct voss_backend * pbe __unused,void * ptr __unused,int len)78 null_play_transfer(struct voss_backend *pbe __unused, void *ptr __unused,
79 int len)
80 {
81 return (len);
82 }
83
84 static void
null_delay(struct voss_backend * pbe __unused,int * pdelay)85 null_delay(struct voss_backend *pbe __unused, int *pdelay)
86 {
87 *pdelay = -1;
88 }
89
90 struct voss_backend voss_backend_null_rec = {
91 .open = null_open,
92 .close = null_close,
93 .transfer = null_rec_transfer,
94 .delay = null_delay,
95 };
96
97 struct voss_backend voss_backend_null_play = {
98 .open = null_open,
99 .close = null_close,
100 .transfer = null_play_transfer,
101 .delay = null_delay,
102 };
103