X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/fbf869934badff9e4eaa9bc9c97a1ef10ffb31ef..cf714d856f8e57ec300704b665f0bbf33a4a317d:/server/speaker.c diff --git a/server/speaker.c b/server/speaker.c index 2114db4..172671b 100644 --- a/server/speaker.c +++ b/server/speaker.c @@ -18,7 +18,7 @@ * USA */ /** @file server/speaker.c - * @brief Speaker processs + * @brief Speaker process * * This program is responsible for transmitting a single coherent audio stream * to its destination (over the network, to some sound API, to some @@ -87,67 +87,17 @@ #include "addr.h" #include "timeval.h" #include "rtp.h" +#include "speaker.h" #if API_ALSA #include #endif -#ifdef WORDS_BIGENDIAN -# define MACHINE_AO_FMT AO_FMT_BIG -#else -# define MACHINE_AO_FMT AO_FMT_LITTLE -#endif - -/** @brief How many seconds of input to buffer - * - * While any given connection has this much audio buffered, no more reads will - * be issued for that connection. The decoder will have to wait. - */ -#define BUFFER_SECONDS 5 - -/** @brief Frame batch size - * - * This controls how many frames are written in one go. - * - * For ALSA we request a buffer of three times this size and set the low - * watermark to this amount. The goal is then to keep between 1 and 3 times - * this many frames in play. - * - * For all backends we attempt to play up to three times this many frames per - * shot. In practice we will often only send much less than this. - */ -#define FRAMES 4096 - -/** @brief Bytes to send per network packet - * - * Don't make this too big or arithmetic will start to overflow. - */ -#define NETWORK_BYTES (1024+sizeof(struct rtp_header)) +/** @brief Linked list of all prepared tracks */ +struct track *tracks; -/** @brief Maximum RTP playahead (ms) */ -#define RTP_AHEAD_MS 1000 - -/** @brief Maximum number of FDs to poll for */ -#define NFDS 256 - -/** @brief Track structure - * - * Known tracks are kept in a linked list. Usually there will be at most two - * of these but rearranging the queue can cause there to be more. - */ -static struct track { - struct track *next; /* next track */ - int fd; /* input FD */ - char id[24]; /* ID */ - size_t start, used; /* start + bytes used */ - int eof; /* input is at EOF */ - int got_format; /* got format yet? */ - ao_sample_format format; /* sample format */ - unsigned long long played; /* number of frames played */ - char *buffer; /* sample buffer */ - size_t size; /* sample buffer size */ - int slot; /* poll array slot */ -} *tracks, *playing; /* all tracks + playing track */ +/** @brief Playing track, or NULL */ +struct track *playing; static time_t last_report; /* when we last reported */ static int paused; /* pause status */ @@ -226,77 +176,6 @@ static int idled; /* set when idled */ /** @brief Error counter */ static int audio_errors; -/** @brief Structure of a backend */ -struct speaker_backend { - /** @brief Which backend this is - * - * @c -1 terminates the list. - */ - int backend; - - /** @brief Flags - * - * Possible values - * - @ref FIXED_FORMAT - */ - unsigned flags; -/** @brief Lock to configured sample format */ -#define FIXED_FORMAT 0x0001 - - /** @brief Initialization - * - * Called once at startup. This is responsible for one-time setup - * operations, for instance opening a network socket to transmit to. - * - * When writing to a native sound API this might @b not imply opening the - * native sound device - that might be done by @c activate below. - */ - void (*init)(void); - - /** @brief Activation - * @return 0 on success, non-0 on error - * - * Called to activate the output device. - * - * After this function succeeds, @ref ready should be non-0. As well as - * opening the audio device, this function is responsible for reconfiguring - * if it necessary to cope with different samples formats (for backends that - * don't demand a single fixed sample format for the lifetime of the server). - */ - int (*activate)(void); - - /** @brief Play sound - * @param frames Number of frames to play - * @return Number of frames actually played - */ - size_t (*play)(size_t frames); - - /** @brief Deactivation - * - * Called to deactivate the sound device. This is the inverse of - * @c activate above. - */ - void (*deactivate)(void); - - /** @brief Called before poll() - * - * Called before the call to poll(). Should call addfd() to update the FD - * array and stash the slot number somewhere safe. - */ - void (*beforepoll)(void); - - /** @brief Called after poll() - * @return 0 if we could play, non-0 if not - * - * Called after the call to poll(). Should arrange to play some audio if the - * output device is ready. - * - * The return value should be 0 if the device was ready to play, or nonzero - * if it was not. - */ - int (*afterpoll)(void); -}; - /** @brief Selected backend */ static const struct speaker_backend *backend;