xref: /openbsd-src/lib/libsndio/sio_priv.h (revision d20001a803bf8b9a154852114830dee9c70d1206)
1*d20001a8Sjsg /*	$OpenBSD: sio_priv.h,v 1.12 2024/05/21 06:07:06 jsg Exp $	*/
2b041ccb2Sratchov /*
3b041ccb2Sratchov  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
4b041ccb2Sratchov  *
5b041ccb2Sratchov  * Permission to use, copy, modify, and distribute this software for any
6b041ccb2Sratchov  * purpose with or without fee is hereby granted, provided that the above
7b041ccb2Sratchov  * copyright notice and this permission notice appear in all copies.
8b041ccb2Sratchov  *
9b041ccb2Sratchov  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10b041ccb2Sratchov  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11b041ccb2Sratchov  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12b041ccb2Sratchov  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13b041ccb2Sratchov  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14b041ccb2Sratchov  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15b041ccb2Sratchov  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16b041ccb2Sratchov  */
17b041ccb2Sratchov #ifndef SNDIO_PRIV_H
18b041ccb2Sratchov #define SNDIO_PRIV_H
19b041ccb2Sratchov 
20b041ccb2Sratchov #include "sndio.h"
21b041ccb2Sratchov 
22334268a5Sratchov #define SIO_MAXNFDS	16
2320fb3e8cSratchov 
24b041ccb2Sratchov /*
25b041ccb2Sratchov  * private ``handle'' structure
26b041ccb2Sratchov  */
27b041ccb2Sratchov struct sio_hdl {
28b041ccb2Sratchov 	struct sio_ops *ops;
29b041ccb2Sratchov 	void (*move_cb)(void *, int);	/* call-back for realpos changes */
30b041ccb2Sratchov 	void *move_addr;		/* user priv. data for move_cb */
31b041ccb2Sratchov 	void (*vol_cb)(void *, unsigned); /* call-back for volume changes */
32b041ccb2Sratchov 	void *vol_addr;			/* user priv. data for vol_cb */
33b041ccb2Sratchov 	unsigned mode;			/* SIO_PLAY | SIO_REC */
34b041ccb2Sratchov 	int started;			/* true if started */
35b041ccb2Sratchov 	int nbio;			/* true if non-blocking io */
362c53affbSjmc 	int eof;			/* true if error occurred */
37ea382012Sratchov 	int rdrop;			/* recorded bytes to drop */
38ea382012Sratchov 	int wsil;			/* silence to play */
39e6877796Sratchov 	int rused;			/* bytes used in read buffer */
40e6877796Sratchov 	int wused;			/* bytes used in write buffer */
41e6877796Sratchov 	long long cpos;			/* clock since start */
42e6877796Sratchov 	struct sio_par par;
43b041ccb2Sratchov #ifdef DEBUG
44b041ccb2Sratchov 	unsigned long long pollcnt;	/* times sio_revents was called */
45ea382012Sratchov 	long long start_nsec;
46b041ccb2Sratchov #endif
47b041ccb2Sratchov };
48b041ccb2Sratchov 
49b041ccb2Sratchov /*
50b041ccb2Sratchov  * operations every device should support
51b041ccb2Sratchov  */
52b041ccb2Sratchov struct sio_ops {
53b041ccb2Sratchov 	void (*close)(struct sio_hdl *);
54b041ccb2Sratchov 	int (*setpar)(struct sio_hdl *, struct sio_par *);
55b041ccb2Sratchov 	int (*getpar)(struct sio_hdl *, struct sio_par *);
56b041ccb2Sratchov 	int (*getcap)(struct sio_hdl *, struct sio_cap *);
57b041ccb2Sratchov 	size_t (*write)(struct sio_hdl *, const void *, size_t);
58b041ccb2Sratchov 	size_t (*read)(struct sio_hdl *, void *, size_t);
59b041ccb2Sratchov 	int (*start)(struct sio_hdl *);
60b041ccb2Sratchov 	int (*stop)(struct sio_hdl *);
61ec8a3410Sratchov 	int (*flush)(struct sio_hdl *);
62b041ccb2Sratchov 	int (*nfds)(struct sio_hdl *);
63b041ccb2Sratchov 	int (*pollfd)(struct sio_hdl *, struct pollfd *, int);
64b041ccb2Sratchov 	int (*revents)(struct sio_hdl *, struct pollfd *);
65b041ccb2Sratchov 	int (*setvol)(struct sio_hdl *, unsigned);
66b041ccb2Sratchov 	void (*getvol)(struct sio_hdl *);
67b041ccb2Sratchov };
68b041ccb2Sratchov 
69d418f94bSratchov struct sio_hdl *_sio_aucat_open(const char *, unsigned, int);
70d418f94bSratchov struct sio_hdl *_sio_sun_open(const char *, unsigned, int);
71d418f94bSratchov void _sio_create(struct sio_hdl *, struct sio_ops *, unsigned, int);
72d418f94bSratchov void _sio_onmove_cb(struct sio_hdl *, int);
73d418f94bSratchov void _sio_onvol_cb(struct sio_hdl *, unsigned);
74ea382012Sratchov #ifdef DEBUG
75d418f94bSratchov void _sio_printpos(struct sio_hdl *);
76ea382012Sratchov #endif
77b041ccb2Sratchov 
78b041ccb2Sratchov #endif /* !defined(SNDIO_PRIV_H) */
79