|
|
@@ -127,8 +127,10 @@ function HlsStreamReader(src, options) {
|
|
|
this.noData = !!options.noData;
|
|
|
|
|
|
// dates are inclusive
|
|
|
- this.startDate = options.startDate;
|
|
|
- this.stopDate = options.stopDate;
|
|
|
+ this.startDate = new Date(options.startDate);
|
|
|
+ this.stopDate = new Date(options.stopDate);
|
|
|
+
|
|
|
+ this.maxStallTime = options.maxStallTime || Infinity;
|
|
|
|
|
|
this.index = null;
|
|
|
this.readState = {
|
|
|
@@ -138,11 +140,21 @@ function HlsStreamReader(src, options) {
|
|
|
};
|
|
|
this.watch = {}; // used to stop buffering on expired segments
|
|
|
|
|
|
+ this.indexStallSince = null;
|
|
|
+
|
|
|
function getUpdateInterval(updated) {
|
|
|
- if (updated && self.index.segments.length)
|
|
|
+ if (updated && self.index.segments.length) {
|
|
|
+ self.indexStallSince = null;
|
|
|
return Math.min(self.index.target_duration, self.index.segments[self.index.segments.length-1].duration);
|
|
|
- else
|
|
|
+ } else {
|
|
|
+ if (self.indexStallSince) {
|
|
|
+ if ((Date.now() - +self.indexStallSince) > self.maxStallTime)
|
|
|
+ return -1;
|
|
|
+ } else {
|
|
|
+ self.indexStallSince = new Date();
|
|
|
+ }
|
|
|
return self.index.target_duration / 2;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function initialSeqNo() {
|
|
|
@@ -200,6 +212,8 @@ function HlsStreamReader(src, options) {
|
|
|
|
|
|
if (self.index && !self.index.ended && self.readable) {
|
|
|
var updateInterval = getUpdateInterval(updated);
|
|
|
+ if (updateInterval <= 0)
|
|
|
+ return self.emit('error', new Error('index stall'));
|
|
|
debug('scheduling index refresh', updateInterval);
|
|
|
setTimeout(updateindex, Math.max(1, updateInterval)*1000);
|
|
|
}
|