Streaming Audio e Terminale

Da MontelLUG.

Appunti su come configurare uno streaming audio tramite server esterno con accesso SSH - Distribuzione Debian 6.0.4

Impostare le variabili:

FILE_ATTESA=attesa.ogg #(da mettere nella dir /usr/share/icecast2/web )


Installazione di icecast2


apt-get install debian-keyring debian-archive-keyring
apt-get update
apt-get upgrade
apt-get install icecast2

Abilito il server icecast2

sed -i "s/\(ENABLE *= *\).*/\1true/" /etc/default/icecast2

Modifico il file di configurazione di icecast2

sed -i "s|\(<source-password>\).*\(</source-password>\)|\1$PASS_ICECAST\2|" /etc/icecast2/icecast.xml
sed -i "s|\(<relay-password>\).*\(</relay-password>\)|\1$PASS_ICECAST\2|" /etc/icecast2/icecast.xml
sed -i "s|\(<admin-password>\).*\(</admin-password>\)|\1$PASS_ICECAST\2|" /etc/icecast2/icecast.xml
sed -i "s|\(<hostname>\).*\(</hostname>\)|\1$SERVER_NAME\2|" /etc/icecast2/icecast.xml

Opzionale per file di intro

sed  "/fileserve/i \\
    </mount>" /etc/icecast2/icecast.xml

/etc/init.d/icecast2 start


ices2: client per invio stream in ogg

apt-get install ices2 alsa-utils

Nota: verificare se servono altri pacchetti oltre a ices2 alsa-utils...

Creo le cartelle di appoggio per ices2

mkdir /var/log/ices
mkdir /etc/ices2
mkdir -p /var/log/ices/audio

Copio la configurazione di esempio per l'utilizzo dell'ingresso della scheda audio come sorgente:

cp /usr/share/doc/ices2/examples/ices-alsa.xml /etc/ices2/

Imposto l'esecuzione in background:

sed -i "s|\(<background>\).*\(</background>\)|\11\2|" /etc/ices2/ices-alsa.xml

Opzionale: metto a 1 il loglevel:

sed -i "s|\(<loglevel>\).*\(</loglevel>\)|\11\2|" /etc/ices2/ices-alsa.xml

Modifico il file di configurazione di ices2 /etc/ices2/ices-alsa.xml:


Modifico la parte stream del file /etc/ices2/ices-alsa.xml in questo modo:

    <!-- metadata used for stream listing -->
        <name>$NOME_DELLO_STREAM</name><!-- es: Lezione 1 Linux Base -->
        <genre>$NOME_DEL_GENERE</genre><!-- es: voice -->
        <description>$DESCRIPTION</description><!-- es: Prima lezione su Linux Base del Montellug -->
        <url>$URL_DELLA_PAGINA_WEB_DI_RIFERIMENTO</url><!-- es: -->

        <param name="rate">44100</param>
        <param name="channels">2</param>
        <param name="device">hw:1,0</param> <!-- 1,0 indica la seconda scheda audio, per noi quella esterna -->
        <!-- Read metadata (from stdin by default, or -->
        <!-- filename defined below (if the latter, only on SIGUSR1) -->
        <param name="metadata">1</param>
        <param name="metadatafilename">commandline</param>
        <!--    Server details.

        You define hostname and port for the server here, along
        with the source password and mountpoint.  -->

	    <yp>0</yp>   <!-- allow stream to be advertised on YP, default 0 -->


        <!-- stereo->mono downmixing, enabled by setting this to 1 -->

        <!-- Salvo una copia dello stream -->


Creo un file per l'avvio di ices2 in automatico (utile per la raspberry quando non gestita). Se e' montata una memoria usb in /media/usb con una cartella audio (/media/usb/audio) uso questa cartella per il salvataggio. Altrimenti salvo lo stream in /var/log/ices/audio

vi /etc/init.d/ices2

#! /bin/sh
# Provides:          ices2
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ices2 initscript
# Description:       
# Author:	Leonardo Serra Maciel de Campos <>.
# Version:	@(#)ices2  2.0.1-5  16-Aug-2006

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the script
DESC="streaming source for Icecast 2"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Function that starts the daemon/service
	[ -d /media/usb/audio ] && AUDIO_DEST="/media/usb/audio" || AUDIO_DEST="/var/log/ices/audio"
	[ ! -d ${AUDIO_DEST}/archive ] && mkdir -p ${AUDIO_DEST}/archive
	[ -h /var/log/ices/dump ] && rm /var/log/ices/dump
	ln -s ${AUDIO_DEST} /var/log/ices/dump
	[ -f /var/log/ices/dump/lezione.ogg ] && mv /var/log/ices/dump/lezione.ogg 
               ${AUDIO_DEST}/archive/$(printf "lezione_%02d.ogg" $(ls -1 ${AUDIO_DEST}/archive/ | wc -l))
	echo "\nSalvataggio su ${AUDIO_DEST}"
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
		|| return 1
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $CONFIGFILE\
		|| return 2
	# Add code here, if necessary, that waits for the process to be ready
	# to handle requests from services started subsequently which depend
	# on this one.  As a last resort, sleep for some time.

# Function that stops the daemon/service
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
	[ "$RETVAL" = 2 ] && return 2
	# Wait for children to finish too if this is a daemon that forks
	# and if the daemon is only ever run from this initscript.
	# If the above conditions are not satisfied then add some other code
	# that waits for the process to drop all resources that could be
	# needed by services started subsequently.  A last resort is to
	# sleep for some time.
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
	[ "$?" = 2 ] && return 2
	# Many daemons don't delete their pidfiles when they exit.
	rm -f $PIDFILE
	return "$RETVAL"

# Function that sends a SIGHUP to the daemon/service
do_reload() {
	# If the daemon can reload its configuration without
	# restarting (for example, when it is sent a SIGHUP),
	# then implement that here.
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
	return 0

case "$1" in
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	# If the "reload" option is implemented then remove the
	# 'force-reload' alias
	log_daemon_msg "Restarting $DESC" "$NAME"
	case "$?" in
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
	  	# Failed to stop
		log_end_msg 1
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3


Abilito l'avvio automatico di ices2:

update-rc.d ices2 default

Per disabilitare l'avvio automatico di ices2:

update-rc.d -f ices2 remove


Installazione sul server web di TTYCAST

Per Debian Wheezy, installo node.js:

apt-get install python g++ make checkinstall build-essential
mkdir ~/src && cd $_
wget -N
tar xzvf node-latest.tar.gz && cd node-v*
checkinstall #(remove the "v" in front of the version number in the dialog)
dpkg -i node_*

apt-get install ttyrec
npm install -g ttycast

Eventualmente modificare la pagina index.html presente in /usr/local/lib/node_modules/ttycast/static

Avvio ttycast:

Soluzione 1

ssh root@serverweb 
export PORT=8081
ttyreccast myterminal.tty

Su altro terminale locale:

ssh root@serverweb
reset && ttyrec /tmp/ttycast

..e la pagina http://serverweb:8081 funziona.

A fine lezione copiare il file myterminal.tty e cancellare /tmp/ttycast.

  • PRO: si ha la registrazione della lezione, non serve installare nulla in locale.
  • CONTRO: bisogna lavorare in remoto.

Soluzione 2

mkfifo /tmp/ttycast && ttyplay -n /tmp/ttycast | ssh root@serverweb PORT=8081 ttycast

Su altro terminale locale:

ttyrec /tmp/ttycast

..e la pagina http://serverweb:8081 funziona

Io ho usato la porta 8081 perche' la predefinita di ttycast (13337) non era aperta nel mio server.