Skip to content

Commit

Permalink
feat: Add experimentalExactManifestTimings which forgoes TIME_FUDGE_F…
Browse files Browse the repository at this point in the history
…ACTOR during segment choice (#1165)
  • Loading branch information
brandonocasey authored Jul 27, 2021
1 parent a0c0359 commit 67a1201
Show file tree
Hide file tree
Showing 7 changed files with 568 additions and 542 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ <h3>Options</h3>
<input id=buffer-water type="checkbox">
[EXPERIMENTAL] Use Buffer Level for ABR (reloads player)
</label>
<label>
<input id=exact-manifest-timings type="checkbox">
[EXPERIMENTAL] Use exact manifest timings for segment choices (reloads player)
</label>
<label>
<input id=pixel-diff-selector type="checkbox">
[EXPERIMENTAL] Use the Pixel difference resolution selector (reloads player)
Expand Down
5 changes: 4 additions & 1 deletion scripts/index-demo-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
'type',
'keysystems',
'buffer-water',
'exact-manifest-timings',
'pixel-diff-selector',
'override-native',
'preload',
Expand Down Expand Up @@ -285,7 +286,8 @@
'buffer-water',
'override-native',
'liveui',
'pixel-diff-selector'
'pixel-diff-selector',
'exact-manifest-timings'
].forEach(function(name) {
stateEls[name].addEventListener('change', function(event) {
saveState();
Expand Down Expand Up @@ -350,6 +352,7 @@
overrideNative: getInputValue(stateEls['override-native']),
experimentalBufferBasedABR: getInputValue(stateEls['buffer-water']),
experimentalLLHLS: getInputValue(stateEls.llhls),
experimentalExactManifestTimings: getInputValue(stateEls['exact-manifest-timings']),
experimentalLeastPixelDiffSelector: getInputValue(stateEls['pixel-diff-selector'])
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ export class MasterPlaylistController extends videojs.EventTarget {
inbandTextTracks: this.inbandTextTracks_,
cacheEncryptionKeys,
sourceUpdater: this.sourceUpdater_,
timelineChangeController: this.timelineChangeController_
timelineChangeController: this.timelineChangeController_,
experimentalExactManifestTimings: options.experimentalExactManifestTimings
};

// The source type check not only determines whether a special DASH playlist loader
Expand Down
61 changes: 36 additions & 25 deletions src/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ export const getMediaInfoForTime = function({
currentTime,
startingSegmentIndex,
startingPartIndex,
startTime
startTime,
experimentalExactManifestTimings
}) {

let time = currentTime - startTime;
Expand Down Expand Up @@ -415,19 +416,23 @@ export const getMediaInfoForTime = function({

time += partAndSegment.duration;

// TODO: consider not using TIME_FUDGE_FACTOR at all here
if ((time + TIME_FUDGE_FACTOR) > 0) {
return {
partIndex: partAndSegment.partIndex,
segmentIndex: partAndSegment.segmentIndex,
startTime: startTime - sumDurations({
defaultDuration: playlist.targetDuration,
durationList: partsAndSegments,
startIndex,
endIndex: i
})
};
if (experimentalExactManifestTimings) {
if (time < 0) {
continue;
}
} else if ((time + TIME_FUDGE_FACTOR) <= 0) {
continue;
}
return {
partIndex: partAndSegment.partIndex,
segmentIndex: partAndSegment.segmentIndex,
startTime: startTime - sumDurations({
defaultDuration: playlist.targetDuration,
durationList: partsAndSegments,
startIndex,
endIndex: i
})
};
}
}

Expand All @@ -446,6 +451,7 @@ export const getMediaInfoForTime = function({
if (startIndex < 0) {
for (let i = startIndex; i < 0; i++) {
time -= playlist.targetDuration;

if (time < 0) {
return {
partIndex: partsAndSegments[0] && partsAndSegments[0].partIndex || null,
Expand All @@ -464,19 +470,24 @@ export const getMediaInfoForTime = function({

time -= partAndSegment.duration;

// TODO: consider not using TIME_FUDGE_FACTOR at all here
if ((time - TIME_FUDGE_FACTOR) < 0) {
return {
partIndex: partAndSegment.partIndex,
segmentIndex: partAndSegment.segmentIndex,
startTime: startTime + sumDurations({
defaultDuration: playlist.targetDuration,
durationList: partsAndSegments,
startIndex,
endIndex: i
})
};
if (experimentalExactManifestTimings) {
if (time > 0) {
continue;
}
} else if ((time - TIME_FUDGE_FACTOR) >= 0) {
continue;
}

return {
partIndex: partAndSegment.partIndex,
segmentIndex: partAndSegment.segmentIndex,
startTime: startTime + sumDurations({
defaultDuration: playlist.targetDuration,
durationList: partsAndSegments,
startIndex,
endIndex: i
})
};
}

// We are out of possible candidates so load the last one...
Expand Down
2 changes: 2 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ export default class SegmentLoader extends videojs.EventTarget {
this.timelineChangeController_ = settings.timelineChangeController;
this.shouldSaveSegmentTimingInfo_ = true;
this.parse708captions_ = settings.parse708captions;
this.experimentalExactManifestTimings = settings.experimentalExactManifestTimings;

// private instance variables
this.checkBufferTimeout_ = null;
Expand Down Expand Up @@ -1404,6 +1405,7 @@ export default class SegmentLoader extends videojs.EventTarget {
} else {
// Find the segment containing the end of the buffer or current time.
const {segmentIndex, startTime, partIndex} = Playlist.getMediaInfoForTime({
experimentalExactManifestTimings: this.experimentalExactManifestTimings,
playlist: this.playlist_,
currentTime: this.fetchAtBuffer_ ? bufferedEnd : this.currentTime_(),
startingPartIndex: this.syncPoint_.partIndex,
Expand Down
1 change: 1 addition & 0 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ class VhsHandler extends Component {
'experimentalBufferBasedABR',
'liveRangeSafeTimeDelta',
'experimentalLLHLS',
'experimentalExactManifestTimings',
'experimentalLeastPixelDiffSelector'
].forEach((option) => {
if (typeof this.source_[option] !== 'undefined') {
Expand Down
Loading

0 comments on commit 67a1201

Please sign in to comment.