Skip to content

Commit

Permalink
Reload live stream using last segment length when distance to playlis…
Browse files Browse the repository at this point in the history
…t end is less than or equal to four target durations

(Reload is scheduled on update. With a default live sync of 3 target durations, without interruption, a distance of 3x-4x is most likely.)
  • Loading branch information
robwalch committed Oct 24, 2022
1 parent 496e51d commit e2f2f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/controller/level-helper.ts
Expand Up @@ -7,7 +7,6 @@ import { logger } from '../utils/logger';
import { Fragment, Part } from '../loader/fragment';
import { LevelDetails } from '../loader/level-details';
import type { Level } from '../types/level';
import type { LoaderStats } from '../types/loader';
import type { MediaPlaylist } from '../types/media-playlist';
import { DateRange } from '../loader/date-range';

Expand Down Expand Up @@ -441,7 +440,11 @@ export function computeReloadInterval(
if (newDetails.updated) {
// Use last segment duration when shorter than target duration and near live edge
const fragments = newDetails.fragments;
if (fragments.length && reloadInterval * 3 > distanceToLiveEdgeMs) {
const liveEdgeMaxTargetDurations = 4;
if (
fragments.length &&
reloadInterval * liveEdgeMaxTargetDurations > distanceToLiveEdgeMs
) {
const lastSegmentDuration =
fragments[fragments.length - 1].duration * 1000;
if (lastSegmentDuration < reloadInterval) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/controller/level-helper.ts
Expand Up @@ -307,11 +307,11 @@ expect: ${JSON.stringify(merged.fragments[i])}`
expect(actual).to.equal(2500);
});

it('returns the last fragment duration when distance to live edge is less than three target durations', function () {
it('returns the last fragment duration when distance to live edge is less than or equal to four target durations', function () {
const newPlaylist = generatePlaylist([3, 4], 0, 2);
newPlaylist.targetduration = 5;
newPlaylist.updated = true;
const actual = computeReloadInterval(newPlaylist, 15000);
const actual = computeReloadInterval(newPlaylist, 20000);
expect(actual).to.equal(5000);
const actualLow = computeReloadInterval(newPlaylist, 14000);
expect(actualLow).to.equal(2000);
Expand Down

0 comments on commit e2f2f24

Please sign in to comment.