Browse Source

RTSP: automatically remux oversized RTP/H264 packets; drop parameter ReadBufferSize

pull/923/head
aler9 3 years ago
parent
commit
98c6cd4650
  1. 8
      README.md
  2. 2
      apidocs/openapi.yaml
  3. 2
      go.mod
  4. 4
      go.sum
  5. 1
      internal/conf/conf.go
  6. 1
      internal/core/api.go
  7. 4
      internal/core/core.go
  8. 4
      internal/core/path.go
  9. 4
      internal/core/path_manager.go
  10. 2
      internal/core/rtsp_server.go
  11. 4
      internal/core/rtsp_source.go
  12. 4
      rtsp-simple-server.yml

8
README.md

@ -705,7 +705,7 @@ paths: @@ -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 @@ -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

2
apidocs/openapi.yaml

@ -81,8 +81,6 @@ components: @@ -81,8 +81,6 @@ components:
type: array
items:
type: string
readBufferSize:
type: integer
# RTMP
rtmpDisable:

2
go.mod

@ -4,7 +4,7 @@ go 1.17 @@ -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

4
go.sum

@ -4,8 +4,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo @@ -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=

1
internal/conf/conf.go

@ -198,7 +198,6 @@ type Conf struct { @@ -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"`

1
internal/core/api.go

@ -74,7 +74,6 @@ func loadConfData(ctx *gin.Context) (interface{}, error) { @@ -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"`

4
internal/core/core.go

@ -224,7 +224,6 @@ func (p *Core) createResources(initial bool) error { @@ -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 { @@ -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 { @@ -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) { @@ -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) {

4
internal/core/path.go

@ -216,7 +216,6 @@ type path struct { @@ -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( @@ -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( @@ -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() { @@ -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://"):

4
internal/core/path_manager.go

@ -23,7 +23,6 @@ type pathManager struct { @@ -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( @@ -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( @@ -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( @@ -277,7 +274,6 @@ func (pm *pathManager) createPath(
pm.readTimeout,
pm.writeTimeout,
pm.readBufferCount,
pm.readBufferSize,
pathConfName,
pathConf,
name,

2
internal/core/rtsp_server.go

@ -80,7 +80,6 @@ func newRTSPServer( @@ -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( @@ -124,7 +123,6 @@ func newRTSPServer(
ReadTimeout: time.Duration(readTimeout),
WriteTimeout: time.Duration(writeTimeout),
ReadBufferCount: readBufferCount,
ReadBufferSize: readBufferSize,
WriteBufferCount: readBufferCount,
RTSPAddress: address,
}

4
internal/core/rtsp_source.go

@ -35,7 +35,6 @@ type rtspSource struct { @@ -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( @@ -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( @@ -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 { @@ -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)

4
rtsp-simple-server.yml

@ -93,10 +93,6 @@ serverKey: server.key @@ -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

Loading…
Cancel
Save