mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
fix transport header error with some Hikvision cameras
fixes 'invalid transport header: encoding/hex: invalid byte: U+0020 ' ''.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user