Tweaked seek/isReadyForPlay implementations, fix HLS support for large key durations.

This commit is contained in:
Thulinma 2016-06-08 00:01:24 +02:00
parent e6ff699ad8
commit 7483bd9fd4
4 changed files with 46 additions and 2 deletions

View file

@ -305,9 +305,12 @@ namespace Mist {
} }
bool inputBuffer::removeKey(unsigned int tid) { bool inputBuffer::removeKey(unsigned int tid) {
if ((myMeta.tracks[tid].keys.size() < 2 || myMeta.tracks[tid].fragments.size() < 2) && config->is_active) { //Make sure we have at least 3 whole fragments at all times,
//unless we're shutting down the whole buffer right now
if (myMeta.tracks[tid].fragments.size() < 5 && config->is_active) {
return false; return false;
} }
//If we're shutting down, and this track is empty, abort
if (!myMeta.tracks[tid].keys.size()) { if (!myMeta.tracks[tid].keys.size()) {
return false; return false;
} }

View file

@ -216,7 +216,7 @@ namespace Mist {
selectDefaultTracks(); selectDefaultTracks();
} }
unsigned int mainTrack = getMainSelectedTrack(); unsigned int mainTrack = getMainSelectedTrack();
if (mainTrack && myMeta.tracks.count(mainTrack) && myMeta.tracks[mainTrack].keys.size() >= 2){ if (mainTrack && myMeta.tracks.count(mainTrack) && (myMeta.tracks[mainTrack].keys.size() >= 2 || myMeta.tracks[mainTrack].lastms - myMeta.tracks[mainTrack].firstms > 5000)){
return true; return true;
}else{ }else{
HIGH_MSG("NOT READY YET (%lu tracks, %lu = %lu keys)", myMeta.tracks.size(), getMainSelectedTrack(), myMeta.tracks[getMainSelectedTrack()].keys.size()); HIGH_MSG("NOT READY YET (%lu tracks, %lu = %lu keys)", myMeta.tracks.size(), getMainSelectedTrack(), myMeta.tracks[getMainSelectedTrack()].keys.size());

View file

@ -32,6 +32,46 @@ namespace Mist {
//capa["canRecord"].append("m3u"); //capa["canRecord"].append("m3u");
} }
/// Same as default implementation, except it will never play the very last keyframe
/// unless that is the only keyframe available.
void OutProgressiveMP4::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 newest keyframe, unless that is <5s, then seek to the oldest keyframe
bool first = true;
for (std::deque<DTSC::Key>::reverse_iterator it = myMeta.tracks[mainTrack].keys.rbegin(); it != myMeta.tracks[mainTrack].keys.rend(); ++it){
seekPos = it->getTime();
if (first){
first = false;
continue;
}
if (seekPos < 5000){continue;}//if we're near the start, skip back
bool good = true;
//check if all tracks have data for this point in time
for (std::set<unsigned long>::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].lastms < 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);
}
long long unsigned OutProgressiveMP4::estimateFileSize() { long long unsigned OutProgressiveMP4::estimateFileSize() {
long long unsigned retVal = 0; long long unsigned retVal = 0;
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++) { for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++) {

View file

@ -49,6 +49,7 @@ namespace Mist {
void onHTTP(); void onHTTP();
void sendNext(); void sendNext();
void sendHeader(); void sendHeader();
void initialSeek();
protected: protected:
long long fileSize; long long fileSize;
long long byteStart; long long byteStart;