manual: Combine overview.pdf and the user manual.
[paraslash.git] / web / manual.md
1 **Paraslash user manual**
2
3 This document describes how to install, configure and use the paraslash
4 network audio streaming system. Most chapters start with a chapter
5 overview and conclude with an example section. We try to focus on
6 general concepts and on the interaction of the various pieces of the
7 paraslash package. Hence this user manual is not meant as a replacement
8 for the manual pages that describe all command line options of each
9 paraslash executable.
10
11 ============
12 Introduction
13 ============
14
15 In this chapter we give an [overview](#Overview) of the interactions
16 of the programs contained in the paraslash package, followed by
17 [brief descriptions](#The.paraslash.executables) of all executables.
18
19 Overview
20 --------
21
22 The core functionality of the para suite is provided by two main
23 applications, para_server and para_audiod. para_server maintains
24 the audio file database and acts as the streaming source, while
25 para_audiod is the streaming client. Usually, both run in the
26 background on different hosts but a local setup is also possible.
27
28 A simplified picture of a typical setup is as follows
29
30
31 .____________________.
32 | ______ |
33 .-----------------------. | .d########b. |
34 |.---------------------.| | .d############b |
35 || || | .d######""####//b. |
36 || || | 9######( )######P |
37 || || | 'b######++######d' |
38 || Screen || | "9############P" |
39 || || | "9a########P" |
40 || || | `""""'' |
41 |`---------------------'| | ________________ |
42 `-----------------------' | |________________| |
43 ___) (___ |____________________|
44 `-._______.-' loudspeaker
45 | |
46 | |
47 | |
48 .____/ \___. ._____________. ._____/ \_____.
49 | | | | | |
50 | para_gui |-----| para_audioc |-----| para_audiod |
51 |____ ___| |_____________| |_____ _____|
52 \ / \ /
53 | |
54 | |
55 | |
56 ._____/ \_____. ._____/ \_____.
57 | | | |
58 | para_client |-----------------------| para_server |
59 |_____________| |_____ _____|
60 \ /
61 |
62 |
63 .-'"""`-.
64 ( )
65 |`-.___.-'|
66 | |
67 |. ' " ` .|
68 | |
69 `-.___.-'
70 Database
71
72 The two client programs, para_client and para_audioc communicate with
73 para_server and para_audiod, respectively.
74
75 para_gui controls para_server and para_audiod by executing para_client
76 and para_audioc. In particular, it runs a command to obtain the state
77 of para_audiod and para_server, and the metadata of the current audio
78 file. This information is pretty-printed in a curses window.
79
80 The paraslash executables
81 -------------------------
82
83 ### para_server ###
84
85 para_server streams binary audio data (MP3, ...) over local and/or
86 remote networks. It listens on a TCP port and accepts commands such
87 as play, stop, pause, next from authenticated clients. The components
88 of para_server are illustrated in the following diagram:
89
90 ______________________________________________________________________ network
91 | | | | |
92 | .-'""""`-. | | | |
93 | ( ) | | | |
94 .____/ \_____. |`-.____.-'| .____/ \____/ \____/ \____. |
95 | | | | | | |
96 | dispatcher | | database | | senders (http/udp/dccp) | |
97 |____ _____| | | |___________ ___________| |
98 \ / |. ' "" ` .| \ / |
99 | | | | |
100 | `-.____.-' | |
101 | | | |
102 | | | |
103 | | | |
104 | ._____/ \_____. .________/ \________. |
105 | | | | | |
106 | | audio file |________| virtual streaming | |
107 | | selector | | system | |
108 | |_____ _____| |________ ________| |
109 | \ / \ / |
110 | | | |
111 | | | |
112 | | ._________________. | |
113 | | | | | |
114 | `---| command handler |---' |
115 | |____ ___ ____| |
116 | \ / \ / |
117 | | | |
118 | | | |
119 | | | |
120 `-------------------------' `--------------------------'
121
122
123 Incoming connections arrive at the dispatcher which creates a process
124 dedicated to the connection. Its task is to authenticate the client
125 and to run the command handler which forwards the client request to
126 either the audio file selector or the virtual streaming system. Results
127 (if any) are sent back to the client.
128
129 The audio file selector manages audio files using various database
130 tables. It maintains statistics on the usage of all audio files such as
131 last-played time and the number of times each file was selected. It
132 is also responsible for selecting and loading audio files for
133 streaming. Additional information may be added to the database to allow
134 fine-grained selection based on various properties of the audio file,
135 including information found in (ID3) tags. Simple playlists are also
136 supported. It is possible to store images (album covers) and lyrics
137 in the database and associate these to the corresponding audio files.
138 The section on the [audio file selector](#The.audio.file.selector)
139 discusses this topic in more detail.
140
141 Another component of para_server is the virtual streaming system,
142 which controls the paraslash senders. During streaming it requests
143 small chunks of data (e.g., mp3 frames) from the audio file selector
144 and feeds them to the senders which forward the chunks to connected
145 clients.
146
147 The three senders of para_server correspond to network streaming
148 protocols based on HTTP, DCCP, or UDP. This is explained in the
149 section on [networking](#Networking).
150
151 ### para_client ###
152
153 The client program to connect to para_server. paraslash commands
154 are sent to para_server and the response is dumped to STDOUT. This
155 can be used by any scripting language to produce user interfaces with
156 little programming effort.
157
158 All connections between para_server and para_client are encrypted
159 with a symmetric session key. For each user of paraslash you must
160 create a public/secret RSA key pair for authentication.
161
162 If para_client is started without non-option arguments, an interactive
163 session (shell) is started. Command history and command completion are
164 supported through libreadline.
165
166 ### para_audiod ###
167
168 The purpose of para_audiod is to download, decode and play an audio
169 stream received from para_server. A typical setup looks as follows.
170
171
172 .----------------------------.
173 | |
174 | |
175 ._____/ \_____. .___/ \____.
176 | | .----------| |
177 | para_server | | .______| receiver |
178 |_____ ____| | | |___ ____|
179 \ / | | \ /
180 | | | |
181 | | | |
182 | | | |
183 ._____/ \_____. | | .___/ \____.
184 | | | | | |
185 | status task |-----+ | | filter 1 |
186 |_____________| | |___ ____|
187 | \ /
188 | | .____________________.
189 | | | ______ |
190 .____________. | .___/ \____. | .d########b. |
191 | | | | | | .d############b |
192 | dispatcher |----------' | filter 2 | | .d######""####//b. |
193 |_____ ____| |___ ____| | 9######( )######P |
194 \ / \ / | 'b######++######d' |
195 | | | "9############P" |
196 | | | "9a########P" |
197 ._____/ \_____. .___/ \____. | `""""'' |
198 | | | | | ________________ |
199 | para_audioc | | writer |------| |________________| |
200 |_____________| |__________| |____________________|
201
202
203 The status task of para_audiod connects to para_server and runs the
204 "stat" command to retrieve the current server status. If an audio
205 stream is available, para_audiod starts a so-called buffer tree to
206 play the stream.
207
208 The buffer tree consists of a receiver, any number of filters and a
209 writer. The receiver downloads the audio stream from para_server and
210 the filters decode or modify the received data. The writer plays the
211 decoded stream.
212
213 The dispatcher of para_audiod listens on a local socket and runs
214 audiod commands on behalf of para_audioc. For example, para_gui runs
215 para_audioc to obtain status information about para_audiod and the
216 current audio file. Access to the local socket may be restricted by
217 means of Unix socket credentials.
218
219 ### para_audioc ###
220
221 The client program which talks to para_audiod. Used to control
222 para_audiod, to receive status info, or to grab the stream at any
223 point of the decoding process. Like para_client, para_audioc supports
224 interactive sessions on systems with libreadline.
225
226 ### para_recv ###
227
228 A command line HTTP/DCCP/UDP stream grabber. The http mode is
229 compatible with arbitrary HTTP streaming sources (e.g. icecast).
230 In addition to the three network streaming modes, para_recv can also
231 operate in local (afh) mode. In this mode it writes the content of
232 an audio file on the local file system in complete chunks to stdout,
233 optionally 'just in time'. This allows to cut an audio file without
234 first decoding it, and it enables third-party software which is unaware
235 of the particular audio format to send complete frames in real time.
236
237 ### para_filter ###
238
239 A filter program that reads from STDIN and writes to STDOUT.
240 Like para_recv, this is an atomic building block which can be used to
241 assemble higher-level audio receiving facilities. It combines several
242 different functionalities in one tool: decoders for multiple audio
243 formats and a number of processing filters, among these a normalizer
244 for audio volume.
245
246 ### para_afh ###
247
248 A small stand-alone program that prints tech info about the given
249 audio file to STDOUT. It can be instructed to print a "chunk table",
250 an array of offsets within the audio file.
251
252 ### para_write ###
253
254 A modular audio stream writer. It supports a simple file writer
255 output plug-in and optional WAV/raw players for ALSA (Linux) and OSS.
256 para_write can also be used as a stand-alone WAV or raw audio player.
257
258 ### para_play ###
259
260 A command line audio player.
261
262 ### para_gui ###
263
264 Curses-based gui that presents status information obtained in a curses
265 window. Appearance can be customized via themes. para_gui provides
266 key-bindings for the most common server commands and new key-bindings
267 can be added easily.
268
269 ### para_mixer ###
270
271 An alarm clock and volume-fader for OSS and ALSA.
272
273 ===========
274 Quick start
275 ===========
276
277 This chapter lists the [necessary software](#Requirements)
278 that must be installed to compile the paraslash package, describes
279 how to [compile and install](#Installation) the paraslash
280 source code and the steps that have to be performed in order to
281 [set up](#Configuration) a typical server and client.
282
283 Requirements
284 ------------
285 ### For the impatient ###
286
287 git clone git://git.tuebingen.mpg.de/lopsub
288 cd lopsub && make && sudo make install
289 git clone git://git.tuebingen.mpg.de/osl
290 cd osl && make && sudo make install && sudo ldconfig
291 sudo apt-get install autoconf libssl-dev m4 \
292 libmad0-dev libid3tag0-dev libasound2-dev libvorbis-dev \
293 libfaad-dev libspeex-dev libFLAC-dev libsamplerate-dev realpath \
294 libasound2-dev libao-dev libreadline-dev libncurses-dev \
295 libopus-dev
296
297 ### Detailed description ###
298
299 In any case you will need
300
301 - [libosl](http://people.tuebingen.mpg.de/maan/osl/). The _object
302 storage layer_ library is used by para_server. To clone the source
303 code repository, execute
304
305 git clone git://git.tuebingen.mpg.de/osl
306
307 - [lopsub](http://people.tuebingen.mpg.de/maan/lopsub/). The long
308 option parser for subcommands generates the command line and config
309 file parsers for all paraslash executables. Clone the source code
310 repository with
311
312 git clone git://git.tuebingen.mpg.de/lopsub
313
314 - [gcc](ftp://ftp.gnu.org/pub/gnu/gcc) or
315 [clang](http://clang.llvm.org). All gcc versions >= 4.2 are currently
316 supported. Clang version 1.1 or newer should work as well.
317
318 - [gnu make](ftp://ftp.gnu.org/pub/gnu/make) is also shipped with the
319 disto. On BSD systems the gnu make executable is often called gmake.
320
321 - [bash](ftp://ftp.gnu.org/pub/gnu/bash). Some scripts which run
322 during compilation require the _Bourne again shell_. It is most
323 likely already installed.
324
325 - [m4](ftp://ftp.gnu.org/pub/gnu/m4/). Some source files are generated
326 from templates by the m4 macro processor.
327
328 Optional:
329
330 - [openssl](http://www.openssl.org/) or
331 [libgcrypt](ftp://ftp.gnupg.org/gcrypt/libgcrypt/). At least one
332 of these two libraries is needed as the backend for cryptographic
333 routines on both the server and the client side. Both openssl and
334 libgcrypt are usually shipped with the distro, but you might have
335 to install the development package (`libssl-dev` or `libgcrypt-dev`
336 on debian systems) as well.
337
338 - [libmad](http://www.underbit.com/products/mad/). To compile in MP3
339 support for paraslash, the development package must be installed. It
340 is called `libmad0-dev` on debian-based systems. Note that libmad is
341 not necessary on the server side, i.e., for sending MP3 files.
342
343 - [libid3tag](http://www.underbit.com/products/mad/). For version-2
344 ID3 tag support, you willl need the libid3tag development package
345 `libid3tag0-dev`. Without libid3tag, only version-1 tags are
346 recognized. The mp3 tagger also needs this library for modifying
347 (id3v1 and id3v2) tags.
348
349 - [ogg vorbis](http://www.xiph.org/downloads/). For ogg vorbis streams
350 you need libogg, libvorbis, libvorbisfile. The corresponding Debian
351 packages are called `libogg-dev` and `libvorbis-dev`.
352
353 - [libfaad and mp4ff](http://www.audiocoding.com/). For aac files
354 (m4a) you need libfaad and libmp4ff (package: `libfaad-dev`). Note
355 that for some distributions, e.g. Ubuntu, mp4ff is not part of the
356 libfaad package. Install the faad library from sources (available
357 through the above link) to get the mp4ff library and header files.
358
359 - [speex](http://www.speex.org/). In order to stream or decode speex
360 files, libspeex (`libspeex-dev`) is required.
361
362 - [flac](http://flac.sourceforge.net/). To stream or decode files
363 encoded with the _Free Lossless Audio Codec_, libFLAC (`libFLAC-dev`)
364 must be installed.
365
366 - [libsamplerate](http://www.mega-nerd.com/SRC/index.html). The
367 resample filter will only be compiled if this library is
368 installed. Debian package: `libsamplerate-dev`.
369
370 - [alsa-lib](ftp://ftp.alsa-project.org/pub/lib/). On Linux, you will
371 need to have the ALSA development package `libasound2-dev` installed.
372
373 - [libao](http://downloads.xiph.org/releases/ao/). Needed to build
374 the ao writer (ESD, PulseAudio,...). Debian package: `libao-dev`.
375
376 - [curses](ftp://ftp.gnu.org/pub/gnu/ncurses). Needed for
377 para_gui. Debian package: `libncurses-dev`.
378
379 - [GNU
380 Readline](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html). If
381 this library (`libreadline-dev`) is installed, para_client, para_audioc
382 and para_play support interactive sessions.
383
384 Installation
385 ------------
386 To build the sources from a tarball, execute
387
388 ./configure && make
389
390 To build from git or a gitweb snapshot, run this command instead:
391
392 ./autogen.sh
393
394 There should be no errors but probably some warnings about missing
395 packages which usually implies that not all audio formats will be
396 supported. If headers or libs are installed at unusual locations you
397 might need to tell the configure script where to find them. Try
398
399 ./configure --help
400
401 to see a list of options. If the paraslash package was compiled
402 successfully, execute (optionally)
403
404 make test
405
406 to run the paraslash test suite. If all tests pass, execute as root
407
408 make install
409
410 to install executables under /usr/local/bin and the man pages under
411 /usr/local/man.
412
413 Configuration
414 -------------
415
416 ### Create a paraslash user ###
417
418 In order to control para_server at runtime you must create a paraslash
419 user. As authentication is based on the RSA crypto system you'll have
420 to create an RSA key pair. If you already have a user and an RSA key
421 pair, you may skip this step.
422
423 In this section we'll assume a typical setup: You would like to run
424 para_server on some host called server_host as user foo, and you want
425 to connect to para_server from another machine called client_host as
426 user bar.
427
428 As foo@server_host, create ~/.paraslash/server.users by typing the
429 following commands:
430
431 user=bar
432 target=~/.paraslash/server.users
433 key=~/.paraslash/id_rsa.pub.$user
434 perms=AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
435 mkdir -p ~/.paraslash
436 echo "user $user $key $perms" >> $target
437
438 Next, change to the "bar" account on client_host and generate the
439 key pair with the commands
440
441 ssh-keygen -q -t rsa -b 2048 -N '' -f $key
442
443 This generates the two files id_rsa and id_rsa.pub in ~/.ssh. Note
444 that para_server won't accept keys shorter than 2048 bits. Moreover,
445 para_client rejects private keys which are world-readable.
446
447 para_server only needs to know the public key of the key pair just
448 created. Copy this public key to server_host:
449
450 src=~/.ssh/id_rsa.pub
451 dest=.paraslash/id_rsa.pub.$LOGNAME
452 scp $src foo@server_host:$dest
453
454 Finally, tell para_client to connect to server_host:
455
456 conf=~/.paraslash/client.conf
457 echo 'hostname server_host' > $conf
458
459
460 ### Start para_server ###
461
462 For this first try, we'll use the info loglevel to make the output
463 of para_server more verbose.
464
465 para_server -l info
466
467 Now you can use para_client to connect to the server and issue
468 commands. Open a new shell as bar@client_host and try
469
470 para_client help
471 para_client si
472
473 to retrieve the list of available commands and some server info.
474 Don't proceed if this doesn't work.
475
476 ### Create and populate the database ###
477
478 An empty database is created with
479
480 para_client init
481
482 This initializes a couple of empty tables under
483 ~/.paraslash/afs_database-0.4. You normally don't need to look at these
484 tables, but it's good to know that you can start from scratch with
485
486 rm -rf ~/.paraslash/afs_database-0.4
487
488 in case something went wrong.
489
490 Next, you need to add some audio files to that database so that
491 para_server knows about them. Choose an absolute path to a directory
492 containing some audio files and add them to the audio file table:
493
494 para_client add /my/mp3/dir
495
496 This might take a while, so it is a good idea to start with a directory
497 containing not too many files. Note that the table only contains data
498 about the audio files found, not the files themselves.
499
500 You may print the list of all known audio files with
501
502 para_client ls
503
504 ### Configure para_audiod ###
505
506 We will have to tell para_audiod that it should receive the audio
507 stream from server_host via http:
508
509 para_audiod -l info -r '.:http -i server_host'
510
511 You should now be able to listen to the audio stream once para_server
512 starts streaming. To activate streaming, execute
513
514 para_client play
515
516 Since no playlist has been specified yet, the "dummy" mode which
517 selects all known audio files is activated automatically. See the
518 section on the [audio file selector](#The.audio.file.selector) for how
519 to use playlists and moods to specify which files should be streamed
520 in which order.
521
522 Troubleshooting
523 ---------------
524
525 To identify streaming problems try to receive, decode and play the
526 stream manually using para_recv, para_filter and para_write as follows.
527 For simplicity we assume that you're running Linux/ALSA and that only
528 MP3 files have been added to the database.
529
530 para_recv -r 'http -i server_host' > file.mp3
531 # (interrupt with CTRL+C after a few seconds)
532 ls -l file.mp3 # should not be empty
533 para_filter -f mp3dec -f wav < file.mp3 > file.wav
534 ls -l file.wav # should be much bigger than file.mp3
535 para_write -w alsa < file.wav
536
537 Double check what is logged by para_server and use the --loglevel
538 option of para_recv, para_filter and para_write to increase verbosity.
539
540 ===============
541 User management
542 ===============
543
544 para_server uses a challenge-response mechanism to authenticate
545 requests from incoming connections, similar to ssh's public key
546 authentication method. Authenticated connections are encrypted using
547 the AES stream cipher in integer counter mode.
548
549 In this chapter we briefly describe RSA and AES, and sketch the
550 [authentication handshake](#Client-server.authentication)
551 between para_client and para_server. User management is discussed
552 in the section on [the user_list file](#The.user_list.file).
553 These sections are all about communication between the client and the
554 server. Connecting para_audiod is a different matter and is described
555 in a [separate section](#Connecting.para_audiod).
556
557 RSA and AES
558 -----------
559
560 A block cipher is a transformation which operates on fixed-length
561 blocks. For symmetric block ciphers the transformation is determined
562 by a single key for both encryption and decryption. For asymmetric
563 block ciphers, on the other hand, the key consists of two parts,
564 called the public key and the private key. A message can be encrypted
565 with either key and only the counterpart of that key can decrypt the
566 message. Asymmetric block ciphers can be used for both signing and
567 encrypting a message.
568
569 RSA is an asymmetric block cipher which is used in many applications,
570 including ssh and gpg. The RSA public key encryption and signatures
571 algorithms are defined in detail in RFC 2437. Paraslash relies on
572 RSA for authentication.
573
574 Stream ciphers XOR the input with a pseudo-random key stream to produce
575 the output. Decryption uses the same function calls as encryption.
576 Any block cipher can be turned into a stream cipher by generating the
577 pseudo-random key stream by encrypting successive values of a counter
578 (counter mode).
579
580 AES, the advanced encryption standard, is a well-known symmetric block
581 cipher. Paraslash employs AES in counter mode as described above to
582 encrypt communications. Since a stream cipher key must not be used
583 twice, a random key is generated for every new connection.
584
585 Client-server authentication
586 ----------------------------
587
588 The authentication handshake between para_client and para_server goes
589 as follows:
590
591 - para_client connects to para_server and sends an authentication
592 request for a user. It does so by connecting to TCP port 2990 of the
593 server host. This port is called the para_server _control port_.
594
595 - para_server accepts the connection and forks a child process which
596 handles the incoming request. The parent process keeps listening on the
597 control port while the child process (also called para_server below)
598 continues as follows.
599
600 - para_server loads the RSA public key of that user, fills a
601 fixed-length buffer with random bytes, encrypts that buffer using the
602 public key and sends the encrypted buffer to the client. The first
603 part of the buffer is the challenge which is used for authentication
604 while the second part is the session key.
605
606 - para_client receives the encrypted buffer and decrypts it with the
607 user's private key, thereby obtaining the challenge buffer and the
608 session key. It sends the SHA1 hash value of the challenge back to
609 para_server and stores the session key for further use.
610
611 - para_server also computes the SHA1 hash of the challenge and compares
612 it against what was sent back by the client.
613
614 - If the two hashes do not match, the authentication has failed and
615 para_server closes the connection.
616
617 - Otherwise the user is considered authenticated and the client is
618 allowed to proceed by sending a command to be executed. From this
619 point on the communication is encrypted using the stream cipher with
620 the session key known to both peers.
621
622 paraslash relies on the quality of the pseudo-random bytes provided
623 by the crypto library (openssl or libgcrypt), on the security of
624 the implementation of the RSA and AES crypto routines and on the
625 infeasibility to invert the SHA1 function.
626
627 Neither para_server or para_client create RSA keys on their
628 own. This has to be done once for each user as sketched in
629 [Quick start](#Quick.start) and discussed in more detail
630 [below](#The.user_list.file).
631
632 The user_list file
633 ------------------
634
635 At startup para_server reads the user list file which contains one
636 line per user. The default location of the user list file may be
637 changed with the --user-list option.
638
639 There should be at least one user in this file. Each user must have
640 an RSA key pair. The public part of the key is needed by para_server
641 while the private key is needed by para_client. Each line of the
642 user list file must be of the form
643
644 user <username> <key> <perms>
645
646 where _username_ is an arbitrary string (usually the user's login
647 name), _key_ is the full path to that user's public RSA key, and
648 _perms_ is a comma-separated list of zero or more of the following
649 permission bits:
650
651 +---------------------------------------------------------+
652 | AFS_READ | read the contents of the databases |
653 +-----------+---------------------------------------------+
654 | AFS_WRITE | change database contents |
655 +-----------+---------------------------------------------+
656 | VSS_READ | obtain information about the current stream |
657 +-----------+---------------------------------------------+
658 | VSS_WRITE | change the current stream |
659 +---------------------------------------------------------+
660
661 The permission bits specify which commands the user is allowed to
662 execute. The output of
663
664 para_client help
665
666 contains the permissions needed to execute the command.
667
668 It is possible to make para_server reread the user_list file by
669 executing the paraslash "hup" command or by sending SIGHUP to the
670 PID of para_server.
671
672 Connecting para_audiod
673 ----------------------
674
675 para_audiod listens on a Unix domain socket. Those sockets are
676 for local communication only, so only local users can connect to
677 para_audiod. The default is to let any user connect but this can be
678 restricted on platforms that support UNIX socket credentials which
679 allow para_audiod to obtain the Unix credentials of the connecting
680 process.
681
682 Use para_audiod's --user-allow option to allow connections only for
683 a limited set of users.
684
685 =======================
686 The audio file selector
687 =======================
688
689 paraslash comes with a sophisticated audio file selector (AFS),
690 whose main task is to determine which file to stream next, based on
691 information on the audio files stored in a database. It communicates
692 also with para_client via the command handler whenever an AFS command
693 is executed, for example to answer a database query.
694
695 Besides the simple playlists, AFS supports audio file selection
696 based on _moods_ which act as a filter that limits the set of all
697 known audio files to those which satisfy certain criteria. It also
698 maintains tables containing images (e.g. album cover art) and lyrics
699 that can be associated with one or more audio files.
700
701 In this chapter we sketch the setup of the [AFS
702 process](#The.AFS.process) during server startup and proceed with the
703 description of the [layout](#Database.layout) of the various database
704 tables. The section on [playlists and moods](#Playlists.and.moods)
705 explains these two audio file selection mechanisms in detail
706 and contains practical examples. The way [file renames and content
707 changes](#File.renames.and.content.changes) are detected is discussed
708 briefly before the [Troubleshooting](#Troubleshooting) section
709 concludes the chapter.
710
711 The AFS process
712 ---------------
713
714 On startup, para_server forks to create the AFS process which opens
715 the database tables. The AFS process accepts incoming connections
716 which arrive either on a pipe which is shared with para_server,
717 or on the local socket it is listening on. The setup is as follows.
718
719 .___________________. .______________.
720 | | | |
721 | virtual streaming | | audio format |
722 | system | | handler |
723 |_________ _______| |_____ ______|
724 \ / \ /
725 | |
726 .-'""""`-. | | .-'""""`-.
727 ( ) | | ( )
728 |`-.____.-'| .__/ \________________/ \___. |`-.____.-'|
729 | | | | | |
730 | file |----| AFS (audio file selector) |----| OSL |
731 | system | | process | | database |
732 | | |___________________________| | |
733 |. ' "" ` .| | |. ' "" ` .|
734 | | | | |
735 `-.____.-' | `-.____.-'
736 ._______/ \_______.
737 | |
738 | command handler |
739 |_______ _______|
740 \ /
741 |
742 |
743 |
744 ._____/ \_____.
745 | |
746 | para_client |
747 |_____________|
748
749 The virtual streaming system, which is part of the server process,
750 communicates with the AFS process via pipes and shared memory. When
751 the current audio file changes, it sends a notification through the
752 shared pipe. The AFS process queries the database to determine the
753 next audio file, opens it, verifies that it has not been changed since
754 it was added to the database and passes the open file descriptor back
755 to the virtual streaming system, along with audio file meta-data such
756 as file name, duration, audio format and so on. The virtual streaming
757 system then starts to stream the file.
758
759 The command handlers of all AFS server commands use the local socket
760 to query or update the database. For example, the command handler of
761 the add command sends the path of an audio file to the local socket.
762 The AFS process opens the file and tries to find an audio format
763 handler which recognizes the file. If all goes well, a new database
764 entry with metadata obtained from the audio format handler is added
765 to the database.
766
767 Note that AFS employs
768 [libosl](http://people.tuebingen.mpg.de/maan/osl/), the object
769 storage layer library, as the database backend. This library offers
770 functionality similar to a relational database, but is much more
771 lightweight than a full featured database management system.
772
773 Database layout
774 ---------------
775
776 Metadata about the known audio files is stored in an OSL database. This
777 database consists of the following tables:
778
779 - The audio file table contains path, hash and metadata of each
780 known file.
781
782 - The "attributes" table maps each of the 64 possible attributes to a
783 string.
784
785 - The "blob" tables store images, lyrics, moods, playlists. All of
786 these are optional.
787
788 - The "score" table describes the subset of admissible files for the
789 current playlist or mood.
790
791 All tables are described in more detail below.
792
793 ### The audio file table ###
794
795 This is the most important and usually also the largest table of the
796 AFS database. It contains the information needed to stream each audio
797 file. In particular the following data is stored for each audio file.
798
799 - SHA1 hash value of the audio file contents. This is computed once
800 when the file is added to the database. Whenever AFS selects this
801 audio file for streaming the hash value is recomputed and checked
802 against the value stored in the database to detect content changes.
803
804 - The time when this audio file was last played.
805
806 - The number of times the file has been played so far.
807
808 - The attribute bitmask.
809
810 - The image id which describes the image associated with this audio
811 file.
812
813 - The lyrics id which describes the lyrics associated with this
814 audio file.
815
816 - The audio format id (MP3, OGG, ...).
817
818 - An amplification value that can be used by the amplification filter
819 to pre-amplify the decoded audio stream.
820
821 - The chunk table. It describes the location and the timing of the
822 building blocks of the audio file. This is used by para_server to
823 send chunks of the file at appropriate times.
824
825 - The duration of the audio file.
826
827 - Tag information contained in the audio file (ID3 tags, Vorbis
828 comments, ...).
829
830 - The number of channels
831
832 - The encoding bitrate.
833
834 - The sampling frequency.
835
836 To add or refresh the data contained in the audio file table, the _add_
837 command is used. It takes the full path of either an audio file or a
838 directory. In the latter case, the directory is traversed recursively
839 and all files which are recognized as valid audio files are added to
840 the database.
841
842 ### The attribute table ###
843
844 The attribute table contains two columns, _name_ and _bitnum_. An
845 attribute is simply a name for a certain bit number in the attribute
846 bitmask of the audio file table.
847
848 Each of the 64 bits of the attribute bitmask can be set for each
849 audio file individually. Hence up to 64 different attributes may be
850 defined. For example, "pop", "rock", "blues", "jazz", "instrumental",
851 "german_lyrics", "speech", whatever. You are free to choose as
852 many attributes as you like and there are no naming restrictions
853 for attributes.
854
855 A new attribute "test" is created by
856
857 para_client addatt test
858 and
859 para_client lsatt
860
861 lists all available attributes. You can set the "test" attribute for
862 an audio file by executing
863
864 para_client setatt test+ /path/to/the/audio/file
865
866 Similarly, the "test" bit can be removed from an audio file with
867
868 para_client setatt test- /path/to/the/audio/file
869
870 Instead of a path you may use a shell wildcard pattern. The attribute
871 is applied to all audio files matching this pattern:
872
873 para_client setatt test+ '/test/directory/*'
874
875 The command
876
877 para_client -- ls -l=v
878
879 gives you a verbose listing of your audio files also showing which
880 attributes are set.
881
882 In case you wonder why the double-dash in the above command is needed:
883 It tells para_client to not interpret the options after the dashes. If
884 you find this annoying, just say
885
886 alias para='para_client --'
887
888 and be happy. In what follows we shall use this alias.
889
890 The "test" attribute can be dropped from the database with
891
892 para rmatt test
893
894 Read the output of
895
896 para help ls
897 para help setatt
898
899 for more information and a complete list of command line options to
900 these commands.
901
902 ### Blob tables ###
903
904 The image, lyrics, moods and playlists tables are all blob tables.
905 Blob tables consist of three columns each: The identifier which is
906 a positive number that is auto-incremented, the name (an arbitrary
907 string) and the content (the blob).
908
909 All blob tables support the same set of actions: cat, ls, mv, rm
910 and add. Of course, _add_ is used for adding new blobs to the table
911 while the other actions have the same meaning as the corresponding
912 Unix commands. The paraslash commands to perform these actions are
913 constructed as the concatenation of the table name and the action. For
914 example addimg, catimg, lsimg, mvimg, rmimg are the commands that
915 manipulate or query the image table.
916
917 The add variant of these commands is special as these commands read
918 the blob contents from stdin. To add an image to the image table the
919 command
920
921 para addimg image_name < file.jpg
922
923 can be used.
924
925 Note that the images and lyrics are not interpreted at all, and also
926 the playlist and the mood blobs are only investigated when the mood
927 or playlist is activated with the select command.
928
929 ### The score table ###
930
931 The score table describes those audio files which are admissible for
932 the current mood or playlist (see below). The table has two columns:
933 a pointer to a row of the audio file table and a score value.
934
935 Unlike all other tables of the database, the score table remains in
936 memory and is never stored on disk. It is initialized at startup and
937 recomputed when the select command loads a new mood or playlist.
938
939 When the audio file selector is asked to open the next audio file,
940 it picks the row with the highest score, opens the corresponding
941 file and passes the file descriptor to the virtual streaming system.
942 At this point the last_played and the num_played fields of the selected
943 file are updated and the score is recomputed.
944
945 Playlists and moods
946 -------------------
947
948 Playlists and moods offer two different ways of specifying the set of
949 admissible files. A playlist in itself describes a set of admissible
950 files. A mood, in contrast, describes the set of admissible files in
951 terms of attributes and other type of information available in the
952 audio file table. As an example, a mood can define a filename pattern,
953 which is then matched against the names of audio files in the table.
954
955 ### Playlists ###
956
957 Playlists are accommodated in the playlist table of the afs database,
958 using the aforementioned blob format for tables. A new playlist is
959 created with the addpl command by specifying the full (absolute)
960 paths of all desired audio files, separated by newlines. Example:
961
962 find /my/mp3/dir -name "*.mp3" | para addpl my_playlist
963
964 If _my_playlist_ already exists it is overwritten. To activate the
965 new playlist, execute
966
967 para select p/my_playlist
968
969 The audio file selector will assign scores to each entry of the list,
970 in descending order so that files will be selected in order. If a
971 file could not be opened for streaming, its entry is removed from
972 the score table (but not from the playlist).
973
974 ### Moods ###
975
976 A mood consists of a unique name and its *mood definition*, which is
977 a set of *mood lines* containing expressions in terms of attributes
978 and other data contained in the database.
979
980 At any time at most one mood can be *active* which means that
981 para_server is going to select only files from that subset of
982 admissible files.
983
984 So in order to create a mood definition one has to write a set of
985 mood lines. Mood lines come in three flavours: Accept lines, deny
986 lines and score lines.
987
988 The general syntax of the three types of mood lines is
989
990
991 accept [with score <score>] [if] [not] <mood_method> [options]
992 deny [with score <score>] [if] [not] <mood_method> [options]
993 score <score> [if] [not] <mood_method> [options]
994
995
996 Here <score> is either an integer or the string "random" which assigns
997 a random score to all matching files. The score value changes the
998 order in which admissible files are going to be selected, but is of
999 minor importance for this introduction.
1000
1001 So we concentrate on the first two forms, i.e. accept and deny
1002 lines. As usual, everything in square brackets is optional, i.e.
1003 accept/deny lines take the following form when ignoring scores:
1004
1005 accept [if] [not] <mood_method> [options]
1006
1007 and analogously for the deny case. The "if" keyword is only syntactic
1008 sugar and has no function. The "not" keyword just inverts the result,
1009 so the essence of a mood line is the mood method part and the options
1010 following thereafter.
1011
1012 A *mood method* is realized as a function which takes an audio file
1013 and computes a number from the data contained in the database.
1014 If this number is non-negative, we say the file *matches* the mood
1015 method. The file matches the full mood line if it either
1016
1017 - matches the mood method and the "not" keyword is not given,
1018 or
1019 - does not match the mood method, but the "not" keyword is given.
1020
1021 The set of admissible files for the whole mood is now defined as those
1022 files which match at least one accept mood line, but no deny mood line.
1023 More formally, an audio file F is admissible if and only if
1024
1025 (F ~ AL1 or F ~ AL2...) and not (F ~ DL1 or F ~ DN2 ...)
1026
1027 where AL1, AL2... are the accept lines, DL1, DL2... are the deny
1028 lines and "~" means "matches".
1029
1030 The cases where no mood lines of accept/deny type are defined need
1031 special treatment:
1032
1033 - Neither accept nor deny lines: This treats all files as
1034 admissible (in fact, that is the definition of the dummy mood
1035 which is activated automatically if no moods are available).
1036
1037 - Only accept lines: A file is admissible iff it matches at
1038 least one accept line:
1039
1040 F ~ AL1 or F ~ AL2 or ...
1041
1042 - Only deny lines: A file is admissible iff it matches no
1043 deny line:
1044
1045 not (F ~ DL1 or F ~ DN2 ...)
1046
1047
1048
1049 ### List of mood_methods ###
1050
1051 no_attributes_set
1052
1053 Takes no arguments and matches an audio file if and only if no
1054 attributes are set.
1055
1056 is_set <attribute_name>
1057
1058 Takes the name of an attribute and matches iff that attribute is set.
1059
1060 path_matches <pattern>
1061
1062 Takes a filename pattern and matches iff the path of the audio file
1063 matches the pattern.
1064
1065 artist_matches <pattern>
1066 album_matches <pattern>
1067 title_matches <pattern>
1068 comment_matches <pattern>
1069
1070 Takes an extended regular expression and matches iff the text of the
1071 corresponding tag of the audio file matches the pattern. If the tag
1072 is not set, the empty string is matched against the pattern.
1073
1074 year ~ <num>
1075 bitrate ~ <num>
1076 frequency ~ <num>
1077 channels ~ <num>
1078 num_played ~ <num>
1079 image_id ~ <num>
1080 lyrics_id ~ <num>
1081
1082 Takes a comparator ~ of the set {<, =, <=, >, >=, !=} and a number
1083 <num>. Matches an audio file iff the condition <val> ~ <num> is
1084 satisfied where val is the corresponding value of the audio file
1085 (value of the year tag, bitrate in kbit/s, etc.).
1086
1087 The year tag is special as its value is undefined if the audio file
1088 has no year tag or the content of the year tag is not a number. Such
1089 audio files never match. Another difference is the special treatment
1090 if the year tag is a two-digit number. In this case either 1900 or
1091 2000 is added to the tag value, depending on whether the number is
1092 greater than 2000 plus the current year.
1093
1094
1095 ### Mood usage ###
1096
1097 To create a new mood called "my_mood", write its definition into
1098 some temporary file, say "tmpfile", and add it to the mood table
1099 by executing
1100
1101 para addmood my_mood < tmpfile
1102
1103 If the mood definition is really short, you may just pipe it to the
1104 client instead of using temporary files. Like this:
1105
1106 echo "$MOOD_DEFINITION" | para addmood my_mood
1107
1108 There is no need to keep the temporary file since you can always use
1109 the catmood command to get it back:
1110
1111 para catmood my_mood
1112
1113 A mood can be activated by executing
1114
1115 para select m/my_mood
1116
1117 Once active, the list of admissible files is shown by the ls command
1118 if the "-a" switch is given:
1119
1120 para ls -a
1121
1122
1123 ### Example mood definition ###
1124
1125 Suppose you have defined attributes "punk" and "rock" and want to define
1126 a mood containing only Punk-Rock songs. That is, an audio file should be
1127 admissible if and only if both attributes are set. Since
1128
1129 punk and rock
1130
1131 is obviously the same as
1132
1133 not (not punk or not rock)
1134
1135 (de Morgan's rule), a mood definition that selects only Punk-Rock
1136 songs is
1137
1138 deny if not is_set punk
1139 deny if not is_set rock
1140
1141
1142
1143 File renames and content changes
1144 --------------------------------
1145
1146 Since the audio file selector knows the SHA1 of each audio file that
1147 has been added to the afs database, it recognizes if the content of
1148 a file has changed, e.g. because an ID3 tag was added or modified.
1149 Also, if a file has been renamed or moved to a different location,
1150 afs will detect that an entry with the same hash value already exists
1151 in the audio file table.
1152
1153 In both cases it is enough to just re-add the new file. In the
1154 first case (file content changed), the audio table is updated, while
1155 metadata such as the num_played and last_played fields, as well as
1156 the attributes, remain unchanged. In the other case, when the file
1157 is moved or renamed, only the path information is updated, all other
1158 data remains as before.
1159
1160 It is possible to change the behaviour of the add command by using the
1161 "-l" (lazy add) or the "-f" (force add) option.
1162
1163 Troubleshooting
1164 ---------------
1165
1166 Use the debug loglevel (-l debug) to show debugging info. All paraslash
1167 executables have a brief online help which is displayed when -h is
1168 given. The --detailed-help option prints the full help text.
1169
1170 If para_server crashed or was killed by SIGKILL (signal 9), it
1171 may refuse to start again because of "dirty osl tables". In this
1172 case you'll have to run the oslfsck program of libosl to fix your
1173 database:
1174
1175 oslfsck -fd ~/.paraslash/afs_database-0.4
1176
1177 However, make sure para_server isn't running before executing oslfsck.
1178
1179 If you don't mind to recreate your database you can start
1180 from scratch by removing the entire database directory, i.e.
1181
1182 rm -rf ~/.paraslash/afs_database-0.4
1183
1184 Be aware that this removes all attribute definitions, all playlists
1185 and all mood definitions and requires to re-initialize the tables.
1186
1187 Although oslfsck fixes inconsistencies in database tables it doesn't
1188 care about the table contents. To check for invalid table contents, use
1189
1190 para_client check
1191
1192 This prints out references to missing audio files as well as invalid
1193 playlists and mood definitions.
1194
1195 Similarly, para_audiod refuses to start if its socket file exists, since
1196 this indicates that another instance of para_audiod is running. After
1197 a crash a stale socket file might remain and you must run
1198
1199 para_audiod --force
1200
1201 once to fix it up.
1202
1203 =======================================
1204 Audio formats and audio format handlers
1205 =======================================
1206
1207 Audio formats
1208 -------------
1209
1210 The following audio formats are supported by paraslash:
1211
1212 ### MP3 ###
1213
1214 Mp3, MPEG-1 Audio Layer 3, is a common audio format for audio storage,
1215 designed as part of its MPEG-1 standard. An MP3 file is made up of
1216 multiple MP3 frames, which consist of a header and a data block. The
1217 size of an MP3 frame depends on the bit rate and on the number
1218 of channels. For a typical CD-audio file (sample rate of 44.1 kHz
1219 stereo), encoded with a bit rate of 128 kbit, an MP3 frame is about
1220 400 bytes large.
1221
1222 ### OGG/Vorbis ###
1223
1224 OGG is a standardized audio container format, while Vorbis is an
1225 open source codec for lossy audio compression. Since Vorbis is most
1226 commonly made available via the OGG container format, it is often
1227 referred to as OGG/Vorbis. The OGG container format divides data into
1228 chunks called OGG pages. A typical OGG page is about 4KB large. The
1229 Vorbis codec creates variable-bitrate (VBR) data, where the bitrate
1230 may vary considerably.
1231
1232 ### OGG/Speex ###
1233
1234 Speex is an open-source speech codec that is based on CELP (Code
1235 Excited Linear Prediction) coding. It is designed for voice
1236 over IP applications, has modest complexity and a small memory
1237 footprint. Wideband and narrowband (telephone quality) speech are
1238 supported. As for Vorbis audio, Speex bit-streams are often stored
1239 in OGG files. As of 2012 this codec is considered obsolete since the
1240 Oppus codec, described below, surpasses its performance in all areas.
1241
1242 ### OGG/Opus ###
1243
1244 Opus is a lossy audio compression format standardized through RFC
1245 6716 in 2012. It combines the speech-oriented SILK codec and the
1246 low-latency CELT (Constrained Energy Lapped Transform) codec. Like
1247 OGG/Vorbis and OGG/Speex, Opus data is usually encapsulated in OGG
1248 containers. All known software patents which cover Opus are licensed
1249 under royalty-free terms.
1250
1251 ### AAC ###
1252
1253 Advanced Audio Coding (AAC) is a standardized, lossy compression
1254 and encoding scheme for digital audio which is the default audio
1255 format for Apple's iPhone, iPod, iTunes. Usually MPEG-4 is used as
1256 the container format and audio files encoded with AAC have the .m4a
1257 extension. A typical AAC frame is about 700 bytes large.
1258
1259 ### WMA ###
1260
1261 Windows Media Audio (WMA) is an audio data compression technology
1262 developed by Microsoft. A WMA file is usually encapsulated in the
1263 Advanced Systems Format (ASF) container format, which also specifies
1264 how meta data about the file is to be encoded. The bit stream of WMA
1265 is composed of superframes, each containing one or more frames of
1266 2048 samples. For 16 bit stereo a WMA superframe is about 8K large.
1267
1268 ### FLAC ###
1269
1270 The Free Lossless Audio Codec (FLAC) compresses audio without quality
1271 loss. It gives better compression ratios than a general purpose
1272 compressor like zip or bzip2 because FLAC is designed specifically
1273 for audio. A FLAC-encoded file consists of frames of varying size, up
1274 to 16K. Each frame starts with a header that contains all information
1275 necessary to decode the frame.
1276
1277 Meta data
1278 ---------
1279
1280 Unfortunately, each audio format has its own conventions how meta
1281 data is added as tags to the audio file.
1282
1283 For MP3 files, ID3, version 1 and 2 are widely used. ID3 version 1
1284 is rather simple but also very limited as it supports only artist,
1285 title, album, year and comment tags. Each of these can only be at most
1286 32 characters long. ID3, version 2 is much more flexible but requires
1287 a separate library being installed for paraslash to support it.
1288
1289 Ogg vorbis, ogg speex and flac files contain meta data as Vorbis
1290 comments, which are typically implemented as strings of the form
1291 "[TAG]=[VALUE]". Unlike ID3 version 1 tags, one may use whichever
1292 tags are appropriate for the content.
1293
1294 AAC files usually use the MPEG-4 container format for storing meta
1295 data while WMA files wrap meta data as special objects within the
1296 ASF container format.
1297
1298 paraslash only tracks the most common tags that are supported by
1299 all tag variants: artist, title, year, album, comment. When a file
1300 is added to the AFS database, the meta data of the file is extracted
1301 and stored in the audio file table.
1302
1303 Chunks and chunk tables
1304 -----------------------
1305
1306 paraslash uses the word "chunk" as common term for the building blocks
1307 of an audio file. For MP3 files, a chunk is the same as an MP3 frame,
1308 while for OGG files a chunk is an OGG page, etc. Therefore the chunk
1309 size varies considerably between audio formats, from a few hundred
1310 bytes (MP3) up to 16K (FLAC).
1311
1312 The chunk table contains the offsets within the audio file that
1313 correspond to the chunk boundaries of the file. Like the meta data,
1314 the chunk table is computed and stored in the database whenever an
1315 audio file is added.
1316
1317 The paraslash senders (see below) always send complete chunks. The
1318 granularity for seeking is therefore determined by the chunk size.
1319
1320 Audio format handlers
1321 ---------------------
1322
1323 For each audio format paraslash contains an audio format handler whose
1324 first task is to tell whether a given file is a valid audio file of
1325 this type. If so, the audio file handler extracts some technical data
1326 (duration, sampling rate, number of channels etc.), computes the
1327 chunk table and reads the meta data.
1328
1329 The audio format handler code is linked into para_server and executed
1330 via the _add_ command. The same code is also available as a stand-alone
1331 tool, para_afh, which prints the technical data, the chunk table
1332 and the meta data of a file. Moreover, all audio format handlers are
1333 combined in the afh receiver which is part of para_recv and para_play.
1334
1335 ==========
1336 Networking
1337 ==========
1338
1339 Paraslash uses different network connections for control and data.
1340 para_client communicates with para_server over a dedicated TCP control
1341 connection. To transport audio data, separate data connections are
1342 used. For these data connections, a variety of transports (UDP, DCCP,
1343 HTTP) can be chosen.
1344
1345 The chapter starts with the [control
1346 service](#The.paraslash.control.service), followed by a section
1347 on the various [streaming protocols](#Streaming.protocols)
1348 in which the data connections are described. The way
1349 audio file headers are embedded into the stream is discussed
1350 [briefly](#Streams.with.headers.and.headerless.streams) before the
1351 [example section](#Networking.examples) which illustrates typical
1352 commands for real-life scenarios.
1353
1354 Both IPv4 and IPv6 are supported.
1355
1356 The paraslash control service
1357 -----------------------------
1358
1359 para_server is controlled at runtime via the paraslash control
1360 connection. This connection is used for server commands (play, stop,
1361 ...) as well as for afs commands (ls, select, ...).
1362
1363 The server listens on a TCP port and accepts connections from clients
1364 that connect the open port. Each connection causes the server to fork
1365 off a client process which inherits the connection and deals with that
1366 client only. In this classical accept/fork approach the server process
1367 is unaffected if the child dies or goes crazy for whatever reason. In
1368 fact, the child process can not change address space of server process.
1369
1370 The section on [client-server
1371 authentication](#Client-server.authentication) above described the
1372 early connection establishment from the crypto point of view. Here
1373 it is described what happens after the connection (including crypto
1374 setup) has been established. There are four processes involved during
1375 command dispatch as sketched in the following diagram.
1376
1377 server_host client_host
1378 ~~~~~~~~~~~ ~~~~~~~~~~~
1379
1380 +-----------+ connect +-----------+
1381 |para_server|<------------------------------ |para_client|
1382 +-----------+ +-----------+
1383 | ^
1384 | fork +---+ |
1385 +----------> |AFS| |
1386 | +---+ |
1387 | ^ |
1388 | | |
1389 | | connect (cookie) |
1390 | | |
1391 | | |
1392 | fork +-----+ inherited connection |
1393 +---------->|child|<--------------------------+
1394 +-----+
1395
1396 Note that the child process is not a child of the afs process,
1397 so communication of these two processes has to happen via local
1398 sockets. In order to avoid abuse of the local socket by unrelated
1399 processes, a magic cookie is created once at server startup time just
1400 before the server process forks off the AFS process. This cookie is
1401 known to the server, AFS and the child, but not to unrelated processes.
1402
1403 There are two different kinds of commands: First there are commands
1404 that cause the server to respond with some answer such as the list
1405 of all audio files. All but the addblob commands (addimg, addlyr,
1406 addpl, addmood) are of this kind. The addblob commands add contents
1407 to the database, so they need to transfer data the other way round,
1408 from the client to the server.
1409
1410 There is no knowledge about the server commands built into para_client,
1411 so it does not know about addblob commands. Instead, the server sends
1412 a special "awaiting data" packet for these commands. If the client
1413 receives this packet, it sends STDIN to the server, otherwise it
1414 dumps data from the server to STDOUT.
1415
1416 Streaming protocols
1417 -------------------
1418
1419 A network (audio) stream usually consists of one streaming source,
1420 the _sender_, and one or more _receivers_ which read data over the
1421 network from the streaming source.
1422
1423 Senders are thus part of para_server while receivers are part of
1424 para_audiod. Moreover, there is the stand-alone tool para_recv which
1425 can be used to manually download a stream, either from para_server
1426 or from a web-based audio streaming service.
1427
1428 The following three streaming protocols are supported by paraslash:
1429
1430 - HTTP. Recommended for public streams that can be played by any
1431 player like mpg123, xmms, itunes, winamp, etc. The HTTP sender is
1432 supported on all operating systems and all platforms.
1433
1434 - DCCP. Recommended for LAN streaming. DCCP is currently available
1435 only for Linux.
1436
1437 - UDP. Recommended for multicast LAN streaming.
1438
1439 See the Appendix on [network protocols](/#Network.protocols)
1440 for brief descriptions of the various protocols relevant for network
1441 audio streaming with paraslash.
1442
1443 It is possible to activate more than one sender simultaneously.
1444 Senders can be controlled at run time and via config file and command
1445 line options.
1446
1447 Note that audio connections are _not_ encrypted. Transport or Internet
1448 layer encryption should be used if encrypted data connections are
1449 needed.
1450
1451 Since DCCP and TCP are both connection-oriented protocols, connection
1452 establishment/teardown and access control are very similar between
1453 these two streaming protocols. UDP is the most lightweight option,
1454 since in contrast to TCP/DCCP it is connectionless. It is also the
1455 only protocol supporting IP multicast.
1456
1457 The HTTP and the DCCP sender listen on a (TCP/DCCP) port waiting for
1458 clients to connect and establish a connection via some protocol-defined
1459 handshake mechanism. Both senders maintain two linked lists each:
1460 The list of all clients which are currently connected, and the list
1461 of access control entries which determines who is allowed to connect.
1462 IP-based access control may be configured through config file and
1463 command line options and via the "allow" and "deny" sender subcommands.
1464
1465 Upon receiving a GET request from the client, the HTTP sender sends
1466 back a status line and a message. The body of this message is the
1467 audio stream. This is common practice and is supported by many popular
1468 clients which can thus be used to play a stream offered by para_server.
1469 For DCCP things are a bit simpler: No messages are exchanged between
1470 the receiver and sender. The client simply connects and the sender
1471 starts to stream.
1472
1473 DCCP is an experimental protocol which offers a number of new features
1474 not available for TCP. Both ends can negotiate these features using
1475 a built-in negotiation mechanism. In contrast to TCP/HTTP, DCCP is
1476 datagram-based (no retransmissions) and thus should not be used over
1477 lossy media (e.g. WiFi networks). One useful feature offered by DCCP
1478 is access to a variety of different congestion-control mechanisms
1479 called CCIDs. Two different CCIDs are available per default on Linux:
1480
1481
1482 - _CCID 2_. A Congestion Control mechanism similar to that of TCP. The
1483 sender maintains a congestion window and halves this window in response
1484 to congestion.
1485
1486
1487 - _CCID-3_. Designed to be fair when competing for bandwidth.
1488 It has lower variation of throughput over time compared with TCP,
1489 which makes it suitable for streaming media.
1490
1491 Unlike the HTTP and DCCP senders, the UDP sender maintains only a
1492 single list, the _target list_. This list describes the set of clients
1493 to which the stream is sent. There is no list for access control and
1494 no "allow" and "deny" commands for the UDP sender. Instead, the "add"
1495 and "delete" commands can be used to modify the target list.
1496
1497 Since both UDP and DCCP offer an unreliable datagram-based transport,
1498 additional measures are necessary to guard against disruptions over
1499 networks that are lossy or which may be subject to interference (as
1500 is for instance the case with WiFi). Paraslash uses FEC (Forward
1501 Error Correction) to guard against packet losses and reordering. The
1502 stream is FEC-encoded before it is sent through the UDP socket and
1503 must be decoded accordingly on the receiver side.
1504
1505 The packet size and the amount of redundancy introduced by FEC can
1506 be configured via the FEC parameters which are dictated by server
1507 and may also be configured through the "sender" command. The FEC
1508 parameters are encoded in the header of each network packet, so no
1509 configuration is necessary on the receiver side. See the section on
1510 [FEC](#Forward.error.correction) below.
1511
1512 Streams with headers and headerless streams
1513 -------------------------------------------
1514
1515 For OGG/Vorbis, OGG/Speex and wma streams, some of the information
1516 needed to decode the stream is only contained in the audio file
1517 header of the container format but not in each data chunk. Clients
1518 must be able to obtain this information in case streaming starts in
1519 the middle of the file or if para_audiod is started while para_server
1520 is already sending a stream.
1521
1522 This is accomplished in different ways, depending on the streaming
1523 protocol. For connection-oriented streams (HTTP, DCCP) the audio file
1524 header is sent prior to audio file data. This technique however does
1525 not work for the connectionless UDP transport. Hence the audio file
1526 header is periodically being embedded into the UDP audio data stream.
1527 By default, the header is resent after five seconds. The receiver has
1528 to wait until the next header arrives before it can start decoding
1529 the stream.
1530
1531 Networking examples
1532 -------------------
1533
1534 The "si" (server info) command lists some information about the
1535 currently running server process.
1536
1537 -> Show PIDs, number of connected clients, uptime, and more:
1538
1539 para_client si
1540
1541 The sender command of para_server prints information about senders,
1542 like the various access control lists, and it allows to (de-)activate
1543 senders and to change the access permissions at runtime.
1544
1545 -> List all senders
1546
1547 para_client sender
1548
1549 -> Obtain general help for the sender command:
1550
1551 para_client help sender
1552
1553 -> Get help for a specific sender (contains further examples):
1554
1555 s=http # or dccp or udp
1556 para_client sender $s help
1557
1558 -> Show status of the http sender
1559
1560 para_client sender http status
1561
1562 By default para_server activates both the HTTP and th DCCP sender on
1563 startup. This can be changed via command line options or para_server's
1564 config file.
1565
1566 -> List config file options for senders:
1567
1568 para_server -h
1569
1570 All senders share the "on" and "off" commands, so senders may be
1571 activated and deactivated independently of each other.
1572
1573 -> Switch off the http sender:
1574
1575 para_client sender http off
1576
1577 -> Receive a DCCP stream using CCID2 and write the output into a file:
1578
1579 host=foo.org; ccid=2; filename=bar
1580 para_recv --receiver "dccp --host $host --ccid $ccid" > $filename
1581
1582 Note the quotes around the arguments for the dccp receiver. Each
1583 receiver has its own set of command line options and its own command
1584 line parser, so arguments for the dccp receiver must be protected
1585 from being interpreted by para_recv.
1586
1587 -> Start UDP multicast, using the default multicast address:
1588
1589 para_client sender udp add 224.0.1.38
1590
1591 -> Receive FEC-encoded multicast stream and write the output into a file:
1592
1593 filename=foo
1594 para_recv -r udp > $filename
1595
1596 -> Add an UDP unicast for a client to the target list of the UDP sender:
1597
1598 t=client.foo.org
1599 para_client sender udp add $t
1600
1601 -> Receive this (FEC-encoded) unicast stream:
1602
1603 filename=foo
1604 para_recv -r 'udp -i 0.0.0.0' > $filename
1605
1606 -> Create a minimal config for para_audiod for HTTP streams:
1607
1608 c=$HOME/.paraslash/audiod.conf.min; s=server.foo.com
1609 echo receiver \".:http -i $s\" > $c
1610 para_audiod --config $c
1611
1612 =======
1613 Filters
1614 =======
1615
1616 A paraslash filter is a module which transforms an input stream into
1617 an output stream. Filters are included in the para_audiod executable
1618 and in the stand-alone tool para_filter which usually contains the
1619 same modules.
1620
1621 While para_filter reads its input stream from STDIN and writes
1622 the output to STDOUT, the filter modules of para_audiod are always
1623 connected to a receiver which produces the input stream and a writer
1624 which absorbs the output stream.
1625
1626 Some filters depend on a specific library and are not compiled in
1627 if this library was not found at compile time. To see the list of
1628 supported filters, run para_filter and para_audiod with the --help
1629 option. The output looks similar to the following:
1630
1631 Available filters:
1632 compress wav amp fecdec wmadec prebuffer oggdec aacdec mp3dec
1633
1634 Out of these filter modules, a chain of filters can be constructed,
1635 much in the way Unix pipes can be chained, and analogous to the use
1636 of modules in gstreamer: The output of the first filter becomes the
1637 input of the second filter. There is no limitation on the number of
1638 filters and the same filter may occur more than once.
1639
1640 Like receivers, each filter has its own command line options which
1641 must be quoted to protect them from the command line options of
1642 the driving application (para_audiod or para_filter). Example:
1643
1644 para_filter -f 'mp3dec --ignore-crc' -f 'compress --damp 1'
1645
1646 For para_audiod, each audio format has its own set of filters. The
1647 name of the audio format for which the filter should be applied can
1648 be used as the prefix for the filter option. Example:
1649
1650 para_audiod -f 'mp3:prebuffer --duration 300'
1651
1652 The "mp3" prefix above is actually interpreted as a POSIX extended
1653 regular expression. Therefore
1654
1655 para_audiod -f '.:prebuffer --duration 300'
1656
1657 activates the prebuffer filter for all supported audio formats (because
1658 "." matches all audio formats) while
1659
1660 para_audiod -f 'wma|ogg:prebuffer --duration 300'
1661
1662 activates it only for wma and ogg streams.
1663
1664 Decoders
1665 --------
1666
1667 For each supported audio format there is a corresponding filter
1668 which decodes audio data in this format to 16 bit PCM data which
1669 can be directly sent to the sound device or any other software that
1670 operates on undecoded PCM data (visualizers, equalizers etc.). Such
1671 filters are called _decoders_ in general, and xxxdec is the name of
1672 the paraslash decoder for the audio format xxx. For example, the mp3
1673 decoder is called mp3dec.
1674
1675 Note that the output of the decoder is about 10 times larger than
1676 its input. This means that filters that operate on the decoded audio
1677 stream have to deal with much more data than filters that transform
1678 the audio stream before it is fed to the decoder.
1679
1680 Paraslash relies on external libraries for most decoders, so these
1681 libraries must be installed for the decoder to be included in the
1682 executables. For example, the mp3dec filter depends on the mad library.
1683
1684 Forward error correction
1685 ------------------------
1686
1687 As already mentioned [earlier](#Streaming.protocols), paraslash
1688 uses forward error correction (FEC) for the unreliable UDP and
1689 DCCP transports. FEC is a technique which was invented already in
1690 1960 by Reed and Solomon and which is widely used for the parity
1691 calculations of storage devices (RAID arrays). It is based on the
1692 algebraic concept of finite fields, today called Galois fields, in
1693 honour of the mathematician Galois (1811-1832). The FEC implementation
1694 of paraslash is based on code by Luigi Rizzo.
1695
1696 Although the details require a sound knowledge of the underlying
1697 mathematics, the basic idea is not hard to understand: For positive
1698 integers k and n with k < n it is possible to compute for any k given
1699 data bytes d_1, ..., d_k the corresponding r := n -k parity bytes p_1,
1700 ..., p_r such that all data bytes can be reconstructed from *any*
1701 k bytes of the set
1702
1703 {d_1, ..., d_k, p_1, ..., p_r}.
1704
1705 FEC-encoding for unreliable network transports boils down to slicing
1706 the audio stream into groups of k suitably sized pieces called _slices_
1707 and computing the r corresponding parity slices. This step is performed
1708 in para_server which then sends both the data and the parity slices
1709 over the unreliable network connection. If the client was able
1710 to receive at least k of the n = k + r slices, it can reconstruct
1711 (FEC-decode) the original audio stream.
1712
1713 From these observations it is clear that there are three different
1714 FEC parameters: The slice size, the number of data slices k, and the
1715 total number of slices n. It is crucial to choose the slice size
1716 such that no fragmentation of network packets takes place because
1717 FEC only guards against losses and reordering but fails if slices are
1718 received partially.
1719
1720 FEC decoding in paralash is performed through the fecdec filter which
1721 usually is the first filter (there can be other filters before fecdec
1722 if these do not alter the audio stream).
1723
1724 Volume adjustment (amp and compress)
1725 ------------------------------------
1726
1727 The amp and the compress filter both adjust the volume of the audio
1728 stream. These filters operate on uncompressed audio samples. Hence
1729 they are usually placed directly after the decoding filter. Each
1730 sample is multiplied with a scaling factor (>= 1) which makes amp
1731 and compress quite expensive in terms of computing power.
1732
1733 ### amp ###
1734
1735 The amp filter amplifies the audio stream by a fixed scaling factor
1736 that must be known in advance. For para_audiod this factor is derived
1737 from the amplification field of the audio file's entry in the audio
1738 file table while para_filter uses the value given at the command line.
1739
1740 The optimal scaling factor F for an audio file is the largest real
1741 number F >= 1 such that after multiplication with F all samples still
1742 fit into the sample interval [-32768, 32767]. One can use para_filter
1743 in combination with the sox utility to compute F:
1744
1745 para_filter -f mp3dec -f wav < file.mp3 | sox -t wav - -e stat -v
1746
1747 The amplification value V which is stored in the audio file table,
1748 however, is an integer between 0 and 255 which is connected to F
1749 through the formula
1750
1751 V = (F - 1) * 64.
1752
1753 To store V in the audio file table, the command
1754
1755 para_client -- touch -a=V file.mp3
1756
1757 is used. The reader is encouraged to write a script that performs
1758 these computations :)
1759
1760 ### compress ###
1761
1762 Unlike the amplification filter, the compress filter adjusts the volume
1763 of the audio stream dynamically without prior knowledge about the peak
1764 value. It maintains the maximal volume of the last n samples of the
1765 audio stream and computes a suitable amplification factor based on that
1766 value and the various configuration options. It tries to chose this
1767 factor such that the adjusted volume meets the desired target level.
1768
1769 Note that it makes sense to combine amp and compress.
1770
1771 Misc filters (wav and prebuffer)
1772 --------------------------------
1773
1774 These filters are rather simple and do not modify the audio stream at
1775 all. The wav filter is only useful with para_filter and in connection
1776 with a decoder. It asks the decoder for the number of channels and the
1777 sample rate of the stream and adds a Microsoft wave header containing
1778 this information at the beginning. This allows to write wav files
1779 rather than raw PCM files (which do not contain any information about
1780 the number of channels and the sample rate).
1781
1782 The prebuffer filter simply delays the output until the given time has
1783 passed (starting from the time the first byte was available in its
1784 input queue) or until the given amount of data has accumulated. It
1785 is mainly useful for para_audiod if the standard parameters result
1786 in buffer underruns.
1787
1788 Both filters require almost no additional computing time, even when
1789 operating on uncompressed audio streams, since data buffers are simply
1790 "pushed down" rather than copied.
1791
1792 Examples
1793 --------
1794
1795 -> Decode an mp3 file to wav format:
1796
1797 para_filter -f mp3dec -f wav < file.mp3 > file.wav
1798
1799 -> Amplify a raw audio file by a factor of 1.5:
1800
1801 para_filter -f amp --amp 32 < foo.raw > bar.raw
1802
1803 ======
1804 Output
1805 ======
1806
1807 Once an audio stream has been received and decoded to PCM format,
1808 it can be sent to a sound device for playback. This part is performed
1809 by paraslash _writers_ which are described in this chapter.
1810
1811 Writers
1812 -------
1813
1814 A paraslash writer acts as a data sink that consumes but does not
1815 produce audio data. Paraslash writers operate on the client side and
1816 are contained in para_audiod and in the stand-alone tool para_write.
1817
1818 The para_write program reads uncompressed audio data from STDIN. If
1819 this data starts with a wav header, sample rate, sample format and
1820 channel count are read from the header. Otherwise CD audio (44.1KHz
1821 16 bit little endian, stereo) is assumed but this can be overridden
1822 by command line options. para_audiod, on the other hand, obtains
1823 the sample rate and the number of channels from the decoder.
1824
1825 Like receivers and filters, each writer has an individual set of
1826 command line options, and for para_audiod writers can be configured
1827 per audio format separately. It is possible to activate more than
1828 one writer for the same stream simultaneously.
1829
1830 OS-dependent APIs
1831 -----------------
1832
1833 Unfortunately, the various flavours of Unix on which paraslash
1834 runs on have different APIs for opening a sound device and starting
1835 playback. Hence for each such API there is a paraslash writer that
1836 can play the audio stream via this API.
1837
1838 - *ALSA*. The _Advanced Linux Sound Architecture_ is only available on
1839 Linux systems. Although there are several mid-layer APIs in use by
1840 the various Linux distributions (ESD, Jack, PulseAudio), paraslash
1841 currently supports only the low-level ALSA API which is not supposed
1842 to be change. ALSA is very feature-rich, in particular it supports
1843 software mixing via its DMIX plugin. ALSA is the default writer on
1844 Linux systems.
1845
1846 - *OSS*. The _Open Sound System_ is the only API on \*BSD Unixes and
1847 is also available on Linux systems, usually provided by ALSA as an
1848 emulation for backwards compatibility. This API is rather simple but
1849 also limited. For example only one application can open the device
1850 at any time. The OSS writer is activated by default on BSD Systems.
1851
1852 - *FILE*. The file writer allows to capture the audio stream and
1853 write the PCM data to a file on the file system rather than playing
1854 it through a sound device. It is supported on all platforms and is
1855 always compiled in.
1856
1857 - *AO*. _Libao_ is a cross-platform audio library which supports a wide
1858 variety of platforms including PulseAudio (gnome), ESD (Enlightened
1859 Sound Daemon), AIX, Solaris and IRIX. The ao writer plays audio
1860 through an output plugin of libao.
1861
1862 Examples
1863 --------
1864
1865 -> Use the OSS writer to play a wav file:
1866
1867 para_write --writer oss < file.wav
1868
1869 -> Enable ALSA software mixing for mp3 streams:
1870
1871 para_audiod --writer 'mp3:alsa -d plug:swmix'
1872
1873
1874 ===
1875 Gui
1876 ===
1877
1878 para_gui executes an arbitrary command which is supposed to print
1879 status information to STDOUT. It then displays this information in
1880 a curses window. By default the command
1881
1882 para_audioc -- stat -p
1883
1884 is executed, but this can be customized via the --stat-cmd option. In
1885 particular it possible to use
1886
1887 para_client -- stat -p
1888
1889 to make para_gui work on systems on which para_audiod is not running.
1890
1891 Key bindings
1892 ------------
1893
1894 It is possible to bind keys to arbitrary commands via custom
1895 key-bindings. Besides the internal keys which can not be changed (help,
1896 quit, loglevel, version...), the following flavours of key-bindings
1897 are supported:
1898
1899 - external: Shutdown curses before launching the given command.
1900 Useful for starting other ncurses programs from within para_gui,
1901 e.g. aumix or dialog scripts. Or, use the mbox output format to write
1902 a mailbox containing one mail for each (admissible) file the audio
1903 file selector knows about. Then start mutt from within para_gui to
1904 browse your collection!
1905
1906 - display: Launch the command and display its stdout in para_gui's
1907 bottom window.
1908
1909 - para: Like display, but start "para_client <specified command>"
1910 instead of "<specified command>".
1911
1912 The general form of a key binding is
1913
1914 key_map k:m:c
1915
1916 which maps key k to command c using mode m. Mode may be x, d or p
1917 for external, display and paraslash commands, respectively.
1918
1919 Themes
1920 ------
1921
1922 Currently there are only two themes for para_gui. It is easy, however,
1923 to add more themes. To create a new theme one has to define the
1924 position, color and geometry for for each status item that should be
1925 shown by this theme. See gui_theme.c for examples.
1926
1927 The "." and "," keys are used to switch between themes.
1928
1929 Examples
1930 --------
1931
1932 -> Show server info:
1933
1934 key_map "i:p:si"
1935
1936 -> Jump to the middle of the current audio file by pressing F5:
1937
1938 key_map "<F5>:p:jmp 50"
1939
1940 -> vi-like bindings for jumping around:
1941
1942 key_map "l:p:ff 10"
1943 key_map "h:p:ff 10-"
1944 key_map "w:p:ff 60"
1945 key_map "b:p:ff 60-"
1946
1947 -> Print the current date and time:
1948
1949 key_map "D:d:date"
1950
1951 -> Call other curses programs:
1952
1953 key_map "U:x:aumix"
1954 key_map "!:x:/bin/bash"
1955 key_map "^E:x:/bin/sh -c 'vi ~/.paraslash/gui.conf'"
1956
1957 ===========
1958 Development
1959 ===========
1960
1961 Contributing
1962 ------------
1963
1964 Paraslash is an open source project and contributions are
1965 welcome. Here's a list of things you can do to help the project:
1966
1967 - Report problems with building, installing or running the software.
1968 In particular, test the experimental git branches ("next" and "pu").
1969 This helps to identify and fix problems before the code gets merged
1970 and thus keeps the master branch as stable as possible.
1971 - Proofread the documentation (manual, web pages, man pages, source
1972 code documentation) and point out unclear or poorly written parts. If
1973 you are a native English speaker you will easily find a lot of text
1974 that could be improved.
1975 - Run analysis tools (coverity, afl, sparse, etc.) and report issues
1976 found by those tools.
1977 - Suggest new features you would like to see implemented.
1978 - Compile and test on your favorite architecture or operating
1979 system. The code is tested only on a limited set of systems, so you
1980 will probably encounter problems when building on different systems.
1981 - Post about about paraslash on your blog or on social networks.
1982 - Build and maintain Debian/RPM packages for your favorite distribution.
1983
1984 Note that there is no mailing list, no bug tracker and no discussion
1985 forum for paraslash. If you'd like to contribute, or have questions
1986 about contributing, send email to Andre Noll <maan@tuebingen.mpg.de>.
1987
1988 Tools
1989 -----
1990
1991 In order to compile the sources from the git repository (rather than
1992 from tar balls) and for contributing non-trivial changes to the
1993 paraslash project, some additional tools should be installed on a
1994 developer machine.
1995
1996 - [git](http://git.or.cz/). As described in more detail
1997 [below](#Git.branches), the git source code management tool is used for
1998 paraslash development. It is necessary for cloning the git repository
1999 and for getting updates.
2000
2001 - [autoconf](ftp://ftp.gnu.org/pub/gnu/autoconf/) GNU autoconf creates
2002 the configure file which is shipped in the tarballs but has to be
2003 generated when compiling from git.
2004
2005 - [discount](http://www.pell.portland.or.us/~orc/Code/discount). The
2006 HTML version of this manual and some of the paraslash web pages are
2007 written in the Markdown markup language and are translated into html
2008 with the converter of the *Discount* package.
2009
2010 - [doxygen](http://www.stack.nl/~dimitri/doxygen/). The documentation
2011 of paraslash's C sources uses the doxygen documentation system. The
2012 conventions for documenting the source code is described in the
2013 [Doxygen section](#Doxygen).
2014
2015 - [global](ftp://ftp.gnu.org/pub/gnu/global). This is used to generate
2016 browsable HTML from the C sources. It is needed by doxygen.
2017
2018 Git branches
2019 ------------
2020
2021 Paraslash has been developed using the git source code management
2022 tool since 2006. Development is organized roughly in the same spirit
2023 as the git development itself, as described below.
2024
2025 The following text passage is based on "A note from the maintainer",
2026 written by Junio C Hamano, the maintainer of git.
2027
2028 There are four branches in the paraslash repository that track the
2029 source tree: "master", "maint", "next", and "pu".
2030
2031 The "master" branch is meant to contain what is well tested and
2032 ready to be used in a production setting. There could occasionally be
2033 minor breakages or brown paper bag bugs but they are not expected to
2034 be anything major, and more importantly quickly and easily fixable.
2035 Every now and then, a "feature release" is cut from the tip of this
2036 branch, named with three dotted decimal digits, like 0.4.2.
2037
2038 Whenever changes are about to be included that will eventually lead to
2039 a new major release (e.g. 0.5.0), a "maint" branch is forked off from
2040 "master" at that point. Obvious, safe and urgent fixes after the major
2041 release are applied to this branch and maintenance releases are cut
2042 from it. New features never go to this branch. This branch is also
2043 merged into "master" to propagate the fixes forward.
2044
2045 A trivial and safe enhancement goes directly on top of "master".
2046 New development does not usually happen on "master", however.
2047 Instead, a separate topic branch is forked from the tip of "master",
2048 and it first is tested in isolation; Usually there are a handful such
2049 topic branches that are running ahead of "master". The tip of these
2050 branches is not published in the public repository to keep the number
2051 of branches that downstream developers need to worry about low.
2052
2053 The quality of topic branches varies widely. Some of them start out as
2054 "good idea but obviously is broken in some areas" and then with some
2055 more work become "more or less done and can now be tested by wider
2056 audience". Luckily, most of them start out in the latter, better shape.
2057
2058 The "next" branch is to merge and test topic branches in the latter
2059 category. In general, this branch always contains the tip of "master".
2060 It might not be quite rock-solid production ready, but is expected to
2061 work more or less without major breakage. The maintainer usually uses
2062 the "next" version of paraslash for his own pleasure, so it cannot
2063 be _that_ broken. The "next" branch is where new and exciting things
2064 take place.
2065
2066 The two branches "master" and "maint" are never rewound, and "next"
2067 usually will not be either (this automatically means the topics that
2068 have been merged into "next" are usually not rebased, and you can find
2069 the tip of topic branches you are interested in from the output of
2070 "git log next"). You should be able to safely build on top of them.
2071
2072 However, at times "next" will be rebuilt from the tip of "master" to
2073 get rid of merge commits that will never be in "master". The commit
2074 that replaces "next" will usually have the identical tree, but it
2075 will have different ancestry from the tip of "master".
2076
2077 The "pu" (proposed updates) branch bundles the remainder of the
2078 topic branches. The "pu" branch, and topic branches that are only in
2079 "pu", are subject to rebasing in general. By the above definition
2080 of how "next" works, you can tell that this branch will contain quite
2081 experimental and obviously broken stuff.
2082
2083 When a topic that was in "pu" proves to be in testable shape, it
2084 graduates to "next". This is done with
2085
2086 git checkout next
2087 git merge that-topic-branch
2088
2089 Sometimes, an idea that looked promising turns out to be not so good
2090 and the topic can be dropped from "pu" in such a case.
2091
2092 A topic that is in "next" is expected to be polished to perfection
2093 before it is merged to "master". Similar to the above, this is
2094 done with
2095
2096 git checkout master
2097 git merge that-topic-branch
2098 git branch -d that-topic-branch
2099
2100 Note that being in "next" is not a guarantee to appear in the next
2101 release (being in "master" is such a guarantee, unless it is later
2102 found seriously broken and reverted), nor even in any future release.
2103
2104 Coding Style
2105 ------------
2106
2107 The preferred coding style for paraslash coincides more or less
2108 with the style of the Linux kernel. So rather than repeating what is
2109 written [there](http://www.kernel.org/doc/Documentation/process/coding-style.rst),
2110 here are the most important points.
2111
2112 - Burn the GNU coding standards.
2113 - Never use spaces for indentation.
2114 - Tabs are 8 characters, and thus indentations are also 8 characters.
2115 - Don't put multiple assignments on a single line.
2116 - Avoid tricky expressions.
2117 - Don't leave whitespace at the end of lines.
2118 - The limit on the length of lines is 80 columns.
2119 - Use K&R style for placing braces and spaces:
2120
2121 if (x is true) {
2122 we do y
2123 }
2124
2125 - Use a space after (most) keywords.
2126 - Do not add spaces around (inside) parenthesized expressions.
2127 - Use one space around (on each side of) most binary and ternary operators.
2128 - Do not use cute names like ThisVariableIsATemporaryCounter, call it tmp.
2129 - Mixed-case names are frowned upon.
2130 - Descriptive names for global variables are a must.
2131 - Avoid typedefs.
2132 - Functions should be short and sweet, and do just one thing.
2133 - The number of local variables shouldn't exceed 10.
2134 - Gotos are fine if they improve readability and reduce nesting.
2135 - Don't use C99-style "// ..." comments.
2136 - Names of macros defining constants and labels in enums are capitalized.
2137 - Enums are preferred when defining several related constants.
2138 - Always use the paraslash wrappers for allocating memory.
2139 - If the name of a function is an action or an imperative.
2140 command, the function should return an error-code integer
2141 (<0 means error, >=0 means success). If the name is a
2142 predicate, the function should return a "succeeded" boolean.
2143
2144 Doxygen
2145 -------
2146
2147 Doxygen is a documentation system for various programming
2148 languages. The API reference on the paraslash web page is generated
2149 by doxygen.
2150
2151 It is more illustrative to look at the source code for examples than
2152 to describe the conventions in this manual, so we only describe which
2153 parts of the code need doxygen comments, but leave out details on
2154 documentation conventions.
2155
2156 As a rule, only the public part of the C source is documented with
2157 Doxygen. This includes structures, defines and enumerations in header
2158 files as well as public (non-static) C functions. These should be
2159 documented completely. For example, each parameter and the return
2160 value of a public function should get a descriptive doxygen comment.
2161
2162 No doxygen comments are necessary for static functions and for
2163 structures and enumerations in C files (which are used only within
2164 this file). This does not mean, however, that those entities need
2165 no documentation at all. Instead, common sense should be applied to
2166 document what is not obvious from reading the code.
2167
2168 ========
2169 Appendix
2170 ========
2171
2172 Network protocols
2173 -----------------
2174
2175 ### IP ###
2176
2177 The _Internet Protocol_ is the primary networking protocol used for
2178 the Internet. All protocols described below use IP as the underlying
2179 layer. Both the prevalent IPv4 and the next-generation IPv6 variant
2180 are being deployed actively worldwide.
2181
2182 ### Connection-oriented and connectionless protocols ###
2183
2184 Connectionless protocols differ from connection-oriented ones in
2185 that state associated with the sending/receiving endpoints is treated
2186 implicitly. Connectionless protocols maintain no internal knowledge
2187 about the state of the connection. Hence they are not capable of
2188 reacting to state changes, such as sudden loss or congestion on the
2189 connection medium. Connection-oriented protocols, in contrast, make
2190 this knowledge explicit. The connection is established only after
2191 a bidirectional handshake which requires both endpoints to agree
2192 on the state of the connection, and may also involve negotiating
2193 specific parameters for the particular connection. Maintaining an
2194 up-to-date internal state of the connection also in general means
2195 that the sending endpoints perform congestion control, adapting to
2196 qualitative changes of the connection medium.
2197
2198 ### Reliability ###
2199
2200 In IP networking, packets can be lost, duplicated, or delivered
2201 out of order, and different network protocols handle these
2202 problems in different ways. We call a transport-layer protocol
2203 _reliable_, if it turns the unreliable IP delivery into an ordered,
2204 duplicate- and loss-free delivery of packets. Sequence numbers
2205 are used to discard duplicates and re-arrange packets delivered
2206 out-of-order. Retransmission is used to guarantee loss-free
2207 delivery. Unreliable protocols, in contrast, do not guarantee ordering
2208 or data integrity.
2209
2210 ### Classification ###
2211
2212 With these definitions the protocols which are used by paraslash for
2213 steaming audio data may be classified as follows.
2214
2215 - HTTP/TCP: connection-oriented, reliable,
2216 - UDP: connectionless, unreliable,
2217 - DCCP: connection-oriented, unreliable.
2218
2219 Below we give a short descriptions of these protocols.
2220
2221 ### TCP ###
2222
2223 The _Transmission Control Protocol_ provides reliable, ordered delivery
2224 of a stream and a classic window-based congestion control. In contrast
2225 to UDP and DCCP (see below), TCP does not have record-oriented or
2226 datagram-based syntax, i.e. it provides a stream which is unaware
2227 and independent of any record (packet) boundaries. TCP is used
2228 extensively by many application layers. Besides HTTP (the Hypertext
2229 Transfer Protocol), also FTP (the File Transfer protocol), SMTP (Simple
2230 Mail Transfer Protocol), SSH (Secure Shell) all sit on top of TCP.
2231
2232 ### UDP ###
2233
2234 The _User Datagram Protocol_ is the simplest transport-layer protocol,
2235 built as a thin layer directly on top of IP. For this reason, it offers
2236 the same best-effort service as IP itself, i.e. there is no detection
2237 of duplicate or reordered packets. Being a connectionless protocol,
2238 only minimal internal state about the connection is maintained, which
2239 means that there is no protection against packet loss or network
2240 congestion. Error checking and correction (if at all) are performed
2241 in the application.
2242
2243 ### DCCP ###
2244
2245 The _Datagram Congestion Control Protocol_ combines the
2246 connection-oriented state maintenance known from TCP with the
2247 unreliable, datagram-based transport of UDP. This means that it
2248 is capable of reacting to changes in the connection by performing
2249 congestion control, offering multiple alternative approaches. But it
2250 is bound to datagram boundaries (the maximum packet size supported
2251 by a medium), and like UDP it lacks retransmission to protect
2252 against loss. Due to the use of sequence numbers, it is however
2253 able to react to loss (interpreted as a congestion indication) and
2254 to ignore out-of-order and duplicate packets. Unlike TCP it allows
2255 to negotiate specific, binding features for a connection, such as
2256 the choice of congestion control: classic, window-based congestion
2257 control known from TCP is available as CCID-2, rate-based, "smooth"
2258 congestion control is offered as CCID-3.
2259
2260 ### HTTP ###
2261
2262 The _Hypertext Transfer Protocol_ is an application layer protocol
2263 on top of TCP. It is spoken by web servers and is most often used
2264 for web services. However, as can be seen by the many Internet radio
2265 stations and YouTube/Flash videos, http is by far not limited to the
2266 delivery of web pages only. Being a simple request/response based
2267 protocol, the semantics of the protocol also allow the delivery of
2268 multimedia content, such as audio over http.
2269
2270 ### Multicast ###
2271
2272 IP multicast is not really a protocol but a technique for one-to-many
2273 communication over an IP network. The challenge is to deliver
2274 information to a group of destinations simultaneously using the
2275 most efficient strategy to send the messages over each link of the
2276 network only once. This has benefits for streaming multimedia: the
2277 standard one-to-one unicast offered by TCP/DCCP means that n clients
2278 listening to the same stream also consume n-times the resources,
2279 whereas multicast requires to send the stream just once, irrespective
2280 of the number of receivers. Since it would be costly to maintain state
2281 for each listening receiver, multicast often implies connectionless
2282 transport, which is the reason that it is currently only available
2283 via UDP.
2284
2285 Abstract socket namespace
2286 -------------------------
2287 UNIX domain sockets are a traditional way to communicate between
2288 processes on the same machine. They are always reliable (see above)
2289 and don't reorder datagrams. Unlike TCP and UDP, UNIX domain sockets
2290 support passing open file descriptors or process credentials to
2291 other processes.
2292
2293 The usual way to set up a UNIX domain socket (as obtained from
2294 socket(2)) for listening is to first bind the socket to a file system
2295 pathname and then call listen(2), then accept(2). Such sockets are
2296 called _pathname sockets_ because bind(2) creates a special socket
2297 file at the specified path. Pathname sockets allow unrelated processes
2298 to communicate with the listening process by binding to the same path
2299 and calling connect(2).
2300
2301 There are two problems with pathname sockets:
2302
2303 * The listing process must be able to (safely) create the
2304 socket special in a directory which is also accessible to
2305 the connecting process.
2306
2307 * After an unclean shutdown of the listening process, a stale
2308 socket special may reside on the file system.
2309
2310 The abstract socket namespace is a non-portable Linux feature which
2311 avoids these problems. Abstract sockets are still bound to a name,
2312 but the name has no connection with file system pathnames.
2313
2314 License
2315 -------
2316
2317 Paraslash is licensed under the GPL, version 2. Most of the code
2318 base has been written from scratch, and those parts are GPL V2
2319 throughout. Notable exceptions are FEC and the WMA decoder. See the
2320 corresponding source files for licencing details for these parts. Some
2321 code sniplets of several other third party software packages have
2322 been incorporated into the paraslash sources, for example log message
2323 coloring was taken from the git sources. These third party software
2324 packages are all published under the GPL or some other license
2325 compatible to the GPL.
2326
2327 Acknowledgements
2328 ----------------
2329
2330 Many thanks to Gerrit Renker who read an early draft of this manual
2331 and contributed significant improvements.
2332
2333 ==========
2334 References
2335 ==========
2336
2337 Articles
2338 --------
2339 - [Polynomial Codes over Certain Finite
2340 Fields](http://kom.aau.dk/~heb/kurser/NOTER/KOFA01.PDF) by Reed, Irving
2341 S.; Solomon, Gustave (1960), Journal of the Society for Industrial
2342 and Applied Mathematics (SIAM) 8 (2): 300-304, doi:10.1137/0108018)
2343
2344 RFCs
2345 ----
2346
2347 - [RFC 768](http://www.ietf.org/rfc/rfc768.txt) (1980): User Datagram
2348 Protocol
2349
2350 - [RFC 791](http://www.ietf.org/rfc/rfc791.txt) (1981): Internet
2351 Protocol
2352
2353 - [RFC 2437](http://www.ietf.org/rfc/rfc2437.txt) (1998): RSA
2354 Cryptography Specifications
2355
2356 - [RFC 4340](http://www.ietf.org/rfc/rfc4340.txt) (2006): Datagram
2357 Congestion Control Protocol (DCCP)
2358
2359 - [RFC 4341](http://www.ietf.org/rfc/rfc4341.txt) (2006): Congestion
2360 Control ID 2: TCP-like Congestion Control
2361
2362 - [RFC 4342](http://www.ietf.org/rfc/rfc4342.txt) (2006): Congestion
2363 Control ID 3: TCP-Friendly Rate Control (TFRC)
2364
2365 - [RFC 6716](http://www.ietf.org/rfc/rfc6716.txt) (2012): Definition
2366 of the Opus Audio Codec
2367
2368 Application web pages
2369 ---------------------
2370
2371 - [paraslash](http://people.tuebingen.mpg.de/maan/paraslash/)
2372 - [xmms](http://xmms2.org/wiki/Main_Page)
2373 - [mpg123](http://www.mpg123.de/)
2374 - [gstreamer](http://gstreamer.freedesktop.org/)
2375 - [icecast](http://www.icecast.org/)
2376 - [Audio Compress](http://beesbuzz.biz/code/audiocompress.php)
2377
2378 External documentation
2379 ----------------------
2380
2381 - [The mathematics of
2382 Raid6](http://kernel.org/pub/linux/kernel/people/hpa/raid6.pdf)
2383 by H. Peter Anvin
2384
2385 - [Effective Erasure Codes for reliable Computer Communication
2386 Protocols](http://info.iet.unipi.it/~luigi/fec_ccr.ps.gz) by Luigi
2387 Rizzo
2388
2389 Code
2390 ----
2391 - [Original FEC
2392 implementation](http://info.iet.unipi.it/~luigi/vdm.tar.gz) by
2393 Luigi Rizzo)