]> code.delx.au - pulseaudio/blob - src/esound-spec.h
esound protocol
[pulseaudio] / src / esound-spec.h
1 #ifndef fooesoundhfoo
2 #define fooesoundhfoo
3
4 /* Most of the following is blatantly stolen from esound. */
5
6
7 /* path and name of the default EsounD domain socket */
8 #define ESD_UNIX_SOCKET_DIR "/tmp/.esd"
9 #define ESD_UNIX_SOCKET_NAME "/tmp/.esd/socket"
10
11 /* length of the audio buffer size */
12 #define ESD_BUF_SIZE (4 * 1024)
13 /* maximum size we can write(). Otherwise we might overflow */
14 #define ESD_MAX_WRITE_SIZE (21 * 4096)
15
16 /* length of the authorization key, octets */
17 #define ESD_KEY_LEN (16)
18
19 /* default port for the EsounD server */
20 #define ESD_DEFAULT_PORT (16001)
21
22 /* default sample rate for the EsounD server */
23 #define ESD_DEFAULT_RATE (44100)
24
25 /* maximum length of a stream/sample name */
26 #define ESD_NAME_MAX (128)
27
28 /* a magic number to identify the relative endianness of a client */
29 #define ESD_ENDIAN_KEY ((uint32_t) (('E' << 24) + ('N' << 16) + ('D' << 8) + ('N')))
30
31 #define ESD_VOLUME_BASE (256)
32
33
34 /*************************************/
35 /* what can we do to/with the EsounD */
36 enum esd_proto {
37 ESD_PROTO_CONNECT, /* implied on inital client connection */
38
39 /* pseudo "security" functionality */
40 ESD_PROTO_LOCK, /* disable "foreign" client connections */
41 ESD_PROTO_UNLOCK, /* enable "foreign" client connections */
42
43 /* stream functionality: play, record, monitor */
44 ESD_PROTO_STREAM_PLAY, /* play all following data as a stream */
45 ESD_PROTO_STREAM_REC, /* record data from card as a stream */
46 ESD_PROTO_STREAM_MON, /* send mixed buffer output as a stream */
47
48 /* sample functionality: cache, free, play, loop, EOL, kill */
49 ESD_PROTO_SAMPLE_CACHE, /* cache a sample in the server */
50 ESD_PROTO_SAMPLE_FREE, /* release a sample in the server */
51 ESD_PROTO_SAMPLE_PLAY, /* play a cached sample */
52 ESD_PROTO_SAMPLE_LOOP, /* loop a cached sample, til eoloop */
53 ESD_PROTO_SAMPLE_STOP, /* stop a looping sample when done */
54 ESD_PROTO_SAMPLE_KILL, /* stop the looping sample immed. */
55
56 /* free and reclaim /dev/dsp functionality */
57 ESD_PROTO_STANDBY, /* release /dev/dsp and ignore all data */
58 ESD_PROTO_RESUME, /* reclaim /dev/dsp and play sounds again */
59
60 /* TODO: move these to a more logical place. NOTE: will break the protocol */
61 ESD_PROTO_SAMPLE_GETID, /* get the ID for an already-cached sample */
62 ESD_PROTO_STREAM_FILT, /* filter mixed buffer output as a stream */
63
64 /* esd remote management */
65 ESD_PROTO_SERVER_INFO, /* get server info (ver, sample rate, format) */
66 ESD_PROTO_ALL_INFO, /* get all info (server info, players, samples) */
67 ESD_PROTO_SUBSCRIBE, /* track new and removed players and samples */
68 ESD_PROTO_UNSUBSCRIBE, /* stop tracking updates */
69
70 /* esd remote control */
71 ESD_PROTO_STREAM_PAN, /* set stream panning */
72 ESD_PROTO_SAMPLE_PAN, /* set default sample panning */
73
74 /* esd status */
75 ESD_PROTO_STANDBY_MODE, /* see if server is in standby, autostandby, etc */
76
77 /* esd latency */
78 ESD_PROTO_LATENCY, /* retrieve latency between write()'s and output */
79
80 ESD_PROTO_MAX /* for bounds checking */
81 };
82
83 /******************/
84 /* The EsounD api */
85
86 /* the properties of a sound buffer are logically or'd */
87
88 /* bits of stream/sample data */
89 #define ESD_MASK_BITS ( 0x000F )
90 #define ESD_BITS8 ( 0x0000 )
91 #define ESD_BITS16 ( 0x0001 )
92
93 /* how many interleaved channels of data */
94 #define ESD_MASK_CHAN ( 0x00F0 )
95 #define ESD_MONO ( 0x0010 )
96 #define ESD_STEREO ( 0x0020 )
97
98 /* whether it's a stream or a sample */
99 #define ESD_MASK_MODE ( 0x0F00 )
100 #define ESD_STREAM ( 0x0000 )
101 #define ESD_SAMPLE ( 0x0100 )
102 #define ESD_ADPCM ( 0x0200 ) /* TODO: anyone up for this? =P */
103
104 /* the function of the stream/sample, and common functions */
105 #define ESD_MASK_FUNC ( 0xF000 )
106 #define ESD_PLAY ( 0x1000 )
107 /* functions for streams only */
108 #define ESD_MONITOR ( 0x0000 )
109 #define ESD_RECORD ( 0x2000 )
110 /* functions for samples only */
111 #define ESD_STOP ( 0x0000 )
112 #define ESD_LOOP ( 0x2000 )
113
114 typedef int esd_format_t;
115 typedef int esd_proto_t;
116
117 /*******************************************************************/
118 /* esdmgr.c - functions to implement a "sound manager" for esd */
119
120 /* structures to retrieve information about streams/samples from the server */
121 typedef struct esd_server_info {
122
123 int version; /* server version encoded as an int */
124 esd_format_t format; /* magic int with the format info */
125 int rate; /* sample rate */
126
127 } esd_server_info_t;
128
129 typedef struct esd_player_info {
130
131 struct esd_player_info *next; /* point to next entry in list */
132 esd_server_info_t *server; /* the server that contains this stream */
133
134 int source_id; /* either a stream fd or sample id */
135 char name[ ESD_NAME_MAX ]; /* name of stream for remote control */
136 int rate; /* sample rate */
137 int left_vol_scale; /* volume scaling */
138 int right_vol_scale;
139
140 esd_format_t format; /* magic int with the format info */
141
142 } esd_player_info_t;
143
144 typedef struct esd_sample_info {
145
146 struct esd_sample_info *next; /* point to next entry in list */
147 esd_server_info_t *server; /* the server that contains this sample */
148
149 int sample_id; /* either a stream fd or sample id */
150 char name[ ESD_NAME_MAX ]; /* name of stream for remote control */
151 int rate; /* sample rate */
152 int left_vol_scale; /* volume scaling */
153 int right_vol_scale;
154
155 esd_format_t format; /* magic int with the format info */
156 int length; /* total buffer length */
157
158 } esd_sample_info_t;
159
160 typedef struct esd_info {
161
162 esd_server_info_t *server;
163 esd_player_info_t *player_list;
164 esd_sample_info_t *sample_list;
165
166 } esd_info_t;
167
168 enum esd_standby_mode {
169 ESM_ERROR, ESM_ON_STANDBY, ESM_ON_AUTOSTANDBY, ESM_RUNNING
170 };
171 typedef int esd_standby_mode_t;
172
173 enum esd_client_state {
174 ESD_STREAMING_DATA, /* data from here on is streamed data */
175 ESD_CACHING_SAMPLE, /* midway through caching a sample */
176 ESD_NEEDS_REQDATA, /* more data needed to complere request */
177 ESD_NEXT_REQUEST, /* proceed to next request */
178 ESD_CLIENT_STATE_MAX /* place holder */
179 };
180 typedef int esd_client_state_t;
181
182 /* switch endian order for cross platform playing */
183 #define swap_endian_32(x) ((x >> 24) | ((x >> 8) & 0xFF00) | (((x & 0xFF00) << 8)) | (x << 24))
184
185 /* the endian key is transferred in binary, if it's read into int, */
186 /* and matches ESD_ENDIAN_KEY (ENDN), then the endianness of the */
187 /* server and the client match; if it's SWAP_ENDIAN_KEY, swap data */
188 #define ESD_SWAP_ENDIAN_KEY ((uint32_t) swap_endian_32(ESD_ENDIAN_KEY))
189
190
191 #endif