diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index eec4e5d9..f5882c98 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -432,20 +432,23 @@ namespace Mist{ } for (std::set::iterator idx = tracks.begin(); idx != tracks.end(); idx++){ size_t i = *idx; + uint64_t lastUp = M.getLastUpdated(i); + //Prevent issues when getLastUpdated > current time. This can happen if the second rolls over exactly during this loop. + if (lastUp >= time){continue;} std::string codec = M.getCodec(i); std::string type = M.getType(i); uint64_t firstms = M.getFirstms(i); uint64_t lastms = M.getLastms(i); // if not updated for an entire buffer duration, or last updated track and this track differ // by an entire buffer duration, erase the track. - if ((time - M.getLastUpdated(i) > (bufferTime / 1000) || - (compareLast && activeTypes.count(type) && (time - M.getLastUpdated(i)) > 5 && + if ((time - lastUp > (bufferTime / 1000) || + (compareLast && activeTypes.count(type) && (time - lastUp) > 5 && ((compareLast < firstms && (firstms - compareLast) > bufferTime) || (compareFirst > lastms && (compareFirst - lastms) > bufferTime))))){ // erase this track - if ((time - M.getLastUpdated(i)) > (bufferTime / 1000)){ + if ((time - lastUp) > (bufferTime / 1000)){ WARN_MSG("Erasing %s track %zu (%s/%s) because not updated for %" PRIu64 "s (> %" PRIu64 "s)", - streamName.c_str(), i, type.c_str(), codec.c_str(), time - M.getLastUpdated(i), + streamName.c_str(), i, type.c_str(), codec.c_str(), time - lastUp, bufferTime / 1000); }else{ WARN_MSG("Erasing %s inactive track %zu (%s/%s) because it was inactive for 5+ seconds "