sad

simple audio daemon
git clone git://git.2f30.org/sad.git
Log | Files | Refs | LICENSE

commit 2d5b18590850aae7b21dcb95442b52d22500811f
parent dc8d59e178950a10156c75fb82cd1fafc8445ebe
Author: sin <sin@2f30.org>
Date:   Sat Dec 27 14:42:57 +0000

Add FIFO output

Diffstat:
Makefile | 3++-
fifo.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
output.c | 1+
sad.h | 3+++
4 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile @@ -7,7 +7,7 @@ CFLAGS = -I/usr/local/include -g LDFLAGS = -L /usr/local/lib LDLIBS = -lsndfile -lmpg123 -lsndio -lvorbisfile -OBJ = sndio.o cmd.o mp3.o wav.o vorbis.o playlist.o sad.o decoder.o output.o +OBJ = sndio.o cmd.o mp3.o wav.o vorbis.o playlist.o sad.o decoder.o output.o fifo.o BIN = sad # non-OpenBSD @@ -28,6 +28,7 @@ playlist.o: sad.h sad.o: sad.h decoder.o: sad.h output.o: sad.h +fifo.o: sad.h install: all mkdir -p $(DESTDIR)$(PREFIX)/bin diff --git a/fifo.c b/fifo.c @@ -0,0 +1,70 @@ +#include <sys/select.h> + +#include <err.h> +#include <fcntl.h> +#include <limits.h> +#include <stdio.h> +#include <unistd.h> + +#include "sad.h" + +static int fifofd = -1; + +static int +fifovol(int vol) +{ + return 0; +} + +static int +fifoopen(int bits, int rate, int channels) +{ + unlink("/tmp/sad-fifo"); + if (mkfifo("/tmp/sad-fifo", 0644) < 0) { + warn("mkfifo /tmp/sad-fifo"); + return -1; + } + + fifofd = open("/tmp/sad-fifo", O_RDWR | O_NONBLOCK); + if (fifofd < 0) { + warn("open /tmp/sad-fifo"); + return -1; + } + return 0; +} + +static int +fifoplay(void *buf, size_t nbytes) +{ + ssize_t n, wrote; + char *p = buf; + + wrote = 0; + while (nbytes > 0) { + n = write(fifofd, &p[wrote], nbytes); + if (n < 0) + return nbytes; /* ignore errors */ + else if (n == 0) + break; + wrote += n; + nbytes -= n; + } + return wrote; +} + +static int +fifoclose(void) +{ + if (fifofd != -1) { + close(fifofd); + fifofd = -1; + } + return 0; +} + +Output fifooutput = { + .vol = fifovol, + .open = fifoopen, + .play = fifoplay, + .close = fifoclose, +}; diff --git a/output.c b/output.c @@ -20,6 +20,7 @@ typedef struct { /* TODO: should be moved to config.def.h */ static Outputdesc Outputdescs[] = { { "sndio", 16, 44100, 2, 1, &sndiooutput }, + { "fifo", 16, 44100, 2, 1, &fifooutput }, }; static int inbits; diff --git a/sad.h b/sad.h @@ -81,6 +81,9 @@ extern Decoder vorbisdecoder; /* sndio.c */ extern Output sndiooutput; +/* fifo.c */ +extern Output fifooutput; + /* tokenizer.c */ int gettokens(char *, char **, int, char *); int tokenize(char *, char **, int);