Annotation of src/usr.bin/aucat/amsg.h, Revision 1.14
1.13 ratchov 1: /* $OpenBSD: amsg.h,v 1.12 2009/10/22 21:41:30 ratchov Exp $ */
1.1 ratchov 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: */
1.5 ratchov 17: #ifndef AMSG_H
18: #define AMSG_H
1.1 ratchov 19:
20: #include <stdint.h>
21:
22: /*
23: * WARNING: since the protocol may be simultaneously used by static
24: * binaries or by different versions of a shared library, we are not
25: * allowed to change the packet binary representation in a backward
26: * incompatible way.
1.6 ratchov 27: *
28: * Especially, make sure the amsg_xxx structures are not larger
29: * than 32 bytes.
1.1 ratchov 30: */
31: struct amsg {
32: #define AMSG_ACK 0 /* ack for START/STOP */
33: #define AMSG_GETPAR 1 /* get the current parameters */
34: #define AMSG_SETPAR 2 /* set the current parameters */
35: #define AMSG_START 3 /* request the server to start the stream */
1.4 ratchov 36: #define AMSG_STOP 4 /* request the server to stop the stream */
1.1 ratchov 37: #define AMSG_DATA 5 /* data block */
38: #define AMSG_MOVE 6 /* position changed */
39: #define AMSG_GETCAP 7 /* get capabilities */
1.2 ratchov 40: #define AMSG_SETVOL 8 /* set volume */
1.6 ratchov 41: #define AMSG_HELLO 9 /* say hello, check versions and so ... */
1.10 ratchov 42: #define AMSG_BYE 10 /* ask server to drop connection */
1.1 ratchov 43: uint32_t cmd;
44: uint32_t __pad;
45: union {
46: struct amsg_par {
1.7 ratchov 47: uint8_t legacy_mode; /* compat for old libs */
1.1 ratchov 48: #define AMSG_IGNORE 0 /* loose sync */
49: #define AMSG_SYNC 1 /* resync after xrun */
50: #define AMSG_ERROR 2 /* kill the stream */
51: uint8_t xrun; /* one of above */
52: uint8_t bps; /* bytes per sample */
53: uint8_t bits; /* actually used bits */
54: uint8_t msb; /* 1 if MSB justified */
55: uint8_t le; /* 1 if little endian */
56: uint8_t sig; /* 1 if signed */
57: uint8_t __pad1;
58: uint16_t pchan; /* play channels */
59: uint16_t rchan; /* record channels */
60: uint32_t rate; /* frames per second */
1.3 ratchov 61: uint32_t bufsz; /* total buffered frames */
1.1 ratchov 62: uint32_t round;
1.3 ratchov 63: uint32_t appbufsz; /* client side bufsz */
64: uint32_t _reserved[1]; /* for future use */
1.1 ratchov 65: } par;
66: struct amsg_cap {
67: uint32_t rate; /* native rate */
1.3 ratchov 68: uint32_t _reserved2[1]; /* for future use */
1.1 ratchov 69: uint16_t rchan; /* native rec channels */
70: uint16_t pchan; /* native play channels */
71: uint8_t bits; /* native bits per sample */
72: uint8_t bps; /* native ytes per sample */
73: uint8_t _reserved[10]; /* for future use */
74: } cap;
75: struct amsg_data {
76: #define AMSG_DATAMAX 0x1000
77: uint32_t size;
78: } data;
79: struct amsg_ts {
80: int32_t delta;
81: } ts;
1.2 ratchov 82: struct amsg_vol {
83: uint32_t ctl;
84: } vol;
1.6 ratchov 85: struct amsg_hello {
86: #define AMSG_PLAY 0x1 /* audio playback */
87: #define AMSG_REC 0x2 /* audio recording */
88: #define AMSG_MIDIIN 0x4 /* MIDI thru input */
89: #define AMSG_MIDIOUT 0x8 /* MIDI thru output */
1.14 ! ratchov 90: #define AMSG_MIXER 0x10 /* MIDI mixer */
1.6 ratchov 91: uint16_t proto; /* protocol type */
1.12 ratchov 92: #define AMSG_VERSION 1
1.11 ratchov 93: uint8_t version; /* protocol version */
94: uint8_t reserved1[5]; /* for future use */
1.8 ratchov 95: char opt[12]; /* profile name */
1.6 ratchov 96: char who[12]; /* hint for leases */
97: } hello;
1.1 ratchov 98: } u;
99: };
100:
101: /*
1.9 ratchov 102: * Initialize an amsg structure: fill all fields with 0xff, so the read
103: * can test which fields were set.
1.1 ratchov 104: */
105: #define AMSG_INIT(m) do { memset((m), 0xff, sizeof(struct amsg)); } while (0)
106:
107: /*
1.9 ratchov 108: * Since the structure is memset to 0xff, the MSB can be used to check
109: * if any field was set.
1.1 ratchov 110: */
111: #define AMSG_ISSET(x) (((x) & (1 << (8 * sizeof(x) - 1))) == 0)
112:
1.5 ratchov 113: #endif /* !defined(AMSG_H) */