diff --git a/go.mod b/go.mod index 070f63c..832903a 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,8 @@ require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pion/sdp v1.3.0 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect diff --git a/go.sum b/go.sum index 84f5961..4b89822 100644 --- a/go.sum +++ b/go.sum @@ -47,6 +47,9 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pion/sdp v1.3.0 h1:21lpgEILHyolpsIrbCBagZaAPj4o057cFjzaFebkVOs= +github.com/pion/sdp v1.3.0/go.mod h1:ceA2lTyftydQTuCIbUNoH77aAt6CiQJaRpssA4Gee8I= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= diff --git a/test/sdp_test.go b/test/sdp_test.go new file mode 100644 index 0000000..5010508 --- /dev/null +++ b/test/sdp_test.go @@ -0,0 +1,53 @@ +package test + +import ( + "github.com/pion/sdp" + "io" + "regexp" + "strings" + "testing" +) + +func TestSDP(t *testing.T) { + req := `v=0 +o=00000000000000000002 0 0 IN IP4 10.10.10.200 +s=Play +c=IN IP4 10.10.10.200 +t=0 0 +m=video 5080 RTP/AVP 99 125 126 96 97 98 +a=recvonly +a=rtpmap:99 H265/90000 +a=fmtp:125 profile-level-id=42e01e +a=rtpmap:125 H264S/90000 +a=fmtp:126 profile-level-id=42e01e +a=rtpmap:126 H264/90000 +a=rtpmap:96 PS/90000 +a=rtpmap:97 MPEG4/90000 +a=rtpmap:98 H264/90000 +a=setup:active +a=connection:new +a=streamnumber:0 +y=501000001 +f= +` + // 匹配 28181 协议的 ssrc + ssrcReg := regexp.MustCompile("y=(.*)") + matchSsrc := ssrcReg.FindStringSubmatch(req) + ssrc := matchSsrc[1] + t.Log("y= ", ssrc) + req = strings.Replace(req, matchSsrc[0], "", 1) + + // 匹配 28181 协议的 format + formatReg := regexp.MustCompile("f=(.*)") + matchFormat := formatReg.FindStringSubmatch(req) + format := matchFormat[1] + t.Log("f= ", format) + req = strings.Replace(req, matchFormat[0], "", 1) + + session := &sdp.SessionDescription{} + err := session.Unmarshal(req) + if err != nil && err != io.EOF { + t.Error(err) + } + t.Logf("%#v\n", session) +}