eyevinn-channel-engine 3.2.3 → 3.2.6

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 CHANGED
@@ -57,7 +57,7 @@ class Session {
57
57
  transitionSegments: null,
58
58
  reloadBehind: null,
59
59
  }
60
- this.alreadyClearedVodCache = null;
60
+ this.isAllowedToClearVodCache = null;
61
61
 
62
62
  if (config) {
63
63
  if (config.sessionId) {
@@ -341,7 +341,7 @@ class Session {
341
341
  }
342
342
  }
343
343
 
344
- async getCurrentMediaSequenceSegments() {
344
+ async getCurrentMediaSequenceSegments(opts) {
345
345
  if (!this._sessionState) {
346
346
  throw new Error('Session not ready');
347
347
  }
@@ -361,7 +361,10 @@ class Session {
361
361
  state = await this.getSessionState();
362
362
  }
363
363
 
364
- const playheadState = await this._playheadState.getValues(["mediaSeq", "vodMediaSeqVideo"]);
364
+ const playheadState = await this._playheadState.getValues(["vodMediaSeqVideo"]);
365
+ if (opts && opts.targetMseq) {
366
+ playheadState.vodMediaSeqVideo = opts.targetMseq;
367
+ }
365
368
 
366
369
  // NOTE: Assume that VOD cache was already cleared in 'getCurrentMediaAndDiscSequenceCount()'
367
370
  // and that we now have access to the correct vod cache
@@ -426,6 +429,7 @@ class Session {
426
429
  return {
427
430
  'mediaSeq': (playheadState.mediaSeq + playheadState.vodMediaSeqVideo),
428
431
  'discSeq': discSeqCount,
432
+ 'vodMediaSeqVideo': playheadState.vodMediaSeqVideo,
429
433
  };
430
434
  } catch (err) {
431
435
  logerror(this._sessionId, err);
@@ -472,14 +476,13 @@ class Session {
472
476
  if (playheadState.vodMediaSeqVideo < 2 || playheadState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
473
477
  debug(`[${this._sessionId}]: current[${playheadState.vodMediaSeqVideo}]_prev[${this.prevVodMediaSeq.video}]`);
474
478
  const isLeader = await this._sessionStateStore.isLeader(this._instanceId);
475
- if (!isLeader && !this.alreadyClearedVodCache) {
479
+ if (!isLeader && this.isAllowedToClearVodCache) {
476
480
  debug(`[${this._sessionId}]: Not a leader and first|second media sequence in a VOD is requested. Invalidate cache to ensure having the correct VOD.`);
477
481
  await this._sessionState.clearCurrentVodCache();
478
- this.alreadyClearedVodCache = true;
482
+ this.isAllowedToClearVodCache = false;
479
483
  }
480
484
  } else {
481
- // Reset the value
482
- this.alreadyClearedVodCache = false;
485
+ this.isAllowedToClearVodCache = true;
483
486
  }
484
487
 
485
488
  const currentVod = await this._sessionState.getCurrentVod();
@@ -593,14 +596,13 @@ class Session {
593
596
  if (playheadState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
594
597
  this.alreadyCleredVodCache = false;
595
598
  }
596
- if (!isLeader && !this.alreadyClearedVodCache) {
599
+ if (!isLeader && this.isAllowedToClearVodCache) {
597
600
  debug(`[${this._sessionId}]: Not a leader and have just set 'playheadState.vodMediaSeqVideo' to 0|1. Invalidate cache to ensure having the correct VOD.`);
598
601
  await this._sessionState.clearCurrentVodCache();
599
- this.alreadyClearedVodCache = true;
602
+ this.isAllowedToClearVodCache = false;
600
603
  }
601
604
  } else {
602
- // Reset the value
603
- this.alreadyClearedVodCache = false;
605
+ this.isAllowedToClearVodCache = true;
604
606
  }
605
607
  // Update Value for Previous Sequence
606
608
  this.prevVodMediaSeq.video = playheadState.vodMediaSeqVideo;
@@ -955,12 +957,19 @@ class Session {
955
957
  this.prevVodMediaSeq.video = sessionState.vodMediaSeqVideo;
956
958
  }
957
959
  // Clear Cache if prev count is HIGHER than current...
958
- if (sessionState.vodMediaSeqVideo < this.prevVodMediaSeq.video ) {
959
- debug(`[${this._sessionId}]: current[${sessionState.vodMediaSeqVideo}], prev[${this.prevVodMediaSeq.video}], total[${currentVod.getLiveMediaSequencesCount()}]`);
960
+ if (sessionState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
961
+ debug(`[${this._sessionId}]: state=VOD_PLAYING, current[${sessionState.vodMediaSeqVideo}], prev[${this.prevVodMediaSeq.video}], total[${currentVod.getLiveMediaSequencesCount()}]`);
960
962
  await this._sessionState.clearCurrentVodCache();
961
963
  currentVod = await this._sessionState.getCurrentVod();
962
964
  this.prevVodMediaSeq.video = sessionState.vodMediaSeqVideo;
963
965
  }
966
+ } else {
967
+ // Handle edge case where Leader loaded next vod but Follower remained in state=VOD_PLAYING
968
+ if (this.prevVodMediaSeq.video !== null & sessionState.vodMediaSeqVideo < this.prevVodMediaSeq.video) {
969
+ debug(`[${this._sessionId}]: state=VOD_PLAYING, current[${sessionState.vodMediaSeqVideo}], prev[${this.prevVodMediaSeq.video}], total[${currentVod.getLiveMediaSequencesCount()}]`);
970
+ // Allow Follower to clear VodCache...
971
+ this.isAllowedToClearVodCache = true;
972
+ }
964
973
  }
965
974
  debug(`[${this._sessionId}]: state=VOD_PLAYING (${sessionState.vodMediaSeqVideo}_${sessionState.vodMediaSeqAudio}, ${currentVod.getLiveMediaSequencesCount()})`);
966
975
  return;
@@ -969,7 +978,8 @@ class Session {
969
978
  if (!isLeader) {
970
979
  debug(`[${this._sessionId}]: not the leader so just waiting for the VOD to be initiated`);
971
980
  }
972
- this.alreadyClearedVodCache = false;
981
+ // Allow Leader|Follower to clear vodCache...
982
+ this.isAllowedToClearVodCache = true;
973
983
  return;
974
984
  case SessionState.VOD_NEXT_INIT:
975
985
  try {
@@ -1143,6 +1153,8 @@ class Session {
1143
1153
  }
1144
1154
  this.waitingForNextVod = true;
1145
1155
  }
1156
+ // Allow Leader|Follower to clear vodCache...
1157
+ this.isAllowedToClearVodCache = true;
1146
1158
  return;
1147
1159
  default:
1148
1160
  throw new Error("Invalid state: " + sessionState.state);
@@ -233,7 +233,7 @@ class StreamSwitcher {
233
233
  debug(`[${this.sessionId}]: [ INIT Switching from V2L->LIVE ]`);
234
234
  this.eventId = scheduleObj.eventId;
235
235
  currVodCounts = await session.getCurrentMediaAndDiscSequenceCount();
236
- currVodSegments = await session.getCurrentMediaSequenceSegments();
236
+ currVodSegments = await session.getCurrentMediaSequenceSegments({ targetMseq: currVodCounts.vodMediaSeqVideo });
237
237
 
238
238
  // Insert preroll if available for current channel
239
239
  if (this.prerollsCache[this.sessionId]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyevinn-channel-engine",
3
- "version": "3.2.3",
3
+ "version": "3.2.6",
4
4
  "description": "OTT TV Channel Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -324,6 +324,7 @@ describe("The initialize switching", () => {
324
324
  expect(currVodCounts).toEqual({
325
325
  mediaSeq: 2,
326
326
  discSeq: 0,
327
+ vodMediaSeqVideo: 2
327
328
  });
328
329
  expect(currVodSegments[1313000][0]).toEqual({
329
330
  duration: 7.5,
@@ -403,6 +404,7 @@ describe("The initialize switching", () => {
403
404
  const expectedCounts = {
404
405
  mediaSeq: 23,
405
406
  discSeq: 1,
407
+ vodMediaSeqVideo: 3
406
408
  };
407
409
 
408
410
  expect(expectedCounts).toEqual(sessionCounts);
@@ -448,6 +450,7 @@ describe("The initialize switching", () => {
448
450
  const expectedCounts = {
449
451
  mediaSeq: 8,
450
452
  discSeq: 0,
453
+ vodMediaSeqVideo: 2
451
454
  };
452
455
 
453
456
  expect(expectedCounts).toEqual(sessionCounts);