1 | #!/bin/ksh |
---|
2 | #--------------------------------------------------------------------------------# |
---|
3 | # This file is part of PALM. |
---|
4 | # |
---|
5 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
6 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
7 | # either version 3 of the License, or (at your option) any later version. |
---|
8 | # |
---|
9 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
11 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
12 | # |
---|
13 | # You should have received a copy of the GNU General Public License along with |
---|
14 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | # |
---|
16 | # Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
17 | #--------------------------------------------------------------------------------# |
---|
18 | # |
---|
19 | # Current revisions: |
---|
20 | # ----------------- |
---|
21 | # |
---|
22 | # Former revisions: |
---|
23 | # ----------------- |
---|
24 | # $Id: process_dvr_output 1310 2014-03-14 08:01:56Z lvollmer $ |
---|
25 | # |
---|
26 | # 1046 2012-11-09 14:38:45Z maronga |
---|
27 | # code put under GPL (PALM 3.9) |
---|
28 | # |
---|
29 | # process_dvr_output - a script processing dvr steering + data files |
---|
30 | |
---|
31 | # This script determines the number of streams opened by the dvr software |
---|
32 | # and creates one single dvrs- and html-file which allow the dvr-plugin |
---|
33 | # to display all streams in one sequence. |
---|
34 | |
---|
35 | # Last changes: |
---|
36 | # 16/03/09 - Siggi - Generating the first version |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | # Variable declarations + default values |
---|
41 | camera=false |
---|
42 | create_config_file=false |
---|
43 | create_sequence_output=false |
---|
44 | data_catalog=`pwd` |
---|
45 | dvrp_output=rtsp |
---|
46 | file_identifier=all_streams |
---|
47 | groundplate=false |
---|
48 | palm_run_identifier="unknown_run" |
---|
49 | topography=false |
---|
50 | |
---|
51 | typeset -i a acceleration=1 k i j nstream nscenes |
---|
52 | |
---|
53 | |
---|
54 | # Read shellscript options |
---|
55 | while getopts :a:cd:f:ls option |
---|
56 | do |
---|
57 | case $option in |
---|
58 | (a) acceleration=$OPTARG;; |
---|
59 | (c) create_config_file=true;; |
---|
60 | (d) data_catalog=$OPTARG;; |
---|
61 | (f) file_identifier=$OPTARG;; |
---|
62 | (l) dvrp_output=local;; |
---|
63 | (s) create_sequence_output=true;; |
---|
64 | (\?) printf "\n +++ unknown option $OPTARG \n" |
---|
65 | printf "\n allowed option are -d, -f, -l, -s \n" |
---|
66 | exit;; |
---|
67 | esac |
---|
68 | done |
---|
69 | |
---|
70 | |
---|
71 | # Create the config file for the streaming server; do nothing else |
---|
72 | if [[ $create_config_file = true ]] |
---|
73 | then |
---|
74 | cp ${PALM_BIN}/.dvrserver.config . |
---|
75 | |
---|
76 | # Entering the BASEDIR, UID and GID into this file |
---|
77 | user_id=`id -u` |
---|
78 | group_id=`id -g` |
---|
79 | |
---|
80 | # data directory is always the current working directory |
---|
81 | sed "s/<replace by dvr data directory>/./g" .dvrserver.config > .dvrserver.1 |
---|
82 | sed "s/<replace by user id>/$user_id/g" .dvrserver.1 > .dvrserver.2 |
---|
83 | sed "s/<replace by group id>/$group_id/g" .dvrserver.2 > .dvrserver.3 |
---|
84 | mv .dvrserver.3 .dvrserver.config |
---|
85 | rm .dvrserver.1 .dvrserver.2 |
---|
86 | exit |
---|
87 | fi |
---|
88 | |
---|
89 | |
---|
90 | # Find out the PALM run identifier |
---|
91 | if [[ -f CPU_MEASURES ]] |
---|
92 | then |
---|
93 | palm_run_identifier=`head -1 CPU_MEASURES` |
---|
94 | fi |
---|
95 | |
---|
96 | |
---|
97 | # Process the streaming server output |
---|
98 | if [[ $dvrp_output = rtsp ]] |
---|
99 | then |
---|
100 | |
---|
101 | # Change to the given directory |
---|
102 | cd $data_catalog |
---|
103 | |
---|
104 | |
---|
105 | # Find out the number of streams |
---|
106 | (( i = 0 )) |
---|
107 | while true |
---|
108 | do |
---|
109 | (( i = i + 1 )) |
---|
110 | if (( i < 10 )) |
---|
111 | then |
---|
112 | cstream=0$i |
---|
113 | else |
---|
114 | cstream=$i |
---|
115 | fi |
---|
116 | |
---|
117 | if [[ $(ls -1 *.* | grep -c $cstream) = 0 ]] |
---|
118 | then |
---|
119 | (( i = i - 1 )) |
---|
120 | break |
---|
121 | fi |
---|
122 | |
---|
123 | # find out the stream name |
---|
124 | streamname[$i]=`ls -1 ${cstream}_*-ge.dvrs | cut -f1 -d"-"` |
---|
125 | |
---|
126 | # get addres |
---|
127 | adr[$i]=`grep ADR= ${streamname[$i]}.dvrs | grep '*' | cut -f2 -d"="` |
---|
128 | |
---|
129 | # get maxbytes |
---|
130 | maxbytes[$i]=`head -1 ${streamname[$i]}.max` |
---|
131 | |
---|
132 | # get number of frames |
---|
133 | frames[$i]=`tail -1 ${streamname[$i]}.max` |
---|
134 | |
---|
135 | done |
---|
136 | |
---|
137 | nstream=$i |
---|
138 | nscenes=$nstream |
---|
139 | |
---|
140 | |
---|
141 | # Check, if there are files containing the camera data, the ground plate |
---|
142 | # and topography data. |
---|
143 | # Check the first stream only, because all streams have the same files. |
---|
144 | if [[ -f ${streamname[1]}_camera.max ]] |
---|
145 | then |
---|
146 | camera=true |
---|
147 | adr_camera=`grep ADR= ${streamname[1]}.dvrs | grep 'camera' | cut -f2 -d"="` |
---|
148 | maxbytes_camera=`head -1 ${streamname[1]}_camera.max` |
---|
149 | (( nscenes = nscenes + 1 )) |
---|
150 | fi |
---|
151 | if [[ -f ${streamname[1]}_groundplate.max ]] |
---|
152 | then |
---|
153 | groundplate=true |
---|
154 | adr_groundplate=`echo $adr_camera | sed "s/camera/groundplate/g"` |
---|
155 | maxbytes_groundplate=`head -1 ${streamname[1]}_groundplate.max` |
---|
156 | (( nscenes = nscenes + 1 )) |
---|
157 | fi |
---|
158 | if [[ -f ${streamname[1]}_topography.max ]] |
---|
159 | then |
---|
160 | topography=true |
---|
161 | adr_topography=`echo $adr_camera | sed "s/camera/topography/g"` |
---|
162 | maxbytes_topography=`head -1 ${streamname[1]}_topography.max` |
---|
163 | (( nscenes = nscenes + 1 )) |
---|
164 | fi |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | # Start with writing the dvrs file for the combined streams |
---|
169 | dvr_file=${file_identifier}_streaming.dvrs |
---|
170 | |
---|
171 | echo "SCENES=$nscenes" > $dvr_file |
---|
172 | |
---|
173 | # First, add the static scenes |
---|
174 | if [[ $camera = true ]] |
---|
175 | then |
---|
176 | echo "MED=TCP" >> $dvr_file |
---|
177 | echo "ADR=$adr_camera" >> $dvr_file |
---|
178 | echo "MAXBYTES=$maxbytes_camera" >> $dvr_file |
---|
179 | echo "FRAMES=1" >> $dvr_file |
---|
180 | echo "FRAMES_P_SEC=0" >> $dvr_file |
---|
181 | echo "SCENEEND" >> $dvr_file |
---|
182 | fi |
---|
183 | |
---|
184 | if [[ $groundplate = true ]] |
---|
185 | then |
---|
186 | echo "MED=TCP" >> $dvr_file |
---|
187 | echo "ADR=$adr_groundplate" >> $dvr_file |
---|
188 | echo "MAXBYTES=$maxbytes_groundplate" >> $dvr_file |
---|
189 | echo "FRAMES=1" >> $dvr_file |
---|
190 | echo "FRAMES_P_SEC=0" >> $dvr_file |
---|
191 | echo "SCENEEND" >> $dvr_file |
---|
192 | fi |
---|
193 | |
---|
194 | if [[ $topography = true ]] |
---|
195 | then |
---|
196 | echo "MED=TCP" >> $dvr_file |
---|
197 | echo "ADR=$adr_topography" >> $dvr_file |
---|
198 | echo "MAXBYTES=$maxbytes_topography" >> $dvr_file |
---|
199 | echo "FRAMES=1" >> $dvr_file |
---|
200 | echo "FRAMES_P_SEC=0" >> $dvr_file |
---|
201 | echo "SCENEEND" >> $dvr_file |
---|
202 | fi |
---|
203 | |
---|
204 | |
---|
205 | # Now add the streams |
---|
206 | (( i = 0 )) |
---|
207 | while (( i < nstream )) |
---|
208 | do |
---|
209 | |
---|
210 | (( i = i + 1 )) |
---|
211 | |
---|
212 | echo "MED=TCP" >> $dvr_file |
---|
213 | echo "ADR=${adr[$i]}" >> $dvr_file |
---|
214 | echo "MAXBYTES=${maxbytes[$i]}" >> $dvr_file |
---|
215 | echo "FRAMES=${frames[$i]}" >> $dvr_file |
---|
216 | echo "FRAMES_P_SEC=25" >> $dvr_file |
---|
217 | echo "SCENEEND" >> $dvr_file |
---|
218 | |
---|
219 | done |
---|
220 | |
---|
221 | |
---|
222 | # Change path to the current file identifier |
---|
223 | # Remove path because BASEDIR of streaming server is set to "." |
---|
224 | # sed "s/DATA_DVR/${file_identifier}_dvr/g" $dvr_file > tmp_file |
---|
225 | sed "s/DATA_DVR\///g" $dvr_file > tmp_file |
---|
226 | mv tmp_file $dvr_file |
---|
227 | |
---|
228 | |
---|
229 | # If there is a dvr configuration file, set the BASEDIR to the parent |
---|
230 | # directory of the above given path (i.e. ".") |
---|
231 | if [[ -f .dvrserver.config ]] |
---|
232 | then |
---|
233 | old_path=`grep BASEDIR .dvrserver.config` |
---|
234 | sed "s&${old_path}&BASEDIR=.&g" .dvrserver.config > .dvrserver.config.new |
---|
235 | mv .dvrserver.config.new .dvrserver.config |
---|
236 | fi |
---|
237 | |
---|
238 | |
---|
239 | # Create the html file for the combined streames |
---|
240 | cp 01_*-ge.html tmp.html |
---|
241 | replace=$(echo `grep src= tmp.html`) |
---|
242 | sed "s&${replace}&src=\"${file_identifier}_streaming.dvrs\"&g" tmp.html > tmp1.html |
---|
243 | if [[ "$palm_run_identifier" = "" ]] |
---|
244 | then |
---|
245 | cp tmp1.html ${file_identifier}_streaming.html |
---|
246 | else |
---|
247 | sed "s&DATA_DVR/${streamname[1]}/\*\*\*\*\*.dvr (DVR 3D Streaming)&DVR 3D streaming generated by $palm_run_identifier&g" tmp1.html > ${file_identifier}_streaming.html |
---|
248 | fi |
---|
249 | rm tmp.html tmp1.html |
---|
250 | |
---|
251 | |
---|
252 | # Informative messages |
---|
253 | printf "\n\n *** processing dvr stream output:" |
---|
254 | printf "\n number of detected streams = $nstream" |
---|
255 | printf "\n stream names:" |
---|
256 | |
---|
257 | (( i = 0 )) |
---|
258 | while (( i < nstream )) |
---|
259 | do |
---|
260 | |
---|
261 | (( i = i + 1 )) |
---|
262 | printf " ${streamname[$i]}" |
---|
263 | |
---|
264 | done |
---|
265 | printf "\n" |
---|
266 | |
---|
267 | |
---|
268 | else |
---|
269 | |
---|
270 | # This is the branch for local output (dvrp_output=local). |
---|
271 | # Find out the number of streams. |
---|
272 | (( i = 0 )) |
---|
273 | while true |
---|
274 | do |
---|
275 | |
---|
276 | (( i = i + 1 )) |
---|
277 | if (( i < 10 )) |
---|
278 | then |
---|
279 | cstream=0$i |
---|
280 | else |
---|
281 | cstream=$i |
---|
282 | fi |
---|
283 | |
---|
284 | if [[ $(ls -1 *.* | grep -c ${cstream}_) = 0 ]] |
---|
285 | then |
---|
286 | (( i = i - 1 )) |
---|
287 | break |
---|
288 | fi |
---|
289 | |
---|
290 | # find out the stream name |
---|
291 | streamname[$i]=`ls -1 ${cstream}_*.camera.dvr | cut -f1 -d"."` |
---|
292 | |
---|
293 | done |
---|
294 | |
---|
295 | # Exit, if there are no streams. |
---|
296 | [[ $i = 0 ]] && exit |
---|
297 | |
---|
298 | nstream=$i |
---|
299 | |
---|
300 | mkdir -p ${data_catalog}/sequence_data |
---|
301 | |
---|
302 | |
---|
303 | # First, merge static scenes into one file |
---|
304 | if [[ -f ${streamname[1]}.camera.dvr ]] |
---|
305 | then |
---|
306 | cat ${streamname[1]}.camera.dvr >> ${data_catalog}/sequence_data/static_scenes.dvr |
---|
307 | fi |
---|
308 | |
---|
309 | if [[ -f ${streamname[1]}.groundplate.dvr ]] |
---|
310 | then |
---|
311 | cat ${streamname[1]}.groundplate.dvr >> ${data_catalog}/sequence_data/static_scenes.dvr |
---|
312 | fi |
---|
313 | |
---|
314 | if [[ -f ${streamname[1]}.topography.dvr ]] |
---|
315 | then |
---|
316 | cat ${streamname[1]}.topography.dvr >> ${data_catalog}/sequence_data/static_scenes.dvr |
---|
317 | fi |
---|
318 | |
---|
319 | |
---|
320 | # Find out the number of frames |
---|
321 | frames[1]=`grep sequence ${streamname[1]}_00000.html | cut -f2 -d";" | cut -f1 -d'"' | cut -f2 -d"-"` |
---|
322 | |
---|
323 | |
---|
324 | # Now, merge the data, frame by frame |
---|
325 | (( j = 0 )) |
---|
326 | while (( j < ${frames[1]} )) |
---|
327 | do |
---|
328 | |
---|
329 | nframe=`printf "%05d" $j` |
---|
330 | |
---|
331 | (( i = 0 )) |
---|
332 | while (( i < nstream )) |
---|
333 | do |
---|
334 | (( i = i + 1 )) |
---|
335 | cat ${streamname[$i]}_$nframe.dvr >> ${data_catalog}/sequence_data/$nframe.dvr |
---|
336 | done |
---|
337 | |
---|
338 | (( j = j + 1 )) |
---|
339 | |
---|
340 | done |
---|
341 | |
---|
342 | |
---|
343 | # Create the html file to be used for the sequence mode |
---|
344 | cp ${streamname[1]}_00000.html tmp1.html |
---|
345 | sed "s&${streamname[1]}_camera.dvr&sequence_data/static_scenes.dvr&g" tmp1.html > tmp2.html |
---|
346 | sed "s&${streamname[1]}_&sequence_data/&g" tmp2.html > tmp3.html |
---|
347 | if [[ "$palm_run_identifier" = "" ]] |
---|
348 | then |
---|
349 | cp tmp3.html ${file_identifier}_sequence.html |
---|
350 | else |
---|
351 | sed "s&sequence_data/%05d.dvr (DVR 3D Sequence)&DVR 3D sequence generated by $palm_run_identifier&g" tmp3.html > ${file_identifier}_sequence.html |
---|
352 | fi |
---|
353 | rm tmp1.html tmp2.html tmp3.html |
---|
354 | mv ${file_identifier}_sequence.html ${data_catalog} |
---|
355 | |
---|
356 | |
---|
357 | # Informative messages |
---|
358 | printf "\n\n *** processing dvr local output (using dvrp_output=local):" |
---|
359 | printf "\n number of detected streams = $nstream" |
---|
360 | printf "\n stream names:" |
---|
361 | |
---|
362 | (( i = 0 )) |
---|
363 | while (( i < nstream )) |
---|
364 | do |
---|
365 | |
---|
366 | (( i = i + 1 )) |
---|
367 | printf " ${streamname[$i]}" |
---|
368 | |
---|
369 | done |
---|
370 | printf "\n" |
---|
371 | |
---|
372 | fi |
---|
373 | |
---|
374 | |
---|
375 | # Create output for viewing dvr data in sequence mode |
---|
376 | if [[ $create_sequence_output = true ]] |
---|
377 | then |
---|
378 | |
---|
379 | rm -rf sequence_data |
---|
380 | mkdir sequence_data |
---|
381 | |
---|
382 | # First, merge static scenes into one file |
---|
383 | if [[ $camera = true ]] |
---|
384 | then |
---|
385 | cat ${streamname[1]}/camera.dvr >> sequence_data/static_scenes.dvr |
---|
386 | fi |
---|
387 | |
---|
388 | if [[ $groundplate = true ]] |
---|
389 | then |
---|
390 | cat ${streamname[1]}/groundplate.dvr >> sequence_data/static_scenes.dvr |
---|
391 | fi |
---|
392 | |
---|
393 | if [[ $topography = true ]] |
---|
394 | then |
---|
395 | cat ${streamname[1]}/topography.dvr >> sequence_data/static_scenes.dvr |
---|
396 | fi |
---|
397 | |
---|
398 | |
---|
399 | # Now, merge the data, frame by frame |
---|
400 | (( j = 0 )) |
---|
401 | (( k = 0 )) |
---|
402 | (( a = 0 )) |
---|
403 | while (( j < ${frames[1]} )) |
---|
404 | do |
---|
405 | |
---|
406 | rframe=`printf "%05d" $j` |
---|
407 | |
---|
408 | if (( a == 0 )) |
---|
409 | then |
---|
410 | |
---|
411 | wframe=`printf "%05d" $k` |
---|
412 | (( k = k + 1 )) |
---|
413 | |
---|
414 | (( i = 0 )) |
---|
415 | while (( i < nstream )) |
---|
416 | do |
---|
417 | (( i = i + 1 )) |
---|
418 | cat ${streamname[$i]}/$rframe.dvr >> sequence_data/$wframe.dvr |
---|
419 | done |
---|
420 | |
---|
421 | |
---|
422 | fi |
---|
423 | |
---|
424 | (( a = a + 1 )) |
---|
425 | if (( a == acceleration )) |
---|
426 | then |
---|
427 | (( a = 0 )) |
---|
428 | fi |
---|
429 | |
---|
430 | (( j = j + 1 )) |
---|
431 | |
---|
432 | done |
---|
433 | |
---|
434 | |
---|
435 | # Create the html file to be used for the sequence mode |
---|
436 | cp ${streamname[1]}.html tmp1.html |
---|
437 | sed "s/camera.dvr/static_scenes.dvr/g" tmp1.html > tmp2.html |
---|
438 | sed "s&${streamname[1]}&sequence_data&g" tmp2.html > tmp3.html |
---|
439 | sed "s/;0-0/;0-$wframe/g" tmp3.html > tmp4.html |
---|
440 | if [[ "$palm_run_identifier" = "" ]] |
---|
441 | then |
---|
442 | cp tmp4.html ${file_identifier}_sequence.html |
---|
443 | else |
---|
444 | sed "s&DATA_DVR/sequence_data/\*\*\*\*\*.dvr (DVR 3D Sequence)&DVR 3D sequence generated by $palm_run_identifier&g" tmp4.html > ${file_identifier}_sequence.html |
---|
445 | fi |
---|
446 | rm tmp1.html tmp2.html tmp3.html tmp4.html |
---|
447 | |
---|
448 | printf " data for using sequence mode generated" |
---|
449 | |
---|
450 | fi |
---|
451 | |
---|
452 | |
---|
453 | |
---|
454 | # Change back to directory from where script has been called |
---|
455 | cd - > /dev/null 2>&1 |
---|