From f01bb9685f5ffe5ecaf4efad82be37ffddb22da0 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 12 Jul 2020 13:21:26 +0200 Subject: [PATCH] new option streamDeadAfter --- conf.go | 4 ++++ conf.yml | 2 ++ server-client.go | 5 ++--- streamer.go | 5 ++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/conf.go b/conf.go index 1b14fabba6c..a39dfb17a4e 100644 --- a/conf.go +++ b/conf.go @@ -34,6 +34,7 @@ type conf struct { PostScript string `yaml:"postScript"` ReadTimeout time.Duration `yaml:"readTimeout"` WriteTimeout time.Duration `yaml:"writeTimeout"` + StreamDeadAfter time.Duration `yaml:"streamDeadAfter"` AuthMethods []string `yaml:"authMethods"` authMethodsParsed []gortsplib.AuthMethod Pprof bool `yaml:"pprof"` @@ -120,6 +121,9 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) { if conf.WriteTimeout == 0 { conf.WriteTimeout = 5 * time.Second } + if conf.StreamDeadAfter == 0 { + conf.StreamDeadAfter = 15 * time.Second + } if len(conf.AuthMethods) == 0 { conf.AuthMethods = []string{"basic", "digest"} diff --git a/conf.yml b/conf.yml index 2fbcb12336a..0d7b40329d1 100644 --- a/conf.yml +++ b/conf.yml @@ -15,6 +15,8 @@ postScript: readTimeout: 5s # timeout of write operations writeTimeout: 5s +# time after which a stream is considered dead +streamDeadAfter: 15s # supported authentication methods authMethods: [basic, digest] # enable pprof on port 9999 to monitor performance diff --git a/server-client.go b/server-client.go index 6bc70aaffe2..1feb945b981 100644 --- a/server-client.go +++ b/server-client.go @@ -15,7 +15,6 @@ import ( const ( _CLIENT_CHECK_STREAM_INTERVAL = 5 * time.Second - _CLIENT_STREAM_DEAD_AFTER = 15 * time.Second _CLIENT_RECEIVER_REPORT_INTERVAL = 10 * time.Second ) @@ -332,7 +331,7 @@ func (c *serverClient) runRecord() bool { case <-checkStreamTicker.C: for trackId := range c.streamTracks { - if time.Since(c.rtcpReceivers[trackId].lastFrameTime()) >= _CLIENT_STREAM_DEAD_AFTER { + if time.Since(c.rtcpReceivers[trackId].lastFrameTime()) >= c.p.conf.StreamDeadAfter { c.log("ERR: stream is dead") c.conn.NetConn().Close() <-readDone @@ -388,7 +387,7 @@ func (c *serverClient) runRecord() bool { case <-checkStreamTicker.C: for trackId := range c.streamTracks { - if time.Since(c.rtcpReceivers[trackId].lastFrameTime()) >= _CLIENT_STREAM_DEAD_AFTER { + if time.Since(c.rtcpReceivers[trackId].lastFrameTime()) >= c.p.conf.StreamDeadAfter { c.log("ERR: stream is dead") c.conn.NetConn().Close() <-readDone diff --git a/streamer.go b/streamer.go index 90c1b457712..8c6118872a7 100644 --- a/streamer.go +++ b/streamer.go @@ -16,7 +16,6 @@ import ( const ( _STREAMER_RETRY_INTERVAL = 5 * time.Second _STREAMER_CHECK_STREAM_INTERVAL = 5 * time.Second - _STREAMER_STREAM_DEAD_AFTER = 15 * time.Second _STREAMER_KEEPALIVE_INTERVAL = 60 * time.Second _STREAMER_RECEIVER_REPORT_INTERVAL = 10 * time.Second ) @@ -431,7 +430,7 @@ outer: case <-checkStreamTicker.C: for trackId := range s.clientSdpParsed.Medias { - if time.Since(s.rtcpReceivers[trackId].lastFrameTime()) >= _STREAMER_STREAM_DEAD_AFTER { + if time.Since(s.rtcpReceivers[trackId].lastFrameTime()) >= s.p.conf.StreamDeadAfter { s.log("ERR: stream is dead") ret = true break outer @@ -634,7 +633,7 @@ outer2: case <-checkStreamTicker.C: for trackId := range s.clientSdpParsed.Medias { - if time.Since(s.rtcpReceivers[trackId].lastFrameTime()) >= _STREAMER_STREAM_DEAD_AFTER { + if time.Since(s.rtcpReceivers[trackId].lastFrameTime()) >= s.p.conf.StreamDeadAfter { s.log("ERR: stream is dead") ret = true break outer2