Skip to content

Commit

Permalink
fix: clear pieces with fixed duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Sep 26, 2024
1 parent c4e1c88 commit 60d9590
Showing 1 changed file with 57 additions and 50 deletions.
107 changes: 57 additions & 50 deletions packages/job-worker/src/playout/adlibUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PieceInstance>['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<PieceInstance>['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)
}
}

Expand Down

0 comments on commit 60d9590

Please sign in to comment.