From 60d9590b094464f7a12665dd78fc89be4c43353d Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Thu, 26 Sep 2024 14:33:23 +0100 Subject: [PATCH] fix: clear pieces with fixed duration --- packages/job-worker/src/playout/adlibUtils.ts | 107 ++++++++++-------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/packages/job-worker/src/playout/adlibUtils.ts b/packages/job-worker/src/playout/adlibUtils.ts index 1aea41cc523..b39e0a353ed 100644 --- a/packages/job-worker/src/playout/adlibUtils.ts +++ b/packages/job-worker/src/playout/adlibUtils.ts @@ -274,61 +274,68 @@ export function innerStopPieces( for (const resolvedPieceInstance of resolvedPieces) { const pieceInstance = resolvedPieceInstance.instance - if ( - !pieceInstance.userDuration && - !pieceInstance.piece.virtual && - filter(pieceInstance) && - resolvedPieceInstance.resolvedStart !== undefined && - resolvedPieceInstance.resolvedStart <= relativeStopAt && - !pieceInstance.plannedStoppedPlayback - ) { - switch (pieceInstance.piece.lifespan) { - case PieceLifespan.WithinPart: - case PieceLifespan.OutOnSegmentChange: - case PieceLifespan.OutOnRundownChange: { - logger.info(`Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt}`) - - const pieceInstanceModel = playoutModel.findPieceInstance(pieceInstance._id) - if (pieceInstanceModel) { - const newDuration: Required['userDuration'] = playoutModel.isMultiGatewayMode - ? { - endRelativeToNow: offsetRelativeToNow, - } - : { - endRelativeToPart: relativeStopAt, - } - - pieceInstanceModel.pieceInstance.setDuration(newDuration) - - stoppedInstances.push(pieceInstance._id) - } else { - logger.warn( - `Blueprint action: Failed to crop PieceInstance "${pieceInstance._id}", it was not found` - ) - } - - break - } - case PieceLifespan.OutOnSegmentEnd: - case PieceLifespan.OutOnRundownEnd: - case PieceLifespan.OutOnShowStyleEnd: { - logger.info( - `Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt} with a virtual` - ) - currentPartInstance.insertVirtualPiece( - relativeStopAt, - pieceInstance.piece.lifespan, - pieceInstance.piece.sourceLayerId, - pieceInstance.piece.outputLayerId - ) + // Virtual pieces aren't allowed a timed end + if (pieceInstance.piece.virtual) continue + + // Check if piece has already had an end defined + if (pieceInstance.userDuration) continue + + // Caller can filter out pieces + if (!filter(pieceInstance)) continue + + // Check if piece has started yet + if (!resolvedPieceInstance.resolvedStart || resolvedPieceInstance.resolvedStart > relativeStopAt) continue + + // If there end time of the piece is already known, make sure it is in the future + if (pieceInstance.plannedStoppedPlayback && pieceInstance.plannedStoppedPlayback <= stopAt) continue + + switch (pieceInstance.piece.lifespan) { + case PieceLifespan.WithinPart: + case PieceLifespan.OutOnSegmentChange: + case PieceLifespan.OutOnRundownChange: { + logger.info(`Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt}`) + + const pieceInstanceModel = playoutModel.findPieceInstance(pieceInstance._id) + if (pieceInstanceModel) { + const newDuration: Required['userDuration'] = playoutModel.isMultiGatewayMode + ? { + endRelativeToNow: offsetRelativeToNow, + } + : { + endRelativeToPart: relativeStopAt, + } + + pieceInstanceModel.pieceInstance.setDuration(newDuration) stoppedInstances.push(pieceInstance._id) - break + } else { + logger.warn( + `Blueprint action: Failed to crop PieceInstance "${pieceInstance._id}", it was not found` + ) } - default: - assertNever(pieceInstance.piece.lifespan) + + break + } + case PieceLifespan.OutOnSegmentEnd: + case PieceLifespan.OutOnRundownEnd: + case PieceLifespan.OutOnShowStyleEnd: { + logger.info( + `Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt} with a virtual` + ) + + currentPartInstance.insertVirtualPiece( + relativeStopAt, + pieceInstance.piece.lifespan, + pieceInstance.piece.sourceLayerId, + pieceInstance.piece.outputLayerId + ) + + stoppedInstances.push(pieceInstance._id) + break } + default: + assertNever(pieceInstance.piece.lifespan) } }