Annotation of src/usr.bin/aucat/amsg.h, Revision 1.9
1.9 ! ratchov 1: /* $OpenBSD: amsg.h,v 1.8 2009/07/25 08:44:27 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.1 ratchov 42: uint32_t cmd;
43: uint32_t __pad;
44: union {
45: struct amsg_par {
1.7 ratchov 46: uint8_t legacy_mode; /* compat for old libs */
1.1 ratchov 47: #define AMSG_IGNORE 0 /* loose sync */
48: #define AMSG_SYNC 1 /* resync after xrun */
49: #define AMSG_ERROR 2 /* kill the stream */
50: uint8_t xrun; /* one of above */
51: uint8_t bps; /* bytes per sample */
52: uint8_t bits; /* actually used bits */
53: uint8_t msb; /* 1 if MSB justified */
54: uint8_t le; /* 1 if little endian */
55: uint8_t sig; /* 1 if signed */
56: uint8_t __pad1;
57: uint16_t pchan; /* play channels */
58: uint16_t rchan; /* record channels */
59: uint32_t rate; /* frames per second */
1.3 ratchov 60: uint32_t bufsz; /* total buffered frames */
1.1 ratchov 61: uint32_t round;
1.3 ratchov 62: uint32_t appbufsz; /* client side bufsz */
63: uint32_t _reserved[1]; /* for future use */
1.1 ratchov 64: } par;
65: struct amsg_cap {
66: uint32_t rate; /* native rate */
1.3 ratchov 67: uint32_t _reserved2[1]; /* for future use */
1.1 ratchov 68: uint16_t rchan; /* native rec channels */
69: uint16_t pchan; /* native play channels */
70: uint8_t bits; /* native bits per sample */
71: uint8_t bps; /* native ytes per sample */
72: uint8_t _reserved[10]; /* for future use */
73: } cap;
74: struct amsg_data {
75: #define AMSG_DATAMAX 0x1000
76: uint32_t size;
77: } data;
78: struct amsg_ts {
79: int32_t delta;
80: } ts;
1.2 ratchov 81: struct amsg_vol {
82: uint32_t ctl;
83: } vol;
1.6 ratchov 84: struct amsg_hello {
85: #define AMSG_PLAY 0x1 /* audio playback */
86: #define AMSG_REC 0x2 /* audio recording */
87: #define AMSG_MIDIIN 0x4 /* MIDI thru input */
88: #define AMSG_MIDIOUT 0x8 /* MIDI thru output */
89: #define AMSG_MIXER 0x10 /* MIDI mixer */
90: uint16_t proto; /* protocol type */
1.8 ratchov 91: uint8_t reserved1[6]; /* for future use */
92: char opt[12]; /* profile name */
1.6 ratchov 93: char who[12]; /* hint for leases */
94: } hello;
1.1 ratchov 95: } u;
96: };
97:
98: /*
1.9 ! ratchov 99: * Initialize an amsg structure: fill all fields with 0xff, so the read
! 100: * can test which fields were set.
1.1 ratchov 101: */
102: #define AMSG_INIT(m) do { memset((m), 0xff, sizeof(struct amsg)); } while (0)
103:
104: /*
1.9 ! ratchov 105: * Since the structure is memset to 0xff, the MSB can be used to check
! 106: * if any field was set.
1.1 ratchov 107: */
108: #define AMSG_ISSET(x) (((x) & (1 << (8 * sizeof(x) - 1))) == 0)
109:
1.5 ratchov 110: #endif /* !defined(AMSG_H) */