fix memory leak when reloading the application
[dvblast.git] / extra / dvbiscovery / dvbiscovery.sh
blob800b730fc4533619bf347459f051739e01a8068a
1 #!/bin/sh
2 ###############################################################################
3 # dvbiscovery.sh
4 ###############################################################################
5 # Copyright (C) 2010 VideoLAN
7 # Authors: Christophe Massiot <massiot@via.ecp.fr>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 ###############################################################################
24 CONF_BASE="/usr/local/share/dvblast/dvbiscovery"
25 #CONF_BASE="./"
26 DVBLAST=dvblast
27 LOCK_TIMEOUT=2500
28 QUIT_TIMEOUT=20000
30 usage() {
31 echo "Usage: $0 [-a <adapter #>] [-n <frontend #>] [-S <diseqc sat num>] [-c <conf file>]" >&2
32 exit 1
35 conf_file_passed=""
36 adapter=""
37 frontend=""
38 diseqc=""
40 TEMP=`getopt -o a:n:S:c: -n "$0" -- "$@"`
42 if test $? -ne 0; then
43 usage
46 eval set -- "$TEMP"
48 while :; do
49 case "$1" in
50 -a)
51 adapter="-a $2"
52 shift 2
54 -n)
55 frontend="-n $2"
56 shift 2
58 -c)
59 conf_file_passed=$2
60 shift 2
62 -S)
63 diseqc="-S $2"
64 shift 2
66 --)
67 shift
68 break
71 usage
73 esac
74 done
76 type=`$DVBLAST $diseqc $adapter $frontend -f 0 2>&1 | grep '^debug: Frontend' | sed 's/^debug: Frontend ".*" type "\(.*\)" supports:$/\1/'`
77 tune=""
78 conf_file=""
80 case "$type" in
81 "QPSK (DVB-S/S2)")
82 conf_file="${CONF_BASE}_dvb-s.conf"
83 tune=tune_sat
85 "QAM (DVB-C)")
86 conf_file="${CONF_BASE}_dvb-c.conf"
87 tune=tune_cable
89 "OFDM (DVB-T)")
90 conf_file="${CONF_BASE}_dvb-t.conf"
91 tune=tune_dtt
93 "ATSC")
94 conf_file="${CONF_BASE}_atsc.conf"
95 tune=tune_atsc
98 echo "unknown frontend type $type" >&2
99 exit 1
100 esac
102 if test -n "$conf_file_passed"; then
103 conf_file=$conf_file_passed
106 if ! test -r "$conf_file"; then
107 echo "unable to open $conf_file" >&2
108 exit 1
111 signal_catch() {
112 if test $childpid -ne 0; then
113 kill $childpid
114 wait $childpid
116 exit 1
119 exec_dvblast() {
120 tmp_file=`mktemp`
122 $DVBLAST $diseqc $adapter $frontend -O $LOCK_TIMEOUT -Q $QUIT_TIMEOUT -q4 -x xml $opts >| $tmp_file &
123 childpid=$!
124 wait $childpid
125 if test $? -eq 0; then
126 cat $tmp_file
127 echo "</TS>"
128 rm $tmp_file
129 exit 0
132 childpid=0
133 rm $tmp_file
136 strtofec() {
137 case "$1" in
138 "NONE") opts="$opts $2 0" ;;
139 "1/2") opts="$opts $2 12" ;;
140 "2/3") opts="$opts $2 23" ;;
141 "3/4") opts="$opts $2 34" ;;
142 "4/5") opts="$opts $2 45" ;;
143 "5/6") opts="$opts $2 56" ;;
144 "6/7") opts="$opts $2 67" ;;
145 "7/8") opts="$opts $2 78" ;;
146 "8/9") opts="$opts $2 89" ;;
147 "AUTO"|*) ;;
148 esac
151 strtomod() {
152 case "$1" in
153 "QPSK") opts="$opts -m qpsk" ;;
154 "QAM16") opts="$opts -m qam_16" ;;
155 "QAM32") opts="$opts -m qam_32" ;;
156 "QAM64") opts="$opts -m qam_64" ;;
157 "QAM128") opts="$opts -m qam_128" ;;
158 "8VSB") opts="$opts -m vsb_8" ;;
159 "16VSB") opts="$opts -m vsb_16" ;;
160 "AUTO"|*) ;;
161 esac
164 tune_sat() {
165 childpid=0
166 trap signal_catch 1 2 3 15
168 while read sys freq pol srate fec what mod; do
169 opts="-f $freq -s $srate"
171 case "$sys" in
172 "S") ;;
173 "S2")
174 case "$mod" in
175 "QPSK") opts="$opts -m qpsk" ;;
176 "8PSK") opts="$opts -m psk_8" ;;
178 echo "invalid modulation $mod" >&2
180 esac
183 echo "incompatible file" >&2
184 exit 1
186 esac
188 strtofec $fec "-F"
190 case "$pol" in
191 "V") opts="$opts -v 13" ;;
192 "H") opts="$opts -v 18" ;;
193 *) ;;
194 esac
196 exec_dvblast
197 done
200 tune_cable() {
201 childpid=0
202 trap signal_catch 1 2 3 15
204 while read sys freq srate fec mod; do
205 opts="-f $freq -s $srate"
207 case "$sys" in
208 "C") ;;
210 echo "incompatible file" >&2
211 exit 1
213 esac
215 strtofec $fec "-F"
216 strtomod $mod
218 exec_dvblast
219 done
222 tune_dtt() {
223 childpid=0
224 trap signal_catch 1 2 3 15
226 while read sys freq bw fec fec2 mod mode guard hier; do
227 opts="-f $freq"
229 case "$sys" in
230 "T"|"T2") ;;
232 echo "incompatible file" >&2
233 exit 1
235 esac
237 case "$bw" in
238 "8MHz") opts="$opts -b 8" ;;
239 "7MHz") opts="$opts -b 7" ;;
240 "6MHz") opts="$opts -b 6" ;;
241 "AUTO"|*) ;;
242 esac
244 strtofec $fec "-F"
245 strtofec $fec2 "-K"
246 strtomod $mod
248 case "$mode" in
249 "2k") opts="$opts -X 2" ;;
250 "8k") opts="$opts -X 8" ;;
251 "AUTO"|*) ;;
252 esac
254 case "$guard" in
255 "1/32") opts="$opts -G 32" ;;
256 "1/16") opts="$opts -G 16" ;;
257 "1/8") opts="$opts -G 8" ;;
258 "1/4") opts="$opts -G 4" ;;
259 "AUTO"|*) ;;
260 esac
262 case "$hier" in
263 "NONE") opts="$opts -H 0" ;;
264 "1") opts="$opts -H 1" ;;
265 "2") opts="$opts -H 2" ;;
266 "4") opts="$opts -H 4" ;;
267 "AUTO"|*) ;;
268 esac
270 exec_dvblast
271 done
274 tune_atsc() {
275 childpid=0
276 trap signal_catch 1 2 3 15
278 while read sys freq mod; do
279 opts="-f $freq"
281 case "$sys" in
282 "A") ;;
284 echo "incompatible file" >&2
285 exit 1
287 esac
289 strtomod $mod
291 exec_dvblast
292 done
295 childpid=0
296 trap signal_catch 1 2 3 15
298 grep -v "^#" < "$conf_file" 2>/dev/null | $tune &
299 childpid=$!
300 wait $childpid
302 exit 100