move server specific bits into new sndiod daemon

This commit is contained in:
Alexandre Ratchov 2011-12-09 23:49:26 +01:00
parent b218a19c35
commit 073a090888
6 changed files with 165 additions and 126 deletions

View File

@ -23,23 +23,24 @@ MAN1_DIR = @mandir@/man1
#
# programs to build
#
PROG = aucat
MAN1 = aucat.1
PROG = aucat sndiod
MAN1 = aucat.1 sndiod.1
all: ${PROG}
all: ${PROG} ${MAN1}
install:
mkdir -p ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN1_DIR}
cp aucat ${DESTDIR}${BIN_DIR}
cd ${DESTDIR}${BIN_DIR}
cp ${MAN1} ${DESTDIR}${MAN1_DIR}
cp aucat.1 ${DESTDIR}${MAN1_DIR}
ln -sf aucat ${DESTDIR}${BIN_DIR}/sndiod
ln -sf aucat.1 ${DESTDIR}${MAN1_DIR}/sndiod.1
uninstall:
cd ${DESTDIR}${BIN_DIR} && rm -f ${PROG}
cd ${DESTDIR}${MAN1_DIR} && rm -f ${MAN1}
clean:
rm -f -- ${PROG} *.o *~ *.bak *.tmp *.core core
rm -f -- *.o aucat sndiod sndiod.1
# ---------------------------------------------------------- dependencies ---
@ -51,6 +52,12 @@ wav.o
aucat: ${OBJS}
${CC} ${LDFLAGS} ${LIB} -o aucat ${OBJS} ${LDADD}
sndiod:
ln -sf aucat sndiod
sndiod.1:
ln -sf aucat.1 sndiod.1
.c.o:
${CC} ${CFLAGS} ${INCLUDE} ${DEFS} -c $<

View File

@ -18,13 +18,13 @@
.Dt AUCAT 1
.Os
.Sh NAME
.Nm aucat
.Nm aucat ,
.Nm sndiod
.Nd audio/MIDI server and stream manipulation tool
.Sh SYNOPSIS
.Nm aucat
.Bk -words
.Op Fl dlMn
.Op Fl a Ar flag
.Op Fl dn
.Op Fl b Ar nframes
.Op Fl C Ar min : Ns Ar max
.Op Fl c Ar min : Ns Ar max
@ -33,11 +33,30 @@
.Op Fl h Ar fmt
.Op Fl i Ar file
.Op Fl j Ar flag
.Op Fl L Ar addr
.Op Fl m Ar mode
.Op Fl o Ar file
.Op Fl q Ar port
.Op Fl r Ar rate
.Op Fl t Ar mode
.Op Fl v Ar volume
.Op Fl w Ar flag
.Op Fl x Ar policy
.Op Fl z Ar nframes
.Ek
.Nm sndiod
.Bk -words
.Op Fl dM
.Op Fl a Ar flag
.Op Fl b Ar nframes
.Op Fl C Ar min : Ns Ar max
.Op Fl c Ar min : Ns Ar max
.Op Fl e Ar enc
.Op Fl f Ar device
.Op Fl j Ar flag
.Op Fl L Ar addr
.Op Fl m Ar mode
.Op Fl q Ar port
.Op Fl r Ar rate
.Op Fl s Ar name
.Op Fl t Ar mode
.Op Fl U Ar unit
@ -50,30 +69,30 @@
.Nm
is an audio utility which can simultaneously play and record
any number of audio
.Em streams
on any number of audio devices,
.Em streams ,
possibly controlled through MIDI.
It can also act as an audio server, in which case streams
correspond to client connections rather than plain files.
.Pp
Audio devices are independent.
A list of streams is attached to each audio device,
as well as an optional list of MIDI ports to control the device.
A typical invocation of
.Nm
consists in providing streams to play and record,
and possibly the audio device to use, if the default is not desired.
and possibly the audio device to use.
.Pp
This also applies to server mode, except that streams are created
The
.Nm sndiod
daemon acts as an audio server.
Its functionality is identical to
.Nm aucat ,
except that streams are created
dynamically when clients connect to the server.
Thus, instead of actual streams (paths to plain files),
templates for client streams (sub-device names) must be provided.
Multiple independent audio devices are supported,
each has its own list of streams and MIDI control ports.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl a Ar flag
Control whether
.Nm
.Nm sndiod
opens the audio device only when needed or keeps it open all the time.
This applies to MIDI ports controlling the device as well.
If the flag is
@ -101,7 +120,7 @@ respectively.
The default is 0:1, i.e. stereo.
.It Fl d
Increase log verbosity.
.Nm
.Nm sndiod
logs on
.Em stderr
until it daemonizes.
@ -146,23 +165,23 @@ be sent on multiple outputs or to record a stereo input into a mono stream.
The default is
.Ar on .
.It Fl L Ar addr
Specify a local network address to listen on in server mode.
.Nm
Specify a local network address
.Nm sndiod
should listen;
.Nm sndiod
will listen on TCP port 11025+n, where n is the unit number
specified with
.Fl U .
Without this option,
.Nm
.Nm sndiod
listens on the
.Ux Ns -domain
socket only, and is not reachable from any network.
If the option argument is
.Sq -
then
.Nm
.Nm sndiod
will accept connections from any address.
.It Fl l
Detach and become a daemon.
.It Fl M
Create a MIDI thru box
.Pq i.e. MIDI-only pseudo device .
@ -177,9 +196,9 @@ preceded by
.Fl m Ar midi
.Pc
can be attached to it.
If sub-devices are exposed
.Pq Fl s
they behave like software MIDI ports,
Exposed sub-devices by
.Nm sndiod
behave like software MIDI ports,
allowing any MIDI-capable application to send MIDI messages to
MIDI hardware or to another application in a uniform way.
.It Fl m Ar mode
@ -208,10 +227,6 @@ It requires at least one input
.Pq Fl i
and one output
.Pq Fl o .
It doesn't support MIDI control
.Pq Fl q
and can't expose sub-devices
.Pq Fl s .
.It Fl o Ar file
Add this file to the list of recording streams.
If the option argument is
@ -233,9 +248,9 @@ The default is 44100Hz.
.It Fl s Ar name
Add
.Ar name
to the list of sub-devices to expose in server mode.
to the list of sub-devices to expose.
This allows clients to use
.Nm
.Nm sndiod
instead of the physical audio device for audio input and output
in order to share the physical device with other clients.
Defining multiple sub-devices allows splitting a physical audio device
@ -262,15 +277,15 @@ to audio streams.
.It Fl U Ar unit
Unit number to use when running in server mode.
Each
.Nm
.Nm sndiod
server instance has an unique unit number,
used in
.Xr sndio 7
device names.
The default is 0.
The unit number must be set before any server-specific
options are used
.Pq Fl Ls .
The unit number must be set before any
.Fl L
is used.
.It Fl v Ar volume
Software volume attenuation of the playback stream.
The value must be between 1 and 127,
@ -284,6 +299,8 @@ The default is 127 i.e. no attenuation.
.It Fl w Ar flag
Control
.Nm
and
.Nm sndiod
behaviour when the maximum volume of the hardware is reached
and a new stream is connected.
This happens only when stream volumes
@ -357,21 +374,18 @@ and stream definitions
must follow the definition of the device
.Pq Fl fMn
to which they are attached.
Global parameters
.Pq Fl dl
are position-independent.
.Pp
If no audio devices
.Pq Fl fMn
are specified,
settings are applied as if
the default device is specified.
If no streams
.Pq Fl ios
If no
.Nm sndiod
sub-devices
.Pq Fl s
are specified for a device, a default server sub-device is
created attached to it, meaning that
.Nm
behaves as an audio server.
created attached to it.
If a device
.Pq Fl fMn
is defined twice, both definitions are merged:
@ -382,12 +396,19 @@ and MIDI control ports
of both definitions are created.
The default
.Xr sndio 7
device is
.Pa snd/0
.Pq also known as Pa snd/0.default .
device used by
.Nm sndiod
is
.Pa rsnd/0 ,
and the default sub-device exposed by
.Nm sndiod
is
.Pa snd/0 .
.Pp
If
.Nm
.Nm sndiod
or
.Nm aucat
is sent
.Dv SIGHUP ,
.Dv SIGINT
@ -475,14 +496,8 @@ signed 18-bit, packed in 3 bytes, little endian
unsigned 18-bit, packed in 3 bytes, big endian
.El
.Sh SERVER MODE
If at least one sub-device
.Pq Fl s
is exposed by
.Nm ,
including the case when no stream options are given,
then
.Nm
can be used as a server
.Nm sndiod
can be used
to overcome hardware limitations and allow applications
to run on fixed sample rate devices or on devices
supporting only unusual encodings.
@ -502,10 +517,10 @@ MIDI ports
.Pq Fl q
and allows audio device properties to be controlled
through MIDI.
If running in server mode
.Nm
creates a MIDI port with the same name as the default audio
device to which MIDI programs can connect.
Additionally,
.Nm sndiod
creates a MIDI port with the same name as the exposed audio
sub-device to which MIDI programs can connect.
.Pp
A MIDI channel is assigned to each stream, and the volume
is changed using the standard volume controller (number 7).
@ -524,32 +539,42 @@ relative to the beginning of the stream, at which playback
and recording must start.
If the requested position is beyond the end of file,
the stream is temporarly disabled until a valid position is requested.
This message is ignored by client streams (server mode).
The given time position is sent to MIDI ports as an MTC
This message is ignored by audio
.Nm sndiod
clients, but the given time position is sent to MIDI ports as an MTC
.Dq "full frame"
message forcing all MTC-slaves to relocate to the given
position (see below).
.It start
Put all streams in starting mode.
In this mode,
.Nm
.Nm sndiod
or
.Nm aucat
waits for all streams to become ready
to start, and then starts them synchronously.
Once started, new streams can be created (server mode)
Once started, new streams can be created
.Pq Nm sndiod
but they will be blocked
until the next stop-to-start transition.
.It stop
Put all streams in stopped mode (the default).
In this mode, any stream attempting to start playback or recording
is paused.
Files are stopped and rewound back to the starting position,
while client streams (server mode) that are already
Files
.Pq Nm aucat
are stopped and rewound back to the starting position,
while client streams
.Pq Nm sndiod
that are already
started are not affected until they stop and try to start again.
.El
.Pp
Streams created with the
.Fl t
option export the server clock using MTC, allowing non-audio
option export the
.Nm sndiod
device clock using MTC, allowing non-audio
software or hardware to be synchronized to the audio stream.
Maximum accuracy is achieved when the number of blocks per
second is equal to one of the standard MTC clock rates (96, 100 and 120Hz).
@ -576,7 +601,7 @@ the default
and a MIDI-controlled
.Va snd/0.mmc :
.Bd -literal -offset indent
$ aucat -l -r 48000 -z 400 -s default -t slave -s mmc
$ sndiod -r 48000 -z 400 -s default -t slave -s mmc
.Ed
.Pp
Streams connected to
@ -634,9 +659,7 @@ $ aucat -n -j off -i stereo.wav -C 0:0 -o left.wav -C 1:1 \e
-o right.wav
.Ed
.Pp
Start
.Nm
in server mode using default parameters, creating an
Start server using default parameters, creating an
additional sub-device for output to channels 2:3 only (rear speakers
on most cards), exposing the
.Pa snd/0
@ -644,30 +667,26 @@ and
.Pa snd/0.rear
devices:
.Bd -literal -offset indent
$ aucat -l -s default -c 2:3 -s rear
$ sndiod -s default -c 2:3 -s rear
.Ed
.Pp
Start
.Nm
in server mode, creating the default sub-device with low volume and
Start server creating the default sub-device with low volume and
an additional sub-device for high volume output, exposing the
.Pa snd/0
and
.Pa snd/0.max
devices:
.Bd -literal -offset indent
$ aucat -l -v 65 -s default -v 127 -s max
$ sndiod -v 65 -s default -v 127 -s max
.Ed
.Pp
Start
.Nm
in server mode, configuring the audio device to use
Start server configuring the audio device to use
a 48kHz sample frequency, 240-frame block size,
and 2-block buffers.
The corresponding latency is 10ms, which is
the time it takes the sound to propagate 3.5 meters.
.Bd -literal -offset indent
$ aucat -l -r 48000 -b 480 -z 240
$ sndiod -r 48000 -b 480 -z 240
.Ed
.Sh SEE ALSO
.Xr audioctl 1 ,
@ -682,10 +701,11 @@ utility assumes non-blocking I/O for input and output streams.
It will not work reliably on files that may block
(ordinary files block, pipes don't).
To avoid audio underruns/overruns or MIDI jitter caused by file I/O,
it's recommended to use two
it's recommended to use two processes: a
.Nm sndiod
server handling audio and MIDI I/O and a
.Nm
processes: a server handling audio and MIDI I/O and a client handling
disk I/O.
client handling disk I/O.
.Pp
Resampling is low quality; down-sampling especially should be avoided
when recording.
@ -696,12 +716,12 @@ thus samples with more than 16 bits are rounded.
.Pp
If
.Fl a Ar off
is used in server mode,
.Nm
is used,
.Nm sndiod
creates sub-devices to expose first
and then opens the audio hardware on demand.
Technically, this allows
.Nm
.Nm sndiod
to attempt to use one of the sub-devices it exposes as an audio device,
creating a deadlock.
To avoid this,

View File

@ -57,6 +57,7 @@
#define SNDIO_PRIO (-20)
#define PROG_AUCAT "aucat"
#define PROG_SNDIOD "sndiod"
/*
* sample rate if no ``-r'' is used
@ -84,12 +85,17 @@ volatile sig_atomic_t debug_level = 1;
#endif
volatile sig_atomic_t quit_flag = 0;
char aucat_usage[] = "usage: " PROG_AUCAT " [-dlMn] [-a flag] [-b nframes] "
char aucat_usage[] = "usage: " PROG_AUCAT " [-dlMn] [-b nframes] "
"[-C min:max] [-c min:max] [-e enc]\n\t"
"[-f device] [-h fmt] [-i file] [-j flag] [-L addr] [-m mode] "
"[-o file]\n\t"
"[-q port] [-r rate] [-s name] [-t mode] [-U unit] [-v volume]\n\t"
"[-w flag] [-x policy] [-z nframes]\n";
"[-f device] [-h fmt] [-i file] [-j flag] [-m mode] [-o file]\n\t"
"[-q port] [-r rate] [-t mode] [-v volume] [-w flag] [-x policy]\n\t"
"[-z nframes]\n";
char sndiod_usage[] = "usage: " PROG_SNDIOD " [-dlM] [-a flag] [-b nframes] "
"[-C min:max] [-c min:max] [-e enc]\n\t"
"[-f device] [-j flag] [-L addr] [-m mode] [-q port] [-r rate]\n\t"
"[-s name] [-t mode] [-U unit] [-v volume] [-w flag] [-x policy]\n\t"
"[-z nframes]\n";
/*
* SIGINT handler, it raises the quit flag. If the flag is already set,
@ -416,6 +422,11 @@ main(int argc, char **argv)
if (strcmp(prog, PROG_AUCAT) == 0) {
optstr = "a:b:c:C:de:f:h:i:j:lL:m:Mno:q:r:s:t:U:v:w:x:z:";
usagestr = aucat_usage;
} else if (strcmp(prog, PROG_SNDIOD) == 0) {
optstr = "a:b:c:C:de:f:j:L:m:Mq:r:s:t:U:v:w:x:z:";
usagestr = sndiod_usage;
background = 1;
hold = 0;
} else {
fprintf(stderr, "%s: can't determine program to run\n", prog);
return 1;
@ -428,6 +439,7 @@ main(int argc, char **argv)
if (debug_level < 4)
debug_level++;
#endif
background = 0;
break;
case 'U':
if (listen_list)
@ -494,7 +506,7 @@ main(int argc, char **argv)
dev_adjpar(d, w->mode, &w->hpar, NULL);
break;
case 's':
d = mkdev(NULL, 0, bufsz, round, 1, autovol);
d = mkdev(DEFAULT_DEV, 0, bufsz, round, 1, autovol);
mkopt(optarg, d, &rpar, &ppar,
mode, vol, mmc, join);
/* XXX: set device rate, if never set */

View File

@ -51,7 +51,7 @@ The
library allows user processes to access
.Xr midi 4
hardware and
.Xr aucat 1
.Xr sndiod 1
MIDI thru boxes and control ports in a uniform way.
.Ss Opening and closing an MIDI stream
First the application must call the
@ -63,7 +63,7 @@ argument of most other functions.
The
.Fn mio_open
function tries to connect to the
.Xr aucat 1
.Xr sndiod 1
MIDI thru box or to use the
.Xr midi 4
hardware port.
@ -241,13 +241,13 @@ may be a value between 0 and 2.
.Bl -tag -width "/tmp/aucat-<uid>/aucat0" -compact
.It Pa /tmp/aucat-<uid>/aucat0
Default path to
.Xr aucat 1
.Xr sndiod 1
socket to connect to.
.It Pa /dev/rmidiX
.Xr midi 4
devices.
.El
.Sh SEE ALSO
.Xr aucat 1 ,
.Xr sndiod 1 ,
.Xr midi 4 ,
.Xr sndio 7

View File

@ -80,11 +80,11 @@ The
library allows user processes to access
.Xr audio 4
hardware and the
.Xr aucat 1
.Xr sndiod 1
audio server in a uniform way.
It supports full-duplex operation, and when
used with the
.Xr aucat 1
.Xr sndiod 1
server it supports resampling and format
conversions on the fly.
.Ss Opening and closing an audio stream
@ -97,7 +97,7 @@ argument of most other functions.
The
.Fn sio_open
function first tries to connect to the
.Xr aucat 1
.Xr sndiod 1
audio server.
If that fails, it then tries to use the
.Xr audio 4
@ -273,7 +273,7 @@ must be called before parameters can be changed.
If
.Nm libsndio
is used to connect to the
.Xr aucat 1
.Xr sndiod 1
server, a transparent emulation layer will
automatically be set up, and in this case any
parameters are supported.
@ -737,7 +737,7 @@ may be a value between 0 and 2.
.Bl -tag -width "/tmp/aucat-<uid>/aucat0" -compact
.It Pa /tmp/aucat-<uid>/aucat0
Default path to
.Xr aucat 1
.Xr sndiod 1
socket to connect to.
.It Pa /dev/audio
Default
@ -748,7 +748,7 @@ device to use.
.\".Bd -literal -offset indent
.\".Ed
.Sh SEE ALSO
.Xr aucat 1 ,
.Xr sndiod 1 ,
.Xr audio 4 ,
.Xr sndio 7 ,
.Xr audio 9
@ -765,7 +765,7 @@ the
function will stop playback immediately.
.Pp
The
.Xr aucat 1
.Xr sndiod 1
server doesn't implement flow control (for performance reasons).
If the application doesn't consume recorded data fast enough then
.Dq "control messages"

View File

@ -25,7 +25,7 @@ The
.Nm sndio
audio and MIDI system provides access to audio and MIDI hardware and
to services provided by
.Xr aucat 1 ,
.Xr sndiod 1 ,
summarized below.
.Pp
Hardware
@ -38,7 +38,7 @@ audio programs.
.Pp
To overcome hardware limitations and to allow multiple applications
to share the hardware,
.Xr aucat 1
.Xr sndiod 1
can be used.
It exposes one or more software subdevices backed by the underlying hardware,
while doing all necessary conversions on the fly.
@ -57,15 +57,15 @@ Software MIDI thru boxes allow one application to send MIDI data to other
applications connected to the thru box (for instance a software sequencer
can send events to multiple software synthesizers).
There's no hardware involved: thru boxes are created by
.Xr aucat 1 .
.Xr sndiod 1 .
.Pp
Additionally,
.Xr aucat 1
.Xr sndiod 1
exposes a MIDI port used to control and monitor audio streams
in real time using MIDI.
.Sh DEVICE NAMES
From the user's perspective every audio interface, MIDI port, and
.Xr aucat 1
.Xr sndiod 1
service has a name of the form:
.Bd -literal -offset center
type[@hostname][,unit]/devnum[.option]
@ -89,31 +89,31 @@ Raw
port.
.It Pa snd
Audio device exposed by
.Xr aucat 1 .
.Xr sndiod 1 .
.It Pa midithru
MIDI thru box created with
.Xr aucat 1 .
.Xr sndiod 1 .
.El
.It Pa hostname
The hostname or address where the remote
.Xr aucat 1
.Xr sndiod 1
server to connect to is running.
.It Pa unit
The number of the
.Xr aucat 1
.Xr sndiod 1
server to connect to, corresponding to the integer specified using the
.Fl U
option of
.Xr aucat 1 .
.Xr sndiod 1 .
Useful only if multiple
.Xr aucat 1
.Xr sndiod 1
servers are running on the same system.
.It Pa devnum
Device number.
For hardware audio or MIDI ports, this corresponds to
the character device minor number.
For audio devices or MIDI ports created with
.Xr aucat 1
.Xr sndiod 1
it corresponds to the number of the corresponding
.Fl fM
option on the command line.
@ -121,7 +121,7 @@ option on the command line.
Corresponds to the sub-device string registered using the
.Fl s
option of
.Xr aucat 1 .
.Xr sndiod 1 .
.El
.Pp
For example:
@ -133,17 +133,17 @@ First hardware audio device.
Hardware MIDI port number 5.
.It Pa snd/0
First audio device exposed by
.Xr aucat 1 .
.Xr sndiod 1 .
.It Pa snd/0.rear
Sub-device registered with
.Fl s Fa rear .
.It Pa midithru/0
First MIDI thru box created with
.Xr aucat 1 .
.Xr sndiod 1 .
.El
.Sh AUTHENTICATION
If a shared
.Xr aucat 1
.Xr sndiod 1
server is running, for privacy reasons only one user may have
connections to it at a given time
(though the same user could have multiple connections to it).
@ -162,7 +162,7 @@ can connect to the server using the same cookie.
.It AUCAT_COOKIE
Path to file containing the session cookie to be used
when connecting to
.Xr aucat 1 .
.Xr sndiod 1 .
.It Ev AUDIODEVICE
Audio device to use if the application provides
no device chooser.
@ -181,7 +181,7 @@ Audio devices.
MIDI ports.
.El
.Sh SEE ALSO
.Xr aucat 1 ,
.Xr sndiod 1 ,
.Xr mio_open 3 ,
.Xr sio_open 3 ,
.Xr audio 4 ,