mirror of
https://github.com/aler9/gortsplib
synced 2025-10-08 16:40:09 +08:00
temp
This commit is contained in:
30
multibuffer.go
Normal file
30
multibuffer.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package gortsplib
|
||||
|
||||
// MultiBuffer implements software multi buffering, that allows to reuse
|
||||
// existing buffers without creating new ones, increasing performance.
|
||||
type MultiBuffer struct {
|
||||
buffers [][]byte
|
||||
curBuf int
|
||||
}
|
||||
|
||||
// NewMultiBuffer allocates a MultiBuffer.
|
||||
func NewMultiBuffer(count int, size int) *MultiBuffer {
|
||||
buffers := make([][]byte, count)
|
||||
for i := 0; i < count; i++ {
|
||||
buffers[i] = make([]byte, size)
|
||||
}
|
||||
|
||||
return &MultiBuffer{
|
||||
buffers: buffers,
|
||||
}
|
||||
}
|
||||
|
||||
// Next gets the current buffer and sets the next buffer as the current one.
|
||||
func (mb *MultiBuffer) Next() []byte {
|
||||
ret := mb.buffers[mb.curBuf]
|
||||
mb.curBuf += 1
|
||||
if mb.curBuf >= len(mb.buffers) {
|
||||
mb.curBuf = 0
|
||||
}
|
||||
return ret
|
||||
}
|
Reference in New Issue
Block a user