mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-12-24 11:51:18 +08:00
update gortsplib
This commit is contained in:
2
go.mod
2
go.mod
@@ -5,7 +5,7 @@ go 1.15
|
||||
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-20201205174405-71861bd1325c
|
||||
github.com/aler9/gortsplib v0.0.0-20201206165643-b4c183ad2a83
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.4.9
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
|
||||
4
go.sum
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/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-20201205174405-71861bd1325c h1:LMCNoh4s3NnExhrZRFtrOyrUzaCLBTgg68uDBr76bQo=
|
||||
github.com/aler9/gortsplib v0.0.0-20201205174405-71861bd1325c/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I=
|
||||
github.com/aler9/gortsplib v0.0.0-20201206165643-b4c183ad2a83 h1:lvG6NoQeNYlqcRIt0ZBrthNqaMh6Xevc60fgQ7f6mvA=
|
||||
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
||||
@@ -106,7 +106,7 @@ type Client struct {
|
||||
stats *stats.Stats
|
||||
serverUDPRtp *serverudp.Server
|
||||
serverUDPRtcp *serverudp.Server
|
||||
conn *gortsplib.ConnServer
|
||||
conn *gortsplib.ServerConn
|
||||
parent Parent
|
||||
|
||||
state state
|
||||
@@ -133,7 +133,6 @@ type Client struct {
|
||||
func New(
|
||||
rtspPort int,
|
||||
readTimeout time.Duration,
|
||||
writeTimeout time.Duration,
|
||||
runOnConnect string,
|
||||
runOnConnectRestart bool,
|
||||
protocols map[gortsplib.StreamProtocol]struct{},
|
||||
@@ -141,7 +140,7 @@ func New(
|
||||
stats *stats.Stats,
|
||||
serverUDPRtp *serverudp.Server,
|
||||
serverUDPRtcp *serverudp.Server,
|
||||
nconn net.Conn,
|
||||
conn *gortsplib.ServerConn,
|
||||
parent Parent) *Client {
|
||||
|
||||
c := &Client{
|
||||
@@ -154,17 +153,12 @@ func New(
|
||||
stats: stats,
|
||||
serverUDPRtp: serverUDPRtp,
|
||||
serverUDPRtcp: serverUDPRtcp,
|
||||
conn: gortsplib.NewConnServer(gortsplib.ConnServerConf{
|
||||
Conn: nconn,
|
||||
ReadTimeout: readTimeout,
|
||||
WriteTimeout: writeTimeout,
|
||||
ReadBufferCount: 1,
|
||||
}),
|
||||
parent: parent,
|
||||
state: stateInitial,
|
||||
streamTracks: make(map[int]*streamTrack),
|
||||
rtcpReceivers: make(map[int]*rtcpreceiver.RtcpReceiver),
|
||||
terminate: make(chan struct{}),
|
||||
conn: conn,
|
||||
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)
|
||||
|
||||
@@ -23,7 +23,6 @@ type Parent interface {
|
||||
type ClientManager struct {
|
||||
rtspPort int
|
||||
readTimeout time.Duration
|
||||
writeTimeout time.Duration
|
||||
runOnConnect string
|
||||
runOnConnectRestart bool
|
||||
protocols map[base.StreamProtocol]struct{}
|
||||
@@ -49,7 +48,6 @@ type ClientManager struct {
|
||||
func New(
|
||||
rtspPort int,
|
||||
readTimeout time.Duration,
|
||||
writeTimeout time.Duration,
|
||||
runOnConnect string,
|
||||
runOnConnectRestart bool,
|
||||
protocols map[base.StreamProtocol]struct{},
|
||||
@@ -63,7 +61,6 @@ func New(
|
||||
cm := &ClientManager{
|
||||
rtspPort: rtspPort,
|
||||
readTimeout: readTimeout,
|
||||
writeTimeout: writeTimeout,
|
||||
runOnConnect: runOnConnect,
|
||||
runOnConnectRestart: runOnConnectRestart,
|
||||
protocols: protocols,
|
||||
@@ -101,7 +98,7 @@ outer:
|
||||
for {
|
||||
select {
|
||||
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.stats, cm.serverUDPRtp, cm.serverUDPRtcp, conn, cm)
|
||||
cm.clients[c] = struct{}{}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package servertcp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/aler9/gortsplib"
|
||||
)
|
||||
|
||||
// Parent is implemented by program.
|
||||
@@ -13,27 +16,35 @@ type Parent interface {
|
||||
type Server struct {
|
||||
parent Parent
|
||||
|
||||
listener *net.TCPListener
|
||||
srv *gortsplib.Server
|
||||
|
||||
// out
|
||||
accept chan net.Conn
|
||||
accept chan *gortsplib.ServerConn
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
// New allocates a Server.
|
||||
func New(port int, parent Parent) (*Server, error) {
|
||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||
Port: port,
|
||||
})
|
||||
func New(port int,
|
||||
readTimeout time.Duration,
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &Server{
|
||||
parent: parent,
|
||||
listener: listener,
|
||||
accept: make(chan net.Conn),
|
||||
done: make(chan struct{}),
|
||||
parent: parent,
|
||||
srv: srv,
|
||||
accept: make(chan *gortsplib.ServerConn),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
|
||||
parent.Log("[TCP server] opened on :%d", port)
|
||||
@@ -49,7 +60,7 @@ func (s *Server) Close() {
|
||||
co.Close()
|
||||
}
|
||||
}()
|
||||
s.listener.Close()
|
||||
s.srv.Close()
|
||||
<-s.done
|
||||
}
|
||||
|
||||
@@ -57,7 +68,7 @@ func (s *Server) run() {
|
||||
defer close(s.done)
|
||||
|
||||
for {
|
||||
conn, err := s.listener.AcceptTCP()
|
||||
conn, err := s.srv.Accept()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
@@ -69,6 +80,6 @@ func (s *Server) run() {
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -105,13 +105,13 @@ func (s *Source) run() {
|
||||
func (s *Source) runInner() bool {
|
||||
s.parent.Log("connecting to rtsp source")
|
||||
|
||||
var conn *gortsplib.ConnClient
|
||||
var conn *gortsplib.ClientConn
|
||||
var err error
|
||||
dialDone := make(chan struct{}, 1)
|
||||
go func() {
|
||||
defer close(dialDone)
|
||||
|
||||
dialer := gortsplib.Dialer{
|
||||
dialer := gortsplib.ClientConf{
|
||||
StreamProtocol: s.proto,
|
||||
ReadTimeout: s.readTimeout,
|
||||
WriteTimeout: s.writeTimeout,
|
||||
|
||||
10
main.go
10
main.go
@@ -175,7 +175,8 @@ func (p *program) createDynamicResources(initial bool) error {
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -189,7 +190,7 @@ func (p *program) createDynamicResources(initial bool) error {
|
||||
|
||||
if p.clientMan == nil {
|
||||
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.pathMan, p.serverTCP, p)
|
||||
}
|
||||
@@ -274,7 +275,9 @@ func (p *program) reloadConf() error {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -295,7 +298,6 @@ func (p *program) reloadConf() error {
|
||||
closePathMan ||
|
||||
conf.RtspPort != p.conf.RtspPort ||
|
||||
conf.ReadTimeout != p.conf.ReadTimeout ||
|
||||
conf.WriteTimeout != p.conf.WriteTimeout ||
|
||||
conf.RunOnConnect != p.conf.RunOnConnect ||
|
||||
conf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
||||
!reflect.DeepEqual(conf.ProtocolsParsed, p.conf.ProtocolsParsed) {
|
||||
|
||||
Reference in New Issue
Block a user