xref: /illumos-gate/usr/src/uts/common/io/audio/impl/audio_client.h (revision d65b419ea7828ceaecc8f2ed7188237add6b14dc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_AUDIO_CLIENT_H
28 #define	_AUDIO_CLIENT_H
29 
30 /*
31  * Structure implementation in audio_impl.h
32  */
33 #include <sys/audio/audio_common.h>
34 
35 typedef struct audio_client_ops {
36 	const char	*aco_minor_prefix;
37 	void		*(*aco_dev_init)(audio_dev_t *);
38 	void		(*aco_dev_fini)(void *);
39 	int		(*aco_open)(audio_client_t *, int);
40 	void		(*aco_close)(audio_client_t *);
41 	int		(*aco_read)(audio_client_t *, struct uio *, cred_t *);
42 	int		(*aco_write)(audio_client_t *, struct uio *, cred_t *);
43 	int		(*aco_ioctl)(audio_client_t *, int, intptr_t, int,
44 			    cred_t *, int *);
45 	int		(*aco_chpoll)(audio_client_t *, short, int, short *,
46 			    struct pollhead **);
47 	int		(*aco_mmap)(audio_client_t *, ...);
48 	void		(*aco_input)(audio_client_t *);
49 	void		(*aco_output)(audio_client_t *);
50 	void		(*aco_notify)(audio_client_t *);
51 	void		(*aco_drain)(audio_client_t *);
52 } audio_client_ops_t;
53 
54 void *auclnt_get_private(audio_client_t *);
55 void auclnt_set_private(audio_client_t *, void *);
56 
57 int auclnt_drain(audio_client_t *);
58 int auclnt_start_drain(audio_client_t *);
59 
60 int auclnt_set_rate(audio_stream_t *, int);
61 int auclnt_get_rate(audio_stream_t *);
62 
63 int auclnt_set_format(audio_stream_t *, int);
64 int auclnt_get_format(audio_stream_t *);
65 
66 int auclnt_set_channels(audio_stream_t *, int);
67 int auclnt_get_channels(audio_stream_t *);
68 
69 void auclnt_set_gain(audio_stream_t *, uint8_t);
70 uint8_t auclnt_get_gain(audio_stream_t *);
71 
72 void auclnt_set_muted(audio_stream_t *, boolean_t);
73 boolean_t auclnt_get_muted(audio_stream_t *);
74 
75 uint64_t auclnt_get_samples(audio_stream_t *);
76 void auclnt_set_samples(audio_stream_t *, uint64_t);
77 
78 uint64_t auclnt_get_errors(audio_stream_t *);
79 void auclnt_set_errors(audio_stream_t *, uint64_t);
80 
81 uint64_t auclnt_get_eof(audio_stream_t *);
82 void auclnt_set_eof(audio_stream_t *, uint64_t);
83 
84 void auclnt_start(audio_stream_t *);
85 void auclnt_stop(audio_stream_t *);
86 
87 void auclnt_set_paused(audio_stream_t *);
88 void auclnt_clear_paused(audio_stream_t *);
89 boolean_t auclnt_is_paused(audio_stream_t *);
90 
91 void auclnt_flush(audio_stream_t *);
92 
93 void auclnt_get_output_qlen(audio_client_t *, unsigned *, unsigned *);
94 
95 unsigned auclnt_get_fragsz(audio_stream_t *);
96 unsigned auclnt_get_framesz(audio_stream_t *);
97 unsigned auclnt_get_nfrags(audio_stream_t *);
98 unsigned auclnt_get_nframes(audio_stream_t *);
99 unsigned auclnt_get_count(audio_stream_t *);
100 uint64_t auclnt_get_head(audio_stream_t *);
101 uint64_t auclnt_get_tail(audio_stream_t *);
102 unsigned auclnt_get_hidx(audio_stream_t *);
103 unsigned auclnt_get_tidx(audio_stream_t *);
104 
105 void auclnt_set_latency(audio_stream_t *, unsigned, unsigned);
106 
107 audio_stream_t *auclnt_input_stream(audio_client_t *);
108 audio_stream_t *auclnt_output_stream(audio_client_t *);
109 
110 int auclnt_get_oflag(audio_client_t *);
111 
112 int auclnt_open(audio_client_t *, unsigned, int);
113 void auclnt_close(audio_client_t *);
114 
115 void auclnt_register_ops(minor_t, audio_client_ops_t *);
116 
117 minor_t	auclnt_get_minor(audio_client_t *);
118 minor_t auclnt_get_original_minor(audio_client_t *);
119 minor_t auclnt_get_minor_type(audio_client_t *);
120 
121 unsigned auclnt_produce(audio_stream_t *, unsigned);
122 unsigned auclnt_produce_data(audio_stream_t *, caddr_t, unsigned);
123 unsigned auclnt_consume(audio_stream_t *, unsigned);
124 unsigned auclnt_consume_data(audio_stream_t *, caddr_t, unsigned);
125 int auclnt_read(audio_client_t *, struct uio *);
126 int auclnt_write(audio_client_t *, struct uio *);
127 int auclnt_chpoll(audio_client_t *, short, int, short *, struct pollhead **);
128 void auclnt_pollwakeup(audio_client_t *, short);
129 
130 /*
131  * Return the process id that performed the original open() of the client.
132  */
133 pid_t auclnt_get_pid(audio_client_t *);
134 
135 /*
136  * Return the credentials of the process that opened the client.
137  */
138 cred_t *auclnt_get_cred(audio_client_t *);
139 
140 /*
141  * Get an opaque handle the underlying device for an audio client.
142  */
143 audio_dev_t *auclnt_get_dev(audio_client_t *);
144 audio_dev_t *auclnt_hold_dev_by_index(int);
145 void auclnt_release_dev(audio_dev_t *);
146 void auclnt_notify_dev(audio_dev_t *);
147 int auclnt_get_dev_index(audio_dev_t *);
148 int auclnt_get_dev_number(audio_dev_t *);
149 void auclnt_set_dev_number(audio_dev_t *, int);
150 const char *auclnt_get_dev_name(audio_dev_t *);
151 const char *auclnt_get_dev_driver(audio_dev_t *);
152 dev_info_t *auclnt_get_dev_devinfo(audio_dev_t *);
153 int auclnt_get_dev_instance(audio_dev_t *);
154 const char *auclnt_get_dev_description(audio_dev_t *);
155 const char *auclnt_get_dev_version(audio_dev_t *);
156 const char *auclnt_get_dev_hw_info(audio_dev_t *, void **);
157 unsigned auclnt_get_dev_capab(audio_dev_t *);
158 #define	AUDIO_CLIENT_CAP_PLAY		(1U << 0)
159 #define	AUDIO_CLIENT_CAP_RECORD		(1U << 1)
160 #define	AUDIO_CLIENT_CAP_DUPLEX		(1U << 2)
161 #define	AUDIO_CLIENT_CAP_SNDSTAT	(1U << 3)
162 
163 /*
164  * Walk all the open client structures for a named audio device.
165  * Clients can use this to find "peer" clients accessing the same
166  * audio device.  (This is useful for implementing special linkages,
167  * e.g. between /dev/audio and /dev/audioctl.)
168  */
169 void auclnt_dev_walk_clients(audio_dev_t *,
170     int (*)(audio_client_t *, void *), void *);
171 
172 /*
173  * Audio control functions for use by clients.
174  */
175 
176 /*
177  * This will walk all controls registered to my device and callback
178  * to walker for each one with its audio_ctrl_desc_t..
179  *
180  * Note that walk_func may return values to continue (AUDIO_WALK_CONTINUE)
181  * or stop walk (AUDIO_WALK_STOP).
182  *
183  */
184 void auclnt_walk_controls(audio_dev_t *,
185     int (*)(audio_ctrl_t *, void *), void *);
186 
187 /*
188  * This will search all controls attached to a clients
189  * audio device for a control with the desired name.
190  *
191  * On successful return a ctrl handle will be returned. On
192  * failure NULL is returned.
193  */
194 audio_ctrl_t *auclnt_find_control(audio_dev_t *, const char *);
195 
196 /*
197  * Given a known control, get its attributes.
198  *
199  * The caller must supply a audio_ctrl_desc_t structure.  Also the
200  * values in the structure are ignored when making the call and filled
201  * in by this function.
202  *
203  * If an error occurs then a non-zero is returned.
204  */
205 int auclnt_control_describe(audio_ctrl_t *, audio_ctrl_desc_t *);
206 
207 
208 /*
209  * This is used to read the current value of a control.
210  * Note, this will cause a callback into the driver to get the value.
211  *
212  * On return zero is returned on success else errno is returned.
213  */
214 int auclnt_control_read(audio_ctrl_t *, uint64_t *);
215 
216 /*
217  * This is used to write a value to a control.
218  * Note, this will cause a callback into the driver to write the value.
219  *
220  * On return zero is returned on success else errno is returned.
221  *
222  */
223 int auclnt_control_write(audio_ctrl_t *, uint64_t);
224 
225 /*
226  * Walk all the audio devices on the system.  Useful for clients
227  * like sndstat, which may need to inquire about every audio device
228  * on the system.
229  */
230 void auclnt_walk_devs(int (*walker)(audio_dev_t *, void *), void *);
231 void auclnt_walk_devs_by_number(int (*walker)(audio_dev_t *, void *), void *);
232 
233 audio_client_t *auclnt_hold_by_devt(dev_t);
234 void auclnt_release(audio_client_t *);
235 
236 /*
237  * Engine rlated accesses.  Note that normally clients don't need this level
238  * of information.
239  */
240 void auclnt_dev_walk_engines(audio_dev_t *,
241     int (*)(audio_engine_t *, void *), void *);
242 int auclnt_engine_get_format(audio_engine_t *);
243 int auclnt_engine_get_rate(audio_engine_t *);
244 int auclnt_engine_get_channels(audio_engine_t *);
245 unsigned auclnt_engine_get_capab(audio_engine_t *);
246 
247 /*
248  * Retrieve minor-specific data for the instance.  This allows for
249  * personality modules to store persistent state data on a physical
250  * device (e.g. to store persistent settings.)  Synchronization of
251  * stored settings between personality modules is up to the
252  * personality modules themselves.
253  */
254 void *auclnt_get_minor_data(audio_client_t *, minor_t);
255 void *auclnt_get_dev_minor_data(audio_dev_t *, minor_t);
256 
257 /*
258  * Simpler warning message, alternative to cmn_err.
259  */
260 void auclnt_warn(audio_client_t *, const char *fmt, ...);
261 
262 #endif	/* _AUDIO_CLIENT_H */
263