@@ -274,61 +274,69 @@ export function innerStopPieces(
274
274
275
275
for ( const resolvedPieceInstance of resolvedPieces ) {
276
276
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
- )
318
277
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 )
325
311
326
312
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
+ )
328
317
}
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
331
337
}
338
+ default :
339
+ assertNever ( pieceInstance . piece . lifespan )
332
340
}
333
341
}
334
342
0 commit comments