Skip to content

Commit

Permalink
fix: livemix segment duplication detection (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfrederiksen authored Oct 21, 2024
1 parent 12c4b85 commit 1a298bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions engine/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Readable = require('stream').Readable;
const { SessionState } = require('./session_state.js');
const { PlayheadState } = require('./playhead_state.js');

const { applyFilter, cloudWatchLog, m3u8Header, logerror, codecsFromString } = require('./util.js');
const { applyFilter, cloudWatchLog, m3u8Header, logerror, codecsFromString, roundToTwoDecimals } = require('./util.js');
const ChaosMonkey = require('./chaos_monkey.js');

const EVENT_LIST_LIMIT = 100;
Expand Down Expand Up @@ -243,9 +243,9 @@ class Session {
{ event: 'applyTimePositionOffset', channel: this._sessionId, offsetMs: this.timePositionOffset });
}
const diff = position - timePosition;
debug(`[${this._sessionId}]: ${timePosition}:${position}:${diff > 0 ? '+' : ''}${diff}ms`);
debug(`[${this._sessionId}]: ${timePosition}:${roundToTwoDecimals(position) }:${diff > 0 ? '+' : ''}${roundToTwoDecimals(diff) }ms`);
cloudWatchLog(!this.cloudWatchLogging, 'engine-session',
{ event: 'playheadDiff', channel: this._sessionId, diffMs: diff });
{ event: 'playheadDiff', channel: this._sessionId, diffMs: roundToTwoDecimals(diff) });
if (this.alwaysNewSegments) {
// Apply Playhead diff compensation, only after external diff compensation has concluded.
if (this.diffCompensation <= 0) {
Expand Down
12 changes: 6 additions & 6 deletions engine/session_live.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ class SessionLive {
this.liveSegQueue[liveBw] = [];
}
// Do not push duplicates
const liveSegURIs = this.liveSegQueue[liveBw].filter((seg) => seg.uri).map((seg) => seg.uri);
const liveSegURIs = this.liveSegQueue[liveBw].filter((seg) => seg.uri).map((seg) => seg.uri).slice(-2);

if (liveSegFromLeader.uri && liveSegURIs.includes(liveSegFromLeader.uri)) {
debug(`[${this.sessionId}]: FOLLOWER: Found duplicate live segment. Skip push! (${liveBw})`);
Expand Down Expand Up @@ -853,9 +853,9 @@ class SessionLive {
this.liveSegQueueAudio[fat] = [];
}
// Do not push duplicates
const liveSegURIs = this.liveSegQueueAudio[fat].filter((seg) => seg.uri).map((seg) => seg.uri);
const liveSegURIs = this.liveSegQueueAudio[fat].filter((seg) => seg.uri).map((seg) => seg.uri).slice(-2);;
if (liveSegFromLeader.uri && liveSegURIs.includes(liveSegFromLeader.uri)) {
debug(`[${this.sessionId}]: FOLLOWER: Found duplicate live segment. Skip push! (${liveGroupId})`);
debug(`[${this.sessionId}]: FOLLOWER: Found duplicate live segment. Skip push! (${followerAudiotracks[0]})`);
} else {
this.liveSegQueueAudio[fat].push(liveSegFromLeader);
debug(
Expand Down Expand Up @@ -1591,14 +1591,14 @@ class SessionLive {
for (let i = 0; i < variantKeys.length; i++) {
let seg = _segments[variantKeys[i]].shift();
if (i === 0) {
debug(`[${this.sessionId}]: ${_name}: (${variantKeys[i]}) Ejected from playlist->: ${JSON.stringify(seg, null, 2)}`);
debug(`[${this.sessionId}]: ${_name}: (${variantKeys[i]}) Ejected from playlist->: ${JSON.stringify(seg)}`);
}
if (seg && seg.discontinuity) {
incrementDiscSeqCount = true;
if (_segments[variantKeys[i]].length > 0) {
seg = _segments[variantKeys[i]].shift();
if (i === 0) {
debug(`[${this.sessionId}]: ${_name}: (${variantKeys[i]}) Ejected from playlist->: ${JSON.stringify(seg, null, 2)}`);
debug(`[${this.sessionId}]: ${_name}: (${variantKeys[i]}) Ejected from playlist->: ${JSON.stringify(seg)}`);
}
}
}
Expand Down Expand Up @@ -1686,7 +1686,7 @@ class SessionLive {
}

if (this.discSeqCountVideo !== this.prevDiscSeqCountVideo) {
debug(`[${this.sessionId}]: ${instanceName}: Incrementing Dseq Count from V{${this.prevDiscSeqCountVideo}} -> {${this.discSeqCount}}`);
debug(`[${this.sessionId}]: ${instanceName}: Incrementing Dseq Count from V{${this.prevDiscSeqCountVideo}} -> {${this.discSeqCountVideo}}`);
}
debug(`[${this.sessionId}]: ${instanceName}: Incrementing Mseq Count from V[${this.prevMediaSeqCountVideo}] -> V[${this.mediaSeqCountVideo}]`);
debug(`[${this.sessionId}]: ${instanceName}: Finished updating all V-Counts and Segment Queues!`);
Expand Down
6 changes: 6 additions & 0 deletions engine/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ const timeLeft = (endTimestamp, currentTimestamp) => {
return msg;
};

const roundToTwoDecimals = (number) => {
const r = Math.round(number * 100) / 100;
return r
}

module.exports = {
filterQueryParser,
applyFilter,
Expand All @@ -266,4 +271,5 @@ module.exports = {
codecsFromString,
timeLeft,
findAudioGroupOrLang,
roundToTwoDecimals
};

0 comments on commit 1a298bd

Please sign in to comment.