Skip to content

Commit

Permalink
new option streamDeadAfter
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jul 12, 2020
1 parent d941132 commit f01bb96
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"}
Expand Down
2 changes: 2 additions & 0 deletions conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions server-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f01bb96

Please sign in to comment.