mirror of
				https://github.com/AlexxIT/go2rtc.git
				synced 2025-10-31 19:53:02 +08:00 
			
		
		
		
	Fix RTSP URL parse bug #208
This commit is contained in:
		| @@ -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 { | ||||||
|   | |||||||
| @@ -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) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Alexey Khit
					Alexey Khit