diff --git a/src/output/output.cpp b/src/output/output.cpp index 39898d77..b60693a5 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -533,20 +533,29 @@ namespace Mist { return 0; } + /// Returns the ID of the main selected track, or 0 if no tracks are selected. + /// The main track is the first video track, if any, and otherwise the first other track. + long unsigned int Output::getMainSelectedTrack(){ + if (!selectedTracks.size()){ + return 0; + } + for (std::set::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){ + if (myMeta.tracks[*it].type == "video"){ + return *it; + } + } + return *(selectedTracks.begin()); + } + void Output::prepareNext(){ if (!sought){ - unsigned int firstms = 0x0; - for (std::set::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){ - lastKeyTime[*it] = 0xFFFFFFFF; - if (myMeta.tracks[*it].firstms > firstms){ - firstms = myMeta.tracks[*it].firstms; - } - } if (myMeta.live){ - if (firstms < 5000){ - firstms = 0; + long unsigned int mainTrack = getMainSelectedTrack(); + unsigned long long seekPos = mymeta.tracks[mainTrack].keys.begin()->getTime(); + if (seekPos < 5000){ + seekPos = 0; } - seek(firstms); + seek(seekPos); }else{ seek(0); } diff --git a/src/output/output.h b/src/output/output.h index dfacfb90..fbb8fffe 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -57,6 +57,7 @@ namespace Mist { bool seek(int tid, long long pos, bool getNextKey = false); void stop(); void setBlocking(bool blocking); + long unsigned int getMainSelectedTrack(); void updateMeta(); static bool listenMode(){return true;} //virtuals. The optional virtuals have default implementations that do as little as possible. @@ -75,7 +76,6 @@ namespace Mist { long long unsigned int firstTime;///< Time of first packet after last seek. Used for real-time sending. std::map nxtKeyNum;///< Contains the number of the next key, for page seeking purposes. std::set buffer;///< A sorted list of next-to-be-loaded packets. - std::map lastKeyTime;///< Stores the time of the last keyframe, for preventing duplicates bool sought;///