client: build track URLs by using Content-Base, when provided by server

This commit is contained in:
aler9
2021-04-03 15:45:14 +02:00
parent c946e4b6cf
commit 1f8d7a9ae7
9 changed files with 312 additions and 120 deletions

View File

@@ -5,6 +5,8 @@ import (
psdp "github.com/pion/sdp/v3"
"github.com/stretchr/testify/require"
"github.com/aler9/gortsplib/pkg/base"
)
func TestTrackClockRate(t *testing.T) {
@@ -84,6 +86,114 @@ func TestTrackClockRate(t *testing.T) {
}
}
func TestTrackURL(t *testing.T) {
for _, ca := range []struct {
name string
sdp []byte
baseURL *base.URL
ur *base.URL
}{
{
"missing control",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/path/"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/path/"),
},
{
"absolute control",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:rtsp://localhost/path/trackID=7"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/path/"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/path/trackID=7"),
},
{
"relative control",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:trackID=5"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/path/"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/path/trackID=5"),
},
{
"relative control, subpath",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:trackID=5"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/sub/path/"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/sub/path/trackID=5"),
},
{
"relative control, url without slash",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:trackID=5"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/sub/path"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/sub/path/trackID=5"),
},
{
"relative control, url with query",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:trackID=5"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/test?user=tmp&password=BagRep1&channel=1&stream=0.sdp/trackID=5"),
},
{
"relative control, url with special chars and query",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:trackID=5"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/te!st?user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=5"),
},
{
"relative control, url with query without question mark",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:trackID=5"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp"),
base.MustParseURL("rtsp://myuser:mypass@192.168.1.99:554/user=tmp&password=BagRep1!&channel=1&stream=0.sdp/trackID=5"),
},
{
"relative control, control is query",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:?ctype=video"),
base.MustParseURL("rtsp://192.168.1.99:554/test"),
base.MustParseURL("rtsp://192.168.1.99:554/test?ctype=video"),
},
{
"relative control, control is query and no path",
[]byte("v=0\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=control:?ctype=video"),
base.MustParseURL("rtsp://192.168.1.99:554/"),
base.MustParseURL("rtsp://192.168.1.99:554/?ctype=video"),
},
} {
t.Run(ca.name, func(t *testing.T) {
tracks, err := ReadTracks(ca.sdp, nil)
require.NoError(t, err)
tracks[0].BaseURL = ca.baseURL
ur, err := tracks[0].URL()
require.NoError(t, err)
require.Equal(t, ca.ur, ur)
})
}
}
var testH264SPS = []byte("\x67\x64\x00\x0c\xac\x3b\x50\xb0\x4b\x42\x00\x00\x03\x00\x02\x00\x00\x03\x00\x3d\x08")
var testH264PPS = []byte("\x68\xee\x3c\x80")