TSSRT: fixes to timestamp rewriting

This commit is contained in:
Marco van Dijk 2023-11-29 11:34:12 +01:00 committed by Thulinma
parent d2d4b0acbe
commit 3fb92a01d3
4 changed files with 30 additions and 16 deletions

View file

@ -51,6 +51,7 @@ namespace Mist{
inputTSSRT::inputTSSRT(Util::Config *cfg, Socket::SRTConnection s) : Input(cfg){ inputTSSRT::inputTSSRT(Util::Config *cfg, Socket::SRTConnection s) : Input(cfg){
rawIdx = INVALID_TRACK_ID; rawIdx = INVALID_TRACK_ID;
lastRawPacket = 0; lastRawPacket = 0;
bootMSOffsetCalculated = false;
assembler.setLive(); assembler.setLive();
capa["name"] = "TSSRT"; capa["name"] = "TSSRT";
capa["desc"] = "This input allows for processing MPEG2-TS-based SRT streams. Use mode=listener " capa["desc"] = "This input allows for processing MPEG2-TS-based SRT streams. Use mode=listener "
@ -264,18 +265,23 @@ namespace Mist{
thisIdx = M.trackIDToIndex(thisPacket.getTrackId(), getpid()); thisIdx = M.trackIDToIndex(thisPacket.getTrackId(), getpid());
if (thisIdx == INVALID_TRACK_ID){getNext(idx);} if (thisIdx == INVALID_TRACK_ID){getNext(idx);}
uint64_t adjustTime = thisPacket.getTime() + timeStampOffset; uint64_t pktTimeWithOffset = thisPacket.getTime() + timeStampOffset;
if (lastTimeStamp || timeStampOffset){ if (lastTimeStamp || timeStampOffset){
if (lastTimeStamp + 5000 < adjustTime || lastTimeStamp > adjustTime + 5000){ uint64_t targetTime = Util::bootMS() - M.getBootMsOffset();
if (targetTime + 5000 < pktTimeWithOffset || targetTime > pktTimeWithOffset + 5000){
INFO_MSG("Timestamp jump " PRETTY_PRINT_MSTIME " -> " PRETTY_PRINT_MSTIME ", compensating.", INFO_MSG("Timestamp jump " PRETTY_PRINT_MSTIME " -> " PRETTY_PRINT_MSTIME ", compensating.",
PRETTY_ARG_MSTIME(lastTimeStamp), PRETTY_ARG_MSTIME(adjustTime)); PRETTY_ARG_MSTIME(targetTime), PRETTY_ARG_MSTIME(pktTimeWithOffset));
timeStampOffset += (lastTimeStamp - adjustTime); timeStampOffset += (targetTime - pktTimeWithOffset);
adjustTime = thisPacket.getTime() + timeStampOffset; pktTimeWithOffset = thisPacket.getTime() + timeStampOffset;
} }
} }
if (!lastTimeStamp){meta.setBootMsOffset(Util::bootMS() - adjustTime);} if (!bootMSOffsetCalculated){
lastTimeStamp = adjustTime; meta.setBootMsOffset((int64_t)Util::bootMS() - (int64_t)pktTimeWithOffset);
thisPacket.setTime(adjustTime); bootMSOffsetCalculated = true;
}
lastTimeStamp = pktTimeWithOffset;
thisPacket.setTime(pktTimeWithOffset);
thisTime = pktTimeWithOffset;
} }
bool inputTSSRT::openStreamSource(){return true;} bool inputTSSRT::openStreamSource(){return true;}

View file

@ -45,6 +45,7 @@ namespace Mist{
Util::ResizeablePointer rawBuffer; Util::ResizeablePointer rawBuffer;
size_t rawIdx; size_t rawIdx;
uint64_t lastRawPacket; uint64_t lastRawPacket;
bool bootMSOffsetCalculated;
}; };
}// namespace Mist }// namespace Mist

View file

@ -16,6 +16,7 @@ namespace Mist{
streamName = config->getString("streamname"); streamName = config->getString("streamname");
Util::setStreamName(streamName); Util::setStreamName(streamName);
pushOut = false; pushOut = false;
bootMSOffsetCalculated = false;
assembler.setLive(); assembler.setLive();
// Push output configuration // Push output configuration
if (config->getString("target").size()){ if (config->getString("target").size()){
@ -382,18 +383,23 @@ namespace Mist{
userSelect[thisIdx].reload(streamName, thisIdx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK); userSelect[thisIdx].reload(streamName, thisIdx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
} }
uint64_t adjustTime = thisPacket.getTime() + timeStampOffset; uint64_t pktTimeWithOffset = thisPacket.getTime() + timeStampOffset;
if (lastTimeStamp || timeStampOffset){ if (lastTimeStamp || timeStampOffset){
if (lastTimeStamp + 5000 < adjustTime || lastTimeStamp > adjustTime + 5000){ uint64_t targetTime = Util::bootMS() - M.getBootMsOffset();
if (targetTime + 5000 < pktTimeWithOffset || targetTime > pktTimeWithOffset + 5000){
INFO_MSG("Timestamp jump " PRETTY_PRINT_MSTIME " -> " PRETTY_PRINT_MSTIME ", compensating.", INFO_MSG("Timestamp jump " PRETTY_PRINT_MSTIME " -> " PRETTY_PRINT_MSTIME ", compensating.",
PRETTY_ARG_MSTIME(lastTimeStamp), PRETTY_ARG_MSTIME(adjustTime)); PRETTY_ARG_MSTIME(targetTime), PRETTY_ARG_MSTIME(pktTimeWithOffset));
timeStampOffset += (lastTimeStamp - adjustTime); timeStampOffset += (targetTime - pktTimeWithOffset);
adjustTime = thisPacket.getTime() + timeStampOffset; pktTimeWithOffset = thisPacket.getTime() + timeStampOffset;
} }
} }
if (!lastTimeStamp){meta.setBootMsOffset(Util::bootMS() - adjustTime);} if (!bootMSOffsetCalculated){
lastTimeStamp = adjustTime; meta.setBootMsOffset(Util::bootMS() - pktTimeWithOffset);
thisPacket.setTime(adjustTime); bootMSOffsetCalculated = true;
}
lastTimeStamp = pktTimeWithOffset;
thisPacket.setTime(pktTimeWithOffset);
thisTime = pktTimeWithOffset;
bufferLivePacket(thisPacket); bufferLivePacket(thisPacket);
} }
} }

View file

@ -29,6 +29,7 @@ namespace Mist{
Socket::UDPConnection pushSock; Socket::UDPConnection pushSock;
TS::Stream tsIn; TS::Stream tsIn;
TS::Assembler assembler; TS::Assembler assembler;
bool bootMSOffsetCalculated;
Socket::SRTConnection & srtConn; Socket::SRTConnection & srtConn;
}; };