|
|
@@ -50,8 +50,14 @@ function checknext(reader) {
|
|
|
if (seq === state.nextSeq)
|
|
|
state.nextSeq++;
|
|
|
|
|
|
- if (object)
|
|
|
+ if (object) {
|
|
|
+ reader.watch[object.seq] = object.stream;
|
|
|
+ oncemore(object.stream).once('end', 'error', function() {
|
|
|
+ delete reader.watch[object.seq];
|
|
|
+ });
|
|
|
+
|
|
|
state.active = reader.push(object);
|
|
|
+ }
|
|
|
|
|
|
checknext(reader);
|
|
|
});
|
|
|
@@ -122,7 +128,8 @@ function HlsStreamReader(src, options) {
|
|
|
nextSeq:-1,
|
|
|
active:false,
|
|
|
fetching:null
|
|
|
- }
|
|
|
+ };
|
|
|
+ this.watch = {}; // used to stop buffering on expired segments
|
|
|
|
|
|
function getUpdateInterval(updated) {
|
|
|
if (updated && self.index.segments.length)
|
|
|
@@ -140,6 +147,19 @@ function HlsStreamReader(src, options) {
|
|
|
self.readState.nextSeq = self.index.startSeqNo(true);
|
|
|
}
|
|
|
|
|
|
+ // check watched segments
|
|
|
+ for (var seq in self.watch) {
|
|
|
+ if (!self.index.isValidSeqNo(seq)) {
|
|
|
+ var stream = self.watch[seq];
|
|
|
+ delete self.watch[seq];
|
|
|
+
|
|
|
+ setTimeout(function () {
|
|
|
+ debug('aborting discontinued segment download');
|
|
|
+ if (!stream.ended && stream.abort) stream.abort();
|
|
|
+ }, self.index.target_duration * 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
self.emit('index', self.index);
|
|
|
|
|
|
if (self.index.variant)
|