Improved seek function for real-time protocols

This commit is contained in:
Thulinma 2018-08-08 12:24:50 +02:00
parent 791fc5eae9
commit 01e15663e9
3 changed files with 23 additions and 3 deletions

View file

@ -592,7 +592,8 @@ namespace Mist{
}
/// Prepares all tracks from selectedTracks for seeking to the specified ms position.
void Output::seek(unsigned long long pos){
/// If toKey is true, clips the seek to the nearest keyframe if the main track is a video track.
void Output::seek(unsigned long long pos, bool toKey){
sought = true;
if (!isInitialized){
initialize();
@ -602,6 +603,25 @@ namespace Mist{
if (myMeta.live){
updateMeta();
}
if (toKey){
long unsigned int mainTrack = getMainSelectedTrack();
//abort toKey if there are no keys in the main track
if (!myMeta.tracks.count(mainTrack) || !myMeta.tracks[mainTrack].keys.size()){
WARN_MSG("Sync-seeking impossible (main track invalid); performing regular seek instead");
seek(pos);
return;
}
DTSC::Track & Trk = myMeta.tracks[mainTrack];
if (Trk.type == "video"){
unsigned long long seekPos = 0;
for (std::deque<DTSC::Key>::iterator it = Trk.keys.begin(); it != Trk.keys.end(); ++it){
unsigned long long currPos = it->getTime();
if (currPos > pos){break;}//stop if we're past the point we wanted
seekPos = currPos;
}
pos = seekPos;
}
}
MEDIUM_MSG("Seeking to %llums", pos);
std::set<long unsigned int> seekTracks = selectedTracks;
for (std::set<long unsigned int>::iterator it = seekTracks.begin(); it != seekTracks.end(); it++){