Skip to content

Commit

Permalink
fix: Segment and Part timing are being out of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Oct 2, 2024
1 parent 38f5690 commit cf68683
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 10 additions & 0 deletions packages/webui/src/client/lib/rundownTiming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class RundownTimingCalculator {

let lastSegmentId: SegmentId | undefined = undefined
let nextRundownAnchor: number | undefined = undefined
let remainingTimeOnCurrentSegment = 0

if (playlist) {
const breakProps = currentRundown ? this.getRundownsBeforeNextBreak(rundowns, currentRundown) : undefined
Expand Down Expand Up @@ -281,6 +282,12 @@ export class RundownTimingCalculator {
defaultDuration
partDisplayDuration = Math.max(partDisplayDurationNoPlayback, now - lastStartedPlayback)
this.partPlayed[partInstanceOrPartId] = now - lastStartedPlayback
if (liveSegmentId === partInstance.segmentId) {
// Workaround:
// The offset of 650 microseconds is to compensate for part and segment being in separate
// clocks windows in the UI
remainingTimeOnCurrentSegment += now - lastStartedPlayback - 650
}
const segmentStartedPlayback =
playlist.segmentsStartedPlayback?.[unprotectString(partInstance.segmentId)] ??
lastStartedPlayback
Expand Down Expand Up @@ -632,6 +639,7 @@ export class RundownTimingCalculator {
segmentStartedPlayback: this.segmentStartedPlayback,
currentTime: now,
remainingTimeOnCurrentPart,
remainingTimeOnCurrentSegment,
remainingBudgetOnCurrentSegment,
currentPartWillAutoNext,
rundownsBeforeNextBreak,
Expand Down Expand Up @@ -726,6 +734,8 @@ export interface RundownTimingContext {
segmentStartedPlayback?: Record<string, number>
/** Remaining time on current part */
remainingTimeOnCurrentPart?: number
/** Remaining time on current segment */
remainingTimeOnCurrentSegment?: number
/** Remaining budget on current segment, if its countdownType === CountdownType.SEGMENT_BUDGET_DURATION */
remainingBudgetOnCurrentSegment?: number
/** Current part will autoNext */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { withTiming, WithTiming } from './withTiming'
import { RundownUtils } from '../../../lib/rundown'
import { PartUi } from '../../SegmentTimeline/SegmentTimelineContainer'
import { calculatePartInstanceExpectedDurationWithTransition } from '@sofie-automation/corelib/dist/playout/timings'
import { getPartInstanceTimingId } from '../../../lib/rundownTiming'
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'

interface ISegmentDurationProps {
Expand All @@ -29,15 +28,14 @@ export const SegmentDuration = withTiming<ISegmentDurationProps, {}>()(function
) {
let duration: number | undefined = undefined
let budget = 0
let playedOut = 0
const playedOut = props.timingDurations.remainingTimeOnCurrentSegment || 0

const segmentBudgetDuration = props.segment.segmentTiming?.budgetDuration

if (segmentBudgetDuration !== undefined) {
budget = segmentBudgetDuration
}
if (props.parts && props.timingDurations.partPlayed) {
const { partPlayed } = props.timingDurations
if (segmentBudgetDuration === undefined) {
props.parts.forEach((part) => {
budget +=
Expand All @@ -46,9 +44,6 @@ export const SegmentDuration = withTiming<ISegmentDurationProps, {}>()(function
: calculatePartInstanceExpectedDurationWithTransition(part.instance) || 0
})
}
props.parts.forEach((part) => {
playedOut += (!part.instance.part.untimed ? partPlayed[getPartInstanceTimingId(part.instance)] : 0) || 0
})
}

duration = budget - playedOut
Expand Down

0 comments on commit cf68683

Please sign in to comment.