This commit is contained in:
aler9
2022-05-23 21:15:50 +02:00
parent 206506a8f0
commit 7e8ec60aad
4 changed files with 132 additions and 7 deletions

4
go.mod
View File

@@ -7,7 +7,7 @@ require (
github.com/icza/bitio v1.0.0 github.com/icza/bitio v1.0.0
github.com/pion/rtcp v1.2.9 github.com/pion/rtcp v1.2.9
github.com/pion/rtp v1.7.9 github.com/pion/rtp v1.7.9
github.com/pion/sdp/v3 v3.0.2 github.com/pion/sdp/v3 v3.0.5
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.1
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b golang.org/x/net v0.0.0-20210610132358-84b48f89b13b
) )

8
go.sum
View File

@@ -14,16 +14,16 @@ github.com/pion/rtcp v1.2.9 h1:1ujStwg++IOLIEoOiIQ2s+qBuJ1VN81KW+9pMPsif+U=
github.com/pion/rtcp v1.2.9/go.mod h1:qVPhiCzAm4D/rxb6XzKeyZiQK69yJpbUDJSF7TgrqNo= github.com/pion/rtcp v1.2.9/go.mod h1:qVPhiCzAm4D/rxb6XzKeyZiQK69yJpbUDJSF7TgrqNo=
github.com/pion/rtp v1.7.9 h1:17W5Mt2IM3MVfOh7yRfzXbbKXYzBZxV8eG4KKAy+0bg= github.com/pion/rtp v1.7.9 h1:17W5Mt2IM3MVfOh7yRfzXbbKXYzBZxV8eG4KKAy+0bg=
github.com/pion/rtp v1.7.9/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= github.com/pion/rtp v1.7.9/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/sdp/v3 v3.0.2 h1:UNnSPVaMM+Pdu/mR9UvAyyo6zkdYbKeuOooCwZvTl/g= github.com/pion/sdp/v3 v3.0.5 h1:ouvI7IgGl+V4CrqskVtr3AaTrPvPisEOxwgpdktctkU=
github.com/pion/sdp/v3 v3.0.2/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk= github.com/pion/sdp/v3 v3.0.5/go.mod h1:iiFWFpQO8Fy3S5ldclBkpXqmWy02ns78NOKoLLL0YQw=
github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE= github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A=
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@@ -40,6 +40,15 @@ func indexOf(element string, data []string) int {
return -1 return -1
} }
func anyOf(element string, data ...string) bool {
for _, v := range data {
if element == v {
return true
}
}
return false
}
func parsePort(value string) (int, error) { func parsePort(value string) (int, error) {
port, err := strconv.Atoi(value) port, err := strconv.Atoi(value)
if err != nil { if err != nil {
@@ -212,9 +221,11 @@ func unmarshalBandwidth(value string) (*psdp.Bandwidth, error) {
experimental := strings.HasPrefix(parts[0], "X-") experimental := strings.HasPrefix(parts[0], "X-")
if experimental { if experimental {
parts[0] = strings.TrimPrefix(parts[0], "X-") parts[0] = strings.TrimPrefix(parts[0], "X-")
} else if i := indexOf(parts[0], []string{"CT", "AS", "RR", "RS"}); i == -1 { } else if !anyOf(parts[0], "CT", "AS", "TIAS", "RS", "RR") {
// Set according to currently registered with IANA // Set according to currently registered with IANA
// https://tools.ietf.org/html/rfc4566#section-5.8 // https://tools.ietf.org/html/rfc4566#section-5.8
// https://tools.ietf.org/html/rfc3890#section-6.2
// https://tools.ietf.org/html/rfc3556#section-2
return nil, fmt.Errorf("%w `%v`", errSDPInvalidValue, parts[0]) return nil, fmt.Errorf("%w `%v`", errSDPInvalidValue, parts[0])
} }

View File

@@ -1524,6 +1524,120 @@ var cases = []struct {
}, },
}, },
}, },
{
"tias",
[]byte("v=0\r\n" +
"o=- 1681692777 1681692777 IN IP4 127.0.0.1\r\n" +
"s=Video Stream\r\n" +
"c=IN IP4 127.0.0.1\r\n" +
"t=0 0\r\n" +
"a=control:*\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"b=TIAS:10000\r\n" +
"a=maxprate:2.0000\r\n" +
"a=control:trackid=1\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=mimetype:string;\"video/H264\"\r\n" +
"a=framesize:96 384-832\r\n" +
"a=Width:integer;384\r\n" +
"a=Height:integer;832\r\n" +
"a=fmtp:96 packetization-mode=1;profile-level-id=64001f;sprop-parameter-sets=J2QAH6xWwYBp+kA=,KO48sA==\r\n"),
[]byte("v=0\r\n" +
"o=- 1681692777 1681692777 IN IP4 127.0.0.1\r\n" +
"s=Video Stream\r\n" +
"c=IN IP4 127.0.0.1\r\n" +
"t=0 0\r\n" +
"a=control:*\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"b=TIAS:10000\r\n" +
"a=maxprate:2.0000\r\n" +
"a=control:trackid=1\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=mimetype:string;\"video/H264\"\r\n" +
"a=framesize:96 384-832\r\n" +
"a=Width:integer;384\r\n" +
"a=Height:integer;832\r\n" +
"a=fmtp:96 packetization-mode=1;profile-level-id=64001f;sprop-parameter-sets=J2QAH6xWwYBp+kA=,KO48sA==\r\n"),
SessionDescription{
Origin: psdp.Origin{
Username: "-",
SessionID: 1681692777,
SessionVersion: 1681692777,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "127.0.0.1",
},
SessionName: "Video Stream",
ConnectionInformation: &psdp.ConnectionInformation{
NetworkType: "IN",
AddressType: "IP4",
Address: &psdp.Address{
Address: "127.0.0.1",
},
},
TimeDescriptions: []psdp.TimeDescription{
{},
},
Attributes: []psdp.Attribute{
{
Key: "control",
Value: "*",
},
},
MediaDescriptions: []*psdp.MediaDescription{
{
MediaName: psdp.MediaName{
Media: "video",
Port: psdp.RangedPort{
Value: 0,
},
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Bandwidth: []psdp.Bandwidth{
{
Type: "TIAS",
Bandwidth: 10000,
},
},
Attributes: []psdp.Attribute{
{
Key: "maxprate",
Value: "2.0000",
},
{
Key: "control",
Value: "trackid=1",
},
{
Key: "rtpmap",
Value: "96 H264/90000",
},
{
Key: "mimetype",
Value: "string;\"video/H264\"",
},
{
Key: "framesize",
Value: "96 384-832",
},
{
Key: "Width",
Value: "integer;384",
},
{
Key: "Height",
Value: "integer;832",
},
{
Key: "fmtp",
Value: "96 packetization-mode=1;profile-level-id=64001f;sprop-parameter-sets=J2QAH6xWwYBp+kA=,KO48sA==",
},
},
},
},
},
},
} }
func TestUnmarshal(t *testing.T) { func TestUnmarshal(t *testing.T) {