Browse Source

move sources inside paths

pull/80/head
aler9 5 years ago
parent
commit
0b589b3e7e
  1. 37
      main.go
  2. 16
      path.go

37
main.go

@ -160,13 +160,12 @@ type program struct { @@ -160,13 +160,12 @@ type program struct {
logFile *os.File
metrics *metrics
pprof *pprof
serverRtsp *serverTcp
paths map[string]*path
serverRtp *serverUdp
serverRtcp *serverUdp
sources []*source
serverRtsp *serverTcp
clients map[*client]struct{}
udpClientsByAddr map[udpClientAddr]*udpClient
paths map[string]*path
publisherCount int
readerCount int
@ -195,9 +194,9 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { @@ -195,9 +194,9 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
p := &program{
conf: conf,
paths: make(map[string]*path),
clients: make(map[*client]struct{}),
udpClientsByAddr: make(map[udpClientAddr]*udpClient),
paths: make(map[string]*path),
events: make(chan programEvent),
done: make(chan struct{}),
}
@ -211,20 +210,6 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { @@ -211,20 +210,6 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
p.log("rtsp-simple-server %s", Version)
for name, confp := range conf.Paths {
if name == "all" {
continue
}
p.paths[name] = newPath(p, name, confp, true)
if confp.Source != "record" {
s := newSource(p, name, confp)
p.sources = append(p.sources, s)
p.paths[name].publisher = s
}
}
if conf.Metrics {
p.metrics, err = newMetrics(p)
if err != nil {
@ -239,6 +224,13 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { @@ -239,6 +224,13 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
}
}
for name, confp := range conf.Paths {
if name == "all" {
continue
}
p.paths[name] = newPath(p, name, confp, true)
}
if _, ok := conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
p.serverRtp, err = newServerUdp(p, conf.RtpPort, gortsplib.StreamTypeRtp)
if err != nil {
@ -271,10 +263,6 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { @@ -271,10 +263,6 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
go p.serverRtsp.run()
for _, s := range p.sources {
go s.run()
}
for _, p := range p.paths {
p.onInit()
}
@ -532,11 +520,6 @@ outer: @@ -532,11 +520,6 @@ outer:
p.serverRtsp.close()
for _, s := range p.sources {
s.events <- sourceEventTerminate{}
<-s.done
}
if _, ok := p.conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
p.serverRtcp.close()
p.serverRtp.close()

16
path.go

@ -19,6 +19,7 @@ type path struct { @@ -19,6 +19,7 @@ type path struct {
name string
confp *confPath
permanent bool
source *source
publisher publisher
publisherReady bool
publisherSdpText []byte
@ -37,10 +38,20 @@ func newPath(p *program, name string, confp *confPath, permanent bool) *path { @@ -37,10 +38,20 @@ func newPath(p *program, name string, confp *confPath, permanent bool) *path {
permanent: permanent,
}
if confp.Source != "record" {
s := newSource(p, name, confp)
pa.source = s
pa.publisher = s
}
return pa
}
func (pa *path) onInit() {
if pa.source != nil {
go pa.source.run()
}
if pa.confp.RunOnInit != "" {
pa.p.log("starting on init command")
@ -58,6 +69,11 @@ func (pa *path) onInit() { @@ -58,6 +69,11 @@ func (pa *path) onInit() {
}
func (pa *path) onClose() {
if pa.source != nil {
pa.source.events <- sourceEventTerminate{}
<-pa.source.done
}
if pa.onInitCmd != nil {
pa.p.log("stopping on init command (exited)")
pa.onInitCmd.Process.Signal(os.Interrupt)

Loading…
Cancel
Save