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

16
path.go

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

Loading…
Cancel
Save