Skip to content

Commit 3ddd1fd

Browse files
committed
chore: simplify innerStopPieces (why was that using 'endRelativeToNow' in the first place?)
1 parent f87d372 commit 3ddd1fd

File tree

4 files changed

+5
-37
lines changed

4 files changed

+5
-37
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ export function innerStopPieces(
278278
}
279279

280280
const resolvedPieces = getResolvedPiecesForCurrentPartInstance(context, sourceLayers, currentPartInstance)
281-
// TODO: this should be reworked, so that getNowOffsetLatency() can be a protected method of the model
282-
const offsetRelativeToNow = (timeOffset ?? 0) + (playoutModel.getNowOffsetLatency() ?? 0)
283-
const stopAt = getCurrentTime() + offsetRelativeToNow
281+
const stopAt = playoutModel.getNowInPlayout() + (timeOffset ?? 0)
284282
const relativeStopAt = stopAt - lastStartedPlayback
285283

286284
for (const resolvedPieceInstance of resolvedPieces) {
@@ -310,15 +308,9 @@ export function innerStopPieces(
310308

311309
const pieceInstanceModel = playoutModel.findPieceInstance(pieceInstance._id)
312310
if (pieceInstanceModel) {
313-
const newDuration: Required<PieceInstance>['userDuration'] = playoutModel.isMultiGatewayMode
314-
? {
315-
endRelativeToNow: offsetRelativeToNow,
316-
}
317-
: {
318-
endRelativeToPart: relativeStopAt,
319-
}
320-
321-
pieceInstanceModel.pieceInstance.setDuration(newDuration)
311+
pieceInstanceModel.pieceInstance.setDuration({
312+
endRelativeToPart: relativeStopAt,
313+
})
322314

323315
stoppedInstances.push(pieceInstance._id)
324316
} else {

packages/job-worker/src/playout/model/implementation/PlayoutModelImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class PlayoutModelReadonlyImpl implements PlayoutModelReadonly {
274274
* Calculate an offset to apply to the 'now' value, to compensate for delay in playout-gateway
275275
* The intention is that any concrete value used instead of 'now' should still be just in the future for playout-gateway
276276
*/
277-
getNowOffsetLatency(): number | undefined {
277+
protected getNowOffsetLatency(): number | undefined {
278278
/** The timestamp that "now" was set to */
279279
let nowOffsetLatency: number | undefined
280280

packages/job-worker/src/studio/model/StudioPlayoutModel.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export interface StudioPlayoutModelBaseReadonly {
2828
readonly isMultiGatewayMode: boolean
2929

3030
readonly multiGatewayNowSafeLatency: number | undefined
31-
32-
getNowOffsetLatency(): number | undefined
3331
}
3432

3533
export interface StudioPlayoutModelBase extends StudioPlayoutModelBaseReadonly {

packages/job-worker/src/studio/model/StudioPlayoutModelImpl.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { DatabasePersistedModel } from '../../modelBase.js'
1818
import { ExpectedPackageDBFromStudioBaselineObjects } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
1919
import { ExpectedPlayoutItemStudio } from '@sofie-automation/corelib/dist/dataModel/ExpectedPlayoutItem'
2020
import { StudioBaselineHelper } from './StudioBaselineHelper.js'
21-
import { getExpectedLatency } from '@sofie-automation/corelib/dist/studio/playout'
2221

2322
/**
2423
* This is a model used for studio operations.
@@ -83,27 +82,6 @@ export class StudioPlayoutModelImpl implements StudioPlayoutModel {
8382
return this.context.studio.settings.multiGatewayNowSafeLatency
8483
}
8584

86-
/**
87-
* Calculate an offset to apply to the 'now' value, to compensate for delay in playout-gateway
88-
* The intention is that any concrete value used instead of 'now' should still be just in the future for playout-gateway
89-
*/
90-
getNowOffsetLatency(): number | undefined {
91-
/** The timestamp that "now" was set to */
92-
let nowOffsetLatency: number | undefined
93-
94-
if (this.isMultiGatewayMode) {
95-
const playoutDevices = this.peripheralDevices.filter(
96-
(device) => device.type === PeripheralDeviceType.PLAYOUT
97-
)
98-
const worstLatency = Math.max(0, ...playoutDevices.map((device) => getExpectedLatency(device).safe))
99-
/** Add a little more latency, to account for network latency variability */
100-
const ADD_SAFE_LATENCY = this.multiGatewayNowSafeLatency || 30
101-
nowOffsetLatency = worstLatency + ADD_SAFE_LATENCY
102-
}
103-
104-
return nowOffsetLatency
105-
}
106-
10785
setExpectedPackagesForStudioBaseline(packages: ExpectedPackageDBFromStudioBaselineObjects[]): void {
10886
this.#baselineHelper.setExpectedPackages(packages)
10987
}

0 commit comments

Comments
 (0)