1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 |
$path = $0; |
---|
26 |
$path =~ s/digitaltvrecording.pl$//i; |
---|
27 |
if ($path ne "./"){ |
---|
28 |
push( @INC, "$path"); |
---|
29 |
} |
---|
30 |
|
---|
31 |
|
---|
32 |
$extendrecendsec = 10; |
---|
33 |
|
---|
34 |
$startupsleeptime = 27; |
---|
35 |
|
---|
36 |
|
---|
37 |
require 'foltialib.pl'; |
---|
38 |
|
---|
39 |
&writelog("digitaltvrecording: DEBUG $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $ARGV[8]"); |
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
&prepare; |
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
&calldigitalrecorder; |
---|
51 |
|
---|
52 |
&writelog("digitaldigitaltvrecording:RECEND:$bandtype $recch $lengthsec $stationid $sleeptype $filename $tid $countno $unittype |
---|
53 |
"); |
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 |
sub prepare{ |
---|
59 |
|
---|
60 |
|
---|
61 |
$bandtype = $ARGV[0] ; |
---|
62 |
$recch = $ARGV[1] ; |
---|
63 |
$lengthsec = $ARGV[2] ; |
---|
64 |
$stationid = $ARGV[3] ; |
---|
65 |
$sleeptype = $ARGV[4] ; |
---|
66 |
$filename = $ARGV[5] ; |
---|
67 |
$tid = $ARGV[6] ; |
---|
68 |
$countno = $ARGV[7] ; |
---|
69 |
$unittype = $ARGV[8] ; |
---|
70 |
|
---|
71 |
if (($bandtype eq "" )|| ($recch eq "")|| ($lengthsec eq "")){ |
---|
72 |
print "usage digitaltvrecording.pl bandtype ch length(sec) [stationid] [sleeptype] [filename] [TID] [NO] [unittype]\n"; |
---|
73 |
exit; |
---|
74 |
} |
---|
75 |
|
---|
76 |
my $intval = $recch % 10; |
---|
77 |
my $startupsleep = $startupsleeptime - $intval; |
---|
78 |
$reclengthsec = $lengthsec + (60 - $startupsleep) + 1; |
---|
79 |
|
---|
80 |
if ( $sleeptype ne "N"){ |
---|
81 |
&writelog("digitaltvrecording: DEBUG SLEEP $startupsleeptime:$intval:$startupsleep:$reclengthsec"); |
---|
82 |
sleep ( $startupsleep); |
---|
83 |
|
---|
84 |
}else{ |
---|
85 |
&writelog("digitaltvrecording: DEBUG RAPID START"); |
---|
86 |
} |
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 |
$outputpath = "$recfolderpath"."/"; |
---|
99 |
|
---|
100 |
if ($countno eq "0"){ |
---|
101 |
$outputfile = $outputpath.$tid."--"; |
---|
102 |
}else{ |
---|
103 |
$outputfile = $outputpath.$tid."-".$countno."-"; |
---|
104 |
} |
---|
105 |
|
---|
106 |
if ($filename ne ""){ |
---|
107 |
|
---|
108 |
$outputfile = $filename ; |
---|
109 |
$outputfile = &filenameinjectioncheck($outputfile); |
---|
110 |
$outputfilewithoutpath = $outputfile ; |
---|
111 |
$outputfile = $outputpath.$outputfile ; |
---|
112 |
&writelog("digitaltvrecording: DEBUG FILENAME ne null \$outputfile $outputfile "); |
---|
113 |
}else{ |
---|
114 |
$outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60)); |
---|
115 |
chomp($outputfile); |
---|
116 |
$outputfile .= ".m2t"; |
---|
117 |
$outputfilewithoutpath = $outputfile ; |
---|
118 |
&writelog("digitaltvrecording: DEBUG FILENAME is null \$outputfile $outputfile "); |
---|
119 |
} |
---|
120 |
|
---|
121 |
|
---|
122 |
@wday_name = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); |
---|
123 |
$sleepcounter = 0; |
---|
124 |
$cmd=""; |
---|
125 |
|
---|
126 |
|
---|
127 |
if ( -e "$outputfile" ){ |
---|
128 |
if ( -s "$outputfile" ){ |
---|
129 |
&writelog("digitaltvrecording :ABORT :recfile $outputfile exist."); |
---|
130 |
exit 1; |
---|
131 |
} |
---|
132 |
} |
---|
133 |
|
---|
134 |
} |
---|
135 |
|
---|
136 |
sub calldigitalrecorderOld{ |
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
my $oserr = 0; |
---|
143 |
|
---|
144 |
if ($bandtype == 0){ |
---|
145 |
|
---|
146 |
|
---|
147 |
if ((-e "$toolpath/perl/tool/b25") && (-e "$toolpath/perl/tool/recfriio")){ |
---|
148 |
my $friiofifo = "$outputpath"."fifo-friio-"."$outputfilewithoutpath"; |
---|
149 |
my $b25fifo = "$outputpath"."fifo-b25-"."$outputfilewithoutpath"; |
---|
150 |
|
---|
151 |
if ((-e "$friiofifo") || (-e "$b25fifo")){ |
---|
152 |
&writelog("digitaltvrecording :ABORT :fifo is exist. It may be overwrite recording."); |
---|
153 |
exit 1; |
---|
154 |
}else{ |
---|
155 |
system ("mkfifo $friiofifo $b25fifo"); |
---|
156 |
|
---|
157 |
&writelog("digitaltvrecording DEBUG mkfifo $friiofifo $b25fifo: $?."); |
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 |
&writelog("digitaltvrecording DEBUG $toolpath/perl/tool/recfriio $recch $reclengthsec $friiofifo & dd if=$friiofifo of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile: $?."); |
---|
163 |
system("dd if=$friiofifo of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile &"); |
---|
164 |
$oserr = system("$toolpath/perl/tool/recfriio $recch $reclengthsec $friiofifo "); |
---|
165 |
$oserr = $oserr >> 8; |
---|
166 |
system ("rm -rf $friiofifo $b25fifo"); |
---|
167 |
&writelog("digitaltvrecording DEBUG rm -rf $friiofifo $b25fifo: $?."); |
---|
168 |
if ($oserr > 0){ |
---|
169 |
|
---|
170 |
&writelog("digitaltvrecording :ERROR :friio is BUSY."); |
---|
171 |
|
---|
172 |
$ddpid = `ps a | grep $friiofifo | grep -v grep`; |
---|
173 |
@ddpid = split(/ /,$ddpid); |
---|
174 |
$ddpid = $ddpid[0]; |
---|
175 |
chomp($ddpid); |
---|
176 |
$killcmd = "kill ".$ddpid; |
---|
177 |
system($killcmd); |
---|
178 |
&writelog("digitaltvrecording :DEBUG dd killed:$killcmd"); |
---|
179 |
|
---|
180 |
|
---|
181 |
$b25pid = `ps a | grep $b25fifo | grep -v grep`; |
---|
182 |
@b25pid = split(/ /,$b25pid); |
---|
183 |
$b25pid = $b25pid[0]; |
---|
184 |
chomp($b25pid); |
---|
185 |
$killcmd = "kill ".$b25pid; |
---|
186 |
system($killcmd); |
---|
187 |
&writelog("digitaltvrecording :DEBUG b25 killed:$killcmd"); |
---|
188 |
|
---|
189 |
system ("rm -rf $outputfile"); |
---|
190 |
|
---|
191 |
exit 2; |
---|
192 |
} |
---|
193 |
} |
---|
194 |
}else{ |
---|
195 |
&writelog("digitaltvrecording :ERROR :recfriio or b25 not found. You must install $toolpath/perl/tool/b25 and $toolpath/perl/tool/recfriio."); |
---|
196 |
exit 1; |
---|
197 |
} |
---|
198 |
|
---|
199 |
}elsif($bandtype == 1){ |
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 |
if ((-e "$toolpath/perl/tool/b25") && (-e "$toolpath/perl/tool/recfriiobs")){ |
---|
204 |
my $friiofifo = "$outputpath"."fifo-friioBS-"."$outputfilewithoutpath"; |
---|
205 |
my $b25fifo = "$outputpath"."fifo-b25-"."$outputfilewithoutpath"; |
---|
206 |
|
---|
207 |
if ((-e "$friiofifo") || (-e "$b25fifo")){ |
---|
208 |
&writelog("digitaltvrecording :ABORT :fifo is exist. It may be overwrite recording."); |
---|
209 |
exit 1; |
---|
210 |
}else{ |
---|
211 |
system ("mkfifo $friiofifo $b25fifo"); |
---|
212 |
&writelog("digitaltvrecording DEBUG mkfifo $friiofifo $b25fifo: $?."); |
---|
213 |
|
---|
214 |
if ($recch == 101) { |
---|
215 |
$bssplitflag = $recch; |
---|
216 |
$recch = 22; |
---|
217 |
}elsif($recch == 102){ |
---|
218 |
$bssplitflag = $recch; |
---|
219 |
$recch = 22; |
---|
220 |
}elsif($recch == 103){ |
---|
221 |
$recch = 23; |
---|
222 |
}elsif($recch == 141){ |
---|
223 |
$recch = 20; |
---|
224 |
}elsif($recch == 151){ |
---|
225 |
$recch = 13; |
---|
226 |
}elsif($recch == 161){ |
---|
227 |
$recch = 14; |
---|
228 |
}elsif($recch == 171){ |
---|
229 |
$recch = 16; |
---|
230 |
}elsif($recch == 181){ |
---|
231 |
$recch = 21; |
---|
232 |
}elsif($recch == 191){ |
---|
233 |
$recch = 15; |
---|
234 |
}elsif($recch == 192){ |
---|
235 |
$recch = 15; |
---|
236 |
}elsif($recch == 193){ |
---|
237 |
$recch = 15; |
---|
238 |
}elsif($recch == 211){ |
---|
239 |
$recch = 17; |
---|
240 |
}else{ |
---|
241 |
$recch = 19; |
---|
242 |
} |
---|
243 |
&writelog("digitaltvrecording DEBUG $toolpath/perl/tool/recfriiobs $recch $reclengthsec $friiofifo & dd if=$friiofifo of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile : $?."); |
---|
244 |
system("dd if=$friiofifo of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile &"); |
---|
245 |
$oserr = system("$toolpath/perl/tool/recfriiobs $recch $reclengthsec $friiofifo "); |
---|
246 |
$oserr = $oserr >> 8; |
---|
247 |
|
---|
248 |
system ("rm -rf $friiofifo $b25fifo"); |
---|
249 |
&writelog("digitaltvrecording DEBUG rm -rf $friiofifo $b25fifo: $?."); |
---|
250 |
if ($oserr > 0){ |
---|
251 |
|
---|
252 |
&writelog("digitaltvrecording :ERROR :friioBS is BUSY."); |
---|
253 |
|
---|
254 |
$ddpid = `ps a | grep $friiofifo | grep -v grep`; |
---|
255 |
@ddpid = split(/ /,$ddpid); |
---|
256 |
$ddpid = $ddpid[0]; |
---|
257 |
chomp($ddpid); |
---|
258 |
$killcmd = "kill ".$ddpid; |
---|
259 |
system($killcmd); |
---|
260 |
&writelog("digitaltvrecording :DEBUG dd killed:$killcmd"); |
---|
261 |
|
---|
262 |
|
---|
263 |
$b25pid = `ps a | grep $b25fifo | grep -v grep`; |
---|
264 |
@b25pid = split(/ /,$b25pid); |
---|
265 |
$b25pid = $b25pid[0]; |
---|
266 |
chomp($b25pid); |
---|
267 |
$killcmd = "kill ".$b25pid; |
---|
268 |
system($killcmd); |
---|
269 |
&writelog("digitaltvrecording :DEBUG b25 killed:$killcmd"); |
---|
270 |
|
---|
271 |
system ("rm -rf $outputfile"); |
---|
272 |
|
---|
273 |
exit 2; |
---|
274 |
} |
---|
275 |
|
---|
276 |
|
---|
277 |
if ($bssplitflag == 101){ |
---|
278 |
if (-e "$toolpath/perl/tool/TsSplitter.exe"){ |
---|
279 |
|
---|
280 |
system("wine $toolpath/perl/tool/TsSplitter.exe -EIT -ECM -EMM -OUT \"$outputpath\" -HD -SD2 -SD3 -1SEG -LOGFILE -WAIT2 $outputfile"); |
---|
281 |
$splitfile = $outputfile; |
---|
282 |
$splitfile =~ s/\.m2t$/_SD1.m2t/; |
---|
283 |
if (-e "$splitfile"){ |
---|
284 |
system("rm -rf $outputfile ; mv $splitfile $outputfile"); |
---|
285 |
&writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?."); |
---|
286 |
}else{ |
---|
287 |
&writelog("digitaltvrecording ERROR File not found:$splitfile."); |
---|
288 |
} |
---|
289 |
}else{ |
---|
290 |
&writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found."); |
---|
291 |
} |
---|
292 |
}elsif($bssplitflag == 102){ |
---|
293 |
if (-e "$toolpath/perl/tool/TsSplitter.exe"){ |
---|
294 |
|
---|
295 |
system("wine $toolpath/perl/tool/TsSplitter.exe -EIT -ECM -EMM -OUT \"$outputpath\" -HD -SD1 -SD3 -1SEG -LOGFILE -WAIT2 $outputfile"); |
---|
296 |
$splitfile = $outputfile; |
---|
297 |
$splitfile =~ s/\.m2t$/_SD2.m2t/; |
---|
298 |
if (-e "$splitfile"){ |
---|
299 |
system("rm -rf $outputfile ; mv $splitfile $outputfile"); |
---|
300 |
&writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?."); |
---|
301 |
}else{ |
---|
302 |
&writelog("digitaltvrecording ERROR File not found:$splitfile."); |
---|
303 |
} |
---|
304 |
}else{ |
---|
305 |
&writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found."); |
---|
306 |
} |
---|
307 |
}else{ |
---|
308 |
&writelog("digitaltvrecording DEBUG not split TS.$bssplitflag"); |
---|
309 |
} |
---|
310 |
|
---|
311 |
} |
---|
312 |
}else{ |
---|
313 |
&writelog("digitaltvrecording :ERROR :recfriiobs or b25 not found. You must install $toolpath/perl/tool/b25 and $toolpath/perl/tool/recfriiobs."); |
---|
314 |
exit 1; |
---|
315 |
} |
---|
316 |
}elsif($bandtype == 2){ |
---|
317 |
}else{ |
---|
318 |
&writelog("digitaltvrecording :ERROR :Unsupported and type (digital CS)."); |
---|
319 |
exit 3; |
---|
320 |
} |
---|
321 |
|
---|
322 |
|
---|
323 |
|
---|
324 |
} |
---|
325 |
|
---|
326 |
|
---|
327 |
sub calldigitalrecorder{ |
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
my $oserr = 0; |
---|
333 |
my $originalrecch = $recch; |
---|
334 |
my $errorflag = 0; |
---|
335 |
if ($bandtype == 0){ |
---|
336 |
|
---|
337 |
}elsif($bandtype == 1){ |
---|
338 |
|
---|
339 |
|
---|
340 |
if ($recch == 101) { |
---|
341 |
$bssplitflag = $recch; |
---|
342 |
$recch = "b10"; |
---|
343 |
}elsif($recch == 102){ |
---|
344 |
$bssplitflag = $recch; |
---|
345 |
$recch = "b10"; |
---|
346 |
}elsif($recch == 103){ |
---|
347 |
$recch = "b11"; |
---|
348 |
}elsif($recch == 141){ |
---|
349 |
$recch = "b8"; |
---|
350 |
}elsif($recch == 151){ |
---|
351 |
$recch = "b1"; |
---|
352 |
}elsif($recch == 161){ |
---|
353 |
$recch = "b2"; |
---|
354 |
}elsif($recch == 171){ |
---|
355 |
$recch = "b4"; |
---|
356 |
}elsif($recch == 181){ |
---|
357 |
$recch = "b9"; |
---|
358 |
}elsif($recch == 191){ |
---|
359 |
$recch = "b3"; |
---|
360 |
}elsif($recch == 192){ |
---|
361 |
$recch = "b3"; |
---|
362 |
}elsif($recch == 193){ |
---|
363 |
$recch = "b3"; |
---|
364 |
}elsif($recch == 211){ |
---|
365 |
$recch = "b5"; |
---|
366 |
}else{ |
---|
367 |
$recch = "b7"; |
---|
368 |
} |
---|
369 |
|
---|
370 |
|
---|
371 |
}elsif($bandtype == 2){ |
---|
372 |
|
---|
373 |
}else{ |
---|
374 |
&writelog("digitaltvrecording :ERROR :Unsupported and type (digital CS)."); |
---|
375 |
exit 3; |
---|
376 |
} |
---|
377 |
|
---|
378 |
|
---|
379 |
|
---|
380 |
if (-e "$toolpath/perl/tool/recpt1"){ |
---|
381 |
&writelog("digitaltvrecording DEBUG recpt1 --b25 $originalrecch $reclengthsec $outputfile "); |
---|
382 |
$oserr = system("$toolpath/perl/tool/recpt1 --b25 $originalrecch $reclengthsec $outputfile "); |
---|
383 |
$oserr = $oserr >> 8; |
---|
384 |
if ($oserr > 0){ |
---|
385 |
&writelog("digitaltvrecording :ERROR :PT1 is BUSY.$oserr"); |
---|
386 |
$errorflag = 2; |
---|
387 |
} |
---|
388 |
}else{ |
---|
389 |
&writelog("digitaltvrecording :ERROR :recpt1 not found. You must install $toolpath/tool/b25 and $toolpath/tool/recpt1."); |
---|
390 |
$errorflag = 1; |
---|
391 |
} |
---|
392 |
|
---|
393 |
if ($errorflag >= 1 ){ |
---|
394 |
|
---|
395 |
if (-e "$toolpath/perl/tool/recfriio"){ |
---|
396 |
|
---|
397 |
if (! -e "$toolpath/perl/tool/friiodetect"){ |
---|
398 |
system("touch $toolpath/perl/tool/friiodetect"); |
---|
399 |
system("chown foltia:foltia $toolpath/perl/tool/friiodetect"); |
---|
400 |
system("chmod 775 $toolpath/perl/tool/friiodetect"); |
---|
401 |
&writelog("digitaltvrecording :DEBUG make lock file.$toolpath/perl/tool/friiodetect"); |
---|
402 |
} |
---|
403 |
&writelog("digitaltvrecording DEBUG recfriio --b25 --lockfile $toolpath/perl/tool/friiodetect $recch $reclengthsec $outputfile "); |
---|
404 |
$oserr = system("$toolpath/perl/tool/recfriio --b25 --lockfile $toolpath/perl/tool/friiodetect $recch $reclengthsec $outputfile "); |
---|
405 |
$oserr = $oserr >> 8; |
---|
406 |
if ($oserr > 0){ |
---|
407 |
&writelog("digitaltvrecording :ERROR :friio is BUSY.$oserr"); |
---|
408 |
exit 2; |
---|
409 |
} |
---|
410 |
}else{ |
---|
411 |
&writelog("digitaltvrecording :ERROR :recfriio not found. You must install $toolpath/perl/tool/b25 and $toolpath/perl/tool/recfriio."); |
---|
412 |
exit 1; |
---|
413 |
} |
---|
414 |
} |
---|
415 |
|
---|
416 |
|
---|
417 |
if ($bssplitflag == 101){ |
---|
418 |
if (-e "$toolpath/perl/tool/TsSplitter.exe"){ |
---|
419 |
|
---|
420 |
system("wine $toolpath/perl/tool/TsSplitter.exe -EIT -ECM -EMM -OUT \"$outputpath\" -HD -SD2 -SD3 -1SEG -LOGFILE -WAIT2 $outputfile"); |
---|
421 |
$splitfile = $outputfile; |
---|
422 |
$splitfile =~ s/\.m2t$/_SD1.m2t/; |
---|
423 |
if (-e "$splitfile"){ |
---|
424 |
system("rm -rf $outputfile ; mv $splitfile $outputfile"); |
---|
425 |
&writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?."); |
---|
426 |
}else{ |
---|
427 |
&writelog("digitaltvrecording ERROR File not found:$splitfile."); |
---|
428 |
} |
---|
429 |
}else{ |
---|
430 |
&writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found."); |
---|
431 |
} |
---|
432 |
}elsif($bssplitflag == 102){ |
---|
433 |
if (-e "$toolpath/perl/tool/TsSplitter.exe"){ |
---|
434 |
|
---|
435 |
system("wine $toolpath/perl/tool/TsSplitter.exe -EIT -ECM -EMM -OUT \"$outputpath\" -HD -SD1 -SD3 -1SEG -LOGFILE -WAIT2 $outputfile"); |
---|
436 |
$splitfile = $outputfile; |
---|
437 |
$splitfile =~ s/\.m2t$/_SD2.m2t/; |
---|
438 |
if (-e "$splitfile"){ |
---|
439 |
system("rm -rf $outputfile ; mv $splitfile $outputfile"); |
---|
440 |
&writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?."); |
---|
441 |
}else{ |
---|
442 |
&writelog("digitaltvrecording ERROR File not found:$splitfile."); |
---|
443 |
} |
---|
444 |
}else{ |
---|
445 |
&writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found."); |
---|
446 |
} |
---|
447 |
}else{ |
---|
448 |
&writelog("digitaltvrecording DEBUG not split TS.$bssplitflag"); |
---|
449 |
} |
---|
450 |
|
---|
451 |
} |
---|
452 |
|
---|
453 |
|
---|