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