Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Option for Bitrate Mapping Where Nearest Value is Always Matched #283

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -181,6 +182,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 @@ -220,6 +222,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 @@ -453,6 +459,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 @@ -1848,7 +1855,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