69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package playback
|
|
|
|
func IsSessionPlaying(
|
|
session SessionSnapshot,
|
|
statuses PlaybackStatusSnapshot,
|
|
) bool {
|
|
if statuses.Generation != session.Generation {
|
|
return false
|
|
}
|
|
|
|
switch session.Plan.Topology {
|
|
case TopologyIndependent:
|
|
hasActiveFeed := session.Plan.Video.Active || session.Plan.Audio.Active
|
|
if !hasActiveFeed {
|
|
return false
|
|
}
|
|
if session.Plan.Video.Active && !statusIsPlaying(
|
|
statuses.Video,
|
|
statuses.HasVideo,
|
|
session.Generation,
|
|
session.Plan.Video,
|
|
) {
|
|
return false
|
|
}
|
|
if session.Plan.Audio.Active && !statusIsPlaying(
|
|
statuses.Audio,
|
|
statuses.HasAudio,
|
|
session.Generation,
|
|
session.Plan.Audio,
|
|
) {
|
|
return false
|
|
}
|
|
return true
|
|
|
|
case TopologySynchronized:
|
|
return statuses.HasSync &&
|
|
statuses.Sync.Generation == session.Generation &&
|
|
statuses.Sync.State == StatePlaying &&
|
|
sameSyncSource(statuses.Sync.Pair, session.Plan.Sync)
|
|
|
|
case TopologyIdle:
|
|
return false
|
|
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func statusIsPlaying(
|
|
status Status,
|
|
present bool,
|
|
generation uint64,
|
|
feed FeedConfig,
|
|
) bool {
|
|
return present &&
|
|
status.Generation == generation &&
|
|
status.State == StatePlaying &&
|
|
sameFeedSource(status.Feed, feed)
|
|
}
|
|
|
|
func sameFeedSource(a, b FeedConfig) bool {
|
|
return a.Domain == b.Domain && a.UUID == b.UUID
|
|
}
|
|
|
|
func sameSyncSource(a, b SyncPairConfig) bool {
|
|
return sameFeedSource(a.Video, b.Video) &&
|
|
sameFeedSource(a.Audio, b.Audio)
|
|
}
|