From b14b5f9bf5c52ca1a4d51d7516816878f8e83c66 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 23 Jul 2016 13:08:20 +0200 Subject: [PATCH] Varioius stability and verbosity tweaks for DTSC, RTMP and in general --- src/output/output_dtsc.cpp | 37 +++++++++++++++++++++++++++++++++++-- src/output/output_dtsc.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/output/output_dtsc.cpp b/src/output/output_dtsc.cpp index 0327e0f0..8cf832bf 100644 --- a/src/output/output_dtsc.cpp +++ b/src/output/output_dtsc.cpp @@ -51,6 +51,40 @@ namespace Mist { } } + /// Seeks to the first sync'ed keyframe of the main track. + /// Aborts if there is no main track or it has no keyframes. + void OutDTSC::initialSeek(){ + unsigned long long seekPos = 0; + if (myMeta.live){ + long unsigned int mainTrack = getMainSelectedTrack(); + //cancel if there are no keys in the main track + if (!myMeta.tracks.count(mainTrack) || !myMeta.tracks[mainTrack].keys.size()){return;} + //seek to the oldest keyframe + for (std::deque::iterator it = myMeta.tracks[mainTrack].keys.begin(); it != myMeta.tracks[mainTrack].keys.end(); ++it){ + seekPos = it->getTime(); + bool good = true; + //check if all tracks have data for this point in time + for (std::set::iterator ti = selectedTracks.begin(); ti != selectedTracks.end(); ++ti){ + if (mainTrack == *ti){continue;}//skip self + if (!myMeta.tracks.count(*ti)){ + HIGH_MSG("Skipping track %lu, not in tracks", *ti); + continue; + }//ignore missing tracks + if (myMeta.tracks[*ti].lastms == myMeta.tracks[*ti].firstms){ + HIGH_MSG("Skipping track %lu, last equals first", *ti); + continue; + }//ignore point-tracks + if (myMeta.tracks[*ti].firstms > seekPos){good = false; break;} + HIGH_MSG("Track %lu is good", *ti); + } + //if yes, seek here + if (good){break;} + } + } + MEDIUM_MSG("Initial seek to %llums", seekPos); + seek(seekPos); + } + void OutDTSC::sendNext(){ //If there are now more selectable tracks, select the new track and do a seek to the current timestamp //Set sentHeader to false to force it to send init data @@ -65,7 +99,7 @@ namespace Mist { if (selectedTracks.size() > prevTrackCount){ INFO_MSG("Picked up new track - selecting it and resetting state."); sentHeader = false; - initialSeek(); + seek(currentTime()); return; } } @@ -86,7 +120,6 @@ namespace Mist { if (myMeta.live){ realTime = 0; } - seek(0); } void OutDTSC::onRequest(){ diff --git a/src/output/output_dtsc.h b/src/output/output_dtsc.h index bc96e25f..7721fe38 100644 --- a/src/output/output_dtsc.h +++ b/src/output/output_dtsc.h @@ -10,6 +10,7 @@ namespace Mist { void onRequest(); void sendNext(); void sendHeader(); + void initialSeek(); private: std::string getStatsName(); std::string salt;