xref: /openbsd/lib/libsndio/amsg.h (revision a6445c1d)
1 /*	$OpenBSD: amsg.h,v 1.6 2012/11/23 06:40:26 ratchov Exp $	*/
2 /*
3  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #ifndef AMSG_H
18 #define AMSG_H
19 
20 #include <stdint.h>
21 
22 /*
23  * socket and option names
24  */
25 #define AUCAT_PATH		"aucat"
26 #define AUCAT_PORT		11025
27 #define DEFAULT_OPT		"default"
28 
29 /*
30  * WARNING: since the protocol may be simultaneously used by static
31  * binaries or by different versions of a shared library, we are not
32  * allowed to change the packet binary representation in a backward
33  * incompatible way.
34  *
35  * Especially, make sure the amsg_xxx structures are not larger
36  * than 32 bytes.
37  */
38 struct amsg {
39 #define AMSG_ACK	0	/* ack for START/STOP */
40 #define AMSG_GETPAR	1	/* get the current parameters */
41 #define AMSG_SETPAR	2	/* set the current parameters */
42 #define AMSG_START	3	/* request the server to start the stream */
43 #define AMSG_STOP	4	/* request the server to stop the stream */
44 #define AMSG_DATA	5	/* data block */
45 #define AMSG_FLOWCTL	6	/* feedback about buffer usage */
46 #define AMSG_MOVE	7	/* position changed */
47 #define AMSG_SETVOL	9	/* set volume */
48 #define AMSG_HELLO	10	/* say hello, check versions and so ... */
49 #define AMSG_BYE	11	/* ask server to drop connection */
50 #define AMSG_AUTH	12	/* send authentication cookie */
51 	uint32_t cmd;
52 	uint32_t __pad;
53 	union {
54 		struct amsg_par {
55 			uint8_t legacy_mode;	/* compat for old libs */
56 			uint8_t xrun;		/* one of above */
57 			uint8_t bps;		/* bytes per sample */
58 			uint8_t bits;		/* actually used bits */
59 			uint8_t msb;		/* 1 if MSB justified */
60 			uint8_t le;		/* 1 if little endian */
61 			uint8_t sig;		/* 1 if signed */
62 			uint8_t __pad1;
63 			uint16_t pchan;		/* play channels */
64 			uint16_t rchan;		/* record channels */
65 			uint32_t rate;		/* frames per second */
66 			uint32_t bufsz;		/* total buffered frames */
67 			uint32_t round;
68 			uint32_t appbufsz;	/* client side bufsz */
69 			uint32_t _reserved[1];	/* for future use */
70 		} par;
71 		struct amsg_data {
72 #define AMSG_DATAMAX	0x1000
73 			uint32_t size;
74 		} data;
75 		struct amsg_ts {
76 			int32_t delta;
77 		} ts;
78 		struct amsg_vol {
79 			uint32_t ctl;
80 		} vol;
81 		struct amsg_hello {
82 			uint16_t mode;		/* bitmap of MODE_XXX */
83 #define AMSG_VERSION	7
84 			uint8_t version;	/* protocol version */
85 			uint8_t devnum;		/* device number */
86 			uint32_t _reserved[1];	/* for future use */
87 #define AMSG_OPTMAX	12
88 			char opt[AMSG_OPTMAX];	/* profile name */
89 			char who[12];		/* hint for leases */
90 		} hello;
91 		struct amsg_auth {
92 #define AMSG_COOKIELEN	16
93 			uint8_t cookie[AMSG_COOKIELEN];
94 		} auth;
95 	} u;
96 };
97 
98 /*
99  * Initialize an amsg structure: fill all fields with 0xff, so the read
100  * can test which fields were set.
101  */
102 #define AMSG_INIT(m) do { memset((m), 0xff, sizeof(struct amsg)); } while (0)
103 
104 /*
105  * Since the structure is memset to 0xff, the MSB can be used to check
106  * if any field was set.
107  */
108 #define AMSG_ISSET(x) (((x) & (1 << (8 * sizeof(x) - 1))) == 0)
109 
110 #endif /* !defined(AMSG_H) */
111