Skip to content

Commit

Permalink
fix: Infinite Pieces are not de-nowified
Browse files Browse the repository at this point in the history
Co-authored-by: Johan Nyman <[email protected]>
  • Loading branch information
jstarpl and nytamin committed Feb 5, 2025
1 parent 0032cea commit ebeb762
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions packages/job-worker/src/playout/timeline/multi-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TimelineObjRundown } from '@sofie-automation/corelib/dist/dataModel/Tim
import { normalizeArray } from '@sofie-automation/corelib/dist/lib'
import { PieceTimelineMetadata } from './pieceGroup'
import { StudioPlayoutModelBase } from '../../studio/model/StudioPlayoutModel'
import { logger } from '../../logging'
import { JobContext } from '../../jobs'
import { getCurrentTime } from '../../lib'
import { PlayoutModel } from '../model/PlayoutModel'
Expand Down Expand Up @@ -46,7 +47,7 @@ export function deNowifyMultiGatewayTimeline(
playoutModel.nextPartInstance
)

deNowifyCurrentPieces(
const { objectsNotDeNowified } = deNowifyCurrentPieces(
targetNowTime,
timingContext,
currentPartInstance,
Expand All @@ -55,6 +56,9 @@ export function deNowifyMultiGatewayTimeline(
)

updatePlannedTimingsForPieceInstances(playoutModel, currentPartInstance, partGroupTimings, timelineObjsMap)

// Because updatePlannedTimingsForPieceInstances changes start times of infinites, we can now run deNowifyInfinites()
deNowifyInfinites(targetNowTime, objectsNotDeNowified, timelineObjsMap)
}

/**
Expand Down Expand Up @@ -142,16 +146,75 @@ function updatePartInstancePlannedTimes(
}
}

/**
* Replace the `now` time in any timeline objects in infinites
*/
function deNowifyInfinites(
targetNowTime: number,
/** A list of objects that need to be updated */
infiniteObjs: TimelineObjRundown[],
timelineObjsMap: Record<string, TimelineObjRundown>
) {
/**
* Recursively look up the absolute starttime of a timeline object
* taking into account its parent's times.
* Note: This only supports timeline objects that have absolute enable.start times.
*/
const getStartTime = (obj: TimelineObjRundown): number | undefined => {
if (Array.isArray(obj.enable)) return undefined

const myStartTime = typeof obj.enable.start === 'number' ? obj.enable.start : undefined

if (!obj.inGroup) return myStartTime

if (myStartTime === undefined) return undefined

const parentObject = timelineObjsMap[obj.inGroup]
if (!parentObject) return undefined

const parentStartTime = getStartTime(parentObject)
if (parentStartTime === undefined) return undefined

return parentStartTime + myStartTime
}

for (const obj of infiniteObjs) {
if (!Array.isArray(obj.enable) && obj.enable.start === 'now') {
if (obj.inGroup) {
const parentObject = timelineObjsMap[obj.inGroup]
if (parentObject) {
const parentStartTime = getStartTime(parentObject)
if (parentStartTime !== undefined) {
obj.enable = { start: targetNowTime - parentStartTime }
} else {
logger.error(
`Unable to derive an absolute start time of parent "${obj.inGroup}" for object "${obj.id}" during deNowifyInfinites`
)
}
} else {
logger.error(`Parent obj "${obj.inGroup}" not found of object "${obj.id}" during deNowifyInfinites`)
}
} else {
logger.error(
`Unexpected "now" time during deNowifyInfinites, setting to absolute time for a timelineObject not inGroup: "${obj.id}"`
)
obj.enable = { start: targetNowTime }
}
}
}
}
/**
* Replace the `now` time in any Pieces on the timeline from the current Part with concrete start times
* @returns a list of object that couldn't be updated at this time.
*/
function deNowifyCurrentPieces(
targetNowTime: number,
timingContext: RundownTimelineTimingContext,
currentPartInstance: PlayoutPartInstanceModel,
currentPartGroupStartTime: number,
timelineObjsMap: Record<string, TimelineObjRundown>
) {
): { objectsNotDeNowified: TimelineObjRundown[] } {
const objectsNotDeNowified: TimelineObjRundown[] = []
// The relative time for 'now' to be resolved to, inside of the part group
const nowInPart = targetNowTime - currentPartGroupStartTime

Expand All @@ -176,6 +239,8 @@ function deNowifyCurrentPieces(
obj.enable = { start: nowInPart }
} else if (!obj.inGroup) {
obj.enable = { start: targetNowTime }
} else {
objectsNotDeNowified.push(obj)
}
}
}
Expand Down Expand Up @@ -203,6 +268,7 @@ function deNowifyCurrentPieces(
}
}
}
return { objectsNotDeNowified }
}

function updatePlannedTimingsForPieceInstances(
Expand Down

0 comments on commit ebeb762

Please sign in to comment.