remove ReadBufferCount; rename WriteBufferCount into WriteQueueSize (#384)

This commit is contained in:
Alessandro Ros
2023-08-26 12:21:05 +02:00
committed by aler9
parent 5d8f742d60
commit b97aed00fe
4 changed files with 15 additions and 35 deletions

View File

@@ -234,15 +234,9 @@ type Client struct {
// at least a packet within this timeout, otherwise it switches to TCP. // at least a packet within this timeout, otherwise it switches to TCP.
// It defaults to 3 seconds. // It defaults to 3 seconds.
InitialUDPReadTimeout time.Duration InitialUDPReadTimeout time.Duration
// read buffer count. // Size of the queue of outgoing packets.
// If greater than 1, allows to pass buffers to routines different than the one
// that is reading frames.
// It defaults to 256. // It defaults to 256.
ReadBufferCount int WriteQueueSize int
// write buffer count.
// It allows to queue packets before sending them.
// It defaults to 256.
WriteBufferCount int
// maximum size of outgoing RTP / RTCP packets. // maximum size of outgoing RTP / RTCP packets.
// This must be less than the UDP MTU (1472 bytes). // This must be less than the UDP MTU (1472 bytes).
// It defaults to 1472. // It defaults to 1472.
@@ -346,13 +340,10 @@ func (c *Client) Start(scheme string, host string) error {
if c.InitialUDPReadTimeout == 0 { if c.InitialUDPReadTimeout == 0 {
c.InitialUDPReadTimeout = 3 * time.Second c.InitialUDPReadTimeout = 3 * time.Second
} }
if c.ReadBufferCount == 0 { if c.WriteQueueSize == 0 {
c.ReadBufferCount = 256 c.WriteQueueSize = 256
} } else if (c.WriteQueueSize & (c.WriteQueueSize - 1)) != 0 {
if c.WriteBufferCount == 0 { return fmt.Errorf("WriteQueueSize must be a power of two")
c.WriteBufferCount = 256
} else if (c.WriteBufferCount & (c.WriteBufferCount - 1)) != 0 {
return fmt.Errorf("WriteBufferCount must be a power of two")
} }
if c.MaxPacketSize == 0 { if c.MaxPacketSize == 0 {
c.MaxPacketSize = udpMaxPayloadSize c.MaxPacketSize = udpMaxPayloadSize
@@ -768,7 +759,7 @@ func (c *Client) startReadRoutines() {
// decrease RAM consumption by allocating less buffers. // decrease RAM consumption by allocating less buffers.
c.writer.allocateBuffer(8) c.writer.allocateBuffer(8)
} else { } else {
c.writer.allocateBuffer(c.WriteBufferCount) c.writer.allocateBuffer(c.WriteQueueSize)
} }
c.timeDecoder = rtptime.NewGlobalDecoder() c.timeDecoder = rtptime.NewGlobalDecoder()

View File

@@ -79,17 +79,9 @@ type Server struct {
WriteTimeout time.Duration WriteTimeout time.Duration
// a TLS configuration to accept TLS (RTSPS) connections. // a TLS configuration to accept TLS (RTSPS) connections.
TLSConfig *tls.Config TLSConfig *tls.Config
// read buffer count. // Size of the queue of outgoing packets.
// If greater than 1, allows to pass buffers to routines different than the one
// that is reading frames.
// It also allows to buffer routed frames and mitigate network fluctuations
// that are particularly relevant when using UDP.
// It defaults to 256. // It defaults to 256.
ReadBufferCount int WriteQueueSize int
// write buffer count.
// It allows to queue packets before sending them.
// It defaults to 256.
WriteBufferCount int
// maximum size of outgoing RTP / RTCP packets. // maximum size of outgoing RTP / RTCP packets.
// This must be less than the UDP MTU (1472 bytes). // This must be less than the UDP MTU (1472 bytes).
// It defaults to 1472. // It defaults to 1472.
@@ -154,13 +146,10 @@ func (s *Server) Start() error {
if s.WriteTimeout == 0 { if s.WriteTimeout == 0 {
s.WriteTimeout = 10 * time.Second s.WriteTimeout = 10 * time.Second
} }
if s.ReadBufferCount == 0 { if s.WriteQueueSize == 0 {
s.ReadBufferCount = 256 s.WriteQueueSize = 256
} } else if (s.WriteQueueSize & (s.WriteQueueSize - 1)) != 0 {
if s.WriteBufferCount == 0 { return fmt.Errorf("WriteQueueSize must be a power of two")
s.WriteBufferCount = 256
} else if (s.WriteBufferCount & (s.WriteBufferCount - 1)) != 0 {
return fmt.Errorf("WriteBufferCount must be a power of two")
} }
if s.MaxPacketSize == 0 { if s.MaxPacketSize == 0 {
s.MaxPacketSize = udpMaxPayloadSize s.MaxPacketSize = udpMaxPayloadSize

View File

@@ -36,7 +36,7 @@ func newServerMulticastWriter(s *Server) (*serverMulticastWriter, error) {
return nil, err return nil, err
} }
wb, _ := ringbuffer.New(uint64(s.WriteBufferCount)) wb, _ := ringbuffer.New(uint64(s.WriteQueueSize))
h := &serverMulticastWriter{ h := &serverMulticastWriter{
rtpl: rtpl, rtpl: rtpl,

View File

@@ -885,7 +885,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
// inside the callback. // inside the callback.
if ss.state != ServerSessionStatePlay && if ss.state != ServerSessionStatePlay &&
*ss.setuppedTransport != TransportUDPMulticast { *ss.setuppedTransport != TransportUDPMulticast {
ss.writer.allocateBuffer(ss.s.WriteBufferCount) ss.writer.allocateBuffer(ss.s.WriteQueueSize)
} }
res, err := sc.s.Handler.(ServerHandlerOnPlay).OnPlay(&ServerHandlerOnPlayCtx{ res, err := sc.s.Handler.(ServerHandlerOnPlay).OnPlay(&ServerHandlerOnPlayCtx{