mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
ringbuffer: force size to be a power of 2
otherwise buffer is used partially when writeIndex overflows.
This commit is contained in:
@@ -318,6 +318,9 @@ func (c *Client) Start(scheme string, host string) error {
|
||||
if c.WriteBufferCount == 0 {
|
||||
c.WriteBufferCount = 256
|
||||
}
|
||||
if (c.WriteBufferCount & (c.WriteBufferCount - 1)) != 0 {
|
||||
return fmt.Errorf("WriteBufferCount must be a power of two")
|
||||
}
|
||||
if c.UserAgent == "" {
|
||||
c.UserAgent = "gortsplib"
|
||||
}
|
||||
@@ -699,9 +702,9 @@ func (c *Client) playRecordStart() {
|
||||
// when reading, writeBuffer is only used to send RTCP receiver reports,
|
||||
// that are much smaller than RTP packets and are sent at a fixed interval.
|
||||
// decrease RAM consumption by allocating less buffers.
|
||||
c.writeBuffer = ringbuffer.New(8)
|
||||
c.writeBuffer, _ = ringbuffer.New(8)
|
||||
} else {
|
||||
c.writeBuffer = ringbuffer.New(uint64(c.WriteBufferCount))
|
||||
c.writeBuffer, _ = ringbuffer.New(uint64(c.WriteBufferCount))
|
||||
}
|
||||
c.writerRunning = true
|
||||
c.writerDone = make(chan struct{})
|
||||
|
Reference in New Issue
Block a user