diff --git a/cmd/mjpeg-player/hlsjs/controller/stream-controller.js b/cmd/mjpeg-player/hlsjs/controller/stream-controller.js index 31fd0828..27cd7a1c 100644 --- a/cmd/mjpeg-player/hlsjs/controller/stream-controller.js +++ b/cmd/mjpeg-player/hlsjs/controller/stream-controller.js @@ -38,20 +38,30 @@ class StreamController extends EventHandler { this.audioCodecSwap = false; this.stallReported = false; this.gapController = null; - this.currentFrag = 0; + this.currentFragIndex = 0; + this.lastSN = 0; + this.fragments = []; } _fetchPayloadOrEos(levelDetails) { - this.fragments = levelDetails.fragments; + // Keep track of any new frags and load them. + for (let i = 0; i < levelDetails.fragments.length; i++) { + let frag = levelDetails.fragments[i]; + if (frag.sn > this.lastSN) { + console.log("adding fragment: " + frag.sn); + this.fragments.push(frag); + this.lastSN = frag.sn; + } + } this._loadFragment(); } _loadFragment() { let fragLen = this.fragments.length; - if (this.currentFrag >= fragLen) { + if (this.currentFragIndex >= fragLen) { return; } - this.hls.trigger(Event.FRAG_LOADING, { frag: this.fragments[this.currentFrag++] }); + this.hls.trigger(Event.FRAG_LOADING, { frag: this.fragments[this.currentFragIndex++] }); } onLevelLoaded(data) { @@ -63,11 +73,6 @@ class StreamController extends EventHandler { console.log(`level ${newLevelId} loaded [${newDetails.startSN},${newDetails.endSN}],duration:${duration}`); - if (newDetails.live) { - console.log("handling of this case is not implemented"); - } else { - newDetails.PTSKnown = false; - } // override level info this.levelLastLoaded = newLevelId; this.hls.trigger(Event.LEVEL_UPDATED, { details: newDetails, level: newLevelId }); @@ -96,7 +101,6 @@ class StreamController extends EventHandler { } this.nextLoadPosition = this.startPosition; } - this._fetchPayloadOrEos(levelDetails); }