Browse Source

log the exact reason why a path is closed

pull/707/head
aler9 4 years ago
parent
commit
f801a9fa39
  1. 52
      internal/core/path.go

52
internal/core/path.go

@ -275,7 +275,6 @@ func newPath( @@ -275,7 +275,6 @@ func newPath(
func (pa *path) close() {
pa.ctxCancel()
pa.log(logger.Info, "closed")
}
// Log is the main logging function.
@ -317,7 +316,7 @@ func (pa *path) run() { @@ -317,7 +316,7 @@ func (pa *path) run() {
})
}
outer:
err := func() error {
for {
select {
case <-pa.onDemandReadyTimer.C:
@ -333,15 +332,15 @@ outer: @@ -333,15 +332,15 @@ outer:
pa.onDemandCloseSource()
if pa.conf.Regexp != nil {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case <-pa.onDemandCloseTimer.C:
pa.onDemandCloseSource()
if pa.conf.Regexp != nil {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case req := <-pa.sourceStaticSetReady:
@ -362,26 +361,22 @@ outer: @@ -362,26 +361,22 @@ outer:
}
close(req.Res)
if pa.source == nil && pa.conf.Regexp != nil {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case req := <-pa.describe:
pa.handleDescribe(req)
if pa.conf.Regexp != nil &&
pa.source == nil &&
len(pa.readers) == 0 &&
len(pa.describeRequests) == 0 &&
len(pa.setupPlayRequests) == 0 {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case req := <-pa.publisherRemove:
pa.handlePublisherRemove(req)
if pa.source == nil && pa.conf.Regexp != nil {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case req := <-pa.publisherAnnounce:
@ -393,8 +388,8 @@ outer: @@ -393,8 +388,8 @@ outer:
case req := <-pa.publisherPause:
pa.handlePublisherPause(req)
if pa.source == nil && pa.conf.Regexp != nil {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case req := <-pa.readerRemove:
@ -403,12 +398,8 @@ outer: @@ -403,12 +398,8 @@ outer:
case req := <-pa.readerSetupPlay:
pa.handleReaderSetupPlay(req)
if pa.conf.Regexp != nil &&
pa.source == nil &&
len(pa.readers) == 0 &&
len(pa.describeRequests) == 0 &&
len(pa.setupPlayRequests) == 0 {
break outer
if pa.shouldClose() {
return fmt.Errorf("not in use")
}
case req := <-pa.readerPlay:
@ -421,9 +412,10 @@ outer: @@ -421,9 +412,10 @@ outer:
pa.handleAPIPathsList(req)
case <-pa.ctx.Done():
break outer
return fmt.Errorf("terminated")
}
}
}()
pa.ctxCancel()
@ -470,9 +462,19 @@ outer: @@ -470,9 +462,19 @@ outer:
pa.log(logger.Info, "runOnDemand command stopped")
}
pa.log(logger.Info, "closed (%v)", err)
pa.parent.onPathClose(pa)
}
func (pa *path) shouldClose() bool {
return pa.conf.Regexp != nil &&
pa.source == nil &&
len(pa.readers) == 0 &&
len(pa.describeRequests) == 0 &&
len(pa.setupPlayRequests) == 0
}
func (pa *path) hasStaticSource() bool {
return strings.HasPrefix(pa.conf.Source, "rtsp://") ||
strings.HasPrefix(pa.conf.Source, "rtsps://") ||

Loading…
Cancel
Save