diff --git a/pkg/rtsp/helpers.go b/pkg/rtsp/helpers.go index 3a7c0dc8..f748c9a2 100644 --- a/pkg/rtsp/helpers.go +++ b/pkg/rtsp/helpers.go @@ -47,9 +47,14 @@ func UnmarshalSDP(rawSDP []byte) ([]*streamer.Media, error) { return medias, nil } -// urlParse fix bug in URL from D-Link camera: -// Content-Base: rtsp://::ffff:192.168.1.123/onvif/profile.1/ +// urlParse fix bugs: +// 1. Content-Base: rtsp://::ffff:192.168.1.123/onvif/profile.1/ +// 2. Content-Base: rtsp://rtsp://turret2-cam.lan:554/stream1/ func urlParse(rawURL string) (*url.URL, error) { + if strings.HasPrefix(rawURL, "rtsp://rtsp://") { + rawURL = rawURL[7:] + } + u, err := url.Parse(rawURL) if err != nil && strings.HasSuffix(err.Error(), "after host") { if i1 := strings.Index(rawURL, "://"); i1 > 0 { diff --git a/pkg/rtsp/rtsp_test.go b/pkg/rtsp/rtsp_test.go index 93b2e930..7e32b272 100644 --- a/pkg/rtsp/rtsp_test.go +++ b/pkg/rtsp/rtsp_test.go @@ -6,7 +6,15 @@ import ( ) func TestURLParse(t *testing.T) { + // https://github.com/AlexxIT/WebRTC/issues/395 base := "rtsp://::ffff:192.168.1.123/onvif/profile.1/" - _, err := urlParse(base) + u, err := urlParse(base) assert.Empty(t, err) + assert.Equal(t, "::ffff:192.168.1.123:", u.Host) + + // https://github.com/AlexxIT/go2rtc/issues/208 + base = "rtsp://rtsp://turret2-cam.lan:554/stream1/" + u, err = urlParse(base) + assert.Empty(t, err) + assert.Equal(t, "turret2-cam.lan:554", u.Host) }