Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/llhls-2
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Apr 5, 2021
2 parents d7c30d2 + 1e94680 commit 01a6763
Show file tree
Hide file tree
Showing 3 changed files with 1,110 additions and 1,356 deletions.
66 changes: 11 additions & 55 deletions src/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ export const liveEdgeDelay = (master, media) => {
} else if (media.serverControl && media.serverControl.holdBack) {
return media.serverControl.holdBack;
} else if (media.targetDuration) {
// TODO: this should probably be targetDuration * 3
// but we use this for backwards compatability.
const lastPartDuration = lastSegment && lastSegment.duration || media.targetDuration;

return lastPartDuration + media.targetDuration * 2;
return media.targetDuration * 3;
}

return 0;
Expand Down Expand Up @@ -273,51 +269,6 @@ export const sumDurations = function(playlist, startIndex, endIndex) {
return durations;
};

/**
* Determines the media index of the segment corresponding to the safe edge of the live
* window which is the duration of the last segment plus 2 target durations from the end
* of the playlist.
*
* A liveEdgePadding can be provided which will be used instead of calculating the safe live edge.
* This corresponds to suggestedPresentationDelay in DASH manifests.
*
* @param {Object} playlist
* a media playlist object
* @param {number} [liveEdgePadding]
* A number in seconds indicating how far from the end we want to be.
* If provided, this value is used instead of calculating the safe live index from the target durations.
* Corresponds to suggestedPresentationDelay in DASH manifests.
* @return {number}
* The media index of the segment at the safe live point. 0 if there is no "safe"
* point.
* @function safeLiveIndex
*/
export const safeLiveIndex = function(playlist, liveEdgePadding) {
const partsAndSegments = getPartsAndSegments(playlist);

if (!partsAndSegments.length) {
return 0;
}

if (typeof liveEdgePadding !== 'number') {
liveEdgePadding = liveEdgeDelay(null, playlist);
}

let i = partsAndSegments.length;
let distanceFromEnd = 0;

while (i--) {
distanceFromEnd += partsAndSegments[i].duration;

if (distanceFromEnd >= liveEdgePadding) {
return partsAndSegments[i].segmentIndex;
}
}

// there is nowhere in the playlist that is a safe distance from live.
return 0;
};

/**
* Calculates the playlist end time
*
Expand Down Expand Up @@ -351,13 +302,19 @@ export const playlistEnd = function(playlist, expired, useSafeLiveEnd, liveEdgeP

expired = expired || 0;

const endSequence = useSafeLiveEnd ? safeLiveIndex(playlist, liveEdgePadding) : playlist.segments.length;

return intervalDuration(
let lastSegmentTime = intervalDuration(
playlist,
playlist.mediaSequence + endSequence,
playlist.mediaSequence + playlist.segments.length,
expired
);

if (useSafeLiveEnd) {
liveEdgePadding = typeof liveEdgePadding === 'number' ? liveEdgePadding : liveEdgeDelay(null, playlist);
lastSegmentTime -= liveEdgePadding;
}

// don't return a time less than zero
return Math.max(0, lastSegmentTime);
};

/**
Expand Down Expand Up @@ -611,7 +568,6 @@ export default {
liveEdgeDelay,
duration,
seekable,
safeLiveIndex,
getMediaInfoForTime,
isEnabled,
isDisabled,
Expand Down
16 changes: 12 additions & 4 deletions src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import {sumDurations} from './playlist';
import videojs from 'video.js';
import logger from './util/logger';

const getSegmentIndex = (i, playlist, currentTime = 0) => {
const segments = playlist.segments;

return (playlist.endList || currentTime === 0) ? i : segments.length - (i + 1);
};

export const syncPointStrategies = [
// Stategy "VOD": Handle the VOD-case where the sync-point is *always*
// the equivalence display-time 0 === segment-index 0
Expand Down Expand Up @@ -38,7 +44,8 @@ export const syncPointStrategies = [
currentTime = currentTime || 0;

for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
const segmentIndex = getSegmentIndex(i, playlist, currentTime);
const segment = segments[segmentIndex];
const datetimeMapping =
syncController.timelineToDatetimeMappings[segment.timeline];

Expand All @@ -60,7 +67,7 @@ export const syncPointStrategies = [
lastDistance = distance;
syncPoint = {
time: segmentStart,
segmentIndex: i
segmentIndex
};
}
}
Expand All @@ -79,7 +86,8 @@ export const syncPointStrategies = [
currentTime = currentTime || 0;

for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
const segmentIndex = getSegmentIndex(i, playlist, currentTime);
const segment = segments[segmentIndex];

if (segment.timeline === currentTimeline &&
typeof segment.start !== 'undefined') {
Expand All @@ -95,7 +103,7 @@ export const syncPointStrategies = [
lastDistance = distance;
syncPoint = {
time: segment.start,
segmentIndex: i
segmentIndex
};
}

Expand Down
Loading

0 comments on commit 01a6763

Please sign in to comment.