#!/bin/bash

# to_h264_server starten				jsffm@web.de

#set -x

h264=h264

#r=$(ps -A | grep to_h264_server)
#if [ "$r" != "" ]
#then
#    echo $r
#    echo "already running"
#    exit 99
#fi

wo=$(which to_h264_server)
conf=$wo.conf

    r=$(ps -A | grep -v to_h264_server | grep to_h264)
    if [ "$r" == "" -a `vdr-dbus-send /Status status.IsReplaying|grep string|wc -c` -lt 27 ]
    then
	while read line
	do
        	until [ `ping -c1 tv >/dev/null 2>&1;echo $?` -gt '0' -a `vdr-dbus-send /Status status.IsReplaying|grep string|wc -c` -lt 27 ]
		do
			sleep 60
		done
	    	#echo $line
	    	if [ -e $line ]
	    	then
			#echo ok
			for rh in $(find $line -name $h264)
			do
		    		#echo $rh
		    		dh=$(dirname "$rh")
		    		cd "$dh"
#		    		to_h264 auto > h264.log 2> h264.err
		    		conv_h264 "$dh" > h264.log 2> h264.err
		    		cd /tmp
		    		#break
			done
	    	fi
		done < $conf
    fi
