fix transport header parsing with dahua rtsp server (#121)

This commit is contained in:
aler9
2022-04-21 08:58:59 +02:00
parent 5338d9ab4c
commit d2380aeed1
2 changed files with 18 additions and 10 deletions

View File

@@ -201,17 +201,8 @@ func (h *Transport) Read(v base.HeaderValue) error {
h.ServerPorts = ports h.ServerPorts = ports
case "ssrc": case "ssrc":
// replace initial spaces v = strings.TrimLeft(v, " ")
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 { if (len(v) % 2) != 0 {
v = "0" + v v = "0" + v
} }

View File

@@ -181,6 +181,23 @@ var casesTransport = []struct {
}(), }(),
}, },
}, },
{
"dahua rtsp server ssrc with initial spaces",
base.HeaderValue{`RTP/AVP/TCP;unicast;interleaved=0-1;ssrc= D93FF`},
base.HeaderValue{`RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=000D93FF`},
Transport{
Protocol: TransportProtocolTCP,
Delivery: func() *TransportDelivery {
v := TransportDeliveryUnicast
return &v
}(),
InterleavedIDs: &[2]int{0, 1},
SSRC: func() *uint32 {
v := uint32(0xD93FF)
return &v
}(),
},
},
} }
func TestTransportRead(t *testing.T) { func TestTransportRead(t *testing.T) {