eyevinn-channel-engine 3.1.8 → 3.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/engine/session.js +2 -2
- package/engine/session_live.js +36 -11
- package/engine/stream_switcher.js +6 -0
- package/engine/util.js +3 -0
- package/package.json +1 -1
package/engine/session.js
CHANGED
|
@@ -446,7 +446,7 @@ class Session {
|
|
|
446
446
|
const sessionState = await this._sessionState.getValues(["vodMediaSeqVideo", "discSeq"]);
|
|
447
447
|
const playheadState = await this._playheadState.getValues(["mediaSeq", "vodMediaSeqVideo"]);
|
|
448
448
|
|
|
449
|
-
if (this.prevVodMediaSeq.video
|
|
449
|
+
if (this.prevVodMediaSeq.video === null) {
|
|
450
450
|
this.prevVodMediaSeq.video = playheadState.vodMediaSeqVideo;
|
|
451
451
|
}
|
|
452
452
|
|
|
@@ -940,7 +940,7 @@ class Session {
|
|
|
940
940
|
}
|
|
941
941
|
} else {
|
|
942
942
|
// Handle edge case where store has been reset, but leader has not cleared cache.
|
|
943
|
-
if (this.prevVodMediaSeq.video
|
|
943
|
+
if (this.prevVodMediaSeq.video === null) {
|
|
944
944
|
this.prevVodMediaSeq.video = sessionState.vodMediaSeqVideo;
|
|
945
945
|
}
|
|
946
946
|
if (this.prevVodMediaSeq.video < sessionState.vodMediaSeqVideo) {
|
package/engine/session_live.js
CHANGED
|
@@ -159,16 +159,16 @@ class SessionLive {
|
|
|
159
159
|
this.waitForPlayhead = false;
|
|
160
160
|
|
|
161
161
|
// Let the playhead move at an interval set according to live segment duration
|
|
162
|
-
|
|
163
|
-
let liveBws = Object.keys(this.liveSegQueue);
|
|
164
|
-
if (liveBws.length !== 0 && this.liveSegQueue[liveBws[0]].length !== 0 && this.liveSegQueue[liveBws[0]][0].duration) {
|
|
165
|
-
liveSegmentDurationMs = this.liveSegQueue[liveBws[0]][0].duration * 1000;
|
|
166
|
-
}
|
|
162
|
+
const liveSegmentDurationMs = this._getAnyFirstSegmentDurationMs() || DEFAULT_PLAYHEAD_INTERVAL_MS;
|
|
167
163
|
|
|
168
164
|
// Set the timer
|
|
169
165
|
let timerValueMs = 0;
|
|
170
166
|
if (this.timerCompensation) {
|
|
171
|
-
|
|
167
|
+
const isLeader = await this.sessionLiveStateStore.isLeader(this.instanceId);
|
|
168
|
+
const incrementDuration = tsIncrementEnd - tsIncrementBegin;
|
|
169
|
+
if (incrementDuration >= liveSegmentDurationMs * 0.5 && isLeader) {
|
|
170
|
+
timerValueMs = liveSegmentDurationMs;
|
|
171
|
+
} else {
|
|
172
172
|
timerValueMs = liveSegmentDurationMs - (tsIncrementEnd - tsIncrementBegin);
|
|
173
173
|
}
|
|
174
174
|
} else {
|
|
@@ -541,12 +541,14 @@ class SessionLive {
|
|
|
541
541
|
if (!leadersMediaSeqRaw < this.lastRequestedMediaSeqRaw && this.blockGenerateManifest) {
|
|
542
542
|
this.blockGenerateManifest = false;
|
|
543
543
|
}
|
|
544
|
-
let attempts = 5;
|
|
545
544
|
|
|
545
|
+
let attempts = 5;
|
|
546
546
|
// CHECK AGAIN CASE 1: Store Empty
|
|
547
547
|
while (!leadersMediaSeqRaw && attempts > 0) {
|
|
548
|
-
|
|
549
|
-
|
|
548
|
+
const segDur = this._getAnyFirstSegmentDurationMs() || DEFAULT_PLAYHEAD_INTERVAL_MS;
|
|
549
|
+
const waitTimeMs = parseInt(segDur / 3, 10);
|
|
550
|
+
debug(`[${this.sessionId}]: FOLLOWER: Leader has not put anything in store... Will check again in ${waitTimeMs}ms (Tries left=[${attempts}])`);
|
|
551
|
+
await timer(waitTimeMs);
|
|
550
552
|
this.timerCompensation = false;
|
|
551
553
|
leadersMediaSeqRaw = await this.sessionLiveState.get("lastRequestedMediaSeqRaw");
|
|
552
554
|
attempts--;
|
|
@@ -566,8 +568,10 @@ class SessionLive {
|
|
|
566
568
|
attempts = 5;
|
|
567
569
|
// CHECK AGAIN CASE 2: Store Old
|
|
568
570
|
while (leadersMediaSeqRaw <= this.lastRequestedMediaSeqRaw && attempts > 0) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
+
const segDur = this._getAnyFirstSegmentDurationMs() || DEFAULT_PLAYHEAD_INTERVAL_MS;
|
|
572
|
+
const waitTimeMs = parseInt(segDur / 3, 10);
|
|
573
|
+
debug(`[${this.sessionId}]: FOLLOWER: Cannot find anything NEW in store... Will check again in ${waitTimeMs}ms (Tries left=[${attempts}])`);
|
|
574
|
+
await timer(waitTimeMs);
|
|
571
575
|
this.timerCompensation = false;
|
|
572
576
|
leadersMediaSeqRaw = await this.sessionLiveState.get("lastRequestedMediaSeqRaw");
|
|
573
577
|
attempts--;
|
|
@@ -1362,6 +1366,27 @@ class SessionLive {
|
|
|
1362
1366
|
this.mediaManifestURIs = newItem;
|
|
1363
1367
|
}
|
|
1364
1368
|
|
|
1369
|
+
_getAnyFirstSegmentDurationMs() {
|
|
1370
|
+
if (this._isEmpty(this.liveSegQueue)) {
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
const bw0 = Object.keys(this.liveSegQueue)[0];
|
|
1375
|
+
if (this.liveSegQueue[bw0].length === 0) {
|
|
1376
|
+
return null;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
for (let i = 0; i < this.liveSegQueue[bw0].length; i++) {
|
|
1380
|
+
const segment = this.liveSegQueue[bw0][i];
|
|
1381
|
+
if (!segment.duration) {
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
return segment.duration * 1000;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1365
1390
|
_isEmpty(obj) {
|
|
1366
1391
|
if (!obj) {
|
|
1367
1392
|
return true;
|
|
@@ -3,6 +3,7 @@ const crypto = require("crypto");
|
|
|
3
3
|
const fetch = require("node-fetch");
|
|
4
4
|
const { AbortController } = require("abort-controller");
|
|
5
5
|
const { SessionState } = require('./session_state');
|
|
6
|
+
const { timer } = require("./util")
|
|
6
7
|
|
|
7
8
|
const SwitcherState = Object.freeze({
|
|
8
9
|
V2L_TO_LIVE: 1,
|
|
@@ -151,6 +152,11 @@ class StreamSwitcher {
|
|
|
151
152
|
);
|
|
152
153
|
validURI = await this._validURI(scheduleObj.uri);
|
|
153
154
|
tries++;
|
|
155
|
+
if (!validURI) {
|
|
156
|
+
const delayMs = tries * 500;
|
|
157
|
+
debug(`[${this.sessionId}]: Going to try validating Master URI again in ${delayMs}ms`);
|
|
158
|
+
await timer(delayMs);
|
|
159
|
+
}
|
|
154
160
|
}
|
|
155
161
|
if (!validURI) {
|
|
156
162
|
debug(`[${this.sessionId}]: Unreachable URI: [${scheduleObj.uri}]`);
|
package/engine/util.js
CHANGED
|
@@ -122,6 +122,8 @@ const logerror = (sessionId, err) => {
|
|
|
122
122
|
console.error(err);
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
const timer = ms => new Promise(res => setTimeout(res, ms));
|
|
126
|
+
|
|
125
127
|
module.exports = {
|
|
126
128
|
filterQueryParser,
|
|
127
129
|
applyFilter,
|
|
@@ -129,4 +131,5 @@ module.exports = {
|
|
|
129
131
|
m3u8Header,
|
|
130
132
|
toHHMMSS,
|
|
131
133
|
logerror,
|
|
134
|
+
timer
|
|
132
135
|
};
|