move sdp functions into gortsplib
This commit is contained in:
parent
a532430396
commit
a4d581d02e
4
go.mod
4
go.mod
|
@ -5,8 +5,8 @@ go 1.13
|
|||
require (
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
|
||||
github.com/aler9/gortsplib v0.0.0-20200517142010-db3770c8f3a0
|
||||
github.com/aler9/gortsplib v0.0.0-20200517144705-37bd9a1b98ce
|
||||
github.com/stretchr/testify v1.4.0
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||
gortc.io/sdp v0.17.0
|
||||
gortc.io/sdp v0.18.2
|
||||
)
|
||||
|
|
12
go.sum
12
go.sum
|
@ -2,12 +2,12 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
|
|||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/aler9/gortsplib v0.0.0-20200517142010-db3770c8f3a0 h1:/v4nyRb/wrhEkx+oKL4iDelWzYVJfcX4oa2MG0Yo9pc=
|
||||
github.com/aler9/gortsplib v0.0.0-20200517142010-db3770c8f3a0/go.mod h1:YiIgmmv0ELkWUy11Jj2h5AgfqLCpy8sIX/l9MmS8+uw=
|
||||
github.com/aler9/gortsplib v0.0.0-20200517144705-37bd9a1b98ce h1:YBes3GDLTF/UonS+v9s478lfCqg6HGRAaaiR9iMtygc=
|
||||
github.com/aler9/gortsplib v0.0.0-20200517144705-37bd9a1b98ce/go.mod h1:sL64nUkmrTVhlT/GCaxRXyI2Xk7m8XSdw5Uv8xKGPdc=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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 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=
|
||||
|
@ -19,5 +19,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gortc.io/sdp v0.17.0 h1:gPmGXqyszHplnlMeF2X0eCOK+G8aAK4PP6puglIcofc=
|
||||
gortc.io/sdp v0.17.0/go.mod h1:iwG4LtzGX1MLglrl5x7AL7cfLndFPMfJ02koQl5KIgE=
|
||||
gortc.io/sdp v0.18.2 h1:w2L1h9rgMZwGQz/bYMxTQ36POQ114ETpYUX1pFfSsLg=
|
||||
gortc.io/sdp v0.18.2/go.mod h1:Oj8tpRIx+Zx6lyrQR9+HHegByfbaz92A9wPSWrQhTI4=
|
||||
|
|
|
@ -7,81 +7,12 @@ import (
|
|||
"log"
|
||||
"net"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
"gortc.io/sdp"
|
||||
)
|
||||
|
||||
func sdpParse(in []byte) (*sdp.Message, error) {
|
||||
s, err := sdp.DecodeSession(in, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := &sdp.Message{}
|
||||
d := sdp.NewDecoder(s)
|
||||
err = d.Decode(m)
|
||||
if err != nil {
|
||||
// allow empty Origins
|
||||
if err.Error() != "failed to decode message: DecodeError in section s: origin address not set" {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if len(m.Medias) == 0 {
|
||||
return nil, fmt.Errorf("no tracks defined in SDP")
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// remove everything from SDP except the bare minimum
|
||||
func sdpFilter(msgIn *sdp.Message, byteIn []byte) (*sdp.Message, []byte) {
|
||||
msgOut := &sdp.Message{}
|
||||
|
||||
msgOut.Name = "Stream"
|
||||
msgOut.Origin = sdp.Origin{
|
||||
Username: "-",
|
||||
NetworkType: "IN",
|
||||
AddressType: "IP4",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
|
||||
for i, m := range msgIn.Medias {
|
||||
var attributes []sdp.Attribute
|
||||
for _, attr := range m.Attributes {
|
||||
if attr.Key == "rtpmap" || attr.Key == "fmtp" {
|
||||
attributes = append(attributes, attr)
|
||||
}
|
||||
}
|
||||
|
||||
// control attribute is mandatory, and is the path that is appended
|
||||
// to the stream path in SETUP
|
||||
attributes = append(attributes, sdp.Attribute{
|
||||
Key: "control",
|
||||
Value: "trackID=" + strconv.FormatInt(int64(i), 10),
|
||||
})
|
||||
|
||||
msgOut.Medias = append(msgOut.Medias, sdp.Media{
|
||||
Bandwidths: m.Bandwidths,
|
||||
Description: sdp.MediaDescription{
|
||||
Type: m.Description.Type,
|
||||
Protocol: "RTP/AVP", // override protocol
|
||||
Formats: m.Description.Formats,
|
||||
},
|
||||
Attributes: attributes,
|
||||
})
|
||||
}
|
||||
|
||||
sdps := sdp.Session{}
|
||||
sdps = msgOut.Append(sdps)
|
||||
byteOut := sdps.AppendTo(nil)
|
||||
|
||||
return msgOut, byteOut
|
||||
}
|
||||
|
||||
func interleavedChannelToTrack(channel uint8) (int, trackFlow) {
|
||||
if (channel % 2) == 0 {
|
||||
return int(channel / 2), _TRACK_FLOW_RTP
|
||||
|
@ -396,13 +327,13 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
sdpParsed, err := sdpParse(req.Content)
|
||||
sdpParsed, err := gortsplib.SDPParse(req.Content)
|
||||
if err != nil {
|
||||
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("invalid SDP: %s", err))
|
||||
return false
|
||||
}
|
||||
|
||||
sdpParsed, req.Content = sdpFilter(sdpParsed, req.Content)
|
||||
sdpParsed, req.Content = gortsplib.SDPFilter(sdpParsed, req.Content)
|
||||
|
||||
err = func() error {
|
||||
c.p.tcpl.mutex.Lock()
|
||||
|
|
Loading…
Reference in New Issue