Several fixes:

- Fixed bug in stream health function causing loop if track not active
- Fixed DTSC pulls ignoring data before the live point
- Improved async buffers (deque mode) to spread the tracks more fairly
- DTSC pull now implements "ping" and "error" commands
- DTSC pulls report suspicious keyframe intervals to the origin and ask for confirmation
- DTSC output now accepts these reports and disconnects if there is no match in keyframe intervals
- Outputs in async mode now keep the seek point in all tracks when reselecting
- Outputs in async mode now default to a starting position in each track that is at a keyframe roughly halfway in the buffer
- Outputs in async mode now ignore playback rate (always fastest possible)
- Removed code duplication in prepareNext function
- Reordered the prepareNext function somewhat to be easier to follow for humans
- DTSC output no longer overrides initialSeek function, now uses default implementation
- Sanitycheck output now supports both sync and async modes, supports printing multiple timestamps for multiple tracks
This commit is contained in:
Thulinma 2022-01-06 12:52:47 +01:00
parent b89875ea37
commit f560b88bfe
9 changed files with 257 additions and 222 deletions

View file

@ -165,7 +165,7 @@ namespace Mist{
DTSC::Packet metaPack(dataPacket.data(), dataPacket.size());
DTSC::Meta nM("", metaPack.getScan());
meta.reInit(streamName, false);
meta.merge(nM);
meta.merge(nM, true, false);
std::set<size_t> validTracks = M.getMySourceTracks(getpid());
userSelect.clear();
for (std::set<size_t>::iterator it = validTracks.begin(); it != validTracks.end(); ++it){
@ -342,20 +342,39 @@ namespace Mist{
// userClient.keepAlive();
std::string cmd;
thisPacket.getString("cmd", cmd);
if (cmd != "reset"){
if (cmd == "reset"){
// Read next packet
thisPacket.reInit(srcConn);
if (thisPacket.getVersion() != DTSC::DTSC_HEAD){
meta.clear();
continue;
}
DTSC::Meta nM("", thisPacket.getScan());
meta.merge(nM, true, false);
thisPacket.reInit(srcConn); // read the next packet before continuing
continue; // parse the next packet before returning
}
if (cmd == "error"){
thisPacket.getString("msg", cmd);
Util::logExitReason("%s", cmd.c_str());
thisPacket.null();
return;
}
if (cmd == "ping"){
thisPacket.reInit(srcConn);
JSON::Value prep;
prep["cmd"] = "ok";
prep["msg"] = "Pong!";
srcConn.SendNow("DTCM");
char sSize[4] ={0, 0, 0, 0};
Bit::htobl(sSize, prep.packedSize());
srcConn.SendNow(sSize, 4);
prep.sendTo(srcConn);
continue;
}
// Read next packet
INFO_MSG("Unhandled command: %s", cmd.c_str());
thisPacket.reInit(srcConn);
if (thisPacket.getVersion() != DTSC::DTSC_HEAD){
meta.clear();
continue;
}
DTSC::Meta nM("", thisPacket.getScan());
meta.merge(nM, true, false);
thisPacket.reInit(srcConn); // read the next packet before continuing
continue; // parse the next packet before returning
continue;
}
if (thisPacket.getVersion() == DTSC::DTSC_HEAD){
DTSC::Meta nM("", thisPacket.getScan());
@ -364,7 +383,33 @@ namespace Mist{
continue; // parse the next packet before returning
}
thisTime = thisPacket.getTime();
thisIdx = thisPacket.getTrackId();
thisIdx = M.trackIDToIndex(thisPacket.getTrackId());
if (thisPacket.getFlag("keyframe") && M.trackValid(thisIdx)){
uint32_t shrtest_key = 0xFFFFFFFFul;
uint32_t longest_key = 0;
DTSC::Keys Mkeys(M.keys(thisIdx));
uint32_t firstKey = Mkeys.getFirstValid();
uint32_t endKey = Mkeys.getEndValid();
uint32_t checkKey = (endKey-firstKey <= 3)?firstKey:endKey-3;
for (uint32_t k = firstKey; k+1 < endKey; k++){
uint64_t kDur = Mkeys.getDuration(k);
if (!kDur){continue;}
if (kDur > longest_key && k >= checkKey){longest_key = kDur;}
if (kDur < shrtest_key){shrtest_key = kDur;}
}
if (longest_key > shrtest_key*2){
JSON::Value prep;
prep["cmd"] = "check_key_duration";
prep["id"] = thisPacket.getTrackId();
prep["duration"] = longest_key;
srcConn.SendNow("DTCM");
char sSize[4] ={0, 0, 0, 0};
Bit::htobl(sSize, prep.packedSize());
srcConn.SendNow(sSize, 4);
prep.sendTo(srcConn);
INFO_MSG("Key duration %" PRIu32 " is quite long - confirming with upstream source", longest_key);
}
}
return; // we have a packet
}
}