From 2ce2381b2c98096c4abf6a2a09b8ed6f8df22c62 Mon Sep 17 00:00:00 2001 From: Guillaume du Pontavice Date: Thu, 22 Mar 2018 09:52:32 -0700 Subject: [PATCH] avoid repeated request for init segment on live fmp4 playlist and fix regression introduced by FragmentTracker (#1611) * level-helper: merge initSegment info to avoid requesting it again on each live playlist refresh * fragment-tracker: dont track initsegment; initsegment does not correspond to any buffered area related to #1607 --- src/helper/fragment-tracker.js | 37 +++++++++++++++++++--------------- src/helper/level-helper.js | 6 +++++- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/helper/fragment-tracker.js b/src/helper/fragment-tracker.js index 77ca97d1e72..5e9c4e3dade 100644 --- a/src/helper/fragment-tracker.js +++ b/src/helper/fragment-tracker.js @@ -99,16 +99,18 @@ export class FragmentTracker extends EventHandler { detectPartialFragments (fragment) { let fragKey = this.getFragmentKey(fragment); let fragmentEntity = this.fragments[fragKey]; - fragmentEntity.buffered = true; + if (fragmentEntity) { + fragmentEntity.buffered = true; - Object.keys(this.timeRanges).forEach(elementaryStream => { - if (fragment.hasElementaryStream(elementaryStream) === true) { - let timeRange = this.timeRanges[elementaryStream]; - // Check for malformed fragments - // Gaps need to be calculated for each elementaryStream - fragmentEntity.range[elementaryStream] = this.getBufferedTimes(fragment.startPTS, fragment.endPTS, timeRange); - } - }); + Object.keys(this.timeRanges).forEach(elementaryStream => { + if (fragment.hasElementaryStream(elementaryStream) === true) { + let timeRange = this.timeRanges[elementaryStream]; + // Check for malformed fragments + // Gaps need to be calculated for each elementaryStream + fragmentEntity.range[elementaryStream] = this.getBufferedTimes(fragment.startPTS, fragment.endPTS, timeRange); + } + }); + } } getBufferedTimes (startPTS, endPTS, timeRange) { @@ -226,13 +228,16 @@ export class FragmentTracker extends EventHandler { */ onFragLoaded (e) { let fragment = e.frag; - let fragKey = this.getFragmentKey(fragment); - let fragmentEntity = { - body: fragment, - range: Object.create(null), - buffered: false - }; - this.fragments[fragKey] = fragmentEntity; + // dont track initsegment (for which sn is not a number) + if (!isNaN(fragment.sn)) { + let fragKey = this.getFragmentKey(fragment); + let fragmentEntity = { + body: fragment, + range: Object.create(null), + buffered: false + }; + this.fragments[fragKey] = fragmentEntity; + } } /** diff --git a/src/helper/level-helper.js b/src/helper/level-helper.js index 7608f4da647..c5f800cb0c3 100644 --- a/src/helper/level-helper.js +++ b/src/helper/level-helper.js @@ -91,7 +91,11 @@ export function mergeDetails (oldDetails, newDetails) { ccOffset = 0, PTSFrag; - // check if old/new playlists have fragments in common + // potentially retrieve cached initsegment + if (newDetails.initSegment && oldDetails.initSegment) + newDetails.initSegment = oldDetails.initSegment; + + // check if old/new playlists have fragments in common if (end < start) { newDetails.PTSKnown = false; return;