From 445fc6bc71c7f18389e148bc2b1a9f289d03755d Mon Sep 17 00:00:00 2001 From: Trek H Date: Fri, 24 Jan 2020 15:50:59 +1030 Subject: [PATCH] mjpeg-player: keeping track of loaded fragments --- .../hlsjs/controller/stream-controller.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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); }