From bd4fc1ae8c1dd5a11e8f003852c3135ea972f140 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 27 Sep 2020 15:52:48 +0200 Subject: [PATCH] update gortsplib --- README.md | 2 +- client.go | 16 ++++++++-------- go.mod | 2 +- go.sum | 7 +++++-- proxy.go | 32 +++++++++++++------------------- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 3aeeaf31..73702cf9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ _rtsp-simple-server_ is a simple, ready-to-use and zero-dependency RTSP server and RTSP proxy, a software that allows multiple users to publish and read live video and audio streams over time. RTSP, RTP and RTCP are standardized protocol that describe how to perform these operations with the help of a server, that is contacted by both readers and publishers in order to negotiate a streaming protocol. The server is then responsible of relaying the publisher streams to the readers. Features: -* Read and publish live streams via UDP and TCP +* Read and publish live streams with UDP and TCP * Each stream can have multiple video and audio tracks, encoded in any format * Publish multiple streams at once, each in a separate path, that can be read by multiple users * Pull and serve streams from other RTSP servers, always or on-demand (RTSP proxy) diff --git a/client.go b/client.go index 031ca0fb..a0ca4f0c 100644 --- a/client.go +++ b/client.go @@ -513,7 +513,7 @@ func (c *client) handleRequest(req *gortsplib.Request) error { return errRunTerminate } - // play via UDP + // play with UDP if th.Protocol == gortsplib.StreamProtocolUDP { if _, ok := c.p.conf.protocolsParsed[gortsplib.StreamProtocolUDP]; !ok { c.writeResError(cseq, gortsplib.StatusUnsupportedTransport, fmt.Errorf("UDP streaming is disabled")) @@ -564,7 +564,7 @@ func (c *client) handleRequest(req *gortsplib.Request) error { }) return nil - // play via TCP + // play with TCP } else { if _, ok := c.p.conf.protocolsParsed[gortsplib.StreamProtocolTCP]; !ok { c.writeResError(cseq, gortsplib.StatusUnsupportedTransport, fmt.Errorf("TCP streaming is disabled")) @@ -621,7 +621,7 @@ func (c *client) handleRequest(req *gortsplib.Request) error { return errRunTerminate } - // record via UDP + // record with UDP if th.Protocol == gortsplib.StreamProtocolUDP { if _, ok := c.p.conf.protocolsParsed[gortsplib.StreamProtocolUDP]; !ok { c.writeResError(cseq, gortsplib.StatusUnsupportedTransport, fmt.Errorf("UDP streaming is disabled")) @@ -669,7 +669,7 @@ func (c *client) handleRequest(req *gortsplib.Request) error { }) return nil - // record via TCP + // record with TCP } else { if _, ok := c.p.conf.protocolsParsed[gortsplib.StreamProtocolTCP]; !ok { c.writeResError(cseq, gortsplib.StatusUnsupportedTransport, fmt.Errorf("TCP streaming is disabled")) @@ -878,7 +878,7 @@ func (c *client) runPlay() bool { // start sending frames only after sending the response to the PLAY request c.p.clientPlay <- c - c.log("is receiving on path '%s', %d %s via %s", c.path.name, len(c.streamTracks), func() string { + c.log("is receiving on path '%s', %d %s with %s", c.path.name, len(c.streamTracks), func() string { if len(c.streamTracks) == 1 { return "track" } @@ -991,7 +991,7 @@ func (c *client) runPlayTCP() { return case frame := <-c.tcpFrame: - c.conn.WriteFrame(frame) + c.conn.WriteFrameTCP(frame) case <-c.terminate: go func() { @@ -1022,7 +1022,7 @@ func (c *client) runRecord() bool { c.p.clientRecord <- c - c.log("is publishing on path '%s', %d %s via %s", c.path.name, len(c.streamTracks), func() string { + c.log("is publishing on path '%s', %d %s with %s", c.path.name, len(c.streamTracks), func() string { if len(c.streamTracks) == 1 { return "track" } @@ -1194,7 +1194,7 @@ func (c *client) runRecordTCP() { case <-receiverReportTicker.C: for trackId := range c.streamTracks { frame := c.rtcpReceivers[trackId].Report() - c.conn.WriteFrame(&gortsplib.InterleavedFrame{ + c.conn.WriteFrameTCP(&gortsplib.InterleavedFrame{ TrackId: trackId, StreamType: gortsplib.StreamTypeRtcp, Content: frame, diff --git a/go.mod b/go.mod index c38dfe43..aace4b38 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.12 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-20200920125203-e34b7d932695 + github.com/aler9/gortsplib v0.0.0-20200927133547-0a70915c8c0a github.com/davecgh/go-spew v1.1.1 // indirect github.com/stretchr/testify v1.6.1 gopkg.in/alecthomas/kingpin.v2 v2.2.6 diff --git a/go.sum b/go.sum index 31786e8f..17f30503 100644 --- a/go.sum +++ b/go.sum @@ -2,18 +2,21 @@ 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-20200920125203-e34b7d932695 h1:3b6hZXRGPbdCX6YhJAD0UhUvSD+8xGWiMHU618MrJUY= -github.com/aler9/gortsplib v0.0.0-20200920125203-e34b7d932695/go.mod h1:IQy51zikcH4wQFNwYPHtC0+HTcPlahJcxcYiMqlCyiw= +github.com/aler9/gortsplib v0.0.0-20200927133547-0a70915c8c0a h1:s69UQblZtmygP9uYMS3ZOjQjsNhRExk+EFuJMT1S3h8= +github.com/aler9/gortsplib v0.0.0-20200927133547-0a70915c8c0a/go.mod h1:QjIqmMY0GHQ2Wan9jIS1amsNn0ncDnufvWD/r5IkDQI= github.com/aler9/sdp-dirty/v3 v3.0.0-20200919115950-f1abc664f625 h1:A3upkpYzceQTuBPvVleu1zd6R8jInhg5ifimSO7ku/o= github.com/aler9/sdp-dirty/v3 v3.0.0-20200919115950-f1abc664f625/go.mod h1:5bO/aUQr9m3OasDatNNcVqKAgs7r5hgGXmszWHaC6mI= 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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pion/randutil v0.0.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/rtcp v1.2.3 h1:2wrhKnqgSz91Q5nzYTO07mQXztYPtxL8a0XOss4rJqA= github.com/pion/rtcp v1.2.3/go.mod h1:zGhIv0RPRF0Z1Wiij22pUt5W/c9fevqSzT4jje/oK7I= +github.com/pion/rtp v1.6.0 h1:4Ssnl/T5W2LzxHj9ssYpGVEQh3YYhQFNVmSWO88MMwk= +github.com/pion/rtp v1.6.0/go.mod h1:QgfogHsMBVE/RFNno467U/KBqfUywEH+HK+0rtnwsdI= 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= diff --git a/proxy.go b/proxy.go index 2dcf3f8c..dc634481 100644 --- a/proxy.go +++ b/proxy.go @@ -183,19 +183,13 @@ func (s *proxy) runInnerInner() bool { } func (s *proxy) runUDP(conn *gortsplib.ConnClient) bool { - var rtpReads []gortsplib.UDPReadFunc - var rtcpReads []gortsplib.UDPReadFunc - for _, track := range s.tracks { - rtpRead, rtcpRead, _, err := conn.SetupUDP(s.pathConf.sourceUrl, track, 0, 0) + _, err := conn.SetupUDP(s.pathConf.sourceUrl, gortsplib.SetupModePlay, track, 0, 0) if err != nil { conn.Close() s.path.log("proxy ERR: %s", err) return true } - - rtpReads = append(rtpReads, rtpRead) - rtcpReads = append(rtcpReads, rtcpRead) } _, err := conn.Play(s.pathConf.sourceUrl) @@ -210,39 +204,39 @@ func (s *proxy) runUDP(conn *gortsplib.ConnClient) bool { var wg sync.WaitGroup // receive RTP packets - for trackId, rtpRead := range rtpReads { + for _, track := range s.tracks { wg.Add(1) - go func(trackId int, rtpRead gortsplib.UDPReadFunc) { + go func(track *gortsplib.Track) { defer wg.Done() for { - buf, err := rtpRead() + buf, err := conn.ReadFrameUDP(track, gortsplib.StreamTypeRtp) if err != nil { break } - s.p.readersMap.forwardFrame(s.path, trackId, + s.p.readersMap.forwardFrame(s.path, track.Id, gortsplib.StreamTypeRtp, buf) } - }(trackId, rtpRead) + }(track) } // receive RTCP packets - for trackId, rtcpRead := range rtcpReads { + for _, track := range s.tracks { wg.Add(1) - go func(trackId int, rtcpRead gortsplib.UDPReadFunc) { + go func(track *gortsplib.Track) { defer wg.Done() for { - buf, err := rtcpRead() + buf, err := conn.ReadFrameUDP(track, gortsplib.StreamTypeRtcp) if err != nil { break } - s.p.readersMap.forwardFrame(s.path, trackId, + s.p.readersMap.forwardFrame(s.path, track.Id, gortsplib.StreamTypeRtcp, buf) } - }(trackId, rtcpRead) + }(track) } tcpConnDone := make(chan error) @@ -278,7 +272,7 @@ outer: func (s *proxy) runTCP(conn *gortsplib.ConnClient) bool { for _, track := range s.tracks { - _, err := conn.SetupTCP(s.pathConf.sourceUrl, track) + _, err := conn.SetupTCP(s.pathConf.sourceUrl, gortsplib.SetupModePlay, track) if err != nil { conn.Close() s.path.log("proxy ERR: %s", err) @@ -298,7 +292,7 @@ func (s *proxy) runTCP(conn *gortsplib.ConnClient) bool { tcpConnDone := make(chan error) go func() { for { - frame, err := conn.ReadFrame() + frame, err := conn.ReadFrameTCP() if err != nil { tcpConnDone <- err return