From f48b2f2877795b97cf28c7b08523990e6d74ec94 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 17 Oct 2016 13:59:52 +0200 Subject: [PATCH] Added live syncing code to RTSP output --- src/output/output_rtsp.cpp | 19 +++++++++++++++++-- src/output/output_rtsp.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/output/output_rtsp.cpp b/src/output/output_rtsp.cpp index a9341d52..a329ff82 100644 --- a/src/output/output_rtsp.cpp +++ b/src/output/output_rtsp.cpp @@ -18,6 +18,7 @@ namespace Mist { minSkipAhead = 0; expectTCP = false; isPushing = false; + lastTimeSync = 0; } /// Function used to send RTP packets over UDP @@ -81,8 +82,8 @@ namespace Mist { char * dataPointer = 0; unsigned int dataLen = 0; thisPacket.getString("data", dataPointer, dataLen); - unsigned int tid = thisPacket.getTrackId(); - unsigned int timestamp = thisPacket.getTime(); + uint32_t tid = thisPacket.getTrackId(); + uint64_t timestamp = thisPacket.getTime(); //if we're past the pausing point, seek to it, and pause immediately if (pausepoint && timestamp > pausepoint){ @@ -90,6 +91,20 @@ namespace Mist { stop(); return; } + + + if (myMeta.live && lastTimeSync + 666 < timestamp){ + lastTimeSync = timestamp; + updateMeta(); + DTSC::Track & mainTrk = myMeta.tracks[getMainSelectedTrack()]; + // The extra 1000ms here is for the metadata sync delay. + // It can be removed once we get rid of that. + if (timestamp + 1000 + needsLookAhead < mainTrk.keys.rbegin()->getTime() && mainTrk.lastms - mainTrk.keys.rbegin()->getTime() > needsLookAhead){ + INFO_MSG("Skipping forward %llums (%llu ms LA)", mainTrk.keys.rbegin()->getTime() - thisPacket.getTime(), needsLookAhead); + seek(mainTrk.keys.rbegin()->getTime()); + return; + } + } void * socket = 0; void (*callBack)(void *, char *, unsigned int, unsigned int) = 0; diff --git a/src/output/output_rtsp.h b/src/output/output_rtsp.h index c04fd78f..4d427abd 100644 --- a/src/output/output_rtsp.h +++ b/src/output/output_rtsp.h @@ -163,6 +163,7 @@ namespace Mist { unsigned int pausepoint;///< Position to pause at, when reached HTTP::Parser HTTP_R, HTTP_S; std::string source; + uint64_t lastTimeSync; bool expectTCP; bool handleTCP(); void handleUDP();