fix transport header error with some Hikvision cameras

fixes 'invalid transport header: encoding/hex: invalid byte: U+0020 ' ''.
This commit is contained in:
aler9
2022-01-05 11:54:03 +01:00
parent 721004c2c8
commit 50f19e6653
2 changed files with 33 additions and 0 deletions

View File

@@ -184,6 +184,17 @@ func (h *Transport) Read(v base.HeaderValue) error {
h.ServerPorts = ports
case "ssrc":
// replace initial spaces
var b strings.Builder
b.Grow(len(v))
i := 0
for ; i < len(v) && v[i] == ' '; i++ {
b.WriteByte('0')
}
b.WriteString(v[i:])
v = b.String()
// add initial zeros
if (len(v) % 2) != 0 {
v = "0" + v
}

View File

@@ -155,6 +155,28 @@ var casesTransport = []struct {
}(),
},
},
{
"hikvision ssrc with initial spaces",
base.HeaderValue{`RTP/AVP/UDP;unicast;client_port=14186;server_port=8052;ssrc= 4317f;mode=play`},
base.HeaderValue{`RTP/AVP;unicast;client_port=14186-14187;server_port=8052-8053;ssrc=0004317F;mode=play`},
Transport{
Protocol: TransportProtocolUDP,
Delivery: func() *TransportDelivery {
v := TransportDeliveryUnicast
return &v
}(),
Mode: func() *TransportMode {
v := TransportModePlay
return &v
}(),
ClientPorts: &[2]int{14186, 14187},
ServerPorts: &[2]int{8052, 8053},
SSRC: func() *uint32 {
v := uint32(0x04317f)
return &v
}(),
},
},
}
func TestTransportRead(t *testing.T) {