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

View File

@@ -79,17 +79,9 @@ type Server struct {
WriteTimeout time.Duration
// a TLS configuration to accept TLS (RTSPS) connections.
TLSConfig *tls.Config
// read buffer count.
// 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.
// Size of the queue of outgoing packets.
// It defaults to 256.
ReadBufferCount int
// write buffer count.
// It allows to queue packets before sending them.
// It defaults to 256.
WriteBufferCount int
WriteQueueSize int
// maximum size of outgoing RTP / RTCP packets.
// This must be less than the UDP MTU (1472 bytes).
// It defaults to 1472.
@@ -154,13 +146,10 @@ func (s *Server) Start() error {
if s.WriteTimeout == 0 {
s.WriteTimeout = 10 * time.Second
}
if s.ReadBufferCount == 0 {
s.ReadBufferCount = 256
}
if s.WriteBufferCount == 0 {
s.WriteBufferCount = 256
} else if (s.WriteBufferCount & (s.WriteBufferCount - 1)) != 0 {
return fmt.Errorf("WriteBufferCount must be a power of two")
if s.WriteQueueSize == 0 {
s.WriteQueueSize = 256
} else if (s.WriteQueueSize & (s.WriteQueueSize - 1)) != 0 {
return fmt.Errorf("WriteQueueSize must be a power of two")
}
if s.MaxPacketSize == 0 {
s.MaxPacketSize = udpMaxPayloadSize

View File

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

View File

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