Browse Source

update gortsplib

pull/169/head
aler9 5 years ago
parent
commit
286d837d9e
  1. 2
      go.mod
  2. 4
      go.sum
  3. 22
      internal/client/client.go
  4. 5
      internal/clientman/clientman.go
  5. 39
      internal/servertcp/server.go
  6. 4
      internal/sourcertsp/source.go
  7. 10
      main.go

2
go.mod

@ -5,7 +5,7 @@ go 1.15
require ( require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20201205174405-71861bd1325c github.com/aler9/gortsplib v0.0.0-20201206165643-b4c183ad2a83
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51

4
go.sum

@ -2,8 +2,8 @@ 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/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 h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20201205174405-71861bd1325c h1:LMCNoh4s3NnExhrZRFtrOyrUzaCLBTgg68uDBr76bQo= github.com/aler9/gortsplib v0.0.0-20201206165643-b4c183ad2a83 h1:lvG6NoQeNYlqcRIt0ZBrthNqaMh6Xevc60fgQ7f6mvA=
github.com/aler9/gortsplib v0.0.0-20201205174405-71861bd1325c/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I= github.com/aler9/gortsplib v0.0.0-20201206165643-b4c183ad2a83/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

22
internal/client/client.go

@ -106,7 +106,7 @@ type Client struct {
stats *stats.Stats stats *stats.Stats
serverUDPRtp *serverudp.Server serverUDPRtp *serverudp.Server
serverUDPRtcp *serverudp.Server serverUDPRtcp *serverudp.Server
conn *gortsplib.ConnServer conn *gortsplib.ServerConn
parent Parent parent Parent
state state state state
@ -133,7 +133,6 @@ type Client struct {
func New( func New(
rtspPort int, rtspPort int,
readTimeout time.Duration, readTimeout time.Duration,
writeTimeout time.Duration,
runOnConnect string, runOnConnect string,
runOnConnectRestart bool, runOnConnectRestart bool,
protocols map[gortsplib.StreamProtocol]struct{}, protocols map[gortsplib.StreamProtocol]struct{},
@ -141,7 +140,7 @@ func New(
stats *stats.Stats, stats *stats.Stats,
serverUDPRtp *serverudp.Server, serverUDPRtp *serverudp.Server,
serverUDPRtcp *serverudp.Server, serverUDPRtcp *serverudp.Server,
nconn net.Conn, conn *gortsplib.ServerConn,
parent Parent) *Client { parent Parent) *Client {
c := &Client{ c := &Client{
@ -154,17 +153,12 @@ func New(
stats: stats, stats: stats,
serverUDPRtp: serverUDPRtp, serverUDPRtp: serverUDPRtp,
serverUDPRtcp: serverUDPRtcp, serverUDPRtcp: serverUDPRtcp,
conn: gortsplib.NewConnServer(gortsplib.ConnServerConf{ conn: conn,
Conn: nconn, parent: parent,
ReadTimeout: readTimeout, state: stateInitial,
WriteTimeout: writeTimeout, streamTracks: make(map[int]*streamTrack),
ReadBufferCount: 1, rtcpReceivers: make(map[int]*rtcpreceiver.RtcpReceiver),
}), terminate: make(chan struct{}),
parent: parent,
state: stateInitial,
streamTracks: make(map[int]*streamTrack),
rtcpReceivers: make(map[int]*rtcpreceiver.RtcpReceiver),
terminate: make(chan struct{}),
} }
atomic.AddInt64(c.stats.CountClients, 1) atomic.AddInt64(c.stats.CountClients, 1)

5
internal/clientman/clientman.go

@ -23,7 +23,6 @@ type Parent interface {
type ClientManager struct { type ClientManager struct {
rtspPort int rtspPort int
readTimeout time.Duration readTimeout time.Duration
writeTimeout time.Duration
runOnConnect string runOnConnect string
runOnConnectRestart bool runOnConnectRestart bool
protocols map[base.StreamProtocol]struct{} protocols map[base.StreamProtocol]struct{}
@ -49,7 +48,6 @@ type ClientManager struct {
func New( func New(
rtspPort int, rtspPort int,
readTimeout time.Duration, readTimeout time.Duration,
writeTimeout time.Duration,
runOnConnect string, runOnConnect string,
runOnConnectRestart bool, runOnConnectRestart bool,
protocols map[base.StreamProtocol]struct{}, protocols map[base.StreamProtocol]struct{},
@ -63,7 +61,6 @@ func New(
cm := &ClientManager{ cm := &ClientManager{
rtspPort: rtspPort, rtspPort: rtspPort,
readTimeout: readTimeout, readTimeout: readTimeout,
writeTimeout: writeTimeout,
runOnConnect: runOnConnect, runOnConnect: runOnConnect,
runOnConnectRestart: runOnConnectRestart, runOnConnectRestart: runOnConnectRestart,
protocols: protocols, protocols: protocols,
@ -101,7 +98,7 @@ outer:
for { for {
select { select {
case conn := <-cm.serverTCP.Accept(): case conn := <-cm.serverTCP.Accept():
c := client.New(cm.rtspPort, cm.readTimeout, cm.writeTimeout, c := client.New(cm.rtspPort, cm.readTimeout,
cm.runOnConnect, cm.runOnConnectRestart, cm.protocols, &cm.wg, cm.runOnConnect, cm.runOnConnectRestart, cm.protocols, &cm.wg,
cm.stats, cm.serverUDPRtp, cm.serverUDPRtcp, conn, cm) cm.stats, cm.serverUDPRtp, cm.serverUDPRtcp, conn, cm)
cm.clients[c] = struct{}{} cm.clients[c] = struct{}{}

39
internal/servertcp/server.go

@ -1,7 +1,10 @@
package servertcp package servertcp
import ( import (
"net" "strconv"
"time"
"github.com/aler9/gortsplib"
) )
// Parent is implemented by program. // Parent is implemented by program.
@ -13,27 +16,35 @@ type Parent interface {
type Server struct { type Server struct {
parent Parent parent Parent
listener *net.TCPListener srv *gortsplib.Server
// out // out
accept chan net.Conn accept chan *gortsplib.ServerConn
done chan struct{} done chan struct{}
} }
// New allocates a Server. // New allocates a Server.
func New(port int, parent Parent) (*Server, error) { func New(port int,
listener, err := net.ListenTCP("tcp", &net.TCPAddr{ readTimeout time.Duration,
Port: port, writeTimeout time.Duration,
}) parent Parent) (*Server, error) {
conf := gortsplib.ServerConf{
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
ReadBufferCount: 1,
}
srv, err := conf.Serve(":"+strconv.FormatInt(int64(port), 10), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
s := &Server{ s := &Server{
parent: parent, parent: parent,
listener: listener, srv: srv,
accept: make(chan net.Conn), accept: make(chan *gortsplib.ServerConn),
done: make(chan struct{}), done: make(chan struct{}),
} }
parent.Log("[TCP server] opened on :%d", port) parent.Log("[TCP server] opened on :%d", port)
@ -49,7 +60,7 @@ func (s *Server) Close() {
co.Close() co.Close()
} }
}() }()
s.listener.Close() s.srv.Close()
<-s.done <-s.done
} }
@ -57,7 +68,7 @@ func (s *Server) run() {
defer close(s.done) defer close(s.done)
for { for {
conn, err := s.listener.AcceptTCP() conn, err := s.srv.Accept()
if err != nil { if err != nil {
break break
} }
@ -69,6 +80,6 @@ func (s *Server) run() {
} }
// Accept returns a channel to accept incoming connections. // Accept returns a channel to accept incoming connections.
func (s *Server) Accept() <-chan net.Conn { func (s *Server) Accept() <-chan *gortsplib.ServerConn {
return s.accept return s.accept
} }

4
internal/sourcertsp/source.go

@ -105,13 +105,13 @@ func (s *Source) run() {
func (s *Source) runInner() bool { func (s *Source) runInner() bool {
s.parent.Log("connecting to rtsp source") s.parent.Log("connecting to rtsp source")
var conn *gortsplib.ConnClient var conn *gortsplib.ClientConn
var err error var err error
dialDone := make(chan struct{}, 1) dialDone := make(chan struct{}, 1)
go func() { go func() {
defer close(dialDone) defer close(dialDone)
dialer := gortsplib.Dialer{ dialer := gortsplib.ClientConf{
StreamProtocol: s.proto, StreamProtocol: s.proto,
ReadTimeout: s.readTimeout, ReadTimeout: s.readTimeout,
WriteTimeout: s.writeTimeout, WriteTimeout: s.writeTimeout,

10
main.go

@ -175,7 +175,8 @@ func (p *program) createDynamicResources(initial bool) error {
} }
if p.serverTCP == nil { if p.serverTCP == nil {
p.serverTCP, err = servertcp.New(p.conf.RtspPort, p) p.serverTCP, err = servertcp.New(p.conf.RtspPort, p.conf.ReadTimeout,
p.conf.WriteTimeout, p)
if err != nil { if err != nil {
return err return err
} }
@ -189,7 +190,7 @@ func (p *program) createDynamicResources(initial bool) error {
if p.clientMan == nil { if p.clientMan == nil {
p.clientMan = clientman.New(p.conf.RtspPort, p.conf.ReadTimeout, p.clientMan = clientman.New(p.conf.RtspPort, p.conf.ReadTimeout,
p.conf.WriteTimeout, p.conf.RunOnConnect, p.conf.RunOnConnectRestart, p.conf.RunOnConnect, p.conf.RunOnConnectRestart,
p.conf.ProtocolsParsed, p.stats, p.serverUDPRtp, p.serverUDPRtcp, p.conf.ProtocolsParsed, p.stats, p.serverUDPRtp, p.serverUDPRtcp,
p.pathMan, p.serverTCP, p) p.pathMan, p.serverTCP, p)
} }
@ -274,7 +275,9 @@ func (p *program) reloadConf() error {
} }
closeServerTCP := false closeServerTCP := false
if conf.RtspPort != p.conf.RtspPort { if conf.RtspPort != p.conf.RtspPort ||
conf.ReadTimeout != p.conf.ReadTimeout ||
conf.WriteTimeout != p.conf.WriteTimeout {
closeServerTCP = true closeServerTCP = true
} }
@ -295,7 +298,6 @@ func (p *program) reloadConf() error {
closePathMan || closePathMan ||
conf.RtspPort != p.conf.RtspPort || conf.RtspPort != p.conf.RtspPort ||
conf.ReadTimeout != p.conf.ReadTimeout || conf.ReadTimeout != p.conf.ReadTimeout ||
conf.WriteTimeout != p.conf.WriteTimeout ||
conf.RunOnConnect != p.conf.RunOnConnect || conf.RunOnConnect != p.conf.RunOnConnect ||
conf.RunOnConnectRestart != p.conf.RunOnConnectRestart || conf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
!reflect.DeepEqual(conf.ProtocolsParsed, p.conf.ProtocolsParsed) { !reflect.DeepEqual(conf.ProtocolsParsed, p.conf.ProtocolsParsed) {

Loading…
Cancel
Save