evision-safe playlist timing
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package playback
|
||||
|
||||
import "time"
|
||||
|
||||
type PlaylistTimingState struct {
|
||||
Revision uint64
|
||||
Duration time.Duration
|
||||
Started bool
|
||||
Deadline time.Time
|
||||
}
|
||||
|
||||
func NewPlaylistTiming(
|
||||
revision uint64,
|
||||
duration time.Duration,
|
||||
) PlaylistTimingState {
|
||||
return PlaylistTimingState{
|
||||
Revision: revision,
|
||||
Duration: duration,
|
||||
}
|
||||
}
|
||||
|
||||
func StartPlaylistTiming(
|
||||
current PlaylistTimingState,
|
||||
revision uint64,
|
||||
now time.Time,
|
||||
) (PlaylistTimingState, bool) {
|
||||
if revision != current.Revision || current.Duration <= 0 || current.Started {
|
||||
return current, false
|
||||
}
|
||||
|
||||
next := current
|
||||
next.Started = true
|
||||
next.Deadline = now.Add(current.Duration)
|
||||
return next, true
|
||||
}
|
||||
|
||||
func ExpirePlaylistTiming(
|
||||
current PlaylistTimingState,
|
||||
revision uint64,
|
||||
now time.Time,
|
||||
) (PlaylistTimingState, bool) {
|
||||
if revision != current.Revision ||
|
||||
!current.Started ||
|
||||
now.Before(current.Deadline) {
|
||||
return current, false
|
||||
}
|
||||
|
||||
next := current
|
||||
next.Started = false
|
||||
next.Deadline = time.Time{}
|
||||
return next, true
|
||||
}
|
||||
Reference in New Issue
Block a user