source: palm/trunk/SCRIPTS/process_dvr_output @ 1046

Last change on this file since 1046 was 1046, checked in by maronga, 9 years ago

put scripts and utilities under GPL

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