playlist GUI
This commit is contained in:
@@ -6,6 +6,7 @@ type PlaylistTimingState struct {
|
||||
Revision uint64
|
||||
Duration time.Duration
|
||||
Started bool
|
||||
Expired bool
|
||||
Deadline time.Time
|
||||
}
|
||||
|
||||
@@ -16,6 +17,7 @@ func NewPlaylistTiming(
|
||||
return PlaylistTimingState{
|
||||
Revision: revision,
|
||||
Duration: duration,
|
||||
Expired: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +26,12 @@ func StartPlaylistTiming(
|
||||
revision uint64,
|
||||
now time.Time,
|
||||
) (PlaylistTimingState, bool) {
|
||||
if revision != current.Revision || current.Duration <= 0 || current.Started {
|
||||
if revision != current.Revision ||
|
||||
current.Duration <= 0 ||
|
||||
current.Started ||
|
||||
current.Expired {
|
||||
return current, false
|
||||
}
|
||||
|
||||
next := current
|
||||
next.Started = true
|
||||
next.Deadline = now.Add(current.Duration)
|
||||
@@ -48,5 +52,6 @@ func ExpirePlaylistTiming(
|
||||
next := current
|
||||
next.Started = false
|
||||
next.Deadline = time.Time{}
|
||||
next.Expired = true
|
||||
return next, true
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ func TestStartPlaylistTimingIgnoresInapplicableReadiness(t *testing.T) {
|
||||
{name: "stale revision", current: NewPlaylistTiming(4, time.Second), revision: 3},
|
||||
{name: "future revision", current: NewPlaylistTiming(4, time.Second), revision: 5},
|
||||
{name: "already started", current: started, revision: 4},
|
||||
{name: "expired", current: PlaylistTimingState{Revision: 4, Duration: time.Second, Expired: true}, revision: 4},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -70,7 +71,7 @@ func TestExpirePlaylistTiming(t *testing.T) {
|
||||
if !expired {
|
||||
t.Fatal("ExpirePlaylistTiming() expired = false, want true")
|
||||
}
|
||||
want := PlaylistTimingState{Revision: 9, Duration: 5 * time.Second}
|
||||
want := PlaylistTimingState{Revision: 9, Duration: 5 * time.Second, Expired: true}
|
||||
if got != want {
|
||||
t.Fatalf("ExpirePlaylistTiming() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user