From 1139d4fcad0507813bedb335a29118f58b5fc94f Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sun, 21 Aug 2022 16:58:35 +0300 Subject: [PATCH] Fix wrong RTSP Transport responses --- pkg/rtsp/conn.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/rtsp/conn.go b/pkg/rtsp/conn.go index 63ebdd9a..574d3d09 100644 --- a/pkg/rtsp/conn.go +++ b/pkg/rtsp/conn.go @@ -362,10 +362,22 @@ func (c *Conn) SetupMedia( // we send our `interleaved`, but camera can answer with another // Transport: RTP/AVP/TCP;unicast;interleaved=10-11;ssrc=10117CB7 + // Transport: RTP/AVP/TCP;unicast;destination=192.168.1.123;source=192.168.10.12;interleaved=0 s := res.Header.Get("Transport") - s, ok1, ok2 := between(s, "RTP/AVP/TCP;unicast;interleaved=", "-") - if !ok1 || !ok2 { - panic("wrong response") + // TODO: rewrite + if !strings.HasPrefix(s, "RTP/AVP/TCP;unicast") { + return nil, fmt.Errorf("wrong transport: %s", s) + } + + i := strings.Index(s, "interleaved=") + if i < 0 { + return nil, fmt.Errorf("wrong transport: %s", s) + } + + s = s[i+len("interleaved="):] + i = strings.IndexAny(s, "-;") + if i > 0 { + s = s[:i] } ch, err = strconv.Atoi(s)