source: palm/trunk/SCRIPTS/process_dvr_output @ 3138

Last change on this file since 3138 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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