Improved output timing
This commit is contained in:
parent
b12c0254e1
commit
075756d646
2 changed files with 24 additions and 6 deletions
|
@ -64,6 +64,7 @@ namespace Mist{
|
|||
isInitialized = false;
|
||||
isBlocking = false;
|
||||
needsLookAhead = 0;
|
||||
extraKeepAway = 0;
|
||||
lastStats = 0;
|
||||
maxSkipAhead = 7500;
|
||||
realTime = 1000;
|
||||
|
@ -522,7 +523,7 @@ namespace Mist{
|
|||
nxtKeyNum[trackId] = 0;
|
||||
}
|
||||
stats(true);
|
||||
Util::wait(100);
|
||||
playbackSleep(100);
|
||||
pageNum = pageNumForKey(trackId, keyNum);
|
||||
}
|
||||
|
||||
|
@ -752,7 +753,7 @@ namespace Mist{
|
|||
continue;
|
||||
}//ignore missing tracks
|
||||
DTSC::Track & thisTrack = myMeta.tracks[*ti];
|
||||
if (thisTrack.lastms < seekPos+needsLookAhead+thisTrack.minKeepAway){good = false; break;}
|
||||
if (thisTrack.lastms < seekPos+needsLookAhead+extraKeepAway+thisTrack.minKeepAway){good = false; break;}
|
||||
if (mainTrack == *ti){continue;}//skip self
|
||||
if (thisTrack.lastms == thisTrack.firstms){
|
||||
HIGH_MSG("Skipping track %lu, last equals first", *ti);
|
||||
|
@ -786,6 +787,16 @@ namespace Mist{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Waits for the given amount of millis, increasing the realtime playback
|
||||
/// related times as needed to keep smooth playback intact.
|
||||
void Output::playbackSleep(uint64_t millis){
|
||||
if (realTime){
|
||||
firstTime += millis;
|
||||
extraKeepAway += millis;
|
||||
}
|
||||
Util::wait(millis);
|
||||
}
|
||||
|
||||
int Output::run(){
|
||||
DONTEVEN_MSG("MistOut client handler started");
|
||||
|
@ -821,7 +832,8 @@ namespace Mist{
|
|||
uint32_t sleepTime = std::min((uint32_t)250, needsLookAhead);
|
||||
//wait at most double the look ahead time, plus ten seconds
|
||||
uint32_t timeoutTries = (needsLookAhead / sleepTime) * 2 + (10000/sleepTime);
|
||||
uint64_t needsTime = thisPacket.getTime() + needsLookAhead;
|
||||
uint64_t needsTime = thisPacket.getTime() + needsLookAhead;
|
||||
bool firstTime = true;
|
||||
while(--timeoutTries && keepGoing()){
|
||||
bool lookReady = true;
|
||||
for (std::set<long unsigned int>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
|
||||
|
@ -834,7 +846,11 @@ namespace Mist{
|
|||
}
|
||||
}
|
||||
if (lookReady){break;}
|
||||
Util::wait(sleepTime);
|
||||
if (firstTime){
|
||||
firstTime = false;
|
||||
}else{
|
||||
playbackSleep(sleepTime);
|
||||
}
|
||||
stats();
|
||||
updateMeta();
|
||||
}
|
||||
|
@ -986,7 +1002,7 @@ namespace Mist{
|
|||
//VoD might be slow, so we check VoD case also, just in case
|
||||
if (currKeyOpen.count(nxt.tid) && (currKeyOpen[nxt.tid] == (unsigned int)nextPage || nextPage == -1)){
|
||||
if (++emptyCount < 100){
|
||||
Util::wait(250);
|
||||
playbackSleep(250);
|
||||
//we're waiting for new data to show up
|
||||
if (emptyCount % 64 == 0){
|
||||
reconnect();//reconnect every 16 seconds
|
||||
|
@ -1073,7 +1089,7 @@ namespace Mist{
|
|||
while(myMeta.live && counter < 40 && myMeta.tracks[nxt.tid].getKey(nxtKeyNum[nxt.tid]).getTime() != thisPacket.getTime()){
|
||||
if (counter++){
|
||||
//Only sleep 250ms if this is not the first updatemeta try
|
||||
Util::wait(250);
|
||||
playbackSleep(250);
|
||||
}
|
||||
updateMeta();
|
||||
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, thisPacket.getTime());
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace Mist {
|
|||
virtual void onFail();
|
||||
virtual void requestHandler();
|
||||
static Util::Config * config;
|
||||
void playbackSleep(uint64_t millis);
|
||||
private://these *should* not be messed with in child classes.
|
||||
std::map<unsigned long, unsigned int> currKeyOpen;
|
||||
void loadPageForKey(long unsigned int trackId, long long int keyNum);
|
||||
|
@ -90,6 +91,7 @@ namespace Mist {
|
|||
std::string UA; ///< User Agent string, if known.
|
||||
uint16_t uaDelay;///<Seconds to wait before setting the UA.
|
||||
uint64_t lastRecv;
|
||||
uint64_t extraKeepAway;
|
||||
long long unsigned int firstTime;///< Time of first packet after last seek. Used for real-time sending.
|
||||
virtual std::string getConnectedHost();
|
||||
virtual std::string getConnectedBinHost();
|
||||
|
|
Loading…
Add table
Reference in a new issue