increase udp kernel read buffer size to minimize packet losses (https://github.com/aler9/rtsp-simple-server/issues/125)

This commit is contained in:
aler9
2020-11-25 21:12:50 +01:00
parent 44a8f094c9
commit 8305ca75f0
2 changed files with 13 additions and 2 deletions

View File

@@ -33,7 +33,6 @@ const (
clientUDPCheckStreamPeriod = 5 * time.Second
clientUDPKeepalivePeriod = 30 * time.Second
clientTCPFrameReadBufferSize = 128 * 1024
clientUDPFrameReadBufferSize = 2048
)
type connClientState int

View File

@@ -9,6 +9,13 @@ import (
"github.com/aler9/gortsplib/pkg/multibuffer"
)
const (
// use the same buffer size as gstreamer's rtspsrc
connClientUDPKernelReadBufferSize = 0x80000
connClientUDPReadBufferSize = 2048
)
type connClientUDPListener struct {
c *ConnClient
pc net.PacketConn
@@ -29,10 +36,15 @@ func newConnClientUDPListener(c *ConnClient, port int) (*connClientUDPListener,
return nil, err
}
err = pc.(*net.UDPConn).SetReadBuffer(connClientUDPKernelReadBufferSize)
if err != nil {
return nil, err
}
return &connClientUDPListener{
c: c,
pc: pc,
udpFrameBuffer: multibuffer.New(c.d.ReadBufferCount, 2048),
udpFrameBuffer: multibuffer.New(c.d.ReadBufferCount, connClientUDPReadBufferSize),
}, nil
}