From 98c6cd4650c2efc80fae7e7727d3465190fffc3a Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 9 Apr 2022 20:20:14 +0200 Subject: [PATCH] RTSP: automatically remux oversized RTP/H264 packets; drop parameter ReadBufferSize --- README.md | 8 +------- apidocs/openapi.yaml | 2 -- go.mod | 2 +- go.sum | 4 ++-- internal/conf/conf.go | 1 - internal/core/api.go | 1 - internal/core/core.go | 4 ---- internal/core/path.go | 4 ---- internal/core/path_manager.go | 4 ---- internal/core/rtsp_server.go | 2 -- internal/core/rtsp_source.go | 4 ---- rtsp-simple-server.yml | 4 ---- 12 files changed, 4 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index dd584fac..e0029d65 100644 --- a/README.md +++ b/README.md @@ -705,7 +705,7 @@ paths: In some scenarios, when reading RTSP from the server, decoded frames can be corrupted or incomplete. This can be caused by multiple reasons: -* the packet buffer of the server is too small and can't handle the stream throughput. A solution consists in increasing its size: +* the packet buffer of the server is too small and can't keep up with the stream throughput. A solution consists in increasing its size: ```yml readBufferCount: 1024 @@ -726,12 +726,6 @@ In some scenarios, when reading RTSP from the server, decoded frames can be corr sourceProtocol: tcp ``` -* the software that is generating the stream (a camera or FFmpeg) is generating non-conformant RTP packets, with a payload bigger than the maximum allowed (that is 1460 due to the UDP MTU). A solution consists in increasing the buffer size: - - ```yml - readBufferSize: 8192 - ``` - ## RTMP protocol ### RTMP general usage diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index fad07684..eade0379 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -81,8 +81,6 @@ components: type: array items: type: string - readBufferSize: - type: integer # RTMP rtmpDisable: diff --git a/go.mod b/go.mod index 8955f40e..72de6554 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5 - github.com/aler9/gortsplib v0.0.0-20220409092623-b1a4b5209088 + github.com/aler9/gortsplib v0.0.0-20220409181614-bfe4e8cdaa9b github.com/asticode/go-astits v1.10.0 github.com/fsnotify/fsnotify v1.4.9 github.com/gin-gonic/gin v1.7.2 diff --git a/go.sum b/go.sum index 2524314e..f4a58976 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,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-20220409092623-b1a4b5209088 h1:LxlbSskpLz+7GvAyId2GGPRQ1aAUQ547H3mTfTBVw9Q= -github.com/aler9/gortsplib v0.0.0-20220409092623-b1a4b5209088/go.mod h1:Mezkz7Jb5zrIWP6MxJ2uBgt5xwywZkcdmuQZ2QrFYsM= +github.com/aler9/gortsplib v0.0.0-20220409181614-bfe4e8cdaa9b h1:4MiZp+d15pIQKVjJdJK5PRnhpLNsOoU5LizzPbg8Cxo= +github.com/aler9/gortsplib v0.0.0-20220409181614-bfe4e8cdaa9b/go.mod h1:Mezkz7Jb5zrIWP6MxJ2uBgt5xwywZkcdmuQZ2QrFYsM= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc= github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8= diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 2aa0e75c..a0b7ef80 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -198,7 +198,6 @@ type Conf struct { ServerKey string `json:"serverKey"` ServerCert string `json:"serverCert"` AuthMethods AuthMethods `json:"authMethods"` - ReadBufferSize int `json:"readBufferSize"` // RTMP RTMPDisable bool `json:"rtmpDisable"` diff --git a/internal/core/api.go b/internal/core/api.go index 59b266ad..139d1710 100644 --- a/internal/core/api.go +++ b/internal/core/api.go @@ -74,7 +74,6 @@ func loadConfData(ctx *gin.Context) (interface{}, error) { ServerKey *string `json:"serverKey"` ServerCert *string `json:"serverCert"` AuthMethods *conf.AuthMethods `json:"authMethods"` - ReadBufferSize *int `json:"readBufferSize"` // RTMP RTMPDisable *bool `json:"rtmpDisable"` diff --git a/internal/core/core.go b/internal/core/core.go index ee23181e..6640d345 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -224,7 +224,6 @@ func (p *Core) createResources(initial bool) error { p.conf.ReadTimeout, p.conf.WriteTimeout, p.conf.ReadBufferCount, - p.conf.ReadBufferSize, p.conf.Paths, p.externalCmdPool, p.metrics, @@ -245,7 +244,6 @@ func (p *Core) createResources(initial bool) error { p.conf.ReadTimeout, p.conf.WriteTimeout, p.conf.ReadBufferCount, - p.conf.ReadBufferSize, useUDP, useMulticast, p.conf.RTPAddress, @@ -282,7 +280,6 @@ func (p *Core) createResources(initial bool) error { p.conf.ReadTimeout, p.conf.WriteTimeout, p.conf.ReadBufferCount, - p.conf.ReadBufferSize, false, false, "", @@ -405,7 +402,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { newConf.ReadTimeout != p.conf.ReadTimeout || newConf.WriteTimeout != p.conf.WriteTimeout || newConf.ReadBufferCount != p.conf.ReadBufferCount || - newConf.ReadBufferSize != p.conf.ReadBufferSize || closeMetrics { closePathManager = true } else if !reflect.DeepEqual(newConf.Paths, p.conf.Paths) { diff --git a/internal/core/path.go b/internal/core/path.go index 723ce0e5..d6834a2b 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -216,7 +216,6 @@ type path struct { readTimeout conf.StringDuration writeTimeout conf.StringDuration readBufferCount int - readBufferSize int confName string conf *conf.PathConf name string @@ -261,7 +260,6 @@ func newPath( readTimeout conf.StringDuration, writeTimeout conf.StringDuration, readBufferCount int, - readBufferSize int, confName string, conf *conf.PathConf, name string, @@ -277,7 +275,6 @@ func newPath( readTimeout: readTimeout, writeTimeout: writeTimeout, readBufferCount: readBufferCount, - readBufferSize: readBufferSize, confName: confName, conf: conf, name: name, @@ -670,7 +667,6 @@ func (pa *path) staticSourceCreate() { pa.readTimeout, pa.writeTimeout, pa.readBufferCount, - pa.readBufferSize, &pa.sourceStaticWg, pa) case strings.HasPrefix(pa.conf.Source, "rtmp://"): diff --git a/internal/core/path_manager.go b/internal/core/path_manager.go index 9bbe4d91..b20d6ed3 100644 --- a/internal/core/path_manager.go +++ b/internal/core/path_manager.go @@ -23,7 +23,6 @@ type pathManager struct { readTimeout conf.StringDuration writeTimeout conf.StringDuration readBufferCount int - readBufferSize int pathConfs map[string]*conf.PathConf externalCmdPool *externalcmd.Pool metrics *metrics @@ -52,7 +51,6 @@ func newPathManager( readTimeout conf.StringDuration, writeTimeout conf.StringDuration, readBufferCount int, - readBufferSize int, pathConfs map[string]*conf.PathConf, externalCmdPool *externalcmd.Pool, metrics *metrics, @@ -65,7 +63,6 @@ func newPathManager( readTimeout: readTimeout, writeTimeout: writeTimeout, readBufferCount: readBufferCount, - readBufferSize: readBufferSize, pathConfs: pathConfs, externalCmdPool: externalCmdPool, metrics: metrics, @@ -277,7 +274,6 @@ func (pm *pathManager) createPath( pm.readTimeout, pm.writeTimeout, pm.readBufferCount, - pm.readBufferSize, pathConfName, pathConf, name, diff --git a/internal/core/rtsp_server.go b/internal/core/rtsp_server.go index dbcf564e..a5cebeb5 100644 --- a/internal/core/rtsp_server.go +++ b/internal/core/rtsp_server.go @@ -80,7 +80,6 @@ func newRTSPServer( readTimeout conf.StringDuration, writeTimeout conf.StringDuration, readBufferCount int, - readBufferSize int, useUDP bool, useMulticast bool, rtpAddress string, @@ -124,7 +123,6 @@ func newRTSPServer( ReadTimeout: time.Duration(readTimeout), WriteTimeout: time.Duration(writeTimeout), ReadBufferCount: readBufferCount, - ReadBufferSize: readBufferSize, WriteBufferCount: readBufferCount, RTSPAddress: address, } diff --git a/internal/core/rtsp_source.go b/internal/core/rtsp_source.go index 5c8295a1..5a8effbc 100644 --- a/internal/core/rtsp_source.go +++ b/internal/core/rtsp_source.go @@ -35,7 +35,6 @@ type rtspSource struct { readTimeout conf.StringDuration writeTimeout conf.StringDuration readBufferCount int - readBufferSize int wg *sync.WaitGroup parent rtspSourceParent @@ -52,7 +51,6 @@ func newRTSPSource( readTimeout conf.StringDuration, writeTimeout conf.StringDuration, readBufferCount int, - readBufferSize int, wg *sync.WaitGroup, parent rtspSourceParent, ) *rtspSource { @@ -66,7 +64,6 @@ func newRTSPSource( readTimeout: readTimeout, writeTimeout: writeTimeout, readBufferCount: readBufferCount, - readBufferSize: readBufferSize, wg: wg, parent: parent, ctx: ctx, @@ -145,7 +142,6 @@ func (s *rtspSource) runInner() bool { ReadTimeout: time.Duration(s.readTimeout), WriteTimeout: time.Duration(s.writeTimeout), ReadBufferCount: s.readBufferCount, - ReadBufferSize: s.readBufferSize, AnyPortEnable: s.anyPortEnable, OnRequest: func(req *base.Request) { s.log(logger.Debug, "c->s %v", req) diff --git a/rtsp-simple-server.yml b/rtsp-simple-server.yml index 2afe6f4c..688f627a 100644 --- a/rtsp-simple-server.yml +++ b/rtsp-simple-server.yml @@ -93,10 +93,6 @@ serverKey: server.key serverCert: server.crt # Authentication methods. authMethods: [basic, digest] -# Read buffer size. -# This doesn't influence throughput and shouldn't be touched unless the server -# reports errors about the buffer size. -readBufferSize: 2048 ############################################### # RTMP parameters