diff --git a/src/output/output.cpp b/src/output/output.cpp index 20de4ede..9537b7b3 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -39,10 +39,12 @@ namespace Mist { sought = false; isInitialized = false; isBlocking = false; + completeKeysOnly = false; lastStats = 0; maxSkipAhead = 7500; minSkipAhead = 5000; realTime = 1000; + completeKeyReadyTimeOut = false; if (myConn){ setBlocking(true); }else{ @@ -584,6 +586,47 @@ namespace Mist { Util::sleep(nxt.time - (((Util::getMS() - firstTime)*1000)+minSkipAhead)/realTime); } } + //delay the stream until its current keyframe is complete + if (completeKeysOnly){ + bool completeKeyReady = false; + int timeoutTries = 40;//attempts to updateMeta before timeOut and moving on; default is approximately 10 seconds + for (std::map::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){ + if (it->second.keys.size() >1){ + int thisTimeoutTries = ((it->second.lastms - it->second.firstms) / (it->second.keys.size()-1)) / 125; + if (thisTimeoutTries > timeoutTries) timeoutTries = thisTimeoutTries; + } + } + while(!completeKeyReady && timeoutTries>0){ + completeKeyReady = true; + for (std::map::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){ + if (!it->second.keys.size() || it->second.keys.rbegin()->getTime() + it->second.keys.rbegin()->getLength() <= nxt.time ){ + completeKeyReady = false; + break; + } + } + if (!completeKeyReady){ + if (completeKeyReadyTimeOut){ + INSANE_MSG("Complete Key not ready and time-out is being skipped"); + timeoutTries = 0; + }else{ + INSANE_MSG("Timeout: %d",timeoutTries); + timeoutTries--;//we count down + stats(); + Util::wait(250); + updateMeta(); + } + } + } + if (timeoutTries<=0){ + if (!completeKeyReadyTimeOut){ + INFO_MSG("Wait for keyframe Timeout triggered! Ended to avoid endless loops"); + } + completeKeyReadyTimeOut = true; + }else{ + //untimeout handling + completeKeyReadyTimeOut = false; + } + } if (curPage[nxt.tid]){ if (nxt.offset < curPage[nxt.tid].len){ unsigned long long nextTime = getDTSCTime(curPage[nxt.tid].mapped, nxt.offset); diff --git a/src/output/output.h b/src/output/output.h index f8a67632..e8c08477 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -73,6 +73,7 @@ namespace Mist { std::map nxtKeyNum;///< Contains the number of the next key, for page seeking purposes. std::set buffer;///< A sorted list of next-to-be-loaded packets. bool sought;///