Fix ONVIF discovery for buggy camera

This commit is contained in:
Alexey Khit
2023-05-02 11:25:00 +03:00
parent 9c8a1d8b19
commit 4bbd3a1cd2
+8 -2
View File
@@ -31,7 +31,7 @@ func UUID() string {
}
func DiscoveryStreamingHosts() ([]string, error) {
conn, err := net.ListenPacket("udp4", ":0")
conn, err := net.ListenUDP("udp4", nil)
if err != nil {
return nil, err
}
@@ -70,7 +70,7 @@ func DiscoveryStreamingHosts() ([]string, error) {
b := make([]byte, 8192)
for {
n, _, err := conn.ReadFrom(b)
n, addr, err := conn.ReadFromUDP(b)
if err != nil {
break
}
@@ -96,6 +96,12 @@ func DiscoveryStreamingHosts() ([]string, error) {
continue
}
// fix some buggy cameras
// <wsdd:XAddrs>http://0.0.0.0:8080/onvif/device_service</wsdd:XAddrs>
if strings.HasPrefix(u.Host, "0.0.0.0") {
u.Host = addr.IP.String() + u.Host[7:]
}
hosts = append(hosts, u.Host)
}