From 57308dbd34ff5a2e7526bbcb81bf8450890747e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20Kr=C3=A6mmer=20Nielsen?= Date: Fri, 31 Mar 2017 18:52:18 +0200 Subject: [PATCH] Fixed resync on lost segments --- monitor-dai.sh | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/monitor-dai.sh b/monitor-dai.sh index 09fe0cf..c89c467 100755 --- a/monitor-dai.sh +++ b/monitor-dai.sh @@ -115,17 +115,7 @@ function monitorStream() { local lastUsedSegment="" lastUsedStreamTime=0 # Stored for use of recording previous segment when seeing ad block local doRecord=0 doStopRecord=0 local syncMode=-1 # (-1=get first, x=saw last at, 0=synched) In syncmode we try to request every second until we see a change to get a more precise time sync - - real_time=$(date +%s) - - if [ -n "$streamDelay" ]; then - stream_time=$(($real_time - $streamDelay)) - pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") - echo >&2 "NOTICE: Using time-offset of -$streamDelay seconds so time is $pretty_time, real time is $(date ${realtime} +"%Y-%m-%d %H:%M:%S")" - else - stream_time="$real_time" - pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") - fi + local stream_time="" # unknown echo >&2 "$pretty_time: INFO: Started monitoring using: $stream" @@ -133,6 +123,19 @@ function monitorStream() { starttime=$(date +%s) warn_not_a_playlist=1 + # Set time to real time first request + if [ -z "$stream_time" ]; then + if [ -n "$streamDelay" ]; then + stream_time=$(($starttime - $streamDelay)) + pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") + echo >&2 "NOTICE: Using time-offset of -${streamDelay}s. Stream time is $pretty_time, real time is $(date ${realtime} +"%Y-%m-%d %H:%M:%S")" + else + stream_time="$starttime" + pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") + echo >&2 "NOTICE: Setting stream time to real time: $pretty_time" + fi + fi + TMPFILE=$(mktemp) || fatal "Can not write tmp-file" curl $BASIC_CURL_PARAMS -o "$TMPFILE" "$stream" if [ $? -eq 0 ]; then @@ -166,8 +169,9 @@ function monitorStream() { 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: WARN: Lost segments ($curSeq > $nextSeq)... resetting..." - failed=10 + echo >&2 "$pretty_time: WARN: Lost segments ($curSeq > $nextSeq)." + stream_time= + syncMode=-1 fi #echo >&2 "$pretty_time: Current mode length: $curLength" nextSeq=$(($curSeq + 1)) -- 2.52.0