1313
1414import {
1515 PlaylistTimingBackTime ,
16+ PlaylistTimingDuration ,
1617 PlaylistTimingForwardTime ,
1718 PlaylistTimingNone ,
1819 PlaylistTimingType ,
@@ -34,6 +35,10 @@ export namespace PlaylistTiming {
3435 return timing . type === PlaylistTimingType . BackTime
3536 }
3637
38+ export function isPlaylistDurationTimed ( timing : RundownPlaylistTiming ) : timing is PlaylistTimingDuration {
39+ return timing . type === PlaylistTimingType . Duration
40+ }
41+
3742 export function getExpectedStart ( timing : RundownPlaylistTiming ) : number | undefined {
3843 if ( PlaylistTiming . isPlaylistTimingForwardTime ( timing ) ) {
3944 return timing . expectedStart
@@ -42,19 +47,29 @@ export namespace PlaylistTiming {
4247 timing . expectedStart ||
4348 ( timing . expectedDuration ? timing . expectedEnd - timing . expectedDuration : undefined )
4449 )
50+ } else if ( PlaylistTiming . isPlaylistDurationTimed ( timing ) ) {
51+ return timing . expectedStart
4552 } else {
4653 return undefined
4754 }
4855 }
4956
50- export function getExpectedEnd ( timing : RundownPlaylistTiming ) : number | undefined {
57+ export function getExpectedEnd ( timing : RundownPlaylistTiming , startedPlayback ?: number ) : number | undefined {
5158 if ( PlaylistTiming . isPlaylistTimingBackTime ( timing ) ) {
5259 return timing . expectedEnd
5360 } else if ( PlaylistTiming . isPlaylistTimingForwardTime ( timing ) ) {
5461 return (
5562 timing . expectedEnd ||
5663 ( timing . expectedDuration ? timing . expectedStart + timing . expectedDuration : undefined )
5764 )
65+ } else if ( PlaylistTiming . isPlaylistDurationTimed ( timing ) ) {
66+ if ( ! startedPlayback ) {
67+ // before the show, estimate the end from start + dur
68+ return timing . expectedStart ? timing . expectedStart + timing . expectedDuration : undefined
69+ } else {
70+ // after starting the show, project the end from startedPlayback + dur
71+ return startedPlayback + timing . expectedDuration
72+ }
5873 } else {
5974 return undefined
6075 }
@@ -70,6 +85,20 @@ export namespace PlaylistTiming {
7085 }
7186 }
7287
88+ export function getEstimatedEnd (
89+ timing : RundownPlaylistTiming ,
90+ now : number ,
91+ remainingPlaylistDuration ?: number ,
92+ startedPlayback ?: number
93+ ) : number | undefined {
94+ if ( remainingPlaylistDuration !== undefined ) {
95+ const frontAnchor = startedPlayback ? now : Math . max ( now , PlaylistTiming . getExpectedStart ( timing ) ?? now )
96+
97+ return frontAnchor + remainingPlaylistDuration
98+ }
99+ return undefined
100+ }
101+
73102 export function sortTimings (
74103 a : ReadonlyDeep < { timing : RundownPlaylistTiming } > ,
75104 b : ReadonlyDeep < { timing : RundownPlaylistTiming } >
0 commit comments