From e5364b1fc6444f116a33b1b1e05434b69916dc19 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 9 Jan 2021 23:04:23 +0100 Subject: [PATCH] perform frame readings and writings in separate routines, in order to increase UDP throughput and avoid freezes caused by a single laggy reader (#125) (#162) --- go.mod | 2 +- go.sum | 4 ++-- internal/serverplain/server.go | 1 - internal/servertls/server.go | 7 +++---- internal/sourcertsp/source.go | 2 +- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 87f2a1e0..b18cec14 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/aler9/gortsplib v0.0.0-20210107121652-0680ffa9a343 + github.com/aler9/gortsplib v0.0.0-20210109215941-7d91c139729d github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.4.9 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 diff --git a/go.sum b/go.sum index 511b7a23..0deff8ae 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aler9/gortsplib v0.0.0-20210107121652-0680ffa9a343 h1:U6C+dTroqLhd/SfDowiSwt7QNJB0Ow09uv3SAQzqug8= -github.com/aler9/gortsplib v0.0.0-20210107121652-0680ffa9a343/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I= +github.com/aler9/gortsplib v0.0.0-20210109215941-7d91c139729d h1:hMNcEEry/jZNXrtPyIijXemRRwbT1oP1SzrPSp/r8j8= +github.com/aler9/gortsplib v0.0.0-20210109215941-7d91c139729d/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/internal/serverplain/server.go b/internal/serverplain/server.go index 986a1e4a..2312fa0f 100644 --- a/internal/serverplain/server.go +++ b/internal/serverplain/server.go @@ -36,7 +36,6 @@ func New(port int, conf := gortsplib.ServerConf{ ReadTimeout: readTimeout, WriteTimeout: writeTimeout, - ReadBufferCount: 1, UDPRTPListener: udpRTPListener, UDPRTCPListener: udpRTCPListener, } diff --git a/internal/servertls/server.go b/internal/servertls/server.go index 65fa5d25..091d68b0 100644 --- a/internal/servertls/server.go +++ b/internal/servertls/server.go @@ -40,10 +40,9 @@ func New(port int, } conf := gortsplib.ServerConf{ - TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}}, - ReadTimeout: readTimeout, - WriteTimeout: writeTimeout, - ReadBufferCount: 1, + TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}}, + ReadTimeout: readTimeout, + WriteTimeout: writeTimeout, } srv, err := conf.Serve(":" + strconv.FormatInt(int64(port), 10)) diff --git a/internal/sourcertsp/source.go b/internal/sourcertsp/source.go index 83d436fe..9b9a1464 100644 --- a/internal/sourcertsp/source.go +++ b/internal/sourcertsp/source.go @@ -121,7 +121,7 @@ func (s *Source) runInner() bool { StreamProtocol: s.proto, ReadTimeout: s.readTimeout, WriteTimeout: s.writeTimeout, - ReadBufferCount: 2, + ReadBufferCount: 1024, OnRequest: func(req *base.Request) { s.log(logger.Debug, "c->s %v", req) },