Change go version to 1.20 for Windows 7 support
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package core
|
||||
|
||||
// This code copied from go1.21 for backward support in go1.20.
|
||||
// We need to support go1.20 for Windows 7
|
||||
|
||||
// Index returns the index of the first occurrence of v in s,
|
||||
// or -1 if not present.
|
||||
func Index[S ~[]E, E comparable](s S, v E) int {
|
||||
for i := range s {
|
||||
if v == s[i] {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Contains reports whether v is present in s.
|
||||
func Contains[S ~[]E, E comparable](s S, v E) bool {
|
||||
return Index(s, v) >= 0
|
||||
}
|
||||
|
||||
type Ordered interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
|
||||
~float32 | ~float64 |
|
||||
~string
|
||||
}
|
||||
|
||||
// Max returns the maximal value in x. It panics if x is empty.
|
||||
// For floating-point E, Max propagates NaNs (any NaN value in x
|
||||
// forces the output to be NaN).
|
||||
func Max[S ~[]E, E Ordered](x S) E {
|
||||
if len(x) < 1 {
|
||||
panic("slices.Max: empty list")
|
||||
}
|
||||
m := x[0]
|
||||
for i := 1; i < len(x); i++ {
|
||||
if x[i] > m {
|
||||
m = x[i]
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package homekit
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand/v2"
|
||||
"math/rand"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package homekit
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"slices"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/aac"
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
@@ -22,8 +21,8 @@ func videoToMedia(codecs []camera.VideoCodec) *core.Media {
|
||||
for _, codec := range codecs {
|
||||
for _, param := range codec.CodecParams {
|
||||
// get best profile and level
|
||||
profileID := slices.Max(param.ProfileID)
|
||||
level := slices.Max(param.Level)
|
||||
profileID := core.Max(param.ProfileID)
|
||||
level := core.Max(param.Level)
|
||||
profile := videoProfiles[profileID] + videoLevels[level]
|
||||
mediaCodec := &core.Codec{
|
||||
Name: videoCodecs[codec.CodecType],
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@ package webrtc
|
||||
|
||||
import (
|
||||
"net"
|
||||
"slices"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/pion/interceptor"
|
||||
"github.com/pion/webrtc/v3"
|
||||
)
|
||||
@@ -47,7 +47,7 @@ func NewServerAPI(network, address string, filters *Filters) (*webrtc.API, error
|
||||
if filters != nil && filters.Interfaces != nil {
|
||||
s.SetIncludeLoopbackCandidate(true)
|
||||
s.SetInterfaceFilter(func(name string) bool {
|
||||
return slices.Contains(filters.Interfaces, name)
|
||||
return core.Contains(filters.Interfaces, name)
|
||||
})
|
||||
} else {
|
||||
// disable listen on Hassio docker interfaces
|
||||
@@ -59,7 +59,7 @@ func NewServerAPI(network, address string, filters *Filters) (*webrtc.API, error
|
||||
if filters != nil && filters.IPs != nil {
|
||||
s.SetIncludeLoopbackCandidate(true)
|
||||
s.SetIPFilter(func(ip net.IP) bool {
|
||||
return slices.Contains(filters.IPs, ip.String())
|
||||
return core.Contains(filters.IPs, ip.String())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user