latencyLevels.go 907 B

123456789101112131415161718192021222324
  1. package models
  2. // LatencyLevel is a representation of HLS configuration values.
  3. type LatencyLevel struct {
  4. Level int `json:"level"`
  5. SecondsPerSegment int `json:"-"`
  6. SegmentCount int `json:"-"`
  7. }
  8. // GetLatencyConfigs will return the available latency level options.
  9. func GetLatencyConfigs() map[int]LatencyLevel {
  10. return map[int]LatencyLevel{
  11. 0: {Level: 0, SecondsPerSegment: 1, SegmentCount: 3}, // Approx 5 seconds
  12. 1: {Level: 1, SecondsPerSegment: 2, SegmentCount: 2}, // Approx 7-8 seconds
  13. 2: {Level: 2, SecondsPerSegment: 3, SegmentCount: 3}, // Default Approx 11 seconds
  14. 3: {Level: 3, SecondsPerSegment: 4, SegmentCount: 3}, // Approx 15 seconds
  15. 4: {Level: 4, SecondsPerSegment: 5, SegmentCount: 4}, // Approx 18 seconds
  16. }
  17. }
  18. // GetLatencyLevel will return the latency level at index.
  19. func GetLatencyLevel(index int) LatencyLevel {
  20. return GetLatencyConfigs()[index]
  21. }