diff --git a/go.mod b/go.mod index f1436a2e..45b6a74f 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/icza/bitio v1.0.0 github.com/pion/rtcp v1.2.9 github.com/pion/rtp v1.7.9 - github.com/pion/sdp/v3 v3.0.2 - github.com/stretchr/testify v1.7.0 + github.com/pion/sdp/v3 v3.0.5 + github.com/stretchr/testify v1.7.1 golang.org/x/net v0.0.0-20210610132358-84b48f89b13b ) diff --git a/go.sum b/go.sum index 578aca7d..6c3e2c2c 100644 --- a/go.sum +++ b/go.sum @@ -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/rtp v1.7.9 h1:17W5Mt2IM3MVfOh7yRfzXbbKXYzBZxV8eG4KKAy+0bg= 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.2/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk= +github.com/pion/sdp/v3 v3.0.5 h1:ouvI7IgGl+V4CrqskVtr3AaTrPvPisEOxwgpdktctkU= +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/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.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/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/pkg/sdp/sdp.go b/pkg/sdp/sdp.go index 7b2afad9..866f72e3 100644 --- a/pkg/sdp/sdp.go +++ b/pkg/sdp/sdp.go @@ -40,6 +40,15 @@ func indexOf(element string, data []string) int { 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) { port, err := strconv.Atoi(value) if err != nil { @@ -212,9 +221,11 @@ func unmarshalBandwidth(value string) (*psdp.Bandwidth, error) { experimental := strings.HasPrefix(parts[0], "X-") if experimental { 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 // 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]) } diff --git a/pkg/sdp/sdp_test.go b/pkg/sdp/sdp_test.go index b83c3bdc..94eb5c32 100644 --- a/pkg/sdp/sdp_test.go +++ b/pkg/sdp/sdp_test.go @@ -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) {