virtual-sink: Fix a crash when moving the sink to a new master right after setup.
[pulseaudio-raopUDP/pulseaudio-raop-alac.git] / src / pulsecore / esound.h
blobabc2355f55a24ee7a330700f9829f7b590c8b76a
1 #ifndef fooesoundhfoo
2 #define fooesoundhfoo
4 /***
5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
25 /* Most of the following is blatantly stolen from esound. */
28 /* path and name of the default EsounD domain socket */
29 #define ESD_UNIX_SOCKET_DIR "/tmp/.esd"
30 #define ESD_UNIX_SOCKET_NAME "/tmp/.esd/socket"
32 /* length of the audio buffer size */
33 #define ESD_BUF_SIZE (4 * 1024)
34 /* maximum size we can write(). Otherwise we might overflow */
35 #define ESD_MAX_WRITE_SIZE (21 * 4096)
37 /* length of the authorization key, octets */
38 #define ESD_KEY_LEN (16)
40 /* default port for the EsounD server */
41 #define ESD_DEFAULT_PORT (16001)
43 /* default sample rate for the EsounD server */
44 #define ESD_DEFAULT_RATE (44100)
46 /* maximum length of a stream/sample name */
47 #define ESD_NAME_MAX (128)
49 /* a magic number to identify the relative endianness of a client */
50 #define ESD_ENDIAN_KEY ((uint32_t) (('E' << 24) + ('N' << 16) + ('D' << 8) + ('N')))
52 #define ESD_VOLUME_BASE (256)
55 /*************************************/
56 /* what can we do to/with the EsounD */
57 enum esd_proto {
58 ESD_PROTO_CONNECT, /* implied on inital client connection */
60 /* pseudo "security" functionality */
61 ESD_PROTO_LOCK, /* disable "foreign" client connections */
62 ESD_PROTO_UNLOCK, /* enable "foreign" client connections */
64 /* stream functionality: play, record, monitor */
65 ESD_PROTO_STREAM_PLAY, /* play all following data as a stream */
66 ESD_PROTO_STREAM_REC, /* record data from card as a stream */
67 ESD_PROTO_STREAM_MON, /* send mixed buffer output as a stream */
69 /* sample functionality: cache, free, play, loop, EOL, kill */
70 ESD_PROTO_SAMPLE_CACHE, /* cache a sample in the server */
71 ESD_PROTO_SAMPLE_FREE, /* release a sample in the server */
72 ESD_PROTO_SAMPLE_PLAY, /* play a cached sample */
73 ESD_PROTO_SAMPLE_LOOP, /* loop a cached sample, til eoloop */
74 ESD_PROTO_SAMPLE_STOP, /* stop a looping sample when done */
75 ESD_PROTO_SAMPLE_KILL, /* stop the looping sample immed. */
77 /* free and reclaim /dev/dsp functionality */
78 ESD_PROTO_STANDBY, /* release /dev/dsp and ignore all data */
79 ESD_PROTO_RESUME, /* reclaim /dev/dsp and play sounds again */
81 /* TODO: move these to a more logical place. NOTE: will break the protocol */
82 ESD_PROTO_SAMPLE_GETID, /* get the ID for an already-cached sample */
83 ESD_PROTO_STREAM_FILT, /* filter mixed buffer output as a stream */
85 /* esd remote management */
86 ESD_PROTO_SERVER_INFO, /* get server info (ver, sample rate, format) */
87 ESD_PROTO_ALL_INFO, /* get all info (server info, players, samples) */
88 ESD_PROTO_SUBSCRIBE, /* track new and removed players and samples */
89 ESD_PROTO_UNSUBSCRIBE, /* stop tracking updates */
91 /* esd remote control */
92 ESD_PROTO_STREAM_PAN, /* set stream panning */
93 ESD_PROTO_SAMPLE_PAN, /* set default sample panning */
95 /* esd status */
96 ESD_PROTO_STANDBY_MODE, /* see if server is in standby, autostandby, etc */
98 /* esd latency */
99 ESD_PROTO_LATENCY, /* retrieve latency between write()'s and output */
101 ESD_PROTO_MAX /* for bounds checking */
104 /******************/
105 /* The EsounD api */
107 /* the properties of a sound buffer are logically or'd */
109 /* bits of stream/sample data */
110 #define ESD_MASK_BITS ( 0x000F )
111 #define ESD_BITS8 ( 0x0000 )
112 #define ESD_BITS16 ( 0x0001 )
114 /* how many interleaved channels of data */
115 #define ESD_MASK_CHAN ( 0x00F0 )
116 #define ESD_MONO ( 0x0010 )
117 #define ESD_STEREO ( 0x0020 )
119 /* whether it's a stream or a sample */
120 #define ESD_MASK_MODE ( 0x0F00 )
121 #define ESD_STREAM ( 0x0000 )
122 #define ESD_SAMPLE ( 0x0100 )
123 #define ESD_ADPCM ( 0x0200 ) /* TODO: anyone up for this? =P */
125 /* the function of the stream/sample, and common functions */
126 #define ESD_MASK_FUNC ( 0xF000 )
127 #define ESD_PLAY ( 0x1000 )
128 /* functions for streams only */
129 #define ESD_MONITOR ( 0x0000 )
130 #define ESD_RECORD ( 0x2000 )
131 /* functions for samples only */
132 #define ESD_STOP ( 0x0000 )
133 #define ESD_LOOP ( 0x2000 )
135 typedef int esd_format_t;
136 typedef int esd_proto_t;
138 /*******************************************************************/
139 /* esdmgr.c - functions to implement a "sound manager" for esd */
141 /* structures to retrieve information about streams/samples from the server */
142 typedef struct esd_server_info {
144 int version; /* server version encoded as an int */
145 esd_format_t format; /* magic int with the format info */
146 int rate; /* sample rate */
148 } esd_server_info_t;
150 typedef struct esd_player_info {
152 struct esd_player_info *next; /* point to next entry in list */
153 esd_server_info_t *server; /* the server that contains this stream */
155 int source_id; /* either a stream fd or sample id */
156 char name[ ESD_NAME_MAX ]; /* name of stream for remote control */
157 int rate; /* sample rate */
158 int left_vol_scale; /* volume scaling */
159 int right_vol_scale;
161 esd_format_t format; /* magic int with the format info */
163 } esd_player_info_t;
165 typedef struct esd_sample_info {
167 struct esd_sample_info *next; /* point to next entry in list */
168 esd_server_info_t *server; /* the server that contains this sample */
170 int sample_id; /* either a stream fd or sample id */
171 char name[ ESD_NAME_MAX ]; /* name of stream for remote control */
172 int rate; /* sample rate */
173 int left_vol_scale; /* volume scaling */
174 int right_vol_scale;
176 esd_format_t format; /* magic int with the format info */
177 int length; /* total buffer length */
179 } esd_sample_info_t;
181 typedef struct esd_info {
183 esd_server_info_t *server;
184 esd_player_info_t *player_list;
185 esd_sample_info_t *sample_list;
187 } esd_info_t;
189 enum esd_standby_mode {
190 ESM_ERROR, ESM_ON_STANDBY, ESM_ON_AUTOSTANDBY, ESM_RUNNING
192 typedef int esd_standby_mode_t;
194 enum esd_client_state {
195 ESD_STREAMING_DATA, /* data from here on is streamed data */
196 ESD_CACHING_SAMPLE, /* midway through caching a sample */
197 ESD_NEEDS_REQDATA, /* more data needed to complere request */
198 ESD_NEXT_REQUEST, /* proceed to next request */
199 ESD_CLIENT_STATE_MAX /* place holder */
201 typedef int esd_client_state_t;
203 /* the endian key is transferred in binary, if it's read into int, */
204 /* and matches ESD_ENDIAN_KEY (ENDN), then the endianness of the */
205 /* server and the client match; if it's SWAP_ENDIAN_KEY, swap data */
206 #define ESD_SWAP_ENDIAN_KEY (PA_UINT32_SWAP(ESD_ENDIAN_KEY))
209 #endif