1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
use DBI; |
---|
16 |
use DBD::Pg; |
---|
17 |
use DBD::SQLite; |
---|
18 |
use Schedule::At; |
---|
19 |
use Time::Local; |
---|
20 |
use Jcode; |
---|
21 |
|
---|
22 |
$path = $0; |
---|
23 |
$path =~ s/recwrap.pl$//i; |
---|
24 |
if ($path ne "./"){ |
---|
25 |
push( @INC, "$path"); |
---|
26 |
} |
---|
27 |
|
---|
28 |
require "foltialib.pl"; |
---|
29 |
|
---|
30 |
$recch = $ARGV[0] ; |
---|
31 |
if ($recch eq "" ){ |
---|
32 |
|
---|
33 |
print "usage recwrap.pl ch length(sec) [bitrate(5)] [TID] [NO] [PID]\n"; |
---|
34 |
exit; |
---|
35 |
} |
---|
36 |
|
---|
37 |
$recch = $ARGV[0] ; |
---|
38 |
$reclength = $ARGV[1] ; |
---|
39 |
$bitrate = $ARGV[2] ; |
---|
40 |
$tid = $ARGV[3] ; |
---|
41 |
$countno = $ARGV[4] ; |
---|
42 |
$pid = $ARGV[5] ; |
---|
43 |
$stationid = $ARGV[6] ; |
---|
44 |
$usedigital = $ARGV[7] ; |
---|
45 |
$digitalstationband = $ARGV[8] ; |
---|
46 |
$digitalch= $ARGV[9] ; |
---|
47 |
|
---|
48 |
|
---|
49 |
$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;; |
---|
50 |
|
---|
51 |
|
---|
52 |
if ($usedigital == 1){ |
---|
53 |
$extension = ".m2t"; |
---|
54 |
}else{ |
---|
55 |
$extension = ".m2p"; |
---|
56 |
} |
---|
57 |
|
---|
58 |
$outputfile = strftime("%Y%m%d-%H%M", localtime(time + 60)); |
---|
59 |
chomp($outputfile); |
---|
60 |
|
---|
61 |
if ($tid == 0){ |
---|
62 |
$outputfilename = "0--".$outputfile."-".$recch.$extension; |
---|
63 |
$mp4newstylefilename = "-0--".$outputfile."-".$recch; |
---|
64 |
}else{ |
---|
65 |
if ($countno == 0){ |
---|
66 |
$outputfilename = $tid ."--".$outputfile.$extension; |
---|
67 |
$mp4newstylefilename = "-" . $tid ."--".$outputfile; |
---|
68 |
}else{ |
---|
69 |
$outputfilename = $tid ."-".$countno."-".$outputfile.$extension; |
---|
70 |
$mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile; |
---|
71 |
} |
---|
72 |
} |
---|
73 |
|
---|
74 |
if ($usedigital == 1){ |
---|
75 |
|
---|
76 |
&writelog("recwrap RECSTART DIGITAL $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio"); |
---|
77 |
|
---|
78 |
$starttime = time(); |
---|
79 |
$oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio"); |
---|
80 |
$oserr = $oserr / 256; |
---|
81 |
|
---|
82 |
if ($oserr == 1){ |
---|
83 |
&writelog("recwrap ABORT recfile exist. [$outputfilename] $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno"); |
---|
84 |
exit; |
---|
85 |
}elsif ($oserr == 2){ |
---|
86 |
&writelog("recwrap ERR 2:friio busy;retry."); |
---|
87 |
&continuousrecordingcheck; |
---|
88 |
sleep(2); |
---|
89 |
$oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid N $outputfilename $tid $countno friio"); |
---|
90 |
$oserr = $oserr / 256; |
---|
91 |
if ($oserr == 2){ |
---|
92 |
&writelog("recwrap ERR 2:friio busy;Giving up digital recording."); |
---|
93 |
} |
---|
94 |
}elsif ($oserr == 3){ |
---|
95 |
&writelog("recwrap ABORT:ERR 3"); |
---|
96 |
exit ; |
---|
97 |
} |
---|
98 |
}else{ |
---|
99 |
|
---|
100 |
|
---|
101 |
if ($haveirdaunit == 1){ |
---|
102 |
|
---|
103 |
if ($recch == 0){ |
---|
104 |
|
---|
105 |
&writelog("recwrap Call Change STB CH :$pid"); |
---|
106 |
system ("$toolpath/perl/changestbch.pl $pid &"); |
---|
107 |
} |
---|
108 |
} |
---|
109 |
|
---|
110 |
if($recch == -10){ |
---|
111 |
|
---|
112 |
&writelog("recwrap Not recordable channel;exit:PID $pid"); |
---|
113 |
exit; |
---|
114 |
} |
---|
115 |
|
---|
116 |
&writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch"); |
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 |
$starttime = time(); |
---|
121 |
|
---|
122 |
$oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno"); |
---|
123 |
$oserr = $oserr / 256; |
---|
124 |
if ($oserr == 1){ |
---|
125 |
&writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
126 |
exit; |
---|
127 |
} |
---|
128 |
|
---|
129 |
} |
---|
130 |
|
---|
131 |
|
---|
132 |
$now = time(); |
---|
133 |
if ($now < $starttime + 100){ |
---|
134 |
$retrycounter = 0; |
---|
135 |
while($now < $starttime + 100){ |
---|
136 |
if($retrycounter >= 5){ |
---|
137 |
&writelog("recwrap WARNING Giving up recording."); |
---|
138 |
last; |
---|
139 |
} |
---|
140 |
&writelog("recwrap retry recording $now $starttime"); |
---|
141 |
|
---|
142 |
$starttime = time(); |
---|
143 |
if($outputfilename =~ /.m2t$/){ |
---|
144 |
$outputfilename =~ s/.m2t$/.m2p/; |
---|
145 |
} |
---|
146 |
$oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno"); |
---|
147 |
$now = time(); |
---|
148 |
$oserr = $oserr / 256; |
---|
149 |
if ($oserr == 1){ |
---|
150 |
&writelog("recwrap ABORT recfile exist. in resume process.[$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
151 |
exit; |
---|
152 |
} |
---|
153 |
$retrycounter++; |
---|
154 |
} |
---|
155 |
} |
---|
156 |
|
---|
157 |
&writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
$sth = $dbh->prepare($stmt{'recwrap.1'}); |
---|
162 |
$sth->execute($outputfilename, $pid); |
---|
163 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}"); |
---|
164 |
&changefilestatus($pid,$FILESTATUSRECEND); |
---|
165 |
|
---|
166 |
|
---|
167 |
$sth = $dbh->prepare($stmt{'recwrap.2'}); |
---|
168 |
$sth->execute($outputfilename); |
---|
169 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}"); |
---|
170 |
|
---|
171 |
|
---|
172 |
if (-e "$toolpath/perl/captureimagemaker.pl"){ |
---|
173 |
&writelog("recwrap Call captureimagemaker $outputfilename"); |
---|
174 |
&changefilestatus($pid,$FILESTATUSCAPTURE); |
---|
175 |
system ("$toolpath/perl/captureimagemaker.pl $outputfilename"); |
---|
176 |
&changefilestatus($pid,$FILESTATUSCAPEND); |
---|
177 |
} |
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
$sth = $dbh->prepare($stmt{'recwrap.3'}); |
---|
183 |
$sth->execute($tid); |
---|
184 |
@psptrcn= $sth->fetchrow_array; |
---|
185 |
if ($psptrcn[0] == 1 ){ |
---|
186 |
&writelog("recwrap Launch ipodtranscode.pl"); |
---|
187 |
exec ("$toolpath/perl/ipodtranscode.pl"); |
---|
188 |
exit; |
---|
189 |
} |
---|
190 |
|
---|
191 |
sub continuousrecordingcheck(){ |
---|
192 |
my $now = time() + 60 * 2; |
---|
193 |
&writelog("recwrap DEBUG continuousrecordingcheck() now $now"); |
---|
194 |
my @processes =`ps ax | grep recfriio`; |
---|
195 |
|
---|
196 |
my $psline = ""; |
---|
197 |
my @processline = ""; |
---|
198 |
my $pid = ""; |
---|
199 |
my @pid; |
---|
200 |
my $sth; |
---|
201 |
foreach (@processes){ |
---|
202 |
if (/friiodetect/) { |
---|
203 |
if (/^.[0-9]*\s/){ |
---|
204 |
push(@pid, $&); |
---|
205 |
} |
---|
206 |
} |
---|
207 |
} |
---|
208 |
|
---|
209 |
if (@pid > 0){ |
---|
210 |
my @filenameparts; |
---|
211 |
my $tid = ""; |
---|
212 |
my $startdate = ""; |
---|
213 |
my $starttime = ""; |
---|
214 |
my $startdatetime = ""; |
---|
215 |
my @recfile; |
---|
216 |
my $endtime = ""; |
---|
217 |
my $endtimeepoch = ""; |
---|
218 |
foreach $pid (@pid){ |
---|
219 |
|
---|
220 |
&writelog("recwrap DEBUG continuousrecordingcheck() PID $pid"); |
---|
221 |
|
---|
222 |
my @lsofoutput = `/usr/sbin/lsof -p $pid`; |
---|
223 |
my $filename = ""; |
---|
224 |
|
---|
225 |
foreach (@lsofoutput){ |
---|
226 |
if (/m2t/){ |
---|
227 |
@processline = split(/\s+/,$_); |
---|
228 |
$filename = $processline[8]; |
---|
229 |
$filename =~ s/$recfolderpath\///; |
---|
230 |
&writelog("recwrap DEBUG continuousrecordingcheck() FILENAME $filename"); |
---|
231 |
|
---|
232 |
@filenameparts = split(/-/,$filename); |
---|
233 |
$tid = $filenameparts[0]; |
---|
234 |
$startdate = $filenameparts[2]; |
---|
235 |
$starttime = $filenameparts[3]; |
---|
236 |
@filenameparts = split(/\./,$starttime); |
---|
237 |
$startdatetime = $startdate.$filenameparts[0]; |
---|
238 |
|
---|
239 |
&writelog("recwrap DEBUG continuousrecordingcheck() $stmt{'recwrap.7'}"); |
---|
240 |
$sth = $dbh->prepare($stmt{'recwrap.7'}); |
---|
241 |
&writelog("recwrap DEBUG continuousrecordingcheck() prepare"); |
---|
242 |
$sth->execute($tid, $startdatetime); |
---|
243 |
&writelog("recwrap DEBUG continuousrecordingcheck() execute"); |
---|
244 |
@recfile = $sth->fetchrow_array; |
---|
245 |
&writelog("recwrap DEBUG continuousrecordingcheck() @recfile $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] $recfile[6] $recfile[7] $recfile[8] $recfile[9] "); |
---|
246 |
|
---|
247 |
$endtime = $recfile[4]; |
---|
248 |
$endtimeepoch = &foldate2epoch($endtime); |
---|
249 |
&writelog("recwrap DEBUG continuousrecordingcheck() $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] endtimeepoch $endtimeepoch"); |
---|
250 |
if ($endtimeepoch < $now){ |
---|
251 |
|
---|
252 |
system("kill $pid"); |
---|
253 |
&writelog("recwrap recording process killed $pid/$endtimeepoch/$now"); |
---|
254 |
} |
---|
255 |
} |
---|
256 |
} |
---|
257 |
} |
---|
258 |
}else{ |
---|
259 |
|
---|
260 |
&writelog("recwrap No recording process killed."); |
---|
261 |
} |
---|
262 |
} |
---|
263 |
|
---|
264 |
|
---|
265 |
|
---|