local expectedAdLength=-1
local mode="UNKNOWN"
local curLength=0
+ local failed=0
+ local target_duration=$TARGET_DURATION
real_time=$(date +%s)
stream_time=$(($real_time - $STREAM_TIME_SCREW))
stream_time=$(echo "$stream_time + $nextSegmentLength" | bc)
pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S")
if [[ $curSeq -ne $nextSeq ]]; then
- echo >&2 "$pretty_time: Skipped a segment by mistake ($curSeq > $nextSeq)"
+ echo >&2 "$pretty_time: WARN: Skipped a segment by mistake ($curSeq > $nextSeq)"
fi
#echo >&2 "$pretty_time: Current mode length: $curLength"
nextSeq=$(($curSeq + 1))
tag="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"
if [ "$tag" == "EXT-X-TARGETDURATION" ]; then
- if [ "$value" != "$TARGET_DURATION" ]; then
- echo "$pretty_time: Changing target durationt to: $value"
- TARGET_DURATION="$value"
+ if [ "$value" != "$target_duration" ]; then
+ echo "$pretty_time: Changing target duration to: $value"
+ target_duration="$value"
fi
elif [ "$tag" == "EXTINF" ]; then
nextSegmentLength=$value
if [ $warn_not_a_playlist -eq 1 ]; then
echo >&2 "$pretty_time: ERROR: Not a valid playlist ($stream)"
+ failed=$(($failed + 1))
+ else
+ failed=0
fi
else
- echo >&2 "$pretty_time: Unable to request: $stream"
+ echo >&2 "$pretty_time: Unable to request: $stream"
+ failed=$(($failed + 1))
fi
rm "$TMPFILE"
endtime=$(date +%s)
- waittime=$(($TARGET_DURATION - ($endtime-$starttime)))
+ waittime=$(($target_duration - ($endtime-$starttime)))
if [ "$waittime" -gt 0 ]; then
sleep $waittime
fi
+
+ if [ "$failed" -ge 2 ]; then
+ echo >&2 "$pretty_time: ERROR: Stream failed twice.. resetting..."
+ return
+ fi
done
}
-streamurl=$(resolveFirstStream "$1")
-if [ -e "$streamurl" ]; then
- echo >&2 "Invalid HLS-stream: $1"
-fi
+while true; do
+ streamurl=$(resolveFirstStream "$1")
+ if [ -e "$streamurl" ]; then
+ echo >&2 "Invalid HLS-stream: $1"
+ sleep 10
+ fi
+ monitorStream "$streamurl"
+done
-monitorStream "$streamurl"