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

Loading…
Cancel
Save