Azioni

Differenze tra le versioni di "Streaming Audio e Terminale"

Da MontelLUG WIKI.

(Ices2)
 
(9 versioni intermedie di 3 utenti non mostrate)
Riga 11: Riga 11:
 
NOME_STREAM=miostream.ogg
 
NOME_STREAM=miostream.ogg
 
FILE_ATTESA=attesa.ogg #(da mettere nella dir /usr/share/icecast2/web )
 
FILE_ATTESA=attesa.ogg #(da mettere nella dir /usr/share/icecast2/web )
 +
</pre>
  
 +
== Icecast2 ==
 +
Installazione di icecast2
 +
<pre>
 
ssh USER_SSH@IP_SERVER
 
ssh USER_SSH@IP_SERVER
  
Riga 18: Riga 22:
 
apt-get upgrade
 
apt-get upgrade
 
apt-get install icecast2
 
apt-get install icecast2
 
 
#########
 
IP_SERVER=123.123.123.123
 
SERVER_NAME=deb2.carinato.net
 
PASS_ICECAST=icecast_password!
 
PASS_ADMIN_ICECAST=icecast2_password1!
 
NOME_STREAM=miostream.ogg
 
FILE_ATTESA=attesa.ogg #(da mettere nella dir /usr/share/icecast2/web )
 
#########
 
 
</pre>
 
</pre>
  
# Abilito il server icecast2
+
Abilito il server icecast2
  
 
<pre>
 
<pre>
Riga 36: Riga 30:
 
</pre>
 
</pre>
  
# Modifico il file di configurazione di icecast2
+
Modifico il file di configurazione di icecast2
  
 
<pre>
 
<pre>
Riga 45: Riga 39:
 
</pre>
 
</pre>
  
# Opzionale per file di intro
+
Opzionale per file di intro
  
 
<pre>
 
<pre>
Riga 59: Riga 53:
 
/etc/init.d/icecast2 start
 
/etc/init.d/icecast2 start
 
</pre>
 
</pre>
############ fine icecast2
 
  
######## ices2: client per invio stream in ogg
+
== Ices2 ==
 +
 
 +
ices2: client per invio stream in ogg
  
 
<pre>
 
<pre>
 
apt-get install ices2 alsa-utils
 
apt-get install ices2 alsa-utils
 
</pre>
 
</pre>
# Verificare se servono altri pacchetti....
+
 
 +
Nota: verificare se servono altri pacchetti oltre a ices2 alsa-utils...
 +
 
 +
Creo le cartelle di appoggio per ices2
  
 
<pre>
 
<pre>
Riga 72: Riga 70:
 
mkdir /etc/ices2
 
mkdir /etc/ices2
 
mkdir -p /var/log/ices/audio
 
mkdir -p /var/log/ices/audio
 +
</pre>
  
 +
Copio la configurazione di esempio per l'utilizzo dell'ingresso della scheda audio come sorgente:
 +
 +
<pre>
 
cp /usr/share/doc/ices2/examples/ices-alsa.xml /etc/ices2/
 
cp /usr/share/doc/ices2/examples/ices-alsa.xml /etc/ices2/
 
</pre>
 
</pre>
  
# imposto a 1 l'esecuzione in background
+
Imposto l'esecuzione in background:
 +
 
 
<pre>
 
<pre>
 
sed -i "s|\(<background>\).*\(</background>\)|\11\2|" /etc/ices2/ices-alsa.xml
 
sed -i "s|\(<background>\).*\(</background>\)|\11\2|" /etc/ices2/ices-alsa.xml
 
</pre>
 
</pre>
  
# Opzionale: metto a 1 il loglevel
+
Opzionale: metto a 1 il loglevel:
 
<pre>
 
<pre>
 
sed -i "s|\(<loglevel>\).*\(</loglevel>\)|\11\2|" /etc/ices2/ices-alsa.xml
 
sed -i "s|\(<loglevel>\).*\(</loglevel>\)|\11\2|" /etc/ices2/ices-alsa.xml
 
</pre>
 
</pre>
  
Modifico /etc/ices2/ices-alsa.xml
+
Modifico il file di configurazione di ices2 '''/etc/ices2/ices-alsa.xml''':
  
 
<pre>
 
<pre>
Riga 92: Riga 95:
 
</pre>
 
</pre>
  
Modifico la parte stream del file /etc/ices2/ices-alsa.xml in questo modo  
+
Modifico la parte stream del file '''/etc/ices2/ices-alsa.xml''' in questo modo:
  
 
<pre>
 
<pre>
Riga 98: Riga 101:
 
     <!-- metadata used for stream listing -->
 
     <!-- metadata used for stream listing -->
 
     <metadata>
 
     <metadata>
         <name>$NOME_DELLO_STREAM</name>
+
         <name>$NOME_DELLO_STREAM</name><!-- es: Lezione 1 Linux Base -->
         <genre>$NOME_DEL_GENERE</genre>
+
         <genre>$NOME_DEL_GENERE</genre><!-- es: voice -->
         <description>$DESCRPTION</description>
+
         <description>$DESCRIPTION</description><!-- es: Prima lezione su Linux Base del Montellug -->
         <url>$URL_DELLA_PAGINA_WEB_DI_RIFERIMENTO</url>
+
         <url>$URL_DELLA_PAGINA_WEB_DI_RIFERIMENTO</url><!-- es: http://www.montellug.it/linuxbase -->
 
     </metadata>
 
     </metadata>
  
Riga 148: Riga 151:
 
</pre>
 
</pre>
  
# Creo un file per l'avvio di ices2 in automatico (utile per la raspberry quando non gestita)
+
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.
vi /etc/init.d/ices2
+
Altrimenti salvo lo stream in '''/var/log/ices/audio'''
# 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'''
 
<pre>
 
<pre>
###########
 
 
#! /bin/sh
 
#! /bin/sh
 
### BEGIN INIT INFO
 
### BEGIN INIT INFO
Riga 202: Riga 203:
 
[ -h /var/log/ices/dump ] && rm /var/log/ices/dump
 
[ -h /var/log/ices/dump ] && rm /var/log/ices/dump
 
ln -s ${AUDIO_DEST} /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))
+
[ -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}"
 
echo "\nSalvataggio su ${AUDIO_DEST}"
 
# Return
 
# Return
Riga 274: Riga 276:
 
esac
 
esac
 
;;
 
;;
  #reload|force-reload)
 
#
 
# If do_reload() is not implemented then leave this commented out
 
# and leave 'force-reload' as an alias for 'restart'.
 
#
 
#log_daemon_msg "Reloading $DESC" "$NAME"
 
#do_reload
 
#log_end_msg $?
 
#;;
 
 
   restart|force-reload)
 
   restart|force-reload)
 
#
 
#
Riga 313: Riga 306:
  
 
:
 
:
#################
 
 
</pre>
 
</pre>
  
# abilito l'avvio automatico di ices2
+
Abilito l'avvio automatico di ices2:
 
<pre>
 
<pre>
 
update-rc.d ices2 default
 
update-rc.d ices2 default
 
</pre>
 
</pre>
  
# per disabilitare l'avvio automatico di ices2:
+
Per disabilitare l'avvio automatico di ices2:
 
<pre>
 
<pre>
 
update-rc.d -f ices2 remove
 
update-rc.d -f ices2 remove
 
</pre>
 
</pre>
############## fine ices2 ###################
 
  
 +
== TTYcast==
  
######## Installazione sul server web di TTYCAST #############
+
Installazione sul server web di TTYCAST
  
# Per Debian Wheezy, installo node.js
+
Per Debian Wheezy, installo '''node.js''':
 
<pre>
 
<pre>
 
apt-get install python g++ make checkinstall build-essential
 
apt-get install python g++ make checkinstall build-essential
Riga 344: Riga 336:
 
</pre>
 
</pre>
  
# eventualmente modificare la pagina index.html presente in /usr/local/lib/node_modules/ttycast/static
+
Eventualmente modificare la pagina '''index.html''' presente in '''/usr/local/lib/node_modules/ttycast/static'''
  
# Avvio ttycast
+
Avvio ttycast:
Soluzione 1:
+
=== Soluzione 1 ===
 
<pre>
 
<pre>
 
ssh root@serverweb  
 
ssh root@serverweb  
Riga 354: Riga 346:
 
</pre>
 
</pre>
  
su altro terminale locale:
+
Su altro terminale locale:
 
<pre>
 
<pre>
 
ssh root@serverweb
 
ssh root@serverweb
Riga 360: Riga 352:
 
</pre>
 
</pre>
  
..e la pagina http://serverweb:8081 funziona
+
..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
+
A fine lezione copiare il file '''myterminal.tty''' e cancellare '''/tmp/ttycast'''.
contro: bisogna lavorare in remoto
 
  
===================
+
* ''PRO'': si ha la registrazione della lezione, non serve installare nulla in locale.
 +
* ''CONTRO'': bisogna lavorare in remoto.
  
Soluzione 2:
+
=== Soluzione 2 ===
 
<pre>
 
<pre>
 
mkfifo /tmp/ttycast && ttyplay -n /tmp/ttycast | ssh root@serverweb PORT=8081 ttycast
 
mkfifo /tmp/ttycast && ttyplay -n /tmp/ttycast | ssh root@serverweb PORT=8081 ttycast
 
</pre>
 
</pre>
  
su altro terminale locale:
+
Su altro terminale locale:
 
<pre>
 
<pre>
 
ttyrec /tmp/ttycast
 
ttyrec /tmp/ttycast
 
</pre>
 
</pre>
 +
 
..e la pagina http://serverweb:8081 funziona
 
..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
+
Io ho usato la porta 8081 perche' la predefinita di ttycast (13337) non era aperta nel mio server.

Versione attuale delle 08:21, 9 lug 2013

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

Impostare le variabili:

                                     
USER_SSH=nomeutente
PASS_SSH=secret
IP_SERVER=123.123.123.123
SERVER_NAME=my.radio.com
PASS_ICECAST=icecast_password
PASS_ADMIN_ICECAST=icecast2_password
NOME_STREAM=miostream.ogg
FILE_ATTESA=attesa.ogg #(da mettere nella dir /usr/share/icecast2/web )

Icecast2

Installazione di icecast2

ssh USER_SSH@IP_SERVER

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>\\
      <mount-name>/${NOME_STREAM}</mount-name>\\
      <username>source</username>\\
      <password>${PASS_ICECAST}</password>\\
      <fallback-mount>/${FILE_ATTESA}</fallback-mount>\\
      <fallback-override>1</fallback-override>\\
    </mount>" /etc/icecast2/icecast.xml

/etc/init.d/icecast2 start

Ices2

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:

<pidfile>/var/run/ices2.pid</pidfile>

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

<stream>
    <!-- metadata used for stream listing -->
    <metadata>
        <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: http://www.montellug.it/linuxbase -->
    </metadata>

    <input>
        <module>alsa</module>
        <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>
    </input>
    <instance>
        <!--    Server details.

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

	    <hostname>$SERVER_NAME</hostname>
	    <port>8000</port>
	    <username>source</username>
	    <password>$PASS_ICECAST</password>
	    <mount>/mountpoint.ogg</mount>
	    <yp>0</yp>   <!-- allow stream to be advertised on YP, default 0 -->

        <encode>
            <quality>0</quality>
            <samplerate>22050</samplerate>
            <channels>1</channels>
        </encode>

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

        <!-- Salvo una copia dello stream -->
        <savefile>/var/log/ices/dump/lezione.ogg</savefile> 

        <resample>
            <in-rate>44100</in-rate>
            <out-rate>22050</out-rate>
        </resample>
    </instance>
</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
### BEGIN INIT INFO
# 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:       
### END INIT INFO
#
# Author:	Leonardo Serra Maciel de Campos <linuxbh@brfree.com.br>.
#
# Version:	@(#)ices2  2.0.1-5  16-Aug-2006  linuxbh@brfree.com.br

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="streaming source for Icecast 2"
NAME=ices2
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
#CONFIGFILE="/etc/ices2.xml"
CONFIGFILE="/etc/ices2/ices-alsa.xml"

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

:

Abilito l'avvio automatico di ices2:

update-rc.d ices2 default

Per disabilitare l'avvio automatico di ices2:

update-rc.d -f ices2 remove

TTYcast

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 http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
./configure
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.