aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-06-06 18:09:06 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-06-06 18:09:06 +0200
commit9bd8f004b216834ea02678dba11a94770f3b3e44 (patch)
tree18ef73015b2bafd427680e200b17217f05a9c0d3
parent764ab2b68bdbee3f012e89b7c07cbb77994d7212 (diff)
downloadmmbtools-aux-9bd8f004b216834ea02678dba11a94770f3b3e44.tar.gz
mmbtools-aux-9bd8f004b216834ea02678dba11a94770f3b3e44.tar.bz2
mmbtools-aux-9bd8f004b216834ea02678dba11a94770f3b3e44.zip
Add encode-jack.sh
-rw-r--r--cosin.mux66
-rwxr-xr-xencode-jack.sh154
2 files changed, 154 insertions, 66 deletions
diff --git a/cosin.mux b/cosin.mux
deleted file mode 100644
index 87e388e..0000000
--- a/cosin.mux
+++ /dev/null
@@ -1,66 +0,0 @@
-general {
- ; the DAB Transmission mode (values 1-4 accepted)
- dabmode 1
-
- ; the number of ETI frames to generate (set to 0 to get an unlimited number)
- nbframes 0
-
-
- syslog false
- writescca false
- tist false
-}
-
-; Some ensemble parameters
-ensemble {
- id 20479
- ecc 1249 ; Extended Country Code (decimal)
- label "TuxMux"
- shortlabel "Tux"
-}
-
-services {
- fbp {
- label "fb+"
- shortlabel "fb+"
- pty 0
- language 0
- ; also supports id
- }
-}
-
-; The subchannels are defined in the corresponding section.
-; supported types are : audio, bridge, data, enhancedpacket,
-; dabplus, dmb, packet, test
-subchannels {
- fbp {
- type dabplus
- inputfile "fb.dabp"
- nonblock false
- bitrate 96
- id 10
- protection 3
- }
-}
-
-; For now, each component links one service to one subchannel
-components {
- ; the component unique identifiers are not used anywhere, but
- ; are useful to disambiguate different components.
- funky {
- label "CoSin"
- shortlabel "CoSin"
- service fbp
- subchannel fbp
- }
-}
-
-; A list of outputs, in the format
-; unique_id "uri"
-outputs {
- foobar "fifo:///dev/stdout?type=raw"
-
- ; This throttles muxing down to nominal rate
- throttle "simul://"
-
-}
diff --git a/encode-jack.sh b/encode-jack.sh
new file mode 100755
index 0000000..ab7e9aa
--- /dev/null
+++ b/encode-jack.sh
@@ -0,0 +1,154 @@
+#!/bin/bash
+#
+# mplayer - jack - jack-stdout - dabplus-enc
+# encoder script.
+#
+# Used to encode webstreams for DAB+, requires
+# jackd -d dummy -r 32000
+# to be running
+
+printerr() {
+ echo -e "\033[01;31m$1\033[0m"
+}
+
+printmsg() {
+ echo -e "\033[01;32m$1\033[0m"
+}
+
+set -u
+
+# check number of arguments
+if [[ "$#" < 3 ]] ; then
+ echo "Usage $0 url jack-id destination [volume]"
+ echo "The volume setting is optional"
+ exit 1
+fi
+
+if [[ "$#" > 2 ]] ; then
+ URL=$1
+ ID=$2
+ DST=$3
+fi
+
+if [[ "$#" == 4 ]] ; then
+ VOL=$4
+else
+ VOL=""
+fi
+
+BITRATE=80
+RATE=32000
+
+encoderalive=0
+mplayerpid=0
+encoderpid=0
+
+# The trap for Ctrl-C
+sigint_trap() {
+ printerr "Got Ctrl-C, killing mplayer and encoder"
+
+ if [[ "$mplayerpid" != "0" ]] ; then
+ kill -TERM $mplayerpid
+ sleep 2
+ kill -KILL $mplayerpid
+ fi
+
+ if [[ "$encoderpid" != "0" ]] ; then
+ kill -TERM $encoderpid
+ sleep 2
+ kill -KILL $encoderpid
+ fi
+
+ printmsg "Goodbye"
+ exit
+}
+
+trap sigint_trap SIGINT
+
+while true
+do
+ mplayer_ok=0
+
+ if [[ "$mplayerpid" == "0" ]] ; then
+ if [[ "$VOL" == "" ]] ; then
+ mplayer -quiet -af resample=$RATE:0:2 -ao jack:name=$ID $URL &
+ mplayerpid=$!
+ else
+ mplayer -quiet -af resample=$RATE:0:2 -af volume=$VOL -ao jack:name=$ID $URL &
+ mplayerpid=$!
+ fi
+
+ printmsg "Started mplayer with pid $mplayerpid"
+
+ # give some time to mplayer to set up and
+ # wait until port becomes visible
+ timeout=10
+
+ while [[ "$mplayer_ok" == "0" ]]
+ do
+ printmsg "Waiting for mplayer to connect to jack ($timeout)"
+ sleep 1
+ mplayer_ok=$(jack_lsp $ID:out_0 | wc -l)
+
+ timeout=$(( $timeout - 1))
+
+ if [[ "$timeout" == "0" ]] ; then
+ printerr "mplayer doesn't connect to jack !"
+ kill $mplayerpid
+ break
+ fi
+ done
+ else
+ printmsg "No need to start mplayer: $mplayerpid"
+ fi
+
+ if [[ "$mplayer_ok" == "1" ]] ; then
+ jack-stdout $ID:out_0 $ID:out_1 | \
+ dabplus-enc -i /dev/stdin -l \
+ -b $BITRATE -r $RATE -f raw -a -o $DST &
+ encoderpid=$!
+ fi
+
+ printmsg "Started encoder with pid $encoderpid"
+
+ sleep 5
+
+ checkloop=1
+ while [[ "$checkloop" == "1" ]]
+ do
+ sleep 2
+
+ kill -s 0 $mplayerpid
+ if [[ "$?" != "0" ]] ; then
+ # mplayer died
+ # we must kill jack-stdout, because we cannot reconnect it
+ # to a new mplayer, since we do not know the jack-stdout name.
+ # And it has no cmdline option to set one, Rrrrongntudtjuuu!
+ if [[ "$encoderpid" != "0" ]] ; then
+ kill -TERM $encoderpid
+ fi
+ checkloop=0
+
+ # mark as dead
+ mplayerpid=0
+
+ printerr "Mplayer died"
+ fi
+
+ if [[ "$encoderpid" != "0" ]] ; then
+ kill -s 0 $encoderpid
+ if [[ "$?" != "0" ]] ; then
+ # the encoder died,
+ # no need to kill the mplayer, we can reconnect to it
+
+ checkloop=0
+
+ printerr "Encoder died"
+ fi
+ fi
+ done
+
+ sleep 5
+
+done
+