playlist timer pause/resume without affecting active feeds
This commit is contained in:
@@ -3,11 +3,14 @@ package playback
|
||||
import "time"
|
||||
|
||||
type PlaylistTimingState struct {
|
||||
Revision uint64
|
||||
Duration time.Duration
|
||||
Started bool
|
||||
Expired bool
|
||||
Deadline time.Time
|
||||
Revision uint64
|
||||
Duration time.Duration
|
||||
Ready bool
|
||||
Started bool
|
||||
Paused bool
|
||||
Expired bool
|
||||
Remaining time.Duration
|
||||
Deadline time.Time
|
||||
}
|
||||
|
||||
func NewPlaylistTiming(
|
||||
@@ -15,9 +18,9 @@ func NewPlaylistTiming(
|
||||
duration time.Duration,
|
||||
) PlaylistTimingState {
|
||||
return PlaylistTimingState{
|
||||
Revision: revision,
|
||||
Duration: duration,
|
||||
Expired: false,
|
||||
Revision: revision,
|
||||
Duration: duration,
|
||||
Remaining: duration,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +32,66 @@ func StartPlaylistTiming(
|
||||
if revision != current.Revision ||
|
||||
current.Duration <= 0 ||
|
||||
current.Started ||
|
||||
current.Paused ||
|
||||
current.Expired {
|
||||
return current, false
|
||||
}
|
||||
next := current
|
||||
if next.Remaining <= 0 {
|
||||
next.Remaining = next.Duration
|
||||
}
|
||||
next.Ready = true
|
||||
next.Started = true
|
||||
next.Deadline = now.Add(current.Duration)
|
||||
next.Deadline = now.Add(next.Remaining)
|
||||
return next, true
|
||||
}
|
||||
|
||||
func PausePlaylistTiming(
|
||||
current PlaylistTimingState,
|
||||
revision uint64,
|
||||
now time.Time,
|
||||
) (PlaylistTimingState, bool) {
|
||||
if revision != current.Revision ||
|
||||
current.Duration <= 0 ||
|
||||
current.Paused ||
|
||||
current.Expired {
|
||||
return current, false
|
||||
}
|
||||
|
||||
next := current
|
||||
if next.Started {
|
||||
next.Remaining = next.Deadline.Sub(now)
|
||||
if next.Remaining < 0 {
|
||||
next.Remaining = 0
|
||||
}
|
||||
if next.Remaining > next.Duration {
|
||||
next.Remaining = next.Duration
|
||||
}
|
||||
next.Started = false
|
||||
next.Deadline = time.Time{}
|
||||
}
|
||||
next.Paused = true
|
||||
return next, true
|
||||
}
|
||||
|
||||
func ResumePlaylistTiming(
|
||||
current PlaylistTimingState,
|
||||
revision uint64,
|
||||
now time.Time,
|
||||
) (PlaylistTimingState, bool) {
|
||||
if revision != current.Revision ||
|
||||
current.Duration <= 0 ||
|
||||
!current.Paused ||
|
||||
current.Expired {
|
||||
return current, false
|
||||
}
|
||||
|
||||
next := current
|
||||
next.Paused = false
|
||||
if next.Ready {
|
||||
next.Started = true
|
||||
next.Deadline = now.Add(next.Remaining)
|
||||
}
|
||||
return next, true
|
||||
}
|
||||
|
||||
@@ -51,7 +108,9 @@ func ExpirePlaylistTiming(
|
||||
|
||||
next := current
|
||||
next.Started = false
|
||||
next.Paused = false
|
||||
next.Deadline = time.Time{}
|
||||
next.Expired = true
|
||||
next.Remaining = 0
|
||||
return next, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user