Skip to content

Commit c8f7c42

Browse files
authored
fix: compensate for piece preroll for adlibbed pieces SOFIE-3369 (#1236)
1 parent a444857 commit c8f7c42

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

packages/corelib/src/playout/processAndPrune.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ import { getPieceControlObjectId } from './ids'
1010
/**
1111
* Get the `enable: { start: ?? }` for the new piece in terms that can be used as an `end` for another object
1212
*/
13-
function getPieceStartTime(newPieceStart: number | 'now', newPiece: PieceInstance): number | string {
13+
function getPieceStartTimeAsReference(newPieceStart: number | 'now', newPiece: PieceInstance): number | string {
1414
return typeof newPieceStart === 'number' ? newPieceStart : `#${getPieceControlObjectId(newPiece)}.start`
1515
}
1616

17+
function getPieceStartTimeWithinPart(p: PieceInstance): 'now' | number {
18+
if (p.piece.enable.start === 'now' || !p.dynamicallyInserted) {
19+
return p.piece.enable.start
20+
} else {
21+
return p.piece.enable.start + (p.piece.prerollDuration ?? 0)
22+
}
23+
}
24+
1725
function isClear(piece?: PieceInstance): boolean {
1826
return !!piece?.piece.virtual
1927
}
@@ -85,7 +93,7 @@ export function processAndPrunePieceInstanceTimings(
8593
for (const pieces of groupedPieces.values()) {
8694
// Group and sort the pieces so that we can step through each point in time
8795
const piecesByStart: Array<[number | 'now', PieceInstance[]]> = _.sortBy(
88-
Array.from(groupByToMapFunc(pieces, (p) => p.piece.enable.start).entries()).map(([k, v]) =>
96+
Array.from(groupByToMapFunc(pieces, (p) => getPieceStartTimeWithinPart(p)).entries()).map(([k, v]) =>
8997
literal<[number | 'now', PieceInstance[]]>([k === 'now' ? 'now' : Number(k), v])
9098
),
9199
([k]) => (k === 'now' ? nowInPart : k)
@@ -120,7 +128,7 @@ function updateWithNewPieces(
120128
if (newPiece) {
121129
const activePiece = activePieces[key]
122130
if (activePiece) {
123-
activePiece.resolvedEndCap = getPieceStartTime(newPiecesStart, newPiece)
131+
activePiece.resolvedEndCap = getPieceStartTimeAsReference(newPiecesStart, newPiece)
124132
}
125133
// track the new piece
126134
activePieces[key] = newPiece
@@ -145,7 +153,7 @@ function updateWithNewPieces(
145153
(newPiecesStart !== 0 || isCandidateBetterToBeContinued(activePieces.other, newPiece))
146154
) {
147155
// These modes should stop the 'other' when they start if not hidden behind a higher priority onEnd
148-
activePieces.other.resolvedEndCap = getPieceStartTime(newPiecesStart, newPiece)
156+
activePieces.other.resolvedEndCap = getPieceStartTimeAsReference(newPiecesStart, newPiece)
149157
activePieces.other = undefined
150158
}
151159
}

packages/job-worker/src/playout/__tests__/timeline.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,14 +1439,16 @@ describe('Timeline', () => {
14391439
// Simulate the piece timing confirmation from playout-gateway
14401440
await doSimulatePiecePlaybackTimings(playlistId, pieceOffset, 1)
14411441

1442+
const pieceOffsetWithPreroll = pieceOffset + 340
1443+
14421444
// Now we have a concrete time
14431445
await checkTimings({
14441446
previousPart: null,
14451447
currentPieces: {
14461448
piece000: {
14471449
controlObj: {
14481450
start: 500, // This one gave the preroll
1449-
end: pieceOffset,
1451+
end: pieceOffsetWithPreroll,
14501452
},
14511453
childGroup: {
14521454
preroll: 500,
@@ -1465,7 +1467,7 @@ describe('Timeline', () => {
14651467
[adlibbedPieceId]: {
14661468
// Our adlibbed piece
14671469
controlObj: {
1468-
start: pieceOffset,
1470+
start: pieceOffsetWithPreroll,
14691471
},
14701472
childGroup: {
14711473
preroll: 340,

packages/job-worker/src/playout/timeline/piece.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ export function getPieceEnableInsidePart(
9393
partGroupId: string
9494
): TSR.Timeline.TimelineEnable {
9595
const pieceEnable: TSR.Timeline.TimelineEnable = { ...pieceInstance.piece.enable }
96-
if (typeof pieceEnable.start === 'number' && !pieceInstance.dynamicallyInserted) {
97-
// timed pieces should be offset based on the preroll of the part
98-
pieceEnable.start += partTimings.toPartDelay
96+
if (typeof pieceEnable.start === 'number') {
97+
if (pieceInstance.dynamicallyInserted) {
98+
// timed adlibbed pieces needs to factor in their preroll
99+
pieceEnable.start += pieceInstance.piece.prerollDuration || 0
100+
} else {
101+
// timed planned pieces should be offset based on the preroll of the part
102+
pieceEnable.start += partTimings.toPartDelay
103+
}
99104
}
105+
100106
if (partTimings.toPartPostroll) {
101107
if (!pieceEnable.duration) {
102108
// make sure that the control object is shortened correctly

0 commit comments

Comments
 (0)