[260] | 1 | #!/bin/ksh |
---|
[1046] | 2 | #--------------------------------------------------------------------------------# |
---|
[2696] | 3 | # This file is part of the PALM model system. |
---|
[1046] | 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 | # |
---|
[4481] | 16 | # Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[1046] | 17 | #--------------------------------------------------------------------------------# |
---|
| 18 | # |
---|
| 19 | # Current revisions: |
---|
| 20 | # ----------------- |
---|
[2716] | 21 | # |
---|
| 22 | # |
---|
[1046] | 23 | # Former revisions: |
---|
| 24 | # ----------------- |
---|
| 25 | # $Id: process_dvr_output 4481 2020-03-31 18:55:54Z suehring $ |
---|
[2716] | 26 | # Corrected "Former revisions" section |
---|
[1046] | 27 | # |
---|
[2716] | 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 | # |
---|
[1047] | 34 | # 1046 2012-11-09 14:38:45Z maronga |
---|
| 35 | # code put under GPL (PALM 3.9) |
---|
| 36 | # |
---|
[260] | 37 | # process_dvr_output - a script processing dvr steering + data files |
---|
| 38 | |
---|
[261] | 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 | |
---|
[260] | 43 | # Last changes: |
---|
| 44 | # 16/03/09 - Siggi - Generating the first version |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
[262] | 48 | # Variable declarations + default values |
---|
[260] | 49 | camera=false |
---|
[336] | 50 | create_config_file=false |
---|
[261] | 51 | create_sequence_output=false |
---|
| 52 | data_catalog=`pwd` |
---|
[262] | 53 | dvrp_output=rtsp |
---|
[261] | 54 | file_identifier=all_streams |
---|
[260] | 55 | groundplate=false |
---|
[336] | 56 | palm_run_identifier="unknown_run" |
---|
[260] | 57 | topography=false |
---|
| 58 | |
---|
[336] | 59 | typeset -i a acceleration=1 k i j nstream nscenes |
---|
[260] | 60 | |
---|
| 61 | |
---|
[262] | 62 | # Read shellscript options |
---|
[336] | 63 | while getopts :a:cd:f:ls option |
---|
[260] | 64 | do |
---|
| 65 | case $option in |
---|
[336] | 66 | (a) acceleration=$OPTARG;; |
---|
| 67 | (c) create_config_file=true;; |
---|
[260] | 68 | (d) data_catalog=$OPTARG;; |
---|
| 69 | (f) file_identifier=$OPTARG;; |
---|
[262] | 70 | (l) dvrp_output=local;; |
---|
[261] | 71 | (s) create_sequence_output=true;; |
---|
[260] | 72 | (\?) printf "\n +++ unknown option $OPTARG \n" |
---|
[262] | 73 | printf "\n allowed option are -d, -f, -l, -s \n" |
---|
[260] | 74 | exit;; |
---|
| 75 | esac |
---|
| 76 | done |
---|
| 77 | |
---|
| 78 | |
---|
[336] | 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 | |
---|
[262] | 98 | # Find out the PALM run identifier |
---|
| 99 | if [[ -f CPU_MEASURES ]] |
---|
| 100 | then |
---|
| 101 | palm_run_identifier=`head -1 CPU_MEASURES` |
---|
| 102 | fi |
---|
[261] | 103 | |
---|
[336] | 104 | |
---|
[262] | 105 | # Process the streaming server output |
---|
| 106 | if [[ $dvrp_output = rtsp ]] |
---|
| 107 | then |
---|
[261] | 108 | |
---|
[262] | 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 ]] |
---|
[260] | 153 | then |
---|
[262] | 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 )) |
---|
[260] | 158 | fi |
---|
[262] | 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 |
---|
[260] | 173 | |
---|
[262] | 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 ]] |
---|
[260] | 183 | then |
---|
[262] | 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 |
---|
[260] | 190 | fi |
---|
| 191 | |
---|
[262] | 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 |
---|
[260] | 201 | |
---|
[262] | 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 |
---|
[260] | 211 | |
---|
| 212 | |
---|
[262] | 213 | # Now add the streams |
---|
| 214 | (( i = 0 )) |
---|
| 215 | while (( i < nstream )) |
---|
| 216 | do |
---|
[260] | 217 | |
---|
[262] | 218 | (( i = i + 1 )) |
---|
[260] | 219 | |
---|
[262] | 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 |
---|
[260] | 226 | |
---|
[262] | 227 | done |
---|
[260] | 228 | |
---|
| 229 | |
---|
[262] | 230 | # Change path to the current file identifier |
---|
[336] | 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 |
---|
[262] | 234 | mv tmp_file $dvr_file |
---|
[260] | 235 | |
---|
| 236 | |
---|
[262] | 237 | # If there is a dvr configuration file, set the BASEDIR to the parent |
---|
[336] | 238 | # directory of the above given path (i.e. ".") |
---|
[262] | 239 | if [[ -f .dvrserver.config ]] |
---|
| 240 | then |
---|
| 241 | old_path=`grep BASEDIR .dvrserver.config` |
---|
[336] | 242 | sed "s&${old_path}&BASEDIR=.&g" .dvrserver.config > .dvrserver.config.new |
---|
[262] | 243 | mv .dvrserver.config.new .dvrserver.config |
---|
| 244 | fi |
---|
[260] | 245 | |
---|
| 246 | |
---|
[262] | 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 |
---|
[260] | 258 | |
---|
| 259 | |
---|
[262] | 260 | # Informative messages |
---|
| 261 | printf "\n\n *** processing dvr stream output:" |
---|
| 262 | printf "\n number of detected streams = $nstream" |
---|
| 263 | printf "\n stream names:" |
---|
[260] | 264 | |
---|
[262] | 265 | (( i = 0 )) |
---|
| 266 | while (( i < nstream )) |
---|
| 267 | do |
---|
[260] | 268 | |
---|
[262] | 269 | (( i = i + 1 )) |
---|
| 270 | printf " ${streamname[$i]}" |
---|
[260] | 271 | |
---|
[262] | 272 | done |
---|
| 273 | printf "\n" |
---|
[260] | 274 | |
---|
| 275 | |
---|
[262] | 276 | else |
---|
[260] | 277 | |
---|
[262] | 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 |
---|
[260] | 283 | |
---|
[262] | 284 | (( i = i + 1 )) |
---|
| 285 | if (( i < 10 )) |
---|
| 286 | then |
---|
| 287 | cstream=0$i |
---|
| 288 | else |
---|
| 289 | cstream=$i |
---|
| 290 | fi |
---|
[261] | 291 | |
---|
[262] | 292 | if [[ $(ls -1 *.* | grep -c ${cstream}_) = 0 ]] |
---|
| 293 | then |
---|
| 294 | (( i = i - 1 )) |
---|
| 295 | break |
---|
| 296 | fi |
---|
[261] | 297 | |
---|
[262] | 298 | # find out the stream name |
---|
| 299 | streamname[$i]=`ls -1 ${cstream}_*.camera.dvr | cut -f1 -d"."` |
---|
[261] | 300 | |
---|
[262] | 301 | done |
---|
[261] | 302 | |
---|
[262] | 303 | # Exit, if there are no streams. |
---|
| 304 | [[ $i = 0 ]] && exit |
---|
[261] | 305 | |
---|
[262] | 306 | nstream=$i |
---|
[261] | 307 | |
---|
[262] | 308 | mkdir -p ${data_catalog}/sequence_data |
---|
[261] | 309 | |
---|
| 310 | |
---|
[262] | 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 |
---|
[261] | 316 | |
---|
[262] | 317 | if [[ -f ${streamname[1]}.groundplate.dvr ]] |
---|
| 318 | then |
---|
| 319 | cat ${streamname[1]}.groundplate.dvr >> ${data_catalog}/sequence_data/static_scenes.dvr |
---|
| 320 | fi |
---|
[261] | 321 | |
---|
[262] | 322 | if [[ -f ${streamname[1]}.topography.dvr ]] |
---|
| 323 | then |
---|
| 324 | cat ${streamname[1]}.topography.dvr >> ${data_catalog}/sequence_data/static_scenes.dvr |
---|
| 325 | fi |
---|
[261] | 326 | |
---|
[262] | 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 |
---|
[261] | 384 | if [[ $create_sequence_output = true ]] |
---|
| 385 | then |
---|
| 386 | |
---|
[336] | 387 | rm -rf sequence_data |
---|
[261] | 388 | mkdir sequence_data |
---|
| 389 | |
---|
[262] | 390 | # First, merge static scenes into one file |
---|
[261] | 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 | |
---|
[262] | 407 | # Now, merge the data, frame by frame |
---|
[261] | 408 | (( j = 0 )) |
---|
[336] | 409 | (( k = 0 )) |
---|
| 410 | (( a = 0 )) |
---|
[261] | 411 | while (( j < ${frames[1]} )) |
---|
| 412 | do |
---|
| 413 | |
---|
[336] | 414 | rframe=`printf "%05d" $j` |
---|
[261] | 415 | |
---|
[336] | 416 | if (( a == 0 )) |
---|
| 417 | then |
---|
[261] | 418 | |
---|
[336] | 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 | |
---|
[261] | 438 | (( j = j + 1 )) |
---|
| 439 | |
---|
| 440 | done |
---|
| 441 | |
---|
| 442 | |
---|
[262] | 443 | # Create the html file to be used for the sequence mode |
---|
[261] | 444 | cp ${streamname[1]}.html tmp1.html |
---|
| 445 | sed "s/camera.dvr/static_scenes.dvr/g" tmp1.html > tmp2.html |
---|
[262] | 446 | sed "s&${streamname[1]}&sequence_data&g" tmp2.html > tmp3.html |
---|
[336] | 447 | sed "s/;0-0/;0-$wframe/g" tmp3.html > tmp4.html |
---|
[262] | 448 | if [[ "$palm_run_identifier" = "" ]] |
---|
| 449 | then |
---|
[336] | 450 | cp tmp4.html ${file_identifier}_sequence.html |
---|
[262] | 451 | else |
---|
[336] | 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 |
---|
[262] | 453 | fi |
---|
[336] | 454 | rm tmp1.html tmp2.html tmp3.html tmp4.html |
---|
[261] | 455 | |
---|
| 456 | printf " data for using sequence mode generated" |
---|
| 457 | |
---|
| 458 | fi |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | |
---|
[262] | 462 | # Change back to directory from where script has been called |
---|
| 463 | cd - > /dev/null 2>&1 |
---|