Git init
[framework/multimedia/pulseaudio.git] / src / pulsecore / esound.h
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, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 /* Most of the following is blatantly stolen from esound. */
26
27
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"
31
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)
36
37 /* length of the authorization key, octets */
38 #define ESD_KEY_LEN (16)
39
40 /* default port for the EsounD server */
41 #define ESD_DEFAULT_PORT (16001)
42
43 /* default sample rate for the EsounD server */
44 #define ESD_DEFAULT_RATE (44100)
45
46 /* maximum length of a stream/sample name */
47 #define ESD_NAME_MAX (128)
48
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')))
51
52 #define ESD_VOLUME_BASE (256)
53
54
55 /*************************************/
56 /* what can we do to/with the EsounD */
57 enum esd_proto {
58     ESD_PROTO_CONNECT,      /* implied on inital client connection */
59
60     /* pseudo "security" functionality */
61     ESD_PROTO_LOCK,         /* disable "foreign" client connections */
62     ESD_PROTO_UNLOCK,       /* enable "foreign" client connections */
63
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 */
68
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. */
76
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 */
80
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 */
84
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 */
90
91     /* esd remote control */
92     ESD_PROTO_STREAM_PAN,   /* set stream panning */
93     ESD_PROTO_SAMPLE_PAN,   /* set default sample panning */
94
95     /* esd status */
96     ESD_PROTO_STANDBY_MODE, /* see if server is in standby, autostandby, etc */
97
98     /* esd latency */
99     ESD_PROTO_LATENCY,      /* retrieve latency between write()'s and output */
100
101     ESD_PROTO_MAX           /* for bounds checking */
102 };
103
104 /******************/
105 /* The EsounD api */
106
107 /* the properties of a sound buffer are logically or'd */
108
109 /* bits of stream/sample data */
110 #define ESD_MASK_BITS   ( 0x000F )
111 #define ESD_BITS8       ( 0x0000 )
112 #define ESD_BITS16      ( 0x0001 )
113
114 /* how many interleaved channels of data */
115 #define ESD_MASK_CHAN   ( 0x00F0 )
116 #define ESD_MONO        ( 0x0010 )
117 #define ESD_STEREO      ( 0x0020 )
118
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 */
124
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 )
134
135 typedef int esd_format_t;
136 typedef int esd_proto_t;
137
138 /*******************************************************************/
139 /* esdmgr.c - functions to implement a "sound manager" for esd */
140
141 /* structures to retrieve information about streams/samples from the server */
142 typedef struct esd_server_info {
143
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 */
147
148 } esd_server_info_t;
149
150 typedef struct esd_player_info {
151
152     struct esd_player_info *next; /* point to next entry in list */
153     esd_server_info_t *server;  /* the server that contains this stream */
154
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;
160
161     esd_format_t format;        /* magic int with the format info */
162
163 } esd_player_info_t;
164
165 typedef struct esd_sample_info {
166
167     struct esd_sample_info *next; /* point to next entry in list */
168     esd_server_info_t *server;  /* the server that contains this sample */
169
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;
175
176     esd_format_t format;        /* magic int with the format info */
177     int length;                 /* total buffer length */
178
179 } esd_sample_info_t;
180
181 typedef struct esd_info {
182
183     esd_server_info_t *server;
184     esd_player_info_t *player_list;
185     esd_sample_info_t *sample_list;
186
187 } esd_info_t;
188
189 enum esd_standby_mode {
190     ESM_ERROR, ESM_ON_STANDBY, ESM_ON_AUTOSTANDBY, ESM_RUNNING
191 };
192 typedef int esd_standby_mode_t;
193
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 */
200 };
201 typedef int esd_client_state_t;
202
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))
207
208
209 #endif