Skip to content

Commit d51eb70

Browse files
authored
Merge pull request #1270 from bbc/fix/clear-source-layer-piece-with-duration
fix: clear pieces with fixed duration
2 parents 5bc0155 + ced0e11 commit d51eb70

File tree

1 file changed

+58
-50
lines changed

1 file changed

+58
-50
lines changed

packages/job-worker/src/playout/adlibUtils.ts

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -274,61 +274,69 @@ export function innerStopPieces(
274274

275275
for (const resolvedPieceInstance of resolvedPieces) {
276276
const pieceInstance = resolvedPieceInstance.instance
277-
if (
278-
!pieceInstance.userDuration &&
279-
!pieceInstance.piece.virtual &&
280-
filter(pieceInstance) &&
281-
resolvedPieceInstance.resolvedStart !== undefined &&
282-
resolvedPieceInstance.resolvedStart <= relativeStopAt &&
283-
!pieceInstance.plannedStoppedPlayback
284-
) {
285-
switch (pieceInstance.piece.lifespan) {
286-
case PieceLifespan.WithinPart:
287-
case PieceLifespan.OutOnSegmentChange:
288-
case PieceLifespan.OutOnRundownChange: {
289-
logger.info(`Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt}`)
290-
291-
const pieceInstanceModel = playoutModel.findPieceInstance(pieceInstance._id)
292-
if (pieceInstanceModel) {
293-
const newDuration: Required<PieceInstance>['userDuration'] = playoutModel.isMultiGatewayMode
294-
? {
295-
endRelativeToNow: offsetRelativeToNow,
296-
}
297-
: {
298-
endRelativeToPart: relativeStopAt,
299-
}
300-
301-
pieceInstanceModel.pieceInstance.setDuration(newDuration)
302-
303-
stoppedInstances.push(pieceInstance._id)
304-
} else {
305-
logger.warn(
306-
`Blueprint action: Failed to crop PieceInstance "${pieceInstance._id}", it was not found`
307-
)
308-
}
309-
310-
break
311-
}
312-
case PieceLifespan.OutOnSegmentEnd:
313-
case PieceLifespan.OutOnRundownEnd:
314-
case PieceLifespan.OutOnShowStyleEnd: {
315-
logger.info(
316-
`Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt} with a virtual`
317-
)
318277

319-
currentPartInstance.insertVirtualPiece(
320-
relativeStopAt,
321-
pieceInstance.piece.lifespan,
322-
pieceInstance.piece.sourceLayerId,
323-
pieceInstance.piece.outputLayerId
324-
)
278+
// Virtual pieces aren't allowed a timed end
279+
if (pieceInstance.piece.virtual) continue
280+
281+
// Check if piece has already had an end defined
282+
if (pieceInstance.userDuration) continue
283+
284+
// Caller can filter out pieces
285+
if (!filter(pieceInstance)) continue
286+
287+
// Check if piece has started yet
288+
if (resolvedPieceInstance.resolvedStart == undefined || resolvedPieceInstance.resolvedStart > relativeStopAt)
289+
continue
290+
291+
// If there end time of the piece is already known, make sure it is in the future
292+
if (pieceInstance.plannedStoppedPlayback && pieceInstance.plannedStoppedPlayback <= stopAt) continue
293+
294+
switch (pieceInstance.piece.lifespan) {
295+
case PieceLifespan.WithinPart:
296+
case PieceLifespan.OutOnSegmentChange:
297+
case PieceLifespan.OutOnRundownChange: {
298+
logger.info(`Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt}`)
299+
300+
const pieceInstanceModel = playoutModel.findPieceInstance(pieceInstance._id)
301+
if (pieceInstanceModel) {
302+
const newDuration: Required<PieceInstance>['userDuration'] = playoutModel.isMultiGatewayMode
303+
? {
304+
endRelativeToNow: offsetRelativeToNow,
305+
}
306+
: {
307+
endRelativeToPart: relativeStopAt,
308+
}
309+
310+
pieceInstanceModel.pieceInstance.setDuration(newDuration)
325311

326312
stoppedInstances.push(pieceInstance._id)
327-
break
313+
} else {
314+
logger.warn(
315+
`Blueprint action: Failed to crop PieceInstance "${pieceInstance._id}", it was not found`
316+
)
328317
}
329-
default:
330-
assertNever(pieceInstance.piece.lifespan)
318+
319+
break
320+
}
321+
case PieceLifespan.OutOnSegmentEnd:
322+
case PieceLifespan.OutOnRundownEnd:
323+
case PieceLifespan.OutOnShowStyleEnd: {
324+
logger.info(
325+
`Blueprint action: Cropping PieceInstance "${pieceInstance._id}" to ${stopAt} with a virtual`
326+
)
327+
328+
currentPartInstance.insertVirtualPiece(
329+
relativeStopAt,
330+
pieceInstance.piece.lifespan,
331+
pieceInstance.piece.sourceLayerId,
332+
pieceInstance.piece.outputLayerId
333+
)
334+
335+
stoppedInstances.push(pieceInstance._id)
336+
break
331337
}
338+
default:
339+
assertNever(pieceInstance.piece.lifespan)
332340
}
333341
}
334342

0 commit comments

Comments
 (0)