source: palm/trunk/SCRIPTS/process_dvr_output @ 350

Last change on this file since 350 was 336, checked in by raasch, 16 years ago

several small bugfixes; some more dvrp changes

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