1 | /* $NetBSD: audiovar.h,v 1.46 2011/11/23 23:07:31 jmcneill Exp $ */ |
2 | |
3 | /*- |
4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. |
5 | * All rights reserved. |
6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by TAMURA Kent |
9 | * |
10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions |
12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
31 | |
32 | /* |
33 | * Copyright (c) 1991-1993 Regents of the University of California. |
34 | * All rights reserved. |
35 | * |
36 | * Redistribution and use in source and binary forms, with or without |
37 | * modification, are permitted provided that the following conditions |
38 | * are met: |
39 | * 1. Redistributions of source code must retain the above copyright |
40 | * notice, this list of conditions and the following disclaimer. |
41 | * 2. Redistributions in binary form must reproduce the above copyright |
42 | * notice, this list of conditions and the following disclaimer in the |
43 | * documentation and/or other materials provided with the distribution. |
44 | * 3. All advertising materials mentioning features or use of this software |
45 | * must display the following acknowledgement: |
46 | * This product includes software developed by the Computer Systems |
47 | * Engineering Group at Lawrence Berkeley Laboratory. |
48 | * 4. Neither the name of the University nor of the Laboratory may be used |
49 | * to endorse or promote products derived from this software without |
50 | * specific prior written permission. |
51 | * |
52 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
53 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
55 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
58 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
62 | * SUCH DAMAGE. |
63 | * |
64 | * From: Header: audiovar.h,v 1.3 93/07/18 14:07:25 mccanne Exp (LBL) |
65 | */ |
66 | #ifndef _SYS_DEV_AUDIOVAR_H_ |
67 | #define _SYS_DEV_AUDIOVAR_H_ |
68 | |
69 | #include <sys/condvar.h> |
70 | |
71 | #include <dev/audio_if.h> |
72 | |
73 | /* |
74 | * Initial/default block duration is both configurable and patchable. |
75 | */ |
76 | #ifndef AUDIO_BLK_MS |
77 | #define AUDIO_BLK_MS 50 /* 50 ms */ |
78 | #endif |
79 | |
80 | #ifndef AU_RING_SIZE |
81 | #define AU_RING_SIZE 65536 |
82 | #endif |
83 | |
84 | #define AUMINBUF 512 |
85 | #define AUMINBLK 32 |
86 | #define AUMINNOBLK 3 |
87 | struct audio_ringbuffer { |
88 | audio_stream_t s; |
89 | int blksize; /* I/O block size (bytes) */ |
90 | int maxblks; /* no of blocks in ring */ |
91 | int usedlow; /* start writer when used falls below this */ |
92 | int usedhigh; /* stop writer when used goes above this */ |
93 | u_long stamp; /* bytes transferred */ |
94 | u_long stamp_last; /* old value of bytes transferred */ |
95 | u_long fstamp; /* bytes transferred from/to the buffer near to userland */ |
96 | u_long drops; /* missed samples from over/underrun */ |
97 | u_long pdrops; /* paused samples */ |
98 | bool pause; /* transfer is paused */ |
99 | bool copying; /* data is being copied */ |
100 | bool needfill; /* buffer needs filling when copying is done */ |
101 | bool mmapped; /* device is mmap()-ed */ |
102 | }; |
103 | |
104 | #define AUDIO_N_PORTS 4 |
105 | |
106 | struct au_mixer_ports { |
107 | int index; /* index of port-selector mixerctl */ |
108 | int master; /* index of master mixerctl */ |
109 | int nports; /* number of selectable ports */ |
110 | bool isenum; /* selector is enum type */ |
111 | u_int allports; /* all aumasks or'd */ |
112 | u_int aumask[AUDIO_N_PORTS]; /* exposed value of "ports" */ |
113 | u_int misel [AUDIO_N_PORTS]; /* ord of port, for selector */ |
114 | u_int miport[AUDIO_N_PORTS]; /* index of port's mixerctl */ |
115 | bool isdual; /* has working mixerout */ |
116 | int mixerout; /* ord of mixerout, for dual case */ |
117 | int cur_port; /* the port that gain actually controls when |
118 | mixerout is selected, for dual case */ |
119 | }; |
120 | |
121 | /* |
122 | * Software state, per audio device. |
123 | */ |
124 | struct audio_softc { |
125 | device_t dev; |
126 | void *hw_hdl; /* Hardware driver handle */ |
127 | const struct audio_hw_if *hw_if; /* Hardware interface */ |
128 | device_t sc_dev; /* Hardware device struct */ |
129 | u_char sc_open; /* single use device */ |
130 | #define AUOPEN_READ 0x01 |
131 | #define AUOPEN_WRITE 0x02 |
132 | u_char sc_mode; /* bitmask for RECORD/PLAY */ |
133 | |
134 | struct selinfo sc_wsel; /* write selector */ |
135 | struct selinfo sc_rsel; /* read selector */ |
136 | pid_t sc_async_audio; /* process who wants audio SIGIO */ |
137 | void *sc_sih_rd; |
138 | void *sc_sih_wr; |
139 | struct mixer_asyncs { |
140 | struct mixer_asyncs *next; |
141 | pid_t pid; |
142 | } *sc_async_mixer; /* processes who want mixer SIGIO */ |
143 | |
144 | /* Locks and sleep channels for reading, writing and draining. */ |
145 | kmutex_t *sc_intr_lock; |
146 | kmutex_t *sc_lock; |
147 | kcondvar_t sc_rchan; |
148 | kcondvar_t sc_wchan; |
149 | kcondvar_t sc_lchan; |
150 | int sc_dvlock; |
151 | bool sc_dying; |
152 | |
153 | bool sc_blkset; /* Blocksize has been set */ |
154 | |
155 | uint8_t *sc_sil_start; /* start of silence in buffer */ |
156 | int sc_sil_count; /* # of silence bytes */ |
157 | |
158 | bool sc_rbus; /* input DMA in progress */ |
159 | bool sc_pbus; /* output DMA in progress */ |
160 | |
161 | /** |
162 | * userland |
163 | * | write(2) & uiomove(9) |
164 | * sc_pstreams[0] <sc_pparams> == sc_pustream; |
165 | * | sc_pfilters[0] |
166 | * sc_pstreams[1] <list_t::filters[n-1].param> |
167 | * : |
168 | * sc_pstreams[n-1] <list_t::filters[1].param> |
169 | * | sc_pfilters[n-1] |
170 | * sc_pr <list_t::filters[0].param> |
171 | * | |
172 | * hardware |
173 | */ |
174 | audio_params_t sc_pparams; /* play encoding parameters */ |
175 | audio_stream_t *sc_pustream; /* the first buffer */ |
176 | int sc_npfilters; /* number of filters */ |
177 | audio_stream_t sc_pstreams[AUDIO_MAX_FILTERS]; |
178 | stream_filter_t *sc_pfilters[AUDIO_MAX_FILTERS]; |
179 | struct audio_ringbuffer sc_pr; /* Play ring */ |
180 | |
181 | /** |
182 | * hardware |
183 | * | |
184 | * sc_rr <list_t::filters[0].param> |
185 | * | sc_rfilters[0] |
186 | * sc_rstreams[0] <list_t::filters[1].param> |
187 | * | sc_rfilters[1] |
188 | * sc_rstreams[1] <list_t::filters[2].param> |
189 | * : |
190 | * | sc_rfilters[n-1] |
191 | * sc_rstreams[n-1] <sc_rparams> == sc_rustream |
192 | * | uiomove(9) & read(2) |
193 | * userland |
194 | */ |
195 | struct audio_ringbuffer sc_rr; /* Record ring */ |
196 | int sc_nrfilters; /* number of filters */ |
197 | stream_filter_t *sc_rfilters[AUDIO_MAX_FILTERS]; |
198 | audio_stream_t sc_rstreams[AUDIO_MAX_FILTERS]; |
199 | audio_stream_t *sc_rustream; /* the last buffer */ |
200 | audio_params_t sc_rparams; /* record encoding parameters */ |
201 | |
202 | int sc_eof; /* EOF, i.e. zero sized write, counter */ |
203 | u_long sc_wstamp; /* # of bytes read with read(2) */ |
204 | u_long sc_playdrop; |
205 | |
206 | int sc_full_duplex; /* device in full duplex mode */ |
207 | |
208 | struct au_mixer_ports sc_inports, sc_outports; |
209 | int sc_monitor_port; |
210 | |
211 | #ifdef AUDIO_INTR_TIME |
212 | u_long sc_pfirstintr; /* first time we saw a play interrupt */ |
213 | int sc_pnintr; /* number of interrupts */ |
214 | u_long sc_plastintr; /* last time we saw a play interrupt */ |
215 | long sc_pblktime; /* nominal time between interrupts */ |
216 | u_long sc_rfirstintr; /* first time we saw a rec interrupt */ |
217 | int sc_rnintr; /* number of interrupts */ |
218 | u_long sc_rlastintr; /* last time we saw a rec interrupt */ |
219 | long sc_rblktime; /* nominal time between interrupts */ |
220 | #endif |
221 | |
222 | u_int sc_lastgain; |
223 | struct audio_info sc_lastinfo; |
224 | bool sc_lastinfovalid; |
225 | |
226 | mixer_ctrl_t *sc_mixer_state; |
227 | int sc_nmixer_states; |
228 | }; |
229 | |
230 | #endif /* _SYS_DEV_AUDIOVAR_H_ */ |
231 | |