Skip to content

Commit

Permalink
avoid repeated request for init segment on live fmp4 playlist and fix…
Browse files Browse the repository at this point in the history
… regression introduced by FragmentTracker (video-dev#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 video-dev#1607
  • Loading branch information
mangui authored and johnBartos committed Mar 22, 2018
1 parent e099169 commit 2ce2381
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
37 changes: 21 additions & 16 deletions src/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/helper/level-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ce2381

Please sign in to comment.