Skip to content

Commit e330668

Browse files
committed
wip: rework
1 parent c336948 commit e330668

File tree

3 files changed

+67
-39
lines changed

3 files changed

+67
-39
lines changed

packages/job-worker/src/playout/abPlayback/abSessionHelper.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,10 @@ export class AbSessionHelper {
195195

196196
// Find an normal partInstance
197197
const partInstanceId = tlObj.partInstanceId
198-
if (partInstanceId) {
199-
const partInstanceSession = sessionsToConsider.find((s) => s.partInstanceIds?.includes(partInstanceId))
200-
if (partInstanceSession) {
201-
partInstanceSession.keep = true
202-
return partInstanceSession.id
203-
}
198+
const partInstanceSession = sessionsToConsider.find((s) => s.partInstanceIds?.includes(partInstanceId))
199+
if (partInstanceSession) {
200+
partInstanceSession.keep = true
201+
return partInstanceSession.id
204202
}
205203

206204
// If it is lookahead, then we run differently

packages/job-worker/src/playout/timeline/generate.ts

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ import { applyAbPlaybackForTimeline } from '../abPlayback'
5050
import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
5151
import { PlayoutPartInstanceModel } from '../model/PlayoutPartInstanceModel'
5252
import { PlayoutChangedType } from '@sofie-automation/shared-lib/dist/peripheralDevice/peripheralDeviceAPI'
53+
import { PieceInstance } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
54+
55+
const DEFAULT_ABSOLUTE_PIECE_PREPARE_TIME = 30000
5356

5457
function isModelForStudio(model: StudioPlayoutModelBase): model is StudioPlayoutModel {
5558
const tmp = model as StudioPlayoutModel
@@ -257,29 +260,48 @@ export interface SelectedPartInstanceTimelineInfo {
257260
partInstance: ReadonlyDeep<DBPartInstance>
258261
pieceInstances: PieceInstanceWithTimings[]
259262
calculatedTimings: PartCalculatedTimings
263+
regenerateTimelineAt: number | undefined
260264
}
261265

262266
function getPartInstanceTimelineInfo(
267+
absolutePiecePrepareTime: number,
263268
currentTime: Time,
264269
sourceLayers: SourceLayers,
265270
partInstance: PlayoutPartInstanceModel | null
266271
): SelectedPartInstanceTimelineInfo | undefined {
267272
if (!partInstance) return undefined
268273

269274
const partTimes = createPartCurrentTimes(currentTime, partInstance.partInstance.timings?.plannedStartedPlayback)
270-
const pieceInstances = processAndPrunePieceInstanceTimings(
271-
sourceLayers,
272-
partInstance.pieceInstances.map((p) => p.pieceInstance),
273-
partTimes
274-
)
275+
276+
let regenerateTimelineAt: Time | undefined = undefined
277+
278+
const rawPieceInstances: ReadonlyDeep<PieceInstance>[] = []
279+
for (const { pieceInstance } of partInstance.pieceInstances) {
280+
if (
281+
pieceInstance.piece.enable.isAbsolute &&
282+
typeof pieceInstance.piece.enable.start === 'number' &&
283+
pieceInstance.piece.enable.start > currentTime + absolutePiecePrepareTime
284+
) {
285+
// This absolute timed piece is starting too far in the future, ignore it
286+
regenerateTimelineAt = Math.min(
287+
regenerateTimelineAt ?? Number.POSITIVE_INFINITY,
288+
pieceInstance.piece.enable.start - absolutePiecePrepareTime
289+
)
290+
291+
continue
292+
}
293+
294+
rawPieceInstances.push(pieceInstance)
295+
}
275296

276297
const partInstanceWithOverrides = partInstance.getPartInstanceWithQuickLoopOverrides()
277298
return {
278299
partInstance: partInstanceWithOverrides,
279-
pieceInstances,
300+
pieceInstances: processAndPrunePieceInstanceTimings(sourceLayers, rawPieceInstances, partTimes),
280301
partTimes,
281302
// Approximate `calculatedTimings`, for the partInstances which already have it cached
282-
calculatedTimings: getPartTimingsOrDefaults(partInstanceWithOverrides, pieceInstances),
303+
calculatedTimings: getPartTimingsOrDefaults(partInstanceWithOverrides, rawPieceInstances),
304+
regenerateTimelineAt,
283305
}
284306
}
285307

@@ -320,10 +342,27 @@ async function getTimelineRundown(
320342
}
321343

322344
const currentTime = getCurrentTime()
345+
const absolutePiecePrepareTime =
346+
context.studio.settings.rundownGlobalPiecesPrepareTime || DEFAULT_ABSOLUTE_PIECE_PREPARE_TIME
323347
const partInstancesInfo: SelectedPartInstancesTimelineInfo = {
324-
current: getPartInstanceTimelineInfo(currentTime, showStyle.sourceLayers, currentPartInstance),
325-
next: getPartInstanceTimelineInfo(currentTime, showStyle.sourceLayers, nextPartInstance),
326-
previous: getPartInstanceTimelineInfo(currentTime, showStyle.sourceLayers, previousPartInstance),
348+
current: getPartInstanceTimelineInfo(
349+
absolutePiecePrepareTime,
350+
currentTime,
351+
showStyle.sourceLayers,
352+
currentPartInstance
353+
),
354+
next: getPartInstanceTimelineInfo(
355+
absolutePiecePrepareTime,
356+
currentTime,
357+
showStyle.sourceLayers,
358+
nextPartInstance
359+
),
360+
previous: getPartInstanceTimelineInfo(
361+
absolutePiecePrepareTime,
362+
currentTime,
363+
showStyle.sourceLayers,
364+
previousPartInstance
365+
),
327366
}
328367

329368
if (partInstancesInfo.next && nextPartInstance) {
@@ -350,14 +389,18 @@ async function getTimelineRundown(
350389
timelineObjs = timelineObjs.concat(await pLookaheadObjs)
351390

352391
let regenerateTimelineToken: string | undefined
353-
if (rundownTimelineResult.timingContext?.regenerateTimelineAt) {
392+
const regenerateTimelineAt = Math.min(
393+
partInstancesInfo.current?.regenerateTimelineAt ?? Number.POSITIVE_INFINITY,
394+
partInstancesInfo.next?.regenerateTimelineAt ?? Number.POSITIVE_INFINITY
395+
)
396+
if (regenerateTimelineAt < Number.POSITIVE_INFINITY) {
354397
// The timeline has requested a regeneration at a specific time
355398
regenerateTimelineToken = getHash(`regenerate-${playoutModel.playlistId}-${getCurrentTime()}`)
356399
timelineObjs.push(
357400
literal<TimelineObjRegenerateTrigger & OnGenerateTimelineObjExt>({
358401
id: `regenerate_${regenerateTimelineToken}`,
359402
enable: {
360-
start: rundownTimelineResult.timingContext.regenerateTimelineAt,
403+
start: regenerateTimelineAt,
361404
},
362405
layer: '__timeline_regeneration_trigger__', // Some unique name, as callbacks need to be on a layer
363406
priority: 1,

packages/job-worker/src/playout/timeline/rundown.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import _ = require('underscore')
2828
import { getPieceEnableInsidePart, transformPieceGroupAndObjects } from './piece'
2929
import { logger } from '../../logging'
3030

31-
const DEFAULT_ABSOLUTE_PIECE_PREPARE_TIME = 30000
32-
3331
/**
3432
* Some additional data used by the timeline generation process
3533
* Fields are populated as it progresses through generation, and consumed during the finalisation
@@ -39,7 +37,7 @@ export interface RundownTimelineTimingContext {
3937
* How long an absolute timed piece should be on the timeline before it is played
4038
* This is a constant derived from the settings
4139
*/
42-
readonly absolutePiecePrepareTime: number
40+
// readonly absolutePiecePrepareTime: number
4341

4442
currentPartGroup: TimelineObjGroupPart
4543
currentPartDuration: number | undefined
@@ -52,7 +50,7 @@ export interface RundownTimelineTimingContext {
5250
/**
5351
* The timeline can request to be regenerated at a specific time, this allows for things to be added to the timeline nearer to when they will be played
5452
*/
55-
regenerateTimelineAt?: Time
53+
// regenerateTimelineAt?: Time
5654
}
5755
export interface RundownTimelineResult {
5856
timeline: (TimelineObjRundown & OnGenerateTimelineObjExt)[]
@@ -148,8 +146,8 @@ export function buildTimelineObjsForRundown(
148146
const currentPartGroup = createPartGroup(partInstancesInfo.current.partInstance, currentPartEnable)
149147

150148
const timingContext: RundownTimelineTimingContext = {
151-
absolutePiecePrepareTime:
152-
context.studio.settings.rundownGlobalPiecesPrepareTime || DEFAULT_ABSOLUTE_PIECE_PREPARE_TIME,
149+
// absolutePiecePrepareTime:
150+
// context.studio.settings.rundownGlobalPiecesPrepareTime || DEFAULT_ABSOLUTE_PIECE_PREPARE_TIME,
153151
currentPartGroup,
154152
currentPartDuration: currentPartEnable.duration,
155153
}
@@ -288,21 +286,19 @@ function generateCurrentInfinitePieceObjects(
288286
return []
289287
}
290288

291-
const pieceEnable = calculateInfinitePieceEnable(
289+
const { infiniteGroupEnable, pieceEnable, nowInParent } = calculateInfinitePieceEnable(
292290
currentPartInfo,
293291
timingContext,
294292
pieceInstance,
295293
currentTime,
296294
currentPartInstanceTimings
297295
)
298-
// Not allowed to be generated
299-
if (!pieceEnable) return []
300296

301297
const { pieceInstanceWithUpdatedEndCap, cappedInfiniteGroupEnable } = applyInfinitePieceGroupEndCap(
302298
currentPartInfo,
303299
timingContext,
304300
pieceInstance,
305-
pieceEnable.infiniteGroupEnable,
301+
infiniteGroupEnable,
306302
currentPartInstanceTimings,
307303
nextPartInstanceTimings,
308304
nextPartInfinites.get(pieceInstance.infinite.infiniteInstanceId)
@@ -327,9 +323,9 @@ function generateCurrentInfinitePieceObjects(
327323
...transformPieceGroupAndObjects(
328324
activePlaylist._id,
329325
infiniteGroup,
330-
pieceEnable.nowInParent,
326+
nowInParent,
331327
pieceInstanceWithUpdatedEndCap,
332-
pieceEnable.pieceEnable,
328+
pieceEnable,
333329
0,
334330
groupClasses,
335331
isInHold,
@@ -365,15 +361,6 @@ function calculateInfinitePieceEnable(
365361
const infiniteGroupStart = pieceInstance.plannedStartedPlayback ?? pieceInstance.piece.enable.start
366362

367363
if (typeof infiniteGroupStart === 'number') {
368-
if (infiniteGroupStart > currentTime + timingContext.absolutePiecePrepareTime) {
369-
// This piece is starting too far in the future, omit it from the timeline
370-
timingContext.regenerateTimelineAt = Math.min(
371-
timingContext.regenerateTimelineAt ?? Number.POSITIVE_INFINITY,
372-
infiniteGroupStart - timingContext.absolutePiecePrepareTime
373-
)
374-
return null
375-
}
376-
377364
nowInParent = currentTime - infiniteGroupStart
378365
} else {
379366
// We should never hit this, but in case start is "now"

0 commit comments

Comments
 (0)