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) { func DiscoveryStreamingHosts() ([]string, error) {
conn, err := net.ListenPacket("udp4", ":0") conn, err := net.ListenUDP("udp4", nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -70,7 +70,7 @@ func DiscoveryStreamingHosts() ([]string, error) {
b := make([]byte, 8192) b := make([]byte, 8192)
for { for {
n, _, err := conn.ReadFrom(b) n, addr, err := conn.ReadFromUDP(b)
if err != nil { if err != nil {
break break
} }
@@ -96,6 +96,12 @@ func DiscoveryStreamingHosts() ([]string, error) {
continue 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) hosts = append(hosts, u.Host)
} }