Fix RTSP URL parse bug #208

This commit is contained in:
Alexey Khit
2023-01-26 09:09:48 +03:00
parent 0e28b0c797
commit 2f436bba4e
2 changed files with 16 additions and 3 deletions

View File

@@ -47,9 +47,14 @@ func UnmarshalSDP(rawSDP []byte) ([]*streamer.Media, error) {
return medias, nil return medias, nil
} }
// urlParse fix bug in URL from D-Link camera: // urlParse fix bugs:
// Content-Base: rtsp://::ffff:192.168.1.123/onvif/profile.1/ // 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) { func urlParse(rawURL string) (*url.URL, error) {
if strings.HasPrefix(rawURL, "rtsp://rtsp://") {
rawURL = rawURL[7:]
}
u, err := url.Parse(rawURL) u, err := url.Parse(rawURL)
if err != nil && strings.HasSuffix(err.Error(), "after host") { if err != nil && strings.HasSuffix(err.Error(), "after host") {
if i1 := strings.Index(rawURL, "://"); i1 > 0 { if i1 := strings.Index(rawURL, "://"); i1 > 0 {

View File

@@ -6,7 +6,15 @@ import (
) )
func TestURLParse(t *testing.T) { func TestURLParse(t *testing.T) {
// https://github.com/AlexxIT/WebRTC/issues/395
base := "rtsp://::ffff:192.168.1.123/onvif/profile.1/" base := "rtsp://::ffff:192.168.1.123/onvif/profile.1/"
_, err := urlParse(base) u, err := urlParse(base)
assert.Empty(t, err) 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)
} }