153a5a1b3Sopenharmony_ci#ifndef fooesoundhfoo
253a5a1b3Sopenharmony_ci#define fooesoundhfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2004-2006 Lennart Poettering
853a5a1b3Sopenharmony_ci
953a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1053a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as published
1153a5a1b3Sopenharmony_ci  by the Free Software Foundation; either version 2.1 of the License,
1253a5a1b3Sopenharmony_ci  or (at your option) any later version.
1353a5a1b3Sopenharmony_ci
1453a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1553a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1653a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1753a5a1b3Sopenharmony_ci  General Public License for more details.
1853a5a1b3Sopenharmony_ci
1953a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public License
2053a5a1b3Sopenharmony_ci  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2153a5a1b3Sopenharmony_ci***/
2253a5a1b3Sopenharmony_ci
2353a5a1b3Sopenharmony_ci/* Most of the following is blatantly stolen from esound. */
2453a5a1b3Sopenharmony_ci
2553a5a1b3Sopenharmony_ci/* path and name of the default EsounD domain socket */
2653a5a1b3Sopenharmony_ci#define ESD_UNIX_SOCKET_DIR     "/tmp/.esd"
2753a5a1b3Sopenharmony_ci#define ESD_UNIX_SOCKET_NAME    "/tmp/.esd/socket"
2853a5a1b3Sopenharmony_ci
2953a5a1b3Sopenharmony_ci/* length of the audio buffer size */
3053a5a1b3Sopenharmony_ci#define ESD_BUF_SIZE (4 * 1024)
3153a5a1b3Sopenharmony_ci/* maximum size we can write().  Otherwise we might overflow */
3253a5a1b3Sopenharmony_ci#define ESD_MAX_WRITE_SIZE (21 * 4096)
3353a5a1b3Sopenharmony_ci
3453a5a1b3Sopenharmony_ci/* length of the authentication key, octets */
3553a5a1b3Sopenharmony_ci#define ESD_KEY_LEN (16)
3653a5a1b3Sopenharmony_ci
3753a5a1b3Sopenharmony_ci/* default port for the EsounD server */
3853a5a1b3Sopenharmony_ci#define ESD_DEFAULT_PORT (16001)
3953a5a1b3Sopenharmony_ci
4053a5a1b3Sopenharmony_ci/* default sample rate for the EsounD server */
4153a5a1b3Sopenharmony_ci#define ESD_DEFAULT_RATE (44100)
4253a5a1b3Sopenharmony_ci
4353a5a1b3Sopenharmony_ci/* maximum length of a stream/sample name */
4453a5a1b3Sopenharmony_ci#define ESD_NAME_MAX (128)
4553a5a1b3Sopenharmony_ci
4653a5a1b3Sopenharmony_ci/* a magic number to identify the relative endianness of a client */
4753a5a1b3Sopenharmony_ci#define ESD_ENDIAN_KEY ((uint32_t) (('E' << 24) + ('N' << 16) + ('D' << 8) + ('N')))
4853a5a1b3Sopenharmony_ci
4953a5a1b3Sopenharmony_ci#define ESD_VOLUME_BASE (256)
5053a5a1b3Sopenharmony_ci
5153a5a1b3Sopenharmony_ci/*************************************/
5253a5a1b3Sopenharmony_ci/* what can we do to/with the EsounD */
5353a5a1b3Sopenharmony_cienum esd_proto {
5453a5a1b3Sopenharmony_ci    ESD_PROTO_CONNECT,      /* implied on initial client connection */
5553a5a1b3Sopenharmony_ci
5653a5a1b3Sopenharmony_ci    /* pseudo "security" functionality */
5753a5a1b3Sopenharmony_ci    ESD_PROTO_LOCK,         /* disable "foreign" client connections */
5853a5a1b3Sopenharmony_ci    ESD_PROTO_UNLOCK,       /* enable "foreign" client connections */
5953a5a1b3Sopenharmony_ci
6053a5a1b3Sopenharmony_ci    /* stream functionality: play, record, monitor */
6153a5a1b3Sopenharmony_ci    ESD_PROTO_STREAM_PLAY,  /* play all following data as a stream */
6253a5a1b3Sopenharmony_ci    ESD_PROTO_STREAM_REC,   /* record data from card as a stream */
6353a5a1b3Sopenharmony_ci    ESD_PROTO_STREAM_MON,   /* send mixed buffer output as a stream */
6453a5a1b3Sopenharmony_ci
6553a5a1b3Sopenharmony_ci    /* sample functionality: cache, free, play, loop, EOL, kill */
6653a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_CACHE, /* cache a sample in the server */
6753a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_FREE,  /* release a sample in the server */
6853a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_PLAY,  /* play a cached sample */
6953a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_LOOP,  /* loop a cached sample, til eoloop */
7053a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_STOP,  /* stop a looping sample when done */
7153a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_KILL,  /* stop the looping sample immediately */
7253a5a1b3Sopenharmony_ci
7353a5a1b3Sopenharmony_ci    /* free and reclaim /dev/dsp functionality */
7453a5a1b3Sopenharmony_ci    ESD_PROTO_STANDBY,      /* release /dev/dsp and ignore all data */
7553a5a1b3Sopenharmony_ci    ESD_PROTO_RESUME,       /* reclaim /dev/dsp and play sounds again */
7653a5a1b3Sopenharmony_ci
7753a5a1b3Sopenharmony_ci    /* TODO: move these to a more logical place. NOTE: will break the protocol */
7853a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_GETID, /* get the ID for an already-cached sample */
7953a5a1b3Sopenharmony_ci    ESD_PROTO_STREAM_FILT,  /* filter mixed buffer output as a stream */
8053a5a1b3Sopenharmony_ci
8153a5a1b3Sopenharmony_ci    /* esd remote management */
8253a5a1b3Sopenharmony_ci    ESD_PROTO_SERVER_INFO,  /* get server info (ver, sample rate, format) */
8353a5a1b3Sopenharmony_ci    ESD_PROTO_ALL_INFO,     /* get all info (server info, players, samples) */
8453a5a1b3Sopenharmony_ci    ESD_PROTO_SUBSCRIBE,    /* track new and removed players and samples */
8553a5a1b3Sopenharmony_ci    ESD_PROTO_UNSUBSCRIBE,  /* stop tracking updates */
8653a5a1b3Sopenharmony_ci
8753a5a1b3Sopenharmony_ci    /* esd remote control */
8853a5a1b3Sopenharmony_ci    ESD_PROTO_STREAM_PAN,   /* set stream panning */
8953a5a1b3Sopenharmony_ci    ESD_PROTO_SAMPLE_PAN,   /* set default sample panning */
9053a5a1b3Sopenharmony_ci
9153a5a1b3Sopenharmony_ci    /* esd status */
9253a5a1b3Sopenharmony_ci    ESD_PROTO_STANDBY_MODE, /* see if server is in standby, autostandby, etc */
9353a5a1b3Sopenharmony_ci
9453a5a1b3Sopenharmony_ci    /* esd latency */
9553a5a1b3Sopenharmony_ci    ESD_PROTO_LATENCY,      /* retrieve latency between write()'s and output */
9653a5a1b3Sopenharmony_ci
9753a5a1b3Sopenharmony_ci    ESD_PROTO_MAX           /* for bounds checking */
9853a5a1b3Sopenharmony_ci};
9953a5a1b3Sopenharmony_ci
10053a5a1b3Sopenharmony_ci/******************/
10153a5a1b3Sopenharmony_ci/* The EsounD api */
10253a5a1b3Sopenharmony_ci
10353a5a1b3Sopenharmony_ci/* the properties of a sound buffer are logically or'd */
10453a5a1b3Sopenharmony_ci
10553a5a1b3Sopenharmony_ci/* bits of stream/sample data */
10653a5a1b3Sopenharmony_ci#define ESD_MASK_BITS   ( 0x000F )
10753a5a1b3Sopenharmony_ci#define ESD_BITS8       ( 0x0000 )
10853a5a1b3Sopenharmony_ci#define ESD_BITS16      ( 0x0001 )
10953a5a1b3Sopenharmony_ci
11053a5a1b3Sopenharmony_ci/* how many interleaved channels of data */
11153a5a1b3Sopenharmony_ci#define ESD_MASK_CHAN   ( 0x00F0 )
11253a5a1b3Sopenharmony_ci#define ESD_MONO        ( 0x0010 )
11353a5a1b3Sopenharmony_ci#define ESD_STEREO      ( 0x0020 )
11453a5a1b3Sopenharmony_ci
11553a5a1b3Sopenharmony_ci/* whether it's a stream or a sample */
11653a5a1b3Sopenharmony_ci#define ESD_MASK_MODE   ( 0x0F00 )
11753a5a1b3Sopenharmony_ci#define ESD_STREAM      ( 0x0000 )
11853a5a1b3Sopenharmony_ci#define ESD_SAMPLE      ( 0x0100 )
11953a5a1b3Sopenharmony_ci#define ESD_ADPCM       ( 0x0200 )      /* TODO: anyone up for this? =P */
12053a5a1b3Sopenharmony_ci
12153a5a1b3Sopenharmony_ci/* the function of the stream/sample, and common functions */
12253a5a1b3Sopenharmony_ci#define ESD_MASK_FUNC   ( 0xF000 )
12353a5a1b3Sopenharmony_ci#define ESD_PLAY        ( 0x1000 )
12453a5a1b3Sopenharmony_ci/* functions for streams only */
12553a5a1b3Sopenharmony_ci#define ESD_MONITOR     ( 0x0000 )
12653a5a1b3Sopenharmony_ci#define ESD_RECORD      ( 0x2000 )
12753a5a1b3Sopenharmony_ci/* functions for samples only */
12853a5a1b3Sopenharmony_ci#define ESD_STOP        ( 0x0000 )
12953a5a1b3Sopenharmony_ci#define ESD_LOOP        ( 0x2000 )
13053a5a1b3Sopenharmony_ci
13153a5a1b3Sopenharmony_citypedef int esd_format_t;
13253a5a1b3Sopenharmony_citypedef int esd_proto_t;
13353a5a1b3Sopenharmony_ci
13453a5a1b3Sopenharmony_ci/*******************************************************************/
13553a5a1b3Sopenharmony_ci/* esdmgr.c - functions to implement a "sound manager" for esd */
13653a5a1b3Sopenharmony_ci
13753a5a1b3Sopenharmony_ci/* structures to retrieve information about streams/samples from the server */
13853a5a1b3Sopenharmony_citypedef struct esd_server_info {
13953a5a1b3Sopenharmony_ci
14053a5a1b3Sopenharmony_ci    int version;                /* server version encoded as an int */
14153a5a1b3Sopenharmony_ci    esd_format_t format;        /* magic int with the format info */
14253a5a1b3Sopenharmony_ci    int rate;                   /* sample rate */
14353a5a1b3Sopenharmony_ci
14453a5a1b3Sopenharmony_ci} esd_server_info_t;
14553a5a1b3Sopenharmony_ci
14653a5a1b3Sopenharmony_citypedef struct esd_player_info {
14753a5a1b3Sopenharmony_ci
14853a5a1b3Sopenharmony_ci    struct esd_player_info *next; /* point to next entry in list */
14953a5a1b3Sopenharmony_ci    esd_server_info_t *server;  /* the server that contains this stream */
15053a5a1b3Sopenharmony_ci
15153a5a1b3Sopenharmony_ci    int source_id;              /* either a stream fd or sample id */
15253a5a1b3Sopenharmony_ci    char name[ ESD_NAME_MAX ];  /* name of stream for remote control */
15353a5a1b3Sopenharmony_ci    int rate;                   /* sample rate */
15453a5a1b3Sopenharmony_ci    int left_vol_scale;         /* volume scaling */
15553a5a1b3Sopenharmony_ci    int right_vol_scale;
15653a5a1b3Sopenharmony_ci
15753a5a1b3Sopenharmony_ci    esd_format_t format;        /* magic int with the format info */
15853a5a1b3Sopenharmony_ci
15953a5a1b3Sopenharmony_ci} esd_player_info_t;
16053a5a1b3Sopenharmony_ci
16153a5a1b3Sopenharmony_citypedef struct esd_sample_info {
16253a5a1b3Sopenharmony_ci
16353a5a1b3Sopenharmony_ci    struct esd_sample_info *next; /* point to next entry in list */
16453a5a1b3Sopenharmony_ci    esd_server_info_t *server;  /* the server that contains this sample */
16553a5a1b3Sopenharmony_ci
16653a5a1b3Sopenharmony_ci    int sample_id;              /* either a stream fd or sample id */
16753a5a1b3Sopenharmony_ci    char name[ ESD_NAME_MAX ];  /* name of stream for remote control */
16853a5a1b3Sopenharmony_ci    int rate;                   /* sample rate */
16953a5a1b3Sopenharmony_ci    int left_vol_scale;         /* volume scaling */
17053a5a1b3Sopenharmony_ci    int right_vol_scale;
17153a5a1b3Sopenharmony_ci
17253a5a1b3Sopenharmony_ci    esd_format_t format;        /* magic int with the format info */
17353a5a1b3Sopenharmony_ci    int length;                 /* total buffer length */
17453a5a1b3Sopenharmony_ci
17553a5a1b3Sopenharmony_ci} esd_sample_info_t;
17653a5a1b3Sopenharmony_ci
17753a5a1b3Sopenharmony_citypedef struct esd_info {
17853a5a1b3Sopenharmony_ci
17953a5a1b3Sopenharmony_ci    esd_server_info_t *server;
18053a5a1b3Sopenharmony_ci    esd_player_info_t *player_list;
18153a5a1b3Sopenharmony_ci    esd_sample_info_t *sample_list;
18253a5a1b3Sopenharmony_ci
18353a5a1b3Sopenharmony_ci} esd_info_t;
18453a5a1b3Sopenharmony_ci
18553a5a1b3Sopenharmony_cienum esd_standby_mode {
18653a5a1b3Sopenharmony_ci    ESM_ERROR, ESM_ON_STANDBY, ESM_ON_AUTOSTANDBY, ESM_RUNNING
18753a5a1b3Sopenharmony_ci};
18853a5a1b3Sopenharmony_citypedef int esd_standby_mode_t;
18953a5a1b3Sopenharmony_ci
19053a5a1b3Sopenharmony_cienum esd_client_state {
19153a5a1b3Sopenharmony_ci    ESD_STREAMING_DATA,         /* data from here on is streamed data */
19253a5a1b3Sopenharmony_ci    ESD_CACHING_SAMPLE,         /* midway through caching a sample */
19353a5a1b3Sopenharmony_ci    ESD_NEEDS_REQDATA,          /* more data needed to complete request */
19453a5a1b3Sopenharmony_ci    ESD_NEXT_REQUEST,           /* proceed to next request */
19553a5a1b3Sopenharmony_ci    ESD_CLIENT_STATE_MAX        /* place holder */
19653a5a1b3Sopenharmony_ci};
19753a5a1b3Sopenharmony_citypedef int esd_client_state_t;
19853a5a1b3Sopenharmony_ci
19953a5a1b3Sopenharmony_ci/* the endian key is transferred in binary, if it's read into int, */
20053a5a1b3Sopenharmony_ci/* and matches ESD_ENDIAN_KEY (ENDN), then the endianness of the */
20153a5a1b3Sopenharmony_ci/* server and the client match; if it's SWAP_ENDIAN_KEY, swap data */
20253a5a1b3Sopenharmony_ci#define ESD_SWAP_ENDIAN_KEY (PA_UINT32_SWAP(ESD_ENDIAN_KEY))
20353a5a1b3Sopenharmony_ci
20453a5a1b3Sopenharmony_ci#endif
205