Skip to content

Commit

Permalink
Merge branch 'master' into feat-trim-start
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfrederiksen authored Aug 8, 2023
2 parents 9059663 + a735bbe commit 67f505f
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 1,129 deletions.
7 changes: 7 additions & 0 deletions engine/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface ChannelEngineOpts {
subtitleSliceEndpoint?: string;
useVTTSubtitles?: boolean;
alwaysNewSegments?: boolean;
alwaysMapBandwidthByNearest?: boolean;
diffCompensationRate?: number;
staticDirectory?: string;
averageSegmentDuration?: number;
Expand Down Expand Up @@ -182,6 +183,7 @@ export class ChannelEngine {
private subtitleSliceEndpoint: string;
private useVTTSubtitles: boolean;
private alwaysNewSegments: boolean;
private alwaysMapBandwidthByNearest: boolean;
private defaultSlateUri?: string;
private slateDuration?: number;
private assetMgr: IAssetManager;
Expand Down Expand Up @@ -221,6 +223,10 @@ export class ChannelEngine {
if (options && options.alwaysNewSegments) {
this.alwaysNewSegments = true;
}
this.alwaysMapBandwidthByNearest = false;
if (options && options.alwaysMapBandwidthByNearest) {
this.alwaysMapBandwidthByNearest = true;
}
if (options && options.defaultSlateUri) {
this.defaultSlateUri = options.defaultSlateUri;
this.slateRepetitions = options.slateRepetitions || 10;
Expand Down Expand Up @@ -454,6 +460,7 @@ export class ChannelEngine {
subtitleSliceEndpoint: this.subtitleSliceEndpoint,
useVTTSubtitles: this.useVTTSubtitles,
alwaysNewSegments: options.alwaysNewSegments,
alwaysMapBandwidthByNearest: options.alwaysMapBandwidthByNearest,
noSessionDataTags: options.noSessionDataTags,
playheadDiffThreshold: channel.options && channel.options.playheadDiffThreshold ? channel.options.playheadDiffThreshold : this.streamerOpts.defaultPlayheadDiffThreshold,
maxTickInterval: channel.options && channel.options.maxTickInterval ? channel.options.maxTickInterval : this.streamerOpts.defaultMaxTickInterval,
Expand Down
28 changes: 18 additions & 10 deletions engine/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ class Session {
}
this.isAllowedToClearVodCache = null;
this.alwaysNewSegments = null;
this.alwaysMapBandwidthByNearest = null;
if (config) {
if (config.alwaysNewSegments) {
this.alwaysNewSegments = config.alwaysNewSegments;
}

if (config.alwaysMapBandwidthByNearest) {
this.alwaysMapBandwidthByNearest = config.alwaysMapBandwidthByNearest;
}

if (config.sessionId) {
this._sessionId = config.sessionId;
}
Expand Down Expand Up @@ -828,7 +833,7 @@ class Session {
let positionV = 0;
let positionA = 0;
const position = (await this._getCurrentPlayheadPosition()) * 1000;
positionV = position / 1000;
positionV = position ? position / 1000 : 0;
let currentVod = await this._sessionState.getCurrentVod();
const sessionState = await this._sessionState.getValues(["vodMediaSeqAudio"]);
let posDiff;
Expand All @@ -840,11 +845,10 @@ class Session {
debug(`[${this._sessionId}]: About to determine audio increment`);
do {
const audioPosition = (await this._getAudioPlayheadPosition(sessionState.vodMediaSeqAudio + index)) * 1000;
positionA = audioPosition / 1000;
posDiff = (positionV-positionA).toFixed(3);
debug(`[${this._sessionId}]: positionV=${positionV};positionA=${positionA};posDiff=${posDiff};(posDiff <= 0.001)=${posDiff <= 0.001}`);
positionA = audioPosition ? audioPosition / 1000 : 0;
posDiff = (positionV - positionA).toFixed(3);
debug(`[${this._sessionId}]: positionV=${positionV};positionA=${positionA};posDiff=${posDiff}`);
if (posDiff <= maxAcceptableDiff) {
debug(`[${this._sessionId}]: posDiff value (${posDiff}) is acceptable`);
break;
}
if (posDiff > thresh) {
Expand All @@ -858,7 +862,7 @@ class Session {
if (sessionState.vodMediaSeqAudio + index > audioSeqLastIdx) {
break;
}
} while (!(-thresh < posDiff && posDiff < thresh));
} while (!(-thresh < posDiff && posDiff < thresh) && !isNaN(posDiff));
audioIncrement = index;
debug(`[${this._sessionId}]: Current VOD Playhead Positions are to be: [${positionV.toFixed(3)}][${positionA.toFixed(3)}] (${posDiff})`);
}
Expand Down Expand Up @@ -1326,7 +1330,8 @@ class Session {
dummySubtitleEndpoint: this.dummySubtitleEndpoint,
subtitleSliceEndpoint: this.subtitleSliceEndpoint,
shouldContainSubtitles: this.use_vtt_subtitles,
expectedSubtitleTracks: this._subtitleTracks
expectedSubtitleTracks: this._subtitleTracks,
alwaysMapBandwidthByNearest: this.alwaysMapBandwidthByNearest
};
newVod = new HLSVod(vodResponse.uri, [], vodResponse.unixTs, vodResponse.offset * 1000, m3u8Header(this._instanceId), hlsOpts);
if (vodResponse.timedMetadata) {
Expand Down Expand Up @@ -1502,7 +1507,8 @@ class Session {
dummySubtitleEndpoint: this.dummySubtitleEndpoint,
subtitleSliceEndpoint: this.subtitleSliceEndpoint,
shouldContainSubtitles: this.use_vtt_subtitles,
expectedSubtitleTracks: this._subtitleTracks
expectedSubtitleTracks: this._subtitleTracks,
alwaysMapBandwidthByNearest: this.alwaysMapBandwidthByNearest
};
newVod = new HLSVod(vodResponse.uri, null, vodResponse.unixTs, vodResponse.offset * 1000, m3u8Header(this._instanceId), hlsOpts);
if (vodResponse.timedMetadata) {
Expand Down Expand Up @@ -1749,7 +1755,8 @@ class Session {
dummySubtitleEndpoint: this.dummySubtitleEndpoint,
subtitleSliceEndpoint: this.subtitleSliceEndpoint,
shouldContainSubtitles: this.use_vtt_subtitles,
expectedSubtitleTracks: this._subtitleTracks
expectedSubtitleTracks: this._subtitleTracks,
alwaysMapBandwidthByNearest: this.alwaysMapBandwidthByNearest
};
const timestamp = Date.now();
hlsVod = new HLSVod(this.slateUri, null, timestamp, null, m3u8Header(this._instanceId), hlsOpts);
Expand Down Expand Up @@ -1852,7 +1859,8 @@ class Session {
dummySubtitleEndpoint: this.dummySubtitleEndpoint,
subtitleSliceEndpoint: this.subtitleSliceEndpoint,
shouldContainSubtitles: this.use_vtt_subtitles,
expectedSubtitleTracks: this._subtitleTracks
expectedSubtitleTracks: this._subtitleTracks,
alwaysMapBandwidthByNearest: this.alwaysMapBandwidthByNearest
};
const timestamp = Date.now();
hlsVod = new HLSVod(nexVodUri, null, timestamp, null, m3u8Header(this._instanceId), hlsOpts);
Expand Down
Loading

0 comments on commit 67f505f

Please sign in to comment.